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.contactlist.server.graphql; 018 019import com.echothree.model.control.contactlist.common.workflow.PartyContactListStatusConstants; 020import com.echothree.model.control.graphql.server.graphql.BaseEntityInstanceObject; 021import com.echothree.model.control.party.server.graphql.PartyObject; 022import com.echothree.model.control.party.server.graphql.PartySecurityUtils; 023import com.echothree.model.control.workflow.server.graphql.WorkflowEntityStatusObject; 024import com.echothree.model.data.contactlist.server.entity.PartyContactList; 025import com.echothree.model.data.contactlist.server.entity.PartyContactListDetail; 026import graphql.annotations.annotationTypes.GraphQLDescription; 027import graphql.annotations.annotationTypes.GraphQLField; 028import graphql.annotations.annotationTypes.GraphQLName; 029import graphql.schema.DataFetchingEnvironment; 030 031@GraphQLDescription("party contact list object") 032@GraphQLName("PartyContactList") 033public class PartyContactListObject 034 extends BaseEntityInstanceObject { 035 036 private final PartyContactList partyContactList; // Always Present 037 038 public PartyContactListObject(PartyContactList partyContactList) { 039 super(partyContactList.getPrimaryKey()); 040 041 this.partyContactList = partyContactList; 042 } 043 044 private PartyContactListDetail partyContactListDetail; // Optional, use getPartyContactListDetail() 045 046 private PartyContactListDetail getPartyContactListDetail() { 047 if(partyContactListDetail == null) { 048 partyContactListDetail = partyContactList.getLastDetail(); 049 } 050 051 return partyContactListDetail; 052 } 053 054 @GraphQLField 055 @GraphQLDescription("party") 056 public PartyObject getParty(final DataFetchingEnvironment env) { 057 var party = getPartyContactListDetail().getParty(); 058 059 return PartySecurityUtils.getHasPartyAccess(env, party) ? new PartyObject(party) : null; 060 } 061 062 @GraphQLField 063 @GraphQLDescription("contact list") 064 public ContactListObject getContactList(final DataFetchingEnvironment env) { 065 var contactList = getPartyContactListDetail().getContactList(); 066 067 return ContactListSecurityUtils.getHasContactListAccess(env) ? new ContactListObject(contactList) : null; 068 } 069 070 @GraphQLField 071 @GraphQLDescription("preferred contact list contact mechanism purpose") 072 public ContactListContactMechanismPurposeObject getPreferredContactListContactMechanismPurpose(final DataFetchingEnvironment env) { 073 var preferredContactListContactMechanismPurpose = getPartyContactListDetail().getPreferredContactListContactMechanismPurpose(); 074 075 return preferredContactListContactMechanismPurpose == null ? null : (ContactListSecurityUtils.getHasContactListContactMechanismPurposeAccess(env) ? new ContactListContactMechanismPurposeObject(preferredContactListContactMechanismPurpose) : null); 076 } 077 078 @GraphQLField 079 @GraphQLDescription("party contact list status") 080 public WorkflowEntityStatusObject getPartyContactListStatus(final DataFetchingEnvironment env) { 081 return getWorkflowEntityStatusObject(env, PartyContactListStatusConstants.Workflow_PARTY_CONTACT_LIST_STATUS); 082 } 083 084}