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