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// -------------------------------------------------------------------------------- 016package com.echothree.model.control.employee.server.transfer; 017 018import com.echothree.model.control.accounting.server.control.AccountingControl; 019import com.echothree.model.control.contact.server.control.ContactControl; 020import com.echothree.model.control.contactlist.server.control.ContactListControl; 021import com.echothree.model.control.core.server.control.EntityInstanceControl; 022import com.echothree.model.control.party.server.control.PartyApplicationEditorUseControl; 023import com.echothree.model.control.party.server.control.PartyEntityTypeControl; 024import com.echothree.model.control.document.server.control.DocumentControl; 025import com.echothree.model.control.employee.common.EmployeeOptions; 026import com.echothree.model.control.employee.common.transfer.EmployeeTransfer; 027import com.echothree.model.control.employee.common.workflow.EmployeeAvailabilityConstants; 028import com.echothree.model.control.employee.common.workflow.EmployeeStatusConstants; 029import com.echothree.model.control.employee.server.control.EmployeeControl; 030import com.echothree.model.control.party.common.PartyOptions; 031import com.echothree.model.control.party.common.transfer.PartyRelationshipTransfer; 032import com.echothree.model.control.party.server.control.PartyControl; 033import com.echothree.model.control.printer.server.control.PrinterControl; 034import com.echothree.model.control.scale.server.control.ScaleControl; 035import com.echothree.model.control.training.server.control.TrainingControl; 036import com.echothree.model.control.user.server.control.UserControl; 037import com.echothree.model.control.workflow.server.control.WorkflowControl; 038import com.echothree.model.data.employee.server.entity.PartyEmployee; 039import com.echothree.model.data.party.server.entity.Party; 040import com.echothree.model.data.user.server.entity.UserVisit; 041import com.echothree.util.common.transfer.ListWrapper; 042import com.echothree.util.server.persistence.Session; 043import java.util.ArrayList; 044import java.util.HashSet; 045import java.util.Set; 046import javax.enterprise.context.RequestScoped; 047 048@RequestScoped 049public class EmployeeTransferCache 050 extends BaseEmployeeTransferCache<Party, EmployeeTransfer> { 051 052 AccountingControl accountingControl = Session.getModelController(AccountingControl.class); 053 ContactControl contactControl = Session.getModelController(ContactControl.class); 054 ContactListControl contactListControl = Session.getModelController(ContactListControl.class); 055 DocumentControl documentControl = Session.getModelController(DocumentControl.class); 056 EmployeeControl employeeControl = Session.getModelController(EmployeeControl.class); 057 EntityInstanceControl entityInstanceControl = Session.getModelController(EntityInstanceControl.class); 058 PartyApplicationEditorUseControl partyApplicationEditorUseControl = Session.getModelController(PartyApplicationEditorUseControl.class); 059 PartyControl partyControl = Session.getModelController(PartyControl.class); 060 PartyEntityTypeControl partyEntityTypeControl = Session.getModelController(PartyEntityTypeControl.class); 061 PrinterControl printerControl = Session.getModelController(PrinterControl.class); 062 ScaleControl scaleControl = Session.getModelController(ScaleControl.class); 063 TrainingControl trainingControl = Session.getModelController(TrainingControl.class); 064 UserControl userControl = Session.getModelController(UserControl.class); 065 WorkflowControl workflowControl = Session.getModelController(WorkflowControl.class); 066 067 boolean includeUserLogin; 068 boolean includeRecoveryAnswer; 069 boolean includePartyAliases; 070 boolean includePartyContactMechanisms; 071 boolean includePartyContactLists; 072 boolean includePartyDocuments; 073 boolean includePartyPrinterGroupUses; 074 boolean includePartyScaleUses; 075 boolean includePartyEntityTypes; 076 boolean includePartyApplicationEditorUses; 077 boolean includePartyRelationships; 078 boolean includePartyRelationshipsByFromParty; 079 boolean includePartyRelationshipsByToParty; 080 boolean includeEmployments; 081 boolean includeLeaves; 082 boolean includePartyResponsibilities; 083 boolean includePartyTrainingClasses; 084 boolean includePartySkills; 085 086 /** Creates a new instance of EmployeeTransferCache */ 087 protected EmployeeTransferCache() { 088 super(); 089 090 var options = session.getOptions(); 091 if(options != null) { 092 setIncludeUuid(options.contains(PartyOptions.PartyIncludeUuid) || options.contains(EmployeeOptions.EmployeeIncludeUuid)); 093 includeUserLogin = options.contains(PartyOptions.PartyIncludeUserLogin); 094 includeRecoveryAnswer = options.contains(PartyOptions.PartyIncludeRecoveryAnswer); 095 includePartyAliases = options.contains(PartyOptions.PartyIncludePartyAliases); 096 includePartyContactMechanisms = options.contains(PartyOptions.PartyIncludePartyContactMechanisms); 097 includePartyContactLists = options.contains(PartyOptions.PartyIncludePartyContactLists); 098 includePartyDocuments = options.contains(PartyOptions.PartyIncludePartyDocuments); 099 includePartyPrinterGroupUses = options.contains(PartyOptions.PartyIncludePartyPrinterGroupUses); 100 includePartyScaleUses = options.contains(PartyOptions.PartyIncludePartyScaleUses); 101 includePartyEntityTypes = options.contains(PartyOptions.PartyIncludePartyEntityTypes); 102 includePartyApplicationEditorUses = options.contains(PartyOptions.PartyIncludePartyApplicationEditorUses); 103 includePartyRelationships = options.contains(EmployeeOptions.EmployeeIncludePartyRelationships); 104 includePartyRelationshipsByFromParty = options.contains(EmployeeOptions.EmployeeIncludePartyRelationshipsByFromParty); 105 includePartyRelationshipsByToParty = options.contains(EmployeeOptions.EmployeeIncludePartyRelationshipsByToParty); 106 includeEmployments = options.contains(EmployeeOptions.EmployeeIncludeEmployments); 107 includeLeaves = options.contains(EmployeeOptions.EmployeeIncludeLeaves); 108 includePartyResponsibilities = options.contains(EmployeeOptions.EmployeeIncludePartyResponsibilities); 109 includePartyTrainingClasses = options.contains(EmployeeOptions.EmployeeIncludePartyTrainingClasses); 110 includePartySkills = options.contains(EmployeeOptions.EmployeeIncludePartySkills); 111 setIncludeEntityAttributeGroups(options.contains(EmployeeOptions.EmployeeIncludeEntityAttributeGroups)); 112 setIncludeTagScopes(options.contains(EmployeeOptions.EmployeeIncludeTagScopes)); 113 } 114 115 setIncludeEntityInstance(true); 116 } 117 118 public EmployeeTransfer getTransfer(UserVisit userVisit, PartyEmployee partyEmployee) { 119 return getTransfer(userVisit, partyEmployee.getParty()); 120 } 121 122 public EmployeeTransfer getTransfer(UserVisit userVisit, Party party) { 123 var employeeTransfer = get(party); 124 125 if(employeeTransfer == null) { 126 var partyDetail = party.getLastDetail(); 127 var partyName = partyDetail.getPartyName(); 128 var partyTypeTransfer = partyControl.getPartyTypeTransfer(userVisit, partyDetail.getPartyType()); 129 var preferredLanguage = partyDetail.getPreferredLanguage(); 130 var preferredLanguageTransfer = preferredLanguage == null ? null : partyControl.getLanguageTransfer(userVisit, preferredLanguage); 131 var preferredCurrency = partyDetail.getPreferredCurrency(); 132 var preferredCurrencyTransfer = preferredCurrency == null ? null : accountingControl.getCurrencyTransfer(userVisit, preferredCurrency); 133 var preferredTimeZone = partyDetail.getPreferredTimeZone(); 134 var preferredTimeZoneTransfer = preferredTimeZone == null ? null : partyControl.getTimeZoneTransfer(userVisit, preferredTimeZone); 135 var preferredDateTimeFormat = partyDetail.getPreferredDateTimeFormat(); 136 var preferredDateTimeFormatTransfer = preferredDateTimeFormat == null ? null : partyControl.getDateTimeFormatTransfer(userVisit, preferredDateTimeFormat); 137 var partyEmployee = employeeControl.getPartyEmployee(party); 138 var person = partyControl.getPerson(party); 139 var personTransfer = person == null ? null : partyControl.getPersonTransfer(userVisit, person); 140 var profile = partyControl.getProfile(party); 141 var profileTransfer = profile == null ? null : partyControl.getProfileTransfer(userVisit, profile); 142 143 var employeeName = partyEmployee.getPartyEmployeeName(); 144 var employeeType = employeeControl.getEmployeeTypeTransfer(userVisit, partyEmployee.getEmployeeType()); 145 146 var entityInstance = entityInstanceControl.getEntityInstanceByBasePK(party.getPrimaryKey()); 147 var employeeStatusTransfer = workflowControl.getWorkflowEntityStatusTransferByEntityInstanceUsingNames(userVisit, 148 EmployeeStatusConstants.Workflow_EMPLOYEE_STATUS, entityInstance); 149 var employeeAvailabilityTransfer = workflowControl.getWorkflowEntityStatusTransferByEntityInstanceUsingNames(userVisit, 150 EmployeeAvailabilityConstants.Workflow_EMPLOYEE_AVAILABILITY, entityInstance); 151 152 employeeTransfer = new EmployeeTransfer(partyName, partyTypeTransfer, preferredLanguageTransfer, preferredCurrencyTransfer, preferredTimeZoneTransfer, preferredDateTimeFormatTransfer, 153 personTransfer, profileTransfer, employeeName, employeeType, employeeStatusTransfer, employeeAvailabilityTransfer); 154 put(userVisit, party, employeeTransfer, entityInstance); 155 156 if(includeUserLogin) { 157 employeeTransfer.setUserLogin(userControl.getUserLoginTransfer(userVisit, party)); 158 } 159 160 if(includeRecoveryAnswer) { 161 employeeTransfer.setRecoveryAnswer(userControl.getRecoveryAnswerTransfer(userVisit, party)); 162 } 163 164 if(includePartyAliases) { 165 employeeTransfer.setPartyAliases(new ListWrapper<>(partyControl.getPartyAliasTransfersByParty(userVisit, party))); 166 } 167 168 if(includePartyContactMechanisms) { 169 employeeTransfer.setPartyContactMechanisms(new ListWrapper<>(contactControl.getPartyContactMechanismTransfersByParty(userVisit, party))); 170 } 171 172 if(includePartyContactLists) { 173 employeeTransfer.setPartyContactLists(new ListWrapper<>(contactListControl.getPartyContactListTransfersByParty(userVisit, party))); 174 } 175 176 if(includePartyDocuments) { 177 employeeTransfer.setPartyDocuments(new ListWrapper<>(documentControl.getPartyDocumentTransfersByParty(userVisit, party))); 178 } 179 180 if(includePartyPrinterGroupUses) { 181 employeeTransfer.setPartyPrinterGroupUses(new ListWrapper<>(printerControl.getPartyPrinterGroupUseTransfersByParty(userVisit, party))); 182 } 183 184 if(includePartyScaleUses) { 185 employeeTransfer.setPartyScaleUses(new ListWrapper<>(scaleControl.getPartyScaleUseTransfersByParty(userVisit, party))); 186 } 187 188 if(includePartyEntityTypes) { 189 employeeTransfer.setPartyEntityTypes(new ListWrapper<>(partyEntityTypeControl.getPartyEntityTypeTransfersByParty(userVisit, party))); 190 } 191 192 if(includePartyApplicationEditorUses) { 193 employeeTransfer.setPartyApplicationEditorUses(new ListWrapper<>(partyApplicationEditorUseControl.getPartyApplicationEditorUseTransfersByParty(userVisit, party))); 194 } 195 196 if(includePartyRelationships || includePartyRelationshipsByFromParty || includePartyRelationshipsByToParty) { 197 Set<PartyRelationshipTransfer> partyRelationships = new HashSet<>(); 198 199 if(includePartyRelationships || includePartyRelationshipsByFromParty) { 200 partyRelationships.addAll(partyControl.getPartyRelationshipTransfersByFromParty(userVisit, party)); 201 } 202 203 if(includePartyRelationships || includePartyRelationshipsByToParty) { 204 partyRelationships.addAll(partyControl.getPartyRelationshipTransfersByToParty(userVisit, party)); 205 } 206 207 employeeTransfer.setPartyRelationships(new ListWrapper<>(new ArrayList<>(partyRelationships))); 208 } 209 210 if(includeEmployments) { 211 employeeTransfer.setEmployments(new ListWrapper<>(employeeControl.getEmploymentTransfersByParty(userVisit, party))); 212 } 213 214 if(includeLeaves) { 215 employeeTransfer.setLeaves(new ListWrapper<>(employeeControl.getLeaveTransfersByParty(userVisit, party))); 216 } 217 218 if(includePartyResponsibilities) { 219 employeeTransfer.setPartyResponsibilities(new ListWrapper<>(employeeControl.getPartyResponsibilityTransfersByParty(userVisit, party))); 220 } 221 222 if(includePartyTrainingClasses) { 223 employeeTransfer.setPartyTrainingClasses(new ListWrapper<>(trainingControl.getPartyTrainingClassTransfersByParty(userVisit, party))); 224 } 225 226 if(includePartySkills) { 227 employeeTransfer.setPartySkills(new ListWrapper<>(employeeControl.getPartySkillTransfersByParty(userVisit, party))); 228 } 229 } 230 231 return employeeTransfer; 232 } 233 234}