You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ch...@apache.org on 2014/01/27 13:17:40 UTC

git commit: [OLINGO-132] Support for * in

Updated Branches:
  refs/heads/master 416537b3d -> 1de55d52f


[OLINGO-132] Support for * in


Project: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/commit/1de55d52
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/1de55d52
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/1de55d52

Branch: refs/heads/master
Commit: 1de55d52f0b9bc9aa8f837b034d8f3947a4784da
Parents: 416537b
Author: Chandan V A <ch...@sap.com>
Authored: Mon Jan 27 17:47:22 2014 +0530
Committer: Chandan V A <ch...@sap.com>
Committed: Mon Jan 27 17:47:22 2014 +0530

----------------------------------------------------------------------
 .../core/ODataJPAResponseBuilderDefault.java    | 21 ++++++++++--
 .../core/access/data/JPAEntityParser.java       | 36 ++++++--------------
 .../core/ODataJPAResponseBuilderTest.java       |  1 +
 3 files changed, 30 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/1de55d52/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilderDefault.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilderDefault.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilderDefault.java
index 04a0fbd..bc01eec 100644
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilderDefault.java
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilderDefault.java
@@ -566,13 +566,18 @@ public final class ODataJPAResponseBuilderDefault implements ODataJPAResponseBui
     try {
       for (SelectItem selectItem : selectItems) {
         if (selectItem.getNavigationPropertySegments().size() <= 0) {
-          selectPropertyList.add(selectItem.getProperty());
+          if (selectItem.isStar()) {
+            selectPropertyList.addAll(getEdmProperties(entity));
+            return selectPropertyList;
+          } else {
+            selectPropertyList.add(selectItem.getProperty());
+          }
         }
       }
       for (EdmProperty keyProperty : entity.getKeyProperties()) {
         flag = true;
         for (SelectItem selectedItem : selectItems) {
-          if (selectedItem.getProperty().equals(keyProperty)) {
+          if (selectedItem.isStar() == false && selectedItem.getProperty().equals(keyProperty)) {
             flag = false;
             break;
           }
@@ -597,4 +602,16 @@ public final class ODataJPAResponseBuilderDefault implements ODataJPAResponseBui
     return navigationPropertyList;
   }
 
+  private static List<EdmProperty> getEdmProperties(EdmStructuralType structuralType) throws ODataJPARuntimeException {
+    List<EdmProperty> edmProperties = new ArrayList<EdmProperty>();
+    try {
+      for (String propertyName : structuralType.getPropertyNames()) {
+        edmProperties.add((EdmProperty) structuralType.getProperty(propertyName));
+      }
+    } catch (EdmException e) {
+      throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
+    }
+    return edmProperties;
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/1de55d52/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParser.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParser.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParser.java
index 7fd2e8f..3930420 100644
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParser.java
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParser.java
@@ -35,8 +35,6 @@ import org.apache.olingo.odata2.api.edm.EdmSimpleType;
 import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
 import org.apache.olingo.odata2.api.edm.EdmStructuralType;
 import org.apache.olingo.odata2.api.edm.EdmTypeKind;
-import org.apache.olingo.odata2.api.uri.NavigationPropertySegment;
-import org.apache.olingo.odata2.api.uri.SelectItem;
 import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
 import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmMapping;
 
@@ -82,39 +80,25 @@ public final class JPAEntityParser {
     return edmEntityList;
   }
 
-  @SuppressWarnings("unchecked")
-  public final <T> HashMap<String, Object> parse2EdmPropertyValueMap(final Object jpaEntity,
-      final List<T> selectPropertyList) throws ODataJPARuntimeException {
+  public final HashMap<String, Object> parse2EdmPropertyValueMap(final Object jpaEntity,
+      final List<EdmProperty> selectPropertyList) throws ODataJPARuntimeException {
 
     HashMap<String, Object> edmEntity = new HashMap<String, Object>();
     HashMap<String, Method> accessModifierMap = null;
     Object propertyValue = null;
-    EdmProperty property = null;
     String jpaEntityAccessKey = null;
 
-    if (selectPropertyList.get(0) instanceof EdmProperty) {
-      jpaEntityAccessKey = jpaEntity.getClass().getName();
-      if (!jpaEntityAccessMap.containsKey(jpaEntityAccessKey)) {
-        accessModifierMap =
-            getAccessModifiers((List<EdmProperty>) selectPropertyList, jpaEntity.getClass(), ACCESS_MODIFIER_GET);
-      } else {
-        accessModifierMap = jpaEntityAccessMap.get(jpaEntityAccessKey);
-      }
+    jpaEntityAccessKey = jpaEntity.getClass().getName();
+    if (!jpaEntityAccessMap.containsKey(jpaEntityAccessKey)) {
+      accessModifierMap =
+          getAccessModifiers((List<EdmProperty>) selectPropertyList, jpaEntity.getClass(), ACCESS_MODIFIER_GET);
+    } else {
+      accessModifierMap = jpaEntityAccessMap.get(jpaEntityAccessKey);
     }
 
-    for (Object item : selectPropertyList) {
+    for (EdmProperty property : selectPropertyList) {
       propertyValue = jpaEntity;
-      if (item instanceof SelectItem) {
-        SelectItem selectItem = (SelectItem) item;
-        for (NavigationPropertySegment navPropSegement : selectItem.getNavigationPropertySegments()) {
-          Method method =
-              getAccessModifier(propertyValue.getClass(), navPropSegement.getNavigationProperty(), ACCESS_MODIFIER_GET);
-          propertyValue = getPropertyValue(method, propertyValue);
-        }
-        property = selectItem.getProperty();
-      } else if (item instanceof EdmProperty) {
-        property = (EdmProperty) item;
-      }
+
       try {
         String propertyName = property.getName();
         Method method = accessModifierMap.get(propertyName);

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/1de55d52/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilderTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilderTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilderTest.java
index 479dc6a..19d3d01 100644
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilderTest.java
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilderTest.java
@@ -326,6 +326,7 @@ public class ODataJPAResponseBuilderTest extends JPAEdmTestModelView {
     EasyMock.expect(selectItem.getProperty()).andStubReturn(getEdmPropertyForSelect());
     List<NavigationPropertySegment> navigationSegmentList = new ArrayList<NavigationPropertySegment>();
     EasyMock.expect(selectItem.getNavigationPropertySegments()).andStubReturn(navigationSegmentList);
+    EasyMock.expect(selectItem.isStar()).andReturn(false).anyTimes();
     EasyMock.replay(selectItem);
     return selectItem;
   }