Пример #1
0
  private List<ProfileDefinition> loadFromDeprecatedRepository(RulesRepository repository) {
    List<ProfileDefinition> result = new ArrayList<ProfileDefinition>();

    for (int index = 0; index < repository.getProvidedProfiles().size(); index++) {
      RulesProfile deprecated = (RulesProfile) repository.getProvidedProfiles().get(index);
      DefaultProfileDefinition providedProfile =
          DefaultProfileDefinition.create(deprecated.getName(), repository.getLanguage().getKey());
      for (ActiveRule deprecatedActiveRule : deprecated.getActiveRules(true)) {
        String repositoryKey = deprecatedActiveRule.getRepositoryKey();
        if (StringUtils.isBlank(repositoryKey)) {
          repositoryKey = getPluginKey(repository);
        }
        Rule rule = ruleFinder.findByKey(repositoryKey, deprecatedActiveRule.getRuleKey());
        if (rule != null) {
          ActiveRule activeRule =
              providedProfile.activateRule(rule, deprecatedActiveRule.getSeverity());
          for (ActiveRuleParam arp : deprecatedActiveRule.getActiveRuleParams()) {
            activeRule.setParameter(arp.getKey(), arp.getValue());
          }
        }
      }
      result.add(providedProfile);
    }
    return result;
  }
Пример #2
0
  /**
   * 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);
  }
Пример #3
0
 /** 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);
 }
Пример #4
0
 /** 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);
 }