Skip to content

Commit

Permalink
SONAR-10587 do not not return external issues in batch/issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Jambet authored and SonarTech committed Apr 26, 2018
1 parent 011eb8e commit af22e60
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ public Set<String> selectComponentUuidsOfOpenIssuesForProjectUuid(DbSession sess
return mapper(session).selectComponentUuidsOfOpenIssuesForProjectUuid(projectUuid);
}

public void scrollNonClosedByComponentUuid(DbSession dbSession, String componentUuid, ResultHandler<IssueDto> handler) {
public void scrollNonClosedByComponentUuidExcludingExternals(DbSession dbSession, String componentUuid, ResultHandler<IssueDto> handler) {
mapper(dbSession).scrollNonClosedByComponentUuid(componentUuid, handler);
}

public void scrollNonClosedByModuleOrProject(DbSession dbSession, ComponentDto module, ResultHandler<IssueDto> handler) {
public void scrollNonClosedByModuleOrProjectExcludingExternals(DbSession dbSession, ComponentDto module, ResultHandler<IssueDto> handler) {
String likeModuleUuidPath = buildLikeValue(module.moduleUuidPath(), WildcardPosition.AFTER);
mapper(dbSession).scrollNonClosedByModuleOrProject(module.projectUuid(), likeModuleUuidPath, handler);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@
inner join projects p on p.uuid=i.component_uuid
inner join projects root on root.uuid=i.project_uuid
where
r.is_external = 'false' and
i.component_uuid = #{componentUuid,jdbcType=VARCHAR} and
i.status &lt;&gt; 'CLOSED'
</select>
Expand Down Expand Up @@ -244,6 +245,7 @@
inner join projects p on p.uuid = i.component_uuid
inner join projects root on root.uuid = i.project_uuid
where
r.is_external = 'false' and
i.project_uuid = #{projectUuid, jdbcType=VARCHAR} and
p.module_uuid_path like #{likeModuleUuidPath, jdbcType=VARCHAR} escape '/' and
i.status &lt;&gt; 'CLOSED'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,19 @@ public void scrollNonClosedByComponentUuid() {
IssueDto closedIssueOnFile = db.issues().insert(rule, project, file, i -> i.setStatus("CLOSED").setResolution("FIXED"));
IssueDto openIssueOnProject = db.issues().insert(rule, project, project, i -> i.setStatus("OPEN").setResolution(null));

RuleDefinitionDto external = db.rules().insert(ruleDefinitionDto -> ruleDefinitionDto.setIsExternal(true));
IssueDto issueFromExteralruleOnFile = db.issues().insert(external, project, file, i -> i.setKee("ON_FILE_FROM_EXTERNAL"));

Accumulator accumulator = new Accumulator();
underTest.scrollNonClosedByComponentUuid(db.getSession(), file.uuid(), accumulator);
underTest.scrollNonClosedByComponentUuidExcludingExternals(db.getSession(), file.uuid(), accumulator);
accumulator.assertThatContainsOnly(openIssue1OnFile, openIssue2OnFile);

accumulator.clear();
underTest.scrollNonClosedByComponentUuid(db.getSession(), project.uuid(), accumulator);
underTest.scrollNonClosedByComponentUuidExcludingExternals(db.getSession(), project.uuid(), accumulator);
accumulator.assertThatContainsOnly(openIssueOnProject);

accumulator.clear();
underTest.scrollNonClosedByComponentUuid(db.getSession(), "does_not_exist", accumulator);
underTest.scrollNonClosedByComponentUuidExcludingExternals(db.getSession(), "does_not_exist", accumulator);
assertThat(accumulator.list).isEmpty();
}

Expand All @@ -160,17 +163,20 @@ public void scrollNonClosedByModuleOrProject() {
IssueDto openIssueOnProject = db.issues().insert(rule, project, project, i -> i.setStatus("OPEN").setResolution(null));
IssueDto openIssueOnAnotherProject = db.issues().insert(rule, anotherProject, anotherProject, i -> i.setStatus("OPEN").setResolution(null));

RuleDefinitionDto external = db.rules().insert(ruleDefinitionDto -> ruleDefinitionDto.setIsExternal(true));
IssueDto issueFromExteralruleOnFile = db.issues().insert(external, project, file, i -> i.setKee("ON_FILE_FROM_EXTERNAL"));

Accumulator accumulator = new Accumulator();
underTest.scrollNonClosedByModuleOrProject(db.getSession(), project, accumulator);
underTest.scrollNonClosedByModuleOrProjectExcludingExternals(db.getSession(), project, accumulator);
accumulator.assertThatContainsOnly(openIssue1OnFile, openIssue2OnFile, openIssueOnModule, openIssueOnProject);

accumulator.clear();
underTest.scrollNonClosedByModuleOrProject(db.getSession(), module, accumulator);
underTest.scrollNonClosedByModuleOrProjectExcludingExternals(db.getSession(), module, accumulator);
accumulator.assertThatContainsOnly(openIssue1OnFile, openIssue2OnFile, openIssueOnModule);

accumulator.clear();
ComponentDto notPersisted = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
underTest.scrollNonClosedByModuleOrProject(db.getSession(), notPersisted, accumulator);
underTest.scrollNonClosedByModuleOrProjectExcludingExternals(db.getSession(), notPersisted, accumulator);
assertThat(accumulator.list).isEmpty();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ public void handle(Request request, Response response) throws Exception {
};
switch (component.scope()) {
case Scopes.PROJECT:
dbClient.issueDao().scrollNonClosedByModuleOrProject(dbSession, component, handler);
dbClient.issueDao().scrollNonClosedByModuleOrProjectExcludingExternals(dbSession, component, handler);
break;
case Scopes.FILE:
dbClient.issueDao().scrollNonClosedByComponentUuid(dbSession, component.uuid(), handler);
dbClient.issueDao().scrollNonClosedByComponentUuidExcludingExternals(dbSession, component.uuid(), handler);
break;
default:
// only projects, modules and files are supported. Other types of components are not allowed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,30 @@ public void return_issues_of_project() {
}
}

@Test
public void does_not_return_issues_from_external_rules() {
RuleDefinitionDto rule = db.rules().insert();
ComponentDto project = db.components().insertPrivateProject();
ComponentDto module = db.components().insertComponent(newModuleDto(project));
ComponentDto file = db.components().insertComponent(newFileDto(module, null));
IssueDto issueOnProject = db.issues().insert(rule, project, project, i -> i.setKee("ON_PROJECT"));
IssueDto issueOnModule = db.issues().insert(rule, project, module, i -> i.setKee("ON_MODULE"));
IssueDto issueOnFile = db.issues().insert(rule, project, file, i -> i.setKee("ON_FILE"));

RuleDefinitionDto external = db.rules().insert(ruleDefinitionDto -> ruleDefinitionDto.setIsExternal(true));
IssueDto issueFromExteralruleOnFile = db.issues().insert(external, project, file, i -> i.setKee("ON_FILE_FROM_EXTERNAL"));

addPermissionTo(project);
try (CloseableIterator<ServerIssue> result = callStream(project.getKey(), null)) {
assertThat(result)
.extracting(ServerIssue::getKey, ServerIssue::getModuleKey)
.containsExactlyInAnyOrder(
tuple(issueOnFile.getKey(), module.getKey()),
tuple(issueOnModule.getKey(), module.getKey()),
tuple(issueOnProject.getKey(), project.getKey()));
}
}

@Test
public void return_issues_of_module() {
RuleDefinitionDto rule = db.rules().insert();
Expand Down

0 comments on commit af22e60

Please sign in to comment.