[OLINGO-365] Enhancing type handling for complex properties
This commit is contained in:
parent
b01b784477
commit
9b28f8df62
|
@ -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().
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
@ -65,14 +64,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.
|
||||
*
|
||||
|
|
|
@ -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() + ")");
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
@ -50,11 +49,6 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder
|
|||
super(client);
|
||||
}
|
||||
|
||||
@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
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
@ -85,11 +85,6 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder
|
|||
super(client);
|
||||
}
|
||||
|
||||
@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();
|
||||
|
||||
|
|
Loading…
Reference in New Issue