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