cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject git commit: [CXF-5591] Support for multiple collections of non primitive types
Date Tue, 04 Mar 2014 15:41:36 GMT
Repository: cxf
Updated Branches:
  refs/heads/2.7.x-fixes b8d1d726c -> d635b081f


[CXF-5591] Support for multiple collections of non primitive types


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

Branch: refs/heads/2.7.x-fixes
Commit: d635b081f0f3ad47714ff998d765c0df2ddf7bff
Parents: b8d1d72
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Tue Mar 4 13:58:42 2014 +0000
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Tue Mar 4 15:40:49 2014 +0000

----------------------------------------------------------------------
 .../cxf/jaxrs/ext/search/fiql/FiqlParser.java   | 15 ++++---
 .../jaxrs/ext/search/fiql/FiqlParserTest.java   | 41 ++++++++++++++++++++
 2 files changed, 51 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/d635b081/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/fiql/FiqlParser.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/fiql/FiqlParser.java
b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/fiql/FiqlParser.java
index fd49a18..e7a08b3 100644
--- a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/fiql/FiqlParser.java
+++ b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/fiql/FiqlParser.java
@@ -311,7 +311,7 @@ public class FiqlParser<T> implements SearchConditionParser<T>
{
             Object object = parseType(originalName, null, null, setter, typeInfo, value);
             return new TypeInfoObject(object, typeInfo);
         } catch (Exception e) {
-            return null;
+            throw new SearchParseException(e);
         }
         
     }
@@ -379,7 +379,8 @@ public class FiqlParser<T> implements SearchConditionParser<T>
{
                 Class<?> actualReturnType = !returnCollection ? returnType 
                     : InjectionUtils.getActualType(getterM.getGenericReturnType());
                 
-                boolean isPrimitive = InjectionUtils.isPrimitive(returnType) || returnType.isEnum();
+                boolean isPrimitive = !returnCollection 
+                    && InjectionUtils.isPrimitive(returnType) || returnType.isEnum();
                 boolean lastTry = names.length == 2 
                     && (isPrimitive || returnType == Date.class || returnCollection);
                 
@@ -404,12 +405,16 @@ public class FiqlParser<T> implements SearchConditionParser<T>
{
                             nextObject = getEmptyCollection(valueType);
                         }
                     }
-                } else {
+                } else if (!returnCollection) {
                     nextObject = returnType.newInstance();
+                } else {
+                    nextObject = actualReturnType.newInstance();
                 }
                 
                 Method setterM = actualType.getMethod("set" + nextPart, new Class[]{returnType});
-                setterM.invoke(valueObject, new Object[]{nextObject});
+                Object valueObjectValue = lastTry || !returnCollection 
+                    ? nextObject : getCollectionSingleton(valueType, nextObject); 
+                setterM.invoke(valueObject, new Object[]{valueObjectValue});
                 
                 if (lastTry) {
                     lastCastedValue = lastCastedValue == null ? valueObject : lastCastedValue;
@@ -418,7 +423,7 @@ public class FiqlParser<T> implements SearchConditionParser<T>
{
                     lastCastedValue = valueObject;
                 }
                 
-                TypeInfo nextTypeInfo = new TypeInfo(nextObject.getClass(), getterM.getGenericReturnType());

+                TypeInfo nextTypeInfo = new TypeInfo(valueObjectValue.getClass(), getterM.getGenericReturnType());

                 Object response = parseType(originalPropName,
                                  nextObject, 
                                  lastCastedValue, 

http://git-wip-us.apache.org/repos/asf/cxf/blob/d635b081/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/fiql/FiqlParserTest.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/fiql/FiqlParserTest.java
b/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/fiql/FiqlParserTest.java
index d7b635e..9bdb76d 100644
--- a/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/fiql/FiqlParserTest.java
+++ b/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/fiql/FiqlParserTest.java
@@ -21,6 +21,7 @@ package org.apache.cxf.jaxrs.ext.search.fiql;
 import java.text.DateFormat;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.util.Collections;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
@@ -301,6 +302,16 @@ public class FiqlParserTest extends Assert {
         assertTrue(filter.isMet(new Condition("foobar", 20, null)));
         assertFalse(filter.isMet(new Condition("fooxxxbar", 0, null)));
     }
+    
+    @Test
+    public void testMultipleLists() throws SearchParseException {
+        FiqlParser<Job> jobParser = new FiqlParser<Job>(Job.class, 
+                                                        Collections.<String, String>emptyMap(),
+                                                        Collections.singletonMap("itemName",
"tasks.items.itemName"));
+        SearchCondition<Job> jobCondition = jobParser.parse("itemName==myitem");
+        Job job = jobCondition.getCondition();
+        assertEquals("myitem", job.getTasks().get(0).getItems().get(0).getItemName());
+    }
 
     @Ignore
     public static class Condition {
@@ -360,4 +371,34 @@ public class FiqlParserTest extends Assert {
 
     }
 
+    
+    public static class Job {
+        private List<Task> tasks;
+        public List<Task> getTasks() {
+            return tasks;
+        }
+        public void setTasks(List<Task> tasks) {
+            this.tasks = tasks;
+            
+        }
+    }
+    public static class Task {
+        private List<Item> items;
+        public List<Item> getItems() {
+            return items;
+        }
+        public void setItems(List<Item> items) {
+            this.items = items;
+        }
+    }
+    public static class Item {
+        private String name;
+        public String getItemName() {
+            return name;
+        }
+        public void setItemName(String itemName) {
+            this.name = itemName;
+        }
+    }
+
 }


Mime
View raw message