From cdd64591259fd683889be330ace758876efb364b Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Wed, 16 Aug 2017 17:39:32 +0200 Subject: [PATCH] SONAR-9708 Fix api/ce/activity when queue has no project --- .../org/sonar/server/ce/ws/ActivityAction.java | 10 +++++++--- .../sonar/server/ce/ws/ActivityActionTest.java | 15 +++++++++++++-- 2 files changed, 20 insertions(+), 5 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 bf3c7923f67..928a4bdc80e 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 @@ -234,12 +234,16 @@ public class ActivityAction implements CeWsAction { query.setStatuses(request.getStatus()); } - query.setComponentUuids(component == null ? loadComponentUuids(dbSession, request).stream().map(ComponentDto::uuid).collect(toList()) : singletonList(component.uuid())); + String componentQuery = request.getQuery(); + if (component != null) { + query.setComponentUuid(component.uuid()); + } else if (componentQuery != null) { + query.setComponentUuids(loadComponents(dbSession, componentQuery).stream().map(ComponentDto::uuid).collect(toList())); + } return query; } - private List loadComponentUuids(DbSession dbSession, ActivityWsRequest request) { - String componentQuery = request.getQuery(); + private List loadComponents(DbSession dbSession, String componentQuery) { ComponentQuery componentDtoQuery = ComponentQuery.builder() .setNameOrKeyQuery(componentQuery) .setQualifiers(POSSIBLE_QUALIFIERS) 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 d3a37c0d0ad..590ccb33ce0 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 @@ -187,6 +187,17 @@ public class ActivityActionTest { assertThat(activityResponse.getTasks(0).getId()).isEqualTo("T2"); } + @Test + public void task_without_project() { + logInAsSystemAdministrator(); + insertQueue("T3", null, PENDING); + + ActivityResponse activityResponse = call(ws.newRequest() + .setParam("status", "PENDING")); + + assertThat(activityResponse.getTasksList()).hasSize(1); + } + @Test public void limit_results() { logInAsSystemAdministrator(); @@ -481,10 +492,10 @@ public class ActivityActionTest { userSession.logIn().setSystemAdministrator(); } - private CeQueueDto insertQueue(String taskUuid, ComponentDto project, CeQueueDto.Status status) { + private CeQueueDto insertQueue(String taskUuid, @Nullable ComponentDto project, CeQueueDto.Status status) { CeQueueDto queueDto = new CeQueueDto(); queueDto.setTaskType(CeTaskTypes.REPORT); - queueDto.setComponentUuid(project.uuid()); + queueDto.setComponentUuid(project == null ? null : project.uuid()); queueDto.setUuid(taskUuid); queueDto.setStatus(status); db.getDbClient().ceQueueDao().insert(db.getSession(), queueDto); -- 2.39.5