use of org.sonar.db.qualityprofile.ActiveRuleKey in project sonarqube by SonarSource.
the class ActiveRuleCompleter method completeShow.
void completeShow(DbSession dbSession, RuleDto rule, ShowResponse.Builder response) {
List<ActiveRuleDto> activeRuleDtos = dbClient.activeRuleDao().selectByRuleId(dbSession, rule.getId());
Map<Integer, ActiveRuleKey> activeRuleIdsByKey = new HashMap<>();
for (ActiveRuleDto activeRuleDto : activeRuleDtos) {
activeRuleIdsByKey.put(activeRuleDto.getId(), activeRuleDto.getKey());
}
List<ActiveRuleParamDto> activeRuleParamDtos = dbClient.activeRuleDao().selectParamsByActiveRuleIds(dbSession, Lists.transform(activeRuleDtos, ActiveRuleDto::getId));
ListMultimap<ActiveRuleKey, ActiveRuleParamDto> activeRuleParamsByActiveRuleKey = ArrayListMultimap.create(activeRuleDtos.size(), 10);
for (ActiveRuleParamDto activeRuleParamDto : activeRuleParamDtos) {
ActiveRuleKey activeRuleKey = activeRuleIdsByKey.get(activeRuleParamDto.getActiveRuleId());
activeRuleParamsByActiveRuleKey.put(activeRuleKey, activeRuleParamDto);
}
for (ActiveRuleDto activeRule : activeRuleDtos) {
response.addActives(buildActiveRuleResponse(activeRule, activeRuleParamsByActiveRuleKey.get(activeRule.getKey())));
}
}
use of org.sonar.db.qualityprofile.ActiveRuleKey in project sonarqube by SonarSource.
the class ActiveRuleResultSetIterator method read.
@Override
protected ActiveRuleDoc read(ResultSet rs) throws SQLException {
RuleKey ruleKey = RuleKey.of(rs.getString(4), rs.getString(3));
ActiveRuleKey activeRuleKey = ActiveRuleKey.of(rs.getString(5), ruleKey);
ActiveRuleDoc doc = new ActiveRuleDoc(activeRuleKey);
// all the fields must be present, even if value is null
doc.setSeverity(SeverityUtil.getSeverityFromOrdinal(rs.getInt(1)));
String inheritance = rs.getString(2);
doc.setInheritance(inheritance == null ? ActiveRule.Inheritance.NONE.name() : inheritance);
doc.setCreatedAt(rs.getLong(6));
doc.setUpdatedAt(rs.getLong(7));
return doc;
}
use of org.sonar.db.qualityprofile.ActiveRuleKey in project sonarqube by SonarSource.
the class RuleActivator method cascadeDeactivation.
private List<ActiveRuleChange> cascadeDeactivation(ActiveRuleKey key, DbSession dbSession, boolean isCascade, boolean force) {
List<ActiveRuleChange> changes = Lists.newArrayList();
RuleActivatorContext context = contextFactory.create(key.qProfile(), key.ruleKey(), dbSession);
ActiveRuleChange change;
ActiveRuleDto activeRuleDto = context.activeRule();
if (activeRuleDto == null) {
return changes;
}
checkRequest(force || isCascade || activeRuleDto.getInheritance() == null, "Cannot deactivate inherited rule '%s'", key.ruleKey());
change = ActiveRuleChange.createFor(ActiveRuleChange.Type.DEACTIVATED, key);
changes.add(change);
persist(change, context, dbSession);
// get all inherited profiles
List<QualityProfileDto> profiles = db.qualityProfileDao().selectChildren(dbSession, key.qProfile());
for (QualityProfileDto profile : profiles) {
ActiveRuleKey activeRuleKey = ActiveRuleKey.of(profile.getKey(), key.ruleKey());
changes.addAll(cascadeDeactivation(activeRuleKey, dbSession, true, force));
}
if (!changes.isEmpty()) {
updateProfileDates(dbSession, context);
}
return changes;
}
use of org.sonar.db.qualityprofile.ActiveRuleKey in project sonarqube by SonarSource.
the class RuleActivator method bulkDeactivate.
BulkChangeResult bulkDeactivate(RuleQuery ruleQuery, String profile) {
DbSession dbSession = db.openSession(false);
BulkChangeResult result = new BulkChangeResult();
try {
Iterator<RuleKey> rules = ruleIndex.searchAll(ruleQuery);
while (rules.hasNext()) {
try {
RuleKey ruleKey = rules.next();
ActiveRuleKey key = ActiveRuleKey.of(profile, ruleKey);
List<ActiveRuleChange> changes = deactivate(dbSession, key);
result.addChanges(changes);
if (!changes.isEmpty()) {
result.incrementSucceeded();
}
} catch (BadRequestException e) {
// other exceptions stop the bulk activation
result.incrementFailed();
result.getErrors().addAll(e.errors());
}
}
dbSession.commit();
activeRuleIndexer.index(result.getChanges());
return result;
} finally {
dbSession.close();
}
}
use of org.sonar.db.qualityprofile.ActiveRuleKey in project sonarqube by SonarSource.
the class RuleActivatorContextFactory method initActiveRules.
private void initActiveRules(String profileKey, RuleKey ruleKey, RuleActivatorContext context, DbSession session, boolean parent) {
ActiveRuleKey key = ActiveRuleKey.of(profileKey, ruleKey);
Optional<ActiveRuleDto> activeRule = db.activeRuleDao().selectByKey(session, key);
Collection<ActiveRuleParamDto> activeRuleParams = null;
if (activeRule.isPresent()) {
activeRuleParams = db.activeRuleDao().selectParamsByActiveRuleId(session, activeRule.get().getId());
}
if (parent) {
context.setParentActiveRule(activeRule.orNull());
context.setParentActiveRuleParams(activeRuleParams);
} else {
context.setActiveRule(activeRule.orNull());
context.setActiveRuleParams(activeRuleParams);
}
}
Aggregations