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