use of org.sonar.db.rule.RuleParamDto in project sonarqube by SonarSource.
the class ActiveRuleDaoTest method setUp.
@Before
public void setUp() {
when(system.now()).thenReturn(NOW);
dbClient.qualityProfileDao().insert(dbSession, profile1);
dbClient.qualityProfileDao().insert(dbSession, profile2);
dbClient.ruleDao().insert(dbSession, rule1);
dbClient.ruleDao().insert(dbSession, rule2);
dbClient.ruleDao().insert(dbSession, rule3);
rule1Param1 = new RuleParamDto().setName("param1").setDefaultValue("value1").setType(RuleParamType.STRING.toString());
dbClient.ruleDao().insertRuleParam(dbSession, rule1, rule1Param1);
rule1Param2 = new RuleParamDto().setRuleId(rule1.getId()).setName("param2").setDefaultValue("2").setType(RuleParamType.INTEGER.toString());
dbClient.ruleDao().insertRuleParam(dbSession, rule1, rule1Param2);
rule2Param1 = new RuleParamDto().setRuleId(rule2.getId()).setName("param1").setDefaultValue("1").setType(RuleParamType.INTEGER.toString());
dbClient.ruleDao().insertRuleParam(dbSession, rule2, rule2Param1);
dbSession.commit();
}
use of org.sonar.db.rule.RuleParamDto in project sonarqube by SonarSource.
the class RuleCreator method validateCustomRule.
private void validateCustomRule(NewCustomRule newRule, DbSession dbSession, RuleKey templateKey) {
List<String> errors = new ArrayList<>();
validateRuleKey(errors, newRule.ruleKey());
validateName(errors, newRule);
validateDescription(errors, newRule);
String severity = newRule.severity();
if (Strings.isNullOrEmpty(severity)) {
errors.add("The severity is missing");
} else if (!Severity.ALL.contains(severity)) {
errors.add(format("Severity \"%s\" is invalid", severity));
}
if (newRule.status() == null) {
errors.add("The status is missing");
}
for (RuleParamDto ruleParam : dbClient.ruleDao().selectRuleParamsByRuleKey(dbSession, templateKey)) {
try {
validateParam(ruleParam, newRule.parameter(ruleParam.getName()));
} catch (BadRequestException validationError) {
errors.addAll(validationError.errors());
}
}
checkRequest(errors.isEmpty(), errors);
}
use of org.sonar.db.rule.RuleParamDto in project sonarqube by SonarSource.
the class RuleCreator method createCustomRule.
private RuleKey createCustomRule(RuleKey ruleKey, NewCustomRule newRule, RuleDto templateRuleDto, DbSession dbSession) {
RuleDto ruleDto = RuleDto.createFor(ruleKey).setTemplateId(templateRuleDto.getId()).setConfigKey(templateRuleDto.getConfigKey()).setName(newRule.name()).setDescription(newRule.markdownDescription()).setDescriptionFormat(Format.MARKDOWN).setSeverity(newRule.severity()).setStatus(newRule.status()).setLanguage(templateRuleDto.getLanguage()).setDefaultRemediationFunction(templateRuleDto.getDefaultRemediationFunction()).setDefaultRemediationGapMultiplier(templateRuleDto.getDefaultRemediationGapMultiplier()).setDefaultRemediationBaseEffort(templateRuleDto.getDefaultRemediationBaseEffort()).setGapDescription(templateRuleDto.getGapDescription()).setTags(templateRuleDto.getTags()).setSystemTags(templateRuleDto.getSystemTags()).setType(templateRuleDto.getType()).setCreatedAt(system2.now()).setUpdatedAt(system2.now());
dbClient.ruleDao().insert(dbSession, ruleDto);
for (RuleParamDto templateRuleParamDto : dbClient.ruleDao().selectRuleParamsByRuleKey(dbSession, templateRuleDto.getKey())) {
String customRuleParamValue = Strings.emptyToNull(newRule.parameter(templateRuleParamDto.getName()));
createCustomRuleParams(customRuleParamValue, ruleDto, templateRuleParamDto, dbSession);
}
return ruleKey;
}
use of org.sonar.db.rule.RuleParamDto in project sonarqube by SonarSource.
the class RuleCreator method createCustomRuleParams.
private void createCustomRuleParams(@Nullable String paramValue, RuleDto ruleDto, RuleParamDto templateRuleParam, DbSession dbSession) {
RuleParamDto ruleParamDto = RuleParamDto.createFor(ruleDto).setName(templateRuleParam.getName()).setType(templateRuleParam.getType()).setDescription(templateRuleParam.getDescription()).setDefaultValue(paramValue);
dbClient.ruleDao().insertRuleParam(dbSession, ruleDto, ruleParamDto);
}
use of org.sonar.db.rule.RuleParamDto 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();
}
Aggregations