[OLINGO-261] Missing V3 implementation of EdmNavigationProperty

This commit is contained in:
Francesco Chicchiriccò 2014-05-02 18:01:38 +02:00
parent 66a8f99b49
commit 6e72b1f3da
18 changed files with 316 additions and 66 deletions

View File

@ -19,4 +19,6 @@
package org.apache.olingo.client.api.edm.xml;
public interface CommonNavigationProperty extends Named {
boolean isContainsTarget();
}

View File

@ -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<ReferentialConstraint> getReferentialConstraints();
OnDelete getOnDelete();

View File

@ -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.

View File

@ -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);
}
}

View File

@ -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<? extends Schema> 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<? extends Schema> xmlSchemas, final ComplexType complexType) {
super(edm, fqn, baseTypeName);
this.helper = new EdmStructuredTypeHelperImpl(edm, complexType);
this.helper = new EdmStructuredTypeHelperImpl(edm, xmlSchemas, complexType);
}
@Override

View File

@ -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);
}

View File

@ -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<? extends Schema> 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<? extends Schema> xmlSchemas, final EntityType entityType) {
super(edm, fqn, baseTypeName, entityType.isHasStream());
this.helper = new EdmStructuredTypeHelperImpl(edm, entityType);
this.helper = new EdmStructuredTypeHelperImpl(edm, xmlSchemas, entityType);
}
@Override

View File

@ -71,14 +71,14 @@ public class EdmNavigationPropertyImpl extends AbstractEdmNavigationProperty {
@Override
public String getReferencingPropertyName(final String referencedPropertyName) {
final List<? extends ReferentialConstraint> referentialConstraints = navigationProperty.getReferentialConstraints();
if (referentialConstraints != null) {
for (ReferentialConstraint constraint : referentialConstraints) {
if (constraint.getReferencedProperty().equals(referencedPropertyName)) {
return constraint.getProperty();
}
final List<? extends ReferentialConstraint> _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<EdmReferentialConstraint>();
if (providerConstraints != null) {
for (ReferentialConstraint constraint : providerConstraints) {
referentialConstraints.add(new EdmReferentialConstraintImpl(constraint.getProperty(), constraint
.getReferencedProperty()));
referentialConstraints.add(
new EdmReferentialConstraintImpl(constraint.getProperty(), constraint.getReferencedProperty()));
}
}
}

View File

@ -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;

View File

@ -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<? extends Schema> xmlSchemas;
private Map<String, EdmProperty> properties;
private Map<String, EdmNavigationProperty> navigationProperties;
public EdmStructuredTypeHelperImpl(final Edm edm, final ComplexType complexType) {
public EdmStructuredTypeHelperImpl(
final Edm edm, final List<? extends Schema> 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<String, EdmNavigationProperty>();
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));
}
}
}

View File

@ -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<AssociationSet> candidateAssociationSets = new ArrayList<AssociationSet>();
final Map<AssociationSet, FullQualifiedName> candidateAssociationSets =
new HashMap<AssociationSet, FullQualifiedName>();
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<AssociationSet, FullQualifiedName> 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<EdmNavigationPropertyBinding> getNavigationPropertyBindings() {
//There are no navigation property bindings in V3 so we will deliver an empty list
return new ArrayList<EdmNavigationPropertyBinding>();
// There are no navigation property bindings in V3 so we will deliver an empty list
return Collections.emptyList();
}
}

View File

@ -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<? extends Schema> 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<EdmReferentialConstraint> referentialConstraints;
public EdmNavigationPropertyProxy(final Edm edm, final List<? extends Schema> 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<EdmReferentialConstraint> getReferentialConstraints() {
if (referentialConstraints == null) {
referentialConstraints = new ArrayList<EdmReferentialConstraint>();
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;
}
}

View File

@ -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;
}
}

View File

@ -42,10 +42,10 @@ public class AssociationDeserializer extends AbstractEdmDeserializer<Association
association.setName(jp.nextTextValue());
} else if ("ReferentialConstraint".equals(jp.getCurrentName())) {
jp.nextToken();
association.setReferentialConstraint(jp.readValueAs( ReferentialConstraintImpl.class));
association.setReferentialConstraint(jp.readValueAs(ReferentialConstraintImpl.class));
} else if ("End".equals(jp.getCurrentName())) {
jp.nextToken();
association.getEnds().add(jp.readValueAs( AssociationEndImpl.class));
association.getEnds().add(jp.readValueAs(AssociationEndImpl.class));
}
}
}

View File

@ -40,8 +40,6 @@ public class NavigationPropertyImpl extends AbstractNavigationProperty implement
private String partner;
private boolean containsTarget = false;
private final List<ReferentialConstraint> referentialConstraints = new ArrayList<ReferentialConstraint>();
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<ReferentialConstraint> getReferentialConstraints() {
return referentialConstraints;

View File

@ -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<FunctionImport> functionImports = (List<FunctionImport>) metadata.getSchemas().get(0).

View File

@ -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;

View File

@ -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;
}