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();
}
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();
}
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);
}
}
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();
}
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();
}
Aggregations