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.letter.server.transfer; 018 019import com.echothree.model.control.contact.server.control.ContactControl; 020import com.echothree.model.control.letter.common.transfer.LetterSourceTransfer; 021import com.echothree.model.control.letter.server.control.LetterControl; 022import com.echothree.model.control.party.server.control.PartyControl; 023import com.echothree.model.data.letter.server.entity.LetterSource; 024import com.echothree.model.data.user.server.entity.UserVisit; 025import com.echothree.util.server.persistence.Session; 026import javax.enterprise.context.RequestScoped; 027 028@RequestScoped 029public class LetterSourceTransferCache 030 extends BaseLetterTransferCache<LetterSource, LetterSourceTransfer> { 031 032 ContactControl contactControl = Session.getModelController(ContactControl.class); 033 LetterControl letterControl = Session.getModelController(LetterControl.class); 034 PartyControl partyControl = Session.getModelController(PartyControl.class); 035 036 /** Creates a new instance of LetterSourceTransferCache */ 037 protected LetterSourceTransferCache() { 038 super(); 039 040 setIncludeEntityInstance(true); 041 } 042 043 public LetterSourceTransfer getLetterSourceTransfer(UserVisit userVisit, LetterSource letterSource) { 044 var letterSourceTransfer = get(letterSource); 045 046 if(letterSourceTransfer == null) { 047 var letterSourceDetail = letterSource.getLastDetail(); 048 var letterSourceName = letterSourceDetail.getLetterSourceName(); 049 var companyTransfer = partyControl.getCompanyTransfer(userVisit, letterSourceDetail.getCompanyParty()); 050 var emailAddressPartyContactMechanismTransfer = contactControl.getPartyContactMechanismTransfer(userVisit, letterSourceDetail.getEmailAddressPartyContactMechanism()); 051 var postalAddressPartyContactMechanismTransfer = contactControl.getPartyContactMechanismTransfer(userVisit, letterSourceDetail.getPostalAddressPartyContactMechanism()); 052 var letterSourcePartyContactMechanismTransfer = contactControl.getPartyContactMechanismTransfer(userVisit, letterSourceDetail.getLetterSourcePartyContactMechanism()); 053 var isDefault = letterSourceDetail.getIsDefault(); 054 var sortOrder = letterSourceDetail.getSortOrder(); 055 var description = letterControl.getBestLetterSourceDescription(letterSource, getLanguage(userVisit)); 056 057 letterSourceTransfer = new LetterSourceTransfer(letterSourceName, companyTransfer, 058 emailAddressPartyContactMechanismTransfer, postalAddressPartyContactMechanismTransfer, 059 letterSourcePartyContactMechanismTransfer, isDefault, sortOrder, description); 060 put(userVisit, letterSource, letterSourceTransfer); 061 } 062 063 return letterSourceTransfer; 064 } 065 066}