/**
  * Update a given promotion rule with conditions cleanup.
  *
  * @param promotionRule promotion rule to update
  * @return updated promotion rule
  */
 public Rule updatePromotionRuleWithConditionsCleanup(final Rule promotionRule) {
   if (promotionRule.getSellingContext() != null) {
     SellingContext sellingContext =
         sellingContextService.getByGuid(promotionRule.getSellingContext().getGuid());
     for (ConditionalExpression conditionalExpression : sellingContext.getConditions().values()) {
       tagConditionService.delete(conditionalExpression);
     }
   }
   Rule updatedPromotionRule = ruleService.update(promotionRule);
   ruleEngine.recompileRuleBase();
   return updatedPromotionRule;
 }
  @Override
  protected List<Rule> findByIDs(final List<Long> subList) {
    // values retrieved in bulk from the database
    final List<Rule> retrivedFronDb = ruleService.findByUids(subList);

    // we have to order the values based on the values in subList, due to the promotion dependency
    // which needs to have the dependent object after the non-depend ones
    final Comparator<Rule> comparator =
        new Comparator<Rule>() {
          @Override
          public int compare(final Rule rule1, final Rule rule2) {
            Integer postion1 = subList.indexOf(rule1.getUidPk());
            Integer position2 = subList.indexOf(rule2.getUidPk());
            return postion1.compareTo(position2);
          }
        };

    Collections.sort(retrivedFronDb, comparator);
    return retrivedFronDb;
  }
 /**
  * Update a given promotion rule.
  *
  * @param promotionRule promotion rule to update
  * @return updated promotion rule
  */
 public Rule updatePromotionRule(final Rule promotionRule) {
   Rule updatedPromotionRule = ruleService.update(promotionRule);
   ruleEngine.recompileRuleBase();
   return updatedPromotionRule;
 }
 /**
  * Returns a shopping cart promotion with the given name.
  *
  * @param promotionName the promotion name
  * @return rule with the given name.
  */
 public Rule findShoppingCartPromotionByName(final String promotionName) {
   return ruleService.findByName(promotionName);
 }
 /**
  * Save configured rule into a database.
  *
  * @param promotionRule to be saved
  * @return persisted rule
  */
 public Rule persistPromotionRule(final Rule promotionRule) {
   Rule persistedPromotionRule = ruleService.add(promotionRule);
   ruleEngine.recompileRuleBase();
   return persistedPromotionRule;
 }
 /**
  * The dependent promotions should be exported before, so at the import the depend will already be
  * in the database.
  *
  * @param ruleUidList - the rules that need to be chaked that are dependent on other promotions
  * @return all the promotion that will be exported in a specific order
  */
 private Set<Long> retriveDependentRulesAndInsertThemBefore(final List<Long> ruleUidList) {
   return ruleService.retrievePromotionDependencies(new LinkedHashSet<Long>(ruleUidList));
 }