Search in sources :

Example 1 with ShowResponse

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();
}
Also used : ShowResponse(org.sonarqube.ws.Rules.ShowResponse) RuleDto(org.sonar.db.rule.RuleDto)

Example 2 with ShowResponse

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);
    }
}
Also used : DbSession(org.sonar.db.DbSession) ShowResponse(org.sonarqube.ws.Rules.ShowResponse) RuleKey(org.sonar.api.rule.RuleKey) RuleDto(org.sonar.db.rule.RuleDto) ArrayList(java.util.ArrayList) RuleParamDto(org.sonar.db.rule.RuleParamDto)

Aggregations

RuleDto (org.sonar.db.rule.RuleDto)2 ShowResponse (org.sonarqube.ws.Rules.ShowResponse)2 ArrayList (java.util.ArrayList)1 RuleKey (org.sonar.api.rule.RuleKey)1 DbSession (org.sonar.db.DbSession)1 RuleParamDto (org.sonar.db.rule.RuleParamDto)1