Repository: olingo-odata2
Updated Branches:
  refs/heads/master 17dc8da79 -> 7d882075a


[OLINGO-1020] Fixed 0..1 edge cases for JPA-ext


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

Branch: refs/heads/master
Commit: 7d882075a5b7058c34ff092abe2dac3c216d9382
Parents: 17dc8da
Author: mibo <m...@apache.org>
Authored: Tue Sep 20 20:40:38 2016 +0200
Committer: mibo <m...@apache.org>
Committed: Tue Sep 20 20:40:38 2016 +0200

----------------------------------------------------------------------
 .../core/access/model/JPAEdmNameBuilder.java      |  7 +++++--
 .../processor/core/model/JPAEdmAssociation.java   | 18 ++++++++++++++++++
 .../core/model/JPAEdmAssociationEnd.java          |  7 +++++++
 3 files changed, 30 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/7d882075/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmNameBuilder.java
----------------------------------------------------------------------
diff --git 
a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmNameBuilder.java
 
b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmNameBuilder.java
index bde7c2f..c404249 100644
--- 
a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmNameBuilder.java
+++ 
b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmNameBuilder.java
@@ -530,6 +530,10 @@ public class JPAEdmNameBuilder {
   }
 
   private static String multiplicityToString(EdmMultiplicity multiplicity) {
+    if(multiplicity == null) {
+      return "";
+    }
+
     switch (multiplicity) {
     case MANY:
       return "Many";
@@ -538,9 +542,8 @@ public class JPAEdmNameBuilder {
     case ZERO_TO_ONE:
       return "ZeroToOne";
     default:
-      break;
+      return "";
     }
-    return "";
   }
 
   private static String buildNamespace(final JPAEdmBaseView view) {

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/7d882075/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmAssociation.java
----------------------------------------------------------------------
diff --git 
a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmAssociation.java
 
b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmAssociation.java
index 889047c..57b1ba3 100644
--- 
a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmAssociation.java
+++ 
b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmAssociation.java
@@ -24,6 +24,7 @@ import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
 
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
 import org.apache.olingo.odata2.api.edm.provider.Association;
 import org.apache.olingo.odata2.api.edm.provider.AssociationEnd;
 import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmBuilder;
@@ -109,6 +110,7 @@ public class JPAEdmAssociation extends JPAEdmBaseViewImpl 
implements JPAEdmAssoc
             }
             if (associationEnd.getMappedByName() != null) {
               if 
(associationEnd.getMappedByName().equals(view.getOwningPropertyName())) {
+                updateAssociationEndMultiplicity(view, association);
                 currentAssociation = association;
                 return association;
               }
@@ -126,6 +128,22 @@ public class JPAEdmAssociation extends JPAEdmBaseViewImpl 
implements JPAEdmAssoc
     return null;
   }
 
+  private void updateAssociationEndMultiplicity(JPAEdmAssociationEndView view, 
Association association) {
+    if (view.getEdmAssociationEnd1().getMultiplicity() == 
EdmMultiplicity.ZERO_TO_ONE
+        && association.getEnd1().getMultiplicity() == EdmMultiplicity.ONE) {
+      association.getEnd1().setMultiplicity(EdmMultiplicity.ZERO_TO_ONE);
+    } else if (view.getEdmAssociationEnd2().getMultiplicity() == 
EdmMultiplicity.ZERO_TO_ONE
+        && association.getEnd2().getMultiplicity() == EdmMultiplicity.ONE) {
+      association.getEnd2().setMultiplicity(EdmMultiplicity.ZERO_TO_ONE);
+    } else if (view.getEdmAssociationEnd1().getMultiplicity() == 
EdmMultiplicity.ZERO_TO_ONE
+        && association.getEnd2().getMultiplicity() == EdmMultiplicity.ONE) {
+      association.getEnd2().setMultiplicity(EdmMultiplicity.ZERO_TO_ONE);
+    } else if (view.getEdmAssociationEnd2().getMultiplicity() == 
EdmMultiplicity.ZERO_TO_ONE
+        && association.getEnd1().getMultiplicity() == EdmMultiplicity.ONE) {
+      association.getEnd1().setMultiplicity(EdmMultiplicity.ZERO_TO_ONE);
+    }
+  }
+
   @Override
   public void addJPAEdmAssociationView(final JPAEdmAssociationView 
associationView,
       final JPAEdmAssociationEndView associationEndView) {

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/7d882075/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmAssociationEnd.java
----------------------------------------------------------------------
diff --git 
a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmAssociationEnd.java
 
b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmAssociationEnd.java
index 98d3745..c2cbd11 100644
--- 
a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmAssociationEnd.java
+++ 
b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmAssociationEnd.java
@@ -164,6 +164,13 @@ public class JPAEdmAssociationEnd extends 
JPAEdmBaseViewImpl implements JPAEdmAs
     FullQualifiedName end2Type = end2.getType();
     FullQualifiedName currentAssociationEnd2Type = 
currentAssociationEnd2.getType();
 
+    if(end1.getMultiplicity() == null || 
currentAssociationEnd1.getMultiplicity() == null) {
+      return false;
+    }
+    if(end2.getMultiplicity() == null || 
currentAssociationEnd2.getMultiplicity() == null) {
+      return false;
+    }
+
     boolean end1eqCurEnd1 = 
end1.getMultiplicity().equals(currentAssociationEnd1.getMultiplicity());
     boolean end2eqCurEnd2 = 
end2.getMultiplicity().equals(currentAssociationEnd2.getMultiplicity());
     if(end1Type.equals(currentAssociationEnd1Type) && 
end2Type.equals(currentAssociationEnd2Type)

Reply via email to