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.warehouse.server.transfer; 018 019import com.echothree.model.control.core.server.control.EntityInstanceControl; 020import com.echothree.model.control.inventory.server.control.InventoryControl; 021import com.echothree.model.control.warehouse.common.WarehouseOptions; 022import com.echothree.model.control.warehouse.common.transfer.LocationTransfer; 023import com.echothree.model.control.warehouse.common.workflow.LocationStatusConstants; 024import com.echothree.model.control.warehouse.server.control.LocationUseTypeControl; 025import com.echothree.model.control.warehouse.server.control.WarehouseControl; 026import com.echothree.model.control.workflow.server.control.WorkflowControl; 027import com.echothree.model.data.user.server.entity.UserVisit; 028import com.echothree.model.data.warehouse.server.entity.Location; 029import com.echothree.util.common.transfer.ListWrapper; 030import com.echothree.util.server.persistence.Session; 031import javax.enterprise.context.RequestScoped; 032 033@RequestScoped 034public class LocationTransferCache 035 extends BaseWarehouseTransferCache<Location, LocationTransfer> { 036 037 EntityInstanceControl entityInstanceControl = Session.getModelController(EntityInstanceControl.class); 038 InventoryControl inventoryControl = Session.getModelController(InventoryControl.class); 039 LocationUseTypeControl locationUseTypeControl = Session.getModelController(LocationUseTypeControl.class); 040 WarehouseControl warehouseControl = Session.getModelController(WarehouseControl.class); 041 WorkflowControl workflowControl = Session.getModelController(WorkflowControl.class); 042 043 boolean includeCapacities; 044 boolean includeVolume; 045 046 /** Creates a new instance of LocationTransferCache */ 047 protected LocationTransferCache() { 048 super(); 049 050 var options = session.getOptions(); 051 if(options != null) { 052 includeCapacities = options.contains(WarehouseOptions.LocationIncludeCapacities); 053 includeVolume = options.contains(WarehouseOptions.LocationIncludeVolume); 054 setIncludeEntityAttributeGroups(options.contains(WarehouseOptions.LocationIncludeEntityAttributeGroups)); 055 setIncludeTagScopes(options.contains(WarehouseOptions.LocationIncludeTagScopes)); 056 } 057 058 setIncludeEntityInstance(true); 059 } 060 061 public LocationTransfer getLocationTransfer(UserVisit userVisit, Location location) { 062 var locationTransfer = get(location); 063 064 if(locationTransfer == null) { 065 var locationDetail = location.getLastDetail(); 066 var warehouse = warehouseControl.getWarehouse(locationDetail.getWarehouseParty()); 067 var warehouseTransfer = warehouseControl.getWarehouseTransfer(userVisit, warehouse); 068 var locationName = locationDetail.getLocationName(); 069 var locationTypeTransfer = warehouseControl.getLocationTypeTransfer(userVisit, locationDetail.getLocationType()); 070 var locationUseTypeTransfer = locationUseTypeControl.getLocationUseTypeTransfer(userVisit, locationDetail.getLocationUseType()); 071 var velocity = locationDetail.getVelocity(); 072 var inventoryLocationGroup = inventoryControl.getInventoryLocationGroupTransfer(userVisit, locationDetail.getInventoryLocationGroup()); 073 var description = warehouseControl.getBestLocationDescription(location, getLanguage(userVisit)); 074 075 var entityInstance = entityInstanceControl.getEntityInstanceByBasePK(location.getPrimaryKey()); 076 var locationStatusTransfer = workflowControl.getWorkflowEntityStatusTransferByEntityInstanceUsingNames(userVisit, 077 LocationStatusConstants.Workflow_LOCATION_STATUS, entityInstance); 078 079 locationTransfer = new LocationTransfer(warehouseTransfer, locationName, locationTypeTransfer, locationUseTypeTransfer, 080 velocity, inventoryLocationGroup, description, locationStatusTransfer); 081 put(userVisit, location, locationTransfer); 082 083 if(includeCapacities) { 084 locationTransfer.setLocationCapacities(new ListWrapper<>(warehouseControl.getLocationCapacityTransfersByLocation(userVisit, location))); 085 } 086 087 if(includeVolume) { 088 var locationVolume = warehouseControl.getLocationVolume(location); 089 090 if(locationVolume != null) { 091 locationTransfer.setLocationVolume(warehouseControl.getLocationVolumeTransfer(userVisit, locationVolume)); 092 } 093 } 094 } 095 096 return locationTransfer; 097 } 098 099}