cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1419097 - in /cxf/branches/2.6.x-fixes: ./ rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/ rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/client/ rt/rs/extensions/search/src/test/java/org/apach...
Date Sun, 09 Dec 2012 19:14:54 GMT
Author: sergeyb
Date: Sun Dec  9 19:14:53 2012
New Revision: 1419097

URL: http://svn.apache.org/viewvc?rev=1419097&view=rev
Log:
Merged revisions 1419014,1419094 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1419014 | sergeyb | 2012-12-09 16:21:19 +0000 (Sun, 09 Dec 2012) | 1 line
  
  Making it easier to pass parser/contextual properties by adding a couple of more methods
to SearchContext
........
  r1419094 | sergeyb | 2012-12-09 19:00:50 +0000 (Sun, 09 Dec 2012) | 1 line
  
  Few updates to SearchConditionBuilder to make it simpler to build some comlpex expressions
........

Modified:
    cxf/branches/2.6.x-fixes/   (props changed)
    cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContext.java
    cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContextImpl.java
    cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/client/CompleteCondition.java
    cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/client/FiqlSearchConditionBuilder.java
    cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/client/Property.java
    cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/client/FiqlSearchConditionBuilderTest.java

Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/trunk:r1419014-1419094

Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContext.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContext.java?rev=1419097&r1=1419096&r2=1419097&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContext.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContext.java
Sun Dec  9 19:14:53 2012
@@ -48,6 +48,21 @@ public interface SearchContext {
      */
     <T> SearchCondition<T> getCondition(Class<T> cls, Map<String, String>
beanProperties);
     
+    /**
+     * Returns the typed search condition representing 
+     * the search expression which is extracted from 
+     * the request URI
+     * 
+     * @param cls the type of the bean(s) the new search condition will 
+     *        attempt to match
+     * @param beanProperties mapping between search and bean properties
+     * @param parserProperties parser properties       
+     * @return the search condition
+     */
+    <T> SearchCondition<T> getCondition(Class<T> cls, 
+                                        Map<String, String> beanProperties, 
+                                        Map<String, String> parserProperties);
+    
     
     /**
      * Returns the typed search condition representing 
@@ -72,6 +87,21 @@ public interface SearchContext {
      */
     <T> SearchCondition<T> getCondition(String expression, Class<T> cls,
Map<String, String> beanProperties);
     
+    /**
+     * Returns the typed search condition representing 
+     * the provided search expression
+     * 
+     * @param expression the search expression
+     * @param cls the type of the bean(s) the new search condition will 
+     *        attempt to match
+     * @param beanProperties mapping between search and bean properties
+     * @param parserProperties parser properties       
+     * @return the search condition
+     */
+    <T> SearchCondition<T> getCondition(String expression, Class<T> cls,

+                                        Map<String, String> beanProperties,
+                                        Map<String, String> parserProperties);
+    
     
     /**
      * Returns the search expression

Modified: cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContextImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContextImpl.java?rev=1419097&r1=1419096&r2=1419097&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContextImpl.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContextImpl.java
Sun Dec  9 19:14:53 2012
@@ -51,20 +51,33 @@ public class SearchContextImpl implement
         return getCondition(null, cls, beanProperties);
     }
     
+    public <T> SearchCondition<T> getCondition(Class<T> cls, 
+                                               Map<String, String> beanProperties,
+                                               Map<String, String> parserProperties)
{
+        return getCondition(null, cls, beanProperties, parserProperties);
+    }
+    
     public <T> SearchCondition<T> getCondition(String expression, Class<T>
cls) {
         return getCondition(expression, cls, null);
     }
     
     public <T> SearchCondition<T> getCondition(String expression, 
                                                Class<T> cls, 
-                                               Map<String, String> beanProperties)
{    
+                                               Map<String, String> beanProperties)
{
+        return getCondition(expression, cls, beanProperties, null);
+    }
+    
+    public <T> SearchCondition<T> getCondition(String expression, 
+                                               Class<T> cls, 
+                                               Map<String, String> beanProperties,
+                                               Map<String, String> parserProperties)
{    
         if (InjectionUtils.isPrimitive(cls)) {
             String errorMessage = "Primitive condition types are not supported"; 
             LOG.warning(errorMessage);
             throw new IllegalArgumentException(errorMessage);
         }
         
-        SearchConditionParser<T> parser = getParser(cls, beanProperties);
+        SearchConditionParser<T> parser = getParser(cls, beanProperties, parserProperties);
         
         String theExpression = expression == null 
             ? getSearchExpression() : expression;
@@ -97,17 +110,24 @@ public class SearchContextImpl implement
         }
     }
     
-    private <T> SearchConditionParser<T> getParser(Class<T> cls, Map<String,
String> beanProperties) {
+    private <T> SearchConditionParser<T> getParser(Class<T> cls, 
+                                                   Map<String, String> beanProperties,
+                                                   Map<String, String> parserProperties)
{
         // we can use this method as a parser factory, ex
         // we can get parsers capable of parsing XQuery and other languages
         // depending on the properties set by a user
-        Map<String, String> props = new LinkedHashMap<String, String>(4);
-        props.put(SearchUtils.DATE_FORMAT_PROPERTY, 
-                  (String)message.getContextualProperty(SearchUtils.DATE_FORMAT_PROPERTY));
-        props.put(SearchUtils.TIMEZONE_SUPPORT_PROPERTY, 
-                  (String)message.getContextualProperty(SearchUtils.TIMEZONE_SUPPORT_PROPERTY));
-        props.put(SearchUtils.LAX_PROPERTY_MATCH, 
-                  (String)message.getContextualProperty(SearchUtils.LAX_PROPERTY_MATCH));
+        Map<String, String> props = null;
+        if (parserProperties == null) {
+            props = new LinkedHashMap<String, String>(4);
+            props.put(SearchUtils.DATE_FORMAT_PROPERTY, 
+                      (String)message.getContextualProperty(SearchUtils.DATE_FORMAT_PROPERTY));
+            props.put(SearchUtils.TIMEZONE_SUPPORT_PROPERTY, 
+                      (String)message.getContextualProperty(SearchUtils.TIMEZONE_SUPPORT_PROPERTY));
+            props.put(SearchUtils.LAX_PROPERTY_MATCH, 
+                      (String)message.getContextualProperty(SearchUtils.LAX_PROPERTY_MATCH));
+        } else {
+            props = parserProperties;
+        }
         
         Map<String, String> beanProps = null;
             

Modified: cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/client/CompleteCondition.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/client/CompleteCondition.java?rev=1419097&r1=1419096&r2=1419097&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/client/CompleteCondition.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/client/CompleteCondition.java
Sun Dec  9 19:14:53 2012
@@ -34,6 +34,10 @@ public interface CompleteCondition {
     /** shortcut for or().is() */
     Property or(String name);
     
+    /** Wraps the current expression in ()*/
+    CompleteCondition wrap();
+    
+    
     /** Finalize condition construction and build search condition query. */
     String query();
 }

