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.party.server.transfer; 018 019import com.echothree.model.control.accounting.server.control.AccountingControl; 020import com.echothree.model.control.carrier.server.control.CarrierControl; 021import com.echothree.model.control.contact.server.control.ContactControl; 022import com.echothree.model.control.contactlist.server.control.ContactListControl; 023import com.echothree.model.control.document.server.control.DocumentControl; 024import com.echothree.model.control.employee.server.control.EmployeeControl; 025import com.echothree.model.control.party.common.PartyOptions; 026import com.echothree.model.control.party.common.transfer.PartyRelationshipTransfer; 027import com.echothree.model.control.party.common.transfer.PartyTransfer; 028import com.echothree.model.control.party.server.control.PartyControl; 029import com.echothree.model.control.printer.server.control.PrinterControl; 030import com.echothree.model.control.scale.server.control.ScaleControl; 031import com.echothree.model.control.training.server.control.TrainingControl; 032import com.echothree.model.control.user.server.control.UserControl; 033import com.echothree.model.data.party.server.entity.Party; 034import com.echothree.model.data.user.server.entity.UserVisit; 035import com.echothree.util.common.transfer.ListWrapper; 036import com.echothree.util.server.persistence.Session; 037import java.util.ArrayList; 038import java.util.HashSet; 039import java.util.Set; 040import javax.enterprise.context.RequestScoped; 041 042@RequestScoped 043public class PartyTransferCache 044 extends BasePartyTransferCache<Party, PartyTransfer> { 045 046 AccountingControl accountingControl = Session.getModelController(AccountingControl.class); 047 CarrierControl carrierControl = Session.getModelController(CarrierControl.class); 048 ContactControl contactControl = Session.getModelController(ContactControl.class); 049 ContactListControl contactListControl = Session.getModelController(ContactListControl.class); 050 DocumentControl documentControl = Session.getModelController(DocumentControl.class); 051 EmployeeControl employeeControl = Session.getModelController(EmployeeControl.class); 052 PartyControl partyControl = Session.getModelController(PartyControl.class); 053 PrinterControl printerControl = Session.getModelController(PrinterControl.class); 054 ScaleControl scaleControl = Session.getModelController(ScaleControl.class); 055 TrainingControl trainingControl = Session.getModelController(TrainingControl.class); 056 UserControl userControl = Session.getModelController(UserControl.class); 057 058 boolean includeUserLogin; 059 boolean includeRecoveryAnswer; 060 boolean includeDescription; 061 boolean includePartyAliases; 062 boolean includePartyContactMechanisms; 063 boolean includePartyContactLists; 064 boolean includePartyDocuments; 065 boolean includePartyPrinterGroupUses; 066 boolean includePartyScaleUses; 067 boolean includePartyCarriers; 068 boolean includePartyCarrierAccounts; 069 boolean includePartyRelationships; 070 boolean includePartyRelationshipsByFromParty; 071 boolean includePartyRelationshipsByToParty; 072 boolean includeEmployments; 073 boolean includeLeaves; 074 boolean includePartyResponsibilities; 075 boolean includePartyTrainingClasses; 076 boolean includePartySkills; 077 078 /** Creates a new instance of PartyTransferCache */ 079 protected PartyTransferCache() { 080 super(); 081 082 var options = session.getOptions(); 083 if(options != null) { 084 setIncludeUuid(options.contains(PartyOptions.PartyIncludeUuid)); 085 includeUserLogin = options.contains(PartyOptions.PartyIncludeUserLogin); 086 includeRecoveryAnswer = options.contains(PartyOptions.PartyIncludeRecoveryAnswer); 087 includeDescription = options.contains(PartyOptions.PartyIncludeDescription); 088 includePartyAliases = options.contains(PartyOptions.PartyIncludePartyAliases); 089 includePartyContactMechanisms = options.contains(PartyOptions.PartyIncludePartyContactMechanisms); 090 includePartyContactLists = options.contains(PartyOptions.PartyIncludePartyContactLists); 091 includePartyDocuments = options.contains(PartyOptions.PartyIncludePartyDocuments); 092 includePartyPrinterGroupUses = options.contains(PartyOptions.PartyIncludePartyPrinterGroupUses); 093 includePartyScaleUses = options.contains(PartyOptions.PartyIncludePartyScaleUses); 094 includePartyCarriers = options.contains(PartyOptions.PartyIncludePartyCarriers); 095 includePartyCarrierAccounts = options.contains(PartyOptions.PartyIncludePartyCarrierAccounts); 096 includePartyRelationships = options.contains(PartyOptions.PartyIncludePartyRelationships); 097 includePartyRelationshipsByFromParty = options.contains(PartyOptions.PartyIncludePartyRelationshipsByFromParty); 098 includePartyRelationshipsByToParty = options.contains(PartyOptions.PartyIncludePartyRelationshipsByToParty); 099 includeEmployments = options.contains(PartyOptions.PartyIncludeEmployments); 100 includeLeaves = options.contains(PartyOptions.PartyIncludeLeaves); 101 includePartyResponsibilities = options.contains(PartyOptions.PartyIncludePartyResponsibilities); 102 includePartyTrainingClasses = options.contains(PartyOptions.PartyIncludePartyTrainingClasses); 103 includePartySkills = options.contains(PartyOptions.PartyIncludePartySkills); 104 } 105 106 setIncludeEntityInstance(true); 107 } 108 109 @Override 110 public PartyTransfer getTransfer(UserVisit userVisit, Party party) { 111 var partyTransfer = get(party); 112 113 if(partyTransfer == null) { 114 var partyDetail = party.getLastDetail(); 115 var partyName = partyDetail.getPartyName(); 116 var partyTypeTransfer = partyControl.getPartyTypeTransfer(userVisit, partyDetail.getPartyType()); 117 var preferredLanguage = partyDetail.getPreferredLanguage(); 118 var preferredLanguageTransfer = preferredLanguage == null? null: partyControl.getLanguageTransfer(userVisit, preferredLanguage); 119 var preferredCurrency = partyDetail.getPreferredCurrency(); 120 var preferredCurrencyTransfer = preferredCurrency == null? null: accountingControl.getCurrencyTransfer(userVisit, preferredCurrency); 121 var preferredTimeZone = partyDetail.getPreferredTimeZone(); 122 var preferredTimeZoneTransfer = preferredTimeZone == null? null: partyControl.getTimeZoneTransfer(userVisit, preferredTimeZone); 123 var preferredDateTimeFormat = partyDetail.getPreferredDateTimeFormat(); 124 var preferredDateTimeFormatTransfer = preferredDateTimeFormat == null? null: partyControl.getDateTimeFormatTransfer(userVisit, preferredDateTimeFormat); 125 var person = partyControl.getPerson(party); 126 var personTransfer = person == null? null: partyControl.getPersonTransfer(userVisit, person); 127 var partyGroup = partyControl.getPartyGroup(party); 128 var partyGroupTransfer = partyGroup == null? null: partyControl.getPartyGroupTransfer(userVisit, partyGroup); 129 var profile = partyControl.getProfile(party); 130 var profileTransfer = profile == null? null: partyControl.getProfileTransfer(userVisit, profile); 131 132 partyTransfer = new PartyTransfer(partyName, partyTypeTransfer, preferredLanguageTransfer, preferredCurrencyTransfer, preferredTimeZoneTransfer, preferredDateTimeFormatTransfer, 133 personTransfer, partyGroupTransfer, profileTransfer); 134 put(userVisit, party, partyTransfer); 135 136 if(includeUserLogin) { 137 partyTransfer.setUserLogin(userControl.getUserLoginTransfer(userVisit, party)); 138 } 139 140 if(includeRecoveryAnswer) { 141 partyTransfer.setRecoveryAnswer(userControl.getRecoveryAnswerTransfer(userVisit, party)); 142 } 143 144 if(includeDescription) { 145 partyTransfer.setDescription(partyControl.getBestPartyDescription(party, getLanguage(userVisit))); 146 } 147 148 if(includePartyContactMechanisms) { 149 partyTransfer.setPartyContactMechanisms(new ListWrapper<>(contactControl.getPartyContactMechanismTransfersByParty(userVisit, party))); 150 } 151 152 if(includePartyContactLists) { 153 partyTransfer.setPartyContactLists(new ListWrapper<>(contactListControl.getPartyContactListTransfersByParty(userVisit, party))); 154 } 155 156 if(includePartyAliases) { 157 partyTransfer.setPartyAliases(new ListWrapper<>(partyControl.getPartyAliasTransfersByParty(userVisit, party))); 158 } 159 160 if(includePartyDocuments) { 161 partyTransfer.setPartyDocuments(new ListWrapper<>(documentControl.getPartyDocumentTransfersByParty(userVisit, party))); 162 } 163 164 if(includePartyPrinterGroupUses) { 165 partyTransfer.setPartyPrinterGroupUses(new ListWrapper<>(printerControl.getPartyPrinterGroupUseTransfersByParty(userVisit, party))); 166 } 167 168 if(includePartyScaleUses) { 169 partyTransfer.setPartyScaleUses(new ListWrapper<>(scaleControl.getPartyScaleUseTransfersByParty(userVisit, party))); 170 } 171 172 if(includePartyCarriers) { 173 partyTransfer.setPartyCarriers(new ListWrapper<>(carrierControl.getPartyCarrierTransfersByParty(userVisit, party))); 174 } 175 176 if(includePartyCarrierAccounts) { 177 partyTransfer.setPartyCarrierAccounts(new ListWrapper<>(carrierControl.getPartyCarrierAccountTransfersByParty(userVisit, party))); 178 } 179 180 if(includePartyRelationships || includePartyRelationshipsByFromParty || includePartyRelationshipsByToParty) { 181 Set<PartyRelationshipTransfer> partyRelationships = new HashSet<>(); 182 183 if(includePartyRelationships || includePartyRelationshipsByFromParty) { 184 partyRelationships.addAll(partyControl.getPartyRelationshipTransfersByFromParty(userVisit, party)); 185 } 186 187 if(includePartyRelationships || includePartyRelationshipsByToParty) { 188 partyRelationships.addAll(partyControl.getPartyRelationshipTransfersByToParty(userVisit, party)); 189 } 190 191 partyTransfer.setPartyRelationships(new ListWrapper<>(new ArrayList<>(partyRelationships))); 192 } 193 194 if(includeEmployments) { 195 partyTransfer.setEmployments(new ListWrapper<>(employeeControl.getEmploymentTransfersByParty(userVisit, party))); 196 } 197 198 if(includeLeaves) { 199 partyTransfer.setLeaves(new ListWrapper<>(employeeControl.getLeaveTransfersByParty(userVisit, party))); 200 } 201 202 if(includePartyResponsibilities) { 203 partyTransfer.setPartyResponsibilities(new ListWrapper<>(employeeControl.getPartyResponsibilityTransfersByParty(userVisit, party))); 204 } 205 206 if(includePartyTrainingClasses) { 207 partyTransfer.setPartyTrainingClasses(new ListWrapper<>(trainingControl.getPartyTrainingClassTransfersByParty(userVisit, party))); 208 } 209 210 if(includePartySkills) { 211 partyTransfer.setPartySkills(new ListWrapper<>(employeeControl.getPartySkillTransfersByParty(userVisit, party))); 212 } 213 } 214 215 return partyTransfer; 216 } 217 218}