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