use of org.sonar.server.qualityprofile.ActiveRuleInheritance 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();
}
use of org.sonar.server.qualityprofile.ActiveRuleInheritance 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;
}
use of org.sonar.server.qualityprofile.ActiveRuleInheritance in project sonarqube by SonarSource.
the class RuleActivator method isSame.
private static boolean isSame(ActiveRuleChange change, ActiveRuleWrapper activeRule) {
ActiveRuleInheritance inheritance = change.getInheritance();
if (inheritance != null && !inheritance.name().equals(activeRule.get().getInheritance())) {
return false;
}
String severity = change.getSeverity();
if (severity != null && !severity.equals(activeRule.get().getSeverityString())) {
return false;
}
for (Map.Entry<String, String> changeParam : change.getParameters().entrySet()) {
String activeParamValue = activeRule.getParamValue(changeParam.getKey());
if (changeParam.getValue() == null && activeParamValue != null) {
return false;
}
if (changeParam.getValue() != null && (activeParamValue == null || !StringUtils.equals(changeParam.getValue(), activeParamValue))) {
return false;
}
}
return true;
}
Aggregations