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.pricing.service.workflow;
 
 import org.mvel2.MVEL;
 
 import java.util.List;
 import java.util.Map;
 

Author(s):
Phillip Verheyden
 
     
     @SuppressWarnings("unchecked")
     protected static final Map EXPRESSION_CACHE = Collections.synchronizedMap(new LRUMap(1000));
     
     @Resource(name = "blFulfillmentGroupService")
 
     @Override
     public ProcessContext<Orderexecute(ProcessContext<Ordercontextthrows Exception {
         Order order = context.getSeedData();
         
         for (FulfillmentGroup fulfillmentGroup : order.getFulfillmentGroups()) {
             //create and associate all the Fulfillment Fees
             for (FulfillmentGroupItem item : fulfillmentGroup.getFulfillmentGroupItems()) {
                 List<SkuFeefees = null;
                 if (item.getOrderItem() instanceof BundleOrderItem) {
                     fees = ((BundleOrderItem)item.getOrderItem()).getSku().getFees();
                 } else if (item.getOrderItem() instanceof DiscreteOrderItem) {
                     fees = ((DiscreteOrderItem)item.getOrderItem()).getSku().getFees();
                 }
                 
                 if (fees != null) {
                     for (SkuFee fee : fees) {
                         if (..equals(fee.getFeeType())) {
                             if (shouldApplyFeeToFulfillmentGroup(feefulfillmentGroup)) {
                                 FulfillmentGroupFee fulfillmentFee = .createFulfillmentGroupFee();
                                 fulfillmentFee.setName(fee.getName());
                                 fulfillmentFee.setTaxable(fee.getTaxable());
                                 fulfillmentFee.setAmount(fee.getAmount());
                                 fulfillmentFee.setFulfillmentGroup(fulfillmentGroup);
                                 
                                 fulfillmentGroup.addFulfillmentGroupFee(fulfillmentFee);
                             }
                         }
                     }
                 }
             }
             
             if (fulfillmentGroup.getFulfillmentGroupFees().size() > 0) {
                 fulfillmentGroup = .save(fulfillmentGroup);
             }
         }
         
         context.setSeedData(order);
         return context;
     }

    
If the SkuFee expression is null or empty, this method will always return true

Parameters:
fee
fulfillmentGroup
Returns:
    protected boolean shouldApplyFeeToFulfillmentGroup(SkuFee feeFulfillmentGroup fulfillmentGroup) {
        boolean appliesToFulfillmentGroup = true;
        String feeExpression = fee.getExpression();
        
        if (!StringUtils.isEmpty(feeExpression)) {
            Serializable exp = (Serializable.get(feeExpression);
            if (exp == null) {
                ParserContext mvelContext = new ParserContext();
                mvelContext.addImport("MVEL"MVEL.class);
                mvelContext.addImport("MvelHelper"MvelHelper.class);
                exp = MVEL.compileExpression(feeExpressionmvelContext);
            
                .put(feeExpressionexp);
            }
            HashMap<StringObjectvars = new HashMap<StringObject>();
            vars.put("fulfillmentGroup"fulfillmentGroup);
            return (Boolean)MVEL.executeExpression(feeExpressionvars);
        }
        
        return appliesToFulfillmentGroup;
    }
New to GrepCode? Check out our FAQ X