Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * #%L
   * BroadleafCommerce Framework
   * %%
   * Copyright (C) 2009 - 2013 Broadleaf Commerce
   * %%
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
  * 
  *       http://www.apache.org/licenses/LICENSE-2.0
  * 
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  * #L%
  */
 package org.broadleafcommerce.core.order.domain;
 
 
 import java.util.List;
 import java.util.Map;
 
 
 
 @Table(name = "BLC_ORDER_ITEM")
 @Cache(usage=., region="blOrderElements")
     {
         @AdminPresentationMergeOverride(name = "", mergeEntries =
             @AdminPresentationMergeEntry(propertyType = ..,
                                             booleanOverrideValue = true))
     }
 )
 @AdminPresentationClass(populateToOneFields = ., friendlyName = "OrderItemImpl_baseOrderItem")
 })
 
     private static final Log LOG = LogFactory.getLog(OrderItemImpl.class);
     private static final long serialVersionUID = 1L;
 
    @Id
    @GeneratedValue(generator = "OrderItemId")
        name="OrderItemId",
        strategy="org.broadleafcommerce.common.persistence.IdOverrideTableGenerator",
        parameters = {
            @Parameter(name="segment_value", value="OrderItemImpl"),
            @Parameter(name="entity_name", value="org.broadleafcommerce.core.order.domain.OrderItemImpl")
        }
    )
    @Column(name = "ORDER_ITEM_ID")
    protected Long id;
    @ManyToOne(targetEntity = CategoryImpl.class)
    @JoinColumn(name = "CATEGORY_ID")
    @Index(name="ORDERITEM_CATEGORY_INDEX", columnNames={"CATEGORY_ID"})
    @NotFound(action = .)
    @AdminPresentation(friendlyName = "OrderItemImpl_Category", order=..,
            group = ..., groupOrder = ...)
    protected Category category;
    @ManyToOne(targetEntity = OrderImpl.class)
    @JoinColumn(name = "ORDER_ID")
    @Index(name="ORDERITEM_ORDER_INDEX", columnNames={"ORDER_ID"})
    @AdminPresentation(excluded = true)
    protected Order order;
    @Column(name = "PRICE", precision = 19, scale = 5)
    @AdminPresentation(friendlyName = "OrderItemImpl_Item_Price", order = ..,
            group = ..., groupOrder = ...,
            fieldType = ., prominent = true, gridOrder = 3000)
    protected BigDecimal price;
    @Column(name = "QUANTITY", nullable = false)
    @AdminPresentation(friendlyName = "OrderItemImpl_Item_Quantity", order = ..,
            group = ..., groupOrder = ...,
            prominent = true, gridOrder = 2000)
    protected int quantity;
    @Column(name = "RETAIL_PRICE", precision=19, scale=5)
    @AdminPresentation(friendlyName = "OrderItemImpl_Item_Retail_Price", order = ..,
            group = ..., groupOrder = ...,
            fieldType = ., prominent = true, gridOrder = 4000)
    protected BigDecimal retailPrice;
    @Column(name = "SALE_PRICE", precision=19, scale=5)
    @AdminPresentation(friendlyName = "OrderItemImpl_Item_Sale_Price", order = ..,
            group = ..., groupOrder = ...,
            fieldType = .)
    protected BigDecimal salePrice;
    @Column(name = "NAME")
    @AdminPresentation(friendlyName = "OrderItemImpl_Item_Name", order=..,
            group = ..., prominent=true, gridOrder = 1000,
            groupOrder = ...)
    protected String name;
    @ManyToOne(targetEntity = PersonalMessageImpl.class, cascade = { . })
    @JoinColumn(name = "PERSONAL_MESSAGE_ID")
    @Cache(usage=., region="blOrderElements")
    @Index(name="ORDERITEM_MESSAGE_INDEX", columnNames={"PERSONAL_MESSAGE_ID"})
    protected PersonalMessage personalMessage;
    @ManyToOne(targetEntity = GiftWrapOrderItemImpl.class, cascade = { .. })
    @JoinColumn(name = "GIFT_WRAP_ITEM_ID", nullable = true)
    @Cache(usage=., region="blOrderElements")
    @Index(name="ORDERITEM_GIFT_INDEX", columnNames={"GIFT_WRAP_ITEM_ID"})
    @AdminPresentation(excluded = true)
    @OneToMany(mappedBy = "orderItem", targetEntity = OrderItemAdjustmentImpl.class, cascade = { . },
            orphanRemoval = true)
    @Cache(usage = ., region = "blOrderElements")
    @AdminPresentationCollection(friendlyName="OrderItemImpl_Adjustments", order = ..,
                    tab = ..., tabOrder = ...)
    @OneToMany(mappedBy = "orderItem", targetEntity = OrderItemQualifierImpl.class, cascade = { . },
            orphanRemoval = true)
    @Cache(usage = ., region = "blOrderElements")
    @OneToMany(mappedBy = "orderItem", targetEntity = CandidateItemOfferImpl.class, cascade = { . },
            orphanRemoval = true)
    @Cache(usage = ., region = "blOrderElements")
    @OneToMany(mappedBy = "orderItem", targetEntity = OrderItemPriceDetailImpl.class, cascade = { . },
            orphanRemoval = true)
    @Cache(usage=., region="blOrderElements")
    @AdminPresentationCollection(friendlyName="OrderItemImpl_Price_Details", order = ..,
                    tab = ..., tabOrder = ...)
    
    @Column(name = "ORDER_ITEM_TYPE")
    @Index(name="ORDERITEM_TYPE_INDEX", columnNames={"ORDER_ITEM_TYPE"})
    protected String orderItemType;
    @Column(name = "ITEM_TAXABLE_FLAG")
    protected Boolean itemTaxable;
    @Column(name = "RETAIL_PRICE_OVERRIDE")
    protected Boolean retailPriceOverride;
    @Column(name = "SALE_PRICE_OVERRIDE")
    protected Boolean salePriceOverride;
    @Column(name = "DISCOUNTS_ALLOWED")
    @AdminPresentation(friendlyName = "OrderItemImpl_Discounts_Allowed", order=..,
            tab = ..., tabOrder = ...)
    protected Boolean discountsAllowed;
    @OneToMany(mappedBy = "orderItem", targetEntity = OrderItemAttributeImpl.class, cascade = { . }, orphanRemoval = true)
    @Cache(usage=., region="blOrderElements")
    @MapKey(name="name")
    @AdminPresentationMap(friendlyName = "OrderItemImpl_Attributes",
        tab = ..., tabOrder = ...,
        deleteEntityUponRemove = true, forceFreeFormKeys = true, keyPropertyFriendlyName = "OrderItemAttributeImpl_Attribute_Name"
    )
    @Column(name = "TOTAL_TAX")
    @AdminPresentation(friendlyName = "OrderItemImpl_Total_Tax", order = ..,
                group = ..., groupOrder = ...,
                fieldType = .)
    protected BigDecimal totalTax;
    
    @OneToMany(mappedBy = "parentOrderItem", targetEntity = OrderItemImpl.class)
    @Cache(usage = ., region = "blOrderElements")
    protected List<OrderItemchildOrderItems = new ArrayList<OrderItem>();
    @ManyToOne(targetEntity = OrderItemImpl.class)
    @JoinColumn(name = "PARENT_ORDER_ITEM_ID")
    @Index(name="ORDERITEM_PARENT_INDEX", columnNames={"PARENT_ORDER_ITEM_ID"})
    protected OrderItem parentOrderItem;
    
    @Override
    public Money getRetailPrice() {
        if ( == null) {
            updateSaleAndRetailPrices();
        }
        return convertToMoney();
    }
    @Override
    public void setRetailPrice(Money retailPrice) {
        this. = Money.toAmount(retailPrice);
    }
    @Override
    public Money getSalePrice() {
        if ( == null) {
            updateSaleAndRetailPrices();
        }
        if ( != null) {
            Money returnPrice = convertToMoney();
            if ( != null && returnPrice.greaterThan(getRetailPrice())) {
                return getRetailPrice();
            } else {
                return returnPrice;
            }
        } else {
            return getRetailPrice();
        }
    }
    @Override
    public void setSalePrice(Money salePrice) {
        this. = Money.toAmount(salePrice);
    }
    @Override
    public Money getPrice() {
        return getAveragePrice();
    }
    @Override
    public void setPrice(Money finalPrice) {
        setRetailPrice(finalPrice);
        setSalePrice(finalPrice);
        setRetailPriceOverride(true);
        setSalePriceOverride(true);
        setDiscountingAllowed(false);
        this. = Money.toAmount(finalPrice);
    }
    @Override
    public Money getTaxablePrice() {
        Money taxablePrice = BroadleafCurrencyUtils.getMoney(.getOrder().getCurrency());
        if (isTaxable() == null || isTaxable()) {
            taxablePrice = getAveragePrice();
        }
        return taxablePrice;
    }
    @Override
    public int getQuantity() {
        return ;
    }
    @Override
    public void setQuantity(int quantity) {
        this. = quantity;
    }
    @Override
    public Category getCategory() {
        return ;
    }
    @Override
    public void setCategory(Category category) {
        this. = category;
    }
    @Override
        return ;
    }
    @Override
    public void setCandidateItemOffers(List<CandidateItemOffercandidateItemOffers) {
        this. = candidateItemOffers;
    }
    @Override
        return ;
    }
    @Override
    public void setPersonalMessage(PersonalMessage personalMessage) {
        this. = personalMessage;
    }
    @Override
    public Order getOrder() {
        return ;
    }
    @Override
    public void setOrder(Order order) {
        this. = order;
    }
    @Override
    public Long getId() {
        return ;
    }
    @Override
    public void setId(Long id) {
        this. = id;
    }
    @Override
    public String getName() {
        return ;
    }
    @Override
    public void setName(String name) {
        this. = name;
    }
    @Override
    public boolean isInCategory(String categoryName) {
        Category currentCategory = ;
        if (currentCategory != null) {
            if (currentCategory.getName().equals(categoryName)) {
                return true;
            }
            while ((currentCategory = currentCategory.getDefaultParentCategory()) != null) {
                if (currentCategory.getName().equals(categoryName)) {
                    return true;
                }
            }
        }
        return false;
    }
    @Override
        return this.;
    }
    @Override
    public void setOrderItemQualifiers(List<OrderItemQualifierorderItemQualifiers) {
        this. = orderItemQualifiers;
    }
    @Override
        return this.;
    }
    @Override
    public void setOrderItemAdjustments(List<OrderItemAdjustmentorderItemAdjustments) {       
        this. = orderItemAdjustments;
    }
    @Override
    public Money getAdjustmentValue() {
        return getAverageAdjustmentValue();
    }
    @Override
        return ;
    }
    @Override
    public void setGiftWrapOrderItem(GiftWrapOrderItem giftWrapOrderItem) {
        this. = giftWrapOrderItem;
    }
    @Override
    public OrderItemType getOrderItemType() {
        return convertOrderItemType();
    }
    @Override
    public void setOrderItemType(OrderItemType orderItemType) {
        this. = orderItemType.getType();
    }
    @Override
    public boolean getIsOnSale() {
        if (getSalePrice() != null) {
            return !getSalePrice().equals(getRetailPrice());
        } else {
            return false;
        }
    }
    @Override
    public boolean getIsDiscounted() {
        if (getPrice() != null) {
            return !getPrice().equals(getRetailPrice());
        } else {
            return false;
        }
    }
    @Override
    public boolean updateSaleAndRetailPrices() {
        if ( == null) {
             = ;
        }
        return false;
    }
    
    @Override
    public void finalizePrice() {
         = getAveragePrice().getAmount();
    }
    @Override
    public void assignFinalPrice() {
        Money finalPrice = getTotalPrice().divide();
         = finalPrice.getAmount();
    }
    @Override
    public Money getPriceBeforeAdjustments(boolean allowSalesPrice) {
        boolean retailPriceOverride = false;
        
        for (OrderItemPriceDetail oipd : getOrderItemPriceDetails()) {
            if (oipd.getUseSalePrice() == false) {
                retailPriceOverride = true;
                break;
            }
        }
        
        if (allowSalesPrice && !retailPriceOverride) {
            return getSalePrice();
        } else {
            return getRetailPrice();
        }
    }
    
    @Override
    public void addCandidateItemOffer(CandidateItemOffer candidateItemOffer) {
        getCandidateItemOffers().add(candidateItemOffer);
    }
    
    @Override
    public void removeAllCandidateItemOffers() {
        if (getCandidateItemOffers() != null) {
            for (CandidateItemOffer candidate : getCandidateItemOffers()) {
                candidate.setOrderItem(null);
            }
            getCandidateItemOffers().clear();
        }
    }
    
    @Override
    public int removeAllAdjustments() {
        int removedAdjustmentCount = 0;
        if (getOrderItemAdjustments() != null) {
            for (OrderItemAdjustment adjustment : getOrderItemAdjustments()) {
                adjustment.setOrderItem(null);
            }
            removedAdjustmentCount = getOrderItemAdjustments().size();
            getOrderItemAdjustments().clear();
        }
        assignFinalPrice();
        return removedAdjustmentCount;
    }
    
    
