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.server.control.ContactListControl; 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.control.workflow.server.graphql.WorkflowEntranceObject; 024import com.echothree.model.control.workflow.server.graphql.WorkflowSecurityUtils; 025import com.echothree.model.data.contactlist.server.entity.ContactList; 026import com.echothree.model.data.contactlist.server.entity.ContactListDetail; 027import com.echothree.util.server.persistence.Session; 028import graphql.annotations.annotationTypes.GraphQLDescription; 029import graphql.annotations.annotationTypes.GraphQLField; 030import graphql.annotations.annotationTypes.GraphQLName; 031import graphql.annotations.annotationTypes.GraphQLNonNull; 032import graphql.schema.DataFetchingEnvironment; 033 034@GraphQLDescription("contact list object") 035@GraphQLName("ContactList") 036public class ContactListObject 037 extends BaseEntityInstanceObject { 038 039 private final ContactList contactList; // Always Present 040 041 public ContactListObject(ContactList contactList) { 042 super(contactList.getPrimaryKey()); 043 044 this.contactList = contactList; 045 } 046 047 private ContactListDetail contactListDetail; // Optional, use getContactListDetail() 048 049 private ContactListDetail getContactListDetail() { 050 if(contactListDetail == null) { 051 contactListDetail = contactList.getLastDetail(); 052 } 053 054 return contactListDetail; 055 } 056 057 @GraphQLField 058 @GraphQLDescription("contact list name") 059 @GraphQLNonNull 060 public String getContactListName() { 061 return getContactListDetail().getContactListName(); 062 } 063 064 @GraphQLField 065 @GraphQLDescription("contact list group") 066 public ContactListGroupObject getContactListGroup(final DataFetchingEnvironment env) { 067 var contactListGroup = getContactListDetail().getContactListGroup(); 068 069 return ContactListSecurityUtils.getHasContactListGroupAccess(env) ? new ContactListGroupObject(contactListGroup) : null; 070 } 071 072 @GraphQLField 073 @GraphQLDescription("contact list type") 074 public ContactListTypeObject getContactListType(final DataFetchingEnvironment env) { 075 var contactListType = getContactListDetail().getContactListType(); 076 077 return ContactListSecurityUtils.getHasContactListTypeAccess(env) ? new ContactListTypeObject(contactListType) : null; 078 } 079 080 @GraphQLField 081 @GraphQLDescription("contact list frequency") 082 public ContactListFrequencyObject getContactListFrequency(final DataFetchingEnvironment env) { 083 var contactListFrequency = getContactListDetail().getContactListFrequency(); 084 085 return contactListFrequency == null ? null : (ContactListSecurityUtils.getHasContactListFrequencyAccess(env) ? new ContactListFrequencyObject(contactListFrequency) : null); 086 } 087 088 @GraphQLField 089 @GraphQLDescription("default party contact list status") 090 public WorkflowEntranceObject getDefaultPartyContactListStatus(final DataFetchingEnvironment env) { 091 var defaultPartyContactListStatus = getContactListDetail().getDefaultPartyContactListStatus(); 092 093 return WorkflowSecurityUtils.getHasWorkflowEntranceAccess(env) ? new WorkflowEntranceObject(defaultPartyContactListStatus) : null; 094 } 095 096 @GraphQLField 097 @GraphQLDescription("is default") 098 @GraphQLNonNull 099 public boolean getIsDefault() { 100 return getContactListDetail().getIsDefault(); 101 } 102 103 @GraphQLField 104 @GraphQLDescription("sort order") 105 @GraphQLNonNull 106 public int getSortOrder() { 107 return getContactListDetail().getSortOrder(); 108 } 109 110 @GraphQLField 111 @GraphQLDescription("description") 112 @GraphQLNonNull 113 public String getDescription(final DataFetchingEnvironment env) { 114 var contactListControl = Session.getModelController(ContactListControl.class); 115 var userControl = Session.getModelController(UserControl.class); 116 117 return contactListControl.getBestContactListDescription(contactList, userControl.getPreferredLanguageFromUserVisit(BaseGraphQl.getUserVisit(env))); 118 } 119 120}