Пример #1
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);
     }
   }
 }
Пример #2
0
 /** @param optionalSeverity if null, then the default rule severity is used */
 public ActiveRule activateRule(final Rule rule, @Nullable RulePriority optionalSeverity) {
   if (Iterables.any(
       activeRules,
       new Predicate<ActiveRule>() {
         @Override
         public boolean apply(ActiveRule input) {
           return input.getRule().equals(rule);
         }
       })) {
     throw MessageException.of(
         String.format(
             "The definition of the profile '%s' (language '%s') contains multiple occurrences of the '%s:%s' rule. The plugin which declares this profile should fix this.",
             getName(), getLanguage(), rule.getRepositoryKey(), rule.getKey()));
   }
   ActiveRule activeRule = new ActiveRule();
   activeRule.setRule(rule);
   activeRule.setRulesProfile(this);
   activeRule.setSeverity(optionalSeverity == null ? rule.getSeverity() : optionalSeverity);
   activeRules.add(activeRule);
   return activeRule;
 }