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.graphql; 018 019import com.echothree.model.control.graphql.server.graphql.BaseEntityInstanceObject; 020import com.echothree.model.control.graphql.server.util.BaseGraphQl; 021import com.echothree.model.control.inventory.server.graphql.InventoryLocationGroupObject; 022import com.echothree.model.control.inventory.server.graphql.InventorySecurityUtils; 023import com.echothree.model.control.item.common.workflow.ItemStatusConstants; 024import com.echothree.model.control.user.server.control.UserControl; 025import com.echothree.model.control.warehouse.common.workflow.LocationStatusConstants; 026import com.echothree.model.control.warehouse.server.control.WarehouseControl; 027import com.echothree.model.control.workflow.server.graphql.WorkflowEntityStatusObject; 028import com.echothree.model.data.warehouse.server.entity.Location; 029import com.echothree.model.data.warehouse.server.entity.LocationDetail; 030import com.echothree.util.server.persistence.Session; 031import graphql.annotations.annotationTypes.GraphQLDescription; 032import graphql.annotations.annotationTypes.GraphQLField; 033import graphql.annotations.annotationTypes.GraphQLName; 034import graphql.annotations.annotationTypes.GraphQLNonNull; 035import graphql.schema.DataFetchingEnvironment; 036 037@GraphQLDescription("location type object") 038@GraphQLName("Location") 039public class LocationObject 040 extends BaseEntityInstanceObject { 041 042 private final Location location; // Always Present 043 044 public LocationObject(Location location) { 045 super(location.getPrimaryKey()); 046 047 this.location = location; 048 } 049 050 private LocationDetail locationDetail; // Optional, use getLocationDetail() 051 052 private LocationDetail getLocationDetail() { 053 if(locationDetail == null) { 054 locationDetail = location.getLastDetail(); 055 } 056 057 return locationDetail; 058 } 059 060 @GraphQLField 061 @GraphQLDescription("warehouse") 062 public WarehouseObject getWarehouse(final DataFetchingEnvironment env) { 063 return WarehouseSecurityUtils.getHasWarehouseAccess(env) ? 064 new WarehouseObject(getLocationDetail().getWarehouseParty()) : null; 065 } 066 067 @GraphQLField 068 @GraphQLDescription("location name") 069 @GraphQLNonNull 070 public String getLocationName() { 071 return getLocationDetail().getLocationName(); 072 } 073 074 @GraphQLField 075 @GraphQLDescription("location type") 076 public LocationTypeObject getLocationType(final DataFetchingEnvironment env) { 077 return WarehouseSecurityUtils.getHasLocationTypeAccess(env) ? 078 new LocationTypeObject(getLocationDetail().getLocationType()) : null; 079 } 080 081 @GraphQLField 082 @GraphQLDescription("location use type") 083 public LocationUseTypeObject getLocationUseType(final DataFetchingEnvironment env) { 084 return WarehouseSecurityUtils.getHasLocationUseTypeAccess(env) ? 085 new LocationUseTypeObject(getLocationDetail().getLocationUseType()) : null; 086 } 087 088 @GraphQLField 089 @GraphQLDescription("velocity") 090 @GraphQLNonNull 091 public int getVelocity() { 092 return getLocationDetail().getVelocity(); 093 } 094 095 @GraphQLField 096 @GraphQLDescription("inventory location group") 097 public InventoryLocationGroupObject getInventoryLocationGroup(final DataFetchingEnvironment env) { 098 return InventorySecurityUtils.getHasInventoryLocationGroupAccess(env) ? 099 new InventoryLocationGroupObject(getLocationDetail().getInventoryLocationGroup()) : null; 100 } 101 102 @GraphQLField 103 @GraphQLDescription("description") 104 @GraphQLNonNull 105 public String getDescription(final DataFetchingEnvironment env) { 106 var warehouseControl = Session.getModelController(WarehouseControl.class); 107 var userControl = Session.getModelController(UserControl.class); 108 109 return warehouseControl.getBestLocationDescription(location, userControl.getPreferredLanguageFromUserVisit(BaseGraphQl.getUserVisit(env))); 110 } 111 112 @GraphQLField 113 @GraphQLDescription("location status") 114 public WorkflowEntityStatusObject getLocationStatus(final DataFetchingEnvironment env) { 115 return getWorkflowEntityStatusObject(env, LocationStatusConstants.Workflow_LOCATION_STATUS); 116 } 117 118}