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.order.server.transfer;
018
019import javax.inject.Inject;
020import com.echothree.model.control.contact.server.control.ContactControl;
021import com.echothree.model.control.item.server.control.ItemControl;
022import com.echothree.model.control.order.common.transfer.OrderShipmentGroupTransfer;
023import com.echothree.model.control.shipping.server.control.ShippingControl;
024import com.echothree.model.data.order.server.entity.OrderShipmentGroup;
025import com.echothree.model.data.user.server.entity.UserVisit;
026import javax.enterprise.context.RequestScoped;
027
028@RequestScoped
029public class OrderShipmentGroupTransferCache
030        extends BaseOrderTransferCache<OrderShipmentGroup, OrderShipmentGroupTransfer> {
031
032    @Inject
033    ContactControl contactControl;
034
035    @Inject
036    ItemControl itemControl;
037
038    @Inject
039    ShippingControl shippingControl;
040
041;
042;
043;
044    
045    /** Creates a new instance of OrderShipmentGroupTransferCache */
046    protected OrderShipmentGroupTransferCache() {
047        super();
048        
049        setIncludeEntityInstance(true);
050    }
051    
052    public OrderShipmentGroupTransfer getOrderShipmentGroupTransfer(UserVisit userVisit, OrderShipmentGroup orderShipmentGroup) {
053        var orderShipmentGroupTransfer = get(orderShipmentGroup);
054        
055        if(orderShipmentGroupTransfer == null) {
056            var orderShipmentGroupDetail = orderShipmentGroup.getLastDetail();
057            var orderShipmentGroupSequence = orderShipmentGroupDetail.getOrderShipmentGroupSequence();
058            var itemDeliveryTypeTransfer = itemControl.getItemDeliveryTypeTransfer(userVisit, orderShipmentGroupDetail.getItemDeliveryType());
059            var isDefault = orderShipmentGroupDetail.getIsDefault();
060            var partyContactMechanism = orderShipmentGroupDetail.getPartyContactMechanism();
061            var partyContactMechanismTransfer = partyContactMechanism == null ? null : contactControl.getPartyContactMechanismTransfer(userVisit, partyContactMechanism);
062            var shippingMethod = orderShipmentGroupDetail.getShippingMethod();
063            var shippingMethodTransfer = shippingMethod == null ? null : shippingControl.getShippingMethodTransfer(userVisit, shippingMethod);
064            var holdUntilComplete = orderShipmentGroupDetail.getHoldUntilComplete();
065            
066            orderShipmentGroupTransfer = new OrderShipmentGroupTransfer(orderShipmentGroupSequence, itemDeliveryTypeTransfer, isDefault,
067                    partyContactMechanismTransfer, shippingMethodTransfer, holdUntilComplete);
068            put(userVisit, orderShipmentGroup, orderShipmentGroupTransfer);
069        }
070        
071        return orderShipmentGroupTransfer;
072    }
073    
074}