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.party.server.graphql;
018
019import com.echothree.model.control.graphql.server.graphql.BaseEntityInstanceObject;
020import com.echothree.model.data.party.server.entity.PersonalTitle;
021import com.echothree.model.data.party.server.entity.PersonalTitleDetail;
022import graphql.annotations.annotationTypes.GraphQLDescription;
023import graphql.annotations.annotationTypes.GraphQLField;
024import graphql.annotations.annotationTypes.GraphQLName;
025import graphql.annotations.annotationTypes.GraphQLNonNull;
026
027@GraphQLDescription("personal title object")
028@GraphQLName("PersonalTitle")
029public class PersonalTitleObject
030        extends BaseEntityInstanceObject {
031    
032    private final PersonalTitle personalTitle; // Always Present
033    
034    public PersonalTitleObject(PersonalTitle personalTitle) {
035        super(personalTitle.getPrimaryKey());
036
037        this.personalTitle = personalTitle;
038    }
039
040    private PersonalTitleDetail personalTitleDetail; // Optional, use getPersonalTitleDetail()
041    
042    private PersonalTitleDetail getPersonalTitleDetail() {
043        if(personalTitleDetail == null) {
044            personalTitleDetail = personalTitle.getLastDetail();
045        }
046        
047        return personalTitleDetail;
048    }
049
050    @GraphQLField
051    @GraphQLDescription("personal title id")
052    @GraphQLNonNull
053    public String getPersonalTitleId() {
054        return Long.toString(personalTitle.getPrimaryKey().getEntityId());
055    }
056    
057    @GraphQLField
058    @GraphQLDescription("description")
059    @GraphQLNonNull
060    public String getDescription() {
061        return getPersonalTitleDetail().getDescription();
062    }
063
064    @GraphQLField
065    @GraphQLDescription("is default")
066    @GraphQLNonNull
067    public boolean getIsDefault() {
068        return getPersonalTitleDetail().getIsDefault();
069    }
070    
071    @GraphQLField
072    @GraphQLDescription("sort order")
073    @GraphQLNonNull
074    public int getSortOrder() {
075        return getPersonalTitleDetail().getSortOrder();
076    }
077
078}