001// -------------------------------------------------------------------------------- 002// Copyright 2002-2024 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.core.server.graphql; 018 019import com.echothree.model.control.core.server.control.CoreControl; 020import com.echothree.model.control.graphql.server.graphql.BaseEntityInstanceObject; 021import com.echothree.model.control.graphql.server.util.BaseGraphQl; 022import com.echothree.model.control.user.server.control.UserControl; 023import com.echothree.model.data.core.server.entity.EntityLongRange; 024import com.echothree.model.data.core.server.entity.EntityLongRangeDetail; 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("entity long range object") 033@GraphQLName("EntityLongRange") 034public class EntityLongRangeObject 035 extends BaseEntityInstanceObject { 036 037 private final EntityLongRange entityLongRange; // Always Present 038 039 public EntityLongRangeObject(EntityLongRange entityLongRange) { 040 super(entityLongRange.getPrimaryKey()); 041 042 this.entityLongRange = entityLongRange; 043 } 044 045 private EntityLongRangeDetail entityLongRangeDetail; // Optional, use getEntityLongRangeDetail() 046 047 private EntityLongRangeDetail getEntityLongRangeDetail() { 048 if(entityLongRangeDetail == null) { 049 entityLongRangeDetail = entityLongRange.getLastDetail(); 050 } 051 052 return entityLongRangeDetail; 053 } 054 055 @GraphQLField 056 @GraphQLDescription("entity attribute") 057 public EntityAttributeObject getEntityAttribute(final DataFetchingEnvironment env) { 058 return CoreSecurityUtils.getHasEntityAttributeAccess(env) ? new EntityAttributeObject(getEntityLongRangeDetail().getEntityAttribute(), null) : null; 059 } 060 061 @GraphQLField 062 @GraphQLDescription("entity long range name") 063 @GraphQLNonNull 064 public String getEntityLongRangeName() { 065 return getEntityLongRangeDetail().getEntityLongRangeName(); 066 } 067 068 @GraphQLField 069 @GraphQLDescription("minimum long value") 070 public Long getMinimumLongValue() { 071 return getEntityLongRangeDetail().getMinimumLongValue(); 072 } 073 074 @GraphQLField 075 @GraphQLDescription("maximum long value") 076 public Long getMaximumLongValue() { 077 return getEntityLongRangeDetail().getMaximumLongValue(); 078 } 079 080 @GraphQLField 081 @GraphQLDescription("is default") 082 @GraphQLNonNull 083 public boolean getIsDefault() { 084 return getEntityLongRangeDetail().getIsDefault(); 085 } 086 087 @GraphQLField 088 @GraphQLDescription("sort order") 089 @GraphQLNonNull 090 public int getSortOrder() { 091 return getEntityLongRangeDetail().getSortOrder(); 092 } 093 094 @GraphQLField 095 @GraphQLDescription("description") 096 @GraphQLNonNull 097 public String getDescription(final DataFetchingEnvironment env) { 098 var coreControl = Session.getModelController(CoreControl.class); 099 var userControl = Session.getModelController(UserControl.class); 100 101 return coreControl.getBestEntityLongRangeDescription(entityLongRange, userControl.getPreferredLanguageFromUserVisit(BaseGraphQl.getUserVisit(env))); 102 } 103 104}