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.inventory.server.transfer; 018 019import javax.inject.Inject; 020import com.echothree.model.control.inventory.common.InventoryOptions; 021import com.echothree.model.control.inventory.common.transfer.InventoryLocationGroupTransfer; 022import com.echothree.model.control.inventory.common.workflow.InventoryLocationGroupStatusConstants; 023import com.echothree.model.control.inventory.server.control.InventoryControl; 024import com.echothree.model.control.warehouse.server.control.WarehouseControl; 025import com.echothree.model.control.workflow.server.control.WorkflowControl; 026import com.echothree.model.data.inventory.server.entity.InventoryLocationGroup; 027import com.echothree.model.data.user.server.entity.UserVisit; 028import com.echothree.util.common.transfer.ListWrapper; 029import javax.enterprise.context.RequestScoped; 030 031@RequestScoped 032public class InventoryLocationGroupTransferCache 033 extends BaseInventoryTransferCache<InventoryLocationGroup, InventoryLocationGroupTransfer> { 034 035 @Inject 036 InventoryControl inventoryControl; 037 038 @Inject 039 WarehouseControl warehouseControl; 040 041 @Inject 042 WorkflowControl workflowControl; 043 044 boolean includeCapacities; 045 boolean includeVolume; 046 047 /** Creates a new instance of InventoryLocationGroupTransferCache */ 048 protected InventoryLocationGroupTransferCache() { 049 super(); 050 051 var options = session.getOptions(); 052 if(options != null) { 053 includeCapacities = options.contains(InventoryOptions.InventoryLocationGroupIncludeCapacities); 054 includeVolume = options.contains(InventoryOptions.InventoryLocationGroupIncludeVolume); 055 } 056 057 setIncludeEntityInstance(true); 058 } 059 060 @Override 061 public InventoryLocationGroupTransfer getTransfer(UserVisit userVisit, InventoryLocationGroup inventoryLocationGroup) { 062 var inventoryLocationGroupTransfer = get(inventoryLocationGroup); 063 064 if(inventoryLocationGroupTransfer == null) { 065 066 var inventoryLocationGroupDetail = inventoryLocationGroup.getLastDetail(); 067 var warehouseParty = inventoryLocationGroupDetail.getWarehouseParty(); 068 var warehouse = warehouseControl.getWarehouse(warehouseParty); 069 var warehouseTransfer = warehouseControl.getWarehouseTransfer(userVisit, warehouse); 070 var inventoryLocationGroupName = inventoryLocationGroupDetail.getInventoryLocationGroupName(); 071 var isDefault = inventoryLocationGroupDetail.getIsDefault(); 072 var sortOrder = inventoryLocationGroupDetail.getSortOrder(); 073 var description = inventoryControl.getBestInventoryLocationGroupDescription(inventoryLocationGroup, getLanguage(userVisit)); 074 075 var entityInstance = entityInstanceControl.getEntityInstanceByBasePK(inventoryLocationGroup.getPrimaryKey()); 076 var inventoryLocationGroupStatusTransfer = workflowControl.getWorkflowEntityStatusTransferByEntityInstanceUsingNames(userVisit, 077 InventoryLocationGroupStatusConstants.Workflow_INVENTORY_LOCATION_GROUP_STATUS, entityInstance); 078 079 inventoryLocationGroupTransfer = new InventoryLocationGroupTransfer(warehouseTransfer, inventoryLocationGroupName, isDefault, sortOrder, 080 description, inventoryLocationGroupStatusTransfer); 081 put(userVisit, inventoryLocationGroup, inventoryLocationGroupTransfer); 082 083 if(includeCapacities) { 084 inventoryLocationGroupTransfer.setInventoryLocationGroupCapacities(new ListWrapper<>(inventoryControl.getInventoryLocationGroupCapacityTransfersByInventoryLocationGroup(userVisit, inventoryLocationGroup))); 085 } 086 087 if(includeVolume) { 088 var inventoryLocationGroupVolume = inventoryControl.getInventoryLocationGroupVolume(inventoryLocationGroup); 089 090 if(inventoryLocationGroupVolume != null) { 091 inventoryLocationGroupTransfer.setInventoryLocationGroupVolume(inventoryControl.getInventoryLocationGroupVolumeTransfer(userVisit, inventoryLocationGroupVolume)); 092 } 093 } 094 } 095 096 return inventoryLocationGroupTransfer; 097 } 098 099}