diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2016-06-16 14:28:17 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2016-06-16 19:29:03 +0200 |
commit | 2cb89afa584faf12559473030b6a82db3557deff (patch) | |
tree | a36a4b244f3663c29c824c39bd35db9bd411e268 /server | |
parent | 7eddfaa03d3fde35cc860d336ce308394c7bb494 (diff) | |
download | sonarqube-2cb89afa584faf12559473030b6a82db3557deff.tar.gz sonarqube-2cb89afa584faf12559473030b6a82db3557deff.zip |
Fix quality flaws
Diffstat (limited to 'server')
-rw-r--r-- | server/sonar-server/src/main/java/org/sonar/server/ce/ws/ActivityAction.java | 34 | ||||
-rw-r--r-- | server/sonar-server/src/main/java/org/sonar/server/ce/ws/TaskFormatter.java | 99 |
2 files changed, 41 insertions, 92 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 2a40aa7308b..038ff9fb24a 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 @@ -20,6 +20,21 @@ package org.sonar.server.ce.ws; +import static java.lang.String.format; +import static java.util.Collections.singletonList; +import static org.apache.commons.lang.StringUtils.defaultString; +import static org.sonar.api.utils.DateUtils.parseDateQuietly; +import static org.sonar.api.utils.DateUtils.parseDateTimeQuietly; +import static org.sonar.server.ws.WsUtils.checkRequest; +import static org.sonar.server.ws.WsUtils.writeProtobuf; +import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_COMPONENT_ID; +import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_COMPONENT_QUERY; +import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_MAX_EXECUTED_AT; +import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_MIN_SUBMITTED_AT; +import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_ONLY_CURRENTS; +import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_STATUS; +import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_TYPE; + import com.google.common.base.Joiner; import com.google.common.base.Optional; import com.google.common.collect.ImmutableList; @@ -56,21 +71,6 @@ import org.sonarqube.ws.WsCe; import org.sonarqube.ws.WsCe.ActivityResponse; import org.sonarqube.ws.client.ce.ActivityWsRequest; -import static java.lang.String.format; -import static java.util.Collections.singletonList; -import static org.apache.commons.lang.StringUtils.defaultString; -import static org.sonar.api.utils.DateUtils.parseDateQuietly; -import static org.sonar.api.utils.DateUtils.parseDateTimeQuietly; -import static org.sonar.server.ws.WsUtils.checkRequest; -import static org.sonar.server.ws.WsUtils.writeProtobuf; -import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_COMPONENT_ID; -import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_COMPONENT_QUERY; -import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_MAX_EXECUTED_AT; -import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_MIN_SUBMITTED_AT; -import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_ONLY_CURRENTS; -import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_STATUS; -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; @@ -242,12 +242,12 @@ public class ActivityAction implements CeWsAction { return null; } - private Iterable<WsCe.Task> loadQueuedTasks(DbSession dbSession, ActivityWsRequest request, CeTaskQuery query) { + private List<WsCe.Task> loadQueuedTasks(DbSession dbSession, ActivityWsRequest request, CeTaskQuery query) { List<CeQueueDto> dtos = dbClient.ceQueueDao().selectByQueryInDescOrder(dbSession, query, request.getPageSize()); return formatter.formatQueue(dbSession, dtos); } - private Iterable<WsCe.Task> loadPastTasks(DbSession dbSession, ActivityWsRequest request, CeTaskQuery query) { + private List<WsCe.Task> loadPastTasks(DbSession dbSession, ActivityWsRequest request, CeTaskQuery query) { List<CeActivityDto> dtos = dbClient.ceActivityDao().selectByQuery(dbSession, query, OFFSET, request.getPageSize()); return formatter.formatActivity(dbSession, dtos); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/ce/ws/TaskFormatter.java b/server/sonar-server/src/main/java/org/sonar/server/ce/ws/TaskFormatter.java index 9e1fb53a750..12c249b7868 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/ce/ws/TaskFormatter.java +++ b/server/sonar-server/src/main/java/org/sonar/server/ce/ws/TaskFormatter.java @@ -19,32 +19,29 @@ */ package org.sonar.server.ce.ws; -import com.google.common.base.Function; import com.google.common.base.Optional; import com.google.common.collect.ImmutableMap; import java.util.Collections; import java.util.Date; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; +import java.util.function.Function; +import java.util.stream.Collectors; import javax.annotation.CheckForNull; -import javax.annotation.Nonnull; import javax.annotation.Nullable; import org.sonar.api.utils.DateUtils; import org.sonar.api.utils.System2; +import org.sonar.ce.log.CeLogging; +import org.sonar.ce.log.LogFileRef; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.ce.CeActivityDto; import org.sonar.db.ce.CeQueueDto; import org.sonar.db.component.ComponentDto; -import org.sonar.db.component.ComponentDtoFunctions; -import org.sonar.ce.log.CeLogging; -import org.sonar.ce.log.LogFileRef; import org.sonarqube.ws.WsCe; -import static com.google.common.base.Predicates.notNull; -import static com.google.common.collect.FluentIterable.from; - /** * Converts {@link CeActivityDto} and {@link CeQueueDto} to the protobuf objects * used to write WS responses (see ws-ce.proto in module sonar-ws) @@ -61,10 +58,9 @@ public class TaskFormatter { this.system2 = system2; } - public Iterable<WsCe.Task> formatQueue(DbSession dbSession, List<CeQueueDto> dtos) { + public List<WsCe.Task> formatQueue(DbSession dbSession, List<CeQueueDto> dtos) { ComponentDtoCache cache = new ComponentDtoCache(dbSession, ceQueueDtoToComponentUuids(dtos)); - return from(dtos) - .transform(new CeQueueDtoToTask(cache)); + return dtos.stream().map(input -> formatQueue(input, cache)).collect(Collectors.toList()); } public WsCe.Task formatQueue(DbSession dbSession, CeQueueDto dto) { @@ -100,9 +96,9 @@ public class TaskFormatter { return formatActivity(dto, new ComponentDtoCache(dbSession, dto.getComponentUuid())); } - public Iterable<WsCe.Task> formatActivity(DbSession dbSession, List<CeActivityDto> dtos) { + public List<WsCe.Task> formatActivity(DbSession dbSession, List<CeActivityDto> dtos) { ComponentDtoCache cache = new ComponentDtoCache(dbSession, ceActivityDtoToComponentUuids(dtos)); - return from(dtos).transform(new CeActivityDtoToTask(cache)); + return dtos.stream().map(input -> formatActivity(input, cache)).collect(Collectors.toList()); } private WsCe.Task formatActivity(CeActivityDto dto, ComponentDtoCache componentDtoCache) { @@ -142,50 +138,30 @@ public class TaskFormatter { } } - private static Set<String> ceQueueDtoToComponentUuids(Iterable<CeQueueDto> dtos) { - return from(dtos) - .transform(CeQueueDtoToComponentUuid.INSTANCE) - .filter(notNull()) - .toSet(); - } - - private static Set<String> ceActivityDtoToComponentUuids(Iterable<CeActivityDto> dtos) { - return from(dtos) - .transform(CeActivityDtoToComponentUuid.INSTANCE) - .filter(notNull()) - .toSet(); - } - - private enum CeQueueDtoToComponentUuid implements Function<CeQueueDto, String> { - INSTANCE; - - @Override - @Nullable - public String apply(@Nonnull CeQueueDto input) { - return input.getComponentUuid(); - } + private static Set<String> ceQueueDtoToComponentUuids(List<CeQueueDto> dtos) { + return dtos.stream().map(CeQueueDto::getComponentUuid) + .filter(Objects::nonNull) + .collect(Collectors.toSet()); } - private enum CeActivityDtoToComponentUuid implements Function<CeActivityDto, String> { - INSTANCE; - - @Override - @Nullable - public String apply(@Nonnull CeActivityDto input) { - return input.getComponentUuid(); - } + private static Set<String> ceActivityDtoToComponentUuids(List<CeActivityDto> dtos) { + return dtos.stream().map(CeActivityDto::getComponentUuid) + .filter(Objects::nonNull) + .collect(Collectors.toSet()); } private class ComponentDtoCache { private final Map<String, ComponentDto> componentsByUuid; - public ComponentDtoCache(DbSession dbSession, Set<String> uuids) { - this.componentsByUuid = from(dbClient.componentDao().selectByUuids(dbSession, uuids)).uniqueIndex(ComponentDtoFunctions.toUuid()); + ComponentDtoCache(DbSession dbSession, Set<String> uuids) { + this.componentsByUuid = dbClient.componentDao().selectByUuids(dbSession, uuids) + .stream() + .collect(Collectors.toMap(ComponentDto::uuid, Function.identity())); } - public ComponentDtoCache(DbSession dbSession, String uuid) { + ComponentDtoCache(DbSession dbSession, String uuid) { Optional<ComponentDto> componentDto = dbClient.componentDao().selectByUuid(dbSession, uuid); - this.componentsByUuid = componentDto.isPresent() ? ImmutableMap.of(uuid, componentDto.get()) : Collections.<String, ComponentDto>emptyMap(); + this.componentsByUuid = componentDto.isPresent() ? ImmutableMap.of(uuid, componentDto.get()) : Collections.emptyMap(); } @CheckForNull @@ -201,7 +177,7 @@ public class TaskFormatter { * now - startedAt */ @CheckForNull - Long computeExecutionTimeMs(CeQueueDto dto) { + private Long computeExecutionTimeMs(CeQueueDto dto) { Long startedAt = dto.getStartedAt(); if (startedAt == null) { return null; @@ -209,31 +185,4 @@ public class TaskFormatter { return system2.now() - startedAt; } - private final class CeActivityDtoToTask implements Function<CeActivityDto, WsCe.Task> { - private final ComponentDtoCache cache; - - public CeActivityDtoToTask(ComponentDtoCache cache) { - this.cache = cache; - } - - @Override - @Nonnull - public WsCe.Task apply(@Nonnull CeActivityDto input) { - return formatActivity(input, cache); - } - } - - private final class CeQueueDtoToTask implements Function<CeQueueDto, WsCe.Task> { - private final ComponentDtoCache cache; - - public CeQueueDtoToTask(ComponentDtoCache cache) { - this.cache = cache; - } - - @Override - @Nonnull - public WsCe.Task apply(@Nonnull CeQueueDto input) { - return formatQueue(input, cache); - } - } } |