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_DISCRETE_ORDER_ITEM")
 @Cache(usage=., region="blOrderElements")
 @AdminPresentationClass(friendlyName = "DiscreteOrderItemImpl_discreteOrderItem")
 public class DiscreteOrderItemImpl extends OrderItemImpl implements DiscreteOrderItem {
 
     private static final long serialVersionUID = 1L;
     
     @Column(name="BASE_RETAIL_PRICE", precision=19, scale=5)
     @AdminPresentation(excluded = true, friendlyName = "DiscreteOrderItemImpl_Base_Retail_Price", order=2,
             group = "DiscreteOrderItemImpl_Pricing", fieldType=.)
     protected BigDecimal baseRetailPrice;
     
     @Column(name="BASE_SALE_PRICE", precision=19, scale=5)
     @AdminPresentation(excluded = true, friendlyName = "DiscreteOrderItemImpl_Base_Sale_Price", order=2,
             group = "DiscreteOrderItemImpl_Pricing", fieldType= .)
     protected BigDecimal baseSalePrice;
     
     @ManyToOne(targetEntity = SkuImpl.class, optional=false)
     @JoinColumn(name = "SKU_ID", nullable = false)
     @Index(name="DISCRETE_SKU_INDEX", columnNames={"SKU_ID"})
     @AdminPresentation(friendlyName = "DiscreteOrderItemImpl_Sku", order=..,
             group = ...., groupOrder = ....)
     protected Sku sku;
 
     @ManyToOne(targetEntity = ProductImpl.class)
     @JoinColumn(name = "PRODUCT_ID")
     @Index(name="DISCRETE_PRODUCT_INDEX", columnNames={"PRODUCT_ID"})
     @NotFound(action = .)
     @AdminPresentation(friendlyName = "DiscreteOrderItemImpl_Product", order=..,
             group = ...., groupOrder = ....)
     protected Product product;
 
     @ManyToOne(targetEntity = BundleOrderItemImpl.class)
     @JoinColumn(name = "BUNDLE_ORDER_ITEM_ID")
     @AdminPresentation(excluded = true)
     protected BundleOrderItem bundleOrderItem;
    @ManyToOne(targetEntity = SkuBundleItemImpl.class)
    @JoinColumn(name = "SKU_BUNDLE_ITEM_ID")
    @AdminPresentation(excluded = true)
    protected SkuBundleItem skuBundleItem;
    @MapKeyColumn(name="NAME")
    @Column(name="VALUE")
    @CollectionTable(name="BLC_ORDER_ITEM_ADD_ATTR", joinColumns=@JoinColumn(name="ORDER_ITEM_ID"))
    @BatchSize(size = 50)
    @Deprecated
    protected Map<StringStringadditionalAttributes = new HashMap<StringString>();
    
    @OneToMany(mappedBy = "discreteOrderItem", targetEntity = DiscreteOrderItemFeePriceImpl.class, cascade = { . }, orphanRemoval = true)
    @Cache(usage = ., region = "blOrderElements")
    @Override
    public Sku getSku() {
        return ;
    }
    @Override
    public void setSku(Sku sku) {
        this. = sku;
        if (sku.hasRetailPrice()) {
            this. = sku.getRetailPrice().getAmount();
        }
        if (sku.hasSalePrice()) {
            this. = sku.getSalePrice().getAmount();
        }
        this. = sku.isTaxable();
        setName(sku.getName());
    }
    @Override
    public Boolean isTaxable() {
        return ( == null || .isTaxable() == null || .isTaxable());
    }
    @Override
    public Product getProduct() {
        return ;
    }
    @Override
    public void setProduct(Product product) {
        this. = product;
    }
    @Override
        return ;
    }
    @Override
    public void setBundleOrderItem(BundleOrderItem bundleOrderItem) {
        if (this. != null && bundleOrderItem != null) {
            throw new IllegalStateException("Cannot set a BundleOrderItem on a DiscreteOrderItem that is already associated with an Order");
        }
        this. = bundleOrderItem;
    }
    @Override
    public void setOrder(Order order) {
        if (order != null &&  != null) {
            throw new IllegalStateException("Cannot set an Order on a DiscreteOrderItem that is already associated with a BundleOrderItem");
        }
        this. = order;
    }

    
If this item is part of a bundle that was created via a ProductBundle, then this method returns a reference to the corresponding SkuBundleItem.

For manually created

For all others, this method returns null.

Returns:
    @Override
    public SkuBundleItem getSkuBundleItem() {
        return ;
    }

    
Sets the associated SkuBundleItem.

