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); } } }
/** 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); }
/** 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); }
public RuleParam getParam(String key) { for (RuleParam param : params) { if (StringUtils.equals(key, param.getKey())) { return param; } } return null; }
/** * 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); }
private static void processParameter(Rule rule, SMInputCursor ruleC) throws XMLStreamException { RuleParam param = rule.createParameter(); String keyAttribute = ruleC.getAttrValue("key"); if (StringUtils.isNotBlank(keyAttribute)) { /* BACKWARD COMPATIBILITY WITH DEPRECATED FORMAT */ param.setKey(StringUtils.trim(keyAttribute)); } String typeAttribute = ruleC.getAttrValue("type"); if (StringUtils.isNotBlank(typeAttribute)) { /* BACKWARD COMPATIBILITY WITH DEPRECATED FORMAT */ param.setType(type(StringUtils.trim(typeAttribute))); } SMInputCursor paramC = ruleC.childElementCursor(); while (paramC.getNext() != null) { String propNodeName = paramC.getLocalName(); String propText = StringUtils.trim(paramC.collectDescendantText(false)); if (StringUtils.equalsIgnoreCase("key", propNodeName)) { param.setKey(propText); } else if (StringUtils.equalsIgnoreCase("description", propNodeName)) { param.setDescription(propText); } else if (StringUtils.equalsIgnoreCase("type", propNodeName)) { param.setType(type(propText)); } else if (StringUtils.equalsIgnoreCase("defaultValue", propNodeName)) { param.setDefaultValue(propText); } } if (Strings.isNullOrEmpty(param.getKey())) { throw new SonarException("Node <key> is missing in <param>"); } }