/** Deal with creation of ActiveRuleChange item when a rule is enabled on a profile */ private void ruleEnabled(RulesProfile profile, ActiveRule newActiveRule, String userName) { incrementProfileVersionIfNeeded(profile); ActiveRuleChange rc = new ActiveRuleChange(userName, profile, newActiveRule.getRule()); rc.setEnabled(true); rc.setNewSeverity(newActiveRule.getSeverity()); if (newActiveRule.getRule().getParams() != null) { for (RuleParam p : newActiveRule.getRule().getParams()) { String newParam = newActiveRule.getParameter(p.getKey()); if (newParam != null) { rc.setParameterChange(p.getKey(), null, newParam); } } } getSession().saveWithoutFlush(rc); }
/** Deal with creation of ActiveRuleChange item when a rule is disabled on a profile */ private void ruleDisabled(RulesProfile profile, ActiveRule disabledRule, String userName) { incrementProfileVersionIfNeeded(profile); ActiveRuleChange rc = new ActiveRuleChange(userName, profile, disabledRule.getRule()); rc.setEnabled(false); rc.setOldSeverity(disabledRule.getSeverity()); if (disabledRule.getRule().getParams() != null) { for (RuleParam p : disabledRule.getRule().getParams()) { String oldParam = disabledRule.getParameter(p.getKey()); if (oldParam != null) { rc.setParameterChange(p.getKey(), oldParam, null); } } } getSession().saveWithoutFlush(rc); }
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); } }
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; }
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); } } }
/** Rule was deactivated in parent profile. */ public void deactivated(int parentProfileId, int deactivatedRuleId, String userName) { ActiveRule parentActiveRule = getSession().getEntity(ActiveRule.class, deactivatedRuleId); RulesProfile profile = getSession().getEntity(RulesProfile.class, parentProfileId); ruleDisabled(profile, parentActiveRule, userName); for (RulesProfile child : getChildren(parentProfileId)) { deactivate(child, parentActiveRule.getRule(), userName); } getSession().commit(); }
/** * Deal with creation of ActiveRuleChange item when a rule is changed (severity and/or param(s)) * on a profile */ private void ruleChanged( RulesProfile profile, ActiveRule oldActiveRule, ActiveRule newActiveRule, String userName) { incrementProfileVersionIfNeeded(profile); ActiveRuleChange rc = new ActiveRuleChange(userName, profile, newActiveRule.getRule()); if (oldActiveRule.getSeverity() != newActiveRule.getSeverity()) { rc.setOldSeverity(oldActiveRule.getSeverity()); rc.setNewSeverity(newActiveRule.getSeverity()); } if (oldActiveRule.getRule().getParams() != null) { for (RuleParam p : oldActiveRule.getRule().getParams()) { String oldParam = oldActiveRule.getParameter(p.getKey()); String newParam = newActiveRule.getParameter(p.getKey()); if (!StringUtils.equals(oldParam, newParam)) { rc.setParameterChange(p.getKey(), oldParam, newParam); } } } getSession().saveWithoutFlush(rc); }
/** Rule severity was changed */ public void ruleSeverityChanged( int profileId, int activeRuleId, RulePriority oldSeverity, RulePriority newSeverity, String userName) { ActiveRule activeRule = getSession().getEntity(ActiveRule.class, activeRuleId); RulesProfile profile = getSession().getEntity(RulesProfile.class, profileId); ruleSeverityChanged(profile, activeRule.getRule(), oldSeverity, newSeverity, userName); // Notify child profiles activatedOrChanged(profileId, activeRuleId, userName); }
/** Rule param was changed */ public void ruleParamChanged( int profileId, int activeRuleId, String paramKey, String oldValue, String newValue, String userName) { ActiveRule activeRule = getSession().getEntity(ActiveRule.class, activeRuleId); RulesProfile profile = getSession().getEntity(RulesProfile.class, profileId); ruleParamChanged(profile, activeRule.getRule(), paramKey, oldValue, newValue, userName); // Notify child profiles activatedOrChanged(profileId, activeRuleId, userName); }
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(); } }