]> source.dussan.org Git - sonarqube.git/commitdiff
Fix regression on created(Before|After) on api/issues/search WS
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Wed, 30 Jul 2014 09:46:11 +0000 (11:46 +0200)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Wed, 30 Jul 2014 09:46:26 +0000 (11:46 +0200)
sonar-plugin-api/src/main/java/org/sonar/api/server/ws/Request.java
sonar-plugin-api/src/test/java/org/sonar/api/server/ws/RequestTest.java

index 87101ff78b1b1677c4242f546a7e0892fb504afc..0344d8b91d3ea863ae49fc8c9efc1b11073b1026 100644 (file)
@@ -23,6 +23,7 @@ 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 org.sonar.api.utils.SonarException;
 
 import javax.annotation.CheckForNull;
 import java.util.Date;
@@ -188,7 +189,15 @@ public abstract class Request {
   public Date paramAsDateTime(String key) {
     String s = param(key);
     if (s != null) {
-      return DateUtils.parseDateTime(s);
+      try {
+        return DateUtils.parseDateTime(s);
+      } catch(SonarException notDateTime) {
+        try {
+          return DateUtils.parseDate(s);
+        } catch (SonarException notDateEither) {
+          throw new SonarException(String.format("'%s' cannot be parsed as either a date or date+time", s));
+        }
+      }
     }
     return null;
   }
index 407a4f8f0ffd07081807cd79a582ce6fed2173ed..2c57236b86c430393ab2999f191f906bc77bc826 100644 (file)
@@ -25,6 +25,7 @@ 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 org.sonar.api.utils.SonarException;
 
 import javax.annotation.Nullable;
 
@@ -191,6 +192,12 @@ public class RequestTest {
   @Test
   public void param_as_datetime() throws Exception {
     assertThat(request.setParam("a_datetime", "2014-05-27T15:50:45+0100").paramAsDateTime("a_datetime")).isEqualTo(DateUtils.parseDateTime("2014-05-27T15:50:45+0100"));
+    assertThat(request.setParam("a_datetime", "2014-05-27").paramAsDateTime("a_datetime")).isEqualTo(DateUtils.parseDate("2014-05-27"));
+    try {
+      request.setParam("a_datetime", "polop").paramAsDateTime("a_datetime");
+    } catch (SonarException error) {
+      assertThat(error.getMessage()).isEqualTo("'polop' cannot be parsed as either a date or date+time");
+    }
   }
 
   @Test