use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class IssueQueryFactory method create.
public IssueQuery create(SearchRequest request) {
try (DbSession dbSession = dbClient.openSession(false)) {
final ZoneId timeZone = parseTimeZone(request.getTimeZone()).orElse(clock.getZone());
Collection<RuleDefinitionDto> ruleDefinitionDtos = ruleKeysToRuleId(dbSession, request.getRules());
Collection<String> ruleUuids = ruleDefinitionDtos.stream().map(RuleDefinitionDto::getUuid).collect(Collectors.toSet());
if (request.getRules() != null && request.getRules().stream().collect(toSet()).size() != ruleDefinitionDtos.size()) {
ruleUuids.add("non-existing-uuid");
}
IssueQuery.Builder builder = IssueQuery.builder().issueKeys(request.getIssues()).severities(request.getSeverities()).statuses(request.getStatuses()).resolutions(request.getResolutions()).resolved(request.getResolved()).rules(ruleDefinitionDtos).ruleUuids(ruleUuids).assigneeUuids(request.getAssigneeUuids()).authors(request.getAuthors()).scopes(request.getScopes()).languages(request.getLanguages()).tags(request.getTags()).types(request.getTypes()).owaspTop10(request.getOwaspTop10()).sansTop25(request.getSansTop25()).cwe(request.getCwe()).sonarsourceSecurity(request.getSonarsourceSecurity()).assigned(request.getAssigned()).createdAt(parseStartingDateOrDateTime(request.getCreatedAt(), timeZone)).createdBefore(parseEndingDateOrDateTime(request.getCreatedBefore(), timeZone)).facetMode(request.getFacetMode()).timeZone(timeZone);
List<ComponentDto> allComponents = new ArrayList<>();
boolean effectiveOnComponentOnly = mergeDeprecatedComponentParameters(dbSession, request, allComponents);
addComponentParameters(builder, dbSession, effectiveOnComponentOnly, allComponents, request);
setCreatedAfterFromRequest(dbSession, builder, request, allComponents, timeZone);
String sort = request.getSort();
if (!isNullOrEmpty(sort)) {
builder.sort(sort);
builder.asc(request.getAsc());
}
return builder.build();
}
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class RegisterRulesTest method do_not_remove_no_more_defined_ad_hoc_rule.
@Test
public void do_not_remove_no_more_defined_ad_hoc_rule() {
RuleDefinitionDto rule = db.rules().insert(r -> r.setRepositoryKey("external_fake").setStatus(READY).setIsExternal(true).setIsAdHoc(true));
execute();
RuleDto reloaded = dbClient.ruleDao().selectByKey(db.getSession(), rule.getKey()).get();
assertThat(reloaded.getStatus()).isEqualTo(READY);
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class RegisterRulesTest method rules_that_deprecate_previous_rule_must_be_recorded.
@Test
public void rules_that_deprecate_previous_rule_must_be_recorded() {
execute(context -> {
NewRepository repo = context.createRepository("fake", "java");
createRule(repo, "rule1");
repo.done();
});
execute(context -> {
NewRepository repo = context.createRepository("fake", "java");
createRule(repo, "newKey").addDeprecatedRuleKey("fake", "rule1").addDeprecatedRuleKey("fake", "rule2");
repo.done();
});
List<RuleDefinitionDto> rules = dbClient.ruleDao().selectAllDefinitions(db.getSession());
Set<DeprecatedRuleKeyDto> deprecatedRuleKeys = dbClient.ruleDao().selectAllDeprecatedRuleKeys(db.getSession());
assertThat(rules).hasSize(1);
assertThat(deprecatedRuleKeys).hasSize(2);
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class IssueIndexFiltersTest method filter_by_rules.
@Test
public void filter_by_rules() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project, null);
RuleDefinitionDto ruleDefinitionDto = newRule();
db.rules().insert(ruleDefinitionDto);
indexIssues(newDoc("I1", file).setRuleUuid(ruleDefinitionDto.getUuid()));
assertThatSearchReturnsOnly(IssueQuery.builder().ruleUuids(singletonList(ruleDefinitionDto.getUuid())), "I1");
assertThatSearchReturnsEmpty(IssueQuery.builder().ruleUuids(singletonList("uuid-abc")));
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class QualityProfileChangeEventServiceImplTest method distributeRuleChangeEvent.
@Test
public void distributeRuleChangeEvent() {
QProfileDto qualityProfileDto = QualityProfileTesting.newQualityProfileDto();
// Template rule
RuleDto templateRule = newTemplateRule(RuleKey.of("xoo", "template-key"));
db.rules().insert(templateRule.getDefinition());
// Custom rule
RuleDefinitionDto rule1 = newCustomRule(templateRule.getDefinition()).setLanguage("xoo").setDescription("<div>line1\nline2</div>").setDescriptionFormat(MARKDOWN);
db.rules().insert(rule1);
ActiveRuleDto activeRuleDto = ActiveRuleDto.createFor(qualityProfileDto, rule1);
ActiveRuleChange activeRuleChange = new ActiveRuleChange(ACTIVATED, activeRuleDto, rule1);
activeRuleChange.setParameter("paramChangeKey", "paramChangeValue");
Collection<QProfileDto> profiles = Collections.singleton(qualityProfileDto);
ProjectDto project = db.components().insertPrivateProjectDto();
db.qualityProfiles().associateWithProject(project, qualityProfileDto);
underTest.distributeRuleChangeEvent(profiles, of(activeRuleChange), "xoo");
ArgumentCaptor<RuleSetChangedEvent> eventCaptor = ArgumentCaptor.forClass(RuleSetChangedEvent.class);
verify(eventsDistributor).pushEvent(eventCaptor.capture());
RuleSetChangedEvent ruleSetChangedEvent = eventCaptor.getValue();
assertThat(ruleSetChangedEvent).isNotNull();
assertThat(ruleSetChangedEvent).extracting(RuleSetChangedEvent::getEvent, RuleSetChangedEvent::getLanguage, RuleSetChangedEvent::getProjects).containsExactly("RuleSetChanged", "xoo", new String[] { project.getKey() });
assertThat(ruleSetChangedEvent.getActivatedRules()).extracting(RuleChange::getKey, RuleChange::getLanguage, RuleChange::getSeverity, RuleChange::getTemplateKey).containsExactly(tuple(rule1.getRuleKey(), "xoo", null, "template-key"));
assertThat(ruleSetChangedEvent.getActivatedRules()[0].getParams()).hasSize(1);
ParamChange actualParamChange = ruleSetChangedEvent.getActivatedRules()[0].getParams()[0];
assertThat(actualParamChange).extracting(ParamChange::getKey, ParamChange::getValue).containsExactly("paramChangeKey", "paramChangeValue");
assertThat(ruleSetChangedEvent.getDeactivatedRules()).isEmpty();
}
Aggregations