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.warehouse.server.transfer; 018 019import javax.inject.Inject; 020import com.echothree.model.control.accounting.server.control.AccountingControl; 021import com.echothree.model.control.contact.server.control.ContactControl; 022import com.echothree.model.control.document.server.control.DocumentControl; 023import com.echothree.model.control.party.common.PartyOptions; 024import com.echothree.model.control.party.server.control.PartyControl; 025import com.echothree.model.control.printer.server.control.PrinterControl; 026import com.echothree.model.control.scale.server.control.ScaleControl; 027import com.echothree.model.control.warehouse.common.WarehouseOptions; 028import com.echothree.model.control.warehouse.common.transfer.WarehouseTransfer; 029import com.echothree.model.control.warehouse.server.control.WarehouseControl; 030import com.echothree.model.data.party.server.entity.Party; 031import com.echothree.model.data.user.server.entity.UserVisit; 032import com.echothree.model.data.warehouse.server.entity.Warehouse; 033import com.echothree.util.common.transfer.ListWrapper; 034import javax.enterprise.context.RequestScoped; 035 036@RequestScoped 037public class WarehouseTransferCache 038 extends BaseWarehouseTransferCache<Party, WarehouseTransfer> { 039 040 @Inject 041 AccountingControl accountingControl; 042 043 @Inject 044 ContactControl contactControl; 045 046 @Inject 047 DocumentControl documentControl; 048 049 @Inject 050 PartyControl partyControl; 051 052 @Inject 053 PrinterControl printerControl; 054 055 @Inject 056 ScaleControl scaleControl; 057 058 @Inject 059 WarehouseControl warehouseControl; 060 061 boolean includeLocationsCount; 062 boolean includeLocations; 063 boolean includePartyAliases; 064 boolean includePartyContactMechanisms; 065 boolean includePartyDocuments; 066 boolean includePartyPrinterGroupUses; 067 boolean includePartyScaleUses; 068 069 /** Creates a new instance of WarehouseTransferCache */ 070 protected WarehouseTransferCache() { 071 super(); 072 073 var options = session.getOptions(); 074 if(options != null) { 075 includeLocationsCount = options.contains(WarehouseOptions.WarehouseIncludeLocationsCount); 076 includeLocations = options.contains(WarehouseOptions.WarehouseIncludeLocations); 077 setIncludeUuid(options.contains(PartyOptions.PartyIncludeUuid) || options.contains(WarehouseOptions.WarehouseIncludeUuid)); 078 includePartyAliases = options.contains(PartyOptions.PartyIncludePartyAliases); 079 includePartyContactMechanisms = options.contains(PartyOptions.PartyIncludePartyContactMechanisms); 080 includePartyDocuments = options.contains(PartyOptions.PartyIncludePartyDocuments); 081 includePartyPrinterGroupUses = options.contains(PartyOptions.PartyIncludePartyPrinterGroupUses); 082 includePartyScaleUses = options.contains(PartyOptions.PartyIncludePartyScaleUses); 083 setIncludeEntityAttributeGroups(options.contains(WarehouseOptions.WarehouseIncludeEntityAttributeGroups)); 084 setIncludeTagScopes(options.contains(WarehouseOptions.WarehouseIncludeTagScopes)); 085 } 086 087 setIncludeEntityInstance(true); 088 } 089 090 public WarehouseTransfer getWarehouseTransfer(UserVisit userVisit, Warehouse warehouse) { 091 return getWarehouseTransfer(userVisit, warehouse.getParty()); 092 } 093 094 public WarehouseTransfer getWarehouseTransfer(UserVisit userVisit, Party party) { 095 var warehouseTransfer = get(party); 096 097 if(warehouseTransfer == null) { 098 var partyDetail = party.getLastDetail(); 099 var partyName = partyDetail.getPartyName(); 100 var partyTypeTransfer = partyControl.getPartyTypeTransfer(userVisit, partyDetail.getPartyType()); 101 var preferredLanguage = partyDetail.getPreferredLanguage(); 102 var preferredLanguageTransfer = preferredLanguage == null ? null : partyControl.getLanguageTransfer(userVisit, preferredLanguage); 103 var preferredCurrency = partyDetail.getPreferredCurrency(); 104 var preferredCurrencyTransfer = preferredCurrency == null ? null : accountingControl.getCurrencyTransfer(userVisit, preferredCurrency); 105 var preferredTimeZone = partyDetail.getPreferredTimeZone(); 106 var preferredTimeZoneTransfer = preferredTimeZone == null ? null : partyControl.getTimeZoneTransfer(userVisit, preferredTimeZone); 107 var preferredDateTimeFormat = partyDetail.getPreferredDateTimeFormat(); 108 var preferredDateTimeFormatTransfer = preferredDateTimeFormat == null ? null : partyControl.getDateTimeFormatTransfer(userVisit, preferredDateTimeFormat); 109 var person = partyControl.getPerson(party); 110 var personTransfer = person == null ? null : partyControl.getPersonTransfer(userVisit, person); 111 var partyGroup = partyControl.getPartyGroup(party); 112 var partyGroupTransfer = partyGroup == null ? null : partyControl.getPartyGroupTransfer(userVisit, partyGroup); 113 var warehouse = warehouseControl.getWarehouse(party); 114 var warehouseName = warehouse.getWarehouseName(); 115 var warehouseTypeTransfer = warehouseControl.getWarehouseTypeTransfer(userVisit, warehouse.getWarehouseType()); 116 var isDefault = warehouse.getIsDefault(); 117 var sortOrder = warehouse.getSortOrder(); 118 119 warehouseTransfer = new WarehouseTransfer(partyName, partyTypeTransfer, preferredLanguageTransfer, preferredCurrencyTransfer, 120 preferredTimeZoneTransfer, preferredDateTimeFormatTransfer, personTransfer, partyGroupTransfer, warehouseName, 121 warehouseTypeTransfer, isDefault, sortOrder); 122 put(userVisit, party, warehouseTransfer); 123 124 if(includeLocationsCount) { 125 warehouseTransfer.setLocationsCount(warehouseControl.countLocationsByWarehouseParty(party)); 126 } 127 128 if(includeLocations) { 129 warehouseTransfer.setLocations(new ListWrapper<>(warehouseControl.getLocationTransfersByWarehouseParty(userVisit, party))); 130 } 131 132 if(includePartyAliases) { 133 warehouseTransfer.setPartyAliases(new ListWrapper<>(partyControl.getPartyAliasTransfersByParty(userVisit, party))); 134 } 135 136 if(includePartyContactMechanisms) { 137 warehouseTransfer.setPartyContactMechanisms(new ListWrapper<>(contactControl.getPartyContactMechanismTransfersByParty(userVisit, party))); 138 } 139 140 if(includePartyDocuments) { 141 warehouseTransfer.setPartyDocuments(new ListWrapper<>(documentControl.getPartyDocumentTransfersByParty(userVisit, party))); 142 } 143 144 if(includePartyPrinterGroupUses) { 145 warehouseTransfer.setPartyPrinterGroupUses(new ListWrapper<>(printerControl.getPartyPrinterGroupUseTransfersByParty(userVisit, party))); 146 } 147 148 if(includePartyScaleUses) { 149 warehouseTransfer.setPartyScaleUses(new ListWrapper<>(scaleControl.getPartyScaleUseTransfersByParty(userVisit, party))); 150 } 151 } 152 153 return warehouseTransfer; 154 } 155 156}