aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2016-05-06 15:23:55 +0200
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2016-05-10 15:03:59 +0200
commit2d9bae8c4d2d03c0cccd77d567678af84ed271d5 (patch)
treeff883b6ca485859a2188af2fc9e98a10f715b8cd /server
parentb37fcd78ff36d2f10d97632f494d08c0f10f3114 (diff)
downloadsonarqube-2d9bae8c4d2d03c0cccd77d567678af84ed271d5.tar.gz
sonarqube-2d9bae8c4d2d03c0cccd77d567678af84ed271d5.zip
SONAR-7370 WS api/ce/activity returns developers
Diffstat (limited to 'server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/ce/ws/ActivityAction.java17
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/ce/ws/ActivityActionTest.java30
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java14
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/permission/ws/SearchProjectPermissionsActionTest.java6
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/BulkApplyTemplateActionTest.java2
5 files changed, 49 insertions, 20 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/ce/ws/ActivityAction.java b/server/sonar-server/src/main/java/org/sonar/server/ce/ws/ActivityAction.java
index 1a15334bd80..8ab38f7c912 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/ce/ws/ActivityAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/ce/ws/ActivityAction.java
@@ -74,6 +74,7 @@ import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_TYPE;
public class ActivityAction implements CeWsAction {
private static final int OFFSET = 0;
private static final int MAX_PAGE_SIZE = 1000;
+ private static final List<String> POSSIBLE_QUALIFIERS = ImmutableList.of(Qualifiers.PROJECT, Qualifiers.VIEW, "DEV");
private final UserSession userSession;
private final DbClient dbClient;
@@ -216,22 +217,28 @@ public class ActivityAction implements CeWsAction {
query.setStatuses(request.getStatus());
}
- loadComponentUuids(dbSession, request, query);
+ query.setComponentUuids(loadComponentUuids(dbSession, request));
return query;
}
- private void loadComponentUuids(DbSession dbSession, ActivityWsRequest request, CeTaskQuery query) {
+ @CheckForNull
+ private List<String> loadComponentUuids(DbSession dbSession, ActivityWsRequest request) {
String componentUuid = request.getComponentId();
String componentQuery = request.getQuery();
if (componentUuid != null) {
- query.setComponentUuid(componentUuid);
+ return singletonList(componentUuid);
}
if (componentQuery != null) {
- ComponentQuery componentDtoQuery = ComponentQuery.builder().setNameOrKeyQuery(componentQuery).setQualifiers(Qualifiers.PROJECT, Qualifiers.VIEW).build();
+ ComponentQuery componentDtoQuery = ComponentQuery.builder()
+ .setNameOrKeyQuery(componentQuery)
+ .setQualifiers(POSSIBLE_QUALIFIERS.toArray(new String[0]))
+ .build();
List<ComponentDto> componentDtos = dbClient.componentDao().selectByQuery(dbSession, componentDtoQuery, 0, CeTaskQuery.MAX_COMPONENT_UUIDS);
- query.setComponentUuids(Lists.transform(componentDtos, ComponentDtoFunctions.toUuid()));
+ return Lists.transform(componentDtos, ComponentDtoFunctions.toUuid());
}
+
+ return null;
}
private Iterable<WsCe.Task> loadQueuedTasks(DbSession dbSession, ActivityWsRequest request, CeTaskQuery query) {
diff --git a/server/sonar-server/src/test/java/org/sonar/server/ce/ws/ActivityActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/ce/ws/ActivityActionTest.java
index eeb4690492e..da181306d87 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/ce/ws/ActivityActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/ce/ws/ActivityActionTest.java
@@ -43,6 +43,7 @@ import org.sonar.db.ce.CeActivityDto;
import org.sonar.db.ce.CeQueueDto;
import org.sonar.db.ce.CeTaskTypes;
import org.sonar.db.component.ComponentDbTester;
+import org.sonar.db.component.ComponentDto;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.TestRequest;
@@ -61,7 +62,9 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.sonar.api.utils.DateUtils.formatDate;
import static org.sonar.api.utils.DateUtils.formatDateTime;
+import static org.sonar.db.component.ComponentTesting.newDeveloper;
import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newView;
import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_COMPONENT_QUERY;
import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_STATUS;
@@ -210,11 +213,14 @@ public class ActivityActionTest {
@Test
public void search_activity_by_component_name() throws IOException {
- componentDb.insertProjectAndSnapshot(newProjectDto().setName("apache struts").setUuid("P1"));
- componentDb.insertProjectAndSnapshot(newProjectDto().setName("apache zookeeper").setUuid("P2"));
- componentDb.insertProjectAndSnapshot(newProjectDto().setName("eclipse").setUuid("P3"));
+ ComponentDto struts = newProjectDto().setName("old apache struts").setUuid("P1");
+ ComponentDto zookeeper = newProjectDto().setName("new apache zookeeper").setUuid("P2");
+ ComponentDto eclipse = newProjectDto().setName("eclipse").setUuid("P3");
+ componentDb.insertProjectAndSnapshot(struts);
+ componentDb.insertProjectAndSnapshot(zookeeper);
+ componentDb.insertProjectAndSnapshot(eclipse);
dbTester.commit();
- componentDb.indexProjects();
+ componentDb.indexComponents(struts.getId(), zookeeper.getId(), eclipse.getId());
userSession.setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
insertActivity("T1", "P1", CeActivityDto.Status.SUCCESS);
insertActivity("T2", "P2", CeActivityDto.Status.SUCCESS);
@@ -226,6 +232,22 @@ public class ActivityActionTest {
}
@Test
+ public void search_activity_returns_views_and_developers() {
+ ComponentDto developer = newDeveloper("Apache Developer").setUuid("D1");
+ ComponentDto apacheView = newView().setName("Apache View").setUuid("V1");
+ componentDb.insertDeveloperAndSnapshot(developer);
+ componentDb.insertViewAndSnapshot(apacheView);
+ componentDb.indexComponents(developer.getId(), apacheView.getId());
+ userSession.setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
+ insertActivity("T1", "D1", CeActivityDto.Status.SUCCESS);
+ insertActivity("T2", "V1", CeActivityDto.Status.SUCCESS);
+
+ ActivityResponse activityResponse = call(ws.newRequest().setParam(PARAM_COMPONENT_QUERY, "apac"));
+
+ assertThat(activityResponse.getTasksList()).extracting("id").containsOnly("T1", "T2");
+ }
+
+ @Test
public void search_task_id_in_queue_ignoring_other_parameters() throws IOException {
insertQueue("T1", "PROJECT_1", CeQueueDto.Status.IN_PROGRESS);
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 16f4f42fc2a..81f47d59f97 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
@@ -118,7 +118,7 @@ public class TreeActionTest {
SnapshotDto directorySnapshot = componentDb.insertComponentAndSnapshot(newDirectory(project, "directory-path-1"), moduleSnapshot);
componentDb.insertComponentAndSnapshot(newFileDto(project, 10), directorySnapshot);
db.commit();
- componentDb.indexProjects();
+ componentDb.indexProjectsAndViews();
TreeWsResponse response = call(ws.newRequest()
.setParam(PARAM_STRATEGY, "children")
@@ -149,7 +149,7 @@ public class TreeActionTest {
SnapshotDto directorySnapshot = componentDb.insertComponentAndSnapshot(newDirectory(project, "directory-path-1"), moduleSnapshot);
componentDb.insertComponentAndSnapshot(newFileDto(project, 1), directorySnapshot);
db.commit();
- componentDb.indexProjects();
+ componentDb.indexProjectsAndViews();
TreeWsResponse response = call(ws.newRequest()
.setParam(PARAM_STRATEGY, "all")
@@ -175,7 +175,7 @@ public class TreeActionTest {
SnapshotDto directorySnapshot = componentDb.insertComponentAndSnapshot(newDirectory(project, "directory-path-1"), moduleSnapshot);
componentDb.insertComponentAndSnapshot(newFileDto(project, 3), directorySnapshot);
db.commit();
- componentDb.indexProjects();
+ componentDb.indexProjectsAndViews();
TreeWsResponse response = call(ws.newRequest()
.setParam(PARAM_STRATEGY, "leaves")
@@ -195,7 +195,7 @@ public class TreeActionTest {
componentDb.insertComponentAndSnapshot(newFileDto(project, 2), projectSnapshot);
componentDb.insertComponentAndSnapshot(newModuleDto("module-uuid-1", project), projectSnapshot);
db.commit();
- componentDb.indexProjects();
+ componentDb.indexProjectsAndViews();
TreeWsResponse response = call(ws.newRequest()
.setParam(PARAM_STRATEGY, "all")
@@ -215,7 +215,7 @@ public class TreeActionTest {
componentDb.insertComponentAndSnapshot(module, projectSnapshot);
componentDb.insertComponentAndSnapshot(newDirectory(project, "path/directory/", "directory-uuid-1"), projectSnapshot);
db.commit();
- componentDb.indexProjects();
+ componentDb.indexProjectsAndViews();
TreeWsResponse response = call(ws.newRequest()
.setParam(PARAM_STRATEGY, "all")
@@ -234,7 +234,7 @@ public class TreeActionTest {
componentDb.insertComponentAndSnapshot(newProjectCopy("project-uuid-1-copy", project, view), viewSnapshot);
componentDb.insertComponentAndSnapshot(newSubView(view, "sub-view-uuid", "sub-view-key").setName("sub-view-name"), viewSnapshot);
db.commit();
- componentDb.indexProjects();
+ componentDb.indexProjectsAndViews();
TreeWsResponse response = call(ws.newRequest()
.setParam(PARAM_STRATEGY, "children")
@@ -414,7 +414,7 @@ public class TreeActionTest {
projectSnapshot);
}
db.commit();
- componentDb.indexProjects();
+ componentDb.indexProjectsAndViews();
return project;
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/SearchProjectPermissionsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/SearchProjectPermissionsActionTest.java
index fa54083e525..73e96ee5aec 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/SearchProjectPermissionsActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/SearchProjectPermissionsActionTest.java
@@ -184,7 +184,7 @@ public class SearchProjectPermissionsActionTest {
public void search_by_query_on_name() {
componentDb.insertProjectAndSnapshot(newProjectDto().setName("project-name"));
componentDb.insertProjectAndSnapshot(newProjectDto().setName("another-name"));
- componentDb.indexProjects();
+ componentDb.indexProjectsAndViews();
String result = ws.newRequest()
.setParam(TEXT_QUERY, "project")
@@ -198,7 +198,7 @@ public class SearchProjectPermissionsActionTest {
public void search_by_query_on_key_must_match_exactly() {
componentDb.insertProjectAndSnapshot(newProjectDto().setKey("project-key"));
componentDb.insertProjectAndSnapshot(newProjectDto().setKey("another-key"));
- componentDb.indexProjects();
+ componentDb.indexProjectsAndViews();
String result = ws.newRequest()
.setParam(TEXT_QUERY, "project-key")
@@ -213,7 +213,7 @@ public class SearchProjectPermissionsActionTest {
for (int i = 1; i <= 1001; i++) {
componentDb.insertProjectAndSnapshot(newProjectDto("project-uuid-" + i));
}
- componentDb.indexProjects();
+ componentDb.indexProjectsAndViews();
String result = ws.newRequest()
.setParam(TEXT_QUERY, "project")
diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/BulkApplyTemplateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/BulkApplyTemplateActionTest.java
index 629c32a1a0e..8b3e5a8a9df 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/BulkApplyTemplateActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/BulkApplyTemplateActionTest.java
@@ -181,7 +181,7 @@ public class BulkApplyTemplateActionTest {
// match must be exact on key
ComponentDto projectUntouched = newProjectDto().setKey("new-sonar").setName("project-name");
componentDb.insertProjectAndSnapshot(projectUntouched);
- componentDb.indexProjects();
+ componentDb.indexProjectsAndViews();
call(ws.newRequest()
.setParam(PARAM_TEMPLATE_ID, template1.getUuid())