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.Date;
 import java.util.List;
 import java.util.Map;
 
@Table(name = "BLC_ORDER")
@Cache(usage=., region="blOrderElements")
    {
        @AdminPresentationMergeOverride(name = "", mergeEntries =
            @AdminPresentationMergeEntry(propertyType = ..,
                                            booleanOverrideValue = true))
    }
@AdminPresentationClass(populateToOneFields = ., friendlyName = "OrderImpl_baseOrder")
        @DirectCopyTransformMember(templateTokens = ., skipOverlaps=true),
})
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(generator = "OrderId")
        name="OrderId",
        strategy="org.broadleafcommerce.common.persistence.IdOverrideTableGenerator",
        parameters = {
            @Parameter(name="segment_value", value="OrderImpl"),
            @Parameter(name="entity_name", value="org.broadleafcommerce.core.order.domain.OrderImpl")
        }
    )
    @Column(name = "ORDER_ID")
    protected Long id;
    @Embedded
    protected Auditable auditable = new Auditable();
    @Embedded
    protected PreviewStatus previewable = new PreviewStatus();
    @Column(name = "NAME")
    @Index(name="ORDER_NAME_INDEX", columnNames={"NAME"})
    @AdminPresentation(friendlyName = "OrderImpl_Order_Name", group = ...,
            order=.., prominent=true, groupOrder = ...,
            gridOrder = 2000)
    protected String name;
    @ManyToOne(targetEntity = CustomerImpl.class, optional=false)
    @JoinColumn(name = "CUSTOMER_ID", nullable = false)
    @Index(name="ORDER_CUSTOMER_INDEX", columnNames={"CUSTOMER_ID"})
    @AdminPresentation(friendlyName = "OrderImpl_Customer", group = ...,
            order=.., groupOrder = ...)
    protected Customer customer;
    @Column(name = "ORDER_STATUS")
    @Index(name="ORDER_STATUS_INDEX", columnNames={"ORDER_STATUS"})
    @AdminPresentation(friendlyName = "OrderImpl_Order_Status", group = ...,
            order=.., prominent=true, fieldType=.,
            broadleafEnumeration="org.broadleafcommerce.core.order.service.type.OrderStatus",
            groupOrder = ..., gridOrder = 3000)
    protected String status;
    @Column(name = "TOTAL_TAX", precision=19, scale=5)
    @AdminPresentation(friendlyName = "OrderImpl_Order_Total_Tax", group = ...,
            order=.., fieldType=.,
            groupOrder = ...)
    protected BigDecimal totalTax;
    @Column(name = "TOTAL_SHIPPING", precision=19, scale=5)
    @AdminPresentation(friendlyName = "OrderImpl_Order_Total_Shipping", group = ...,
            order=.., fieldType=.,
            groupOrder = ...)
    @Column(name = "ORDER_SUBTOTAL", precision=19, scale=5)
    @AdminPresentation(friendlyName = "OrderImpl_Order_Subtotal", group = ...,
            order=.., fieldType=.,
            groupOrder = ...)
    protected BigDecimal subTotal;
    @Column(name = "ORDER_TOTAL", precision=19, scale=5)
    @AdminPresentation(friendlyName = "OrderImpl_Order_Total", group = ...,
            order=.., fieldType= ., prominent=true,
            groupOrder = ...,
            gridOrder = 4000)
    protected BigDecimal total;
    @Column(name = "SUBMIT_DATE")
    @AdminPresentation(friendlyName = "OrderImpl_Order_Submit_Date", group = ...,
            order=.., groupOrder = ..., prominent = true,
            gridOrder = 5000)
    protected Date submitDate;
    @Column(name = "ORDER_NUMBER")
    @Index(name="ORDER_NUMBER_INDEX", columnNames={"ORDER_NUMBER"})
    @AdminPresentation(friendlyName = "OrderImpl_Order_Number", group = ...,
            order=.., prominent=true, groupOrder = ...,
            gridOrder = 1000)
    private String orderNumber;
    @Column(name = "EMAIL_ADDRESS")
    @Index(name="ORDER_EMAIL_INDEX", columnNames={"EMAIL_ADDRESS"})
    @AdminPresentation(friendlyName = "OrderImpl_Order_Email_Address", group = ...,
            order=.., groupOrder = ...)
    protected String emailAddress;
    @OneToMany(mappedBy = "order", targetEntity = OrderItemImpl.class, cascade = {.})
    @Cache(usage = ., region="blOrderElements")
    @AdminPresentationCollection(friendlyName="OrderImpl_Order_Items",
            tab = ..., tabOrder = ...)
    protected List<OrderItemorderItems = new ArrayList<OrderItem>();
    @OneToMany(mappedBy = "order", targetEntity = FulfillmentGroupImpl.class, cascade = {.})
    @Cache(usage = ., region="blOrderElements")
    @AdminPresentationCollection(friendlyName="OrderImpl_Fulfillment_Groups",
                tab = ..., tabOrder = ...)
    @OneToMany(mappedBy = "order", targetEntity = OrderAdjustmentImpl.class, cascade = { . },
            orphanRemoval = true)
    @Cache(usage = ., region="blOrderElements")
    @AdminPresentationCollection(friendlyName="OrderImpl_Adjustments",
                tab = ..., tabOrder = ...,
                order = ..)
    @ManyToMany(fetch = ., targetEntity = OfferCodeImpl.class)
    @JoinTable(name = "BLC_ORDER_OFFER_CODE_XREF", joinColumns = @JoinColumn(name = "ORDER_ID",
            referencedColumnName = "ORDER_ID"), inverseJoinColumns = @JoinColumn(name = "OFFER_CODE_ID",
            referencedColumnName = "OFFER_CODE_ID"))
    @Cache(usage = ., region="blOrderElements")
    @AdminPresentationCollection(friendlyName="OrderImpl_Offer_Codes",
                tab = ..., tabOrder = ...,
                manyToField = "orders", order = ..)
    protected List<OfferCodeaddedOfferCodes = new ArrayList<OfferCode>();
    @OneToMany(mappedBy = "order", targetEntity = CandidateOrderOfferImpl.class, cascade = { . },
            orphanRemoval = true)
    @Cache(usage = ., region="blOrderElements")
    @OneToMany(mappedBy = "order", targetEntity = OrderPaymentImpl.class, cascade = {..})
    @Cache(usage = ., region="blOrderElements")
    @AdminPresentationCollection(friendlyName="OrderImpl_Payments",
                tab = ..., tabOrder = ...)
    protected List<OrderPaymentpayments = new ArrayList<OrderPayment>();
    @ManyToMany(targetEntity=OfferInfoImpl.class)
    @JoinTable(name = "BLC_ADDITIONAL_OFFER_INFO", joinColumns = @JoinColumn(name = "BLC_ORDER_ORDER_ID",
            referencedColumnName = "ORDER_ID"), inverseJoinColumns = @JoinColumn(name = "OFFER_INFO_ID",
            referencedColumnName = "OFFER_INFO_ID"))
    @MapKeyJoinColumn(name = "OFFER_ID")
    @MapKeyClass(OfferImpl.class)
    @Cache(usage = ., region="blOrderElements")
    @BatchSize(size = 50)
    @OneToMany(mappedBy = "order", targetEntity = OrderAttributeImpl.class, cascade = { . },
            orphanRemoval = true)
    @Cache(usage=., region="blOrderElements")
    @MapKey(name="name")
    @AdminPresentationMap(friendlyName = "OrderImpl_Attributes",
        forceFreeFormKeys = true, keyPropertyFriendlyName = "OrderImpl_Attributes_Key_Name"
    )
    
    @ManyToOne(targetEntity = BroadleafCurrencyImpl.class)
    @JoinColumn(name = "CURRENCY_CODE")
    @AdminPresentation(excluded = true)
    protected BroadleafCurrency currency;
    @ManyToOne(targetEntity = LocaleImpl.class)
    @JoinColumn(name = "LOCALE_CODE")
    @AdminPresentation(excluded = true)
    protected Locale locale;
    @Column(name = "TAX_OVERRIDE")
    protected Boolean taxOverride;
    @Transient
    @Override
    public Long getId() {
        return ;
    }
    @Override
    public void setId(Long id) {
        this. = id;
    }
    @Override
    public Auditable getAuditable() {
        return ;
    }
    @Override
    public void setAuditable(Auditable auditable) {
        this. = auditable;
    }
    @Override
    public Money getSubTotal() {
        return  == null ? null : BroadleafCurrencyUtils.getMoney(getCurrency());
    }
    @Override
    public void setSubTotal(Money subTotal) {
        this. = Money.toAmount(subTotal);
    }
    @Override
    public Money calculateSubTotal() {
        Money calculatedSubTotal = BroadleafCurrencyUtils.getMoney(getCurrency());
        for (OrderItem orderItem : ) {
            calculatedSubTotal = calculatedSubTotal.add(orderItem.getTotalPrice());
        }
        return calculatedSubTotal;
    }
    @Override
    public void assignOrderItemsFinalPrice() {
        for (OrderItem orderItem : ) {
            orderItem.assignFinalPrice();
        }
    }
    @Override
    public Money getTotal() {
        return  == null ? null : BroadleafCurrencyUtils.getMoney(getCurrency());
    }
    @Override
        Money myTotal = getTotal();
        if (myTotal == null) {
            return null;
        }
        Money totalPayments = BroadleafCurrencyUtils.getMoney(.getCurrency());
        for (OrderPayment payment : getPayments()) {
            if (payment.isActive() && payment.getAmount() != null) {
                totalPayments = totalPayments.add(payment.getAmount());
            }
        }
        return myTotal.subtract(totalPayments);
    }
    @Override
    public void setTotal(Money orderTotal) {
        this. = Money.toAmount(orderTotal);
    }
    @Override
    public Boolean getPreview() {
        if ( == null) {
             = new PreviewStatus();
        }
        return .getPreview();
    }
    @Override
    public void setPreview(Boolean preview) {
        if ( == null) {
             = new PreviewStatus();
        }
        .setPreview(preview);
    }
    @Override
    public Date getSubmitDate() {
        return ;
    }
    @Override
    public void setSubmitDate(Date submitDate) {
        this. = submitDate;
    }
    @Override
    public Customer getCustomer() {
        return ;
    }
    @Override
    public void setCustomer(Customer customer) {
        this. = customer;
    }
    @Override
    public OrderStatus getStatus() {
        return OrderStatus.getInstance();
    }
    @Override
    public void setStatus(OrderStatus status) {
        this. = status.getType();
    }
    @Override
    public List<OrderItemgetOrderItems() {
        return ;
    }
    @Override
    public void setOrderItems(List<OrderItemorderItems) {
        this. = orderItems;
    }
    @Override
    public void addOrderItem(OrderItem orderItem) {
        .add(orderItem);
    }
    @Override
        return ;
    }
    @Override
    public void setFulfillmentGroups(List<FulfillmentGroupfulfillmentGroups) {
        this. = fulfillmentGroups;
    }
    @Override
    public void setCandidateOrderOffers(List<CandidateOrderOffercandidateOrderOffers) {
        this. = candidateOrderOffers;
    }
    @Override
        return ;
    }
    @Override
    public String getName() {
        return ;
    }
    @Override
    public void setName(String name) {
        this. = name;
    }
    @Override
    public Money getTotalTax() {
        return  == null ? null : BroadleafCurrencyUtils.getMoney(getCurrency());
    }
    @Override
    public void setTotalTax(Money totalTax) {
        this. = Money.toAmount(totalTax);
    }
    @Override
    public Money getTotalShipping() {
        return getTotalFulfillmentCharges();
    }
    @Override
    public void setTotalShipping(Money totalShipping) {
        setTotalFulfillmentCharges(totalShipping);
    }
    @Override
    public Money getTotalFulfillmentCharges() {
        return  == null ? null : BroadleafCurrencyUtils.getMoney(,
                getCurrency());
    }
    @Override
    public void setTotalFulfillmentCharges(Money totalFulfillmentCharges) {
        this. = Money.toAmount(totalFulfillmentCharges);
    }
    @Override
    public List<OrderPaymentgetPayments() {
        return ;
    }
    @Override
    public void setPayments(List<OrderPaymentpayments) {
        this. = payments;
    }
    @Override
    public boolean hasCategoryItem(String categoryName) {
        for (OrderItem orderItem : ) {
            if(orderItem.isInCategory(categoryName)) {
                return true;
            }
        }
        return false;
    }
    @Override
        return this.;
    }
    protected void setOrderAdjustments(List<OrderAdjustmentorderAdjustments) {
        this. = orderAdjustments;
    }
    @Override
        List<DiscreteOrderItemdiscreteOrderItems = new ArrayList<DiscreteOrderItem>();
        for (OrderItem orderItem : ) {
            if (orderItem instanceof BundleOrderItem) {
                BundleOrderItemImpl bundleOrderItem = (BundleOrderItemImpl)orderItem;
                for (DiscreteOrderItem discreteOrderItem : bundleOrderItem.getDiscreteOrderItems()) {
                    discreteOrderItems.add(discreteOrderItem);
                }
            } else if (orderItem instanceof DiscreteOrderItem) {
                DiscreteOrderItem discreteOrderItem = (DiscreteOrderItemorderItem;
                discreteOrderItems.add(discreteOrderItem);
            }
        }
        return discreteOrderItems;
    }
    
    @Override
    public boolean containsSku(Sku sku) {
        for (OrderItem orderItem : getOrderItems()) {
            if (orderItem instanceof DiscreteOrderItem) {
                DiscreteOrderItem discreteOrderItem = (DiscreteOrderItemorderItem;
                if (discreteOrderItem.getSku() != null && discreteOrderItem.getSku().equals(sku)) {
                    return true;
                }
            } else if (orderItem instanceof BundleOrderItem) {
                BundleOrderItem bundleOrderItem = (BundleOrderItemorderItem;
                if (bundleOrderItem.getSku() != null && bundleOrderItem.getSku().equals(sku)) {
                    return true;
                }
            }
        }
        
        return false;
    }
    @Override
    public List<OfferCodegetAddedOfferCodes() {
        return ;
    }
    @Override
    public String getOrderNumber() {
        return ;
    }
    @Override
    public void setOrderNumber(String orderNumber) {
        this. = orderNumber;
    }
    @Override
    public String getFulfillmentStatus() {
        return null;
    }
    @Override
    public String getEmailAddress() {
        return ;
    }
    @Override
    public void setEmailAddress(String emailAddress) {
        this. = emailAddress;
    }
    @Override
        return ;
    }
    @Override
    public void setAdditionalOfferInformation(Map<OfferOfferInfoadditionalOfferInformation) {
        this. = additionalOfferInformation;
    }
    @Override
    public Money getItemAdjustmentsValue() {
        Money itemAdjustmentsValue = BroadleafCurrencyUtils.getMoney(.getCurrency());
        for (OrderItem orderItem : ) {
            itemAdjustmentsValue = itemAdjustmentsValue.add(orderItem.getTotalAdjustmentValue());
        }
        return itemAdjustmentsValue;
    }
    
    @Override
        Money adjustmentValue = BroadleafCurrencyUtils.getMoney(.getCurrency());
        for (FulfillmentGroup fulfillmentGroup : ) {
            adjustmentValue = adjustmentValue.add(fulfillmentGroup.getFulfillmentGroupAdjustmentsValue());
        }
        return adjustmentValue;
    }
    @Override
    public Money getOrderAdjustmentsValue() {
        Money orderAdjustmentsValue = BroadleafCurrencyUtils.getMoney(.getCurrency());
        for (OrderAdjustment orderAdjustment : ) {
            orderAdjustmentsValue = orderAdjustmentsValue.add(orderAdjustment.getValue());
        }
        return orderAdjustmentsValue;
    }
    @Override
    public Money getTotalAdjustmentsValue() {
        Money totalAdjustmentsValue = getItemAdjustmentsValue();
        totalAdjustmentsValue = totalAdjustmentsValue.add(getOrderAdjustmentsValue());
        totalAdjustmentsValue = totalAdjustmentsValue.add(getFulfillmentGroupAdjustmentsValue());
        return totalAdjustmentsValue;
    }
    @Override
    public boolean updatePrices() {
        boolean updated = false;
        for (OrderItem orderItem : ) {
            if (orderItem.updateSaleAndRetailPrices()) {
                updated = true;
            }
        }
        return updated;
    }
    @Override
    public boolean finalizeItemPrices() {
        boolean updated = false;
        for (OrderItem orderItem : ) {
            orderItem.finalizePrice();
        }
        return updated;
    }
    @Override
        return ;
    }
    @Override
    public void setOrderAttributes(Map<StringOrderAttributeorderAttributes) {
        this. = orderAttributes;
    }
    @Override
    @Deprecated
    public void addAddedOfferCode(OfferCode offerCode) {
        addOfferCode(offerCode);
    }
    
    @Override
    public void addOfferCode(OfferCode offerCode) {
        getAddedOfferCodes().add(offerCode);
    }
    
    @Override
    public BroadleafCurrency getCurrency() {
        return ;
    }
    @Override
    public void setCurrency(BroadleafCurrency currency) {
        this. = currency;
    }
    @Override
    public Locale getLocale() {
        return ;
    }
    @Override
    public void setLocale(Locale locale) {
        this. = locale;
    }
    
    @Override
    public Boolean getTaxOverride() {
        return  == null ? false : ;
    }
    @Override
    public void setTaxOverride(Boolean taxOverride) {
        this. = taxOverride;
    }
    @Override
    public int getItemCount() {
        int count = 0;
        for (DiscreteOrderItem doi : getDiscreteOrderItems()) {
            count += doi.getQuantity();
        }
        return count;
    }
    @Override
    public boolean getHasOrderAdjustments() {
        Money orderAdjustmentsValue = getOrderAdjustmentsValue();
        if (orderAdjustmentsValue != null) {
            return (orderAdjustmentsValue.compareTo(.) != 0);
        }
        return false;
    }
    @Override
    public String getMainEntityName() {
        String customerName = null;
        String orderNumber = getOrderNumber();
        if (!StringUtils.isEmpty(getCustomer().getFirstName()) && !StringUtils.isEmpty(getCustomer().getLastName())) {
            customerName = getCustomer().getFirstName() + " " + getCustomer().getLastName();
        }
        if (!StringUtils.isEmpty(orderNumber) && !StringUtils.isEmpty(customerName)) {
            return orderNumber + " - " + customerName;
        }
        if (!StringUtils.isEmpty(orderNumber)) {
            return orderNumber;
        }
        if (!StringUtils.isEmpty(customerName)) {
            return customerName;
        }
        return "";
    }
    @Override
    public String getCurrencyCode() {
        if (getCurrency() != null) {
            return getCurrency().getCurrencyCode();
        }
        return null;
    }
    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        OrderImpl other = (OrderImplobj;
        if ( != null && other.id != null) {
            return .equals(other.id);
        }
        if ( == null) {
            if (other.customer != null) {
                return false;
            }
        } else if (!.equals(other.customer)) {
            return false;
        }
        Date myDateCreated =  != null ? .getDateCreated() : null;
        Date otherDateCreated = other.auditable != null ? other.auditable.getDateCreated() : null;
        if (myDateCreated == null) {
            if (otherDateCreated != null) {
                return false;
            }
        } else if (!myDateCreated.equals(otherDateCreated)) {
            return false;
        }
        return true;
    }
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = super.hashCode();
        result = prime * result + (( == null) ? 0 : .hashCode());
        Date myDateCreated =  != null ? .getDateCreated() : null;
        result = prime * result + ((myDateCreated == null) ? 0 : myDateCreated.hashCode());
        return result;
    }
    @Override
        if (this. == null) {
            this. = new ArrayList<ActivityMessageDTO>();
        }
        return this.;
    }
    @Override
    public void setOrderMessages(List<ActivityMessageDTOorderMessages) {
        this. = orderMessages;
    }
    public static class Presentation {
        public static class Tab {
            public static class Name {
                public static final String OrderItems = "OrderImpl_Order_Items_Tab";
                public static final String FulfillmentGroups = "OrderImpl_Fulfillment_Groups_Tab";
                public static final String Payment = "OrderImpl_Payment_Tab";
                public static final String Advanced = "OrderImpl_Advanced_Tab";
            }
            public static class Order {
                public static final int OrderItems = 2000;
                public static final int FulfillmentGroups = 3000;
                public static final int Payment = 4000;
                public static final int Advanced = 5000;
            }
        }
        public static class Group {
            public static class Name {
                public static final String General = "OrderImpl_Order";
            }
            public static class Order {
                public static final int General = 1000;
            }
        }
        public static class FieldOrder {
            public static final int NAME = 1000;
            public static final int CUSTOMER = 2000;
            public static final int TOTAL = 3000;
            public static final int STATUS = 4000;
            public static final int SUBTOTAL = 5000;
            public static final int ORDERNUMBER = 6000;
            public static final int TOTALTAX = 7000;
            public static final int TOTALFGCHARGES = 8000;
            public static final int SUBMITDATE = 9000;
            public static final int EMAILADDRESS = 10000;
            public static final int ADJUSTMENTS = 1000;
            public static final int OFFERCODES = 2000;
        }
    }