diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/edm/xml/CommonNavigationProperty.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/edm/xml/CommonNavigationProperty.java index 20eb9deef..ae66b4e90 100644 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/edm/xml/CommonNavigationProperty.java +++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/edm/xml/CommonNavigationProperty.java @@ -19,4 +19,6 @@ package org.apache.olingo.client.api.edm.xml; public interface CommonNavigationProperty extends Named { + + boolean isContainsTarget(); } diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/edm/xml/v4/NavigationProperty.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/edm/xml/v4/NavigationProperty.java index e0885fe8c..b6e2fcc16 100644 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/edm/xml/v4/NavigationProperty.java +++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/edm/xml/v4/NavigationProperty.java @@ -21,9 +21,9 @@ package org.apache.olingo.client.api.edm.xml.v4; import org.apache.olingo.client.api.edm.xml.OnDelete; import java.util.List; +import org.apache.olingo.client.api.edm.xml.CommonNavigationProperty; -public interface NavigationProperty - extends org.apache.olingo.client.api.edm.xml.CommonNavigationProperty, AnnotatedEdmItem { +public interface NavigationProperty extends CommonNavigationProperty, AnnotatedEdmItem { String getType(); @@ -31,8 +31,6 @@ public interface NavigationProperty String getPartner(); - boolean isContainsTarget(); - List getReferentialConstraints(); OnDelete getOnDelete(); diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/response/AbstractODataResponse.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/response/AbstractODataResponse.java index fe8fa526b..2109d968f 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/response/AbstractODataResponse.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/response/AbstractODataResponse.java @@ -42,6 +42,7 @@ import org.apache.olingo.client.core.communication.request.batch.ODataBatchContr import org.apache.olingo.client.core.communication.request.batch.ODataBatchLineIteratorImpl; import org.apache.olingo.client.core.communication.request.batch.ODataBatchUtilities; import org.apache.olingo.commons.api.Constants; +import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** @@ -52,7 +53,7 @@ public abstract class AbstractODataResponse implements ODataResponse { /** * Logger. */ - protected static final org.slf4j.Logger LOG = LoggerFactory.getLogger(ODataResponse.class); + protected static final Logger LOG = LoggerFactory.getLogger(ODataResponse.class); /** * HTTP client. diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmClientImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmClientImpl.java index 58e896350..ae6c37755 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmClientImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmClientImpl.java @@ -157,7 +157,7 @@ public class EdmClientImpl extends AbstractEdm { if (schema != null) { final EntityType xmlEntityType = schema.getEntityType(entityTypeName.getName()); if (xmlEntityType != null) { - result = EdmEntityTypeImpl.getInstance(this, entityTypeName, xmlEntityType); + result = EdmEntityTypeImpl.getInstance(this, entityTypeName, xmlSchemas, xmlEntityType); } } @@ -172,7 +172,7 @@ public class EdmClientImpl extends AbstractEdm { if (schema != null) { final ComplexType xmlComplexType = schema.getComplexType(complexTypeName.getName()); if (xmlComplexType != null) { - result = EdmComplexTypeImpl.getInstance(this, complexTypeName, xmlComplexType); + result = EdmComplexTypeImpl.getInstance(this, complexTypeName, xmlSchemas, xmlComplexType); } } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmComplexTypeImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmComplexTypeImpl.java index 325473b49..1ccc8d54f 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmComplexTypeImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmComplexTypeImpl.java @@ -18,9 +18,11 @@ */ package org.apache.olingo.client.core.edm; +import java.util.List; import org.apache.olingo.commons.core.edm.EdmTypeInfo; import java.util.Map; import org.apache.olingo.client.api.edm.xml.ComplexType; +import org.apache.olingo.client.api.edm.xml.Schema; import org.apache.olingo.commons.api.edm.Edm; import org.apache.olingo.commons.api.edm.EdmNavigationProperty; import org.apache.olingo.commons.api.edm.EdmProperty; @@ -33,7 +35,7 @@ public class EdmComplexTypeImpl extends AbstractEdmComplexType { private final EdmStructuredTypeHelper helper; public static EdmComplexTypeImpl getInstance(final Edm edm, final FullQualifiedName fqn, - final ComplexType complexType) { + final List xmlSchemas, final ComplexType complexType) { FullQualifiedName baseTypeName = null; if (complexType instanceof org.apache.olingo.client.api.edm.xml.v4.ComplexType) { @@ -41,17 +43,17 @@ public class EdmComplexTypeImpl extends AbstractEdmComplexType { baseTypeName = baseType == null ? null : new EdmTypeInfo.Builder().setTypeExpression(baseType).build().getFullQualifiedName(); } - final EdmComplexTypeImpl instance = new EdmComplexTypeImpl(edm, fqn, baseTypeName, complexType); + final EdmComplexTypeImpl instance = new EdmComplexTypeImpl(edm, fqn, baseTypeName, xmlSchemas, complexType); instance.baseType = instance.buildBaseType(baseTypeName); return instance; } private EdmComplexTypeImpl(final Edm edm, final FullQualifiedName fqn, final FullQualifiedName baseTypeName, - final ComplexType complexType) { + final List xmlSchemas, final ComplexType complexType) { super(edm, fqn, baseTypeName); - this.helper = new EdmStructuredTypeHelperImpl(edm, complexType); + this.helper = new EdmStructuredTypeHelperImpl(edm, xmlSchemas, complexType); } @Override diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmEntityContainerImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmEntityContainerImpl.java index fba22a8ef..cf846f7e8 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmEntityContainerImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmEntityContainerImpl.java @@ -140,9 +140,8 @@ public class EdmEntityContainerImpl extends AbstractEdmEntityContainer { final FullQualifiedName entityType = new EdmTypeInfo.Builder().setTypeExpression(entitySet.getEntityType()). setDefaultNamespace(entityContainerName.getNamespace()).build().getFullQualifiedName(); if (entitySet instanceof org.apache.olingo.client.api.edm.xml.v4.EntitySet) { - edmSet = - new EdmEntitySetImpl(edm, this, entitySet.getName(), entityType, - (org.apache.olingo.client.api.edm.xml.v4.EntitySet) entitySet); + edmSet = new EdmEntitySetImpl(edm, this, entitySet.getName(), entityType, + (org.apache.olingo.client.api.edm.xml.v4.EntitySet) entitySet); } else { edmSet = new EdmEntitySetProxy(edm, this, entitySet.getName(), entityType, xmlSchemas); } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmEntityTypeImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmEntityTypeImpl.java index 02814a3c3..c7dc7fdae 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmEntityTypeImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmEntityTypeImpl.java @@ -25,6 +25,7 @@ import java.util.Map; import org.apache.olingo.client.api.edm.xml.EntityType; import org.apache.olingo.client.api.edm.xml.PropertyRef; +import org.apache.olingo.client.api.edm.xml.Schema; import org.apache.olingo.commons.api.edm.Edm; import org.apache.olingo.commons.api.edm.EdmEntityType; import org.apache.olingo.commons.api.edm.EdmKeyPropertyRef; @@ -38,11 +39,13 @@ public class EdmEntityTypeImpl extends AbstractEdmEntityType { private final EdmStructuredTypeHelper helper; - public static EdmEntityTypeImpl getInstance(final Edm edm, final FullQualifiedName fqn, final EntityType entityType) { + public static EdmEntityTypeImpl getInstance(final Edm edm, final FullQualifiedName fqn, + final List xmlSchemas, final EntityType entityType) { + final FullQualifiedName baseTypeName = entityType.getBaseType() == null ? null : new EdmTypeInfo.Builder().setTypeExpression(entityType.getBaseType()).build().getFullQualifiedName(); - final EdmEntityTypeImpl instance = new EdmEntityTypeImpl(edm, fqn, baseTypeName, entityType); + final EdmEntityTypeImpl instance = new EdmEntityTypeImpl(edm, fqn, baseTypeName, xmlSchemas, entityType); instance.baseType = instance.buildBaseType(baseTypeName); if (instance.baseType == null) { @@ -62,10 +65,10 @@ public class EdmEntityTypeImpl extends AbstractEdmEntityType { } private EdmEntityTypeImpl(final Edm edm, final FullQualifiedName fqn, final FullQualifiedName baseTypeName, - final EntityType entityType) { + final List xmlSchemas, final EntityType entityType) { super(edm, fqn, baseTypeName, entityType.isHasStream()); - this.helper = new EdmStructuredTypeHelperImpl(edm, entityType); + this.helper = new EdmStructuredTypeHelperImpl(edm, xmlSchemas, entityType); } @Override diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmNavigationPropertyImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmNavigationPropertyImpl.java index 6ea464b53..08abd9ca2 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmNavigationPropertyImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmNavigationPropertyImpl.java @@ -71,14 +71,14 @@ public class EdmNavigationPropertyImpl extends AbstractEdmNavigationProperty { @Override public String getReferencingPropertyName(final String referencedPropertyName) { - final List referentialConstraints = navigationProperty.getReferentialConstraints(); - if (referentialConstraints != null) { - for (ReferentialConstraint constraint : referentialConstraints) { - if (constraint.getReferencedProperty().equals(referencedPropertyName)) { - return constraint.getProperty(); - } + final List _referentialConstraints = + navigationProperty.getReferentialConstraints(); + for (ReferentialConstraint constraint : _referentialConstraints) { + if (constraint.getReferencedProperty().equals(referencedPropertyName)) { + return constraint.getProperty(); } } + return null; } @@ -89,8 +89,8 @@ public class EdmNavigationPropertyImpl extends AbstractEdmNavigationProperty { referentialConstraints = new ArrayList(); if (providerConstraints != null) { for (ReferentialConstraint constraint : providerConstraints) { - referentialConstraints.add(new EdmReferentialConstraintImpl(constraint.getProperty(), constraint - .getReferencedProperty())); + referentialConstraints.add( + new EdmReferentialConstraintImpl(constraint.getProperty(), constraint.getReferencedProperty())); } } } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmSchemaImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmSchemaImpl.java index 5ee34614b..8e0f9d66b 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmSchemaImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmSchemaImpl.java @@ -150,7 +150,7 @@ public class EdmSchemaImpl extends AbstractEdmSchema { if (providerEntityTypes != null) { for (EntityType entityType : providerEntityTypes) { entityTypes.add(EdmEntityTypeImpl.getInstance(edm, - new FullQualifiedName(namespace, entityType.getName()), entityType)); + new FullQualifiedName(namespace, entityType.getName()), xmlSchemas, entityType)); } } return entityTypes; @@ -163,7 +163,7 @@ public class EdmSchemaImpl extends AbstractEdmSchema { if (providerComplexTypes != null) { for (ComplexType complexType : providerComplexTypes) { complexTypes.add(EdmComplexTypeImpl.getInstance(edm, new FullQualifiedName(namespace, complexType.getName()), - complexType)); + xmlSchemas, complexType)); } } return complexTypes; diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmStructuredTypeHelperImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmStructuredTypeHelperImpl.java index 45bd2c11c..77d92df5c 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmStructuredTypeHelperImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmStructuredTypeHelperImpl.java @@ -19,13 +19,15 @@ package org.apache.olingo.client.core.edm; import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; import org.apache.olingo.client.api.edm.xml.CommonNavigationProperty; import org.apache.olingo.client.api.edm.xml.CommonProperty; import org.apache.olingo.client.api.edm.xml.ComplexType; import org.apache.olingo.client.api.edm.xml.EntityType; -import org.apache.olingo.client.api.edm.xml.v4.NavigationProperty; +import org.apache.olingo.client.api.edm.xml.Schema; +import org.apache.olingo.client.core.edm.v3.EdmNavigationPropertyProxy; import org.apache.olingo.commons.api.edm.Edm; import org.apache.olingo.commons.api.edm.EdmNavigationProperty; import org.apache.olingo.commons.api.edm.EdmProperty; @@ -37,13 +39,18 @@ public class EdmStructuredTypeHelperImpl implements EdmStructuredTypeHelper { private final ComplexType complexType; + private final List xmlSchemas; + private Map properties; private Map navigationProperties; - public EdmStructuredTypeHelperImpl(final Edm edm, final ComplexType complexType) { + public EdmStructuredTypeHelperImpl( + final Edm edm, final List xmlSchemas, final ComplexType complexType) { + this.edm = edm; this.complexType = complexType; + this.xmlSchemas = xmlSchemas; } @Override @@ -62,9 +69,12 @@ public class EdmStructuredTypeHelperImpl implements EdmStructuredTypeHelper { if (navigationProperties == null) { navigationProperties = new LinkedHashMap(); for (CommonNavigationProperty navigationProperty : complexType.getNavigationProperties()) { - if (navigationProperty instanceof NavigationProperty) { - navigationProperties.put(navigationProperty.getName(), - new EdmNavigationPropertyImpl(edm, (NavigationProperty) navigationProperty)); + if (navigationProperty instanceof org.apache.olingo.client.api.edm.xml.v4.NavigationProperty) { + navigationProperties.put(navigationProperty.getName(), new EdmNavigationPropertyImpl( + edm, (org.apache.olingo.client.api.edm.xml.v4.NavigationProperty) navigationProperty)); + } else if (navigationProperty instanceof org.apache.olingo.client.api.edm.xml.v3.NavigationProperty) { + navigationProperties.put(navigationProperty.getName(), new EdmNavigationPropertyProxy( + edm, xmlSchemas, (org.apache.olingo.client.api.edm.xml.v3.NavigationProperty) navigationProperty)); } } } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/v3/EdmEntitySetProxy.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/v3/EdmEntitySetProxy.java index 1303fefa0..1af488918 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/v3/EdmEntitySetProxy.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/v3/EdmEntitySetProxy.java @@ -18,9 +18,10 @@ */ package org.apache.olingo.client.core.edm.v3; -import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; import java.util.List; - +import java.util.Map; import org.apache.olingo.client.api.edm.xml.EntityContainer; import org.apache.olingo.client.api.edm.xml.Schema; import org.apache.olingo.client.api.edm.xml.v3.Association; @@ -49,7 +50,8 @@ public class EdmEntitySetProxy extends AbstractEdmBindingTarget implements EdmEn @Override public EdmBindingTarget getRelatedBindingTarget(final String path) { - final List candidateAssociationSets = new ArrayList(); + final Map candidateAssociationSets = + new HashMap(); for (Schema schema : xmlSchemas) { for (EntityContainer _entityContainer : schema.getEntityContainers()) { final EntityContainerImpl entityContainer = (EntityContainerImpl) _entityContainer; @@ -57,7 +59,8 @@ public class EdmEntitySetProxy extends AbstractEdmBindingTarget implements EdmEn if (getName().equals(associationSet.getEnds().get(0).getEntitySet()) || getName().equals(associationSet.getEnds().get(1).getEntitySet())) { - candidateAssociationSets.add(associationSet); + candidateAssociationSets.put(associationSet, + new FullQualifiedName(schema.getNamespace(), entityContainer.getName())); } } } @@ -66,34 +69,33 @@ public class EdmEntitySetProxy extends AbstractEdmBindingTarget implements EdmEn throw new EdmException("Cannot find any AssociationSet with first End: " + getName()); } - Schema targetSchema = null; + FullQualifiedName targetEntityContainer = null; String targetEntitySet = null; - for (AssociationSet associationSet : candidateAssociationSets) { + for (Map.Entry entry : candidateAssociationSets.entrySet()) { for (Schema schema : xmlSchemas) { for (Association association : ((SchemaImpl) schema).getAssociations()) { final FullQualifiedName associationName = new FullQualifiedName(schema.getNamespace(), association.getName()); - if (associationName.getFullQualifiedNameAsString().equals(associationSet.getAssociation()) + if (associationName.getFullQualifiedNameAsString().equals(entry.getKey().getAssociation()) && (path.equals(association.getEnds().get(0).getRole()) || path.equals(association.getEnds().get(1).getRole()))) { - targetSchema = schema; - if (getName().equals(associationSet.getEnds().get(0).getEntitySet())) { - targetEntitySet = associationSet.getEnds().get(1).getEntitySet(); + targetEntityContainer = entry.getValue(); + if (getName().equals(entry.getKey().getEnds().get(0).getEntitySet())) { + targetEntitySet = entry.getKey().getEnds().get(1).getEntitySet(); } else { - targetEntitySet = associationSet.getEnds().get(0).getEntitySet(); + targetEntitySet = entry.getKey().getEnds().get(0).getEntitySet(); } } } } } - if (targetSchema == null || targetEntitySet == null) { + if (targetEntityContainer == null || targetEntitySet == null) { throw new EdmException("Cannot find Association for candidate AssociationSets and given Role"); } - final FullQualifiedName relatedFQN = new FullQualifiedName(targetSchema.getNamespace(), targetEntitySet); - final EdmEntityContainer entityContainer = edm.getEntityContainer(relatedFQN); + final EdmEntityContainer entityContainer = edm.getEntityContainer(targetEntityContainer); if (entityContainer == null) { - throw new EdmException("Cannot find EntityContainer with name: " + relatedFQN); + throw new EdmException("Cannot find EntityContainer with name: " + targetEntityContainer); } return entityContainer.getEntitySet(targetEntitySet); @@ -107,8 +109,8 @@ public class EdmEntitySetProxy extends AbstractEdmBindingTarget implements EdmEn @Override public List getNavigationPropertyBindings() { - //There are no navigation property bindings in V3 so we will deliver an empty list - return new ArrayList(); + // There are no navigation property bindings in V3 so we will deliver an empty list + return Collections.emptyList(); } } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/v3/EdmNavigationPropertyProxy.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/v3/EdmNavigationPropertyProxy.java new file mode 100644 index 000000000..cadb3ae0a --- /dev/null +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/v3/EdmNavigationPropertyProxy.java @@ -0,0 +1,168 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.olingo.client.core.edm.v3; + +import java.util.ArrayList; +import java.util.List; +import org.apache.olingo.client.api.edm.xml.Schema; +import org.apache.olingo.client.api.edm.xml.v3.Association; +import org.apache.olingo.client.api.edm.xml.v3.AssociationEnd; +import org.apache.olingo.client.api.edm.xml.v3.NavigationProperty; +import org.apache.olingo.client.api.edm.xml.v3.ReferentialConstraint; +import org.apache.olingo.client.core.edm.xml.v3.SchemaImpl; +import org.apache.olingo.commons.api.edm.Edm; +import org.apache.olingo.commons.api.edm.EdmEntityType; +import org.apache.olingo.commons.api.edm.EdmNavigationProperty; +import org.apache.olingo.commons.api.edm.EdmReferentialConstraint; +import org.apache.olingo.commons.api.edm.FullQualifiedName; +import org.apache.olingo.commons.core.edm.AbstractEdmNavigationProperty; +import org.apache.olingo.commons.core.edm.EdmReferentialConstraintImpl; + +public class EdmNavigationPropertyProxy extends AbstractEdmNavigationProperty { + + private final List xmlSchemas; + + private final NavigationProperty navigationProperty; + + private final FullQualifiedName typeFQN; + + private final boolean isCollection; + + private final boolean isNullable; + + private EdmNavigationProperty partner; + + private final ReferentialConstraint constraint; + + private List referentialConstraints; + + public EdmNavigationPropertyProxy(final Edm edm, final List xmlSchemas, + final NavigationProperty navigationProperty) { + + super(edm, navigationProperty.getName()); + this.xmlSchemas = xmlSchemas; + this.navigationProperty = navigationProperty; + + final FullQualifiedName relFQN = new FullQualifiedName(navigationProperty.getRelationship()); + Schema associationSchema = null; + for (Schema schema : xmlSchemas) { + if (schema.getNamespace().equals(relFQN.getNamespace())) { + associationSchema = schema; + } + } + if (!(associationSchema instanceof SchemaImpl)) { + throw new IllegalArgumentException("Could not find schema for Association " + relFQN); + } + + final Association association = ((SchemaImpl) associationSchema).getAssociation(relFQN.getName()); + if (association == null) { + throw new IllegalArgumentException("Could not find Association " + relFQN.getName()); + } + + AssociationEnd thisEnd = null; + AssociationEnd partnerEnd = null; + for (AssociationEnd _end : association.getEnds()) { + if (_end.getRole().equals(navigationProperty.getToRole())) { + thisEnd = _end; + } else { + partnerEnd = _end; + } + } + if (thisEnd == null || partnerEnd == null) { + throw new IllegalArgumentException("Could not find AssociationEnd for role " + navigationProperty.getToRole()); + } + + typeFQN = new FullQualifiedName(thisEnd.getType()); + isCollection = "*".equals(thisEnd.getMultiplicity()); + isNullable = thisEnd.getMultiplicity().charAt(0) == '0'; + constraint = association.getReferentialConstraint(); + + final EdmEntityType partnerEntity = edm.getEntityType(new FullQualifiedName(thisEnd.getType())); + for (String navPropName : partnerEntity.getNavigationPropertyNames()) { + final EdmNavigationPropertyProxy navProp = + (EdmNavigationPropertyProxy) partnerEntity.getNavigationProperty(navPropName); + if (partnerEnd.getRole().equals(navProp.getXMLNavigationProperty().getToRole())) { + partner = navProp; + } + } + } + + protected NavigationProperty getXMLNavigationProperty() { + return navigationProperty; + } + + @Override + protected FullQualifiedName getTypeFQN() { + return typeFQN; + } + + @Override + protected String internatGetPartner() { + // not used + return null; + } + + @Override + public EdmNavigationProperty getPartner() { + return partner == null ? this: partner; + } + + @Override + public String getReferencingPropertyName(final String referencedPropertyName) { + if (constraint != null) { + for (int i = 0; i < constraint.getPrincipal().getPropertyRefs().size(); i++) { + if (referencedPropertyName.equals(constraint.getPrincipal().getPropertyRefs().get(i).getName())) { + return constraint.getDependent().getPropertyRefs().get(i).getName(); + } + } + } + return null; + } + + @Override + public boolean isCollection() { + return isCollection; + } + + @Override + public Boolean isNullable() { + return isNullable; + } + + @Override + public Boolean containsTarget() { + return navigationProperty.isContainsTarget(); + } + + @Override + public List getReferentialConstraints() { + if (referentialConstraints == null) { + referentialConstraints = new ArrayList(); + if (constraint != null) { + for (int i = 0; i < constraint.getPrincipal().getPropertyRefs().size(); i++) { + referentialConstraints.add(new EdmReferentialConstraintImpl( + constraint.getPrincipal().getPropertyRefs().get(i).getName(), + constraint.getDependent().getPropertyRefs().get(i).getName())); + } + } + } + return referentialConstraints; + } + +} diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/AbstractNavigationProperty.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/AbstractNavigationProperty.java index 65c9a8f4c..74882ccf9 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/AbstractNavigationProperty.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/AbstractNavigationProperty.java @@ -29,6 +29,9 @@ public class AbstractNavigationProperty extends AbstractEdmItem implements Commo @JsonProperty(value = "Name", required = true) private String name; + @JsonProperty(value = "ContainsTarget") + private boolean containsTarget = false; + @Override public String getName() { return name; @@ -37,4 +40,13 @@ public class AbstractNavigationProperty extends AbstractEdmItem implements Commo public void setName(final String name) { this.name = name; } + + @Override + public boolean isContainsTarget() { + return containsTarget; + } + + public void setContainsTarget(final boolean containsTarget) { + this.containsTarget = containsTarget; + } } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/v3/AssociationDeserializer.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/v3/AssociationDeserializer.java index c1d422d3e..51dc42aff 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/v3/AssociationDeserializer.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/v3/AssociationDeserializer.java @@ -42,10 +42,10 @@ public class AssociationDeserializer extends AbstractEdmDeserializer referentialConstraints = new ArrayList(); private OnDelete onDelete; @@ -75,15 +73,6 @@ public class NavigationPropertyImpl extends AbstractNavigationProperty implement this.partner = partner; } - @Override - public boolean isContainsTarget() { - return containsTarget; - } - - public void setContainsTarget(final boolean containsTarget) { - this.containsTarget = containsTarget; - } - @Override public List getReferentialConstraints() { return referentialConstraints; diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/MetadataTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/MetadataTest.java index ac4fffe73..303d18ad8 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/MetadataTest.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/MetadataTest.java @@ -49,6 +49,7 @@ import org.apache.olingo.commons.api.edm.EdmEntityType; import org.apache.olingo.commons.api.edm.EdmFunction; import org.apache.olingo.commons.api.edm.EdmFunctionImport; import org.apache.olingo.commons.api.edm.EdmFunctionImportInfo; +import org.apache.olingo.commons.api.edm.EdmNavigationProperty; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; import org.apache.olingo.commons.api.edm.FullQualifiedName; import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory; @@ -62,7 +63,69 @@ public class MetadataTest extends AbstractTest { } @Test - public void parse() { + public void parseWithEdm() { + final Edm edm = getClient().getReader().readMetadata(getClass().getResourceAsStream("metadata.xml")); + assertNotNull(edm); + + // 1. Complex + final EdmComplexType responseStatus = edm.getComplexType( + new FullQualifiedName("Microsoft.Test.OData.Services.AstoriaDefaultService", "ContactDetails")); + assertNotNull(responseStatus); + assertTrue(responseStatus.getNavigationPropertyNames().isEmpty()); + assertEquals(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.String), + responseStatus.getProperty("EmailBag").getType()); + + // 2. Entity + final EdmEntityType product = edm.getEntityType( + new FullQualifiedName("Microsoft.Test.OData.Services.AstoriaDefaultService", "Product")); + assertNotNull(product); + assertFalse(product.getPropertyNames().isEmpty()); + assertFalse(product.getNavigationPropertyNames().isEmpty()); + + final EdmNavigationProperty detail = product.getNavigationProperty("Detail"); + assertNotNull(detail); + assertEquals("Product", detail.getPartner().getName()); + assertFalse(detail.isCollection()); + assertTrue(detail.isNullable()); + + final EdmNavigationProperty relatedProducts = product.getNavigationProperty("RelatedProducts"); + assertNotNull(relatedProducts); + assertEquals("RelatedProducts", relatedProducts.getPartner().getName()); + assertTrue(relatedProducts.isCollection()); + assertFalse(relatedProducts.isNullable()); + + final EdmEntityType order = edm.getEntityType( + new FullQualifiedName("Microsoft.Test.OData.Services.AstoriaDefaultService", "Order")); + assertFalse(order.getPropertyNames().isEmpty()); + assertFalse(order.getNavigationPropertyNames().isEmpty()); + + final EdmEntityType customer = edm.getEntityType( + new FullQualifiedName("Microsoft.Test.OData.Services.AstoriaDefaultService", "Customer")); + assertEquals(order, customer.getNavigationProperty("Orders").getType()); + + // 3. Action + final EdmAction sack = edm.getBoundAction( + new FullQualifiedName("Microsoft.Test.OData.Services.AstoriaDefaultService", "Sack"), + new FullQualifiedName("Microsoft.Test.OData.Services.AstoriaDefaultService", "Employee"), + false); + assertNotNull(sack); + assertTrue(sack.isBound()); + assertEquals(1, sack.getParameterNames().size()); + + // 4. EntityContainer + final EdmEntityContainer container = edm.getEntityContainer( + new FullQualifiedName("Microsoft.Test.OData.Services.AstoriaDefaultService", "DefaultContainer")); + assertNotNull(container); + final EdmEntitySet logins = container.getEntitySet("Login"); + assertNotNull(logins); + assertEquals(edm.getEntityType(new FullQualifiedName(container.getNamespace(), "Login")), logins.getEntityType()); + assertEquals(container.getEntitySet("Customer").getEntityContainer().getFullQualifiedName(), + logins.getRelatedBindingTarget("Customer").getEntityContainer().getFullQualifiedName()); + assertEquals(container.getEntitySet("Customer").getName(), logins.getRelatedBindingTarget("Customer").getName()); + } + + @Test + public void parseWithXMLMetadata() { final XMLMetadata metadata = getClient().getDeserializer(). toMetadata(getClass().getResourceAsStream("metadata.xml")); assertNotNull(metadata); @@ -70,6 +133,7 @@ public class MetadataTest extends AbstractTest { final EntityType order = metadata.getSchemas().get(0).getEntityType("Order"); assertNotNull(order); assertEquals("Order", order.getName()); + assertFalse(order.getNavigationProperties().isEmpty()); @SuppressWarnings("unchecked") final List functionImports = (List) metadata.getSchemas().get(0). diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/JSONTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/JSONTest.java index efc7dac05..65d85e2d9 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/JSONTest.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/JSONTest.java @@ -27,7 +27,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; import java.io.ByteArrayInputStream; import java.io.StringWriter; -import java.net.URI; import java.util.ArrayList; import java.util.Iterator; import java.util.List; diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmReferentialConstraintImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmReferentialConstraintImpl.java index 93e151976..ed3f5c315 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmReferentialConstraintImpl.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmReferentialConstraintImpl.java @@ -23,9 +23,10 @@ import org.apache.olingo.commons.api.edm.EdmReferentialConstraint; public class EdmReferentialConstraintImpl implements EdmReferentialConstraint { private final String property; + private final String referencedProperty; - public EdmReferentialConstraintImpl(String property, String referencedProperty) { + public EdmReferentialConstraintImpl(final String property, final String referencedProperty) { this.property = property; this.referencedProperty = referencedProperty; }