You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by il...@apache.org on 2014/08/01 12:36:01 UTC
git commit: [OLINGO-365] Enhancing type handling for complex
properties
Repository: olingo-odata4
Updated Branches:
refs/heads/master b01b78447 -> 9b28f8df6
[OLINGO-365] Enhancing type handling for complex properties
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/9b28f8df
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/9b28f8df
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/9b28f8df
Branch: refs/heads/master
Commit: 9b28f8df62b36d0453191dd52d84d92b45b763c8
Parents: b01b784
Author: Francesco Chicchiriccò <--global>
Authored: Fri Aug 1 12:35:52 2014 +0200
Committer: Francesco Chicchiriccò <--global>
Committed: Fri Aug 1 12:35:52 2014 +0200
----------------------------------------------------------------------
.../olingo/fit/v4/DerivedTypeTestITCase.java | 2 +-
.../api/serialization/CommonODataBinder.java | 9 -----
.../core/serialization/AbstractODataBinder.java | 30 +++++++++++---
.../core/serialization/v3/ODataBinderImpl.java | 22 ++++------
.../core/serialization/v4/ODataBinderImpl.java | 42 ++++++++++----------
5 files changed, 54 insertions(+), 51 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9b28f8df/fit/src/test/java/org/apache/olingo/fit/v4/DerivedTypeTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/DerivedTypeTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/DerivedTypeTestITCase.java
index 12fe0dd..3102802 100644
--- a/fit/src/test/java/org/apache/olingo/fit/v4/DerivedTypeTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/v4/DerivedTypeTestITCase.java
@@ -107,7 +107,7 @@ public class DerivedTypeTestITCase extends AbstractTestITCase {
client.getObjectFactory().newCollectionValue("Edm.String")));
customer.getProperties().add(client.getObjectFactory().newPrimitiveProperty("City",
client.getObjectFactory().newPrimitiveValueBuilder().buildString("Pescara")));
- Calendar dateTime = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
+ final Calendar dateTime = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
dateTime.set(1977, 8, 8, 0, 0, 0);
customer.getProperties().add(client.getObjectFactory().newPrimitiveProperty("Birthday",
client.getObjectFactory().newPrimitiveValueBuilder().
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9b28f8df/lib/client-api/src/main/java/org/apache/olingo/client/api/serialization/CommonODataBinder.java
----------------------------------------------------------------------
diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/serialization/CommonODataBinder.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/serialization/CommonODataBinder.java
index 04b6bfc..0fd4fe8 100644
--- a/lib/client-api/src/main/java/org/apache/olingo/client/api/serialization/CommonODataBinder.java
+++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/serialization/CommonODataBinder.java
@@ -27,7 +27,6 @@ import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.domain.CommonODataEntity;
import org.apache.olingo.commons.api.domain.CommonODataEntitySet;
import org.apache.olingo.commons.api.domain.CommonODataProperty;
-import org.apache.olingo.commons.api.domain.ODataComplexValue;
import org.apache.olingo.commons.api.domain.ODataLink;
import org.apache.olingo.commons.api.domain.ODataServiceDocument;
@@ -66,14 +65,6 @@ public interface CommonODataBinder {
Property getProperty(CommonODataProperty property);
/**
- * Adds the given property to the given complex value.
- *
- * @param complex OData complex value.
- * @param property OData property.
- */
- void add(ODataComplexValue<CommonODataProperty> complex, CommonODataProperty property);
-
- /**
* Adds the given property to the given entity.
*
* @param entity OData entity.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9b28f8df/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/AbstractODataBinder.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/AbstractODataBinder.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/AbstractODataBinder.java
index 46aead4..6852f84 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/AbstractODataBinder.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/AbstractODataBinder.java
@@ -55,6 +55,7 @@ import org.apache.olingo.commons.api.domain.ODataServiceDocument;
import org.apache.olingo.commons.api.domain.ODataValue;
import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.EdmBindingTarget;
+import org.apache.olingo.commons.api.edm.EdmComplexType;
import org.apache.olingo.commons.api.edm.EdmElement;
import org.apache.olingo.commons.api.edm.EdmEntityContainer;
import org.apache.olingo.commons.api.edm.EdmEntityType;
@@ -561,15 +562,32 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
? null
: EdmPrimitiveTypeKind.valueOfFQN(client.getServiceVersion(), type.toString())).
build();
- } else if (valuable.isComplex() || valuable.isLinkedComplex()) {
- value = client.getObjectFactory().newComplexValue(type == null ? null : type.toString());
+ } else if (valuable.isComplex()) {
+ @SuppressWarnings("unchecked")
+ final ODataComplexValue<CommonODataProperty> cValue =
+ (ODataComplexValue<CommonODataProperty>) client.getObjectFactory().
+ newComplexValue(type == null ? null : type.toString());
+
if (!valuable.isNull()) {
- final List<Property> properties = valuable.isLinkedComplex()
- ? valuable.asLinkedComplex().getValue() : valuable.asComplex();
- for (Property property : properties) {
- value.asComplex().add(getODataProperty(new ResWrap<Property>(contextURL, metadataETag, property)));
+ EdmComplexType edmType = null;
+ if (client instanceof EdmEnabledODataClient && type != null) {
+ edmType = ((EdmEnabledODataClient) client).getEdm(metadataETag).getComplexType(type);
+ }
+
+ for (Property property : valuable.asComplex()) {
+ EdmType edmPropertyType = null;
+ if (edmType != null) {
+ final EdmElement edmProp = edmType.getProperty(property.getName());
+ if (edmProp != null) {
+ edmPropertyType = edmProp.getType();
+ }
+ }
+
+ cValue.add(getODataProperty(edmPropertyType, property));
}
}
+
+ value = cValue;
} else if (valuable.isCollection()) {
value = client.getObjectFactory().newCollectionValue(type == null ? null : "Collection(" + type.toString() + ")");
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9b28f8df/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/v3/ODataBinderImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/v3/ODataBinderImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/v3/ODataBinderImpl.java
index 4bd6b08..3e97760 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/v3/ODataBinderImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/v3/ODataBinderImpl.java
@@ -32,7 +32,6 @@ import org.apache.olingo.commons.api.domain.CommonODataEntity;
import org.apache.olingo.commons.api.domain.CommonODataEntitySet;
import org.apache.olingo.commons.api.domain.CommonODataProperty;
import org.apache.olingo.commons.api.domain.ODataCollectionValue;
-import org.apache.olingo.commons.api.domain.ODataComplexValue;
import org.apache.olingo.commons.api.domain.ODataValue;
import org.apache.olingo.commons.api.domain.v3.ODataEntity;
import org.apache.olingo.commons.api.domain.v3.ODataEntitySet;
@@ -51,11 +50,6 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder
}
@Override
- public void add(final ODataComplexValue<CommonODataProperty> complex, final CommonODataProperty property) {
- complex.add(property);
- }
-
- @Override
public boolean add(final CommonODataEntity entity, final CommonODataProperty property) {
return ((ODataEntity) entity).getProperties().add((ODataProperty) property);
}
@@ -74,8 +68,8 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder
if (property.hasPrimitiveValue()) {
propertyResource.setType(property.getPrimitiveValue().getTypeName());
propertyResource.setValue(
- propertyValue instanceof Geospatial ? ValueType.GEOSPATIAL : ValueType.PRIMITIVE,
- propertyValue);
+ propertyValue instanceof Geospatial ? ValueType.GEOSPATIAL : ValueType.PRIMITIVE,
+ propertyValue);
} else if (property.hasComplexValue()) {
propertyResource.setType(((ODataProperty) property).getComplexValue().getTypeName());
propertyResource.setValue(ValueType.COMPLEX, propertyValue);
@@ -86,9 +80,9 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder
ValueType valueType = ValueType.COLLECTION_PRIMITIVE;
if (value == null) {
valueType = ValueType.COLLECTION_PRIMITIVE;
- } else if (value.isPrimitive()) {
- valueType = value.asPrimitive().toValue() instanceof Geospatial ?
- ValueType.COLLECTION_GEOSPATIAL : ValueType.COLLECTION_PRIMITIVE;
+ } else if (value.isPrimitive()) {
+ valueType = value.asPrimitive().toValue() instanceof Geospatial
+ ? ValueType.COLLECTION_GEOSPATIAL : ValueType.COLLECTION_PRIMITIVE;
} else if (value.isComplex()) {
valueType = ValueType.COLLECTION_COMPLEX;
}
@@ -111,7 +105,7 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder
@Override
public ODataProperty getODataProperty(final ResWrap<Property> property) {
final EdmTypeInfo typeInfo = buildTypeInfo(ContextURLParser.parse(property.getContextURL()),
- property.getMetadataETag(), property.getPayload().getName(), property.getPayload().getType());
+ property.getMetadataETag(), property.getPayload().getName(), property.getPayload().getType());
return new ODataPropertyImpl(property.getPayload().getName(),
getODataValue(typeInfo == null ? null : typeInfo.getFullQualifiedName(),
@@ -123,8 +117,8 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder
final EdmTypeInfo typeInfo = buildTypeInfo(type == null ? null : type.getFullQualifiedName(), resource.getType());
return new ODataPropertyImpl(resource.getName(),
- getODataValue(typeInfo == null ? null : typeInfo.getFullQualifiedName(),
- resource, null, null));
+ getODataValue(typeInfo == null ? null : typeInfo.getFullQualifiedName(),
+ resource, null, null));
}
@Override
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9b28f8df/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/v4/ODataBinderImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/v4/ODataBinderImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/v4/ODataBinderImpl.java
index e84dcfa..e74f238 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/v4/ODataBinderImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/v4/ODataBinderImpl.java
@@ -43,7 +43,6 @@ import org.apache.olingo.commons.api.domain.CommonODataEntity;
import org.apache.olingo.commons.api.domain.CommonODataEntitySet;
import org.apache.olingo.commons.api.domain.CommonODataProperty;
import org.apache.olingo.commons.api.domain.ODataCollectionValue;
-import org.apache.olingo.commons.api.domain.ODataComplexValue;
import org.apache.olingo.commons.api.domain.ODataInlineEntity;
import org.apache.olingo.commons.api.domain.ODataInlineEntitySet;
import org.apache.olingo.commons.api.domain.ODataLinked;
@@ -78,6 +77,7 @@ import org.apache.olingo.commons.core.serialization.ContextURLParser;
import java.net.URI;
import java.util.List;
+import org.apache.olingo.commons.api.edm.EdmElement;
public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder {
@@ -86,11 +86,6 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder
}
@Override
- public void add(final ODataComplexValue<CommonODataProperty> complex, final CommonODataProperty property) {
- complex.add(property);
- }
-
- @Override
public boolean add(final CommonODataEntity entity, final CommonODataProperty property) {
return ((ODataEntity) entity).getProperties().add((ODataProperty) property);
}
@@ -124,7 +119,6 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder
}
private void updateValuable(final Valuable propertyResource, final ODataValuable odataValuable) {
-
final Object propertyValue = getValue(odataValuable.getValue());
if (odataValuable.hasPrimitiveValue()) {
propertyResource.setType(odataValuable.getPrimitiveValue().getTypeName());
@@ -163,7 +157,6 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder
}
private void annotations(final ODataAnnotatable odataAnnotatable, final Annotatable annotatable) {
-
for (ODataAnnotation odataAnnotation : odataAnnotatable.getAnnotations()) {
final Annotation annotation = new AnnotationImpl();
@@ -273,9 +266,9 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder
final ODataEntitySet entitySet = (ODataEntitySet) super.getODataEntitySet(resource);
if (resource.getPayload().getDeltaLink() != null) {
- final URI base = resource.getContextURL() == null ?
- resource.getPayload().getBaseURI() :
- ContextURLParser.parse(resource.getContextURL()).getServiceRoot();
+ final URI base = resource.getContextURL() == null
+ ? resource.getPayload().getBaseURI()
+ : ContextURLParser.parse(resource.getContextURL()).getServiceRoot();
entitySet.setDeltaLink(URIUtils.getURI(base, resource.getPayload().getDeltaLink()));
}
odataAnnotations(resource.getPayload(), entitySet);
@@ -309,11 +302,11 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder
public ODataProperty getODataProperty(final ResWrap<Property> resource) {
final Property payload = resource.getPayload();
final EdmTypeInfo typeInfo = buildTypeInfo(ContextURLParser.parse(resource.getContextURL()),
- resource.getMetadataETag(), payload.getName(), payload.getType());
+ resource.getMetadataETag(), payload.getName(), payload.getType());
final ODataProperty property = new ODataPropertyImpl(payload.getName(),
getODataValue(typeInfo == null ? null : typeInfo.getFullQualifiedName(),
- payload, resource.getContextURL(), resource.getMetadataETag()));
+ payload, resource.getContextURL(), resource.getMetadataETag()));
odataAnnotations(payload, property);
return property;
@@ -325,7 +318,7 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder
final ODataProperty property = new ODataPropertyImpl(resource.getName(),
getODataValue(typeInfo == null ? null : typeInfo.getFullQualifiedName(),
- resource, null, null));
+ resource, null, null));
odataAnnotations(resource, property);
return property;
@@ -351,15 +344,22 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder
final ODataLinkedComplexValue lcValue =
((ODataClient) client).getObjectFactory().newLinkedComplexValue(type == null ? null : type.toString());
- for (Property property : valuable.asLinkedComplex().getValue()) {
- lcValue.add(getODataProperty(new ResWrap<Property>(contextURL, metadataETag, property)));
- }
-
EdmComplexType edmType = null;
if (client instanceof EdmEnabledODataClient && type != null) {
edmType = ((EdmEnabledODataClient) client).getEdm(metadataETag).getComplexType(type);
}
+ for (Property property : valuable.asLinkedComplex().getValue()) {
+ EdmType edmPropertyType = null;
+ if (edmType != null) {
+ final EdmElement edmProp = edmType.getProperty(property.getName());
+ if (edmProp != null) {
+ edmPropertyType = edmProp.getType();
+ }
+ }
+ lcValue.add(getODataProperty(edmPropertyType, property));
+ }
+
odataNavigationLinks(edmType, valuable.asLinkedComplex(), lcValue, metadataETag, contextURL);
odataAnnotations(valuable.asLinkedComplex(), lcValue);
@@ -373,9 +373,9 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder
@Override
public ODataDelta getODataDelta(final ResWrap<Delta> resource) {
- final URI base = resource.getContextURL() == null ?
- resource.getPayload().getBaseURI() :
- ContextURLParser.parse(resource.getContextURL()).getServiceRoot();
+ final URI base = resource.getContextURL() == null
+ ? resource.getPayload().getBaseURI()
+ : ContextURLParser.parse(resource.getContextURL()).getServiceRoot();
final URI next = resource.getPayload().getNext();