Search in sources :

Example 6 with ActiveRuleDao

use of org.sonar.db.qualityprofile.ActiveRuleDao in project sonarqube by SonarSource.

the class RuleActivator method doUpdate.

private ActiveRuleDto doUpdate(ActiveRuleChange change, RuleActivationContext context, DbSession dbSession) {
    ActiveRuleWrapper activeRule = context.getActiveRule();
    if (activeRule == null) {
        return null;
    }
    ActiveRuleDao dao = db.activeRuleDao();
    String severity = change.getSeverity();
    if (severity != null) {
        activeRule.get().setSeverity(severity);
    }
    ActiveRuleInheritance inheritance = change.getInheritance();
    if (inheritance != null) {
        activeRule.get().setInheritance(inheritance.name());
    }
    activeRule.get().setUpdatedAt(system2.now());
    dao.update(dbSession, activeRule.get());
    for (Map.Entry<String, String> param : change.getParameters().entrySet()) {
        ActiveRuleParamDto activeRuleParamDto = activeRule.getParam(param.getKey());
        if (activeRuleParamDto == null) {
            // did not exist
            if (param.getValue() != null) {
                activeRuleParamDto = ActiveRuleParamDto.createFor(context.getRule().getParam(param.getKey()));
                activeRuleParamDto.setValue(param.getValue());
                dao.insertParam(dbSession, activeRule.get(), activeRuleParamDto);
            }
        } else {
            if (param.getValue() != null) {
                activeRuleParamDto.setValue(param.getValue());
                dao.updateParam(dbSession, activeRuleParamDto);
            } else {
                dao.deleteParam(dbSession, activeRuleParamDto);
            }
        }
    }
    return activeRule.get();
}
Also used : ActiveRuleDao(org.sonar.db.qualityprofile.ActiveRuleDao) ActiveRuleWrapper(org.sonar.server.qualityprofile.builtin.RuleActivationContext.ActiveRuleWrapper) ActiveRuleInheritance(org.sonar.server.qualityprofile.ActiveRuleInheritance) ActiveRuleParamDto(org.sonar.db.qualityprofile.ActiveRuleParamDto) Map(java.util.Map)

Example 7 with ActiveRuleDao

use of org.sonar.db.qualityprofile.ActiveRuleDao in project sonarqube by SonarSource.

the class RuleActivator method persist.

private void persist(ActiveRuleChange change, RuleActivationContext context, DbSession dbSession) {
    ActiveRuleDto activeRule = null;
    if (change.getType() == ActiveRuleChange.Type.ACTIVATED) {
        activeRule = doInsert(change, context, dbSession);
    } else if (change.getType() == ActiveRuleChange.Type.DEACTIVATED) {
        ActiveRuleDao dao = db.activeRuleDao();
        activeRule = dao.delete(dbSession, change.getKey()).orElse(null);
    } else if (change.getType() == ActiveRuleChange.Type.UPDATED) {
        activeRule = doUpdate(change, context, dbSession);
    }
    change.setActiveRule(activeRule);
    db.qProfileChangeDao().insert(dbSession, change.toDto(userSession.getUuid()));
}
Also used : ActiveRuleDao(org.sonar.db.qualityprofile.ActiveRuleDao) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto)

Example 8 with ActiveRuleDao

use of org.sonar.db.qualityprofile.ActiveRuleDao 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

ActiveRuleDao (org.sonar.db.qualityprofile.ActiveRuleDao)8 ActiveRuleDto (org.sonar.db.qualityprofile.ActiveRuleDto)7 ActiveRuleParamDto (org.sonar.db.qualityprofile.ActiveRuleParamDto)6 Map (java.util.Map)4 Test (org.junit.Test)2 RuleKey (org.sonar.api.rule.RuleKey)2 ActiveRuleKey (org.sonar.db.qualityprofile.ActiveRuleKey)2 QualityProfileDao (org.sonar.db.qualityprofile.QualityProfileDao)2 QualityProfileDto (org.sonar.db.qualityprofile.QualityProfileDto)2 ActiveRuleInheritance (org.sonar.server.qualityprofile.ActiveRuleInheritance)2 ActiveRuleWrapper (org.sonar.server.qualityprofile.builtin.RuleActivationContext.ActiveRuleWrapper)2 ServerTester (org.sonar.server.tester.ServerTester)2 SearchOptions (org.sonar.server.es.SearchOptions)1 Platform (org.sonar.server.platform.Platform)1 RuleWrapper (org.sonar.server.qualityprofile.builtin.RuleActivationContext.RuleWrapper)1 RuleQuery (org.sonar.server.rule.index.RuleQuery)1