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.vendor.server.graphql; 018 019import com.echothree.model.control.graphql.server.graphql.BaseObject; 020import com.echothree.model.control.graphql.server.graphql.UnitCostObject; 021import com.echothree.model.control.inventory.server.graphql.InventoryConditionObject; 022import com.echothree.model.control.inventory.server.graphql.InventorySecurityUtils; 023import com.echothree.model.control.party.server.control.PartyControl; 024import com.echothree.model.control.uom.server.graphql.UnitOfMeasureTypeObject; 025import com.echothree.model.control.uom.server.graphql.UomSecurityUtils; 026import com.echothree.model.data.vendor.server.entity.VendorItemCost; 027import com.echothree.util.server.persistence.Session; 028import graphql.annotations.annotationTypes.GraphQLDescription; 029import graphql.annotations.annotationTypes.GraphQLField; 030import graphql.annotations.annotationTypes.GraphQLName; 031import graphql.schema.DataFetchingEnvironment; 032 033@GraphQLDescription("vendor item cost object") 034@GraphQLName("VendorItemCost") 035public class VendorItemCostObject 036 extends BaseObject { 037 038 private final VendorItemCost vendorItemCost; // Always Present 039 040 public VendorItemCostObject(VendorItemCost vendorItemCost) { 041 this.vendorItemCost = vendorItemCost; 042 } 043 044 @GraphQLField 045 @GraphQLDescription("vendor item") 046 public VendorItemObject getVendorItem(final DataFetchingEnvironment env) { 047 return VendorSecurityUtils.getHasVendorItemAccess(env) ? new VendorItemObject(vendorItemCost.getVendorItem()) : null; 048 } 049 050 @GraphQLField 051 @GraphQLDescription("inventory condition") 052 public InventoryConditionObject getInventoryCondition(final DataFetchingEnvironment env) { 053 return InventorySecurityUtils.getHasInventoryConditionAccess(env) ? new InventoryConditionObject(vendorItemCost.getInventoryCondition()) : null; 054 } 055 056 @GraphQLField 057 @GraphQLDescription("unit of measure type") 058 public UnitOfMeasureTypeObject getUnitOfMeasureType(final DataFetchingEnvironment env) { 059 return UomSecurityUtils.getHasUnitOfMeasureTypeAccess(env) ? new UnitOfMeasureTypeObject(vendorItemCost.getUnitOfMeasureType()) : null; 060 } 061 062 @GraphQLField 063 @GraphQLDescription("unit cost") 064 public UnitCostObject getUnitCost() { 065 var partyControl = Session.getModelController(PartyControl.class); 066 067 return new UnitCostObject(partyControl.getPreferredCurrency(vendorItemCost.getVendorItem().getLastDetail().getVendorParty()), 068 vendorItemCost.getUnitCost()); 069 } 070 071}