Search in sources :

Example 1 with RuleWrapper

use of org.sonar.server.qualityprofile.builtin.RuleActivationContext.RuleWrapper in project sonarqube by SonarSource.

the class RuleActivator method applySeverityAndParamToChange.

/**
 * Update severity and params
 */
private void applySeverityAndParamToChange(RuleActivation request, RuleActivationContext context, ActiveRuleChange change) {
    RuleWrapper rule = context.getRule();
    ActiveRuleWrapper activeRule = context.getActiveRule();
    ActiveRuleWrapper parentActiveRule = context.getParentActiveRule();
    if (request.isReset()) {
        applySeverityAndParamsWhenResetRequested(change, rule, parentActiveRule);
    } else if (context.getRulesProfile().isBuiltIn()) {
        applySeverityAndParamsWhenBuiltInProfile(request, context, change, rule);
    } else {
        applySeverityAndParamsWhenNonBuiltInProfile(request, context, change, rule, activeRule, parentActiveRule);
    }
}
Also used : ActiveRuleWrapper(org.sonar.server.qualityprofile.builtin.RuleActivationContext.ActiveRuleWrapper) RuleWrapper(org.sonar.server.qualityprofile.builtin.RuleActivationContext.RuleWrapper) ActiveRuleWrapper(org.sonar.server.qualityprofile.builtin.RuleActivationContext.ActiveRuleWrapper)

Example 2 with RuleWrapper

use of org.sonar.server.qualityprofile.builtin.RuleActivationContext.RuleWrapper in project sonarqube by SonarSource.

the class RuleActivator method doInsert.

private ActiveRuleDto doInsert(ActiveRuleChange change, RuleActivationContext context, DbSession dbSession) {
    ActiveRuleDao dao = db.activeRuleDao();
    RuleWrapper rule = context.getRule();
    ActiveRuleDto activeRule = new ActiveRuleDto();
    activeRule.setProfileUuid(context.getRulesProfile().getUuid());
    activeRule.setRuleUuid(rule.get().getUuid());
    activeRule.setKey(ActiveRuleKey.of(context.getRulesProfile(), rule.get().getKey()));
    String severity = change.getSeverity();
    if (severity != null) {
        activeRule.setSeverity(severity);
    }
    ActiveRuleInheritance inheritance = change.getInheritance();
    if (inheritance != null) {
        activeRule.setInheritance(inheritance.name());
    }
    activeRule.setUpdatedAt(system2.now());
    activeRule.setCreatedAt(system2.now());
    dao.insert(dbSession, activeRule);
    for (Map.Entry<String, String> param : change.getParameters().entrySet()) {
        if (param.getValue() != null) {
            ActiveRuleParamDto paramDto = ActiveRuleParamDto.createFor(rule.getParam(param.getKey()));
            paramDto.setValue(param.getValue());
            dao.insertParam(dbSession, activeRule, paramDto);
        }
    }
    return activeRule;
}
Also used : ActiveRuleDao(org.sonar.db.qualityprofile.ActiveRuleDao) ActiveRuleInheritance(org.sonar.server.qualityprofile.ActiveRuleInheritance) ActiveRuleParamDto(org.sonar.db.qualityprofile.ActiveRuleParamDto) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) Map(java.util.Map) RuleWrapper(org.sonar.server.qualityprofile.builtin.RuleActivationContext.RuleWrapper) ActiveRuleWrapper(org.sonar.server.qualityprofile.builtin.RuleActivationContext.ActiveRuleWrapper)

Aggregations

ActiveRuleWrapper (org.sonar.server.qualityprofile.builtin.RuleActivationContext.ActiveRuleWrapper)2 RuleWrapper (org.sonar.server.qualityprofile.builtin.RuleActivationContext.RuleWrapper)2 Map (java.util.Map)1 ActiveRuleDao (org.sonar.db.qualityprofile.ActiveRuleDao)1 ActiveRuleDto (org.sonar.db.qualityprofile.ActiveRuleDto)1 ActiveRuleParamDto (org.sonar.db.qualityprofile.ActiveRuleParamDto)1 ActiveRuleInheritance (org.sonar.server.qualityprofile.ActiveRuleInheritance)1