Search in sources :

Example 11 with RuleDto

use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.

the class CreateAction method createResponse.

private Rules.CreateResponse createResponse(DbSession dbSession, RuleKey ruleKey) {
    RuleDto rule = dbClient.ruleDao().selectOrFailByKey(dbSession, ruleKey);
    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()));
    SearchAction.SearchResult searchResult = new SearchAction.SearchResult().setRules(singletonList(rule)).setRuleParameters(ruleParameters).setTemplateRules(templateRules).setTotal(1L);
    return Rules.CreateResponse.newBuilder().setRule(ruleMapper.toWsRule(rule, searchResult, Collections.<String>emptySet())).build();
}
Also used : RuleDto(org.sonar.db.rule.RuleDto) ArrayList(java.util.ArrayList) RuleParamDto(org.sonar.db.rule.RuleParamDto)

Example 12 with RuleDto

use of org.sonar.db.rule.RuleDto 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 13 with RuleDto

use of org.sonar.db.rule.RuleDto 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)

Example 14 with RuleDto

use of org.sonar.db.rule.RuleDto 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 15 with RuleDto

use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.

the class IntegrateIssuesVisitorTest method addBaseIssue.

private void addBaseIssue(RuleKey ruleKey) {
    ComponentDto project = ComponentTesting.newProjectDto(dbTester.organizations().insert(), PROJECT_UUID).setKey(PROJECT_KEY);
    ComponentDto file = ComponentTesting.newFileDto(project, null, FILE_UUID).setKey(FILE_KEY);
    dbTester.getDbClient().componentDao().insert(dbTester.getSession(), project, file);
    RuleDto ruleDto = RuleTesting.newDto(ruleKey);
    dbTester.getDbClient().ruleDao().insert(dbTester.getSession(), ruleDto);
    ruleRepositoryRule.add(ruleKey);
    IssueDto issue = IssueTesting.newDto(ruleDto, file, project).setKee("ISSUE").setStatus(Issue.STATUS_OPEN).setSeverity(Severity.MAJOR);
    dbTester.getDbClient().issueDao().insert(dbTester.getSession(), issue);
    dbTester.getSession().commit();
}
Also used : RuleDto(org.sonar.db.rule.RuleDto) ComponentDto(org.sonar.db.component.ComponentDto) IssueDto(org.sonar.db.issue.IssueDto)

Aggregations

RuleDto (org.sonar.db.rule.RuleDto)197 Test (org.junit.Test)140 ActiveRuleDto (org.sonar.db.qualityprofile.ActiveRuleDto)80 ComponentDto (org.sonar.db.component.ComponentDto)47 WsTester (org.sonar.server.ws.WsTester)38 QualityProfileDto (org.sonar.db.qualityprofile.QualityProfileDto)29 RuleParamDto (org.sonar.db.rule.RuleParamDto)29 IssueDto (org.sonar.db.issue.IssueDto)28 RuleKey (org.sonar.api.rule.RuleKey)24 SearchOptions (org.sonar.server.es.SearchOptions)16 RuleQuery (org.sonar.server.rule.index.RuleQuery)16 BadRequestException (org.sonar.server.exceptions.BadRequestException)15 RuleTesting.newRuleDto (org.sonar.db.rule.RuleTesting.newRuleDto)14 ActiveRuleParamDto (org.sonar.db.qualityprofile.ActiveRuleParamDto)12 IssueIndexer (org.sonar.server.issue.index.IssueIndexer)10 Date (java.util.Date)9 RulesDefinition (org.sonar.api.server.rule.RulesDefinition)8 QualityProfileDao (org.sonar.db.qualityprofile.QualityProfileDao)8 ActiveRuleDao (org.sonar.db.qualityprofile.ActiveRuleDao)7 ArrayList (java.util.ArrayList)6