Beispiel #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);
    }
  }
Beispiel #2
0
 public ValidationMessages changeParentProfile(
     Integer profileId, String parentName, String userName) {
   ValidationMessages messages = ValidationMessages.create();
   RulesProfile profile = getSession().getEntity(RulesProfile.class, profileId);
   if (profile != null && !profile.getProvided()) {
     RulesProfile oldParent = getParentProfile(profile);
     RulesProfile newParent = getProfile(profile.getLanguage(), parentName);
     if (isCycle(profile, newParent)) {
       messages.addWarningText("Please do not select a child profile as parent.");
       return messages;
     }
     // Deactivate all inherited rules
     if (oldParent != null) {
       for (ActiveRule activeRule : oldParent.getActiveRules()) {
         deactivate(profile, activeRule.getRule(), userName);
       }
     }
     // Activate all inherited rules
     if (newParent != null) {
       for (ActiveRule activeRule : newParent.getActiveRules()) {
         activateOrChange(profile, activeRule, userName);
       }
     }
     profile.setParentName(newParent == null ? null : newParent.getName());
     getSession().saveWithoutFlush(profile);
     getSession().commit();
   }
   return messages;
 }
Beispiel #3
0
 /** Rule was activated/changed in parent profile. */
 private void activatedOrChanged(int parentProfileId, int activeRuleId, String userName) {
   ActiveRule parentActiveRule = getSession().getEntity(ActiveRule.class, activeRuleId);
   if (parentActiveRule.isInherited()) {
     parentActiveRule.setInheritance(ActiveRule.OVERRIDES);
     getSession().saveWithoutFlush(parentActiveRule);
   }
   for (RulesProfile child : getChildren(parentProfileId)) {
     activateOrChange(child, parentActiveRule, userName);
   }
   getSession().commit();
 }
Beispiel #4
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();
    }
  }