use of org.sonarqube.ws.Rules.ShowResponse in project sonarqube by SonarSource.
the class ShowAction method buildResponse.
private ShowResponse buildResponse(DbSession dbSession, Request request, SearchAction.SearchResult searchResult) {
ShowResponse.Builder responseBuilder = ShowResponse.newBuilder();
RuleDto rule = searchResult.getRules().get(0);
responseBuilder.setRule(mapper.toWsRule(rule, searchResult, Collections.<String>emptySet()));
if (request.mandatoryParamAsBoolean(PARAM_ACTIVES)) {
activeRuleCompleter.completeShow(dbSession, rule, responseBuilder);
}
return responseBuilder.build();
}
use of org.sonarqube.ws.Rules.ShowResponse in project sonarqube by SonarSource.
the class ShowAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
RuleKey key = RuleKey.parse(request.mandatoryParam(PARAM_KEY));
try (DbSession dbSession = dbClient.openSession(false)) {
Optional<RuleDto> optionalRule = dbClient.ruleDao().selectByKey(dbSession, key);
checkFoundWithOptional(optionalRule, "Rule not found: " + key);
RuleDto rule = optionalRule.get();
List<RuleDto> templateRules = new ArrayList<>();
if (rule.getTemplateId() != null) {
Optional<RuleDto> templateRule = dbClient.ruleDao().selectById(rule.getTemplateId(), dbSession);
if (templateRule.isPresent()) {
templateRules.add(templateRule.get());
}
}
List<RuleParamDto> ruleParameters = dbClient.ruleDao().selectRuleParamsByRuleIds(dbSession, singletonList(rule.getId()));
ShowResponse showResponse = buildResponse(dbSession, request, new SearchAction.SearchResult().setRules(singletonList(rule)).setTemplateRules(templateRules).setRuleParameters(ruleParameters).setTotal(1L));
writeProtobuf(showResponse, request, response);
}
}
Aggregations