Search in sources :

Example 1 with UpdateResponse

use of org.sonarqube.ws.Rules.UpdateResponse in project sonarqube by SonarSource.

the class UpdateAction method buildResponse.

private UpdateResponse buildResponse(DbSession dbSession, RuleKey key) {
    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()));
    UpdateResponse.Builder responseBuilder = UpdateResponse.newBuilder();
    SearchAction.SearchResult searchResult = new SearchAction.SearchResult().setRules(singletonList(rule)).setTemplateRules(templateRules).setRuleParameters(ruleParameters).setTotal(1L);
    responseBuilder.setRule(mapper.toWsRule(rule, searchResult, Collections.<String>emptySet()));
    return responseBuilder.build();
}
Also used : UpdateResponse(org.sonarqube.ws.Rules.UpdateResponse) RuleDto(org.sonar.db.rule.RuleDto) ArrayList(java.util.ArrayList) RuleParamDto(org.sonar.db.rule.RuleParamDto)

Example 2 with UpdateResponse

use of org.sonarqube.ws.Rules.UpdateResponse in project sonarqube by SonarSource.

the class UpdateAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    ruleWsSupport.checkQProfileAdminPermission();
    try (DbSession dbSession = dbClient.openSession(false)) {
        RuleUpdate update = readRequest(dbSession, request);
        ruleUpdater.update(dbSession, update, userSession);
        UpdateResponse updateResponse = buildResponse(dbSession, update.getRuleKey());
        writeProtobuf(updateResponse, request, response);
    }
}
Also used : DbSession(org.sonar.db.DbSession) UpdateResponse(org.sonarqube.ws.Rules.UpdateResponse) RuleUpdate(org.sonar.server.rule.RuleUpdate)

Aggregations

UpdateResponse (org.sonarqube.ws.Rules.UpdateResponse)2 ArrayList (java.util.ArrayList)1 DbSession (org.sonar.db.DbSession)1 RuleDto (org.sonar.db.rule.RuleDto)1 RuleParamDto (org.sonar.db.rule.RuleParamDto)1 RuleUpdate (org.sonar.server.rule.RuleUpdate)1