cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1506028 - in /cxf/branches/2.7.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/fiql/ rt/rs/extensions/search/src/test/java/org/apache/...
Date Tue, 23 Jul 2013 13:13:27 GMT
Author: sergeyb
Date: Tue Jul 23 13:13:27 2013
New Revision: 1506028

URL: http://svn.apache.org/r1506028
Log:
Merged revisions 1506026 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1506026 | sergeyb | 2013-07-23 14:07:33 +0100 (Tue, 23 Jul 2013) | 1 line
  
  [CXF-5139] Optionall support for a single equals operator in FIQL expressions
........

Modified:
    cxf/branches/2.7.x-fixes/   (props changed)
    cxf/branches/2.7.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContextImpl.java
    cxf/branches/2.7.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/fiql/FiqlParser.java
    cxf/branches/2.7.x-fixes/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/SearchContextImplTest.java

Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/trunk:r1506026

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

Modified: cxf/branches/2.7.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.7.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContextImpl.java?rev=1506028&r1=1506027&r2=1506028&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContextImpl.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContextImpl.java
Tue Jul 23 13:13:27 2013
@@ -176,6 +176,9 @@ public class SearchContextImpl implement
                       (String)message.getContextualProperty(SearchUtils.TIMEZONE_SUPPORT_PROPERTY));
             props.put(SearchUtils.LAX_PROPERTY_MATCH, 
                       (String)message.getContextualProperty(SearchUtils.LAX_PROPERTY_MATCH));
+            // FIQL specific
+            props.put(FiqlParser.SUPPORT_SINGLE_EQUALS, 
+                      (String)message.getContextualProperty(FiqlParser.SUPPORT_SINGLE_EQUALS));

         } else {
             props = parserProperties;
         }

Modified: cxf/branches/2.7.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/fiql/FiqlParser.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/fiql/FiqlParser.java?rev=1506028&r1=1506027&r2=1506028&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/fiql/FiqlParser.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/fiql/FiqlParser.java
Tue Jul 23 13:13:27 2013
@@ -74,11 +74,13 @@ public class FiqlParser<T> implements Se
     public static final Map<ConditionType, String> CONDITION_MAP;
         
     public static final String EXTENSION_COUNT = "count";
+    public static final String SUPPORT_SINGLE_EQUALS = "fiql.support.single.equals.operator";
     
     private static final String EXTENSION_COUNT_OPEN = EXTENSION_COUNT + "(";
     
     private static final Map<String, ConditionType> OPERATORS_MAP;
-    private static final Pattern COMPARATORS_PATTERN; 
+    private static final Pattern COMPARATORS_PATTERN;
+    private static final Pattern COMPARATORS_PATTERN_SINGLE_EQUALS;
     
     static {
         // operatorsMap
@@ -103,12 +105,18 @@ public class FiqlParser<T> implements Se
         String comparators = GT + "|" + GE + "|" + LT + "|" + LE + "|" + EQ + "|" + NEQ;
         String s1 = "[\\p{ASCII}]+(" + comparators + ")";
         COMPARATORS_PATTERN = Pattern.compile(s1);
+        
+        String s2 = "[\\p{ASCII}]+(" + comparators + "|" + "=" + ")";
+        COMPARATORS_PATTERN_SINGLE_EQUALS = Pattern.compile(s2);
     }
 
     private Beanspector<T> beanspector;
     private Class<T> conditionClass;
     private Map<String, String> contextProperties;
     private Map<String, String> beanPropertiesMap;
+    
+    private Map<String, ConditionType> operatorsMap = OPERATORS_MAP;
+    private Pattern comparatorsPattern = COMPARATORS_PATTERN;
     /**
      * Creates FIQL parser.
      * 
@@ -146,6 +154,11 @@ public class FiqlParser<T> implements Se
         this.contextProperties = contextProperties == null 
             ? Collections.<String, String>emptyMap() : contextProperties;
         this.beanPropertiesMap = beanProperties;
+        if (MessageUtils.isTrue(this.contextProperties.get(SUPPORT_SINGLE_EQUALS))) {
+            operatorsMap = new HashMap<String, ConditionType>(operatorsMap);
+            operatorsMap.put("=", ConditionType.EQUALS);
+            comparatorsPattern = COMPARATORS_PATTERN_SINGLE_EQUALS;
+        }
     }
     
     /**
@@ -257,7 +270,7 @@ public class FiqlParser<T> implements Se
     }
 
     private Comparison parseComparison(String expr) throws SearchParseException {
-        Matcher m = COMPARATORS_PATTERN.matcher(expr);
+        Matcher m = comparatorsPattern.matcher(expr);
         if (m.find()) {
             String propertyName = expr.substring(0, m.start(1));
             String operator = m.group(1);
@@ -560,7 +573,7 @@ public class FiqlParser<T> implements Se
         public SearchCondition<T> build() throws SearchParseException {
             String templateName = getSetter(name);
             T cond = createTemplate(templateName);
-            ConditionType ct = OPERATORS_MAP.get(operator);
+            ConditionType ct = operatorsMap.get(operator);
             
             if (isPrimitive(cond)) {
                 return new SimpleSearchCondition<T>(ct, cond); 

Modified: cxf/branches/2.7.x-fixes/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/SearchContextImplTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/SearchContextImplTest.java?rev=1506028&r1=1506027&r2=1506028&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/SearchContextImplTest.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/SearchContextImplTest.java
Tue Jul 23 13:13:27 2013
@@ -171,4 +171,39 @@ public class SearchContextImplTest exten
                    && "CXF Rocks".equals(sc1.getStatement().getValue()));
         
     }
+    
+    @Test
+    public void testPrimitiveStatement() {
+        Message m = new MessageImpl();
+        m.put(Message.QUERY_STRING, "_s=name==CXF");
+        SearchContext context = new SearchContextImpl(m);
+        SearchCondition<SearchBean> sc = context.getCondition(SearchBean.class);
+        assertNotNull(sc);
+        
+        PrimitiveStatement ps = sc.getStatement();
+        assertNotNull(ps);
+        
+        assertEquals("name", ps.getProperty());
+        assertEquals("CXF", ps.getValue());
+        assertEquals(ConditionType.EQUALS, ps.getCondition());
+        assertEquals(String.class, ps.getValueType());
+    }
+    
+    @Test
+    public void testSingleEquals() {
+        Message m = new MessageImpl();
+        m.put(Message.QUERY_STRING, "_s=name=CXF");
+        m.put("fiql.support.single.equals.operator", "true");
+        SearchContext context = new SearchContextImpl(m);
+        SearchCondition<SearchBean> sc = context.getCondition(SearchBean.class);
+        assertNotNull(sc);
+        
+        PrimitiveStatement ps = sc.getStatement();
+        assertNotNull(ps);
+        
+        assertEquals("name", ps.getProperty());
+        assertEquals("CXF", ps.getValue());
+        assertEquals(ConditionType.EQUALS, ps.getCondition());
+        assertEquals(String.class, ps.getValueType());
+    }
 }



Mime
View raw message