Modified: cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/client/FiqlSearchConditionBuilder.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/client/FiqlSearchConditionBuilder.java?rev=1419097&r1=1419096&r2=1419097&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/client/FiqlSearchConditionBuilder.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/client/FiqlSearchConditionBuilder.java
Sun Dec  9 19:14:53 2012
@@ -86,6 +86,7 @@ public class FiqlSearchConditionBuilder 
         private Builder parent;
         private DateFormat df;
         private boolean timeZoneSupported;
+        private String currentCompositeOp;
 
         public Builder(Map<String, String> properties) {
             parent = null;
@@ -128,22 +129,31 @@ public class FiqlSearchConditionBuilder 
             return condition(FiqlParser.LT, toString(date));
         }
 
-        public CompleteCondition equalTo(String literalOrPattern) {
-            return condition(FiqlParser.EQ, literalOrPattern);
+        public CompleteCondition equalTo(String value, String...moreValues) {
+            return condition(FiqlParser.EQ, value, (Object[])moreValues);
         }
 
-        public CompleteCondition equalTo(double number) {
-            return condition(FiqlParser.EQ, number);
+        public CompleteCondition equalTo(Double number, Double... moreValues) {
+            return condition(FiqlParser.EQ, number, (Object[])moreValues);
         }
         
-        public CompleteCondition equalTo(long number) {
-            return condition(FiqlParser.EQ, number);
+        public CompleteCondition equalTo(Long number, Long... moreValues) {
+            return condition(FiqlParser.EQ, number, (Object[])moreValues);
+        }
+        
+        public CompleteCondition equalTo(Integer number, Integer... moreValues) {
+            return condition(FiqlParser.EQ, number, (Object[])moreValues);
+        }
+
+        public CompleteCondition equalTo(Date date, Date... moreValues) {
+            return condition(FiqlParser.EQ, date, (Object[])moreValues);
         }
 
-        public CompleteCondition equalTo(Date date) {
-            return condition(FiqlParser.EQ, toString(date));
+        public CompleteCondition equalTo(Duration distanceFromNow, Duration... moreValues)
{
+            return condition(FiqlParser.EQ, distanceFromNow, (Object[])moreValues);
         }
 
+        
         public CompleteCondition greaterOrEqualTo(double number) {
             return condition(FiqlParser.GE, number);
         }
@@ -224,10 +234,6 @@ public class FiqlSearchConditionBuilder 
             return condition(FiqlParser.LT, distanceFromNow);
         }
 
-        public CompleteCondition equalTo(Duration distanceFromNow) {
-            return condition(FiqlParser.EQ, distanceFromNow);
-        }
-
         public CompleteCondition notAfter(Duration distanceFromNow) {
             return condition(FiqlParser.LE, distanceFromNow);
         }
@@ -240,12 +246,29 @@ public class FiqlSearchConditionBuilder 
             return condition(FiqlParser.NEQ, distanceFromNow);
         }
 
-        protected CompleteCondition condition(String operator, Object value) {
-            result += operator + value;
+        protected CompleteCondition condition(String operator, Object value, Object...moreValues)
{
+            String name = result;
+            result += operator + toString(value);
+            if (moreValues != null && moreValues.length > 0) {
+                for (Object next : moreValues) {
+                    result += "," + name + operator + toString(next);
+                }
+                currentCompositeOp = FiqlParser.OR;
+            }
             return this;
         }
         
         public PartialCondition and() {
+            if (currentCompositeOp == FiqlParser.OR 
+                || parent != null && parent.currentCompositeOp == FiqlParser.OR)
{
+                if (parent != null) {
+                    parent.result = "(" + parent.result;
+                    result += ")";
+                } else {
+                    wrap();
+                }
+                currentCompositeOp = FiqlParser.AND;
+            }
             result += FiqlParser.AND;
             return this;
         }
@@ -255,6 +278,16 @@ public class FiqlSearchConditionBuilder 
         }
 
         public PartialCondition or() {
+            if (currentCompositeOp == FiqlParser.AND
+                || parent != null && parent.currentCompositeOp == FiqlParser.AND)
{
+                if (parent != null) {
+                    parent.result = "(" + parent.result;
+                    result += ")";
+                } else {
+                    wrap();
+                }
+                currentCompositeOp = FiqlParser.OR;
+            }
             result += FiqlParser.OR;
             return this;
         }
@@ -263,6 +296,12 @@ public class FiqlSearchConditionBuilder 
             return or().is(name);
         }
 
+        public CompleteCondition wrap() {
+            result = "(" + result + ")";
+            this.currentCompositeOp = null;
+            return this;
+        }
+        
         public CompleteCondition and(CompleteCondition c1, CompleteCondition c2, CompleteCondition...
cn) {
             result += "(" + ((Builder)c1).buildPartial(this) + FiqlParser.AND
                       + ((Builder)c2).buildPartial(this);
@@ -289,14 +328,21 @@ public class FiqlSearchConditionBuilder 
             return b;
         }
 
-        private String toString(Date date) {
-            String s = df.format(date);
-            if (timeZoneSupported) {
-                // zone in XML is "+01:00" in Java is "+0100"; adding semicolon
-                int len = s.length();
-                return s.substring(0, len - 2) + ":" + s.substring(len - 2, len);
+        private String toString(Object value) {
+            if (value == null) {
+                return null;
+            }
+            if (value.getClass() == Date.class) {
+                String s = df.format((Date)value);
+                if (timeZoneSupported) {
+                    // zone in XML is "+01:00" in Java is "+0100"; adding semicolon
+                    int len = s.length();
+                    return s.substring(0, len - 2) + ":" + s.substring(len - 2, len);
+                } else {
+                    return s;
+                }
             } else {
-                return s;
+                return value.toString();
             }
         }
     }

Modified: cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/client/Property.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/client/Property.java?rev=1419097&r1=1419096&r2=1419097&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/client/Property.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/client/Property.java
Sun Dec  9 19:14:53 2012
@@ -27,19 +27,22 @@ import javax.xml.datatype.Duration;
  */
 public interface Property {
     /** Is textual property equal to given literal or matching given pattern? */
-    CompleteCondition equalTo(String literalOrPattern);
+    CompleteCondition equalTo(String value, String ...moreValues);
 
     /** Is numeric property equal to given double number? */
-    CompleteCondition equalTo(double number);
+    CompleteCondition equalTo(Double number, Double... moreValues);
 
     /** Is numeric property equal to given long number? */
-    CompleteCondition equalTo(long number);
+    CompleteCondition equalTo(Long number, Long... moreValues);
+    
+    /** Is numeric property equal to given long number? */
+    CompleteCondition equalTo(Integer number, Integer... moreValues);
     
     /** Is date property same as given date? */
-    CompleteCondition equalTo(Date date);
+    CompleteCondition equalTo(Date date, Date... moreValues);
 
     /** Is date property same as date distant from now by given period of time? */
-    CompleteCondition equalTo(Duration distanceFromNow);
+    CompleteCondition equalTo(Duration distanceFromNow, Duration... moreValues);
 
     /** Is textual property different than given literal or not matching given pattern? */
     CompleteCondition notEqualTo(String literalOrPattern);

Modified: cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/client/FiqlSearchConditionBuilderTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/client/FiqlSearchConditionBuilderTest.java?rev=1419097&r1=1419096&r2=1419097&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/client/FiqlSearchConditionBuilderTest.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/client/FiqlSearchConditionBuilderTest.java
Sun Dec  9 19:14:53 2012
@@ -297,12 +297,46 @@ public class FiqlSearchConditionBuilderT
 
     @Test
     public void testComplex2() {
-        String ret = b.is("foo").equalTo(123.4).or().is("foo").equalTo("null").and().or(
+        String ret = b.is("foo").equalTo(123L).or().is("foo").equalTo("null").and().or(
             b.is("bar").equalTo("asadf*"), 
             b.is("baz").lessThan(20).and().or(
-                b.is("sub1").equalTo(0),
-                b.is("sub2").equalTo(0))).query();
+                b.is("sub1").equalTo(0L),
+                b.is("sub2").equalTo(0L))).query();
         
-        assertEquals("foo==123.4,foo==null;(bar==asadf*,baz=lt=20;(sub1==0,sub2==0))", ret);
+        assertEquals("foo==123,foo==null;(bar==asadf*,baz=lt=20;(sub1==0,sub2==0))", ret);
+    }
+    
+    @Test
+    public void testOrAndImplicitWrap() {
+        String ret = b.is("foo").equalTo(1, 2).and("bar").equalTo("baz").query();
+        
+        assertEquals("(foo==1,foo==2);bar==baz", ret);
+    }
+    
+    @Test
+    public void testMultipleOrShortcut() {
+        // alternative to
+        // b.is("foo").equalTo(123.4).or().is("foo").equalTo("137.8")
+        String ret = b.is("foo").equalTo(123.4, 137.8).query();
+        
+        assertEquals("foo==123.4,foo==137.8", ret);
+    }
+    
+    @Test
+    public void testMultipleOrShortcutWithAnd() {
+        // alternative to
+        // b.is("foo").equalTo(123.4).or().is("foo").equalTo("137.8")
+        String ret = b.is("foo").equalTo(123.4, 137.8).and("bar").equalTo("baz").query();
+        
+        assertEquals("(foo==123.4,foo==137.8);bar==baz", ret);
+    }
+    
+    @Test
+    public void testMultipleOrShortcutWithAnd2() {
+        // alternative to
+        // b.is("foo").equalTo(123.4).or().is("foo").equalTo("137.8")
+        String ret = b.is("foo").equalTo(123.4, 137.8).or("n").equalTo("n1").and("bar").equalTo("baz").query();
+        
+        assertEquals("(foo==123.4,foo==137.8,n==n1);bar==baz", ret);
     }
 }



Mime
View raw message