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.customer.server.graphql; 018 019import com.echothree.model.control.accounting.server.graphql.AccountingSecurityUtils; 020import com.echothree.model.control.accounting.server.graphql.GlAccountObject; 021import com.echothree.model.control.cancellationpolicy.server.graphql.CancellationPolicyObject; 022import com.echothree.model.control.cancellationpolicy.server.graphql.CancellationPolicySecurityUtils; 023import com.echothree.model.control.customer.server.control.CustomerControl; 024import com.echothree.model.control.offer.server.graphql.OfferSecurityUtils; 025import com.echothree.model.control.offer.server.graphql.OfferUseObject; 026import com.echothree.model.control.party.server.graphql.BasePartyObject; 027import com.echothree.model.control.returnpolicy.server.graphql.ReturnPolicyObject; 028import com.echothree.model.control.returnpolicy.server.graphql.ReturnPolicySecurityUtils; 029import com.echothree.model.data.customer.server.entity.Customer; 030import com.echothree.model.data.party.server.entity.Party; 031import com.echothree.util.server.persistence.Session; 032import graphql.annotations.annotationTypes.GraphQLDescription; 033import graphql.annotations.annotationTypes.GraphQLField; 034import graphql.annotations.annotationTypes.GraphQLName; 035import graphql.annotations.annotationTypes.GraphQLNonNull; 036import graphql.schema.DataFetchingEnvironment; 037 038@GraphQLDescription("customer object") 039@GraphQLName("Customer") 040public class CustomerObject 041 extends BasePartyObject { 042 043 public CustomerObject(Party party) { 044 super(party); 045 } 046 047 public CustomerObject(Customer customer) { 048 super(customer.getParty()); 049 050 this.customer = customer; 051 } 052 053 private Customer customer; // Optional, use getCustomer() 054 055 protected Customer getCustomer() { 056 if(customer == null) { 057 var customerControl = Session.getModelController(CustomerControl.class); 058 059 customer = customerControl.getCustomer(party); 060 } 061 062 return customer; 063 } 064 065 @GraphQLField 066 @GraphQLDescription("customer name") 067 @GraphQLNonNull 068 public String getCustomerName() { 069 return getCustomer().getCustomerName(); 070 } 071 072 @GraphQLField 073 @GraphQLDescription("customer type") 074 @GraphQLNonNull 075 public CustomerTypeObject getCustomerType(final DataFetchingEnvironment env) { 076 return CustomerSecurityUtils.getHasCustomerTypeAccess(env) ? 077 new CustomerTypeObject(getCustomer().getCustomerType()) : null; 078 } 079 080 @GraphQLField 081 @GraphQLDescription("initial offer use") 082 @GraphQLNonNull 083 public OfferUseObject getInitialOfferUse(final DataFetchingEnvironment env) { 084 return OfferSecurityUtils.getHasOfferUseAccess(env) ? 085 new OfferUseObject(getCustomer().getInitialOfferUse()) : null; 086 } 087 088 @GraphQLField 089 @GraphQLDescription("cancellation policy") 090 public CancellationPolicyObject getCancellationPolicy(final DataFetchingEnvironment env) { 091 var cancellationPolicy = getCustomer().getCancellationPolicy(); 092 093 return cancellationPolicy == null ? null : CancellationPolicySecurityUtils.getHasCancellationPolicyAccess(env) ? 094 new CancellationPolicyObject(cancellationPolicy) : null; 095 } 096 097 @GraphQLField 098 @GraphQLDescription("return policy") 099 public ReturnPolicyObject getReturnPolicy(final DataFetchingEnvironment env) { 100 var returnPolicy = getCustomer().getReturnPolicy(); 101 102 return returnPolicy == null ? null : ReturnPolicySecurityUtils.getHasReturnPolicyAccess(env) ? 103 new ReturnPolicyObject(returnPolicy) : null; 104 } 105 106 @GraphQLField 107 @GraphQLDescription("AR GL account") 108 public GlAccountObject getArGlAccount(final DataFetchingEnvironment env) { 109 var arGlAccount = getCustomer().getArGlAccount(); 110 111 return arGlAccount == null ? null : AccountingSecurityUtils.getHasGlAccountAccess(env) ? 112 new GlAccountObject(getCustomer().getArGlAccount()) : null; 113 } 114 115 @GraphQLField 116 @GraphQLDescription("hold until complete") 117 @GraphQLNonNull 118 public boolean getHoldUntilComplete() { 119 return getCustomer().getHoldUntilComplete(); 120 } 121 122 @GraphQLField 123 @GraphQLDescription("allow backorders") 124 @GraphQLNonNull 125 public boolean getAllowBackorders() { 126 return getCustomer().getAllowBackorders(); 127 } 128 129 @GraphQLField 130 @GraphQLDescription("allow substitutions") 131 @GraphQLNonNull 132 public boolean getAllowSubstitutions() { 133 return getCustomer().getAllowSubstitutions(); 134 } 135 136 @GraphQLField 137 @GraphQLDescription("allow combining shipments") 138 @GraphQLNonNull 139 public boolean getAllowCombiningShipments() { 140 return getCustomer().getAllowCombiningShipments(); 141 } 142 143 @GraphQLField 144 @GraphQLDescription("require reference") 145 @GraphQLNonNull 146 public boolean getRequireReference() { 147 return getCustomer().getRequireReference(); 148 } 149 150 @GraphQLField 151 @GraphQLDescription("allow reference duplicates") 152 @GraphQLNonNull 153 public boolean getAllowReferenceDuplicates() { 154 return getCustomer().getAllowReferenceDuplicates(); 155 } 156 157 @GraphQLField 158 @GraphQLDescription("reference validation pattern") 159 public String getReferenceValidationPattern() { 160 return getCustomer().getReferenceValidationPattern(); 161 } 162 163}