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.wishlist.server.transfer; 018 019import com.echothree.model.control.associate.common.transfer.AssociateReferralTransfer; 020import com.echothree.model.control.inventory.server.control.InventoryControl; 021import com.echothree.model.control.item.server.control.ItemControl; 022import com.echothree.model.control.offer.server.control.OfferUseControl; 023import com.echothree.model.control.uom.server.control.UomControl; 024import com.echothree.model.control.wishlist.common.transfer.WishlistLineTransfer; 025import com.echothree.model.control.wishlist.server.control.WishlistControl; 026import com.echothree.model.data.order.server.entity.OrderLine; 027import com.echothree.model.data.user.server.entity.UserVisit; 028import com.echothree.util.server.persistence.Session; 029import com.echothree.util.server.string.AmountUtils; 030import javax.enterprise.context.RequestScoped; 031 032@RequestScoped 033public class WishlistLineTransferCache 034 extends BaseWishlistTransferCache<OrderLine, WishlistLineTransfer> { 035 036 InventoryControl inventoryControl = Session.getModelController(InventoryControl.class); 037 ItemControl itemControl = Session.getModelController(ItemControl.class); 038 OfferUseControl offerUseControl = Session.getModelController(OfferUseControl.class); 039 UomControl uomControl = Session.getModelController(UomControl.class); 040 WishlistControl wishlistControl = Session.getModelController(WishlistControl.class); 041 042 /** Creates a new instance of WishlistLineTransferCache */ 043 protected WishlistLineTransferCache() { 044 super(); 045 046 setIncludeEntityInstance(true); 047 } 048 049 public WishlistLineTransfer getWishlistLineTransfer(UserVisit userVisit, OrderLine orderLine) { 050 var wishlistLineTransfer = get(orderLine); 051 052 if(wishlistLineTransfer == null) { 053 var orderLineDetail = orderLine.getLastDetail(); 054 var wishlistLine = wishlistControl.getWishlistLine(orderLine); 055 var order = orderLineDetail.getOrder(); 056 var wishlist = wishlistControl.getWishlistTransfer(userVisit, order); 057 var orderLineSequence = orderLineDetail.getOrderLineSequence(); 058 var item = itemControl.getItemTransfer(userVisit, orderLineDetail.getItem()); 059 var inventoryCondition = inventoryControl.getInventoryConditionTransfer(userVisit, orderLineDetail.getInventoryCondition()); 060 var unitOfMeasureType = uomControl.getUnitOfMeasureTypeTransfer(userVisit, orderLineDetail.getUnitOfMeasureType()); 061 var quantity = orderLineDetail.getQuantity(); 062 var unformattedUnitAmount = orderLineDetail.getUnitAmount(); 063 var unitAmount = AmountUtils.getInstance().formatPriceLine(order.getLastDetail().getCurrency(), unformattedUnitAmount); 064 var description = orderLineDetail.getDescription(); 065 var offerUse = offerUseControl.getOfferUseTransfer(userVisit, wishlistLine.getOfferUse()); 066 var wishlistPriority = wishlistControl.getWishlistPriorityTransfer(userVisit, wishlistLine.getWishlistPriority()); 067 AssociateReferralTransfer associateReferral = null; // TODO 068 var comment = wishlistLine.getComment(); 069 070 wishlistLineTransfer = new WishlistLineTransfer(wishlist, orderLineSequence, item, inventoryCondition, unitOfMeasureType, quantity, 071 unformattedUnitAmount, unitAmount, description, offerUse, wishlistPriority, associateReferral, comment); 072 put(userVisit, orderLine, wishlistLineTransfer); 073 } 074 075 return wishlistLineTransfer; 076 } 077 078}