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.item.server.graphql; 018 019import com.echothree.model.control.graphql.server.graphql.BaseEntityInstanceObject; 020import com.echothree.model.data.item.server.entity.RelatedItem; 021import com.echothree.model.data.item.server.entity.RelatedItemDetail; 022import graphql.annotations.annotationTypes.GraphQLDescription; 023import graphql.annotations.annotationTypes.GraphQLField; 024import graphql.annotations.annotationTypes.GraphQLName; 025import graphql.annotations.annotationTypes.GraphQLNonNull; 026import graphql.schema.DataFetchingEnvironment; 027 028@GraphQLDescription("related item object") 029@GraphQLName("RelatedItem") 030public class RelatedItemObject 031 extends BaseEntityInstanceObject { 032 033 private final RelatedItem relatedItem; // Always Present 034 035 public RelatedItemObject(RelatedItem relatedItem) { 036 super(relatedItem.getPrimaryKey()); 037 038 this.relatedItem = relatedItem; 039 } 040 041 private RelatedItemDetail relatedItemDetail; // Optional, use getRelatedItemTypeDetail() 042 043 private RelatedItemDetail getRelatedItemDetail() { 044 if(relatedItemDetail == null) { 045 relatedItemDetail = relatedItem.getLastDetail(); 046 } 047 048 return relatedItemDetail; 049 } 050 051 @GraphQLField 052 @GraphQLDescription("related item type") 053 public RelatedItemTypeObject getRelatedItemType(final DataFetchingEnvironment env) { 054 return ItemSecurityUtils.getHasItemAliasTypeAccess(env) ? new RelatedItemTypeObject(getRelatedItemDetail().getRelatedItemType(), null) : null; 055 } 056 057 @GraphQLField 058 @GraphQLDescription("from item") 059 public ItemObject getFromItem(final DataFetchingEnvironment env) { 060 return ItemSecurityUtils.getHasItemAccess(env) ? new ItemObject(getRelatedItemDetail().getFromItem()) : null; 061 } 062 063 @GraphQLField 064 @GraphQLDescription("to item") 065 public ItemObject getToItem(final DataFetchingEnvironment env) { 066 return ItemSecurityUtils.getHasItemAccess(env) ? new ItemObject(getRelatedItemDetail().getToItem()) : null; 067 } 068 069 @GraphQLField 070 @GraphQLDescription("sort order") 071 @GraphQLNonNull 072 public int getSortOrder() { 073 return getRelatedItemDetail().getSortOrder(); 074 } 075 076}