A list of arbitrary attributes added to this item.
    @Override
        return ;
    }

    
Sets the map of order item attributes.

Parameters:
orderItemAttributes
    @Override
    public void setOrderItemAttributes(Map<String,OrderItemAttributeorderItemAttributes) {
        this. = orderItemAttributes;
    }
    @Override
    public Boolean isTaxable() {
        return  == null ? true : ;
    }
    @Override
    public void setTaxable(Boolean taxable) {
        this. = taxable;
    }
    @Override
    public void setOrderItemPriceDetails(List<OrderItemPriceDetailorderItemPriceDetails) {
        this. = orderItemPriceDetails;
    }
    @Override
    public boolean isDiscountingAllowed() {
        if ( == null) {
            return true;
        } else {
            return .booleanValue();
        }
    }
    @Override
    public void setDiscountingAllowed(boolean discountsAllowed) {
        this. = discountsAllowed;
    }
    @Override
    public Money getAveragePrice() {
        if ( == 0) {
            return  == null ? null : BroadleafCurrencyUtils.getMoney(getOrder().getCurrency());
        }
        return getTotalPrice().divide();
    }
    @Override
    public Money getAverageAdjustmentValue() {
        if ( == 0) {
            return null;
        }
        return getTotalAdjustmentValue().divide();
    }
    @Override
    public Money getTotalAdjustmentValue() {
        Money totalAdjustmentValue = BroadleafCurrencyUtils.getMoney(getOrder().getCurrency());
        List<OrderItemPriceDetailpriceDetails = getOrderItemPriceDetails();
        if (priceDetails != null) {
            for (OrderItemPriceDetail priceDetail : getOrderItemPriceDetails()) {
                totalAdjustmentValue = totalAdjustmentValue.add(priceDetail.getTotalAdjustmentValue());
            }
        }
        return totalAdjustmentValue;
    }
    @Override
    public Money getTotalPrice() {
        Money returnValue = convertToMoney(.);
        if ( != null && .size() > 0) {
            for (OrderItemPriceDetail oipd : ) {
                returnValue = returnValue.add(oipd.getTotalAdjustedPrice());
            }
        } else {
            if ( != null) {
                returnValue = convertToMoney().multiply();
            } else {
                return getSalePrice().multiply();
            }
        }
        return returnValue;
    }
    @Override
    public Money getTotalPriceBeforeAdjustments(boolean allowSalesPrice) {
        return getPriceBeforeAdjustments(allowSalesPrice).multiply(getQuantity());
    }
    @Override
    public void setRetailPriceOverride(boolean override) {
        this. = Boolean.valueOf(override);
    }
    @Override
    public boolean isRetailPriceOverride() {
        if ( == null) {
            return false;
        } else {
            return .booleanValue();
        }
    }
    @Override
    public void setSalePriceOverride(boolean override) {
        this. = Boolean.valueOf(override);
    }
    @Override
    public boolean isSalePriceOverride() {
        if ( == null) {
            return false;
        } else {
            return .booleanValue();
        }
    }
    @Override
        return ;
    }
    
    @Override
    public List<OrderItemgetChildOrderItems() {
        return ;
    }
    
    @Override
    public void setChildOrderItems(List<OrderItemchildOrderItems) {
        this. = childOrderItems;
    }
    
    @Override
    public OrderItem getParentOrderItem() {
        return ;
    }
    
    @Override
    public void setParentOrderItem(OrderItem parentOrderItem) {
        this. = parentOrderItem;
    }
    
    @Override
    public boolean isAParentOf(OrderItem candidateChild) {
        if (CollectionUtils.isNotEmpty(this.getChildOrderItems())) {
            for (OrderItem child : this.getChildOrderItems()) {
                if (child.equals(candidateChild)) {
                    return true;
                }
            }
            // Item wasn't a direct child. Let's check the hierarchy
            for (OrderItem child : this.getChildOrderItems()) {
                if (child.isAParentOf(candidateChild)) {
                    return true;
                }
            }
        }
        return false;
    }
    @Override
    public String getMainEntityName() {
        return getName();
    }
    @Override
    public String getCurrencyCode() {
        if (getOrder().getCurrency() != null) {
            return getOrder().getCurrency().getCurrencyCode();
        }
        return null;
    }
        Method cloneMethod = orderItem.getClass().getMethod("clone"new Class[]{});
        if (cloneMethod.getDeclaringClass().getName().startsWith("org.broadleafcommerce") &&
                !orderItem.getClass().getName().startsWith("org.broadleafcommerce")) {
            //subclass is not implementing the clone method
            throw new CloneNotSupportedException("Custom extensions and implementations should implement clone in " +
                    "order to guarantee split and merge operations are performed accurately");
        }
    }
    protected Money convertToMoney(BigDecimal amount) {
        return amount == null ? null : BroadleafCurrencyUtils.getMoney(amountgetOrder().getCurrency());
    }
    protected OrderItemType convertOrderItemType(String type) {
        return OrderItemType.getInstance(type);
    }
    
    @Override
    public OrderItem clone() {
        //this is likely an extended class - instantiate from the fully qualified name via reflection
        OrderItemImpl clonedOrderItem;
        try {
            clonedOrderItem = (OrderItemImpl) Class.forName(this.getClass().getName()).newInstance();
            try {
                checkCloneable(clonedOrderItem);
            } catch (CloneNotSupportedException e) {
                .warn("Clone implementation missing in inheritance hierarchy outside of Broadleaf: " +
                        clonedOrderItem.getClass().getName(), e);
            }
            if ( != null) {
                for (CandidateItemOffer candidate : ) {
                    CandidateItemOffer clone = candidate.clone();
                    clone.setOrderItem(clonedOrderItem);
                    clonedOrderItem.getCandidateItemOffers().add(clone);
                }
            }
            
            if ( != null && !.isEmpty()) {
                for (OrderItemAttribute attribute : .values()) {
                    OrderItemAttribute clone = attribute.clone();
                    clone.setOrderItem(clonedOrderItem);
                    clonedOrderItem.getOrderItemAttributes().put(clone.getName(), clone);
                }
            }
            
            if (CollectionUtils.isNotEmpty()) {
                for (OrderItem childOrderItem : ) {
                    OrderItem clone = childOrderItem.clone();
                    clone.setParentOrderItem(clonedOrderItem);
                    clonedOrderItem.getChildOrderItems().add(clone);
                }
            }
            
            clonedOrderItem.setCategory();
            clonedOrderItem.setGiftWrapOrderItem();
            clonedOrderItem.setName();
            clonedOrderItem.setOrder();
            clonedOrderItem.setOrderItemType(convertOrderItemType());
            clonedOrderItem.setPersonalMessage();
            clonedOrderItem.setQuantity();
            clonedOrderItem.retailPrice = ;
            clonedOrderItem.salePrice = ;
            clonedOrderItem.discountsAllowed = ;
            clonedOrderItem.salePriceOverride = ;
            clonedOrderItem.retailPriceOverride = ;
            clonedOrderItem.setParentOrderItem();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        
        return clonedOrderItem;
    }
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + (( == null) ? 0 : .hashCode());
        result = prime * result + (( == null) ? 0 : .hashCode());
        result = prime * result + (( == null) ? 0 : .hashCode());
        result = prime * result + (( == null) ? 0 : .hashCode());
        result = prime * result + (( == null) ? 0 : .hashCode());
        result = prime * result + (( == null) ? 0 : .hashCode());
        result = prime * result + ;
        result = prime * result + (( == null) ? 0 : .hashCode());
        result = prime * result + (( == null) ? 0 : .hashCode());
        result = prime * result + (( == null) ? 0 : .hashCode());
        return result;
    }
    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        OrderItemImpl other = (OrderItemImplobj;
        if ( != null && other.id != null) {
            return .equals(other.id);
        }
        if ( == null) {
            if (other.category != null) {
                return false;
            }
        } else if (!.equals(other.category)) {
            return false;
        }
        if ( == null) {
            if (other.giftWrapOrderItem != null) {
                return false;
            }
        } else if (!.equals(other.giftWrapOrderItem)) {
            return false;
        }
        if ( == null) {
            if (other.order != null) {
                return false;
            }
        } else if (!.equals(other.order)) {
            return false;
        }
        if ( == null) {
            if (other.orderItemType != null) {
                return false;
            }
        } else if (!.equals(other.orderItemType)) {
            return false;
        }
        if ( == null) {
            if (other.personalMessage != null) {
                return false;
            }
        } else if (!.equals(other.personalMessage)) {
            return false;
        }
        if ( == null) {
            if (other.price != null) {
                return false;
            }
        } else if (!.equals(other.price)) {
            return false;
        }
        if ( != other.quantity) {
            return false;
        }
        if ( == null) {
            if (other.retailPrice != null) {
                return false;
            }
        } else if (!.equals(other.retailPrice)) {
            return false;
        }
        if ( == null) {
            if (other.salePrice != null) {
                return false;
            }
        } else if (!.equals(other.salePrice)) {
            return false;
        }
        if ( == null) {
            if (other.parentOrderItem != null) {
                return false;
            }
        } else if (!.equals(other.parentOrderItem)) {
            return false;
        }
        return true;
    }
    public static class Presentation {
        public static class Tab {
            public static class Name {
                public static final String Advanced = "OrderImpl_Advanced";
            }
            public static class Order {
                public static final int Advanced = 2000;
            }
        }
        public static class Group {
            public static class Name {
                public static final String Description = "OrderItemImpl_Description";
                public static final String Pricing = "OrderItemImpl_Pricing";
                public static final String Catalog = "OrderItemImpl_Catalog";
            }
            public static class Order {
                public static final int Description = 1000;
                public static final int Pricing = 2000;
                public static final int Catalog = 3000;
            }
        }
        public static class FieldOrder {
            public static final int NAME = 1000;
            public static final int PRICE = 2000;
            public static final int QUANTITY = 3000;
            public static final int RETAILPRICE = 4000;
            public static final int SALEPRICE = 5000;
            public static final int TOTALTAX = 6000;
            public static final int CATEGORY = 1000;
            public static final int PRICEDETAILS = 1000;
            public static final int ADJUSTMENTS = 2000;
            public static final int DISCOUNTALLOWED = 3000;
        }
    }
    @Override
    public boolean isSkuActive() {
        //abstract method, by default return true
        return true;
    }