001// -------------------------------------------------------------------------------- 002// Copyright 2002-2025 Echo Three, LLC 003// 004// Licensed under the Apache License, Version 2.0 (the "License"); 005// you may not use this file except in compliance with the License. 006// You may obtain a copy of the License at 007// 008// http://www.apache.org/licenses/LICENSE-2.0 009// 010// Unless required by applicable law or agreed to in writing, software 011// distributed under the License is distributed on an "AS IS" BASIS, 012// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013// See the License for the specific language governing permissions and 014// limitations under the License. 015// -------------------------------------------------------------------------------- 016 017package com.echothree.model.control.campaign.server.transfer; 018 019import com.echothree.model.control.campaign.common.CampaignOptions; 020import com.echothree.model.control.campaign.common.transfer.CampaignContentTransfer; 021import com.echothree.model.control.campaign.common.workflow.CampaignContentStatusConstants; 022import com.echothree.model.control.campaign.server.control.CampaignControl; 023import com.echothree.model.control.core.server.control.EntityInstanceControl; 024import com.echothree.model.control.workflow.server.control.WorkflowControl; 025import com.echothree.model.data.campaign.server.entity.CampaignContent; 026import com.echothree.model.data.user.server.entity.UserVisit; 027import com.echothree.util.server.persistence.Session; 028import javax.enterprise.context.RequestScoped; 029 030@RequestScoped 031public class CampaignContentTransferCache 032 extends BaseCampaignTransferCache<CampaignContent, CampaignContentTransfer> { 033 034 CampaignControl campaignControl = Session.getModelController(CampaignControl.class); 035 EntityInstanceControl entityInstanceControl = Session.getModelController(EntityInstanceControl.class); 036 WorkflowControl workflowControl = Session.getModelController(WorkflowControl.class); 037 038 /** Creates a new instance of CampaignContentTransferCache */ 039 protected CampaignContentTransferCache() { 040 super(); 041 042 var options = session.getOptions(); 043 if(options != null) { 044 setIncludeUuid(options.contains(CampaignOptions.CampaignContentIncludeUuid)); 045 } 046 047 setIncludeEntityInstance(true); 048 } 049 050 public CampaignContentTransfer getCampaignContentTransfer(UserVisit userVisit, CampaignContent campaignContent) { 051 var campaignContentTransfer = get(campaignContent); 052 053 if(campaignContentTransfer == null) { 054 var campaignContentDetail = campaignContent.getLastDetail(); 055 var campaignContentName = campaignContentDetail.getCampaignContentName(); 056 var valueSha1Hash = campaignContentDetail.getValueSha1Hash(); 057 var value = campaignContentDetail.getValue(); 058 var isDefault = campaignContentDetail.getIsDefault(); 059 var sortOrder = campaignContentDetail.getSortOrder(); 060 var description = campaignControl.getBestCampaignContentDescription(campaignContent, getLanguage(userVisit)); 061 062 var entityInstance = entityInstanceControl.getEntityInstanceByBasePK(campaignContent.getPrimaryKey()); 063 var campaignContentStatusTransfer = workflowControl.getWorkflowEntityStatusTransferByEntityInstanceUsingNames(userVisit, 064 CampaignContentStatusConstants.Workflow_CAMPAIGN_CONTENT_STATUS, entityInstance); 065 066 campaignContentTransfer = new CampaignContentTransfer(campaignContentName, valueSha1Hash, value, isDefault, sortOrder, description, 067 campaignContentStatusTransfer); 068 put(userVisit, campaignContent, campaignContentTransfer); 069 } 070 071 return campaignContentTransfer; 072 } 073 074}