use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class CachingRuleFinderTest method findAll_returns_all_rules_with_exact_same_rulekey_and_order_them_most_recent_first.
@Test
public void findAll_returns_all_rules_with_exact_same_rulekey_and_order_them_most_recent_first() {
String ruleKey = "ABCD";
RuleDefinitionDto[] sameRuleKey = { dbTester.rules().insert(rule -> rule.setRuleKey(ruleKey).setUpdatedAt(system2.now())), dbTester.rules().insert(rule -> rule.setRuleKey(ruleKey).setUpdatedAt(system2.now())) };
RuleDefinitionDto otherRule = dbTester.rules().insert(rule -> rule.setUpdatedAt(system2.now()));
CachingRuleFinder underTest = new CachingRuleFinder(dbClient);
assertThat(underTest.findAll(RuleQuery.create().withKey(ruleKey))).extracting(CachingRuleFinderTest::toRuleKey).containsExactly(sameRuleKey[1].getKey(), sameRuleKey[0].getKey());
assertThat(underTest.findAll(RuleQuery.create().withKey(otherRule.getRuleKey()))).extracting(CachingRuleFinderTest::toRuleKey).containsExactly(otherRule.getKey());
assertThat(underTest.findAll(RuleQuery.create().withKey(ruleKey.toLowerCase()))).isEmpty();
assertThat(underTest.findAll(RuleQuery.create().withKey(randomAlphabetic(3)))).isEmpty();
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class CachingRuleFinderTest method findByKey_returns_all_loaded_rules.
@Test
public void findByKey_returns_all_loaded_rules() {
for (int i = 0; i < ruleDefinitions.length; i++) {
RuleDefinitionDto ruleDefinition = ruleDefinitions[i];
RuleParamDto ruleParam = ruleParams[i];
org.sonar.api.rules.Rule rule = underTest.findByKey(ruleDefinition.getKey());
verifyRule(rule, ruleDefinition, ruleParam);
assertThat(underTest.findByKey(ruleDefinition.getRepositoryKey(), ruleDefinition.getRuleKey())).isSameAs(rule);
}
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class IssueIndexFacetsTest method facets_on_languages.
@Test
public void facets_on_languages() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project, null);
RuleDefinitionDto ruleDefinitionDto = newRule();
db.rules().insert(ruleDefinitionDto);
indexIssues(newDoc("I1", file).setRuleUuid(ruleDefinitionDto.getUuid()).setLanguage("xoo"));
assertThatFacetHasOnly(IssueQuery.builder(), "languages", entry("xoo", 1L));
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class BulkChangeAction method toNotification.
@CheckForNull
private ChangedIssue toNotification(BulkChangeData bulkChangeData, Map<String, UserDto> userDtoByUuid, DefaultIssue issue) {
BranchDto branchDto = bulkChangeData.branchesByProjectUuid.get(issue.projectUuid());
if (!hasNotificationSupport(branchDto)) {
return null;
}
RuleDefinitionDto ruleDefinitionDto = bulkChangeData.rulesByKey.get(issue.ruleKey());
ComponentDto projectDto = bulkChangeData.projectsByUuid.get(issue.projectUuid());
if (ruleDefinitionDto == null || projectDto == null) {
return null;
}
Optional<UserDto> assignee = Optional.ofNullable(issue.assignee()).map(userDtoByUuid::get);
return new ChangedIssue.Builder(issue.key()).setNewStatus(issue.status()).setNewResolution(issue.resolution()).setAssignee(assignee.map(u -> new User(u.getUuid(), u.getLogin(), u.getName())).orElse(null)).setRule(new IssuesChangesNotificationBuilder.Rule(ruleDefinitionDto.getKey(), RuleType.valueOfNullable(ruleDefinitionDto.getType()), ruleDefinitionDto.getName())).setProject(new Project.Builder(projectDto.uuid()).setKey(projectDto.getKey()).setProjectName(projectDto.name()).setBranchName(branchDto.isMain() ? null : branchDto.getKey()).build()).build();
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class IssueUpdater method doSaveIssue.
private IssueDto doSaveIssue(DbSession session, DefaultIssue issue, IssueChangeContext context, Optional<RuleDefinitionDto> rule, ComponentDto project, BranchDto branchDto) {
IssueDto issueDto = issueStorage.save(session, singletonList(issue)).iterator().next();
if (// since this method is called after an update of the issue, date should never be null
issue.updateDate() == null || // name of rule is displayed in notification, rule must therefor be present
!rule.isPresent() || // notification are not supported on PRs
!hasNotificationSupport(branchDto)) {
return issueDto;
}
Optional<UserDto> assignee = Optional.ofNullable(issue.assignee()).map(assigneeUuid -> dbClient.userDao().selectByUuid(session, assigneeUuid));
UserDto author = Optional.ofNullable(context.userUuid()).map(authorUuid -> dbClient.userDao().selectByUuid(session, authorUuid)).orElseThrow(() -> new IllegalStateException("Can not find dto for change author " + context.userUuid()));
IssuesChangesNotificationBuilder notificationBuilder = new IssuesChangesNotificationBuilder(singleton(new ChangedIssue.Builder(issue.key()).setNewResolution(issue.resolution()).setNewStatus(issue.status()).setAssignee(assignee.map(assigneeDto -> new User(assigneeDto.getUuid(), assigneeDto.getLogin(), assigneeDto.getName())).orElse(null)).setRule(rule.map(r -> new Rule(r.getKey(), RuleType.valueOfNullable(r.getType()), r.getName())).get()).setProject(new Project.Builder(project.uuid()).setKey(project.getKey()).setProjectName(project.name()).setBranchName(branchDto.isMain() ? null : branchDto.getKey()).build()).build()), new UserChange(issue.updateDate().getTime(), new User(author.getUuid(), author.getLogin(), author.getName())));
notificationService.scheduleForSending(notificationSerializer.serialize(notificationBuilder));
return issueDto;
}
Aggregations