From 3e0798675ae572869fcaab50b357258bc2894fb5 Mon Sep 17 00:00:00 2001 From: Christian Amend Date: Fri, 7 Feb 2014 16:14:03 +0100 Subject: [PATCH] [OLINGO-62] Referntial Constraint support at edm --- .../odata4/commons/api/edm/EdmException.java | 2 +- .../odata4/commons/api/edm/EdmMappable.java | 1 - .../api/edm/EdmNavigationProperty.java | 7 ++ .../odata4/commons/api/edm/EdmParameter.java | 1 - .../odata4/commons/api/edm/EdmProperty.java | 1 - .../commons/api/edm/EdmServiceMetadata.java | 1 - .../commons/api/edm/EdmStructuralType.java | 2 +- .../odata4/commons/api/edm/EdmType.java | 2 - .../api/edm/provider/ActionImport.java | 1 - .../commons/api/edm/provider/Annotation.java | 1 - .../api/edm/provider/BindingTarget.java | 1 - .../commons/api/edm/provider/ComplexType.java | 1 - .../api/edm/provider/EntityContainer.java | 1 - .../api/edm/provider/EntityContainerInfo.java | 1 - .../commons/api/edm/provider/EntitySet.java | 1 - .../commons/api/edm/provider/EntityType.java | 1 - .../commons/api/edm/provider/EnumMember.java | 4 +- .../commons/api/edm/provider/EnumType.java | 1 - .../api/edm/provider/FunctionImport.java | 1 - .../commons/api/edm/provider/Parameter.java | 1 - .../commons/api/edm/provider/Property.java | 3 +- .../commons/api/edm/provider/ReturnType.java | 1 - .../commons/api/edm/provider/Singleton.java | 1 - .../api/edm/provider/StructuralType.java | 1 - .../commons/api/edm/provider/Target.java | 1 - .../odata4/commons/api/edm/provider/Term.java | 3 +- .../api/edm/provider/TypeDefinition.java | 1 - .../provider/EdmNavigationPropertyImpl.java | 40 +++++++++++ .../EdmNavigationPropertyImplTest.java | 71 +++++++++++++++++++ 29 files changed, 125 insertions(+), 29 deletions(-) diff --git a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmException.java b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmException.java index 05350b89e..ec756f9d6 100644 --- a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmException.java +++ b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmException.java @@ -33,7 +33,7 @@ public class EdmException extends RuntimeException { super(msg); } - public EdmException(String string, Exception e) { + public EdmException(final String string, final Exception e) { super(string, e); } diff --git a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmMappable.java b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmMappable.java index 28fa16ad9..b698a0b64 100644 --- a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmMappable.java +++ b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmMappable.java @@ -18,7 +18,6 @@ ******************************************************************************/ package org.apache.olingo.odata4.commons.api.edm; - /** * EdmMappable can be applied to CSDL elements to associate additional information. */ diff --git a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmNavigationProperty.java b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmNavigationProperty.java index cb873002f..aa317e419 100644 --- a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmNavigationProperty.java +++ b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmNavigationProperty.java @@ -29,4 +29,11 @@ public interface EdmNavigationProperty extends EdmElement { */ Boolean isNullable(); + /** + * @return the partner navigation property + */ + EdmNavigationProperty getPartner(); + + String getReferencingPropertyName(String referencedPropertyName); + } \ No newline at end of file diff --git a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmParameter.java b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmParameter.java index c89f917fa..5ee9b7edc 100644 --- a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmParameter.java +++ b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmParameter.java @@ -18,7 +18,6 @@ ******************************************************************************/ package org.apache.olingo.odata4.commons.api.edm; - /** * A CSDL parameter element */ diff --git a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmProperty.java b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmProperty.java index 89ee766d3..9856c3234 100644 --- a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmProperty.java +++ b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmProperty.java @@ -18,7 +18,6 @@ ******************************************************************************/ package org.apache.olingo.odata4.commons.api.edm; - /** * A CSDL Property element *

EdmProperty defines a simple type or a complex type. diff --git a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmServiceMetadata.java b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmServiceMetadata.java index d7b49b23f..a41c8bd64 100644 --- a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmServiceMetadata.java +++ b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmServiceMetadata.java @@ -21,7 +21,6 @@ package org.apache.olingo.odata4.commons.api.edm; import java.io.InputStream; import java.util.List; - /** * This interface gives access to the metadata of a service, * the calculated Data Service Version and an info list of all entity sets, singletons, and function imports diff --git a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmStructuralType.java b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmStructuralType.java index 440c3e706..ceb63cb70 100644 --- a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmStructuralType.java +++ b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmStructuralType.java @@ -51,7 +51,7 @@ public interface EdmStructuralType extends EdmType { * @return {@link EdmStructuralType} */ EdmStructuralType getBaseType(); - + /** * Checks if this type is convertable to parameter {@link targetType} * diff --git a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmType.java b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmType.java index 0248a1967..9ca54f5ec 100644 --- a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmType.java +++ b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmType.java @@ -36,6 +36,4 @@ public interface EdmType extends EdmNamed { */ EdmTypeKind getKind(); - - } \ No newline at end of file diff --git a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/ActionImport.java b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/ActionImport.java index 6023fd46c..bca2e9f99 100644 --- a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/ActionImport.java +++ b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/ActionImport.java @@ -18,7 +18,6 @@ ******************************************************************************/ package org.apache.olingo.odata4.commons.api.edm.provider; - public class ActionImport extends OperationImport { private FullQualifiedName action; diff --git a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/Annotation.java b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/Annotation.java index c2a71f613..b54f76758 100644 --- a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/Annotation.java +++ b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/Annotation.java @@ -20,7 +20,6 @@ package org.apache.olingo.odata4.commons.api.edm.provider; import java.util.List; - public class Annotation { private FullQualifiedName term; // Target should be a target path diff --git a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/BindingTarget.java b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/BindingTarget.java index 0ce5dcb6b..412eeed55 100644 --- a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/BindingTarget.java +++ b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/BindingTarget.java @@ -20,7 +20,6 @@ package org.apache.olingo.odata4.commons.api.edm.provider; import java.util.List; - public abstract class BindingTarget { protected String name; diff --git a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/ComplexType.java b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/ComplexType.java index acbcade4d..cd51413cd 100644 --- a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/ComplexType.java +++ b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/ComplexType.java @@ -20,7 +20,6 @@ package org.apache.olingo.odata4.commons.api.edm.provider; import java.util.List; - public class ComplexType extends StructuralType { @Override diff --git a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/EntityContainer.java b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/EntityContainer.java index bf4626d6b..9334292a2 100644 --- a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/EntityContainer.java +++ b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/EntityContainer.java @@ -20,7 +20,6 @@ package org.apache.olingo.odata4.commons.api.edm.provider; import java.util.List; - public class EntityContainer { private String name; diff --git a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/EntityContainerInfo.java b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/EntityContainerInfo.java index 61f490728..e7de3a961 100644 --- a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/EntityContainerInfo.java +++ b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/EntityContainerInfo.java @@ -18,7 +18,6 @@ ******************************************************************************/ package org.apache.olingo.odata4.commons.api.edm.provider; - public class EntityContainerInfo { private FullQualifiedName containerName; private FullQualifiedName extendsContainer; diff --git a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/EntitySet.java b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/EntitySet.java index f21cb06d7..26969e563 100644 --- a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/EntitySet.java +++ b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/EntitySet.java @@ -20,7 +20,6 @@ package org.apache.olingo.odata4.commons.api.edm.provider; import java.util.List; - public class EntitySet extends BindingTarget { private boolean includeInServiceDocument; diff --git a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/EntityType.java b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/EntityType.java index 0eaaad100..d1d07d8f3 100644 --- a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/EntityType.java +++ b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/EntityType.java @@ -20,7 +20,6 @@ package org.apache.olingo.odata4.commons.api.edm.provider; import java.util.List; - public class EntityType extends StructuralType { private List key; diff --git a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/EnumMember.java b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/EnumMember.java index 085741887..bfc64679c 100644 --- a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/EnumMember.java +++ b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/EnumMember.java @@ -20,13 +20,14 @@ package org.apache.olingo.odata4.commons.api.edm.provider; import org.apache.olingo.odata4.commons.api.edm.EdmMember; -public class EnumMember implements EdmMember{ +public class EnumMember implements EdmMember { private String name; private String value; // Annotations? + @Override public String getName() { return name; } @@ -36,6 +37,7 @@ public class EnumMember implements EdmMember{ return this; } + @Override public String getValue() { return value; } diff --git a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/EnumType.java b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/EnumType.java index 6252e67fa..010382729 100644 --- a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/EnumType.java +++ b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/EnumType.java @@ -20,7 +20,6 @@ package org.apache.olingo.odata4.commons.api.edm.provider; import java.util.List; - public class EnumType { private String name; diff --git a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/FunctionImport.java b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/FunctionImport.java index 79e5b7844..503f7762c 100644 --- a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/FunctionImport.java +++ b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/FunctionImport.java @@ -18,7 +18,6 @@ ******************************************************************************/ package org.apache.olingo.odata4.commons.api.edm.provider; - public class FunctionImport extends OperationImport { private FullQualifiedName function; diff --git a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/Parameter.java b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/Parameter.java index cd954872d..4b195e463 100644 --- a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/Parameter.java +++ b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/Parameter.java @@ -18,7 +18,6 @@ ******************************************************************************/ package org.apache.olingo.odata4.commons.api.edm.provider; - public class Parameter { private String name; diff --git a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/Property.java b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/Property.java index 6eba8d1ce..a053b1d40 100644 --- a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/Property.java +++ b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/Property.java @@ -18,7 +18,6 @@ ******************************************************************************/ package org.apache.olingo.odata4.commons.api.edm.provider; - public class Property { private String name; @@ -26,7 +25,7 @@ public class Property { private FullQualifiedName type; private boolean collection; - //TODO: Mimetype and mapping what here + // TODO: Mimetype and mapping what here private String mimeType; private Mapping mapping; diff --git a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/ReturnType.java b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/ReturnType.java index f76d68b2b..4b4b388a6 100644 --- a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/ReturnType.java +++ b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/ReturnType.java @@ -18,7 +18,6 @@ ******************************************************************************/ package org.apache.olingo.odata4.commons.api.edm.provider; - public class ReturnType { private FullQualifiedName type; diff --git a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/Singleton.java b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/Singleton.java index 18ec7d599..3dd104416 100644 --- a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/Singleton.java +++ b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/Singleton.java @@ -20,7 +20,6 @@ package org.apache.olingo.odata4.commons.api.edm.provider; import java.util.List; - public class Singleton extends BindingTarget { @Override diff --git a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/StructuralType.java b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/StructuralType.java index ba41508af..ad67a7d97 100644 --- a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/StructuralType.java +++ b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/StructuralType.java @@ -20,7 +20,6 @@ package org.apache.olingo.odata4.commons.api.edm.provider; import java.util.List; - public abstract class StructuralType { protected String name; diff --git a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/Target.java b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/Target.java index 33ec922a1..ced9497de 100644 --- a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/Target.java +++ b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/Target.java @@ -18,7 +18,6 @@ ******************************************************************************/ package org.apache.olingo.odata4.commons.api.edm.provider; - public class Target { private String targetName; diff --git a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/Term.java b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/Term.java index dbf8c63ea..452c79a87 100644 --- a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/Term.java +++ b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/Term.java @@ -20,12 +20,11 @@ package org.apache.olingo.odata4.commons.api.edm.provider; import java.util.List; - public class Term { private String name; private FullQualifiedName type; private FullQualifiedName baseTerm; - //TODO: AppliesTo is a list of csdl elements => should we put this list inside an enum? + // TODO: AppliesTo is a list of csdl elements => should we put this list inside an enum? private String appliesTo; private boolean isCollection; diff --git a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/TypeDefinition.java b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/TypeDefinition.java index dfd1a1e79..5c3670a29 100644 --- a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/TypeDefinition.java +++ b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/provider/TypeDefinition.java @@ -18,7 +18,6 @@ ******************************************************************************/ package org.apache.olingo.odata4.commons.api.edm.provider; - public class TypeDefinition { private String name; diff --git a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmNavigationPropertyImpl.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmNavigationPropertyImpl.java index 86a6e39fe..e11738b31 100644 --- a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmNavigationPropertyImpl.java +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmNavigationPropertyImpl.java @@ -18,16 +18,22 @@ ******************************************************************************/ package org.apache.olingo.odata4.commons.core.edm.provider; +import java.util.List; + +import org.apache.olingo.odata4.commons.api.edm.EdmElement; import org.apache.olingo.odata4.commons.api.edm.EdmEntityType; import org.apache.olingo.odata4.commons.api.edm.EdmException; import org.apache.olingo.odata4.commons.api.edm.EdmNavigationProperty; +import org.apache.olingo.odata4.commons.api.edm.EdmStructuralType; import org.apache.olingo.odata4.commons.api.edm.EdmType; import org.apache.olingo.odata4.commons.api.edm.provider.NavigationProperty; +import org.apache.olingo.odata4.commons.api.edm.provider.ReferentialConstraint; public class EdmNavigationPropertyImpl extends EdmElementImpl implements EdmNavigationProperty { private final NavigationProperty navigationProperty; private EdmEntityType typeImpl; + private EdmNavigationProperty partnerNavigationProperty; public EdmNavigationPropertyImpl(final EdmProviderImpl edm, final NavigationProperty navigationProperty) { super(edm, navigationProperty.getName()); @@ -55,4 +61,38 @@ public class EdmNavigationPropertyImpl extends EdmElementImpl implements EdmNavi return navigationProperty.getNullable(); } + @Override + public EdmNavigationProperty getPartner() { + if (partnerNavigationProperty == null) { + String partner = navigationProperty.getPartner(); + if (partner != null) { + EdmStructuralType type = (EdmStructuralType) getType(); + EdmElement property = null; + String[] split = partner.split("/"); + for (String element : split) { + property = type.getProperty(element); + if (property == null) { + throw new EdmException("Cannot find property with name: " + element + " at type " + type.getName()); + } + type = (EdmStructuralType) property.getType(); + } + partnerNavigationProperty = (EdmNavigationProperty) property; + } + } + return partnerNavigationProperty; + } + + @Override + public String getReferencingPropertyName(final String referencedPropertyName) { + List referentialConstraints = navigationProperty.getReferentialConstraints(); + if (referentialConstraints != null) { + for (ReferentialConstraint constraint : referentialConstraints) { + if (constraint.getReferencedProperty().equals(referencedPropertyName)) { + return constraint.getProperty(); + } + } + } + return null; + } + } diff --git a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmNavigationPropertyImplTest.java b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmNavigationPropertyImplTest.java index 8ef61e2e1..d1bc879ef 100644 --- a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmNavigationPropertyImplTest.java +++ b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmNavigationPropertyImplTest.java @@ -20,11 +20,15 @@ package org.apache.olingo.odata4.commons.core.edm.provider; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import java.util.ArrayList; import java.util.Collections; +import java.util.List; import org.apache.olingo.odata4.commons.api.edm.EdmException; import org.apache.olingo.odata4.commons.api.edm.EdmNavigationProperty; @@ -35,6 +39,7 @@ import org.apache.olingo.odata4.commons.api.edm.provider.EntityType; import org.apache.olingo.odata4.commons.api.edm.provider.FullQualifiedName; import org.apache.olingo.odata4.commons.api.edm.provider.NavigationProperty; import org.apache.olingo.odata4.commons.api.edm.provider.PropertyRef; +import org.apache.olingo.odata4.commons.api.edm.provider.ReferentialConstraint; import org.junit.Test; public class EdmNavigationPropertyImplTest { @@ -57,12 +62,78 @@ public class EdmNavigationPropertyImplTest { assertEquals(EdmTypeKind.ENTITY, type.getKind()); assertEquals("ns", type.getNamespace()); assertEquals("entity", type.getName()); + assertNull(property.getReferencingPropertyName("referencedPropertyName")); + assertNull(property.getPartner()); // Test caching EdmType cachedType = property.getType(); assertTrue(type == cachedType); } + @Test + public void navigationPropertyWithReferntialConstraint() throws Exception { + EdmProvider provider = mock(EdmProvider.class); + EdmProviderImpl edm = new EdmProviderImpl(provider); + final FullQualifiedName entityTypeName = new FullQualifiedName("ns", "entity"); + EntityType entityTypeProvider = new EntityType(); + entityTypeProvider.setKey(Collections. emptyList()); + when(provider.getEntityType(entityTypeName)).thenReturn(entityTypeProvider); + NavigationProperty propertyProvider = new NavigationProperty(); + propertyProvider.setType(entityTypeName); + propertyProvider.setNullable(false); + List referentialConstraints = new ArrayList(); + referentialConstraints.add(new ReferentialConstraint().setProperty("property").setReferencedProperty( + "referencedProperty")); + propertyProvider.setReferentialConstraints(referentialConstraints); + EdmNavigationProperty property = new EdmNavigationPropertyImpl(edm, propertyProvider); + assertEquals("property", property.getReferencingPropertyName("referencedProperty")); + assertNull(property.getReferencingPropertyName("wrong")); + } + + @Test + public void navigationPropertyWithPartner() throws Exception { + EdmProvider provider = mock(EdmProvider.class); + EdmProviderImpl edm = new EdmProviderImpl(provider); + final FullQualifiedName entityTypeName = new FullQualifiedName("ns", "entity"); + EntityType entityTypeProvider = new EntityType(); + entityTypeProvider.setKey(Collections. emptyList()); + + List navigationProperties = new ArrayList(); + navigationProperties.add(new NavigationProperty().setName("partnerName").setType(entityTypeName)); + entityTypeProvider.setNavigationProperties(navigationProperties); + when(provider.getEntityType(entityTypeName)).thenReturn(entityTypeProvider); + NavigationProperty propertyProvider = new NavigationProperty(); + propertyProvider.setType(entityTypeName); + propertyProvider.setNullable(false); + propertyProvider.setPartner("partnerName"); + EdmNavigationProperty property = new EdmNavigationPropertyImpl(edm, propertyProvider); + EdmNavigationProperty partner = property.getPartner(); + assertNotNull(partner); + + // Caching + assertTrue(partner == property.getPartner()); + } + + @Test(expected = EdmException.class) + public void navigationPropertyWithNonexistentPartner() throws Exception { + EdmProvider provider = mock(EdmProvider.class); + EdmProviderImpl edm = new EdmProviderImpl(provider); + final FullQualifiedName entityTypeName = new FullQualifiedName("ns", "entity"); + EntityType entityTypeProvider = new EntityType(); + entityTypeProvider.setKey(Collections. emptyList()); + + List navigationProperties = new ArrayList(); + navigationProperties.add(new NavigationProperty().setName("partnerName").setType(entityTypeName)); + entityTypeProvider.setNavigationProperties(navigationProperties); + when(provider.getEntityType(entityTypeName)).thenReturn(entityTypeProvider); + NavigationProperty propertyProvider = new NavigationProperty(); + propertyProvider.setType(entityTypeName); + propertyProvider.setNullable(false); + propertyProvider.setPartner("wrong"); + EdmNavigationProperty property = new EdmNavigationPropertyImpl(edm, propertyProvider); + property.getPartner(); + } + @Test(expected = EdmException.class) public void navigationPropertyWithNonExistentType() throws Exception { EdmProviderImpl edm = mock(EdmProviderImpl.class);