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.order.server.graphql; 018 019import com.echothree.model.control.accounting.server.graphql.AccountingSecurityUtils; 020import com.echothree.model.control.accounting.server.graphql.CurrencyObject; 021import com.echothree.model.control.cancellationpolicy.server.graphql.CancellationPolicyObject; 022import com.echothree.model.control.cancellationpolicy.server.graphql.CancellationPolicySecurityUtils; 023import com.echothree.model.control.graphql.server.graphql.BaseEntityInstanceObject; 024import com.echothree.model.control.returnpolicy.server.graphql.ReturnPolicyObject; 025import com.echothree.model.control.returnpolicy.server.graphql.ReturnPolicySecurityUtils; 026import com.echothree.model.control.shipment.server.graphql.FreeOnBoardObject; 027import com.echothree.model.control.shipment.server.graphql.ShipmentSecurityUtils; 028import com.echothree.model.control.term.server.graphql.TermObject; 029import com.echothree.model.control.term.server.graphql.TermSecurityUtils; 030import com.echothree.model.data.order.server.entity.Order; 031import com.echothree.model.data.order.server.entity.OrderDetail; 032import graphql.annotations.annotationTypes.GraphQLDescription; 033import graphql.annotations.annotationTypes.GraphQLField; 034import graphql.annotations.annotationTypes.GraphQLNonNull; 035import graphql.schema.DataFetchingEnvironment; 036 037public abstract class BaseOrderObject 038 extends BaseEntityInstanceObject { 039 040 private final Order order; // Always Present 041 042 protected BaseOrderObject(final Order order) { 043 super(order.getPrimaryKey()); 044 045 this.order = order; 046 } 047 048 private OrderDetail orderDetail; // Optional, use getOrderDetail() 049 050 private OrderDetail getOrderDetail() { 051 if(orderDetail == null) { 052 orderDetail = order.getLastDetail(); 053 } 054 055 return orderDetail; 056 } 057 058 @GraphQLField 059 @GraphQLDescription("order type") 060 @GraphQLNonNull 061 public OrderTypeObject getOrderType(final DataFetchingEnvironment env) { 062 return OrderSecurityUtils.getHasOrderTypeAccess(env) ? new OrderTypeObject(getOrderDetail().getOrderType()) : null; 063 } 064 065 @GraphQLField 066 @GraphQLDescription("order type name") 067 @GraphQLNonNull 068 public String getOrderName() { 069 return getOrderDetail().getOrderName(); 070 } 071 072 @GraphQLField 073 @GraphQLDescription("order priority") 074 public OrderPriorityObject getOrderPriority(final DataFetchingEnvironment env) { 075 var orderPriority = getOrderDetail().getOrderPriority(); 076 077 return orderPriority == null ? null : OrderSecurityUtils.getHasOrderPriorityAccess(env) ? 078 new OrderPriorityObject(orderPriority) : null; 079 } 080 081 @GraphQLField 082 @GraphQLDescription("currency") 083 @GraphQLNonNull 084 public CurrencyObject getCurrency(final DataFetchingEnvironment env) { 085 return AccountingSecurityUtils.getHasCurrencyAccess(env) ? 086 new CurrencyObject(getOrderDetail().getCurrency()) : null; 087 } 088 089 @GraphQLField 090 @GraphQLDescription("hold until complete") 091 public Boolean getHoldUntilComplete() { 092 return getOrderDetail().getHoldUntilComplete(); 093 } 094 095 @GraphQLField 096 @GraphQLDescription("allow backorders") 097 public Boolean getAllowBackorders() { 098 return getOrderDetail().getAllowBackorders(); 099 } 100 101 @GraphQLField 102 @GraphQLDescription("allow substitutions") 103 public Boolean getAllowSubstitutions() { 104 return getOrderDetail().getAllowSubstitutions(); 105 } 106 107 @GraphQLField 108 @GraphQLDescription("allow combining shipments") 109 public Boolean getAllowCombiningShipments() { 110 return getOrderDetail().getAllowCombiningShipments(); 111 } 112 113 @GraphQLField 114 @GraphQLDescription("term") 115 public TermObject getTerm(final DataFetchingEnvironment env) { 116 var term = getOrderDetail().getTerm(); 117 118 return term == null ? null : (TermSecurityUtils.getHasTermAccess(env) ? 119 new TermObject(getOrderDetail().getTerm()) : null); 120 } 121 122 @GraphQLField 123 @GraphQLDescription("freeOnBoard") 124 public FreeOnBoardObject getFreeOnBoard(final DataFetchingEnvironment env) { 125 var freeOnBoard = getOrderDetail().getFreeOnBoard(); 126 127 return freeOnBoard == null ? null : ShipmentSecurityUtils.getHasFreeOnBoardAccess(env) ? 128 new FreeOnBoardObject(getOrderDetail().getFreeOnBoard()) : null; 129 } 130 131 @GraphQLField 132 @GraphQLDescription("reference") 133 public String getReference() { 134 return getOrderDetail().getReference(); 135 } 136 137 @GraphQLField 138 @GraphQLDescription("description") 139 public String getDescription() { 140 return getOrderDetail().getDescription(); 141 } 142 143 @GraphQLField 144 @GraphQLDescription("cancellation policy") 145 public CancellationPolicyObject getCancellationPolicy(final DataFetchingEnvironment env) { 146 var cancellationPolicy = getOrderDetail().getCancellationPolicy(); 147 148 return cancellationPolicy == null ? null : CancellationPolicySecurityUtils.getHasCancellationPolicyAccess(env) ? 149 new CancellationPolicyObject(cancellationPolicy) : null; 150 } 151 152 @GraphQLField 153 @GraphQLDescription("return policy") 154 public ReturnPolicyObject getReturnPolicy(final DataFetchingEnvironment env) { 155 var returnPolicy = getOrderDetail().getReturnPolicy(); 156 157 return returnPolicy == null ? null : ReturnPolicySecurityUtils.getHasReturnPolicyAccess(env) ? 158 new ReturnPolicyObject(returnPolicy) : null; 159 } 160 161 @GraphQLField 162 @GraphQLDescription("taxable") 163 public Boolean getTaxable() { 164 return getOrderDetail().getTaxable(); 165 } 166 167}