001// -------------------------------------------------------------------------------- 002// Copyright 2002-2024 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.CampaignSourceTransfer; 021import com.echothree.model.control.campaign.server.control.CampaignControl; 022import com.echothree.model.control.core.server.control.CoreControl; 023import com.echothree.model.control.campaign.common.workflow.CampaignSourceStatusConstants; 024import com.echothree.model.control.workflow.common.transfer.WorkflowEntityStatusTransfer; 025import com.echothree.model.control.workflow.server.control.WorkflowControl; 026import com.echothree.model.data.campaign.server.entity.CampaignSource; 027import com.echothree.model.data.campaign.server.entity.CampaignSourceDetail; 028import com.echothree.model.data.core.server.entity.EntityInstance; 029import com.echothree.model.data.user.server.entity.UserVisit; 030import com.echothree.util.server.persistence.Session; 031import java.util.Set; 032 033public class CampaignSourceTransferCache 034 extends BaseCampaignTransferCache<CampaignSource, CampaignSourceTransfer> { 035 036 CoreControl coreControl = Session.getModelController(CoreControl.class); 037 WorkflowControl workflowControl = Session.getModelController(WorkflowControl.class); 038 039 /** Creates a new instance of CampaignSourceTransferCache */ 040 public CampaignSourceTransferCache(UserVisit userVisit, CampaignControl campaignControl) { 041 super(userVisit, campaignControl); 042 043 var options = session.getOptions(); 044 if(options != null) { 045 setIncludeKey(options.contains(CampaignOptions.CampaignSourceIncludeKey)); 046 setIncludeGuid(options.contains(CampaignOptions.CampaignSourceIncludeGuid)); 047 } 048 049 setIncludeEntityInstance(true); 050 } 051 052 public CampaignSourceTransfer getCampaignSourceTransfer(CampaignSource campaignSource) { 053 CampaignSourceTransfer campaignSourceTransfer = get(campaignSource); 054 055 if(campaignSourceTransfer == null) { 056 CampaignSourceDetail campaignSourceDetail = campaignSource.getLastDetail(); 057 String campaignSourceName = campaignSourceDetail.getCampaignSourceName(); 058 String valueSha1Hash = campaignSourceDetail.getValueSha1Hash(); 059 String value = campaignSourceDetail.getValue(); 060 Boolean isDefault = campaignSourceDetail.getIsDefault(); 061 Integer sortOrder = campaignSourceDetail.getSortOrder(); 062 String description = campaignControl.getBestCampaignSourceDescription(campaignSource, getLanguage()); 063 064 EntityInstance entityInstance = coreControl.getEntityInstanceByBasePK(campaignSource.getPrimaryKey()); 065 WorkflowEntityStatusTransfer campaignSourceStatusTransfer = workflowControl.getWorkflowEntityStatusTransferByEntityInstanceUsingNames(userVisit, 066 CampaignSourceStatusConstants.Workflow_CAMPAIGN_SOURCE_STATUS, entityInstance); 067 068 campaignSourceTransfer = new CampaignSourceTransfer(campaignSourceName, valueSha1Hash, value, isDefault, sortOrder, description, 069 campaignSourceStatusTransfer); 070 put(campaignSource, campaignSourceTransfer); 071 } 072 073 return campaignSourceTransfer; 074 } 075 076}