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.contactlist.server.transfer; 018 019import com.echothree.model.control.comment.common.CommentConstants; 020import com.echothree.model.control.contactlist.common.ContactListOptions; 021import com.echothree.model.control.contactlist.common.transfer.PartyContactListTransfer; 022import com.echothree.model.control.contactlist.server.control.ContactListControl; 023import com.echothree.model.control.core.server.control.EntityInstanceControl; 024import com.echothree.model.control.party.server.control.PartyControl; 025import com.echothree.model.control.workflow.server.control.WorkflowControl; 026import com.echothree.model.data.contactlist.server.entity.PartyContactList; 027import com.echothree.model.data.user.server.entity.UserVisit; 028import com.echothree.util.server.persistence.Session; 029import javax.enterprise.context.RequestScoped; 030 031@RequestScoped 032public class PartyContactListTransferCache 033 extends BaseContactListTransferCache<PartyContactList, PartyContactListTransfer> { 034 035 ContactListControl contactListControl = Session.getModelController(ContactListControl.class); 036 EntityInstanceControl entityInstanceControl = Session.getModelController(EntityInstanceControl.class); 037 PartyControl partyControl = Session.getModelController(PartyControl.class); 038 WorkflowControl workflowControl = Session.getModelController(WorkflowControl.class); 039 040 boolean includeStatus; 041 boolean includeComments; 042 043 /** Creates a new instance of PartyContactListTransferCache */ 044 protected PartyContactListTransferCache() { 045 super(); 046 047 var options = session.getOptions(); 048 if(options != null) { 049 setIncludeUuid(options.contains(ContactListOptions.PartyContactListIncludeUuid)); 050 includeStatus = options.contains(ContactListOptions.PartyContactListIncludeStatus); 051 includeComments = options.contains(ContactListOptions.PartyContactListIncludeComments); 052 } 053 054 setIncludeEntityInstance(true); 055 } 056 057 public PartyContactListTransfer getPartyContactListTransfer(UserVisit userVisit, PartyContactList partyContactList) { 058 var partyContactListTransfer = get(partyContactList); 059 060 if(partyContactListTransfer == null) { 061 var partyContactListDetail = partyContactList.getLastDetail(); 062 var partyTransfer = partyControl.getPartyTransfer(userVisit, partyContactListDetail.getParty()); 063 var contactList = partyContactListDetail.getContactList(); 064 var contactListTransfer = contactListControl.getContactListTransfer(userVisit, contactList); 065 var preferredContactListContactMechanismPurpose = partyContactListDetail.getPreferredContactListContactMechanismPurpose(); 066 var preferredContactListContactMechanismPurposeTransfer = preferredContactListContactMechanismPurpose == null ? null : contactListControl.getContactListContactMechanismPurposeTransfer(userVisit, preferredContactListContactMechanismPurpose); 067 var entityInstance = entityInstanceControl.getEntityInstanceByBasePK(partyContactList.getPrimaryKey()); 068 069 partyContactListTransfer = new PartyContactListTransfer(partyTransfer, contactListTransfer, preferredContactListContactMechanismPurposeTransfer); 070 put(userVisit, partyContactList, partyContactListTransfer, entityInstance); 071 072 if(includeStatus) { 073 var workflow = contactList.getLastDetail().getDefaultPartyContactListStatus().getLastDetail().getWorkflow(); 074 075 if(workflow != null) { 076 partyContactListTransfer.setPartyContactListStatus(workflowControl.getWorkflowEntityStatusTransferByEntityInstance(userVisit, workflow, 077 entityInstance)); 078 } 079 } 080 081 if(includeComments) { 082 setupComments(userVisit, partyContactList, entityInstance, partyContactListTransfer, CommentConstants.CommentType_PARTY_CONTACT_LIST); 083 } 084 } 085 086 return partyContactListTransfer; 087 } 088 089}