use of org.sonar.db.rule.RuleParamDto 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.RuleParamDto 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.RuleParamDto in project sonarqube by SonarSource.
the class CompareActionMediumTest method createActiveRuleWithParam.
private ActiveRuleDto createActiveRuleWithParam(RuleDto rule, QualityProfileDto profile, String value) {
ActiveRuleDto activeRule = createActiveRule(rule, profile);
RuleParamDto paramDto = db.ruleDao().selectRuleParamsByRuleKey(session, rule.getKey()).get(0);
ActiveRuleParamDto activeRuleParam = ActiveRuleParamDto.createFor(paramDto).setValue(value);
db.activeRuleDao().insertParam(session, activeRule, activeRuleParam);
return activeRule;
}
use of org.sonar.db.rule.RuleParamDto in project sonarqube by SonarSource.
the class SearchActionMediumTest method search_all_active_rules_params.
@Test
public void search_all_active_rules_params() throws Exception {
QualityProfileDto profile = QProfileTesting.newXooP1("org-123");
tester.get(QualityProfileDao.class).insert(dbSession, profile);
RuleDto rule = RuleTesting.newXooX1();
ruleDao.insert(dbSession, rule);
dbSession.commit();
RuleParamDto param = RuleParamDto.createFor(rule).setDefaultValue("some value").setType("string").setDescription("My small description").setName("my_var");
ruleDao.insertRuleParam(dbSession, rule, param);
RuleParamDto param2 = RuleParamDto.createFor(rule).setDefaultValue("other value").setType("integer").setDescription("My small description").setName("the_var");
ruleDao.insertRuleParam(dbSession, rule, param2);
ActiveRuleDto activeRule = newActiveRule(profile, rule);
tester.get(ActiveRuleDao.class).insert(dbSession, activeRule);
ActiveRuleParamDto activeRuleParam = ActiveRuleParamDto.createFor(param).setValue("The VALUE");
tester.get(ActiveRuleDao.class).insertParam(dbSession, activeRule, activeRuleParam);
ActiveRuleParamDto activeRuleParam2 = ActiveRuleParamDto.createFor(param2).setValue("The Other Value");
tester.get(ActiveRuleDao.class).insertParam(dbSession, activeRule, activeRuleParam2);
dbSession.commit();
ruleIndexer.index();
activeRuleIndexer.index();
WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
request.setParam(WebService.Param.TEXT_QUERY, "x1");
request.setParam(PARAM_ACTIVATION, "true");
request.setParam(WebService.Param.FIELDS, "params");
WsTester.Result result = request.execute();
result.assertJson(this.getClass(), "search_active_rules_params.json");
}
use of org.sonar.db.rule.RuleParamDto in project sonarqube by SonarSource.
the class CreateActionMediumTest method create_custom_rule.
@Test
public void create_custom_rule() throws Exception {
// Template rule
RuleDto templateRule = RuleTesting.newTemplateRule(RuleKey.of("java", "S001"));
ruleDao.insert(session, templateRule);
RuleParamDto param = RuleParamDto.createFor(templateRule).setName("regex").setType("STRING").setDescription("Reg ex").setDefaultValue(".*");
ruleDao.insertRuleParam(session, templateRule, param);
session.commit();
WsTester.TestRequest request = wsTester.newPostRequest("api/rules", "create").setParam("custom_key", "MY_CUSTOM").setParam("template_key", templateRule.getKey().toString()).setParam("name", "My custom rule").setParam("markdown_description", "Description").setParam("severity", "MAJOR").setParam("status", "BETA").setParam("params", "regex=a.*");
request.execute().assertJson(getClass(), "create_custom_rule.json");
}
Aggregations