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.service;
 
 
 import java.util.List;
 import java.util.Map;
 

Author(s):
Andre Azzolini (apazzolini)
 
 @Service("blOrderMultishipOptionService")
 
     @Resource(name = "blOrderMultishipOptionDao")
     
     @Resource(name = "blAddressService")
     protected AddressService addressService;
     
     @Resource(name = "blOrderItemService")
     protected OrderItemService orderItemService;
     
     @Resource(name = "blFulfillmentOptionService")
     
     @Resource(name = "blFulfillmentGroupService")
 
     @Override
     public OrderMultishipOption save(OrderMultishipOption orderMultishipOption) {
         return .save(orderMultishipOption);
     }
 
     @Override
         return .readOrderMultishipOptions(orderId);
     }
     
     @Override
         return .readOrderItemOrderMultishipOptions(orderItemId);
     }
     
     @Override
     public OrderMultishipOption create() {
         return .create();
     }
     
     @Override
     public void deleteOrderItemOrderMultishipOptions(Long orderItemId) {
         List<OrderMultishipOptionoptions = findOrderItemOrderMultishipOptions(orderItemId);
         .deleteAll(options);
     }
     
     @Override
     public void deleteOrderItemOrderMultishipOptions(Long orderItemIdint numToDelete) {
         List<OrderMultishipOptionoptions = findOrderItemOrderMultishipOptions(orderItemId);
         numToDelete = (numToDelete > options.size()) ? options.size() : numToDelete;
         options = options.subList(0, numToDelete);
         .deleteAll(options);
     }
     
     @Override
     public void deleteAllOrderMultishipOptions(Order order) {
         List<OrderMultishipOptionoptions = findOrderMultishipOptions(order.getId());
         .deleteAll(options);
     }
    
    @Override
    public void saveOrderMultishipOptions(Order orderList<OrderMultishipOptionDTOoptionDTOs) {
        Map<LongOrderMultishipOptioncurrentOptions = new HashMap<LongOrderMultishipOption>();
        for (OrderMultishipOption option : findOrderMultishipOptions(order.getId())) {
            currentOptions.put(option.getId(), option);
        }
        
        List<OrderMultishipOptionorderMultishipOptions = new ArrayList<OrderMultishipOption>();
        for (OrderMultishipOptionDTO dtooptionDTOs) {
            OrderMultishipOption option = currentOptions.get(dto.getId());
            if (option == null) {
                option = .create();
            }
            
            option.setOrder(order);
            option.setOrderItem(.readOrderItemById(dto.getOrderItemId()));
            
            if (dto.getAddressId() != null) {
                option.setAddress(.readAddressById(dto.getAddressId()));
            } else {
                option.setAddress(null);
            }
            
            if (dto.getFulfillmentOptionId() != null) {
            } else {
                option.setFulfillmentOption(null);
            }
            
            orderMultishipOptions.add(option);
        }
        
        for (OrderMultishipOption option : orderMultishipOptions) {
            save(option);
        }
    }
    
    @Override
        List<OrderMultishipOptionorderMultishipOptions = findOrderMultishipOptions(order.getId());
        if (orderMultishipOptions == null || orderMultishipOptions.size() == 0) {
            orderMultishipOptions = generateOrderMultishipOptions(order);
        }
        
        // Create a map representing the current discrete order item counts for the order
        Map<LongIntegerorderDiscreteOrderItemCounts = new HashMap<LongInteger>();
        for (DiscreteOrderItem item : order.getDiscreteOrderItems()) {
            orderDiscreteOrderItemCounts.put(item.getId(), item.getQuantity());
        }
        
        List<OrderMultishipOptionoptionsToRemove = new ArrayList<OrderMultishipOption>();
        for (OrderMultishipOption option : orderMultishipOptions) {
            Integer count = orderDiscreteOrderItemCounts.get(option.getOrderItem().getId());
            if (count == null || count == 0) {
                optionsToRemove.add(option);
            } else {
                count--;
                orderDiscreteOrderItemCounts.put(option.getOrderItem().getId(), count);
            }
        }
        
        for (Entry<LongIntegerentry : orderDiscreteOrderItemCounts.entrySet()) {
            DiscreteOrderItem item = (DiscreteOrderItem.readOrderItemById(entry.getKey());
            orderMultishipOptions.addAll(createPopulatedOrderMultishipOption(orderitementry.getValue()));
        }
        
        orderMultishipOptions.removeAll(optionsToRemove);
        .deleteAll(optionsToRemove);
        
        return orderMultishipOptions;
    }
    
    @Override
        List<OrderMultishipOptionorderMultishipOptions = new ArrayList<OrderMultishipOption>();
        for (OrderMultishipOptionDTO optionDto : optionDtos) {
            OrderMultishipOption option = new OrderMultishipOptionImpl();
            if (optionDto.getAddressId() != null) {
                option.setAddress(.readAddressById(optionDto.getAddressId()));
            }   
            if (optionDto.getFulfillmentOptionId() != null) {
            }
            option.setId(optionDto.getId());
            option.setOrder(order);
            option.setOrderItem(.readOrderItemById(optionDto.getOrderItemId()));
            orderMultishipOptions.add(option);
        }
        return orderMultishipOptions;
    }
    
    @Override
        List<OrderMultishipOptionorderMultishipOptions = new ArrayList<OrderMultishipOption>();
        for (DiscreteOrderItem discreteOrderItem : order.getDiscreteOrderItems()) {
            orderMultishipOptions.addAll(createPopulatedOrderMultishipOption(orderdiscreteOrderItemdiscreteOrderItem.getQuantity()));
        }
        
        return orderMultishipOptions;
    }
    
        List<OrderMultishipOptionorderMultishipOptions = new ArrayList<OrderMultishipOption>();
            return orderMultishipOptions;
        }
        for (int i = 0; i < quantityi++) {
            OrderMultishipOption orderMultishipOption = new OrderMultishipOptionImpl();
            orderMultishipOption.setOrder(order);
            orderMultishipOption.setOrderItem(item);
            orderMultishipOptions.add(orderMultishipOption);
        }
        return orderMultishipOptions;
    }
New to GrepCode? Check out our FAQ X