cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject git commit: CXF-5549: Introduce Tika Search Visitor. Added ParamConverterProvider usage into LuceneQueryVisititor
Date Tue, 08 Jul 2014 11:52:27 GMT
Repository: cxf
Updated Branches:
  refs/heads/master f5684767d -> 9a258338b


CXF-5549: Introduce Tika Search Visitor. Added ParamConverterProvider usage into LuceneQueryVisititor


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

Branch: refs/heads/master
Commit: 9a258338bef4c952db0fed6dfa108279c34a4630
Parents: f568476
Author: reta <drreta@gmail.com>
Authored: Tue Jul 8 07:51:56 2014 -0400
Committer: reta <drreta@gmail.com>
Committed: Tue Jul 8 07:51:56 2014 -0400

----------------------------------------------------------------------
 .../jaxrs/ext/search/ParamConverterUtils.java   | 81 ++++++++++++++++++++
 .../ext/search/lucene/LuceneQueryVisitor.java   | 11 +--
 .../search/tika/TikaLuceneContentExtractor.java | 37 +--------
 .../visitor/AbstractSearchConditionVisitor.java |  2 +
 .../tika/TikaLuceneContentExtractorTest.java    |  2 +-
 5 files changed, 93 insertions(+), 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/9a258338/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/ParamConverterUtils.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/ParamConverterUtils.java
