cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject git commit: [CXF-5549] Some updates to do with supporting Dates on different paths
Date Tue, 01 Jul 2014 21:30:01 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 5372863ce -> f6def6a6e


[CXF-5549] Some updates to do with supporting Dates on different paths


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/f6def6a6
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/f6def6a6
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/f6def6a6

Branch: refs/heads/master
Commit: f6def6a6eea387221d81dcf36dcd3e973dffd723
Parents: 5372863
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Tue Jul 1 22:29:42 2014 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Tue Jul 1 22:29:42 2014 +0100

----------------------------------------------------------------------
 .../cxf/jaxrs/ext/search/SearchUtils.java       | 41 +++++++++++++++-----
 .../ext/search/lucene/LuceneQueryVisitor.java   |  2 +-
 .../search/tika/TikaLuceneContentExtractor.java |  4 +-
 .../tika/TikaLuceneContentExtractorTest.java    |  2 +-
 4 files changed, 34 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/f6def6a6/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchUtils.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchUtils.java
b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchUtils.java
index a5f6128..49ad457 100644
--- a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchUtils.java
+++ b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchUtils.java
@@ -28,10 +28,12 @@ import java.util.logging.Logger;
 
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.jaxrs.ext.search.sql.SQLPrinterVisitor;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.PhaseInterceptorChain;
 
 public final class SearchUtils {
     public static final String TIMESTAMP_WITH_TIMEZONE = "yyyy-MM-dd'T'HH:mm:ss";
-    public static final String TIMESTAMP = "yyyy-MM-dd'T'HH:mm:ssZ";
+    public static final String TIMESTAMP_WITH_TIMEZONE_Z = "yyyy-MM-dd'T'HH:mm:ssZ";
     public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd";
     public static final String DATE_FORMAT_PROPERTY = "search.date-format";
     public static final String TIMEZONE_SUPPORT_PROPERTY = "search.timezone.support";
@@ -45,8 +47,27 @@ public final class SearchUtils {
         
     }
     
+    public static SimpleDateFormat getContextualDateFormat() {
+        Message m = PhaseInterceptorChain.getCurrentMessage();
+        if (m != null) {
+            return getDateFormat((String)m.getContextualProperty(DATE_FORMAT_PROPERTY));
+        } else {
+            return new SimpleDateFormat(DEFAULT_DATE_FORMAT);
+        }
+    }
+    
+    public static Date dateFromStringWithContextProperties(String value) {
+        try {
+            return getContextualDateFormat().parse(value);
+        } catch (ParseException ex) {
+            return dateFromStringWithDefaultFormats(value);
+        }
+    }
+    
     public static SimpleDateFormat getDateFormat(Map<String, String> properties) {
-        String dfProperty = properties.get(DATE_FORMAT_PROPERTY);
+        return getDateFormat(properties.get(DATE_FORMAT_PROPERTY));
+    }
+    public static SimpleDateFormat getDateFormat(String dfProperty) {
         return new SimpleDateFormat(dfProperty == null ? DEFAULT_DATE_FORMAT : dfProperty);
   
     }
     
@@ -151,26 +172,26 @@ public final class SearchUtils {
         return op;
     }
     
-    public static Date timestampFromString(final String value) {
-        Date date = timestampFromString(value, TIMESTAMP);
+    public static Date dateFromStringWithDefaultFormats(String value) {
+        value = value.replaceAll("Z$", "+0000");
+        Date date = timestampFromString(new SimpleDateFormat(TIMESTAMP_WITH_TIMEZONE_Z),
value);
         
         if (date == null) {
-            date = timestampFromString(value, TIMESTAMP_WITH_TIMEZONE);
+            date = timestampFromString(new SimpleDateFormat(TIMESTAMP_WITH_TIMEZONE), value);
         }
         
         if (date == null) {
-            date = timestampFromString(value, DEFAULT_DATE_FORMAT);
+            date = timestampFromString(getContextualDateFormat(), value);
         }
-        
+                
         return date;
     }
     
-    private  static Date timestampFromString(final String value, final String format) {
+    private  static Date timestampFromString(final SimpleDateFormat formatter, final String
value) {
         try {
-            final SimpleDateFormat formatter = new SimpleDateFormat(format); 
             return formatter.parse(value); 
         } catch (final ParseException ex) {
-            LOG.log(Level.WARNING, "Unable to parse date using format specification: " +
format, ex);
+            LOG.log(Level.FINE, "Unable to parse date using format specification: " + formatter.toPattern(),
ex);
             return null;
         }                 
     }

http://git-wip-us.apache.org/repos/asf/cxf/blob/f6def6a6/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitor.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitor.java
b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitor.java
index e485380..c697ddb 100644
--- a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitor.java
+++ b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitor.java
@@ -201,7 +201,7 @@ public class LuceneQueryVisitor<T> extends AbstractSearchConditionVisitor<T,
Que
         } else if (Date.class.isAssignableFrom(cls)) {
             // This code has not been tested - most likely needs to be fixed  
             // Resolution should be configurable ?
-            final Date date = SearchUtils.timestampFromString(value.toString());        
  
+            final Date date = SearchUtils.dateFromStringWithContextProperties(value.toString());
          
             final String luceneDateValue = (date != null) 
                 ? DateTools.dateToString(date, Resolution.MILLISECOND) : value.toString();
                 

http://git-wip-us.apache.org/repos/asf/cxf/blob/f6def6a6/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/tika/TikaLuceneContentExtractor.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/tika/TikaLuceneContentExtractor.java
b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/tika/TikaLuceneContentExtractor.java
index 09a5ba1..d84a360 100644
--- a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/tika/TikaLuceneContentExtractor.java
+++ b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/tika/TikaLuceneContentExtractor.java
@@ -24,8 +24,6 @@ import java.util.List;
 
 import org.apache.cxf.jaxrs.ext.search.SearchUtils;
 import org.apache.cxf.jaxrs.ext.search.tika.TikaContentExtractor.TikaContent;
-
-
 import org.apache.lucene.document.DateTools;
 import org.apache.lucene.document.DateTools.Resolution;
 import org.apache.lucene.document.Document;
@@ -215,7 +213,7 @@ public class TikaLuceneContentExtractor {
                     return new IntField(name, Integer.valueOf(value), Store.YES);
                 }
             } else if (Date.class.isAssignableFrom(type)) {
-                final Date date = SearchUtils.timestampFromString(value);               

+                final Date date = SearchUtils.dateFromStringWithDefaultFormats(value);  
             
                 Field field = null;
                 
                 if (date != null) {

http://git-wip-us.apache.org/repos/asf/cxf/blob/f6def6a6/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/tika/TikaLuceneContentExtractorTest.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/tika/TikaLuceneContentExtractorTest.java
b/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/tika/TikaLuceneContentExtractorTest.java
index 5574806..2010c44 100644
--- a/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/tika/TikaLuceneContentExtractorTest.java
+++ b/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/tika/TikaLuceneContentExtractorTest.java
@@ -92,7 +92,7 @@ public class TikaLuceneContentExtractorTest extends Assert {
         writer.commit();
 
         assertEquals(1, getHits("modified=gt=2007-09-14T09:02:31", documentMetadata.getFieldTypes()).length);
-        assertEquals(1, getHits("modified=le=2007-09-15T09:02:31", documentMetadata.getFieldTypes()).length);
+        assertEquals(0, getHits("modified=le=2007-09-15T09:02:31", documentMetadata.getFieldTypes()).length);
         assertEquals(1, getHits("modified=ge=2007-09-15", documentMetadata.getFieldTypes()).length);
         assertEquals(1, getHits("modified==2007-09-15", documentMetadata.getFieldTypes()).length);
         assertEquals(0, getHits("modified==2007-09-16", documentMetadata.getFieldTypes()).length);


Mime
View raw message