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 13:59:06 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 979297158 -> e0be73d83


[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/e0be73d8
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/e0be73d8
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/e0be73d8

Branch: refs/heads/master
Commit: e0be73d83783888e49ad4216f11671fe78c176b7
Parents: 9792971
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 13:58:42 2014 +0000

----------------------------------------------------------------------
 .../search/AbstractSearchConditionParser.java   | 14 ++++---
 .../jaxrs/ext/search/fiql/FiqlParserTest.java   | 41 ++++++++++++++++++++
 2 files changed, 50 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/e0be73d8/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/AbstractSearchConditionParser.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/AbstractSearchConditionParser.java
b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/AbstractSearchConditionParser.java
index 5537f44..2eb8189 100644
--- a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/AbstractSearchConditionParser.java
+++ b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/AbstractSearchConditionParser.java
@@ -154,7 +154,8 @@ public abstract class AbstractSearchConditionParser<T> implements
SearchConditio
                 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);
                 
@@ -179,12 +180,15 @@ public abstract class AbstractSearchConditionParser<T> implements
SearchConditio
                             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;
@@ -193,7 +197,7 @@ public abstract class AbstractSearchConditionParser<T> implements
SearchConditio
                     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/e0be73d8/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