You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by mi...@apache.org on 2013/12/05 13:31:21 UTC

[28/52] git commit: Fix for related null values

Fix for related null values


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/f97d37f4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/f97d37f4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/f97d37f4

Branch: refs/heads/master
Commit: f97d37f442c9ef9ef575775129cc7986a767e620
Parents: d440793
Author: Michael Bolz <mi...@apache.org>
Authored: Wed Nov 20 06:10:11 2013 +0100
Committer: Michael Bolz <mi...@apache.org>
Committed: Wed Nov 20 06:10:11 2013 +0100

----------------------------------------------------------------------
 .../annotation/data/AnnotationInMemoryDs.java   | 17 +++++------------
 .../annotation/data/AnnotationValueAccess.java  | 14 ++++++++++++--
 .../annotation/processor/ListsProcessor.java    | 20 +++++++++++++-------
 3 files changed, 30 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/f97d37f4/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
index a8f4cb9..6414264 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
@@ -138,13 +138,13 @@ public class AnnotationInMemoryDs implements ListsDataSource {
         }
       }
       
-      if(navigationInfo.getToMultiplicity() == EdmMultiplicity.ONE) {
-        if(resultData.isEmpty()) {
-          return null;
-        }
+      if(resultData.isEmpty()) {
+        return null;
+      } else if(navigationInfo.getToMultiplicity() == EdmMultiplicity.ONE) {
         return resultData.get(0);
+      } else {
+        return resultData;
       }
-      return resultData;
     } else {
       throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
     }
@@ -264,13 +264,6 @@ public class AnnotationInMemoryDs implements ListsDataSource {
     }
   }
 
-  private Field extractSourceField(DataStore sourceStore, DataStore targetStore) {
-    Class sourceDataTypeClass = sourceStore.getDataTypeClass();
-    Class targetDataTypeClass = targetStore.getDataTypeClass();
-    
-    return ANNOTATION_HELPER.getCommonNavigationFieldFromTarget(sourceDataTypeClass, targetDataTypeClass);
-  }
-
   private AnnotationHelper.AnnotatedNavInfo extractNavigationInfo(DataStore sourceStore, DataStore targetStore) {
     Class sourceDataTypeClass = sourceStore.getDataTypeClass();
     Class targetDataTypeClass = targetStore.getDataTypeClass();

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/f97d37f4/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationValueAccess.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationValueAccess.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationValueAccess.java
index 6c65bf8..ceea74d 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationValueAccess.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationValueAccess.java
@@ -23,8 +23,11 @@ import org.apache.olingo.odata2.api.data.ValueAccess;
 import org.apache.olingo.odata2.api.edm.EdmMapping;
 import org.apache.olingo.odata2.api.edm.EdmProperty;
 import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.exception.ODataHttpException;
+import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
 import org.apache.olingo.odata2.api.exception.ODataNotImplementedException;
 import org.apache.olingo.odata2.core.annotation.edm.AnnotationHelper;
+import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
 
 /**
  *
@@ -40,11 +43,18 @@ public class AnnotationValueAccess implements ValueAccess {
    */
   @Override
   public <T> Object getPropertyValue(final T data, final EdmProperty property) throws ODataException {
+    if(data == null) {
+      if(property.getFacets() == null || property.getFacets().isNullable()) {
+        return null;
+      }
+      throw new ODataRuntimeException("Invalid value for data '" + data + "' and property '" + property + "'.");
+    }
+    
     if(data instanceof Collection) {
       Collection c = (Collection) data;
       for (Object object : c) {
-        if(annotationHelper.isEdmAnnotated(data)) {
-          return annotationHelper.getValueForProperty(data, property.getName());
+        if(annotationHelper.isEdmAnnotated(object)) {
+          return annotationHelper.getValueForProperty(object, property.getName());
         }
       }
     }

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/f97d37f4/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/ListsProcessor.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/ListsProcessor.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/ListsProcessor.java
index 26c85df..f659383 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/ListsProcessor.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/ListsProcessor.java
@@ -1000,14 +1000,20 @@ public class ListsProcessor extends ODataSingleProcessor {
         } catch (final ODataNotFoundException e) {
           relatedData = null;
         }
-        result.setEntryData(getStructuralTypeValueMap(relatedData, entityType));
+        
+        if(relatedData == null) {
+          result.setEntryData(new HashMap<String, Object>());
+          return result;
+        } else {
+          result.setEntryData(getStructuralTypeValueMap(relatedData, entityType));
 
-        EntityProviderWriteProperties inlineProperties =
-            EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).callbacks(
-                getCallbacks(relatedData, entityType)).expandSelectTree(context.getCurrentExpandSelectTreeNode())
-                .build();
-        result.setInlineProperties(inlineProperties);
-        return result;
+          EntityProviderWriteProperties inlineProperties =
+              EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).callbacks(
+                  getCallbacks(relatedData, entityType)).expandSelectTree(context.getCurrentExpandSelectTreeNode())
+                  .build();
+          result.setInlineProperties(inlineProperties);
+          return result;
+        }
       } catch (final ODataException e) {
         throw new ODataApplicationException(e.getLocalizedMessage(), Locale.ROOT, e);
       }