Repository: marmotta Updated Branches: refs/heads/develop 676607916 -> 027d3ea7f
fix facading tests for date parsing Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/027d3ea7 Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/027d3ea7 Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/027d3ea7 Branch: refs/heads/develop Commit: 027d3ea7fe456bd27c0f70ead5dc2bd0098eec2a Parents: 6766079 Author: Sebastian Schaffert <[email protected]> Authored: Tue Nov 11 12:03:33 2014 +0100 Committer: Sebastian Schaffert <[email protected]> Committed: Tue Nov 11 12:03:33 2014 +0100 ---------------------------------------------------------------------- .../facading/impl/FacadingInvocationHandler.java | 15 +++++---------- .../sesame/facading/util/FacadeUtils.java | 19 +++++++++++++++---- .../facading/primitive/BoxedFacadingTest.java | 12 ++++++------ 3 files changed, 26 insertions(+), 20 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/marmotta/blob/027d3ea7/commons/marmotta-sesame-tools/marmotta-util-facading/src/main/java/org/apache/marmotta/commons/sesame/facading/impl/FacadingInvocationHandler.java ---------------------------------------------------------------------- diff --git a/commons/marmotta-sesame-tools/marmotta-util-facading/src/main/java/org/apache/marmotta/commons/sesame/facading/impl/FacadingInvocationHandler.java b/commons/marmotta-sesame-tools/marmotta-util-facading/src/main/java/org/apache/marmotta/commons/sesame/facading/impl/FacadingInvocationHandler.java index fb70791..52fd2e6 100644 --- a/commons/marmotta-sesame-tools/marmotta-util-facading/src/main/java/org/apache/marmotta/commons/sesame/facading/impl/FacadingInvocationHandler.java +++ b/commons/marmotta-sesame-tools/marmotta-util-facading/src/main/java/org/apache/marmotta/commons/sesame/facading/impl/FacadingInvocationHandler.java @@ -25,22 +25,15 @@ import org.apache.marmotta.commons.sesame.facading.api.FacadingPredicateBuilder; import org.apache.marmotta.commons.sesame.facading.model.Facade; import org.apache.marmotta.commons.sesame.facading.util.FacadeUtils; import org.apache.marmotta.commons.util.DateUtils; -import org.openrdf.model.Literal; -import org.openrdf.model.Resource; -import org.openrdf.model.Statement; -import org.openrdf.model.URI; -import org.openrdf.model.Value; +import org.joda.time.DateTime; +import org.openrdf.model.*; import org.openrdf.repository.RepositoryConnection; import org.openrdf.repository.RepositoryException; import org.openrdf.repository.RepositoryResult; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; +import java.lang.reflect.*; import java.util.*; /** @@ -756,6 +749,8 @@ class FacadingInvocationHandler implements InvocationHandler { private Value createLiteral(Object o, Locale loc) { if (o instanceof Date) { return connection.getValueFactory().createLiteral(DateUtils.getXMLCalendar((Date) o)); + } else if (o instanceof DateTime) { + return connection.getValueFactory().createLiteral(DateUtils.getXMLCalendar((DateTime) o)); } else if (Integer.class.isAssignableFrom(o.getClass())) { return connection.getValueFactory().createLiteral((Integer) o); } else if (Long.class.isAssignableFrom(o.getClass())) { http://git-wip-us.apache.org/repos/asf/marmotta/blob/027d3ea7/commons/marmotta-sesame-tools/marmotta-util-facading/src/main/java/org/apache/marmotta/commons/sesame/facading/util/FacadeUtils.java ---------------------------------------------------------------------- diff --git a/commons/marmotta-sesame-tools/marmotta-util-facading/src/main/java/org/apache/marmotta/commons/sesame/facading/util/FacadeUtils.java b/commons/marmotta-sesame-tools/marmotta-util-facading/src/main/java/org/apache/marmotta/commons/sesame/facading/util/FacadeUtils.java index 3c29da5..f003e17 100644 --- a/commons/marmotta-sesame-tools/marmotta-util-facading/src/main/java/org/apache/marmotta/commons/sesame/facading/util/FacadeUtils.java +++ b/commons/marmotta-sesame-tools/marmotta-util-facading/src/main/java/org/apache/marmotta/commons/sesame/facading/util/FacadeUtils.java @@ -19,12 +19,12 @@ package org.apache.marmotta.commons.sesame.facading.util; import org.apache.commons.lang3.LocaleUtils; import org.apache.marmotta.commons.sesame.facading.model.Facade; -import org.apache.marmotta.commons.util.DateUtils; +import org.joda.time.DateTime; +import org.joda.time.format.ISODateTimeFormat; import org.openrdf.model.Resource; import org.openrdf.model.Value; import java.lang.annotation.Annotation; -import java.text.ParseException; import java.util.Collection; import java.util.Date; import java.util.Locale; @@ -354,8 +354,19 @@ public class FacadeUtils { return null; } else { try { - return returnType.cast(DateUtils.ISO8601FORMAT.parse(value)); - } catch (final ParseException e) { + return returnType.cast(ISODateTimeFormat.dateTimeParser().parseDateTime(value).toDate()); + } catch (final IllegalArgumentException e) { + e.printStackTrace(); + return null; + } + } + } else if (DateTime.class.equals(returnType)) { + if(value == null) { + return null; + } else { + try { + return returnType.cast(ISODateTimeFormat.dateTimeParser().parseDateTime(value)); + } catch (final IllegalArgumentException e) { e.printStackTrace(); return null; } http://git-wip-us.apache.org/repos/asf/marmotta/blob/027d3ea7/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/primitive/BoxedFacadingTest.java ---------------------------------------------------------------------- diff --git a/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/primitive/BoxedFacadingTest.java b/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/primitive/BoxedFacadingTest.java index 0f6e330..01c7991 100644 --- a/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/primitive/BoxedFacadingTest.java +++ b/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/primitive/BoxedFacadingTest.java @@ -17,11 +17,6 @@ package org.apache.marmotta.commons.sesame.facading.primitive; -import java.util.Date; -import java.util.Locale; -import java.util.Random; -import java.util.UUID; - import org.apache.marmotta.commons.sesame.facading.AbstractFacadingTest; import org.apache.marmotta.commons.sesame.facading.FacadingFactory; import org.apache.marmotta.commons.sesame.facading.api.Facading; @@ -34,6 +29,11 @@ import org.openrdf.model.URI; import org.openrdf.repository.RepositoryConnection; import org.openrdf.repository.RepositoryException; +import java.util.Date; +import java.util.Locale; +import java.util.Random; +import java.util.UUID; + public class BoxedFacadingTest extends AbstractFacadingTest { private Random random; @@ -143,7 +143,7 @@ public class BoxedFacadingTest extends AbstractFacadingTest { final Locale locale = boxed.getLocale(); - Assert.assertNotNull(locale); + Assert.assertNotNull("Locale " + l + "not properly unboxed",locale); //Assert.assertEquals(l, locale); Assert.assertEquals(l.getDisplayLanguage(), locale.getDisplayLanguage()); }
