aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/ce/ws/ActivityAction.java42
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/issue/IssueQueryService.java17
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/ce/ws/ActivityActionTest.java2
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/utils/DateUtils.java4
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/utils/DateUtilsTest.java4
5 files changed, 14 insertions, 55 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 206920be337..9c26b418bcd 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
@@ -30,7 +30,6 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
@@ -59,8 +58,8 @@ 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.api.utils.DateUtils.parseEndingDateOrDateTime;
+import static org.sonar.api.utils.DateUtils.parseStartingDateOrDateTime;
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;
@@ -211,8 +210,10 @@ public class ActivityAction implements CeWsAction {
CeTaskQuery query = new CeTaskQuery();
query.setType(request.getType());
query.setOnlyCurrents(request.getOnlyCurrents());
- query.setMinSubmittedAt(parseFromDate(request.getMinSubmittedAt()));
- query.setMaxExecutedAt(parseToDate(request.getMaxExecutedAt()));
+ Date minSubmittedAt = parseStartingDateOrDateTime(request.getMinSubmittedAt());
+ query.setMinSubmittedAt(minSubmittedAt == null ? null : minSubmittedAt.getTime());
+ Date maxExecutedAt = parseEndingDateOrDateTime(request.getMaxExecutedAt());
+ query.setMaxExecutedAt(maxExecutedAt == null ? null : maxExecutedAt.getTime());
List<String> statuses = request.getStatus();
if (statuses != null && !statuses.isEmpty()) {
@@ -264,37 +265,6 @@ public class ActivityAction implements CeWsAction {
}
}
- @CheckForNull
- private static Long parseToDate(@Nullable String dateAsString) {
- if (dateAsString == null) {
- return null;
- }
-
- Date date = parseDateTimeQuietly(dateAsString);
- if (date == null) {
- date = parseDateQuietly(dateAsString);
- checkRequest(date != null, "Date '%s' cannot be parsed as either a date or date+time", dateAsString);
- date = DateUtils.addDays(date, 1);
- }
-
- return date.getTime();
- }
-
- @CheckForNull
- private static Long parseFromDate(@Nullable String dateAsString) {
- if (dateAsString == null) {
- return null;
- }
-
- Date date = parseDateTimeQuietly(dateAsString);
- if (date == null) {
- date = parseDateQuietly(dateAsString);
- checkRequest(date != null, "Date '%s' cannot be parsed as either a date or date+time", dateAsString);
- }
-
- return date.getTime();
- }
-
public static boolean isAllowedOnComponentUuid(UserSession userSession, String componentUuid) {
return userSession.hasPermission(GlobalPermissions.SYSTEM_ADMIN) || userSession.hasComponentUuidPermission(UserRole.ADMIN, componentUuid);
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueQueryService.java b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueQueryService.java
index 08d0f6db3e2..610a72699c2 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueQueryService.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueQueryService.java
@@ -70,6 +70,7 @@ import static com.google.common.collect.FluentIterable.from;
import static com.google.common.collect.Lists.newArrayList;
import static java.lang.String.format;
import static org.sonar.api.utils.DateUtils.longToDate;
+import static org.sonar.api.utils.DateUtils.parseEndingDateOrDateTime;
import static org.sonar.db.component.ComponentDtoFunctions.toProjectUuid;
import static org.sonar.server.ws.WsUtils.checkFoundWithOptional;
import static org.sonar.server.ws.WsUtils.checkRequest;
@@ -122,7 +123,7 @@ public class IssueQueryService {
.hideRules(RubyUtils.toBoolean(params.get(IssueFilterParameters.HIDE_RULES)))
.createdAt(RubyUtils.toDate(params.get(IssueFilterParameters.CREATED_AT)))
.createdAfter(buildCreatedAfterFromDates(RubyUtils.toDate(params.get(CREATED_AFTER)), (String) params.get(CREATED_IN_LAST)))
- .createdBefore(RubyUtils.toDate(buildCreatedBefore((String) params.get(IssueFilterParameters.CREATED_BEFORE))));
+ .createdBefore(RubyUtils.toDate(parseEndingDateOrDateTime((String) params.get(IssueFilterParameters.CREATED_BEFORE))));
Set<String> allComponentUuids = Sets.newHashSet();
boolean effectiveOnComponentOnly = mergeDeprecatedComponentParameters(session,
@@ -193,7 +194,7 @@ public class IssueQueryService {
.types(request.getTypes())
.assigned(request.getAssigned())
.createdAt(parseAsDateTime(request.getCreatedAt()))
- .createdBefore(buildCreatedBefore(request.getCreatedBefore()))
+ .createdBefore(parseEndingDateOrDateTime(request.getCreatedBefore()))
.facetMode(request.getFacetMode());
Set<String> allComponentUuids = Sets.newHashSet();
@@ -248,18 +249,6 @@ public class IssueQueryService {
}
@CheckForNull
- private static Date buildCreatedBefore(String stringDate) {
- Date date = DateUtils.parseDateTimeQuietly(stringDate);
- if (date != null) {
- return date;
- }
-
- date = DateUtils.parseDateQuietly(stringDate);
-
- return date == null ? null : DateUtils.addDays(date, 1);
- }
-
- @CheckForNull
private Date findCreatedAfterFromComponentUuid(DbSession dbSession, String uuid) {
ComponentDto component = checkFoundWithOptional(componentService.getByUuid(uuid), "Component with id '%s' not found", uuid);
Optional<SnapshotDto> snapshot = dbClient.snapshotDao().selectLastAnalysisByComponentUuid(dbSession, component.uuid());
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 34b86270e3d..5a15efb7e24 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
@@ -312,7 +312,7 @@ public class ActivityActionTest {
@Test
public void fail_if_date_is_not_well_formatted() {
- expectedException.expect(BadRequestException.class);
+ expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Date 'ill-formatted-date' cannot be parsed as either a date or date+time");
ws.newRequest()
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/DateUtils.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/DateUtils.java
index b3f1a36311d..ee54763a274 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/DateUtils.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/DateUtils.java
@@ -161,7 +161,7 @@ public final class DateUtils {
}
date = parseDateQuietly(stringDate);
- checkArgument(date != null, "'%s' cannot be parsed as either a date or date+time", stringDate);
+ checkArgument(date != null, "Date '%s' cannot be parsed as either a date or date+time", stringDate);
return date;
}
@@ -194,7 +194,7 @@ public final class DateUtils {
}
date = parseDateQuietly(stringDate);
- checkArgument(date != null, "'%s' cannot be parsed as either a date or date+time", stringDate);
+ checkArgument(date != null, "Date '%s' cannot be parsed as either a date or date+time", stringDate);
return addDays(date, 1);
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/DateUtilsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/DateUtilsTest.java
index 94892baf665..b778b878af7 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/DateUtilsTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/DateUtilsTest.java
@@ -173,7 +173,7 @@ public class DateUtilsTest {
@Test
public void fail_when_param_as_date_or_datetime_not_a_datetime() {
expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("'polop' cannot be parsed as either a date or date+time");
+ expectedException.expectMessage("Date 'polop' cannot be parsed as either a date or date+time");
parseDateOrDateTime("polop");
}
@@ -181,7 +181,7 @@ public class DateUtilsTest {
@Test
public void fail_when_param_as_starting_datetime_not_a_datetime() {
expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("'polop' cannot be parsed as either a date or date+time");
+ expectedException.expectMessage("Date 'polop' cannot be parsed as either a date or date+time");
parseStartingDateOrDateTime("polop");
}