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.dao;
 
 
 import java.util.List;
 
 @Repository("blOrderDao")
 public class OrderDaoImpl implements OrderDao {
 
     @PersistenceContext(unitName = "blPU")
     protected EntityManager em;
 
     @Resource(name = "blEntityConfiguration")
 
     @Resource(name = "blCustomerDao")
     protected CustomerDao customerDao;
 
     @Resource(name = "blOrderDaoExtensionManager")
 
     @Override
     public Order readOrderById(final Long orderId) {
         return .find(OrderImpl.classorderId);
     }
 
     @Override
     public Order save(final Order order) {
         Order response = .merge(order);
         //em.flush();
         return response;
     }
 
     @Override
     public void delete(Order salesOrder) {
         if (!.contains(salesOrder)) {
             salesOrder = readOrderById(salesOrder.getId());
         }
 
         //need to null out the reference to the Order for all the OrderPayments
         //as they are not deleted but Archived.
         for (OrderPayment payment : salesOrder.getPayments()) {
             payment.setOrder(null);
             payment.setArchived('Y');
             for (PaymentTransaction transaction : payment.getTransactions()) {
                 transaction.setArchived('Y');
             }
         }
 
         .remove(salesOrder);
     }
 
     @Override
     @SuppressWarnings("unchecked")
     public List<OrderreadOrdersForCustomer(final Customer customerfinal OrderStatus orderStatus) {
         if (orderStatus == null) {
             return readOrdersForCustomer(customer.getId());
         } else {
             final Query query = .createNamedQuery("BC_READ_ORDERS_BY_CUSTOMER_ID_AND_STATUS");
             query.setParameter("customerId"customer.getId());
             query.setParameter("orderStatus"orderStatus.getType());
             return query.getResultList();
         }
     }
    @Override
    @SuppressWarnings("unchecked")
    public List<OrderreadOrdersForCustomer(final Long customerId) {
        final Query query = .createNamedQuery("BC_READ_ORDERS_BY_CUSTOMER_ID");
        query.setParameter("customerId"customerId);
        return query.getResultList();
    }
    @Override
    public Order readCartForCustomer(final Customer customer) {
        Order order = null;
        final Query query = .createNamedQuery("BC_READ_ORDERS_BY_CUSTOMER_ID_AND_NAME_NULL");
        query.setParameter("customerId"customer.getId());
        query.setParameter("orderStatus"..getType());
        query.setHint(.true);
        query.setHint(."query.Order");
        @SuppressWarnings("rawtypes")
        final List temp = query.getResultList();
        if (temp != null && !temp.isEmpty()) {
            order = (Ordertemp.get(0);
        }
        return order;
    }
    @Override
    public Order createNewCartForCustomer(Customer customer) {
        Order order = create();
        if (customer.getUsername() == null) {
            customer.setUsername(String.valueOf(customer.getId()));
            if (.readCustomerById(customer.getId()) != null) {
                throw new IllegalArgumentException("Attempting to save a customer with an id (" + customer.getId() + ") " +
                        "that already exists in the database. This can occur when legacy customers have been migrated to " +
                        "Broadleaf customers, but the batchStart setting has not been declared for id generation. In " +
                        "such a case, the defaultBatchStart property of IdGenerationDaoImpl (spring id of " +
                        "blIdGenerationDao) should be set to the appropriate start value.");
            }
            customer = .save(customer);
        }
        order.setCustomer(customer);
        order.setEmailAddress(customer.getEmailAddress());
        order.setStatus(.);
        if (BroadleafRequestContext.getBroadleafRequestContext() != null) {
            order.setCurrency(BroadleafRequestContext.getBroadleafRequestContext().getBroadleafCurrency());
            order.setLocale(BroadleafRequestContext.getBroadleafRequestContext().getLocale());
        }
        if ( != null) {
            .getProxy().attachAdditionalDataToNewCart(customerorder);
        }
        
        order = save(order);
        if ( != null) {
            .getProxy().processPostSaveNewCart(customerorder);
        }
        return order;
    }
    @Override
    public Order submitOrder(final Order cartOrder) {
        cartOrder.setStatus(.);
        return save(cartOrder);
    }
    @Override
    public Order create() {
        final Order order = ((Order.createEntityInstance("org.broadleafcommerce.core.order.domain.Order"));
        return order;
    }
    @Override
    @SuppressWarnings("unchecked")
    public Order readNamedOrderForCustomer(final Customer customerfinal String name) {
        final Query query = .createNamedQuery("BC_READ_NAMED_ORDER_FOR_CUSTOMER");
        query.setParameter("customerId"customer.getId());
        query.setParameter("orderStatus"..getType());
        query.setParameter("orderName"name);
        List<Orderorders = query.getResultList();
        
        // Filter out orders that don't match the current locale (if one is set)
        if (BroadleafRequestContext.getBroadleafRequestContext() != null) {
            ListIterator<Orderiter = orders.listIterator();
            while (iter.hasNext()) {
                Locale locale = BroadleafRequestContext.getBroadleafRequestContext().getLocale();
                Order order = iter.next();
                if (locale != null && !locale.equals(order.getLocale())) {
                    iter.remove();
                }
            }
        }
            
        // Apply any additional filters that extension modules have registered
        if (orders != null && !orders.isEmpty() &&  != null) {
            .getProxy().applyAdditionalOrderLookupFilter(customernameorders);
        }
        
        return orders == null || orders.isEmpty() ? null : orders.get(0);
    }
    @Override
    @SuppressWarnings("unchecked")
    public Order readOrderByOrderNumber(final String orderNumber) {
        if (orderNumber == null || "".equals(orderNumber)) {
            return null;
        }
        final Query query = .createNamedQuery("BC_READ_ORDER_BY_ORDER_NUMBER");
        query.setParameter("orderNumber"orderNumber);
        List<Orderorders = query.getResultList();
        return orders == null || orders.isEmpty() ? null : orders.get(0);
    }
    @Override
    public Order updatePrices(Order order) {
        order = .merge(order);
        if (order.updatePrices()) {
            order = save(order);
        }
        return order;
    }
New to GrepCode? Check out our FAQ X