Parameters:
SkuBundleItem
    @Override
    public void setSkuBundleItem(SkuBundleItem SkuBundleItem) {
        this. =SkuBundleItem;
    }
    @Override
    public String getName() {
        String name = super.getName();
        if (name == null) {
            return .getName();
        }
        return name;
    }
    
    @Override
    public Order getOrder() {
        if ( == null) {
            if (getBundleOrderItem() != null) {
                return getBundleOrderItem().getOrder();
            }
        }
        return ;
    }
    private boolean updateSalePrice() {
        if (isSalePriceOverride()) {
            return false;
        }
        Money skuSalePrice = (getSku().getSalePrice() == null ? null : getSku().getSalePrice());
        // Override retail/sale prices from skuBundle.
        if ( != null) {
            if (.getSalePrice() != null) {
                skuSalePrice = .getSalePrice();
            }
        }
        boolean updated = false;
        //use the sku prices - the retail and sale prices could be null
        if (skuSalePrice != null && !skuSalePrice.getAmount().equals()) {
             = skuSalePrice.getAmount();
             = skuSalePrice.getAmount();
            updated = true;
        }
        // Adjust prices by adding in fees if they are attached.
        if (getDiscreteOrderItemFeePrices() != null) {
            for (DiscreteOrderItemFeePrice fee : getDiscreteOrderItemFeePrices()) {
                Money returnPrice = convertToMoney();
                 = returnPrice.add(fee.getAmount()).getAmount();
            }
        }
        return updated;
    }
    private boolean updateRetailPrice() {
        if (isRetailPriceOverride()) {
            return false;
        }
        Money skuRetailPrice = getSku().getRetailPrice();
        // Override retail/sale prices from skuBundle.
        if ( != null) {
            if (.getRetailPrice() != null) {
                skuRetailPrice = .getRetailPrice();
            }
        }
        boolean updated = false;
        //use the sku prices - the retail and sale prices could be null
        if (!skuRetailPrice.getAmount().equals()) {
             = skuRetailPrice.getAmount();
             = skuRetailPrice.getAmount();
            updated = true;
        }
        // Adjust prices by adding in fees if they are attached.
        if (getDiscreteOrderItemFeePrices() != null) {
            for (DiscreteOrderItemFeePrice fee : getDiscreteOrderItemFeePrices()) {
                Money returnPrice = convertToMoney();
                 = returnPrice.add(fee.getAmount()).getAmount();
            }
        }
        return updated;
    }
    @Override
    public boolean updateSaleAndRetailPrices() {
        boolean salePriceUpdated = updateSalePrice();
        boolean retailPriceUpdated = updateRetailPrice();
        if (!isRetailPriceOverride() && !isSalePriceOverride()) {
            if ( != null && .compareTo() <= 0) {
                 = ;
            } else {
                 = ;
            }
        }
        return salePriceUpdated || retailPriceUpdated;
    }
    @Override
    public Map<StringStringgetAdditionalAttributes() {
        return ;
    }
    @Override
    public void setAdditionalAttributes(Map<StringStringadditionalAttributes) {
        this. = additionalAttributes;
    }
    @Override
    public Money getBaseRetailPrice() {
        return convertToMoney();
    }
    @Override
    public void setBaseRetailPrice(Money baseRetailPrice) {
        this. = baseRetailPrice.getAmount();
    }
    @Override
    public Money getBaseSalePrice() {
        return convertToMoney();
    }
    @Override
    public void setBaseSalePrice(Money baseSalePrice) {
        this. = baseSalePrice==null?null:baseSalePrice.getAmount();
    }
    @Override
        return ;
    }
    @Override
    public void setDiscreteOrderItemFeePrices(List<DiscreteOrderItemFeePricediscreteOrderItemFeePrices) {
        this. = discreteOrderItemFeePrices;
    }
    protected Money convertToMoney(BigDecimal amount) {
        return amount == null ? null : BroadleafCurrencyUtils.getMoney(amountgetOrder().getCurrency());
    }
    
    @Override
    public OrderItem clone() {
        DiscreteOrderItem orderItem = (DiscreteOrderItemsuper.clone();
        if ( != null) {
            for (DiscreteOrderItemFeePrice feePrice : ) {
                DiscreteOrderItemFeePrice cloneFeePrice = feePrice.clone();
                cloneFeePrice.setDiscreteOrderItem(orderItem);
                orderItem.getDiscreteOrderItemFeePrices().add(cloneFeePrice);
            }
        }
        if ( != null) {
            orderItem.getAdditionalAttributes().putAll();
        }
        orderItem.setBaseSalePrice(convertToMoney());
        orderItem.setBundleOrderItem();
        orderItem.setProduct();
        orderItem.setSku();
        if (orderItem.getOrder() == null) {
            throw new IllegalStateException("Either an Order or a BundleOrderItem must be set on the DiscreteOrderItem");
        }
        
        return orderItem;
    }
    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        DiscreteOrderItemImpl other = (DiscreteOrderItemImplobj;
        
        if (!super.equals(obj)) {
            return false;
        }
        if ( != null && other.id != null) {
            return .equals(other.id);
        }
        if ( == null) {
            if (other.bundleOrderItem != null) {
                return false;
            }
        } else if (!.equals(other.bundleOrderItem)) {
            return false;
        }
        if ( == null) {
            if (other.sku != null) {
                return false;
            }
        } else if (!.equals(other.sku)) {
            return false;
        }
        return true;
    }
    @Override
    public int hashCode() {
        final int prime = super.hashCode();
        int result = 1;
        result = prime * result + (( == null) ? 0 : .hashCode());
        result = prime * result + (( == null) ? 0 : .hashCode());
        return result;
    }
    @Override
    public boolean isDiscountingAllowed() {
        if ( == null) {
            return .isDiscountable();
        } else {
            return .booleanValue();
        }
    }
    @Override
    public BundleOrderItem findParentItem() {
        for (OrderItem orderItem : getOrder().getOrderItems()) {
            if (orderItem instanceof BundleOrderItem) {
                BundleOrderItem bundleItem = (BundleOrderItemorderItem;
                for (OrderItem containedItem : bundleItem.getOrderItems()) {
                    if (containedItem.equals(this)) {
                        return bundleItem;
                    }
                }
            }
        }
        return null;
    }
    public static class Presentation {
        public static class Tab {
            public static class Name {
                public static final String OrderItems = "OrderImpl_Order_Items_Tab";
            }
            public static class Order {
                public static final int OrderItems = 2000;
            }
        }
        public static class Group {
            public static class Name {
            }
            public static class Order {
            }
        }
        public static class FieldOrder {
            public static final int PRODUCT = 2000;
            public static final int SKU = 3000;
        }
    }
    @Override
    public boolean isSkuActive() {
        return .isActive();
    }
New to GrepCode? Check out our FAQ X