b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/ParamConverterUtils.java
new file mode 100644
index 0000000..7a8b62c
--- /dev/null
+++ b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/ParamConverterUtils.java
@@ -0,0 +1,81 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.jaxrs.ext.search;
+
+import java.lang.annotation.Annotation;
+
+import javax.ws.rs.ext.ParamConverter;
+import javax.ws.rs.ext.ParamConverterProvider;
+
+/**
+ * Helper class to work with parameter converter providers and parameter converters. 
+ */
+public final class ParamConverterUtils {
+    private ParamConverterUtils() {        
+    }
+    
+    /**
+     * Converts the string-based representation of the value to the instance of particular
type
+     * using parameter converter provider and available parameter converter.
+     * @param type type to convert from string-based representation 
+     * @param provider parameter converter provider to use
+     * @param value the string-based representation to convert
+     * @return instance of particular type converter from its string representation
+     */
+    @SuppressWarnings("unchecked")
+    public static< T > T getValue(final Class< T > type, final ParamConverterProvider
provider, 
+            final String value) {
+        
+        if (String.class.isAssignableFrom(type)) {
+            return (T)value;
+        }
+        
+        if (provider != null) {        
+            final ParamConverter< T > converter = provider.getConverter(type, null,
new Annotation[0]);
+            if (converter != null) {
+                return converter.fromString(value);
+            }
+        }
+               
+        throw new IllegalArgumentException(String.format(
+                "Unable to convert string '%s' to instance of class '%s': no appropriate
converter provided",
+                value, type.getName()));        
+    }
+    
+    /**
+     * Converts the instance of particular type into its string-based representation
+     * using parameter converter provider and available parameter converter.
+     * @param type type to convert to string-based representation 
+     * @param provider parameter converter provider to use
+     * @param value the typed instance to convert to string representation
+     * @return string-based representation of the instance of particular type 
+     */
+    public static< T > String getString(final Class< T > type, final ParamConverterProvider
provider, 
+            final T value) {
+        
+        if (provider != null) {        
+            final ParamConverter< T > converter = provider.getConverter(type, null,
new Annotation[0]);
+            if (converter != null) {
+                return converter.toString(value);
+            }
+        }
+               
+        return value == null ? null : value.toString();         
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/9a258338/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 1f9dfda..11de05e 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
@@ -28,7 +28,6 @@ import java.util.Stack;
 import org.apache.cxf.jaxrs.ext.search.ConditionType;
 import org.apache.cxf.jaxrs.ext.search.PrimitiveStatement;
 import org.apache.cxf.jaxrs.ext.search.SearchCondition;
-import org.apache.cxf.jaxrs.ext.search.SearchUtils;
 import org.apache.cxf.jaxrs.ext.search.visitor.AbstractSearchConditionVisitor;
 import org.apache.lucene.document.DateTools;
 import org.apache.lucene.document.DateTools.Resolution;
@@ -42,13 +41,16 @@ import org.apache.lucene.search.TermQuery;
 import org.apache.lucene.search.TermRangeQuery;
 import org.apache.lucene.search.WildcardQuery;
 
+import static org.apache.cxf.jaxrs.ext.search.ParamConverterUtils.getString;
+import static org.apache.cxf.jaxrs.ext.search.ParamConverterUtils.getValue;
+
 public class LuceneQueryVisitor<T> extends AbstractSearchConditionVisitor<T, Query>
{
 
     private String contentsFieldName;
     private Map<String, String> contentsFieldMap;
     private Stack<List<Query>> queryStack = new Stack<List<Query>>();
     public LuceneQueryVisitor() {
-        this(Collections.<String, String>emptyMap());
+        this(Collections.<String, String>emptyMap());        
     }
     
     public LuceneQueryVisitor(String contentsFieldAlias, String contentsFieldName) {
@@ -198,9 +200,8 @@ public class LuceneQueryVisitor<T> extends AbstractSearchConditionVisitor<T,
Que
         
             return query;
         } else if (Date.class.isAssignableFrom(cls)) {
-            final Date date = SearchUtils.dateFromStringWithContextProperties(value.toString());
          
-            final String luceneDateValue = (date != null) 
-                ? DateTools.dateToString(date, Resolution.MILLISECOND) : value.toString();
+            final Date date = getValue(Date.class, getFieldTypeConverter(), value.toString());
          
+            final String luceneDateValue = getString(Date.class, getFieldTypeConverter(),
date);
                 
             if (type == ConditionType.LESS_THAN || type == ConditionType.LESS_OR_EQUALS)
{
                 return TermRangeQuery.newStringRange(name, "", luceneDateValue, minInclusive,
maxInclusive);

http://git-wip-us.apache.org/repos/asf/cxf/blob/9a258338/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 0f78791..8ca0b29 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
@@ -19,11 +19,9 @@
 package org.apache.cxf.jaxrs.ext.search.tika;
 
 import java.io.InputStream;
-import java.lang.annotation.Annotation;
 import java.util.Date;
 import java.util.List;
 
-import javax.ws.rs.ext.ParamConverter;
 import javax.ws.rs.ext.ParamConverterProvider;
 
 import org.apache.cxf.jaxrs.ext.search.tika.TikaContentExtractor.TikaContent;
@@ -39,6 +37,9 @@ import org.apache.lucene.document.TextField;
 import org.apache.tika.metadata.Metadata;
 import org.apache.tika.parser.Parser;
 
+import static org.apache.cxf.jaxrs.ext.search.ParamConverterUtils.getString;
+import static org.apache.cxf.jaxrs.ext.search.ParamConverterUtils.getValue;
+
 public class TikaLuceneContentExtractor {
     private final LuceneDocumentMetadata defaultDocumentMetadata;    
     private final TikaContentExtractor extractor;
@@ -198,38 +199,6 @@ public class TikaLuceneContentExtractor {
         return new TextField(documentMetadata.getContentFieldName(), content, Store.YES);
     }
     
-    @SuppressWarnings("unchecked")
-    private static< T > T getValue(final Class< T > type, final ParamConverterProvider
provider, 
-            final String value) {
-        
-        if (String.class.isAssignableFrom(type)) {
-            return (T)value;
-        }
-        
-        if (provider != null) {        
-            final ParamConverter< T > converter = provider.getConverter(type, null,
new Annotation[0]);
-            if (converter != null) {
-                return converter.fromString(value);
-            }
-        }
-               
-        throw new IllegalArgumentException(String.format(
-                "Unable to convert string '%s' to instance of class '%s': no appropriate
converter provided",
-                value, type.getName()));        
-    }
-    
-    private static< T > String getString(final Class< T > type, final ParamConverterProvider
provider, 
-            final T value) {
-        
-        if (provider != null) {        
-            final ParamConverter< T > converter = provider.getConverter(type, null,
new Annotation[0]);
-            if (converter != null) {
-                return converter.toString(value);
-            }
-        }
-               
-        return value == null ? null : value.toString();         
-    }
     
     private static Field getField(final LuceneDocumentMetadata documentMetadata, 
                                   final String name, final String value) { 

http://git-wip-us.apache.org/repos/asf/cxf/blob/9a258338/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/AbstractSearchConditionVisitor.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/AbstractSearchConditionVisitor.java
b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/AbstractSearchConditionVisitor.java
index 98259bd..d30b133 100644
--- a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/AbstractSearchConditionVisitor.java
+++ b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/AbstractSearchConditionVisitor.java
@@ -27,6 +27,7 @@ import java.util.Set;
 
 import javax.ws.rs.ext.ParamConverterProvider;
 
+import org.apache.cxf.jaxrs.ext.search.DefaultParamConverterProvider;
 import org.apache.cxf.jaxrs.ext.search.PrimitiveStatement;
 import org.apache.cxf.jaxrs.ext.search.SearchConditionVisitor;
 import org.apache.cxf.jaxrs.ext.search.collections.CollectionCheckInfo;
@@ -44,6 +45,7 @@ public abstract class AbstractSearchConditionVisitor <T, E> implements
SearchCon
     
     protected AbstractSearchConditionVisitor(Map<String, String> fieldMap) {
         this.fieldMap = fieldMap;
+        this.converterProvider = new DefaultParamConverterProvider();
     }
     
     protected String getRealPropertyName(String name) {

http://git-wip-us.apache.org/repos/asf/cxf/blob/9a258338/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 bd510ff..2f87eb0 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(0, getHits("modified=le=2007-09-15T09:02:31", documentMetadata.getFieldTypes()).length);
+        assertEquals(1, 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