From: Teryk Bellahsene Date: Wed, 13 Jan 2016 15:37:45 +0000 (+0100) Subject: SONAR-7129 WS api/components/tree search for project copy X-Git-Tag: 5.4-M5~5 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2bfedb819981ac053da492f6775386b9141869cc;p=sonarqube.git SONAR-7129 WS api/components/tree search for project copy --- diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java index aaa504649ff..59c7c542482 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java @@ -243,10 +243,10 @@ public class TreeActionTest { public void direct_children_of_a_view() throws IOException { ComponentDto view = newView("view-uuid"); SnapshotDto viewSnapshot = componentDb.insertViewAndSnapshot(view); - ComponentDto project = newProjectDto("project-uuid-1"); + ComponentDto project = newProjectDto("project-uuid-1").setName("project-name"); componentDb.insertProjectAndSnapshot(project); componentDb.insertComponentAndSnapshot(newProjectCopy("project-uuid-1-copy", project, view), viewSnapshot); - componentDb.insertComponentAndSnapshot(newSubView(view, "sub-view-uuid", "sub-view-key"), viewSnapshot); + componentDb.insertComponentAndSnapshot(newSubView(view, "sub-view-uuid", "sub-view-key").setName("sub-view-name"), viewSnapshot); db.commit(); componentDb.indexProjects(); @@ -254,6 +254,7 @@ public class TreeActionTest { .setMediaType(MediaTypes.PROTOBUF) .setParam(PARAM_STRATEGY, "children") .setParam(PARAM_BASE_COMPONENT_ID, "view-uuid") + .setParam(Param.TEXT_QUERY, "name") .execute().getInputStream(); WsComponents.TreeWsResponse response = WsComponents.TreeWsResponse.parseFrom(responseStream); diff --git a/sonar-db/src/main/java/org/sonar/db/component/ComponentTreeQuery.java b/sonar-db/src/main/java/org/sonar/db/component/ComponentTreeQuery.java index 96ac077613a..42a76c6f65a 100644 --- a/sonar-db/src/main/java/org/sonar/db/component/ComponentTreeQuery.java +++ b/sonar-db/src/main/java/org/sonar/db/component/ComponentTreeQuery.java @@ -112,7 +112,7 @@ public class ComponentTreeQuery { return Joiner.on(", ").join(sqlSortFields); } - private String buildBaseSnapshotPath(SnapshotDto baseSnapshot) { + private static String buildBaseSnapshotPath(SnapshotDto baseSnapshot) { String existingSnapshotPath = baseSnapshot.getPath() == null ? "" : baseSnapshot.getPath(); return buildLikeValue(existingSnapshotPath + baseSnapshot.getId() + ".", WildcardPosition.AFTER); } diff --git a/sonar-db/src/main/resources/org/sonar/db/component/ComponentMapper.xml b/sonar-db/src/main/resources/org/sonar/db/component/ComponentMapper.xml index 28c94bb38f5..6d92ed2c932 100644 --- a/sonar-db/src/main/resources/org/sonar/db/component/ComponentMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/component/ComponentMapper.xml @@ -355,7 +355,7 @@ select 1 from resource_index ri where - ri.resource_id=p.id + (ri.resource_id=p.id OR ri.resource_id=p.copy_resource_id) AND ri.kee like #{query.nameOrKeyQueryToSqlForResourceIndex} ESCAPE '/') OR p.kee like #{query.nameOrKeyQueryToSqlForProjectKey} ESCAPE '/') diff --git a/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java b/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java index 0eaf33e3482..65dd56ee237 100644 --- a/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java @@ -43,7 +43,9 @@ import static org.assertj.guava.api.Assertions.assertThat; import static org.sonar.db.component.ComponentTesting.newDeveloper; import static org.sonar.db.component.ComponentTesting.newFileDto; import static org.sonar.db.component.ComponentTesting.newModuleDto; +import static org.sonar.db.component.ComponentTesting.newProjectCopy; import static org.sonar.db.component.ComponentTesting.newProjectDto; +import static org.sonar.db.component.ComponentTesting.newSubView; import static org.sonar.db.component.ComponentTesting.newView; @Category(DbTests.class) @@ -868,6 +870,25 @@ public class ComponentDaoTest { assertThat(result).extracting("uuid").containsExactly("file-1-uuid", "file-2-uuid", "module-1-uuid"); } + @Test + public void select_direct_children_of_a_view() { + ComponentDto view = newView("view-uuid"); + SnapshotDto viewSnapshot = componentDb.insertViewAndSnapshot(view); + // one subview + ComponentDto subView = newSubView(view, "subview-uuid", "subview-key").setName("subview-name"); + componentDb.insertComponentAndSnapshot(subView, viewSnapshot); + // one project and its copy linked to the view + ComponentDto project = newProjectDto("project-uuid").setName("project-name"); + componentDb.insertProjectAndSnapshot(project); + componentDb.insertComponentAndSnapshot(newProjectCopy("project-copy-uuid", project, view), viewSnapshot); + componentDb.indexProjects(); + ComponentTreeQuery dbQuery = newTreeQuery(viewSnapshot).setNameOrKeyQuery("name").build(); + + List components = underTest.selectDirectChildren(dbSession, dbQuery); + + assertThat(components).extracting("uuid").containsOnly("project-copy-uuid", "subview-uuid"); + } + @Test public void select_all_files_of_a_project_paginated_and_ordered() { ComponentDto project = newProjectDto().setKey("project-key").setUuid("project-uuid"); @@ -903,7 +924,6 @@ public class ComponentDaoTest { .setPageSize(500) .setBaseSnapshot(baseSnapshot) .setSortFields(singletonList("name")) - .setAsc(true) - .setQualifiers(newArrayList(Qualifiers.FILE, Qualifiers.MODULE, Qualifiers.DIRECTORY, Qualifiers.PROJECT)); + .setAsc(true); } }