001// --------------------------------------------------------------------------------
002// Copyright 2002-2025 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.inventory.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.graphql.server.graphql.BaseEntityInstanceObject;
022import com.echothree.model.control.graphql.server.graphql.UnitCostObject;
023import com.echothree.model.control.item.server.graphql.ItemObject;
024import com.echothree.model.control.item.server.graphql.ItemSecurityUtils;
025import com.echothree.model.control.party.server.graphql.PartyObject;
026import com.echothree.model.control.party.server.graphql.PartySecurityUtils;
027import com.echothree.model.control.uom.server.graphql.UnitOfMeasureTypeObject;
028import com.echothree.model.control.uom.server.graphql.UomSecurityUtils;
029import com.echothree.model.data.inventory.server.entity.Lot;
030import com.echothree.model.data.inventory.server.entity.LotDetail;
031import graphql.annotations.annotationTypes.GraphQLDescription;
032import graphql.annotations.annotationTypes.GraphQLField;
033import graphql.annotations.annotationTypes.GraphQLName;
034import graphql.annotations.annotationTypes.GraphQLNonNull;
035import graphql.schema.DataFetchingEnvironment;
036
037@GraphQLDescription("lot object")
038@GraphQLName("Lot")
039public class LotObject
040        extends BaseEntityInstanceObject {
041    
042    private final Lot lot; // Always Present
043    
044    public LotObject(Lot lot) {
045        super(lot.getPrimaryKey());
046        
047        this.lot = lot;
048    }
049
050    private LotDetail lotDetail; // Optional, use getLotDetail()
051    
052    private LotDetail getLotDetail() {
053        if(lotDetail == null) {
054            lotDetail = lot.getLastDetail();
055        }
056        
057        return lotDetail;
058    }
059
060    @GraphQLField
061    @GraphQLDescription("item")
062    public ItemObject getItem(final DataFetchingEnvironment env) {
063        return ItemSecurityUtils.getHasItemAccess(env) ? new ItemObject(getLotDetail().getItem()) : null;
064    }
065
066    @GraphQLField
067    @GraphQLDescription("lot identifier")
068    @GraphQLNonNull
069    public String getLotIdentifier() {
070        return getLotDetail().getLotIdentifier();
071    }
072
073}