/** True if trying to override an inherited rule but with exactly the same values */
 boolean isSameAsParent(ActiveRuleChange change) {
   if (parentActiveRule == null) {
     return false;
   }
   if (!StringUtils.equals(change.getSeverity(), parentActiveRule.getSeverityString())) {
     return false;
   }
   for (Map.Entry<String, String> entry : change.getParameters().entrySet()) {
     if (entry.getValue() != null && !entry.getValue().equals(parentParamValue(entry.getKey()))) {
       return false;
     }
   }
   return true;
 }
 boolean isSame(ActiveRuleChange change) {
   ActiveRule.Inheritance inheritance = change.getInheritance();
   if (inheritance != null && !inheritance.name().equals(activeRule.getInheritance())) {
     return false;
   }
   String severity = change.getSeverity();
   if (severity != null && !severity.equals(activeRule.getSeverityString())) {
     return false;
   }
   for (Map.Entry<String, String> changeParam : change.getParameters().entrySet()) {
     ActiveRuleParamDto param = activeRuleParams.get(changeParam.getKey());
     if (param != null && !StringUtils.equals(changeParam.getValue(), param.getValue())) {
       return false;
     }
   }
   return true;
 }
 @CheckForNull
 String currentSeverity() {
   return activeRule != null ? activeRule.getSeverityString() : null;
 }
 @CheckForNull
 String parentSeverity() {
   return parentActiveRule != null ? parentActiveRule.getSeverityString() : null;
 }
  @Override
  public ProjectReferentials load(ProjectReactor reactor, Settings settings, Languages languages) {
    ProjectReferentials ref = new ProjectReferentials();

    String defaultName = settings.getString(ModuleQProfiles.SONAR_PROFILE_PROP);

    for (Language language : languages.all()) {
      org.sonar.batch.protocol.input.QProfile profile = null;
      if (StringUtils.isNotBlank(defaultName)) {
        profile = loadDefaultQProfile(defaultName, language.getKey());
      }
      if (profile == null) {
        profile = loadQProfile(settings, language.getKey());
      }
      if (profile != null) {
        ref.addQProfile(profile);
      }
    }

    for (QProfile qProfile : ref.qProfiles()) {
      ListMultimap<Integer, ActiveRuleParamDto> paramDtosByActiveRuleId =
          ArrayListMultimap.create();
      for (ActiveRuleParamDto dto : activeRuleDao.selectParamsByProfileKey(qProfile.key())) {
        paramDtosByActiveRuleId.put(dto.getActiveRuleId(), dto);
      }

      for (ActiveRuleDto activeDto : activeRuleDao.selectByProfileKey(qProfile.key())) {
        Rule rule = ruleFinder.findById(activeDto.getRuleId());
        if (rule != null) {
          String internalKey;
          Rule template = rule.getTemplate();
          if (template != null) {
            internalKey = template.getConfigKey();
          } else {
            internalKey = rule.getConfigKey();
          }
          ActiveRule activeRule =
              new ActiveRule(
                  rule.ruleKey().repository(),
                  rule.ruleKey().rule(),
                  rule.getName(),
                  activeDto.getSeverityString(),
                  internalKey,
                  rule.getLanguage());

          // load parameter values
          for (ActiveRuleParamDto paramDto : paramDtosByActiveRuleId.get(activeDto.getId())) {
            activeRule.params().put(paramDto.getKey(), paramDto.getValue());
          }

          // load default values
          for (RuleParam param : rule.getParams()) {
            if (!activeRule.params().containsKey(param.getKey())) {
              activeRule.params().put(param.getKey(), param.getDefaultValue());
            }
          }

          ref.addActiveRule(activeRule);
        }
      }
    }

    return ref;
  }