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.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.common.workflow.InventoryLocationGroupStatusConstants; 022import com.echothree.model.control.inventory.server.control.InventoryControl; 023import com.echothree.model.control.user.server.control.UserControl; 024import com.echothree.model.control.warehouse.server.graphql.WarehouseObject; 025import com.echothree.model.control.warehouse.server.graphql.WarehouseSecurityUtils; 026import com.echothree.model.control.workflow.server.graphql.WorkflowEntityStatusObject; 027import com.echothree.model.data.inventory.server.entity.InventoryLocationGroup; 028import com.echothree.model.data.inventory.server.entity.InventoryLocationGroupDetail; 029import com.echothree.util.server.persistence.Session; 030import graphql.annotations.annotationTypes.GraphQLDescription; 031import graphql.annotations.annotationTypes.GraphQLField; 032import graphql.annotations.annotationTypes.GraphQLName; 033import graphql.annotations.annotationTypes.GraphQLNonNull; 034import graphql.schema.DataFetchingEnvironment; 035 036@GraphQLDescription("inventory location group object") 037@GraphQLName("InventoryLocationGroup") 038public class InventoryLocationGroupObject 039 extends BaseEntityInstanceObject { 040 041 private final InventoryLocationGroup inventoryLocationGroup; // Always Present 042 043 public InventoryLocationGroupObject(InventoryLocationGroup inventoryLocationGroup) { 044 super(inventoryLocationGroup.getPrimaryKey()); 045 046 this.inventoryLocationGroup = inventoryLocationGroup; 047 } 048 049 private InventoryLocationGroupDetail inventoryLocationGroupDetail; // Optional, use getInventoryLocationGroupDetail() 050 051 private InventoryLocationGroupDetail getInventoryLocationGroupDetail() { 052 if(inventoryLocationGroupDetail == null) { 053 inventoryLocationGroupDetail = inventoryLocationGroup.getLastDetail(); 054 } 055 056 return inventoryLocationGroupDetail; 057 } 058 059 @GraphQLField 060 @GraphQLDescription("warehouse") 061 public WarehouseObject getWarehouse(final DataFetchingEnvironment env) { 062 return WarehouseSecurityUtils.getHasWarehouseAccess(env) ? 063 new WarehouseObject(getInventoryLocationGroupDetail().getWarehouseParty()) : null; 064 } 065 066 @GraphQLField 067 @GraphQLDescription("inventory location group name") 068 @GraphQLNonNull 069 public String getInventoryLocationGroupName() { 070 return getInventoryLocationGroupDetail().getInventoryLocationGroupName(); 071 } 072 073 @GraphQLField 074 @GraphQLDescription("is default") 075 @GraphQLNonNull 076 public boolean getIsDefault() { 077 return getInventoryLocationGroupDetail().getIsDefault(); 078 } 079 080 @GraphQLField 081 @GraphQLDescription("sort order") 082 @GraphQLNonNull 083 public int getSortOrder() { 084 return getInventoryLocationGroupDetail().getSortOrder(); 085 } 086 087 @GraphQLField 088 @GraphQLDescription("description") 089 @GraphQLNonNull 090 public String getDescription(final DataFetchingEnvironment env) { 091 var inventoryControl = Session.getModelController(InventoryControl.class); 092 var userControl = Session.getModelController(UserControl.class); 093 094 return inventoryControl.getBestInventoryLocationGroupDescription(inventoryLocationGroup, userControl.getPreferredLanguageFromUserVisit(BaseGraphQl.getUserVisit(env))); 095 } 096 097 @GraphQLField 098 @GraphQLDescription("inventory location group status") 099 public WorkflowEntityStatusObject getInventoryLocationGroupStatus(final DataFetchingEnvironment env) { 100 return getWorkflowEntityStatusObject(env, InventoryLocationGroupStatusConstants.Workflow_INVENTORY_LOCATION_GROUP_STATUS); 101 } 102 103}