You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ch...@apache.org on 2014/11/13 17:33:52 UTC
[6/8] olingo-odata4 git commit: [OLINGO-485] refactored server
serializers
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c2c8bf19/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/utils/ContextURLBuilderTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/utils/ContextURLBuilderTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/utils/ContextURLBuilderTest.java
index 8a7c9c6..0e8e8bd 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/utils/ContextURLBuilderTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/utils/ContextURLBuilderTest.java
@@ -119,9 +119,10 @@ public class ContextURLBuilderTest {
contextURL = ContextURL.with().serviceRoot(URI.create("http://host/service/"))
.entitySet(entitySet)
.keyPath("one=1,two='two'")
- .navOrPropertyPath("Name")
+ .navOrPropertyPath("ComplexName")
+ .selectList("Part1")
.build();
- assertEquals("http://host/service/$metadata#Customers(one=1,two='two')/Name",
+ assertEquals("http://host/service/$metadata#Customers(one=1,two='two')/ComplexName(Part1)",
ContextURLBuilder.create(contextURL).toASCIIString());
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c2c8bf19/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
index 34da317..971c50a 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
@@ -18,7 +18,6 @@
*/
package org.apache.olingo.server.tecsvc.processor;
-import java.io.ByteArrayInputStream;
import java.util.List;
import java.util.Locale;
@@ -37,8 +36,9 @@ import org.apache.olingo.server.api.ODataResponse;
import org.apache.olingo.server.api.processor.CountEntityCollectionProcessor;
import org.apache.olingo.server.api.processor.EntityCollectionProcessor;
import org.apache.olingo.server.api.processor.EntityProcessor;
+import org.apache.olingo.server.api.serializer.EntityCollectionSerializerOptions;
import org.apache.olingo.server.api.serializer.ODataSerializer;
-import org.apache.olingo.server.api.serializer.ODataSerializerOptions;
+import org.apache.olingo.server.api.serializer.EntitySerializerOptions;
import org.apache.olingo.server.api.serializer.SerializerException;
import org.apache.olingo.server.api.uri.UriInfo;
import org.apache.olingo.server.api.uri.UriResource;
@@ -76,8 +76,8 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
ODataSerializer serializer = odata.createSerializer(format);
final ExpandOption expand = uriInfo.getExpandOption();
final SelectOption select = uriInfo.getSelectOption();
- response.setContent(serializer.entitySet(edmEntitySet, entitySet,
- ODataSerializerOptions.with()
+ response.setContent(serializer.entityCollection(edmEntitySet.getEntityType(), entitySet,
+ EntityCollectionSerializerOptions.with()
.contextURL(format == ODataFormat.JSON_NO_METADATA ? null :
getContextUrl(serializer, edmEntitySet, false, expand, select))
.count(uriInfo.getCountOption())
@@ -103,7 +103,7 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
if (entitySet == null) {
throw new ODataApplicationException("Nothing found.", HttpStatusCode.NOT_FOUND.getStatusCode(), Locale.ROOT);
} else {
- response.setContent(new ByteArrayInputStream(entitySet.getCount().toString().getBytes()));
+ response.setContent(odata.createFixedFormatSerializer().count(entitySet.getCount()));
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, requestedContentType.toContentTypeString());
}
@@ -129,11 +129,10 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
ODataSerializer serializer = odata.createSerializer(format);
final ExpandOption expand = uriInfo.getExpandOption();
final SelectOption select = uriInfo.getSelectOption();
- response.setContent(serializer.entity(edmEntitySet, entity,
- ODataSerializerOptions.with()
+ response.setContent(serializer.entity(edmEntitySet.getEntityType(), entity,
+ EntitySerializerOptions.with()
.contextURL(format == ODataFormat.JSON_NO_METADATA ? null :
getContextUrl(serializer, edmEntitySet, true, expand, select))
- .count(uriInfo.getCountOption())
.expand(expand).select(select)
.build()));
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
@@ -155,7 +154,7 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
final EdmEntitySet entitySet, final boolean isSingleEntity,
final ExpandOption expand, final SelectOption select) throws SerializerException {
return ContextURL.with().entitySet(entitySet)
- .selectList(serializer.buildContextURLSelectList(entitySet, expand, select))
+ .selectList(serializer.buildContextURLSelectList(entitySet.getEntityType(), expand, select))
.suffix(isSingleEntity ? Suffix.ENTITY : null)
.build();
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c2c8bf19/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalPrimitiveComplexProcessor.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalPrimitiveComplexProcessor.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalPrimitiveComplexProcessor.java
index 037ffcb..09e9e8f 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalPrimitiveComplexProcessor.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalPrimitiveComplexProcessor.java
@@ -18,8 +18,6 @@
*/
package org.apache.olingo.server.tecsvc.processor;
-import java.io.ByteArrayInputStream;
-import java.io.UnsupportedEncodingException;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
@@ -27,11 +25,12 @@ import java.util.Locale;
import org.apache.olingo.commons.api.data.ContextURL;
import org.apache.olingo.commons.api.data.Entity;
import org.apache.olingo.commons.api.data.Property;
+import org.apache.olingo.commons.api.edm.EdmComplexType;
import org.apache.olingo.commons.api.edm.EdmEntitySet;
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.EdmProperty;
+import org.apache.olingo.commons.api.edm.EdmStructuredType;
import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.commons.api.http.HttpHeader;
@@ -44,8 +43,12 @@ import org.apache.olingo.server.api.processor.ComplexCollectionProcessor;
import org.apache.olingo.server.api.processor.ComplexProcessor;
import org.apache.olingo.server.api.processor.PrimitiveCollectionProcessor;
import org.apache.olingo.server.api.processor.PrimitiveProcessor;
+import org.apache.olingo.server.api.serializer.ComplexSerializerOptions;
+import org.apache.olingo.server.api.serializer.FixedFormatSerializer;
import org.apache.olingo.server.api.serializer.ODataSerializer;
-import org.apache.olingo.server.api.serializer.ODataSerializerOptions;
+import org.apache.olingo.server.api.serializer.PrimitiveSerializerOptions;
+import org.apache.olingo.server.api.serializer.PrimitiveValueSerializerOptions;
+import org.apache.olingo.server.api.serializer.RepresentationType;
import org.apache.olingo.server.api.serializer.SerializerException;
import org.apache.olingo.server.api.uri.UriInfo;
import org.apache.olingo.server.api.uri.UriInfoResource;
@@ -53,14 +56,15 @@ import org.apache.olingo.server.api.uri.UriResource;
import org.apache.olingo.server.api.uri.UriResourceEntitySet;
import org.apache.olingo.server.api.uri.UriResourceKind;
import org.apache.olingo.server.api.uri.UriResourceProperty;
+import org.apache.olingo.server.api.uri.queryoption.ExpandOption;
+import org.apache.olingo.server.api.uri.queryoption.SelectOption;
import org.apache.olingo.server.tecsvc.data.DataProvider;
/**
* Technical Processor which provides functionality related to primitive and complex types and collections thereof.
*/
public class TechnicalPrimitiveComplexProcessor extends TechnicalProcessor
- implements PrimitiveProcessor, PrimitiveCollectionProcessor,
- ComplexProcessor, ComplexCollectionProcessor {
+ implements PrimitiveProcessor, PrimitiveCollectionProcessor, ComplexProcessor, ComplexCollectionProcessor {
public TechnicalPrimitiveComplexProcessor(final DataProvider dataProvider) {
super(dataProvider);
@@ -69,29 +73,29 @@ public class TechnicalPrimitiveComplexProcessor extends TechnicalProcessor
@Override
public void readPrimitive(final ODataRequest request, ODataResponse response, final UriInfo uriInfo,
final ContentType contentType) throws ODataApplicationException, SerializerException {
- readProperty(response, uriInfo, contentType);
+ readProperty(response, uriInfo, contentType, RepresentationType.PRIMITIVE);
}
@Override
public void readPrimitiveCollection(final ODataRequest request, ODataResponse response, final UriInfo uriInfo,
final ContentType contentType) throws ODataApplicationException, SerializerException {
- readProperty(response, uriInfo, contentType);
+ readProperty(response, uriInfo, contentType, RepresentationType.COLLECTION_PRIMITIVE);
}
@Override
public void readComplex(final ODataRequest request, ODataResponse response, final UriInfo uriInfo,
final ContentType contentType) throws ODataApplicationException, SerializerException {
- readProperty(response, uriInfo, contentType);
+ readProperty(response, uriInfo, contentType, RepresentationType.COMPLEX);
}
@Override
public void readComplexCollection(final ODataRequest request, ODataResponse response, final UriInfo uriInfo,
final ContentType contentType) throws ODataApplicationException, SerializerException {
- readProperty(response, uriInfo, contentType);
+ readProperty(response, uriInfo, contentType, RepresentationType.COLLECTION_COMPLEX);
}
- private void readProperty(ODataResponse response, final UriInfo uriInfo, final ContentType contentType)
- throws ODataApplicationException, SerializerException {
+ private void readProperty(ODataResponse response, final UriInfo uriInfo, final ContentType contentType,
+ final RepresentationType representationType) throws ODataApplicationException, SerializerException {
final UriInfoResource resource = uriInfo.asUriInfoResource();
validateOptions(resource);
validatePath(resource);
@@ -113,14 +117,40 @@ public class TechnicalPrimitiveComplexProcessor extends TechnicalProcessor
final ODataFormat format = ODataFormat.fromContentType(contentType);
ODataSerializer serializer = odata.createSerializer(format);
- response.setContent(serializer.entityProperty(edmProperty, property,
- ODataSerializerOptions.with().contextURL(format == ODataFormat.JSON_NO_METADATA ? null :
- ContextURL.with().entitySet(edmEntitySet)
- .keyPath(serializer.buildContextURLKeyPredicate(
- ((UriResourceEntitySet) resourceParts.get(0)).getKeyPredicates()))
- .navOrPropertyPath(buildPropertyPath(path))
- .build())
- .build()));
+ final ExpandOption expand = uriInfo.getExpandOption();
+ final SelectOption select = uriInfo.getSelectOption();
+ final ContextURL contextURL = format == ODataFormat.JSON_NO_METADATA ? null :
+ ContextURL.with().entitySet(edmEntitySet)
+ .keyPath(serializer.buildContextURLKeyPredicate(
+ ((UriResourceEntitySet) resourceParts.get(0)).getKeyPredicates()))
+ .navOrPropertyPath(buildPropertyPath(path))
+ .selectList(edmProperty.isPrimitive() ? null :
+ serializer.buildContextURLSelectList((EdmStructuredType) edmProperty.getType(), expand, select))
+ .build();
+ switch (representationType) {
+ case PRIMITIVE:
+ response.setContent(serializer.primitive((EdmPrimitiveType) edmProperty.getType(), property,
+ PrimitiveSerializerOptions.with().contextURL(contextURL).facetsFrom(edmProperty).build()));
+ break;
+ case COMPLEX:
+ response.setContent(serializer.complex((EdmComplexType) edmProperty.getType(), property,
+ ComplexSerializerOptions.with().contextURL(contextURL)
+ .expand(expand).select(select)
+ .build()));
+ break;
+ case COLLECTION_PRIMITIVE:
+ response.setContent(serializer.primitiveCollection((EdmPrimitiveType) edmProperty.getType(), property,
+ PrimitiveSerializerOptions.with().contextURL(contextURL).facetsFrom(edmProperty).build()));
+ break;
+ case COLLECTION_COMPLEX:
+ response.setContent(serializer.complexCollection((EdmComplexType) edmProperty.getType(), property,
+ ComplexSerializerOptions.with().contextURL(contextURL)
+ .expand(expand).select(select)
+ .build()));
+ break;
+ default:
+ break;
+ }
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, contentType.toContentTypeString());
}
@@ -187,22 +217,11 @@ public class TechnicalPrimitiveComplexProcessor extends TechnicalProcessor
} else {
final EdmProperty edmProperty = ((UriResourceProperty) resourceParts.get(path.size())).getProperty();
final EdmPrimitiveType type = (EdmPrimitiveType) edmProperty.getType();
- if (type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Binary)) {
- response.setContent(new ByteArrayInputStream((byte[]) property.getValue()));
- } else {
- try {
- final String value = type.valueToString(property.getValue(),
- edmProperty.isNullable(), edmProperty.getMaxLength(),
- edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode());
- response.setContent(new ByteArrayInputStream(value.getBytes("UTF-8")));
- } catch (final EdmPrimitiveTypeException e) {
- throw new ODataApplicationException("Error in value formatting.",
- HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.ROOT, e);
- } catch (final UnsupportedEncodingException e) {
- throw new ODataApplicationException("Encoding exception.",
- HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.ROOT, e);
- }
- }
+ final FixedFormatSerializer serializer = odata.createFixedFormatSerializer();
+ response.setContent(type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Binary) ?
+ serializer.binary((byte[]) property.getValue()) :
+ serializer.primitiveValue(type, property.getValue(),
+ PrimitiveValueSerializerOptions.with().facetsFrom(edmProperty).build()));
response.setHeader(HttpHeader.CONTENT_TYPE, contentType.toContentTypeString());
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c2c8bf19/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
index fc65245..f0801d8 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
@@ -31,16 +31,22 @@ import org.apache.olingo.commons.api.data.EntitySet;
import org.apache.olingo.commons.api.data.Property;
import org.apache.olingo.commons.api.data.ValueType;
import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmComplexType;
import org.apache.olingo.commons.api.edm.EdmEntityContainer;
import org.apache.olingo.commons.api.edm.EdmEntitySet;
+import org.apache.olingo.commons.api.edm.EdmEntityType;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
import org.apache.olingo.commons.api.edm.EdmProperty;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.commons.core.data.PropertyImpl;
import org.apache.olingo.server.api.OData;
import org.apache.olingo.server.api.edmx.EdmxReference;
+import org.apache.olingo.server.api.serializer.ComplexSerializerOptions;
+import org.apache.olingo.server.api.serializer.EntityCollectionSerializerOptions;
import org.apache.olingo.server.api.serializer.ODataSerializer;
-import org.apache.olingo.server.api.serializer.ODataSerializerOptions;
+import org.apache.olingo.server.api.serializer.EntitySerializerOptions;
+import org.apache.olingo.server.api.serializer.PrimitiveSerializerOptions;
import org.apache.olingo.server.api.serializer.SerializerException;
import org.apache.olingo.server.api.uri.queryoption.CountOption;
import org.apache.olingo.server.api.uri.queryoption.ExpandItem;
@@ -58,7 +64,7 @@ import org.mockito.Mockito;
public class ODataJsonSerializerTest {
private static final Edm edm = OData.newInstance().createServiceMetadata(
- new EdmTechProvider(), Collections.<EdmxReference>emptyList()).getEdm();
+ new EdmTechProvider(), Collections.<EdmxReference> emptyList()).getEdm();
private static final EdmEntityContainer entityContainer = edm.getEntityContainer(
new FullQualifiedName("olingo.odata.test1", "Container"));
private final DataProvider data = new DataProvider();
@@ -68,8 +74,8 @@ public class ODataJsonSerializerTest {
public void entitySimple() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim");
final Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
- InputStream result = serializer.entity(edmEntitySet, entity,
- ODataSerializerOptions.with()
+ InputStream result = serializer.entity(edmEntitySet.getEntityType(), entity,
+ EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
.build());
final String resultString = IOUtils.toString(result);
@@ -100,8 +106,8 @@ public class ODataJsonSerializerTest {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim");
Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
entity.getProperties().retainAll(Arrays.asList(entity.getProperties().get(0)));
- final String resultString = IOUtils.toString(serializer.entity(edmEntitySet, entity,
- ODataSerializerOptions.with()
+ final String resultString = IOUtils.toString(serializer.entity(edmEntitySet.getEntityType(), entity,
+ EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
.build()));
final String expectedResult = "{\"@odata.context\":\"$metadata#ESAllPrim/$entity\","
@@ -121,8 +127,8 @@ public class ODataJsonSerializerTest {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim");
Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
entity.getProperties().clear();
- serializer.entity(edmEntitySet, entity,
- ODataSerializerOptions.with()
+ serializer.entity(edmEntitySet.getEntityType(), entity,
+ EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
.build());
}
@@ -133,8 +139,8 @@ public class ODataJsonSerializerTest {
Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
entity.getProperties().get(0).setValue(ValueType.PRIMITIVE, false);
try {
- serializer.entity(edmEntitySet, entity,
- ODataSerializerOptions.with()
+ serializer.entity(edmEntitySet.getEntityType(), entity,
+ EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
.build());
Assert.fail("Expected exception not thrown!");
@@ -154,8 +160,8 @@ public class ODataJsonSerializerTest {
entitySet.setNext(URI.create("/next"));
CountOption countOption = Mockito.mock(CountOption.class);
Mockito.when(countOption.getValue()).thenReturn(true);
- InputStream result = serializer.entitySet(edmEntitySet, entitySet,
- ODataSerializerOptions.with()
+ InputStream result = serializer.entityCollection(edmEntitySet.getEntityType(), entitySet,
+ EntityCollectionSerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).build())
.count(countOption)
.build());
@@ -179,8 +185,8 @@ public class ODataJsonSerializerTest {
public void entityCollAllPrim() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESCollAllPrim");
final Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
- InputStream result = serializer.entity(edmEntitySet, entity,
- ODataSerializerOptions.with()
+ InputStream result = serializer.entity(edmEntitySet.getEntityType(), entity,
+ EntitySerializerOptions.with()
.contextURL(ContextURL.with().serviceRoot(URI.create("http://host/service/"))
.entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
.build());
@@ -215,8 +221,8 @@ public class ODataJsonSerializerTest {
public void entityCompAllPrim() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESCompAllPrim");
final Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
- InputStream result = serializer.entity(edmEntitySet, entity,
- ODataSerializerOptions.with()
+ InputStream result = serializer.entity(edmEntitySet.getEntityType(), entity,
+ EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
.build());
final String resultString = IOUtils.toString(result);
@@ -248,8 +254,8 @@ public class ODataJsonSerializerTest {
public void entityMixPrimCollComp() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMixPrimCollComp");
final Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
- InputStream result = serializer.entity(edmEntitySet, entity,
- ODataSerializerOptions.with()
+ InputStream result = serializer.entity(edmEntitySet.getEntityType(), entity,
+ EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
.build());
final String resultString = IOUtils.toString(result);
@@ -271,8 +277,8 @@ public class ODataJsonSerializerTest {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMixPrimCollComp");
Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
entity.getProperties().retainAll(Arrays.asList(entity.getProperties().get(0)));
- final String resultString = IOUtils.toString(serializer.entity(edmEntitySet, entity,
- ODataSerializerOptions.with()
+ final String resultString = IOUtils.toString(serializer.entity(edmEntitySet.getEntityType(), entity,
+ EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
.build()));
final String expectedResult = "{\"@odata.context\":\"$metadata#ESMixPrimCollComp/$entity\","
@@ -286,7 +292,7 @@ public class ODataJsonSerializerTest {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESTwoPrim");
final Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
InputStream result = new ODataJsonSerializer(ODataFormat.JSON_NO_METADATA)
- .entity(edmEntitySet, entity, null);
+ .entity(edmEntitySet.getEntityType(), entity, null);
final String resultString = IOUtils.toString(result);
final String expectedResult = "{\"PropertyInt16\":32766,\"PropertyString\":\"Test String1\"}";
Assert.assertEquals(expectedResult, resultString);
@@ -297,8 +303,8 @@ public class ODataJsonSerializerTest {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESTwoPrim");
final EntitySet entitySet = data.readAll(edmEntitySet);
InputStream result = new ODataJsonSerializer(ODataFormat.JSON_NO_METADATA)
- .entitySet(edmEntitySet, entitySet,
- ODataSerializerOptions.with()
+ .entityCollection(edmEntitySet.getEntityType(), entitySet,
+ EntityCollectionSerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).build()).build());
final String resultString = IOUtils.toString(result);
final String expectedResult = "{\"value\":["
@@ -314,8 +320,8 @@ public class ODataJsonSerializerTest {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMedia");
Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
entity.setMediaETag("theMediaETag");
- final String resultString = IOUtils.toString(serializer.entity(edmEntitySet, entity,
- ODataSerializerOptions.with()
+ final String resultString = IOUtils.toString(serializer.entity(edmEntitySet.getEntityType(), entity,
+ EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
.build()));
final String expectedResult = "{\"@odata.context\":\"$metadata#ESMedia/$entity\","
@@ -328,8 +334,8 @@ public class ODataJsonSerializerTest {
public void entitySetMedia() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMedia");
final EntitySet entitySet = data.readAll(edmEntitySet);
- final String resultString = IOUtils.toString(serializer.entitySet(edmEntitySet, entitySet,
- ODataSerializerOptions.with()
+ final String resultString = IOUtils.toString(serializer.entityCollection(edmEntitySet.getEntityType(), entitySet,
+ EntityCollectionSerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).build()).build()));
final String expectedResult = "{\"@odata.context\":\"$metadata#ESMedia\",\"value\":["
+ "{\"@odata.mediaContentType\":\"image/png\",\"PropertyInt16\":1},"
@@ -342,16 +348,17 @@ public class ODataJsonSerializerTest {
@Test
public void select() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim");
+ final EdmEntityType entityType = edmEntitySet.getEntityType();
final Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
final SelectItem selectItem1 = ExpandSelectMock.mockSelectItem(edmEntitySet, "PropertyDate");
final SelectItem selectItem2 = ExpandSelectMock.mockSelectItem(edmEntitySet, "PropertyBoolean");
final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(
selectItem1, selectItem2, selectItem2));
InputStream result = serializer
- .entity(edmEntitySet, entity,
- ODataSerializerOptions.with()
+ .entity(entityType, entity,
+ EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet)
- .selectList(serializer.buildContextURLSelectList(edmEntitySet, null, select))
+ .selectList(serializer.buildContextURLSelectList(entityType, null, select))
.suffix(Suffix.ENTITY).build())
.select(select)
.build());
@@ -370,8 +377,8 @@ public class ODataJsonSerializerTest {
SelectItem selectItem2 = Mockito.mock(SelectItem.class);
Mockito.when(selectItem2.isStar()).thenReturn(true);
final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(selectItem1, selectItem2));
- InputStream result = serializer.entity(edmEntitySet, entity,
- ODataSerializerOptions.with()
+ InputStream result = serializer.entity(edmEntitySet.getEntityType(), entity,
+ EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
.select(select)
.build());
@@ -384,14 +391,15 @@ public class ODataJsonSerializerTest {
@Test
public void selectComplex() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESCompComp");
+ final EdmEntityType entityType = edmEntitySet.getEntityType();
final EntitySet entitySet = data.readAll(edmEntitySet);
final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(
ExpandSelectMock.mockSelectItem(edmEntitySet, "PropertyComp", "PropertyComp", "PropertyString")));
InputStream result = serializer
- .entitySet(edmEntitySet, entitySet,
- ODataSerializerOptions.with()
+ .entityCollection(entityType, entitySet,
+ EntityCollectionSerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet)
- .selectList(serializer.buildContextURLSelectList(edmEntitySet, null, select))
+ .selectList(serializer.buildContextURLSelectList(entityType, null, select))
.build())
.select(select)
.build());
@@ -407,15 +415,16 @@ public class ODataJsonSerializerTest {
@Test
public void selectComplexTwice() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESCompComp");
+ final EdmEntityType entityType = edmEntitySet.getEntityType();
final EntitySet entitySet = data.readAll(edmEntitySet);
final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(
ExpandSelectMock.mockSelectItem(edmEntitySet, "PropertyComp", "PropertyComp", "PropertyString"),
ExpandSelectMock.mockSelectItem(edmEntitySet, "PropertyComp", "PropertyComp")));
final String resultString = IOUtils.toString(serializer
- .entitySet(edmEntitySet, entitySet,
- ODataSerializerOptions.with()
+ .entityCollection(entityType, entitySet,
+ EntityCollectionSerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet)
- .selectList(serializer.buildContextURLSelectList(edmEntitySet, null, select))
+ .selectList(serializer.buildContextURLSelectList(entityType, null, select))
.build())
.select(select)
.build()));
@@ -433,8 +442,8 @@ public class ODataJsonSerializerTest {
final Entity entity = data.readAll(edmEntitySet).getEntities().get(3);
final ExpandOption expand = ExpandSelectMock.mockExpandOption(Arrays.asList(
ExpandSelectMock.mockExpandItem(edmEntitySet, "NavPropertyETAllPrimOne")));
- InputStream result = serializer.entity(edmEntitySet, entity,
- ODataSerializerOptions.with()
+ InputStream result = serializer.entity(edmEntitySet.getEntityType(), entity,
+ EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
.expand(expand)
.build());
@@ -464,6 +473,7 @@ public class ODataJsonSerializerTest {
@Test
public void expandSelect() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESTwoPrim");
+ final EdmEntityType entityType = edmEntitySet.getEntityType();
final Entity entity = data.readAll(edmEntitySet).getEntities().get(3);
final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(
ExpandSelectMock.mockSelectItem(entityContainer.getEntitySet("ESAllPrim"), "PropertyDate")));
@@ -471,10 +481,10 @@ public class ODataJsonSerializerTest {
Mockito.when(expandItem.getSelectOption()).thenReturn(select);
final ExpandOption expand = ExpandSelectMock.mockExpandOption(Arrays.asList(expandItem));
final String resultString = IOUtils.toString(serializer
- .entity(edmEntitySet, entity,
- ODataSerializerOptions.with()
+ .entity(entityType, entity,
+ EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet)
- .selectList(serializer.buildContextURLSelectList(edmEntitySet, expand, select))
+ .selectList(serializer.buildContextURLSelectList(entityType, expand, select))
.suffix(Suffix.ENTITY).build())
.expand(expand)
.build()));
@@ -488,6 +498,7 @@ public class ODataJsonSerializerTest {
@Test
public void expandAll() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim");
+ final EdmEntityType entityType = edmEntitySet.getEntityType();
final Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
final ExpandItem expandItem = ExpandSelectMock.mockExpandItem(edmEntitySet, "NavPropertyETTwoPrimOne");
ExpandItem expandItemAll = Mockito.mock(ExpandItem.class);
@@ -497,10 +508,10 @@ public class ODataJsonSerializerTest {
final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(
ExpandSelectMock.mockSelectItem(edmEntitySet, "PropertySByte")));
final String resultString = IOUtils.toString(serializer
- .entity(edmEntitySet, entity,
- ODataSerializerOptions.with()
+ .entity(entityType, entity,
+ EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet)
- .selectList(serializer.buildContextURLSelectList(edmEntitySet, expand, select))
+ .selectList(serializer.buildContextURLSelectList(entityType, expand, select))
.suffix(Suffix.ENTITY).build())
.expand(expand)
.select(select)
@@ -516,6 +527,7 @@ public class ODataJsonSerializerTest {
@Test
public void expandNoData() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim");
+ final EdmEntityType entityType = edmEntitySet.getEntityType();
final Entity entity = data.readAll(edmEntitySet).getEntities().get(1);
ExpandItem expandItemAll = Mockito.mock(ExpandItem.class);
Mockito.when(expandItemAll.isStar()).thenReturn(true);
@@ -523,10 +535,10 @@ public class ODataJsonSerializerTest {
final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(
ExpandSelectMock.mockSelectItem(edmEntitySet, "PropertyTimeOfDay")));
final String resultString = IOUtils.toString(serializer
- .entity(edmEntitySet, entity,
- ODataSerializerOptions.with()
+ .entity(entityType, entity,
+ EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet)
- .selectList(serializer.buildContextURLSelectList(edmEntitySet, expand, select))
+ .selectList(serializer.buildContextURLSelectList(entityType, expand, select))
.suffix(Suffix.ENTITY).build())
.expand(expand)
.select(select)
@@ -541,6 +553,7 @@ public class ODataJsonSerializerTest {
@Test
public void expandTwoLevels() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESTwoPrim");
+ final EdmEntityType entityType = edmEntitySet.getEntityType();
final EdmEntitySet innerEntitySet = entityContainer.getEntitySet("ESAllPrim");
final Entity entity = data.readAll(edmEntitySet).getEntities().get(1);
ExpandItem expandItemSecond = Mockito.mock(ExpandItem.class);
@@ -553,10 +566,10 @@ public class ODataJsonSerializerTest {
Mockito.when(expandItemFirst.getSelectOption()).thenReturn(select);
final ExpandOption expand = ExpandSelectMock.mockExpandOption(Arrays.asList(expandItemFirst));
final String resultString = IOUtils.toString(serializer
- .entity(edmEntitySet, entity,
- ODataSerializerOptions.with()
+ .entity(entityType, entity,
+ EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet)
- .selectList(serializer.buildContextURLSelectList(edmEntitySet, expand, select))
+ .selectList(serializer.buildContextURLSelectList(entityType, expand, select))
.suffix(Suffix.ENTITY).build())
.expand(expand)
.build()));
@@ -579,8 +592,8 @@ public class ODataJsonSerializerTest {
final EdmProperty edmProperty = (EdmProperty) edmEntitySet.getEntityType().getProperty("PropertyString");
final Property property = data.readAll(edmEntitySet).getEntities().get(0).getProperty(edmProperty.getName());
final String resultString = IOUtils.toString(serializer
- .entityProperty(edmProperty, property,
- ODataSerializerOptions.with()
+ .primitive((EdmPrimitiveType) edmProperty.getType(), property,
+ PrimitiveSerializerOptions.with()
.contextURL(ContextURL.with()
.entitySet(edmEntitySet).keyPath("32767").navOrPropertyPath(edmProperty.getName())
.build())
@@ -596,8 +609,8 @@ public class ODataJsonSerializerTest {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim");
final EdmProperty edmProperty = (EdmProperty) edmEntitySet.getEntityType().getProperty("PropertyString");
final Property property = new PropertyImpl("Edm.String", edmProperty.getName(), ValueType.PRIMITIVE, null);
- serializer.entityProperty(edmProperty, property,
- ODataSerializerOptions.with()
+ serializer.primitive((EdmPrimitiveType) edmProperty.getType(), property,
+ PrimitiveSerializerOptions.with()
.contextURL(ContextURL.with()
.entitySet(edmEntitySet).keyPath("4242").navOrPropertyPath(edmProperty.getName())
.build())
@@ -611,8 +624,8 @@ public class ODataJsonSerializerTest {
final Property property = data.readAll(edmEntitySet).getEntities().get(0).getProperty(edmProperty.getName());
final String resultString = IOUtils.toString(serializer
- .entityProperty(edmProperty, property,
- ODataSerializerOptions.with()
+ .primitiveCollection((EdmPrimitiveType) edmProperty.getType(), property,
+ PrimitiveSerializerOptions.with()
.contextURL(ContextURL.with()
.entitySet(edmEntitySet).keyPath("1").navOrPropertyPath(edmProperty.getName())
.build())
@@ -630,8 +643,8 @@ public class ODataJsonSerializerTest {
final Property property = data.readAll(edmEntitySet).getEntities().get(0).getProperty("PropertyComp");
final String resultString = IOUtils.toString(serializer
- .entityProperty(edmProperty, property,
- ODataSerializerOptions.with()
+ .complex((EdmComplexType) edmProperty.getType(), property,
+ ComplexSerializerOptions.with()
.contextURL(ContextURL.with()
.entitySet(edmEntitySet).keyPath("32767").navOrPropertyPath(edmProperty.getName())
.build())
@@ -641,4 +654,25 @@ public class ODataJsonSerializerTest {
+ "\"PropertyInt16\":111,\"PropertyString\":\"TEST A\"}",
resultString);
}
+
+ @Test
+ public void complexCollectionProperty() throws Exception {
+ final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMixPrimCollComp");
+ final EdmProperty edmProperty = (EdmProperty) edmEntitySet.getEntityType().getProperty("CollPropertyComp");
+ final Property property = data.readAll(edmEntitySet).getEntities().get(0).getProperty(edmProperty.getName());
+
+ final String resultString = IOUtils.toString(serializer
+ .complexCollection((EdmComplexType) edmProperty.getType(), property,
+ ComplexSerializerOptions.with()
+ .contextURL(ContextURL.with()
+ .entitySet(edmEntitySet).keyPath("32767").navOrPropertyPath(edmProperty.getName())
+ .build())
+ .build()));
+ Assert.assertEquals("{"
+ + "\"@odata.context\":\"$metadata#ESMixPrimCollComp(32767)/CollPropertyComp\","
+ + "\"value\":[{\"PropertyInt16\":123,\"PropertyString\":\"TEST 1\"},"
+ + "{\"PropertyInt16\":456,\"PropertyString\":\"TEST 2\"},"
+ + "{\"PropertyInt16\":789,\"PropertyString\":\"TEST 3\"}]}",
+ resultString);
+ }
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c2c8bf19/samples/server/src/main/java/org/apache/olingo/server/sample/data/DataProvider.java
----------------------------------------------------------------------
diff --git a/samples/server/src/main/java/org/apache/olingo/server/sample/data/DataProvider.java b/samples/server/src/main/java/org/apache/olingo/server/sample/data/DataProvider.java
index 80609aa..d59d251 100644
--- a/samples/server/src/main/java/org/apache/olingo/server/sample/data/DataProvider.java
+++ b/samples/server/src/main/java/org/apache/olingo/server/sample/data/DataProvider.java
@@ -22,7 +22,6 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.UUID;
import org.apache.olingo.commons.api.ODataException;
import org.apache.olingo.commons.api.data.Entity;
@@ -41,8 +40,6 @@ import org.apache.olingo.server.api.uri.UriParameter;
public class DataProvider {
- private static final UUID GUID = UUID.fromString("01234567-89ab-cdef-0123-456789abcdef");
-
private Map<String, EntitySet> data;
public DataProvider() {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c2c8bf19/samples/server/src/main/java/org/apache/olingo/server/sample/processor/CarsProcessor.java
----------------------------------------------------------------------
diff --git a/samples/server/src/main/java/org/apache/olingo/server/sample/processor/CarsProcessor.java b/samples/server/src/main/java/org/apache/olingo/server/sample/processor/CarsProcessor.java
index bf3aa17..5cfce31 100644
--- a/samples/server/src/main/java/org/apache/olingo/server/sample/processor/CarsProcessor.java
+++ b/samples/server/src/main/java/org/apache/olingo/server/sample/processor/CarsProcessor.java
@@ -27,7 +27,9 @@ import org.apache.olingo.commons.api.data.ContextURL.Suffix;
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.edm.EdmComplexType;
import org.apache.olingo.commons.api.edm.EdmEntitySet;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
import org.apache.olingo.commons.api.edm.EdmProperty;
import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.commons.api.format.ODataFormat;
@@ -38,14 +40,15 @@ import org.apache.olingo.server.api.ODataApplicationException;
import org.apache.olingo.server.api.ODataRequest;
import org.apache.olingo.server.api.ODataResponse;
import org.apache.olingo.server.api.ServiceMetadata;
-import org.apache.olingo.server.api.processor.ComplexCollectionProcessor;
import org.apache.olingo.server.api.processor.ComplexProcessor;
import org.apache.olingo.server.api.processor.EntityCollectionProcessor;
import org.apache.olingo.server.api.processor.EntityProcessor;
-import org.apache.olingo.server.api.processor.PrimitiveCollectionProcessor;
import org.apache.olingo.server.api.processor.PrimitiveProcessor;
+import org.apache.olingo.server.api.serializer.ComplexSerializerOptions;
+import org.apache.olingo.server.api.serializer.EntityCollectionSerializerOptions;
+import org.apache.olingo.server.api.serializer.EntitySerializerOptions;
import org.apache.olingo.server.api.serializer.ODataSerializer;
-import org.apache.olingo.server.api.serializer.ODataSerializerOptions;
+import org.apache.olingo.server.api.serializer.PrimitiveSerializerOptions;
import org.apache.olingo.server.api.serializer.SerializerException;
import org.apache.olingo.server.api.uri.UriInfo;
import org.apache.olingo.server.api.uri.UriInfoResource;
@@ -62,8 +65,8 @@ import org.apache.olingo.server.sample.data.DataProvider.DataProviderException;
* This is a very simple example which should give you a rough guideline on how to implement such an processor.
* See the JavaDoc of the server.api interfaces for more information.
*/
-public class CarsProcessor implements EntityCollectionProcessor, EntityProcessor, PrimitiveProcessor,
- PrimitiveCollectionProcessor, ComplexProcessor, ComplexCollectionProcessor {
+public class CarsProcessor implements EntityCollectionProcessor, EntityProcessor,
+ PrimitiveProcessor, ComplexProcessor {
private OData odata;
private DataProvider dataProvider;
@@ -97,8 +100,8 @@ public class CarsProcessor implements EntityCollectionProcessor, EntityProcessor
// Now the content is serialized using the serializer.
final ExpandOption expand = uriInfo.getExpandOption();
final SelectOption select = uriInfo.getSelectOption();
- InputStream serializedContent = serializer.entitySet(edmEntitySet, entitySet,
- ODataSerializerOptions.with()
+ InputStream serializedContent = serializer.entityCollection(edmEntitySet.getEntityType(), entitySet,
+ EntityCollectionSerializerOptions.with()
.contextURL(format == ODataFormat.JSON_NO_METADATA ? null :
getContextUrl(serializer, edmEntitySet, false, expand, select, null))
.count(uriInfo.getCountOption())
@@ -135,11 +138,10 @@ public class CarsProcessor implements EntityCollectionProcessor, EntityProcessor
ODataSerializer serializer = odata.createSerializer(format);
final ExpandOption expand = uriInfo.getExpandOption();
final SelectOption select = uriInfo.getSelectOption();
- InputStream serializedContent = serializer.entity(edmEntitySet, entity,
- ODataSerializerOptions.with()
+ InputStream serializedContent = serializer.entity(edmEntitySet.getEntityType(), entity,
+ EntitySerializerOptions.with()
.contextURL(format == ODataFormat.JSON_NO_METADATA ? null :
getContextUrl(serializer, edmEntitySet, true, expand, select, null))
- .count(uriInfo.getCountOption())
.expand(expand).select(select)
.build());
response.setContent(serializedContent);
@@ -148,8 +150,8 @@ public class CarsProcessor implements EntityCollectionProcessor, EntityProcessor
}
}
- private void readProperty(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType contentType)
- throws ODataApplicationException, SerializerException {
+ private void readProperty(ODataResponse response, UriInfo uriInfo, ContentType contentType,
+ boolean complex) throws ODataApplicationException, SerializerException {
// To read a property we have to first get the entity out of the entity set
final EdmEntitySet edmEntitySet = getEdmEntitySet(uriInfo.asUriInfoResource());
Entity entity;
@@ -178,11 +180,13 @@ public class CarsProcessor implements EntityCollectionProcessor, EntityProcessor
} else {
final ODataFormat format = ODataFormat.fromContentType(contentType);
ODataSerializer serializer = odata.createSerializer(format);
- InputStream serializerContent = serializer.entityProperty(edmProperty, property,
- ODataSerializerOptions.with()
- .contextURL(format == ODataFormat.JSON_NO_METADATA ? null :
- getContextUrl(serializer, edmEntitySet, true, null, null, edmProperty.getName()))
- .build());
+ final ContextURL contextURL = format == ODataFormat.JSON_NO_METADATA ? null :
+ getContextUrl(serializer, edmEntitySet, true, null, null, edmProperty.getName());
+ InputStream serializerContent = complex ?
+ serializer.complex((EdmComplexType) edmProperty.getType(), property,
+ ComplexSerializerOptions.with().contextURL(contextURL).build()) :
+ serializer.primitive((EdmPrimitiveType) edmProperty.getType(), property,
+ PrimitiveSerializerOptions.with().contextURL(contextURL).build());
response.setContent(serializerContent);
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, contentType.toContentTypeString());
@@ -222,41 +226,28 @@ public class CarsProcessor implements EntityCollectionProcessor, EntityProcessor
throws SerializerException {
return ContextURL.with().entitySet(entitySet)
- .selectList(serializer.buildContextURLSelectList(entitySet, expand, select))
+ .selectList(serializer.buildContextURLSelectList(entitySet.getEntityType(), expand, select))
.suffix(isSingleEntity ? Suffix.ENTITY : null)
.navOrPropertyPath(navOrPropertyPath)
.build();
}
@Override
- public void readComplexCollection(ODataRequest request, ODataResponse response, UriInfo uriInfo,
- ContentType format) throws ODataApplicationException, SerializerException {
- readProperty(request, response, uriInfo, format);
+ public void readPrimitive(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType format)
+ throws ODataApplicationException, SerializerException {
+ readProperty(response, uriInfo, format, false);
}
@Override
public void readComplex(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType format)
throws ODataApplicationException, SerializerException {
- readProperty(request, response, uriInfo, format);
- }
-
- @Override
- public void readPrimitiveCollection(ODataRequest request, ODataResponse response, UriInfo uriInfo,
- ContentType format) throws ODataApplicationException, SerializerException {
- readProperty(request, response, uriInfo, format);
+ readProperty(response, uriInfo, format, true);
}
@Override
- public void readPrimitive(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType format)
+ public void readPrimitiveAsValue(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType format)
throws ODataApplicationException, SerializerException {
- readProperty(request, response, uriInfo, format);
- }
-
- @Override
- public void
- readPrimitiveAsValue(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType format)
- throws ODataApplicationException, SerializerException {
- throw new ODataApplicationException("Not implemented for this sample", HttpStatusCode.NOT_IMPLEMENTED
- .getStatusCode(), Locale.ENGLISH);
+ throw new ODataApplicationException("Not implemented for this sample",
+ HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ENGLISH);
}
}