Пример #1
0
  private void activateOrChange(
      RulesProfile profile, ActiveRule parentActiveRule, String userName) {
    ActiveRule oldActiveRule = profile.getActiveRule(parentActiveRule.getRule());
    if (oldActiveRule != null) {
      if (oldActiveRule.isInherited()) {
        removeActiveRule(profile, oldActiveRule);
      } else {
        oldActiveRule.setInheritance(ActiveRule.OVERRIDES);
        getSession().saveWithoutFlush(oldActiveRule);
        return; // no need to change in children
      }
    }
    ActiveRule newActiveRule = (ActiveRule) parentActiveRule.clone();
    newActiveRule.setRulesProfile(profile);
    newActiveRule.setInheritance(ActiveRule.INHERITED);
    profile.addActiveRule(newActiveRule);
    getSession().saveWithoutFlush(newActiveRule);

    if (oldActiveRule != null) {
      ruleChanged(profile, oldActiveRule, newActiveRule, userName);
    } else {
      ruleEnabled(profile, newActiveRule, userName);
    }

    for (RulesProfile child : getChildren(profile)) {
      activateOrChange(child, newActiveRule, userName);
    }
  }
Пример #2
0
 private void importActiveRules(RulesDao rulesDao, RulesProfile profile) {
   for (Iterator<ActiveRule> iar = profile.getActiveRules(true).iterator(); iar.hasNext(); ) {
     ActiveRule activeRule = iar.next();
     Rule unMarshalledRule = activeRule.getRule();
     Rule matchingRuleInDb =
         rulesDao.getRuleByKey(unMarshalledRule.getRepositoryKey(), unMarshalledRule.getKey());
     if (matchingRuleInDb == null) {
       LoggerFactory.getLogger(getClass())
           .error(
               "Unable to find active rule "
                   + unMarshalledRule.getRepositoryKey()
                   + ":"
                   + unMarshalledRule.getKey());
       iar.remove();
       continue;
     }
     activeRule.setRule(matchingRuleInDb);
     activeRule.setRulesProfile(profile);
     activeRule.getActiveRuleParams();
     for (Iterator<ActiveRuleParam> irp = activeRule.getActiveRuleParams().iterator();
         irp.hasNext(); ) {
       ActiveRuleParam activeRuleParam = irp.next();
       RuleParam unMarshalledRP = activeRuleParam.getRuleParam();
       RuleParam matchingRPInDb = rulesDao.getRuleParam(matchingRuleInDb, unMarshalledRP.getKey());
       if (matchingRPInDb == null) {
         LoggerFactory.getLogger(getClass())
             .error("Unable to find active rule parameter " + unMarshalledRP.getKey());
         irp.remove();
         continue;
       }
       activeRuleParam.setActiveRule(activeRule);
       activeRuleParam.setRuleParam(matchingRPInDb);
     }
   }
 }
Пример #3
0
  public void revert(int profileId, int activeRuleId, String userName) {
    RulesProfile profile = getSession().getEntity(RulesProfile.class, profileId);
    ActiveRule oldActiveRule = getSession().getEntity(ActiveRule.class, activeRuleId);
    if (oldActiveRule != null && oldActiveRule.doesOverride()) {
      ActiveRule parentActiveRule =
          getParentProfile(profile).getActiveRule(oldActiveRule.getRule());
      removeActiveRule(profile, oldActiveRule);
      ActiveRule newActiveRule = (ActiveRule) parentActiveRule.clone();
      newActiveRule.setRulesProfile(profile);
      newActiveRule.setInheritance(ActiveRule.INHERITED);
      profile.addActiveRule(newActiveRule);
      getSession().saveWithoutFlush(newActiveRule);

      // Compute change
      ruleChanged(profile, oldActiveRule, newActiveRule, userName);

      for (RulesProfile child : getChildren(profile)) {
        activateOrChange(child, newActiveRule, userName);
      }

      getSession().commit();
    }
  }