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.letter.server.transfer; 018 019import com.echothree.model.control.chain.common.transfer.ChainTypeTransfer; 020import com.echothree.model.control.chain.server.control.ChainControl; 021import com.echothree.model.control.contactlist.common.transfer.ContactListTransfer; 022import com.echothree.model.control.contactlist.server.ContactListControl; 023import com.echothree.model.control.letter.common.transfer.LetterSourceTransfer; 024import com.echothree.model.control.letter.common.transfer.LetterTransfer; 025import com.echothree.model.control.letter.server.control.LetterControl; 026import com.echothree.model.data.contactlist.server.entity.ContactList; 027import com.echothree.model.data.letter.server.entity.Letter; 028import com.echothree.model.data.letter.server.entity.LetterDetail; 029import com.echothree.model.data.user.server.entity.UserVisit; 030import com.echothree.util.server.persistence.Session; 031 032public class LetterTransferCache 033 extends BaseLetterTransferCache<Letter, LetterTransfer> { 034 035 ChainControl chainControl = Session.getModelController(ChainControl.class); 036 ContactListControl contactListControl = Session.getModelController(ContactListControl.class); 037 038 /** Creates a new instance of LetterTransferCache */ 039 public LetterTransferCache(UserVisit userVisit, LetterControl letterControl) { 040 super(userVisit, letterControl); 041 042 setIncludeEntityInstance(true); 043 } 044 045 public LetterTransfer getLetterTransfer(Letter letter) { 046 LetterTransfer letterTransfer = get(letter); 047 048 if(letterTransfer == null) { 049 LetterDetail letterDetail = letter.getLastDetail(); 050 ChainTypeTransfer chainTypeTransfer = chainControl.getChainTypeTransfer(userVisit, letterDetail.getChainType()); 051 String letterName = letterDetail.getLetterName(); 052 LetterSourceTransfer letterSourceTransfer = letterControl.getLetterSourceTransfer(userVisit, letterDetail.getLetterSource()); 053 ContactList contactList = letterDetail.getContactList(); 054 ContactListTransfer contactListTransfer = contactList == null? null: contactListControl.getContactListTransfer(userVisit, contactList); 055 Boolean isDefault = letterDetail.getIsDefault(); 056 Integer sortOrder = letterDetail.getSortOrder(); 057 String description = letterControl.getBestLetterDescription(letter, getLanguage()); 058 059 letterTransfer = new LetterTransfer(chainTypeTransfer, letterName, letterSourceTransfer, contactListTransfer, isDefault, 060 sortOrder, description); 061 put(letter, letterTransfer); 062 } 063 064 return letterTransfer; 065 } 066 067}