You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by mi...@apache.org on 2014/06/27 14:26:53 UTC
[3/3] git commit: [OLINGO-317] Refactoring of 'Value-classes'
[OLINGO-317] Refactoring of 'Value-classes'
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/a2874142
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/a2874142
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/a2874142
Branch: refs/heads/Olingo-317_DeSerializerRefactoring
Commit: a2874142c5fb5478b96f7a0d3083ce81924a9fd2
Parents: 2d79cc7
Author: Michael Bolz <mi...@sap.com>
Authored: Fri Jun 27 14:21:01 2014 +0200
Committer: Michael Bolz <mi...@sap.com>
Committed: Fri Jun 27 14:25:30 2014 +0200
----------------------------------------------------------------------
.../olingo/ext/proxy/utils/CoreUtils.java | 8 +-
.../org/apache/olingo/fit/AbstractServices.java | 82 +++++----
.../java/org/apache/olingo/fit/V4Services.java | 51 +++---
.../olingo/fit/utils/AbstractUtilities.java | 24 +--
.../apache/olingo/fit/v3/AsyncTestITCase.java | 2 +-
.../olingo/fit/v3/OpenTypeTestITCase.java | 6 +-
.../fit/v3/PropertyRetrieveTestITCase.java | 9 +-
.../olingo/fit/v3/PropertyTestITCase.java | 8 +-
.../olingo/fit/v3/PropertyValueTestITCase.java | 2 +-
.../olingo/fit/v4/AbstractTestITCase.java | 15 +-
.../apache/olingo/fit/v4/BatchTestITCase.java | 5 +-
.../fit/v4/BoundOperationInvokeTestITCase.java | 10 +-
.../olingo/fit/v4/ConformanceTestITCase.java | 13 +-
.../olingo/fit/v4/DerivedTypeTestITCase.java | 10 +-
.../olingo/fit/v4/EntityUpdateTestITCase.java | 9 +-
.../olingo/fit/v4/OpenTypeTestITCase.java | 12 +-
.../cud/ODataValueUpdateRequestImpl.java | 5 +-
.../request/retrieve/ODataValueRequestImpl.java | 10 +-
.../EdmConstantAnnotationExpressionImpl.java | 54 +++---
.../core/serialization/AbstractODataBinder.java | 79 ++++-----
.../core/serialization/AbstractODataReader.java | 4 +-
.../core/serialization/v3/ODataBinderImpl.java | 30 +++-
.../core/serialization/v4/ODataBinderImpl.java | 68 +++++---
.../serialization/v4/ODataDeserializerImpl.java | 3 +
.../client/core/v3/PrimitiveValueTest.java | 19 +--
.../olingo/client/core/v3/PropertyTest.java | 4 +-
.../apache/olingo/client/core/v4/JSONTest.java | 4 +-
.../olingo/client/core/v4/entity.primitive.json | 2 +-
.../commons/api/data/CollectionValue.java | 27 ---
.../olingo/commons/api/data/ComplexValue.java | 27 ---
.../olingo/commons/api/data/EnumValue.java | 25 ---
.../commons/api/data/GeospatialValue.java | 28 ---
.../commons/api/data/LinkedComplexValue.java | 5 +-
.../olingo/commons/api/data/NullValue.java | 26 ---
.../olingo/commons/api/data/PrimitiveValue.java | 25 ---
.../olingo/commons/api/data/Valuable.java | 25 ++-
.../apache/olingo/commons/api/data/Value.java | 50 ------
.../olingo/commons/api/data/ValueType.java | 42 +++++
.../commons/api/domain/ODataPrimitiveValue.java | 2 -
.../commons/core/data/AbstractValuable.java | 143 ++++++++++++++++
.../olingo/commons/core/data/AbstractValue.java | 115 -------------
.../commons/core/data/AnnotationImpl.java | 14 +-
.../commons/core/data/CollectionValueImpl.java | 40 -----
.../commons/core/data/ComplexValueImpl.java | 40 -----
.../olingo/commons/core/data/EnumValueImpl.java | 41 -----
.../commons/core/data/GeospatialValueImpl.java | 42 -----
.../core/data/LinkedComplexValueImpl.java | 11 +-
.../olingo/commons/core/data/NullValueImpl.java | 35 ----
.../commons/core/data/PrimitiveValueImpl.java | 41 -----
.../olingo/commons/core/data/PropertyImpl.java | 13 +-
.../domain/AbstractODataPrimitiveValue.java | 76 +++------
.../core/domain/AbstractODataProperty.java | 2 +-
.../commons/core/edm/primitivetype/EdmDate.java | 2 +-
.../core/edm/primitivetype/EdmDateTime.java | 11 +-
.../edm/primitivetype/EdmDateTimeOffset.java | 47 +++--
.../core/edm/primitivetype/EdmTimeOfDay.java | 26 ++-
.../core/serialization/AtomDeserializer.java | 160 +++++++++--------
.../core/serialization/AtomSerializer.java | 128 +++++++++-----
.../core/serialization/JsonDeserializer.java | 123 +++++++-------
.../serialization/JsonEntityDeserializer.java | 13 +-
.../serialization/JsonEntitySerializer.java | 6 +-
.../JsonEntitySetDeserializer.java | 7 +-
.../serialization/JsonEntitySetSerializer.java | 6 +-
.../serialization/JsonPropertyDeserializer.java | 17 +-
.../serialization/JsonPropertySerializer.java | 26 +--
.../core/serialization/JsonSerializer.java | 170 ++++++++++++-------
.../primitivetype/CommonPrimitiveTypeTest.java | 3 +-
.../core/serializer/ODataJsonSerializer.java | 12 +-
.../tecsvc/processor/SampleJsonProcessor.java | 8 +-
69 files changed, 1007 insertions(+), 1201 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a2874142/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/utils/CoreUtils.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/utils/CoreUtils.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/utils/CoreUtils.java
index 5e44e74..d1f680f 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/utils/CoreUtils.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/utils/CoreUtils.java
@@ -93,7 +93,7 @@ public final class CoreUtils {
final EdmTypeInfo intType = new EdmTypeInfo.Builder().
setEdm(client.getCachedEdm()).setTypeExpression(type.getFullQualifiedName().toString()).build();
- for (Object collectionItem : (Collection) obj) {
+ for (Object collectionItem : (Collection<?>) obj) {
if (intType.isPrimitiveType()) {
value.asCollection().add(getODataValue(client, intType, collectionItem).asPrimitive());
} else if (intType.isComplexType()) {
@@ -137,7 +137,7 @@ public final class CoreUtils {
throw new UnsupportedInV3Exception();
} else {
value = ((org.apache.olingo.commons.api.domain.v4.ODataObjectFactory) client.getObjectFactory()).
- newEnumValue(type.getFullQualifiedName().toString(), ((Enum) obj).name());
+ newEnumValue(type.getFullQualifiedName().toString(), ((Enum<?>) obj).name());
}
} else {
value = client.getObjectFactory().newPrimitiveValueBuilder().setType(type.getPrimitiveTypeKind()).setValue(obj).
@@ -281,6 +281,9 @@ public final class CoreUtils {
return new EdmTypeInfo.Builder().setEdm(client.getCachedEdm()).setTypeExpression(kind.toString()).build();
} else if (target.isAssignableFrom(clazz)) {
bckCandidate = kind;
+ } else if (target == Timestamp.class
+ && (kind == EdmPrimitiveTypeKind.DateTime || kind == EdmPrimitiveTypeKind.DateTimeOffset)) {
+ bckCandidate = kind;
}
}
}
@@ -495,7 +498,6 @@ public final class CoreUtils {
}
}
- @SuppressWarnings("unchecked")
public static Object getObjectFromODataValue(
final CommonEdmEnabledODataClient<?> client,
final ODataValue value,
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a2874142/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java b/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java
index 4db7659..5d00864 100644
--- a/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java
+++ b/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java
@@ -36,6 +36,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -67,13 +68,15 @@ import org.apache.cxf.jaxrs.client.WebClient;
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.apache.cxf.jaxrs.ext.multipart.Multipart;
import org.apache.cxf.jaxrs.ext.multipart.MultipartBody;
-import org.apache.olingo.commons.api.data.ComplexValue;
import org.apache.olingo.commons.api.data.Entity;
import org.apache.olingo.commons.api.data.EntitySet;
import org.apache.olingo.commons.api.data.Link;
+import org.apache.olingo.commons.api.data.LinkedComplexValue;
import org.apache.olingo.commons.api.data.Property;
import org.apache.olingo.commons.api.data.ResWrap;
-import org.apache.olingo.commons.api.data.Value;
+import org.apache.olingo.commons.api.data.Valuable;
+import org.apache.olingo.commons.api.data.ValueType;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
import org.apache.olingo.commons.api.format.ContentType;
@@ -82,9 +85,8 @@ import org.apache.olingo.commons.api.serialization.ODataSerializer;
import org.apache.olingo.commons.core.data.EntityImpl;
import org.apache.olingo.commons.core.data.EntitySetImpl;
import org.apache.olingo.commons.core.data.LinkImpl;
-import org.apache.olingo.commons.core.data.NullValueImpl;
-import org.apache.olingo.commons.core.data.PrimitiveValueImpl;
import org.apache.olingo.commons.core.data.PropertyImpl;
+import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
import org.apache.olingo.commons.core.serialization.AtomSerializer;
import org.apache.olingo.commons.core.serialization.JsonDeserializer;
import org.apache.olingo.commons.core.serialization.JsonSerializer;
@@ -228,7 +230,7 @@ public abstract class AbstractServices {
final Property id = new PropertyImpl();
id.setType("Edm.Int32");
id.setName("StoredPIID");
- id.setValue(new PrimitiveValueImpl("1000"));
+ id.setValue(ValueType.PRIMITIVE, 1000);
entity.getProperties().add(id);
final Link edit = new LinkImpl();
edit.setHref(uriInfo.getRequestUri().toASCIIString());
@@ -474,7 +476,7 @@ public abstract class AbstractServices {
if (_property == null) {
container.getPayload().getProperties().add(property);
} else {
- _property.setValue(property.getValue());
+ _property.setValue(property.getValueType(), property.getValue());
}
}
@@ -625,7 +627,9 @@ public abstract class AbstractServices {
final Property prop = new PropertyImpl();
prop.setName(id.getKey());
prop.setType(id.getValue().toString());
- prop.setValue(new PrimitiveValueImpl(entityKey));
+ prop.setValue(ValueType.PRIMITIVE,
+ id.getValue() == EdmPrimitiveTypeKind.Int32 ? Integer.parseInt(entityKey) :
+ id.getValue() == EdmPrimitiveTypeKind.Guid ? UUID.fromString(entityKey) : entityKey);
entry.getProperties().add(prop);
}
@@ -721,8 +725,8 @@ public abstract class AbstractServices {
final InputStream entity = entityInfo.getValue();
final ResWrap<Entity> container = atomDeserializer.toEntity(entity);
- container.getPayload().getProperty("Salary").setValue(new PrimitiveValueImpl("0"));
- container.getPayload().getProperty("Title").setValue(new PrimitiveValueImpl("[Sacked]"));
+ container.getPayload().getProperty("Salary").setValue(ValueType.PRIMITIVE, 0);
+ container.getPayload().getProperty("Title").setValue(ValueType.PRIMITIVE, "[Sacked]");
final FSManager fsManager = FSManager.instance(version);
fsManager.putInMemory(xml.writeEntity(Accept.ATOM, container),
@@ -815,7 +819,8 @@ public abstract class AbstractServices {
final Entity param = xml.readEntity(utils.getKey(), IOUtils.toInputStream(argument, Constants.ENCODING));
- container.getPayload().getProperty("Dimensions").setValue(param.getProperty("dimensions").getValue());
+ final Property property = param.getProperty("dimensions");
+ container.getPayload().getProperty("Dimensions").setValue(property.getValueType(), property.getValue());
final FSManager fsManager = FSManager.instance(version);
fsManager.putInMemory(xml.writeEntity(Accept.ATOM, container),
@@ -850,8 +855,10 @@ public abstract class AbstractServices {
final Entity param = xml.readEntity(utils.getKey(), IOUtils.toInputStream(argument, Constants.ENCODING));
- container.getPayload().getProperty("SpecificationsBag").setValue(param.getProperty("specifications").getValue());
- container.getPayload().getProperty("PurchaseDate").setValue(param.getProperty("purchaseTime").getValue());
+ Property property = param.getProperty("specifications");
+ container.getPayload().getProperty("SpecificationsBag").setValue(property.getValueType(), property.getValue());
+ property = param.getProperty("purchaseTime");
+ container.getPayload().getProperty("PurchaseDate").setValue(property.getValueType(), property.getValue());
final FSManager fsManager = FSManager.instance(version);
fsManager.putInMemory(xml.writeEntity(Accept.ATOM, container),
@@ -1327,8 +1334,8 @@ public abstract class AbstractServices {
if (toBeReplaced == null) {
toBeReplaced = entry.getProperty(element.trim());
} else {
- ComplexValue value = toBeReplaced.getValue().asComplex();
- for (Property field : value.get()) {
+ List<Property> value = toBeReplaced.asComplex();
+ for (Property field : value) {
if (field.getName().equalsIgnoreCase(element)) {
toBeReplaced = field;
}
@@ -1342,13 +1349,13 @@ public abstract class AbstractServices {
if (justValue) {
// just for primitive values
- toBeReplaced.setValue(new PrimitiveValueImpl(changes));
+ toBeReplaced.setValue(ValueType.PRIMITIVE, changes);
} else {
final Property pchanges = xml.readProperty(
Accept.parse(contentType, version),
IOUtils.toInputStream(changes, Constants.ENCODING));
- toBeReplaced.setValue(pchanges.getValue());
+ toBeReplaced.setValue(pchanges.getValueType(), pchanges.getValue());
}
fsManager.putInMemory(xml.writeEntity(Accept.ATOM, container),
@@ -1767,12 +1774,12 @@ public abstract class AbstractServices {
final String[] pathElems = StringUtils.split(path, "/");
Property property = entryContainer.getPayload().getProperty(pathElems[0]);
- if (pathElems.length > 1 && property.getValue().isComplex()) {
- for (Property sub : property.getValue().asComplex().get()) {
+ if (pathElems.length > 1 && property.isComplex()) {
+ for (Property sub : property.asComplex()) {
if (pathElems[1].equals(sub.getName())) {
property = sub;
- if (pathElems.length > 2 && property.getValue().isComplex()) {
- for (Property subsub : property.getValue().asComplex().get()) {
+ if (pathElems.length > 2 && property.isComplex()) {
+ for (Property subsub : property.asComplex()) {
if (pathElems[2].equals(subsub.getName())) {
property = subsub;
}
@@ -1790,15 +1797,27 @@ public abstract class AbstractServices {
property);
return xml.createResponse(null,
- searchForValue ?
- IOUtils.toInputStream(container.getPayload().getValue() == null
- || container.getPayload().getValue().isNull() ? StringUtils.EMPTY :
- container.getPayload().getValue().asPrimitive().get(), Constants.ENCODING) :
- utils.writeProperty(acceptType, container),
+ searchForValue ?
+ IOUtils.toInputStream(
+ container.getPayload().isNull() ? StringUtils.EMPTY : stringValue(container.getPayload()),
+ Constants.ENCODING) :
+ utils.writeProperty(acceptType, container),
Commons.getETag(Commons.getEntityBasePath(entitySetName, entityId), version),
acceptType);
}
+ private String stringValue(final Property property) {
+ EdmPrimitiveTypeKind kind = EdmPrimitiveTypeKind.valueOfFQN(version, property.getType());
+ try {
+ return EdmPrimitiveTypeFactory.getInstance(kind)
+ .valueToString(property.asPrimitive(), null, null,
+ org.apache.olingo.commons.api.Constants.DEFAULT_PRECISION,
+ org.apache.olingo.commons.api.Constants.DEFAULT_SCALE, null);
+ } catch (final EdmPrimitiveTypeException e) {
+ return property.asPrimitive().toString();
+ }
+ }
+
/**
* Count sample.
*
@@ -1876,20 +1895,21 @@ public abstract class AbstractServices {
alink.setRel(Constants.get(version, ConstantKey.ATOM_LINK_REL) + property.getName());
- if (property.getValue().isComplex()) {
+ if (property.isComplex()) {
Entity inline = new EntityImpl();
inline.setType(navProperties.get(property.getName()).getType());
- for (Property prop : property.getValue().asComplex().get()) {
+ for (Property prop : property.asComplex()) {
inline.getProperties().add(prop);
}
alink.setInlineEntity(inline);
- } else if (property.getValue().isCollection()) {
+ } else if (property.isCollection()) {
EntitySet inline = new EntitySetImpl();
- for (Value value : property.getValue().asCollection().get()) {
+ for (Object value : property.asCollection()) {
Entity inlineEntity = new EntityImpl();
inlineEntity.setType(navProperties.get(property.getName()).getType());
- for (Property prop : value.asComplex().get()) {
+ for (Property prop : (value instanceof LinkedComplexValue ?
+ ((LinkedComplexValue) value).getValue() : ((Valuable) value).asComplex())) {
inlineEntity.getProperties().add(prop);
}
inline.getEntities().add(inlineEntity);
@@ -1911,7 +1931,7 @@ public abstract class AbstractServices {
if (entry.getProperty(property.getKey()) == null && property.getValue().isNullable()) {
final PropertyImpl prop = new PropertyImpl();
prop.setName(property.getKey());
- prop.setValue(new NullValueImpl());
+ prop.setValue(ValueType.PRIMITIVE, null);
entry.getProperties().add(prop);
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a2874142/fit/src/main/java/org/apache/olingo/fit/V4Services.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/V4Services.java b/fit/src/main/java/org/apache/olingo/fit/V4Services.java
index eaa66d0..27634b2 100644
--- a/fit/src/main/java/org/apache/olingo/fit/V4Services.java
+++ b/fit/src/main/java/org/apache/olingo/fit/V4Services.java
@@ -26,6 +26,7 @@ import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.net.URI;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -60,18 +61,15 @@ import org.apache.cxf.interceptor.InInterceptors;
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.apache.cxf.jaxrs.ext.multipart.Multipart;
import org.apache.cxf.jaxrs.ext.multipart.MultipartBody;
-import org.apache.olingo.commons.api.data.CollectionValue;
import org.apache.olingo.commons.api.data.Entity;
import org.apache.olingo.commons.api.data.EntitySet;
import org.apache.olingo.commons.api.data.Property;
import org.apache.olingo.commons.api.data.ResWrap;
+import org.apache.olingo.commons.api.data.ValueType;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
import org.apache.olingo.commons.api.format.ContentType;
-import org.apache.olingo.commons.core.data.CollectionValueImpl;
import org.apache.olingo.commons.core.data.EntityImpl;
import org.apache.olingo.commons.core.data.EntitySetImpl;
-import org.apache.olingo.commons.core.data.EnumValueImpl;
-import org.apache.olingo.commons.core.data.PrimitiveValueImpl;
import org.apache.olingo.commons.core.data.PropertyImpl;
import org.apache.olingo.commons.core.edm.EdmTypeInfo;
import org.apache.olingo.fit.metadata.Metadata;
@@ -481,7 +479,7 @@ public class V4Services extends AbstractServices {
final Property property = new PropertyImpl();
property.setType("Edm.Int32");
- property.setValue(new PrimitiveValueImpl("2"));
+ property.setValue(ValueType.PRIMITIVE, 2);
final ResWrap<Property> container = new ResWrap<Property>(
URI.create(Constants.get(version, ConstantKey.ODATA_METADATA_PREFIX) + property.getType()), null,
property);
@@ -545,12 +543,12 @@ public class V4Services extends AbstractServices {
final Property productId = new PropertyImpl();
productId.setName("ProductID");
productId.setType("Edm.Int32");
- productId.setValue(new PrimitiveValueImpl(entityId));
+ productId.setValue(ValueType.PRIMITIVE, Integer.valueOf(entityId));
entry.getProperties().add(productId);
final Property productDetailId = new PropertyImpl();
productDetailId.setName("ProductDetailID");
productDetailId.setType("Edm.Int32");
- productDetailId.setValue(new PrimitiveValueImpl("2"));
+ productDetailId.setValue(ValueType.PRIMITIVE, 2);
entry.getProperties().add(productDetailId);
final EntitySetImpl feed = new EntitySetImpl();
@@ -707,7 +705,7 @@ public class V4Services extends AbstractServices {
final Property property = new PropertyImpl();
property.setType("Edm.Double");
- property.setValue(new PrimitiveValueImpl("41.79"));
+ property.setValue(ValueType.PRIMITIVE, 41.79);
final ResWrap<Property> container = new ResWrap<Property>((URI) null, null, property);
@@ -1096,7 +1094,7 @@ public class V4Services extends AbstractServices {
final PropertyImpl property = new PropertyImpl();
property.setType("Microsoft.Test.OData.Services.ODataWCFService.Color");
- property.setValue(new EnumValueImpl("Red"));
+ property.setValue(ValueType.ENUM, "Red");
final ResWrap<Property> container = new ResWrap<Property>(
URI.create(Constants.get(version, ConstantKey.ODATA_METADATA_PREFIX) + property.getType()), null,
property);
@@ -1160,13 +1158,8 @@ public class V4Services extends AbstractServices {
final PropertyImpl property = new PropertyImpl();
property.setType("Collection(String)");
- final CollectionValue value = new CollectionValueImpl();
- value.get().add(new PrimitiveValueImpl("Cheetos"));
- value.get().add(new PrimitiveValueImpl("Mushrooms"));
- value.get().add(new PrimitiveValueImpl("Apple"));
- value.get().add(new PrimitiveValueImpl("Car"));
- value.get().add(new PrimitiveValueImpl("Computer"));
- property.setValue(value);
+ final List<String> value = Arrays.asList("Cheetos", "Mushrooms", "Apple", "Car", "Computer");
+ property.setValue(ValueType.COLLECTION_PRIMITIVE, value);
final ResWrap<Property> container = new ResWrap<Property>(
URI.create(Constants.get(version, ConstantKey.ODATA_METADATA_PREFIX) + property.getType()), null,
property);
@@ -1198,19 +1191,13 @@ public class V4Services extends AbstractServices {
final PropertyImpl property = new PropertyImpl();
property.setType("Collection(Edm.String)");
- final CollectionValue value = new CollectionValueImpl();
- value.get().add(new PrimitiveValueImpl("first@olingo.apache.org"));
- value.get().add(new PrimitiveValueImpl("second@olingo.apache.org"));
- property.setValue(value);
+ property.setValue(ValueType.COLLECTION_PRIMITIVE,
+ Arrays.asList("first@olingo.apache.org", "second@olingo.apache.org"));
final ResWrap<Property> container = new ResWrap<Property>(
URI.create(Constants.get(version, ConstantKey.ODATA_METADATA_PREFIX) + property.getType()), null,
property);
- return xml.createResponse(
- null,
- xml.writeProperty(acceptType, container),
- null,
- acceptType);
+ return xml.createResponse(null, xml.writeProperty(acceptType, container), null, acceptType);
} catch (Exception e) {
return xml.createFaultResponse(accept, e);
}
@@ -1244,11 +1231,11 @@ public class V4Services extends AbstractServices {
property = paramContainer.getPayload();
}
- assert property.getValue().isComplex();
- assert 1 == property.getValue().asComplex().get().size();
- assert "Edm.Int32".equals(property.getValue().asComplex().get().get(0).getType());
- assert property.getValue().asComplex().get().get(0).getValue().isPrimitive();
- assert "percentage".equals(property.getValue().asComplex().get().get(0).getName());
+ assert property.isComplex();
+ assert 1 == property.asComplex().size();
+ assert "Edm.Int32".equals(property.asComplex().get(0).getType());
+ assert property.asComplex().get(0).isPrimitive();
+ assert "percentage".equals(property.asComplex().get(0).getName());
return xml.createResponse(null, null, null, acceptType, Response.Status.NO_CONTENT);
} catch (Exception e) {
@@ -1276,7 +1263,7 @@ public class V4Services extends AbstractServices {
final Entity entity = xml.readEntity(contentTypeValue, IOUtils.toInputStream(param, Constants.ENCODING));
assert "Microsoft.Test.OData.Services.ODataWCFService.Address".equals(entity.getType());
- assert entity.getProperty("address").getValue().isComplex();
+ assert entity.getProperty("address").isComplex();
final ResWrap<Property> result = new ResWrap<Property>(
URI.create(Constants.get(version, ConstantKey.ODATA_METADATA_PREFIX)
@@ -1315,7 +1302,7 @@ public class V4Services extends AbstractServices {
assert 1 == entry.getProperties().size();
assert "Collection(Edm.String)".equals(entry.getProperty("emails").getType());
- assert entry.getProperty("emails").getValue().isCollection();
+ assert entry.getProperty("emails").isCollection();
return xml.createResponse(
null,
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a2874142/fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java b/fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java
index e293a78..779c531 100644
--- a/fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java
+++ b/fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java
@@ -617,7 +617,7 @@ public abstract class AbstractUtilities {
throw new IOException(String.format("Unable to retrieve entity key value for %s", entitySetName));
}
} else {
- res = entry.getProperty(propertyName).getValue().asPrimitive().get();
+ res = entry.getProperty(propertyName).asPrimitive().toString();
}
Commons.SEQUENCE.put(entitySetName, Integer.valueOf(res));
@@ -638,9 +638,9 @@ public abstract class AbstractUtilities {
throw new IOException(String.format("Unable to retrieve entity key value for %s", entitySetName));
}
} else {
- productID = Integer.valueOf(entity.getProperty("OrderID").getValue().asPrimitive().get());
- res = "OrderID=" + entity.getProperty("OrderID").getValue().asPrimitive().get()
- + ",ProductID=" + entity.getProperty("ProductID").getValue().asPrimitive().get();
+ productID = (Integer) entity.getProperty("OrderID").asPrimitive();
+ res = "OrderID=" + entity.getProperty("OrderID").asPrimitive()
+ + ",ProductID=" + entity.getProperty("ProductID").asPrimitive();
}
Commons.SEQUENCE.put(entitySetName, productID);
} else if ("Message".equals(entitySetName)) {
@@ -653,9 +653,9 @@ public abstract class AbstractUtilities {
throw new IOException(String.format("Unable to retrieve entity key value for %s", entitySetName));
}
} else {
- messageId = Integer.valueOf(entity.getProperty("MessageId").getValue().asPrimitive().get());
- res = "FromUsername=" + entity.getProperty("FromUsername").getValue().asPrimitive().get()
- + ",MessageId=" + entity.getProperty("MessageId").getValue().asPrimitive().get();
+ messageId = (Integer) entity.getProperty("MessageId").asPrimitive();
+ res = "FromUsername=" + entity.getProperty("FromUsername").asPrimitive()
+ + ",MessageId=" + entity.getProperty("MessageId").asPrimitive();
}
Commons.SEQUENCE.put(entitySetName, messageId);
} else if ("Order".equals(entitySetName)) {
@@ -681,7 +681,7 @@ public abstract class AbstractUtilities {
} else if ("RowIndex".equals(entitySetName)) {
res = getDefaultEntryKey(entitySetName, entity, "Id");
} else if ("Login".equals(entitySetName)) {
- res = entity.getProperty("Username").getValue().asPrimitive().get();
+ res = (String) entity.getProperty("Username").asPrimitive();
} else if ("Products".equals(entitySetName)) {
res = getDefaultEntryKey(entitySetName, entity, "ProductID");
} else if ("ProductDetails".equals(entitySetName)) {
@@ -697,10 +697,10 @@ public abstract class AbstractUtilities {
}
Commons.SEQUENCE.put(entitySetName, productDetailId);
} else {
- productId = Integer.valueOf(entity.getProperty("ProductID").getValue().asPrimitive().get());
- productDetailId = Integer.valueOf(entity.getProperty("ProductDetailID").getValue().asPrimitive().get());
- res = "ProductID=" + entity.getProperty("ProductID").getValue().asPrimitive().get()
- + ",ProductDetailID=" + entity.getProperty("ProductDetailID").getValue().asPrimitive().get();
+ productId = (Integer) entity.getProperty("ProductID").asPrimitive();
+ productDetailId = (Integer) entity.getProperty("ProductDetailID").asPrimitive();
+ res = "ProductID=" + entity.getProperty("ProductID").asPrimitive()
+ + ",ProductDetailID=" + entity.getProperty("ProductDetailID").asPrimitive();
}
Commons.SEQUENCE.put(entitySetName, productDetailId);
Commons.SEQUENCE.put("Products", productId);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a2874142/fit/src/test/java/org/apache/olingo/fit/v3/AsyncTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v3/AsyncTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v3/AsyncTestITCase.java
index d28bea2..1482545 100644
--- a/fit/src/test/java/org/apache/olingo/fit/v3/AsyncTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/v3/AsyncTestITCase.java
@@ -75,7 +75,7 @@ public class AsyncTestITCase extends AbstractTestITCase {
entity.getProperties().remove(entity.getProperty("Description"));
getClient().getBinder().add(entity,
client.getObjectFactory().newPrimitiveProperty("Description",
- client.getObjectFactory().newPrimitiveValueBuilder().setText("AsyncTest#updateEntity").build()));
+ client.getObjectFactory().newPrimitiveValueBuilder().setValue("AsyncTest#updateEntity").build()));
final ODataEntityUpdateRequest<ODataEntity> updateReq =
client.getCUDRequestFactory().getEntityUpdateRequest(uri, UpdateType.MERGE, entity);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a2874142/fit/src/test/java/org/apache/olingo/fit/v3/OpenTypeTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v3/OpenTypeTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v3/OpenTypeTestITCase.java
index b6b4d53..98e5b94 100644
--- a/fit/src/test/java/org/apache/olingo/fit/v3/OpenTypeTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/v3/OpenTypeTestITCase.java
@@ -112,15 +112,15 @@ public class OpenTypeTestITCase extends AbstractTestITCase {
getClient().getObjectFactory().newPrimitiveValueBuilder().buildBinary("text".getBytes())));
contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("LastContacted",
getClient().getObjectFactory().newPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.DateTimeOffset).setText("2001-04-05T05:05:05.001+00:01").build()));
+ setType(EdmPrimitiveTypeKind.DateTimeOffset).setValue(null).build()));
contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("Contacted",
getClient().getObjectFactory().newPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.DateTime).setText("2001-04-05T05:05:04.001").build()));
+ setType(EdmPrimitiveTypeKind.DateTime).setValue(null).build()));
contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("GUID",
getClient().getObjectFactory().newPrimitiveValueBuilder().buildGuid(UUID.randomUUID())));
contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("PreferedContactTime",
getClient().getObjectFactory().newPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.Time).setText("-P9DT51M10.5063807S").build()));
+ setType(EdmPrimitiveTypeKind.Time).setValue(null).build()));
contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("Byte",
getClient().getObjectFactory().newPrimitiveValueBuilder().
setType(EdmPrimitiveTypeKind.Byte).setValue(24).build()));
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a2874142/fit/src/test/java/org/apache/olingo/fit/v3/PropertyRetrieveTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v3/PropertyRetrieveTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v3/PropertyRetrieveTestITCase.java
index 0904df8..2a0bf65 100644
--- a/fit/src/test/java/org/apache/olingo/fit/v3/PropertyRetrieveTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/v3/PropertyRetrieveTestITCase.java
@@ -20,11 +20,11 @@ package org.apache.olingo.fit.v3;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.List;
+
import org.apache.olingo.client.api.communication.ODataClientErrorException;
import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetRequest;
import org.apache.olingo.client.api.communication.request.retrieve.ODataPropertyRequest;
@@ -52,15 +52,16 @@ public class PropertyRetrieveTestITCase extends AbstractTestITCase {
final ODataProperty property = req.execute().getBody();
assertNotNull(property);
if (property.hasNullValue()) {
- assertNull(property.getValue());
+ assertTrue(property.getValue() == null
+ || property.getValue().isPrimitive() && property.getValue().asPrimitive().toValue() == null);
} else if (property.hasPrimitiveValue()) {
final ODataPrimitiveValue value = property.getPrimitiveValue();
assertTrue(value.isPrimitive());
} else if (property.hasComplexValue()) {
- final ODataComplexValue value = property.getComplexValue();
+ final ODataComplexValue<?> value = property.getComplexValue();
assertTrue(value.isComplex());
} else if (property.hasCollectionValue()) {
- final ODataCollectionValue value = property.getCollectionValue();
+ final ODataCollectionValue<?> value = property.getCollectionValue();
assertTrue(value.isCollection());
}
} catch (ODataClientErrorException e) {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a2874142/fit/src/test/java/org/apache/olingo/fit/v3/PropertyTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v3/PropertyTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v3/PropertyTestITCase.java
index 107fec7..7a29f0f 100644
--- a/fit/src/test/java/org/apache/olingo/fit/v3/PropertyTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/v3/PropertyTestITCase.java
@@ -182,7 +182,7 @@ public class PropertyTestITCase extends AbstractTestITCase {
assertNotEquals(newMsg, oldMsg);
- final ODataPrimitiveValue newVal = client.getObjectFactory().newPrimitiveValueBuilder().setText(newMsg).build();
+ final ODataPrimitiveValue newVal = client.getObjectFactory().newPrimitiveValueBuilder().setValue(newMsg).build();
final ODataValueUpdateRequest updateReq =
client.getCUDRequestFactory().getValueUpdateRequest(uriBuilder.build(), type, newVal);
@@ -224,7 +224,7 @@ public class PropertyTestITCase extends AbstractTestITCase {
final int origSize = originalValue.size();
- originalValue.add(client.getObjectFactory().newPrimitiveValueBuilder().setText(newItem).build());
+ originalValue.add(client.getObjectFactory().newPrimitiveValueBuilder().setValue(newItem).build());
assertEquals(origSize + 1, originalValue.size());
final ODataPropertyUpdateRequest updateReq = client.getCUDRequestFactory().
@@ -271,7 +271,7 @@ public class PropertyTestITCase extends AbstractTestITCase {
final int origSize = originalValue.size();
- originalValue.add(client.getObjectFactory().newPrimitiveValueBuilder().setText(newItem).build());
+ originalValue.add(client.getObjectFactory().newPrimitiveValueBuilder().setValue(newItem).build());
assertEquals(origSize + 1, originalValue.size());
final ODataPropertyUpdateRequest updateReq =
@@ -319,7 +319,7 @@ public class PropertyTestITCase extends AbstractTestITCase {
assertNotEquals(newMsg, oldMsg);
phoneNumber = client.getObjectFactory().newPrimitiveProperty("PhoneNumber",
- client.getObjectFactory().newPrimitiveValueBuilder().setText(newMsg).build());
+ client.getObjectFactory().newPrimitiveValueBuilder().setValue(newMsg).build());
final ODataPropertyUpdateRequest updateReq =
client.getCUDRequestFactory().getPropertyPrimitiveValueUpdateRequest(uriBuilder.build(), phoneNumber);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a2874142/fit/src/test/java/org/apache/olingo/fit/v3/PropertyValueTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v3/PropertyValueTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v3/PropertyValueTestITCase.java
index b27461e..82296f2 100644
--- a/fit/src/test/java/org/apache/olingo/fit/v3/PropertyValueTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/v3/PropertyValueTestITCase.java
@@ -77,7 +77,7 @@ public class PropertyValueTestITCase extends AbstractTestITCase {
req.setFormat(ODataFormat.TEXT_PLAIN);
final ODataValue value = req.execute().getBody();
assertNotNull(value);
- assertEquals("7866-11-16T22:25:52.747755+01:00", value.toString());
+ assertEquals("7866-11-16T22:25:52.747755", value.toString());
}
@Test
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a2874142/fit/src/test/java/org/apache/olingo/fit/v4/AbstractTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/AbstractTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/AbstractTestITCase.java
index 5ba1c26..c7f3557 100644
--- a/fit/src/test/java/org/apache/olingo/fit/v4/AbstractTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/v4/AbstractTestITCase.java
@@ -22,7 +22,10 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.io.IOException;
+import java.math.BigDecimal;
import java.net.URI;
+import java.util.Calendar;
+import java.util.TimeZone;
import org.apache.olingo.client.api.communication.request.cud.ODataDeleteRequest;
import org.apache.olingo.client.api.communication.request.cud.ODataEntityCreateRequest;
@@ -112,22 +115,24 @@ public abstract class AbstractTestITCase extends AbstractBaseTestITCase {
getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(id));
order.getProperties().add(orderId);
+ Calendar dateTime = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
+ dateTime.set(2011, 2, 4, 16, 3, 57);
final ODataProperty orderDate = getClient().getObjectFactory().newPrimitiveProperty("OrderDate",
- getClient().getObjectFactory().newPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.DateTimeOffset).setText("2011-03-04T16:03:57Z").build());
+ getClient().getObjectFactory().newPrimitiveValueBuilder()
+ .setType(EdmPrimitiveTypeKind.DateTimeOffset).setValue(dateTime).build());
order.getProperties().add(orderDate);
final ODataProperty shelfLife = getClient().getObjectFactory().newPrimitiveProperty("ShelfLife",
getClient().getObjectFactory().newPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.Duration).setText("PT0.0000001S").build());
+ setType(EdmPrimitiveTypeKind.Duration).setValue(BigDecimal.TEN.scaleByPowerOfTen(7)).build());
order.getProperties().add(shelfLife);
final ODataCollectionValue<ODataValue> orderShelfLifesValue = getClient().getObjectFactory().
newCollectionValue("Collection(Duration)");
orderShelfLifesValue.add(getClient().getObjectFactory().newPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.Duration).setText("PT0.0000001S").build());
+ setType(EdmPrimitiveTypeKind.Duration).setValue(new BigDecimal("0.0000001")).build());
orderShelfLifesValue.add(getClient().getObjectFactory().newPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.Duration).setText("PT0.0000002S").build());
+ setType(EdmPrimitiveTypeKind.Duration).setValue(new BigDecimal("0.0000002")).build());
final ODataProperty orderShelfLifes = getClient().getObjectFactory().
newCollectionProperty("OrderShelfLifes", orderShelfLifesValue);
order.getProperties().add(orderShelfLifes);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a2874142/fit/src/test/java/org/apache/olingo/fit/v4/BatchTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/BatchTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/BatchTestITCase.java
index a491418..0f511b8 100644
--- a/fit/src/test/java/org/apache/olingo/fit/v4/BatchTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/v4/BatchTestITCase.java
@@ -24,6 +24,7 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.IOException;
+import java.math.BigDecimal;
import java.net.URI;
import java.util.Calendar;
import java.util.Collection;
@@ -674,11 +675,11 @@ public class BatchTestITCase extends AbstractTestITCase {
setType(EdmPrimitiveTypeKind.DateTimeOffset).setValue(Calendar.getInstance()).build()));
order.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("ShelfLife",
getClient().getObjectFactory().newPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.Duration).setText("PT0.0000002S").build()));
+ setType(EdmPrimitiveTypeKind.Duration).setValue(new BigDecimal("0.0000002")).build()));
order.getProperties().add(getClient().getObjectFactory().newCollectionProperty("OrderShelfLifes",
getClient().getObjectFactory().newCollectionValue(EdmPrimitiveTypeKind.Duration.name()).add(
getClient().getObjectFactory().newPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.Duration).
- setText("PT0.0000002S").build())));
+ setValue(new BigDecimal("0.0000002")).build())));
return order;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a2874142/fit/src/test/java/org/apache/olingo/fit/v4/BoundOperationInvokeTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/BoundOperationInvokeTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/BoundOperationInvokeTestITCase.java
index a009aea..1e6fc57 100644
--- a/fit/src/test/java/org/apache/olingo/fit/v4/BoundOperationInvokeTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/v4/BoundOperationInvokeTestITCase.java
@@ -22,10 +22,12 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
+import java.util.TimeZone;
import org.apache.olingo.client.api.communication.request.invoke.ODataInvokeRequest;
import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
@@ -350,8 +352,10 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase {
boundOp = entity.getOperation("Microsoft.Test.OData.Services.ODataWCFService.RefreshDefaultPI");
assertNotNull(boundOp);
+ Calendar dateTime = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
+ dateTime.set(2014, 3, 9, 0, 0, 0);
final ODataPrimitiveValue newDate = client.getObjectFactory().newPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.DateTimeOffset).setText("2014-04-09T00:00:00Z").build();
+ setType(EdmPrimitiveTypeKind.DateTimeOffset).setValue(dateTime).build();
final ODataInvokeRequest<ODataEntity> getDefaultPIReq =
client.getInvokeRequestFactory().getActionInvokeRequest(boundOp.getTarget(), ODataEntity.class,
Collections.<String, ODataValue>singletonMap("newDate", newDate));
@@ -434,8 +438,10 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase {
assertEquals(2, resetAddressRes.getProperty("PersonID").getPrimitiveValue().toCastValue(Integer.class), 0);
// RefreshDefaultPI
+ Calendar dateTime = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
+ dateTime.set(2014, 3, 9, 0, 0, 0);
final ODataPrimitiveValue newDate = edmClient.getObjectFactory().newPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.DateTimeOffset).setText("2014-04-09T00:00:00Z").build();
+ setType(EdmPrimitiveTypeKind.DateTimeOffset).setValue(dateTime).build();
final ODataInvokeRequest<ODataEntity> getDefaultPIReq =
edmClient.getInvokeRequestFactory().getBoundActionInvokeRequest(
edmClient.newURIBuilder().appendEntitySetSegment("Accounts").appendKeySegment(102).build(),
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a2874142/fit/src/test/java/org/apache/olingo/fit/v4/ConformanceTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/ConformanceTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/ConformanceTestITCase.java
index fc1c2e3..748d5ed 100644
--- a/fit/src/test/java/org/apache/olingo/fit/v4/ConformanceTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/v4/ConformanceTestITCase.java
@@ -23,7 +23,10 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import java.math.BigDecimal;
import java.net.URI;
+import java.util.Calendar;
+import java.util.TimeZone;
import org.apache.olingo.client.api.communication.header.HeaderName;
import org.apache.olingo.client.api.communication.request.cud.ODataDeleteRequest;
@@ -93,22 +96,24 @@ public class ConformanceTestITCase extends AbstractTestITCase {
getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(2000));
order.getProperties().add(orderId);
+ Calendar dateTime = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
+ dateTime.set(2011, 2, 4, 16, 3, 57);
final ODataProperty orderDate = getClient().getObjectFactory().newPrimitiveProperty("OrderDate",
getClient().getObjectFactory().newPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.DateTimeOffset).setText("2011-03-04T16:03:57Z").build());
+ setType(EdmPrimitiveTypeKind.DateTimeOffset).setValue(dateTime).build());
order.getProperties().add(orderDate);
final ODataProperty shelfLife = getClient().getObjectFactory().newPrimitiveProperty("ShelfLife",
getClient().getObjectFactory().newPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.Duration).setText("PT0.0000001S").build());
+ setType(EdmPrimitiveTypeKind.Duration).setValue(new BigDecimal("0.0000001")).build());
order.getProperties().add(shelfLife);
final ODataCollectionValue<ODataValue> orderShelfLifesValue = getClient().getObjectFactory().
newCollectionValue("Collection(Duration)");
orderShelfLifesValue.add(getClient().getObjectFactory().newPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.Duration).setText("PT0.0000001S").build());
+ setType(EdmPrimitiveTypeKind.Duration).setValue(new BigDecimal("0.0000001")).build());
orderShelfLifesValue.add(getClient().getObjectFactory().newPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.Duration).setText("PT0.0000002S").build());
+ setType(EdmPrimitiveTypeKind.Duration).setValue(new BigDecimal("0.0000002")).build());
final ODataProperty orderShelfLifes = getClient().getObjectFactory().
newCollectionProperty("OrderShelfLifes", orderShelfLifesValue);
order.getProperties().add(orderShelfLifes);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a2874142/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 929f453..76e6937 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
@@ -20,6 +20,10 @@ package org.apache.olingo.fit.v4;
import static org.junit.Assert.assertEquals;
+import java.math.BigDecimal;
+import java.util.Calendar;
+import java.util.TimeZone;
+
import org.apache.olingo.client.api.communication.request.cud.ODataDeleteRequest;
import org.apache.olingo.client.api.communication.request.cud.ODataEntityCreateRequest;
import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
@@ -103,12 +107,14 @@ 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"));
+ dateTime.set(1977, 8, 8, 0, 0, 0);
customer.getProperties().add(client.getObjectFactory().newPrimitiveProperty("Birthday",
client.getObjectFactory().newPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.DateTimeOffset).setText("1977-09-08T00:00:00Z").build()));
+ setType(EdmPrimitiveTypeKind.DateTimeOffset).setValue(dateTime).build()));
customer.getProperties().add(client.getObjectFactory().newPrimitiveProperty("TimeBetweenLastTwoOrders",
client.getObjectFactory().newPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.Duration).setText("PT0.0000002S").build()));
+ setType(EdmPrimitiveTypeKind.Duration).setValue(new BigDecimal("0.0000002")).build()));
final ODataEntityCreateRequest<ODataEntity> createReq = client.getCUDRequestFactory().
getEntityCreateRequest(
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a2874142/fit/src/test/java/org/apache/olingo/fit/v4/EntityUpdateTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/EntityUpdateTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/EntityUpdateTestITCase.java
index a81376c..34fa574 100644
--- a/fit/src/test/java/org/apache/olingo/fit/v4/EntityUpdateTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/v4/EntityUpdateTestITCase.java
@@ -21,8 +21,10 @@ package org.apache.olingo.fit.v4;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import java.math.BigDecimal;
import java.net.URI;
import java.util.Calendar;
+import java.util.TimeZone;
import java.util.UUID;
import org.apache.olingo.client.api.communication.request.cud.ODataEntityUpdateRequest;
@@ -45,11 +47,12 @@ public class EntityUpdateTestITCase extends AbstractTestITCase {
order.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("OrderID",
getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(9)));
order.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("OrderDate",
- getClient().getObjectFactory().newPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.DateTimeOffset).setValue(Calendar.getInstance()).build()));
+ getClient().getObjectFactory().newPrimitiveValueBuilder()
+ .setType(EdmPrimitiveTypeKind.DateTimeOffset).setValue(
+ Calendar.getInstance(TimeZone.getTimeZone("GMT"))).build()));
order.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("ShelfLife",
getClient().getObjectFactory().newPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.Duration).setText("PT0.0000002S").build()));
+ setType(EdmPrimitiveTypeKind.Duration).setValue(new BigDecimal("0.0000002")).build()));
final URI upsertURI = getClient().newURIBuilder(testStaticServiceRootURL).
appendEntitySetSegment("Orders").appendKeySegment(9).build();
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a2874142/fit/src/test/java/org/apache/olingo/fit/v4/OpenTypeTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/OpenTypeTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/OpenTypeTestITCase.java
index 6ce43c6..fabc739 100644
--- a/fit/src/test/java/org/apache/olingo/fit/v4/OpenTypeTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/v4/OpenTypeTestITCase.java
@@ -23,6 +23,7 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.Calendar;
+import java.util.TimeZone;
import java.util.UUID;
import org.apache.olingo.client.api.communication.request.cud.ODataEntityCreateRequest;
@@ -118,17 +119,22 @@ public class OpenTypeTestITCase extends AbstractTestITCase {
"Microsoft.Test.OData.Services.OpenTypesServiceV4.ContactDetails");
contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("FirstContacted",
getClient().getObjectFactory().newPrimitiveValueBuilder().buildBinary("text".getBytes())));
+ Calendar dateTime = Calendar.getInstance(TimeZone.getTimeZone("GMT+00:01"));
+ dateTime.set(2014, 3, 5, 5, 5, 5);
+ dateTime.set(Calendar.MILLISECOND, 1);
contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("LastContacted",
getClient().getObjectFactory().newPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.DateTimeOffset).setText("2001-04-05T05:05:05.001+00:01").build()));
+ setType(EdmPrimitiveTypeKind.DateTimeOffset).setValue(dateTime).build()));
+ Calendar date = Calendar.getInstance();
+ date.set(2001, 3, 5);
contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("Contacted",
getClient().getObjectFactory().newPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.Date).setText("2001-04-05").build()));
+ setType(EdmPrimitiveTypeKind.Date).setValue(date).build()));
contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("GUID",
getClient().getObjectFactory().newPrimitiveValueBuilder().buildGuid(UUID.randomUUID())));
contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("PreferedContactTime",
getClient().getObjectFactory().newPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.Duration).setText("-P9DT51M10.5063807S").build()));
+ setType(EdmPrimitiveTypeKind.Duration).setValue(0).build()));
contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("Byte",
getClient().getObjectFactory().newPrimitiveValueBuilder().
setType(EdmPrimitiveTypeKind.Byte).setValue(24).build()));
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a2874142/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataValueUpdateRequestImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataValueUpdateRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataValueUpdateRequestImpl.java
index 4a46684..b229052 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataValueUpdateRequestImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataValueUpdateRequestImpl.java
@@ -115,9 +115,6 @@ public class ODataValueUpdateRequestImpl extends AbstractODataBasicRequest<OData
super(client, res);
}
- /**
- * {@inheritDoc }
- */
@Override
public ODataPrimitiveValue getBody() {
if (value == null) {
@@ -127,7 +124,7 @@ public class ODataValueUpdateRequestImpl extends AbstractODataBasicRequest<OData
value = odataClient.getObjectFactory().newPrimitiveValueBuilder().
setType(format == ODataFormat.TEXT_PLAIN
? EdmPrimitiveTypeKind.String : EdmPrimitiveTypeKind.Stream).
- setText(IOUtils.toString(getRawResponse())).
+ setValue(getRawResponse()).
build();
} catch (Exception e) {
throw new HttpClientException(e);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a2874142/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataValueRequestImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataValueRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataValueRequestImpl.java
index 6e1e466..95cf016 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataValueRequestImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataValueRequestImpl.java
@@ -84,9 +84,6 @@ public class ODataValueRequestImpl extends AbstractODataRetrieveRequest<ODataPri
super(client, res);
}
- /**
- * {@inheritDoc }
- */
@Override
public ODataPrimitiveValue getBody() {
if (value == null) {
@@ -94,10 +91,9 @@ public class ODataValueRequestImpl extends AbstractODataRetrieveRequest<ODataPri
try {
value = odataClient.getObjectFactory().newPrimitiveValueBuilder().
- setType(format == ODataFormat.TEXT_PLAIN
- ? EdmPrimitiveTypeKind.String : EdmPrimitiveTypeKind.Stream).
- setText(IOUtils.toString(getRawResponse())).
- build();
+ setType(format == ODataFormat.TEXT_PLAIN ?
+ EdmPrimitiveTypeKind.String : EdmPrimitiveTypeKind.Stream).
+ setValue(IOUtils.toString(getRawResponse())).build();
} catch (Exception e) {
throw new HttpClientException(e);
} finally {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a2874142/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/v4/annotation/EdmConstantAnnotationExpressionImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/v4/annotation/EdmConstantAnnotationExpressionImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/v4/annotation/EdmConstantAnnotationExpressionImpl.java
index c53d0e8..e0ce3ba 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/v4/annotation/EdmConstantAnnotationExpressionImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/v4/annotation/EdmConstantAnnotationExpressionImpl.java
@@ -20,17 +20,22 @@ package org.apache.olingo.client.core.edm.v4.annotation;
import java.util.ArrayList;
import java.util.List;
+
import org.apache.commons.lang3.StringUtils;
import org.apache.olingo.client.api.edm.xml.v4.annotation.ConstantAnnotationExpression;
+import org.apache.olingo.commons.api.Constants;
import org.apache.olingo.commons.api.domain.v4.ODataEnumValue;
import org.apache.olingo.commons.api.domain.v4.ODataValue;
import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.edm.annotation.EdmConstantAnnotationExpression;
import org.apache.olingo.commons.api.edm.annotation.EdmDynamicAnnotationExpression;
import org.apache.olingo.commons.core.domain.v4.ODataCollectionValueImpl;
import org.apache.olingo.commons.core.domain.v4.ODataEnumValueImpl;
import org.apache.olingo.commons.core.domain.v4.ODataPrimitiveValueImpl;
+import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
public class EdmConstantAnnotationExpressionImpl implements EdmConstantAnnotationExpression {
@@ -55,54 +60,53 @@ public class EdmConstantAnnotationExpressionImpl implements EdmConstantAnnotatio
value = collValue;
}
} else {
- final ODataPrimitiveValueImpl.BuilderImpl primitiveValueBuilder =
- new ODataPrimitiveValueImpl.BuilderImpl(edm.getServiceMetadata().getDataServiceVersion());
- primitiveValueBuilder.setText(constExprConstruct.getValue());
-
+ EdmPrimitiveTypeKind kind;
switch (constExprConstruct.getType()) {
case Binary:
- primitiveValueBuilder.setType(EdmPrimitiveTypeKind.Binary);
+ kind = EdmPrimitiveTypeKind.Binary;
break;
-
case Bool:
- primitiveValueBuilder.setType(EdmPrimitiveTypeKind.Boolean);
+ kind = EdmPrimitiveTypeKind.Boolean;
break;
-
case Date:
- primitiveValueBuilder.setType(EdmPrimitiveTypeKind.Date);
+ kind = EdmPrimitiveTypeKind.Date;
break;
-
case DateTimeOffset:
- primitiveValueBuilder.setType(EdmPrimitiveTypeKind.DateTimeOffset);
+ kind = EdmPrimitiveTypeKind.DateTimeOffset;
break;
-
case Decimal:
- primitiveValueBuilder.setType(EdmPrimitiveTypeKind.Decimal);
+ kind = EdmPrimitiveTypeKind.Decimal;
break;
-
case Duration:
- primitiveValueBuilder.setType(EdmPrimitiveTypeKind.Duration);
+ kind = EdmPrimitiveTypeKind.Duration;
break;
-
case Float:
- primitiveValueBuilder.setType(EdmPrimitiveTypeKind.Single);
+ kind = EdmPrimitiveTypeKind.Single;
break;
-
case Guid:
- primitiveValueBuilder.setType(EdmPrimitiveTypeKind.Guid);
+ kind = EdmPrimitiveTypeKind.Guid;
break;
-
case Int:
- primitiveValueBuilder.setType(EdmPrimitiveTypeKind.Int32);
+ kind = EdmPrimitiveTypeKind.Int32;
break;
-
case TimeOfDay:
- primitiveValueBuilder.setType(EdmPrimitiveTypeKind.TimeOfDay);
+ kind = EdmPrimitiveTypeKind.TimeOfDay;
break;
-
case String:
default:
- primitiveValueBuilder.setType(EdmPrimitiveTypeKind.String);
+ kind = EdmPrimitiveTypeKind.String;
+ }
+ final ODataPrimitiveValueImpl.BuilderImpl primitiveValueBuilder =
+ new ODataPrimitiveValueImpl.BuilderImpl(edm.getServiceMetadata().getDataServiceVersion());
+ primitiveValueBuilder.setType(kind);
+ try {
+ final EdmPrimitiveType primitiveType = EdmPrimitiveTypeFactory.getInstance(kind);
+ primitiveValueBuilder.setValue(
+ primitiveType.valueOfString(constExprConstruct.getValue(),
+ null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null,
+ primitiveType.getDefaultType()));
+ } catch (final EdmPrimitiveTypeException e) {
+ throw new IllegalArgumentException(e);
}
value = primitiveValueBuilder.build();
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a2874142/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 620204a..a0ab765 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
@@ -20,7 +20,8 @@ package org.apache.olingo.client.core.serialization;
import java.io.StringWriter;
import java.net.URI;
-import java.util.Iterator;
+import java.util.ArrayList;
+import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.apache.olingo.client.api.CommonODataClient;
@@ -38,7 +39,6 @@ import org.apache.olingo.commons.api.data.Linked;
import org.apache.olingo.commons.api.data.Property;
import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.data.Valuable;
-import org.apache.olingo.commons.api.data.Value;
import org.apache.olingo.commons.api.domain.CommonODataEntity;
import org.apache.olingo.commons.api.domain.CommonODataEntitySet;
import org.apache.olingo.commons.api.domain.CommonODataProperty;
@@ -65,17 +65,11 @@ import org.apache.olingo.commons.api.edm.EdmSchema;
import org.apache.olingo.commons.api.edm.EdmStructuredType;
import org.apache.olingo.commons.api.edm.EdmType;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.edm.geo.Geospatial;
import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.commons.api.serialization.ODataSerializerException;
-import org.apache.olingo.commons.core.data.CollectionValueImpl;
-import org.apache.olingo.commons.core.data.ComplexValueImpl;
import org.apache.olingo.commons.core.data.EntityImpl;
import org.apache.olingo.commons.core.data.EntitySetImpl;
-import org.apache.olingo.commons.core.data.GeospatialValueImpl;
import org.apache.olingo.commons.core.data.LinkImpl;
-import org.apache.olingo.commons.core.data.NullValueImpl;
-import org.apache.olingo.commons.core.data.PrimitiveValueImpl;
import org.apache.olingo.commons.core.data.PropertyImpl;
import org.apache.olingo.commons.core.edm.EdmTypeInfo;
import org.slf4j.Logger;
@@ -223,32 +217,29 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
return linkResource;
}
- protected Value getValue(final ODataValue value) {
- Value valueResource = null;
-
+ protected Object getValue(final ODataValue value) {
if (value == null) {
- valueResource = new NullValueImpl();
+ return null;
} else if (value.isPrimitive()) {
- valueResource = value.asPrimitive().getTypeKind().isGeospatial()
- ? new GeospatialValueImpl((Geospatial) value.asPrimitive().toValue())
- : new PrimitiveValueImpl(value.asPrimitive().toString());
+ return value.asPrimitive().toValue();
} else if (value.isComplex()) {
final ODataComplexValue<? extends CommonODataProperty> _value = value.asComplex();
- valueResource = new ComplexValueImpl();
+ List<Property> valueResource = new ArrayList<Property>();
- for (final Iterator<? extends CommonODataProperty> itor = _value.iterator(); itor.hasNext();) {
- valueResource.asComplex().get().add(getProperty(itor.next()));
+ for (final CommonODataProperty propertyValue : _value) {
+ valueResource.add(getProperty(propertyValue));
}
+ return valueResource;
} else if (value.isCollection()) {
final ODataCollectionValue<? extends ODataValue> _value = value.asCollection();
- valueResource = new CollectionValueImpl();
+ ArrayList<Object> valueResource = new ArrayList<Object>();
- for (final Iterator<? extends ODataValue> itor = _value.iterator(); itor.hasNext();) {
- valueResource.asCollection().get().add(getValue(itor.next()));
+ for (final ODataValue collectionValue : _value) {
+ valueResource.add(getValue(collectionValue));
}
+ return valueResource;
}
-
- return valueResource;
+ return null;
}
protected abstract boolean add(CommonODataEntitySet entitySet, CommonODataEntity entity);
@@ -493,32 +484,34 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
final Valuable valuable, final ContextURL contextURL, final String metadataETag) {
ODataValue value = null;
- if (valuable.getValue().isGeospatial()) {
- value = client.getObjectFactory().newPrimitiveValueBuilder().
- setValue(valuable.getValue().asGeospatial().get()).
- setType(type == null
+ if (valuable.isGeospatial()) {
+ value = client.getObjectFactory().newPrimitiveValueBuilder()
+ .setValue(valuable.asGeospatial())
+ .setType(type == null
|| EdmPrimitiveTypeKind.Geography.getFullQualifiedName().equals(type)
- || EdmPrimitiveTypeKind.Geometry.getFullQualifiedName().equals(type)
- ? valuable.getValue().asGeospatial().get().getEdmPrimitiveTypeKind()
- : EdmPrimitiveTypeKind.valueOfFQN(client.getServiceVersion(), type.toString())).build();
- } else if (valuable.getValue().isPrimitive()) {
- value = client.getObjectFactory().newPrimitiveValueBuilder().
- setText(valuable.getValue().asPrimitive().get()).
- setType(type == null || !EdmPrimitiveType.EDM_NAMESPACE.equals(type.getNamespace())
- ? null
- : EdmPrimitiveTypeKind.valueOfFQN(client.getServiceVersion(), type.toString())).build();
- } else if (valuable.getValue().isComplex()) {
+ || EdmPrimitiveTypeKind.Geometry.getFullQualifiedName().equals(type) ?
+ valuable.asGeospatial().getEdmPrimitiveTypeKind() :
+ EdmPrimitiveTypeKind.valueOfFQN(client.getServiceVersion(), type.toString())).build();
+ } else if (valuable.isPrimitive() || valuable.getValueType() == null) {
+ value = client.getObjectFactory().newPrimitiveValueBuilder()
+ .setValue(valuable.asPrimitive())
+ .setType(type == null || !EdmPrimitiveType.EDM_NAMESPACE.equals(type.getNamespace()) ? null :
+ EdmPrimitiveTypeKind.valueOfFQN(client.getServiceVersion(), type.toString())).build();
+ } else if (valuable.isComplex() || valuable.isLinkedComplex()) {
value = client.getObjectFactory().newComplexValue(type == null ? null : type.toString());
-
- for (Property property : valuable.getValue().asComplex().get()) {
- value.asComplex().add(getODataProperty(new ResWrap<Property>(contextURL, metadataETag, property)));
+ 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)));
+ }
}
- } else if (valuable.getValue().isCollection()) {
+ } else if (valuable.isCollection()) {
value = client.getObjectFactory().newCollectionValue(type == null ? null : "Collection(" + type.toString() + ")");
- for (Value _value : valuable.getValue().asCollection().get()) {
+ for (Object _value : valuable.asCollection()) {
final Property fake = new PropertyImpl();
- fake.setValue(_value);
+ fake.setValue(valuable.getValueType().getBaseType(), _value);
value.asCollection().add(getODataValue(type, fake, contextURL, metadataETag));
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a2874142/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/AbstractODataReader.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/AbstractODataReader.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/AbstractODataReader.java
index fca8273..5a32d70 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/AbstractODataReader.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/AbstractODataReader.java
@@ -121,8 +121,8 @@ public abstract class AbstractODataReader implements CommonODataReader {
reference.cast(client.getObjectFactory().newPrimitiveValueBuilder().
setType(ODataFormat.fromString(format) == ODataFormat.TEXT_PLAIN
? EdmPrimitiveTypeKind.String : EdmPrimitiveTypeKind.Stream).
- setText(IOUtils.toString(src)).
- build()));
+ setValue(IOUtils.toString(src)) // TODO: set correct value
+ .build()));
} else if (XMLMetadata.class.isAssignableFrom(reference)) {
res = new ResWrap<T>(
(URI) null,
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a2874142/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 77ea315..9410de0 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
@@ -26,15 +26,19 @@ import org.apache.olingo.commons.api.data.Entity;
import org.apache.olingo.commons.api.data.EntitySet;
import org.apache.olingo.commons.api.data.Property;
import org.apache.olingo.commons.api.data.ResWrap;
+import org.apache.olingo.commons.api.data.ValueType;
import org.apache.olingo.commons.api.data.v3.LinkCollection;
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;
import org.apache.olingo.commons.api.domain.v3.ODataProperty;
import org.apache.olingo.commons.api.edm.EdmType;
+import org.apache.olingo.commons.api.edm.geo.Geospatial;
import org.apache.olingo.commons.core.data.PropertyImpl;
import org.apache.olingo.commons.core.domain.v3.ODataPropertyImpl;
import org.apache.olingo.commons.core.edm.EdmTypeInfo;
@@ -64,14 +68,30 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder
public Property getProperty(final CommonODataProperty property) {
final Property propertyResource = new PropertyImpl();
propertyResource.setName(property.getName());
- propertyResource.setValue(getValue(property.getValue()));
+ final Object propertyValue = getValue(property.getValue());
if (property.hasPrimitiveValue()) {
propertyResource.setType(property.getPrimitiveValue().getTypeName());
+ propertyResource.setValue(
+ propertyValue instanceof Geospatial ? ValueType.GEOSPATIAL : ValueType.PRIMITIVE,
+ propertyValue);
} else if (property.hasComplexValue()) {
propertyResource.setType(((ODataProperty) property).getComplexValue().getTypeName());
+ propertyResource.setValue(ValueType.COMPLEX, propertyValue);
} else if (property.hasCollectionValue()) {
- propertyResource.setType(((ODataProperty) property).getCollectionValue().getTypeName());
+ final ODataCollectionValue<ODataValue> collectionValue = ((ODataProperty) property).getCollectionValue();
+ propertyResource.setType(collectionValue.getTypeName());
+ final ODataValue value = collectionValue.iterator().hasNext() ? collectionValue.iterator().next() : null;
+ 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.isComplex()) {
+ valueType = ValueType.COLLECTION_COMPLEX;
+ }
+ propertyResource.setValue(valueType, propertyValue);
}
return propertyResource;
@@ -102,10 +122,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/a2874142/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 2362a9a..231e4fb 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
@@ -19,6 +19,7 @@
package org.apache.olingo.client.core.serialization.v4;
import java.net.URI;
+import java.util.List;
import org.apache.olingo.client.api.data.ServiceDocument;
import org.apache.olingo.client.api.data.ServiceDocumentItem;
@@ -41,10 +42,11 @@ import org.apache.olingo.commons.api.data.LinkedComplexValue;
import org.apache.olingo.commons.api.data.Property;
import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.data.Valuable;
-import org.apache.olingo.commons.api.data.Value;
+import org.apache.olingo.commons.api.data.ValueType;
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;
@@ -67,8 +69,8 @@ import org.apache.olingo.commons.api.edm.EdmEnumType;
import org.apache.olingo.commons.api.edm.EdmTerm;
import org.apache.olingo.commons.api.edm.EdmType;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.edm.geo.Geospatial;
import org.apache.olingo.commons.core.data.AnnotationImpl;
-import org.apache.olingo.commons.core.data.EnumValueImpl;
import org.apache.olingo.commons.core.data.LinkedComplexValueImpl;
import org.apache.olingo.commons.core.data.PropertyImpl;
import org.apache.olingo.commons.core.domain.v4.ODataAnnotationImpl;
@@ -123,16 +125,40 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder
private void updateValuable(final Valuable propertyResource, final ODataValuable odataValuable) {
- propertyResource.setValue(getValue(odataValuable.getValue()));
-
+ final Object propertyValue = getValue(odataValuable.getValue());
if (odataValuable.hasPrimitiveValue()) {
propertyResource.setType(odataValuable.getPrimitiveValue().getTypeName());
+ propertyResource.setValue(
+ propertyValue instanceof Geospatial ? ValueType.GEOSPATIAL : ValueType.PRIMITIVE,
+ propertyValue);
} else if (odataValuable.hasEnumValue()) {
propertyResource.setType(odataValuable.getEnumValue().getTypeName());
+ propertyResource.setValue(ValueType.ENUM, propertyValue);
} else if (odataValuable.hasComplexValue()) {
propertyResource.setType(odataValuable.getComplexValue().getTypeName());
+ propertyResource.setValue(
+ propertyValue instanceof LinkedComplexValue ? ValueType.LINKED_COMPLEX : ValueType.COMPLEX,
+ propertyValue);
} else if (odataValuable.hasCollectionValue()) {
- propertyResource.setType(odataValuable.getCollectionValue().getTypeName());
+ final ODataCollectionValue<org.apache.olingo.commons.api.domain.v4.ODataValue> collectionValue =
+ odataValuable.getCollectionValue();
+ propertyResource.setType(collectionValue.getTypeName());
+ final org.apache.olingo.commons.api.domain.v4.ODataValue value =
+ collectionValue.iterator().hasNext() ? collectionValue.iterator().next() : null;
+ 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.isEnum()) {
+ valueType = ValueType.COLLECTION_ENUM;
+ } else if (value.isLinkedComplex()) {
+ valueType = ValueType.COLLECTION_LINKED_COMPLEX;
+ } else if (value.isComplex()) {
+ valueType = ValueType.COLLECTION_COMPLEX;
+ }
+ propertyResource.setValue(valueType, propertyValue);
}
}
@@ -190,13 +216,13 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder
}
@Override
- protected Value getValue(final ODataValue value) {
- Value valueResource;
+ protected Object getValue(final ODataValue value) {
+ Object valueResource;
if (value instanceof org.apache.olingo.commons.api.domain.v4.ODataValue
&& ((org.apache.olingo.commons.api.domain.v4.ODataValue) value).isEnum()) {
- valueResource = new EnumValueImpl(
- ((org.apache.olingo.commons.api.domain.v4.ODataValue) value).asEnum().getValue());
+ valueResource =
+ ((org.apache.olingo.commons.api.domain.v4.ODataValue) value).asEnum().getValue();
} else {
valueResource = super.getValue(value);
@@ -204,7 +230,7 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder
&& ((org.apache.olingo.commons.api.domain.v4.ODataValue) value).isLinkedComplex()) {
final LinkedComplexValue lcValueResource = new LinkedComplexValueImpl();
- lcValueResource.get().addAll(valueResource.asComplex().get());
+ lcValueResource.getValue().addAll((List<Property>) valueResource);
final ODataLinkedComplexValue linked =
((org.apache.olingo.commons.api.domain.v4.ODataValue) value).asLinkedComplex();
@@ -296,10 +322,8 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder
final EdmTypeInfo typeInfo = buildTypeInfo(type == null ? null : type.getFullQualifiedName(), resource.getType());
final ODataProperty property = new ODataPropertyImpl(resource.getName(),
- getODataValue(typeInfo == null
- ? null
- : typeInfo.getFullQualifiedName(),
- resource, null, null));
+ getODataValue(typeInfo == null ? null : typeInfo.getFullQualifiedName(),
+ resource, null, null));
odataAnnotations(resource, property);
return property;
@@ -312,20 +336,20 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder
// fixes enum values treated as primitive when no type information is available
if (client instanceof EdmEnabledODataClient && type != null) {
final EdmEnumType edmType = ((EdmEnabledODataClient) client).getEdm(metadataETag).getEnumType(type);
- if (valuable.getValue().isPrimitive() && edmType != null) {
- valuable.setValue(new EnumValueImpl(valuable.getValue().asPrimitive().get()));
+ if (valuable.isPrimitive() && edmType != null) {
+ valuable.setValue(ValueType.ENUM, valuable.asPrimitive());
}
}
ODataValue value;
- if (valuable.getValue().isEnum()) {
+ if (valuable.isEnum()) {
value = ((ODataClient) client).getObjectFactory().newEnumValue(type == null ? null : type.toString(),
- valuable.getValue().asEnum().get());
- } else if (valuable.getValue().isLinkedComplex()) {
+ valuable.asEnum().toString());
+ } else if (valuable.isLinkedComplex()) {
final ODataLinkedComplexValue lcValue =
((ODataClient) client).getObjectFactory().newLinkedComplexValue(type == null ? null : type.toString());
- for (Property property : valuable.getValue().asLinkedComplex().get()) {
+ for (Property property : valuable.asLinkedComplex().getValue()) {
lcValue.add(getODataProperty(new ResWrap<Property>(contextURL, metadataETag, property)));
}
@@ -334,9 +358,9 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder
edmType = ((EdmEnabledODataClient) client).getEdm(metadataETag).getComplexType(type);
}
- odataNavigationLinks(edmType, valuable.getValue().asLinkedComplex(), lcValue, metadataETag,
+ odataNavigationLinks(edmType, valuable.asLinkedComplex(), lcValue, metadataETag,
contextURL == null ? null : contextURL.getURI());
- odataAnnotations(valuable.getValue().asLinkedComplex(), lcValue);
+ odataAnnotations(valuable.asLinkedComplex(), lcValue);
value = lcValue;
} else {