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.associate.server.transfer; 018 019import com.echothree.model.control.associate.common.transfer.AssociatePartyContactMechanismTransfer; 020import com.echothree.model.control.associate.common.transfer.AssociateReferralTransfer; 021import com.echothree.model.control.associate.common.transfer.AssociateTransfer; 022import com.echothree.model.control.associate.server.control.AssociateControl; 023import com.echothree.model.control.core.common.transfer.EntityInstanceTransfer; 024import com.echothree.model.control.core.server.control.CoreControl; 025import com.echothree.model.data.associate.server.entity.AssociatePartyContactMechanism; 026import com.echothree.model.data.associate.server.entity.AssociateReferral; 027import com.echothree.model.data.associate.server.entity.AssociateReferralDetail; 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; 031 032public class AssociateReferralTransferCache 033 extends BaseAssociateTransferCache<AssociateReferral, AssociateReferralTransfer> { 034 035 CoreControl coreControl = Session.getModelController(CoreControl.class); 036 037 /** Creates a new instance of AssociateReferralTransferCache */ 038 public AssociateReferralTransferCache(UserVisit userVisit, AssociateControl associateControl) { 039 super(userVisit, associateControl); 040 041 setIncludeEntityInstance(true); 042 } 043 044 @Override 045 public AssociateReferralTransfer getTransfer(AssociateReferral associateReferral) { 046 AssociateReferralTransfer associateReferralTransfer = get(associateReferral); 047 048 if(associateReferralTransfer == null) { 049 AssociateReferralDetail associateReferralDetail = associateReferral.getLastDetail(); 050 String associateReferralName = associateReferralDetail.getAssociateReferralName(); 051 AssociateTransfer associateTransfer = associateControl.getAssociateTransfer(userVisit, associateReferralDetail.getAssociate()); 052 AssociatePartyContactMechanism associatePartyContactMechanism = associateReferralDetail.getAssociatePartyContactMechanism(); 053 AssociatePartyContactMechanismTransfer associatePartyContactMechanismTransfer = associatePartyContactMechanism == null ? null : associateControl.getAssociatePartyContactMechanismTransfer(userVisit, associatePartyContactMechanism); 054 EntityInstance targetEntityInstance = associateReferralDetail.getTargetEntityInstance(); 055 EntityInstanceTransfer targetEntityInstanceTransfer = targetEntityInstance == null ? null : coreControl.getEntityInstanceTransfer(userVisit, targetEntityInstance, false, false, false, false, false, false); 056 Long unformattedAssociateReferralTime = associateReferralDetail.getAssociateReferralTime(); 057 String associateReferralTime = formatTypicalDateTime(unformattedAssociateReferralTime); 058 059 associateReferralTransfer = new AssociateReferralTransfer(associateReferralName, associateTransfer, associatePartyContactMechanismTransfer, 060 targetEntityInstanceTransfer, unformattedAssociateReferralTime, associateReferralTime); 061 put(associateReferral, associateReferralTransfer); 062 } 063 064 return associateReferralTransfer; 065 } 066 067}