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.user.server.control.UserControl; 022import com.echothree.model.control.warehouse.server.control.WarehouseControl; 023import com.echothree.model.data.warehouse.server.entity.LocationNameElement; 024import com.echothree.model.data.warehouse.server.entity.LocationNameElementDetail; 025import com.echothree.util.server.persistence.Session; 026import graphql.annotations.annotationTypes.GraphQLDescription; 027import graphql.annotations.annotationTypes.GraphQLField; 028import graphql.annotations.annotationTypes.GraphQLName; 029import graphql.annotations.annotationTypes.GraphQLNonNull; 030import graphql.schema.DataFetchingEnvironment; 031 032@GraphQLDescription("location type object") 033@GraphQLName("LocationNameElement") 034public class LocationNameElementObject 035 extends BaseEntityInstanceObject { 036 037 private final LocationNameElement locationNameElement; // Always Present 038 039 public LocationNameElementObject(LocationNameElement locationNameElement) { 040 super(locationNameElement.getPrimaryKey()); 041 042 this.locationNameElement = locationNameElement; 043 } 044 045 private LocationNameElementDetail locationNameElementDetail; // Optional, use getLocationNameElementDetail() 046 047 private LocationNameElementDetail getLocationNameElementDetail() { 048 if(locationNameElementDetail == null) { 049 locationNameElementDetail = locationNameElement.getLastDetail(); 050 } 051 052 return locationNameElementDetail; 053 } 054 055 @GraphQLField 056 @GraphQLDescription("location type") 057 public LocationTypeObject getLocationType(final DataFetchingEnvironment env) { 058 return WarehouseSecurityUtils.getHasLocationTypeAccess(env) ? 059 new LocationTypeObject(getLocationNameElementDetail().getLocationType()) : null; 060 } 061 062 @GraphQLField 063 @GraphQLDescription("location type name") 064 @GraphQLNonNull 065 public String getLocationNameElementName() { 066 return getLocationNameElementDetail().getLocationNameElementName(); 067 } 068 069 @GraphQLField 070 @GraphQLDescription("offset") 071 @GraphQLNonNull 072 public int getOffset() { 073 return getLocationNameElementDetail().getOffset(); 074 } 075 076 @GraphQLField 077 @GraphQLDescription("velocity") 078 @GraphQLNonNull 079 public int getLength() { 080 return getLocationNameElementDetail().getLength(); 081 } 082 083 @GraphQLField 084 @GraphQLDescription("validation pattern") 085 public String getValidationPattern() { 086 return getLocationNameElementDetail().getValidationPattern(); 087 } 088 089 @GraphQLField 090 @GraphQLDescription("description") 091 @GraphQLNonNull 092 public String getDescription(final DataFetchingEnvironment env) { 093 var warehouseControl = Session.getModelController(WarehouseControl.class); 094 var userControl = Session.getModelController(UserControl.class); 095 096 return warehouseControl.getBestLocationNameElementDescription(locationNameElement, userControl.getPreferredLanguageFromUserVisit(BaseGraphQl.getUserVisit(env))); 097 } 098 099}