aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2014-05-28 12:43:13 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2014-05-28 12:43:13 +0200
commit19397ac0aaf022afabbbdde4686edc550c8a5d36 (patch)
tree751aac3c3a68655671b02bc210a474411bb2944a /sonar-plugin-api
parent52e6ce846f536ec245578525c9a200f81e649681 (diff)
downloadsonarqube-19397ac0aaf022afabbbdde4686edc550c8a5d36.tar.gz
sonarqube-19397ac0aaf022afabbbdde4686edc550c8a5d36.zip
SONAR-5341 In /issues/search WS, add parameter 'extra_fields'
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/server/ws/Request.java20
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/server/ws/RequestTest.java9
2 files changed, 24 insertions, 5 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/Request.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/Request.java
index ee422a76070..f4c0a40d3f4 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/Request.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/Request.java
@@ -22,9 +22,11 @@ package org.sonar.api.server.ws;
import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
import org.apache.commons.lang.StringUtils;
+import org.sonar.api.utils.DateUtils;
import javax.annotation.CheckForNull;
+import java.util.Date;
import java.util.List;
/**
@@ -93,6 +95,7 @@ public abstract class Request {
return values;
}
+ @CheckForNull
public List<String> paramAsStrings(String key) {
String value = param(key);
if (value == null) {
@@ -182,9 +185,16 @@ public abstract class Request {
return result;
}
-// @CheckForNull
-// public Date paramAsDate(String key) {
-// String s = param(key);
-// return s == null ? null : Long.parseLong(s);
-// }
+ @CheckForNull
+ public Date paramAsDate(String key) {
+ String s = param(key);
+ if (s != null) {
+ Date date = DateUtils.parseDateTimeQuietly(s);
+ if (date != null) {
+ return date;
+ }
+ return DateUtils.parseDate(s);
+ }
+ return null;
+ }
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/server/ws/RequestTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/server/ws/RequestTest.java
index 9d2926460f6..a4b34acd653 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/server/ws/RequestTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/server/ws/RequestTest.java
@@ -24,8 +24,10 @@ import org.junit.Before;
import org.junit.Test;
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.server.ws.internal.ValidatingRequest;
+import org.sonar.api.utils.DateUtils;
import javax.annotation.Nullable;
+
import java.util.Map;
import static org.fest.assertions.Assertions.assertThat;
@@ -71,6 +73,7 @@ public class RequestTest {
action.createParam("a_boolean");
action.createParam("a_number");
action.createParam("a_enum");
+ action.createParam("a_date");
action.createParam("a_required_string").setRequired(true);
action.createParam("a_required_boolean").setRequired(true);
@@ -178,6 +181,12 @@ public class RequestTest {
}
@Test
+ public void param_as_date() throws Exception {
+ assertThat(request.setParam("a_date", "2014-05-27").paramAsDate("a_date")).isEqualTo(DateUtils.parseDate("2014-05-27"));
+ assertThat(request.setParam("a_date", "2014-05-27T15:50:45+0100").paramAsDate("a_date")).isEqualTo(DateUtils.parseDateTime("2014-05-27T15:50:45+0100"));
+ }
+
+ @Test
public void param_as_strings() throws Exception {
assertThat(request.paramAsStrings("a_string")).isNull();
assertThat(request.setParam("a_string", "").paramAsStrings("a_string")).isEmpty();