You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ra...@apache.org on 2015/04/20 16:28:22 UTC
[02/22] olingo-odata4 git commit: [OLINGO-617] Derserializer and
Serializer result refactoring, ExpandBuilder
[OLINGO-617] Derserializer and Serializer result refactoring, ExpandBuilder
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/502f7ced
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/502f7ced
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/502f7ced
Branch: refs/heads/OLINGO-573
Commit: 502f7cedee18749ab92fd55b700cf64b75a11a16
Parents: 61b0daa
Author: Christian Holzer <c....@sap.com>
Authored: Thu Apr 2 14:55:51 2015 +0200
Committer: Christian Holzer <ch...@t-online.de>
Committed: Fri Apr 3 12:41:55 2015 +0200
----------------------------------------------------------------------
.../fit/tecsvc/client/DeepInsertITCase.java | 132 ++++++++++++++++++-
.../api/deserializer/DeserializerResult.java | 69 ++++++++++
.../api/deserializer/ODataDeserializer.java | 25 ++--
.../server/api/processor/DefaultProcessor.java | 6 +-
.../server/api/serializer/ODataSerializer.java | 18 +--
.../server/api/serializer/SerializerResult.java | 32 +++++
.../apache/olingo/server/core/ErrorHandler.java | 2 +-
.../server/core/requests/DataRequest.java | 6 +-
.../server/core/responses/EntityResponse.java | 4 +-
.../core/responses/EntitySetResponse.java | 3 +-
.../server/core/responses/MetadataResponse.java | 2 +-
.../server/core/responses/PropertyResponse.java | 8 +-
.../core/responses/ServiceDocumentResponse.java | 2 +-
.../olingo/server/example/TripPinDataModel.java | 2 +-
.../deserializer/DeserializerResultImpl.java | 126 ++++++++++++++++++
.../deserializer/helper/ExpandTreeBuilder.java | 40 ++++++
.../helper/ExpandTreeBuilderImpl.java | 67 ++++++++++
.../json/ODataJsonDeserializer.java | 66 ++++++----
.../core/serializer/SerializerResultImpl.java | 53 ++++++++
.../serializer/json/ODataJsonSerializer.java | 37 +++---
.../serializer/xml/ODataXmlSerializerImpl.java | 24 ++--
.../json/ODataJsonDeserializerBasicTest.java | 5 +-
.../json/ODataErrorSerializerTest.java | 14 +-
.../json/ODataJsonSerializerTest.java | 2 +-
.../xml/MetadataDocumentXmlSerializerTest.java | 10 +-
.../processor/TechnicalEntityProcessor.java | 18 ++-
.../TechnicalPrimitiveComplexProcessor.java | 8 +-
.../json/ODataDeserializerDeepInsertTest.java | 8 +-
.../ODataDeserializerEntityCollectionTest.java | 9 +-
...ataJsonDeserializerActionParametersTest.java | 4 +-
.../json/ODataJsonDeserializerEntityTest.java | 56 +++++---
.../json/ODataJsonSerializerTest.java | 48 +++----
.../serializer/json/ServiceDocumentTest.java | 2 +-
.../serializer/xml/MetadataDocumentTest.java | 2 +-
.../server/sample/processor/CarsProcessor.java | 8 +-
35 files changed, 732 insertions(+), 186 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/DeepInsertITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/DeepInsertITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/DeepInsertITCase.java
index 4e15ca0..ba33e3f 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/DeepInsertITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/DeepInsertITCase.java
@@ -24,6 +24,7 @@ import static org.junit.Assert.assertNotNull;
import java.net.URI;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.LinkedHashMap;
import java.util.Map;
import org.apache.olingo.client.api.ODataClient;
@@ -45,7 +46,6 @@ import org.apache.olingo.commons.api.http.HttpHeader;
import org.apache.olingo.commons.api.http.HttpStatusCode;
import org.apache.olingo.fit.AbstractBaseTestITCase;
import org.apache.olingo.fit.tecsvc.TecSvcConst;
-import org.junit.AfterClass;
import org.junit.Test;
public class DeepInsertITCase extends AbstractBaseTestITCase {
@@ -72,11 +72,133 @@ public class DeepInsertITCase extends AbstractBaseTestITCase {
private static final String NAV_PROPERTY_ET_TWO_KEY_NAV_ONE = "NavPropertyETTwoKeyNavOne";
private static final String NAV_PROPERTY_ET_TWO_KEY_NAV_MANY = "NavPropertyETTwoKeyNavMany";
- @AfterClass
- public static void tearDownAfterClass() throws Exception {
- //Nothing needed here.
- }
+ @Test
+ public void testDeepInsertExpandedResponse() {
+ final ODataClient client = ODataClientFactory.getEdmEnabledClient(SERVICE_URI);
+ client.getConfiguration().setDefaultPubFormat(ODataFormat.JSON);
+ final URI createURI = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).build();
+ final ODataObjectFactory of = client.getObjectFactory();
+ final ODataEntity entity = of.newEntity(ET_KEY_NAV);
+
+ // Root entity
+ entity.getProperties().add(
+ of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("String Property level 0")));
+ entity.getProperties().add(
+ of.newComplexProperty(PROPERTY_COMP_TWO_PRIM, of.newComplexValue(CT_TWO_PRIM)
+ .add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 41)))
+ .add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString(
+ "String Property level 0, complex level 1")))));
+
+ // First level NavPropertyETTwoKeyNavOne => Type ETTwoKeyNav
+ final ODataEntity firstLevelTwoKeyNav = of.newEntity(ET_TWO_KEY_NAV);
+ firstLevelTwoKeyNav.getProperties().add(
+ of.newComplexProperty(PROPERTY_COMP_TWO_PRIM, of.newComplexValue(CT_TWO_PRIM)
+ .add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 42)))
+ .add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString(
+ "String Property level 1, complex level 1")))));
+ final ODataInlineEntity firstLevelTwoKeyOneInline =
+ of.newDeepInsertEntity(NAV_PROPERTY_ET_TWO_KEY_NAV_ONE, firstLevelTwoKeyNav);
+ entity.addLink(firstLevelTwoKeyOneInline);
+
+ // Second level NavPropertyETTwoKeyNavOne => Type ETTwoKeyNav
+ final ODataEntity secondLevelTwoKeyNav = of.newEntity(ET_TWO_KEY_NAV);
+ secondLevelTwoKeyNav.getProperties().add(
+ of.newComplexProperty(PROPERTY_COMP_TWO_PRIM, of.newComplexValue(CT_TWO_PRIM)
+ .add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 421)))
+ .add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString(
+ "String Property level 2, complex level 1")))));
+
+ // Binding links
+ secondLevelTwoKeyNav.addLink(of.newEntityNavigationLink(NAV_PROPERTY_ET_TWO_KEY_NAV_ONE, client.newURIBuilder(
+ SERVICE_URI).appendEntitySetSegment(ES_TWO_KEY_NAV).appendKeySegment(new LinkedHashMap<String, Object>() {
+ private static final long serialVersionUID = 3109256773218160485L;
+ {
+ put(PROPERTY_INT16, 3);
+ put(PROPERTY_STRING, "1");
+ }
+ }).build()));
+
+ final ODataInlineEntity secondLevelTwoKeyOneInline =
+ of.newDeepInsertEntity(NAV_PROPERTY_ET_TWO_KEY_NAV_ONE, secondLevelTwoKeyNav);
+ firstLevelTwoKeyNav.addLink(secondLevelTwoKeyOneInline);
+
+ // Third level NavPropertyETTwoKeyNavMany => Type ETTwoKeyNav
+ final ODataEntity thirdLevelTwoKeyNavMany1 = of.newEntity(ET_TWO_KEY_NAV);
+ thirdLevelTwoKeyNavMany1.getProperties().add(
+ of.newComplexProperty(PROPERTY_COMP_TWO_PRIM, of.newComplexValue(CT_TWO_PRIM)
+ .add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 431)))
+ .add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString(
+ "String Property level 3, complex level 1")))));
+
+ final ODataEntity thirdLevelTwoKeyNavMany2 = of.newEntity(ET_TWO_KEY_NAV);
+ thirdLevelTwoKeyNavMany2.getProperties().add(
+ of.newComplexProperty(PROPERTY_COMP_TWO_PRIM, of.newComplexValue(CT_TWO_PRIM)
+ .add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 432)))
+ .add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString(
+ "String Property level 3, complex level 1")))));
+
+ final ODataEntitySet entitySetThirdLevelTwoKeyNavMany = of.newEntitySet();
+ entitySetThirdLevelTwoKeyNavMany.getEntities().add(thirdLevelTwoKeyNavMany1);
+ entitySetThirdLevelTwoKeyNavMany.getEntities().add(thirdLevelTwoKeyNavMany2);
+ secondLevelTwoKeyNav.addLink(of.newDeepInsertEntitySet(NAV_PROPERTY_ET_TWO_KEY_NAV_MANY,
+ entitySetThirdLevelTwoKeyNavMany));
+
+ // First level NavPropertyETTwoKeyNavMany => Type ETTwoKeyNav
+ final ODataEntity firstLevelTwoKeyNavMany1 = of.newEntity(ET_TWO_KEY_NAV);
+ firstLevelTwoKeyNavMany1.getProperties().add(
+ of.newComplexProperty(PROPERTY_COMP_TWO_PRIM, of.newComplexValue(CT_TWO_PRIM)
+ .add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 422)))
+ .add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString(
+ "String Property level 1, complex level 1")))));
+
+ final ODataEntitySet entitySetfirstLevelTwoKeyNavMany = of.newEntitySet();
+ entitySetfirstLevelTwoKeyNavMany.getEntities().add(firstLevelTwoKeyNavMany1);
+ entity.addLink(of.newDeepInsertEntitySet(NAV_PROPERTY_ET_TWO_KEY_NAV_MANY,
+ entitySetfirstLevelTwoKeyNavMany));
+
+ final ODataEntityCreateResponse<ODataEntity> createResponse =
+ client.getCUDRequestFactory().getEntityCreateRequest(createURI, entity).execute();
+ // Check response
+ final ODataEntity resultEntityFirstLevel =
+ createResponse.getBody().getNavigationLink(NAV_PROPERTY_ET_TWO_KEY_NAV_ONE).asInlineEntity().getEntity();
+ assertEquals(42, resultEntityFirstLevel.getProperty(PROPERTY_COMP_TWO_PRIM).getComplexValue().get(PROPERTY_INT16)
+ .getPrimitiveValue().toValue());
+ assertEquals("String Property level 1, complex level 1", resultEntityFirstLevel.getProperty(PROPERTY_COMP_TWO_PRIM)
+ .getComplexValue().get(PROPERTY_STRING)
+ .getPrimitiveValue().toValue());
+
+ final ODataEntity resultEntitySecondLevel =
+ resultEntityFirstLevel.getNavigationLink(NAV_PROPERTY_ET_TWO_KEY_NAV_ONE).asInlineEntity().getEntity();
+ assertEquals(421, resultEntitySecondLevel.getProperty(PROPERTY_COMP_TWO_PRIM).getComplexValue().get(PROPERTY_INT16)
+ .getPrimitiveValue().toValue());
+ assertEquals("String Property level 2, complex level 1", resultEntitySecondLevel.getProperty(PROPERTY_COMP_TWO_PRIM)
+ .getComplexValue().get(PROPERTY_STRING)
+ .getPrimitiveValue().toValue());
+
+ final ODataEntitySet thirdLevelEntitySetNavMany =
+ resultEntitySecondLevel.getNavigationLink(NAV_PROPERTY_ET_TWO_KEY_NAV_MANY).asInlineEntitySet().getEntitySet();
+ assertEquals(2, thirdLevelEntitySetNavMany.getEntities().size());
+
+ assertEquals(431, thirdLevelEntitySetNavMany.getEntities().get(0).getProperty(PROPERTY_COMP_TWO_PRIM)
+ .getComplexValue().get(PROPERTY_INT16).getPrimitiveValue().toValue());
+ assertEquals("String Property level 3, complex level 1", thirdLevelEntitySetNavMany.getEntities().get(0)
+ .getProperty(PROPERTY_COMP_TWO_PRIM).getComplexValue().get(PROPERTY_STRING).getPrimitiveValue().toValue());
+
+ assertEquals(432, thirdLevelEntitySetNavMany.getEntities().get(1).getProperty(PROPERTY_COMP_TWO_PRIM)
+ .getComplexValue().get(PROPERTY_INT16).getPrimitiveValue().toValue());
+ assertEquals("String Property level 3, complex level 1", thirdLevelEntitySetNavMany.getEntities().get(1)
+ .getProperty(PROPERTY_COMP_TWO_PRIM).getComplexValue().get(PROPERTY_STRING).getPrimitiveValue().toValue());
+
+ final ODataEntitySet firstLevelEntitySetNavMany =
+ createResponse.getBody().getNavigationLink(NAV_PROPERTY_ET_TWO_KEY_NAV_MANY).asInlineEntitySet().getEntitySet();
+ assertEquals(1, firstLevelEntitySetNavMany.getEntities().size());
+ assertEquals(422, firstLevelEntitySetNavMany.getEntities().get(0).getProperty(PROPERTY_COMP_TWO_PRIM)
+ .getComplexValue().get(PROPERTY_INT16).getPrimitiveValue().toValue());
+ assertEquals("String Property level 1, complex level 1", firstLevelEntitySetNavMany.getEntities().get(0)
+ .getProperty(PROPERTY_COMP_TWO_PRIM).getComplexValue().get(PROPERTY_STRING).getPrimitiveValue().toValue());
+ }
+
@Test
public void testSimpleDeepInsert() throws EdmPrimitiveTypeException {
final ODataClient client = getClient();
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/DeserializerResult.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/DeserializerResult.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/DeserializerResult.java
new file mode 100644
index 0000000..3f36939
--- /dev/null
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/DeserializerResult.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.api.deserializer;
+
+import java.net.URI;
+import java.util.List;
+
+import org.apache.olingo.commons.api.data.Entity;
+import org.apache.olingo.commons.api.data.EntitySet;
+import org.apache.olingo.commons.api.data.Parameter;
+import org.apache.olingo.server.api.uri.queryoption.ExpandOption;
+import org.apache.olingo.commons.api.data.Property;
+
+/**
+ * Result type for {@link ODataDeserializer} methods
+ */
+public interface DeserializerResult {
+ /**
+ * Return an entity
+ * @return an {@link Entity} or null
+ */
+ Entity getEntity();
+
+ /**
+ * Returns a entity set
+ * @return an {@link EntitySet} or null
+ */
+ EntitySet getEntityCollection();
+
+ /**
+ * Returns the ExpandOptions for serialized entities
+ * @return an {@link ExpandOption} or null
+ */
+ ExpandOption getExpandTree();
+
+ /**
+ * Returns the deserialized action-parameters of an {@link Entity} object.
+ * @return a collection {@link Parameter}
+ */
+ List<Parameter> getActionParameter();
+
+ /**
+ * Returns a Property or collections of properties (primitive & complex)
+ * @return {@link Property} or collections of properties (primitive & complex) or null
+ */
+ Property getProperty();
+
+ /**
+ * Returns the entity references from the provided document
+ * @return a collection of entity reference
+ */
+ List<URI> getEntityReferences();
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/ODataDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/ODataDeserializer.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/ODataDeserializer.java
index 9aabf33..f014ad6 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/ODataDeserializer.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/ODataDeserializer.java
@@ -19,13 +19,9 @@
package org.apache.olingo.server.api.deserializer;
import java.io.InputStream;
-import java.net.URI;
-import java.util.List;
import org.apache.olingo.commons.api.data.Entity;
import org.apache.olingo.commons.api.data.EntitySet;
-import org.apache.olingo.commons.api.data.Parameter;
-import org.apache.olingo.commons.api.data.Property;
import org.apache.olingo.commons.api.edm.EdmAction;
import org.apache.olingo.commons.api.edm.EdmEntityType;
import org.apache.olingo.commons.api.edm.EdmProperty;
@@ -38,47 +34,48 @@ public interface ODataDeserializer {
/**
* Deserializes an entity stream into an {@link Entity} object.
* Validates: property types, no double properties, correct json types
+ * Returns a deserialized {@link Entity} object and an {@link ExpandOption} object
* @param stream
* @param edmEntityType
- * @return deserialized {@link Entity} object
+ * @return {@link DeserializerResult#getEntity()} and {@link DeserializerResult#getExpandTree()}
* @throws DeserializerException
*/
- Entity entity(InputStream stream, EdmEntityType edmEntityType) throws DeserializerException;
+ DeserializerResult entity(InputStream stream, EdmEntityType edmEntityType) throws DeserializerException;
/**
* Deserializes an entity collection stream into an {@link EntitySet} object.
* @param stream
* @param edmEntityType
- * @return deserialized {@link EntitySet} object
+ * @return {@link DeserializerResult#getEntityCollection()}
* @throws DeserializerException
*/
- EntitySet entityCollection(InputStream stream, EdmEntityType edmEntityType) throws DeserializerException;
+ DeserializerResult entityCollection(InputStream stream, EdmEntityType edmEntityType) throws DeserializerException;
/**
* Deserializes an action-parameters stream into an {@link Entity} object.
* Validates: parameter types, no double parameters, correct json types.
* @param stream
* @param edmAction
- * @return deserialized list of {@link Parameter} objects
+ * @return {@link DeserializerResult#getActionParameter()}
* @throws DeserializerException
*/
- List<Parameter> actionParameters(InputStream stream, EdmAction edmAction) throws DeserializerException;
+ DeserializerResult actionParameters(InputStream stream, EdmAction edmAction) throws DeserializerException;
/**
* Deserializes the Property or collections of properties (primitive & complex)
* @param stream
* @param edmProperty
- * @return deserialized {@link Property}
+ * @return {@link DeserializerResult#getProperty()}
* @throws DeserializerException
*/
- Property property(InputStream stream, EdmProperty edmProperty) throws DeserializerException;
+ DeserializerResult property(InputStream stream, EdmProperty edmProperty) throws DeserializerException;
/**
* Read entity references from the provided document
* @param stream
* @param keys
- * @return
+ * @return {@link DeserializerResult#getEntityReferences()}}
* @throws DeserializerException
*/
- List<URI> entityReferences(InputStream stream) throws DeserializerException;
+ DeserializerResult entityReferences(InputStream stream) throws DeserializerException;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/DefaultProcessor.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/DefaultProcessor.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/DefaultProcessor.java
index f62c6c7..f2da16e 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/DefaultProcessor.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/DefaultProcessor.java
@@ -56,7 +56,7 @@ public class DefaultProcessor implements MetadataProcessor, ServiceDocumentProce
public void readServiceDocument(final ODataRequest request, final ODataResponse response, final UriInfo uriInfo,
final ContentType requestedContentType) throws ODataApplicationException, SerializerException {
ODataSerializer serializer = odata.createSerializer(ODataFormat.fromContentType(requestedContentType));
- response.setContent(serializer.serviceDocument(serviceMetadata.getEdm(), null));
+ response.setContent(serializer.serviceDocument(serviceMetadata.getEdm(), null).getContent());
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, requestedContentType.toContentTypeString());
}
@@ -65,7 +65,7 @@ public class DefaultProcessor implements MetadataProcessor, ServiceDocumentProce
public void readMetadata(final ODataRequest request, final ODataResponse response, final UriInfo uriInfo,
final ContentType requestedContentType) throws ODataApplicationException, SerializerException {
ODataSerializer serializer = odata.createSerializer(ODataFormat.fromContentType(requestedContentType));
- response.setContent(serializer.metadataDocument(serviceMetadata));
+ response.setContent(serializer.metadataDocument(serviceMetadata).getContent());
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, requestedContentType.toContentTypeString());
}
@@ -75,7 +75,7 @@ public class DefaultProcessor implements MetadataProcessor, ServiceDocumentProce
ContentType requestedContentType) {
try {
ODataSerializer serializer = odata.createSerializer(ODataFormat.fromContentType(requestedContentType));
- response.setContent(serializer.error(serverError));
+ response.setContent(serializer.error(serverError).getContent());
response.setStatusCode(serverError.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, requestedContentType.toContentTypeString());
} catch (Exception e) {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java
index 55377ce..01db1a4 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java
@@ -41,20 +41,20 @@ public interface ODataSerializer {
* @param edm the Entity Data Model
* @param serviceRoot the service-root URI of this OData service
*/
- InputStream serviceDocument(Edm edm, String serviceRoot) throws SerializerException;
+ SerializerResult serviceDocument(Edm edm, String serviceRoot) throws SerializerException;
/**
* Writes the metadata document into an InputStream.
* @param serviceMetadata the metadata information for the service
*/
- InputStream metadataDocument(ServiceMetadata serviceMetadata) throws SerializerException;
+ SerializerResult metadataDocument(ServiceMetadata serviceMetadata) throws SerializerException;
/**
* Writes an ODataError into an InputStream.
* @param error the main error
* @return inputStream containing the OData-formatted error
*/
- InputStream error(ODataServerError error) throws SerializerException;
+ SerializerResult error(ODataServerError error) throws SerializerException;
/**
* Writes entity-collection data into an InputStream.
@@ -63,7 +63,7 @@ public interface ODataSerializer {
* @param entitySet the data of the entity set
* @param options options for the serializer
*/
- InputStream entityCollection(ServiceMetadata metadata, EdmEntityType entityType,
+ SerializerResult entityCollection(ServiceMetadata metadata, EdmEntityType entityType,
EntitySet entitySet, EntityCollectionSerializerOptions options) throws SerializerException;
/**
@@ -73,7 +73,7 @@ public interface ODataSerializer {
* @param entity the data of the entity
* @param options options for the serializer
*/
- InputStream entity(ServiceMetadata metadata, EdmEntityType entityType, Entity entity,
+ SerializerResult entity(ServiceMetadata metadata, EdmEntityType entityType, Entity entity,
EntitySerializerOptions options) throws SerializerException;
/**
@@ -82,7 +82,7 @@ public interface ODataSerializer {
* @param property property value
* @param options options for the serializer
*/
- InputStream primitive(EdmPrimitiveType type, Property property, PrimitiveSerializerOptions options)
+ SerializerResult primitive(EdmPrimitiveType type, Property property, PrimitiveSerializerOptions options)
throws SerializerException;
/**
@@ -92,7 +92,7 @@ public interface ODataSerializer {
* @param property property value
* @param options options for the serializer
*/
- InputStream complex(ServiceMetadata metadata, EdmComplexType type, Property property,
+ SerializerResult complex(ServiceMetadata metadata, EdmComplexType type, Property property,
ComplexSerializerOptions options) throws SerializerException;
/**
@@ -101,7 +101,7 @@ public interface ODataSerializer {
* @param property property value
* @param options options for the serializer
*/
- InputStream primitiveCollection(EdmPrimitiveType type, Property property, PrimitiveSerializerOptions options)
+ SerializerResult primitiveCollection(EdmPrimitiveType type, Property property, PrimitiveSerializerOptions options)
throws SerializerException;
/**
@@ -111,6 +111,6 @@ public interface ODataSerializer {
* @param property property value
* @param options options for the serializer
*/
- InputStream complexCollection(ServiceMetadata metadata, EdmComplexType type, Property property,
+ SerializerResult complexCollection(ServiceMetadata metadata, EdmComplexType type, Property property,
ComplexSerializerOptions options) throws SerializerException;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerResult.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerResult.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerResult.java
new file mode 100644
index 0000000..5249bb4
--- /dev/null
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerResult.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.api.serializer;
+
+import java.io.InputStream;
+
+/**
+* Result type for {@link ODataSerializer} methods
+ */
+public interface SerializerResult {
+ /**
+ * Returns the serialized content
+ * @return serialized content
+ */
+ InputStream getContent();
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ErrorHandler.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ErrorHandler.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ErrorHandler.java
index 199c62d..b83d383 100644
--- a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ErrorHandler.java
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ErrorHandler.java
@@ -108,7 +108,7 @@ public class ErrorHandler {
try {
ODataSerializer serializer = this.odata.createSerializer(ODataFormat
.fromContentType(requestedContentType));
- response.setContent(serializer.error(serverError));
+ response.setContent(serializer.error(serverError).getContent());
response.setStatusCode(serverError.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, requestedContentType.toContentTypeString());
} catch (Exception e) {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/DataRequest.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/DataRequest.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/DataRequest.java
index 32bf26a..cebaf64 100644
--- a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/DataRequest.java
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/DataRequest.java
@@ -315,7 +315,7 @@ public class DataRequest extends ServiceRequest {
private Entity getEntityFromClient() throws DeserializerException {
ODataDeserializer deserializer = odata.createDeserializer(ODataFormat
.fromContentType(getRequestContentType()));
- return deserializer.entity(getODataRequest().getBody(), getEntitySet().getEntityType());
+ return deserializer.entity(getODataRequest().getBody(), getEntitySet().getEntityType()).getEntity();
}
@Override
@@ -431,7 +431,7 @@ public class DataRequest extends ServiceRequest {
private List<URI> getPayload() throws DeserializerException {
ODataDeserializer deserializer = odata.createDeserializer(ODataFormat
.fromContentType(getRequestContentType()));
- return deserializer.entityReferences(getODataRequest().getBody());
+ return deserializer.entityReferences(getODataRequest().getBody()).getEntityReferences();
}
@Override
@@ -664,7 +664,7 @@ public class DataRequest extends ServiceRequest {
// for now it is responsibility of the user
ODataDeserializer deserializer = odata.createDeserializer(ODataFormat
.fromContentType(getRequestContentType()));
- return deserializer.property(getODataRequest().getBody(), edmProperty);
+ return deserializer.property(getODataRequest().getBody(), edmProperty).getProperty();
}
static ContextURL.Builder buildEntitySetContextURL(UriHelper helper,
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/EntityResponse.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/EntityResponse.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/EntityResponse.java
index fd29bbd..e90681d 100644
--- a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/EntityResponse.java
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/EntityResponse.java
@@ -82,7 +82,7 @@ public class EntityResponse extends ServiceResponse {
}
// write the entity to response
- this.response.setContent(this.serializer.entity(this.metadata, entityType, entity, this.options));
+ this.response.setContent(this.serializer.entity(this.metadata, entityType, entity, this.options).getContent());
writeOK(this.responseContentType.toContentTypeString());
close();
}
@@ -107,7 +107,7 @@ public class EntityResponse extends ServiceResponse {
}
// return the content of the created entity
- this.response.setContent(this.serializer.entity(this.metadata, entityType, entity, this.options));
+ this.response.setContent(this.serializer.entity(this.metadata, entityType, entity, this.options).getContent());
writeCreated(false);
writeHeader(HttpHeader.LOCATION, locationHeader);
writeHeader("Preference-Applied", "return=representation"); //$NON-NLS-1$ //$NON-NLS-2$
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/EntitySetResponse.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/EntitySetResponse.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/EntitySetResponse.java
index 40276d2..c70854b 100644
--- a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/EntitySetResponse.java
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/EntitySetResponse.java
@@ -69,7 +69,8 @@ public class EntitySetResponse extends ServiceResponse {
}
// write the whole collection to response
- this.response.setContent(this.serializer.entityCollection(metadata, entityType, entitySet, this.options));
+ this.response.setContent(this.serializer.entityCollection(metadata, entityType, entitySet, this.options)
+ .getContent());
writeOK(this.responseContentType.toContentTypeString());
close();
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/MetadataResponse.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/MetadataResponse.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/MetadataResponse.java
index 055c0b0..b325421 100644
--- a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/MetadataResponse.java
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/MetadataResponse.java
@@ -49,7 +49,7 @@ public class MetadataResponse extends ServiceResponse {
public void writeMetadata()throws ODataTranslatedException {
assert (!isClosed());
- this.response.setContent(this.serializer.metadataDocument(this.metadata));
+ this.response.setContent(this.serializer.metadataDocument(this.metadata).getContent());
writeOK(this.responseContentType.toContentTypeString());
close();
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/PropertyResponse.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/PropertyResponse.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/PropertyResponse.java
index e6b951d..79ac90d 100644
--- a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/PropertyResponse.java
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/PropertyResponse.java
@@ -106,10 +106,10 @@ public class PropertyResponse extends ServiceResponse {
throws SerializerException {
if (this.collection) {
this.response.setContent(this.serializer.complexCollection(this.metadata, type, property,
- this.complexOptions));
+ this.complexOptions).getContent());
} else {
this.response.setContent(this.serializer.complex(this.metadata, type, property,
- this.complexOptions));
+ this.complexOptions).getContent());
}
writeOK(this.responseContentType.toContentTypeString());
close();
@@ -118,9 +118,9 @@ public class PropertyResponse extends ServiceResponse {
private void writePrimitiveProperty(EdmPrimitiveType type, Property property)
throws SerializerException {
if(this.collection) {
- this.response.setContent(this.serializer.primitiveCollection(type, property, this.primitiveOptions));
+ this.response.setContent(this.serializer.primitiveCollection(type, property, this.primitiveOptions).getContent());
} else {
- this.response.setContent(this.serializer.primitive(type, property, this.primitiveOptions));
+ this.response.setContent(this.serializer.primitive(type, property, this.primitiveOptions).getContent());
}
writeOK(this.responseContentType.toContentTypeString());
close();
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/ServiceDocumentResponse.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/ServiceDocumentResponse.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/ServiceDocumentResponse.java
index 86c420b..8b77684 100644
--- a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/ServiceDocumentResponse.java
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/ServiceDocumentResponse.java
@@ -50,7 +50,7 @@ public class ServiceDocumentResponse extends ServiceResponse {
public void writeServiceDocument(String serviceRoot)
throws ODataTranslatedException {
assert (!isClosed());
- this.response.setContent(this.serializer.serviceDocument(this.metadata.getEdm(), serviceRoot));
+ this.response.setContent(this.serializer.serviceDocument(this.metadata.getEdm(), serviceRoot).getContent());
writeOK(this.responseContentType.toContentTypeString());
close();
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinDataModel.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinDataModel.java b/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinDataModel.java
index 904f4d8..055f073 100644
--- a/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinDataModel.java
+++ b/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinDataModel.java
@@ -124,7 +124,7 @@ public class TripPinDataModel {
ODataJsonDeserializer deserializer = new ODataJsonDeserializer();
EntitySet set = deserializer.entityCollection(new FileInputStream(new File(
- "src/test/resources/" + entitySetName.toLowerCase() + ".json")), type);
+ "src/test/resources/" + entitySetName.toLowerCase() + ".json")), type).getEntityCollection();
// TODO: the count needs to be part of deserializer
set.setCount(set.getEntities().size());
for (Entity entity : set.getEntities()) {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/DeserializerResultImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/DeserializerResultImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/DeserializerResultImpl.java
new file mode 100644
index 0000000..84d64ea
--- /dev/null
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/DeserializerResultImpl.java
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.core.deserializer;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.commons.api.data.Entity;
+import org.apache.olingo.commons.api.data.EntitySet;
+import org.apache.olingo.commons.api.data.Parameter;
+import org.apache.olingo.commons.api.data.Property;
+import org.apache.olingo.server.api.deserializer.DeserializerResult;
+import org.apache.olingo.server.api.uri.queryoption.ExpandOption;
+
+public class DeserializerResultImpl implements DeserializerResult {
+ private Entity entity;
+ private EntitySet entitySet;
+ private ExpandOption expandOption;
+ private Property property;
+ private List<Parameter> actionParametes;
+ private List<URI> entityReferences;
+
+ private DeserializerResultImpl() {}
+
+ @Override
+ public Entity getEntity() {
+ return entity;
+ }
+
+ @Override
+ public EntitySet getEntityCollection() {
+ return entitySet;
+ }
+
+ @Override
+ public ExpandOption getExpandTree() {
+ return expandOption;
+ }
+
+ @Override
+ public List<Parameter> getActionParameter() {
+ return actionParametes;
+ }
+
+ @Override
+ public Property getProperty() {
+ return property;
+ }
+
+ @Override
+ public List<URI> getEntityReferences() {
+ return entityReferences;
+ }
+
+ public static DeserializerResultBuilder with() {
+ return new DeserializerResultBuilder();
+ }
+
+ public static class DeserializerResultBuilder {
+ private Entity entity;
+ private EntitySet entitySet;
+ private ExpandOption expandOption;
+ private Property property;
+ private List<Parameter> actionParametes;
+ private List<URI> entityReferences;
+
+ public DeserializerResult build() {
+ DeserializerResultImpl result = new DeserializerResultImpl();
+ result.entity = entity;
+ result.entitySet = entitySet;
+ result.expandOption = expandOption;
+ result.property = property;
+ result.entityReferences = (entityReferences == null) ? new ArrayList<URI>() : entityReferences;
+ result.actionParametes = (actionParametes == null) ? new ArrayList<Parameter>() : actionParametes;
+
+ return result;
+ }
+
+ public DeserializerResultBuilder entity(final Entity entity) {
+ this.entity = entity;
+ return this;
+ }
+
+ public DeserializerResultBuilder entityCollection(final EntitySet entitySet) {
+ this.entitySet = entitySet;
+ return this;
+ }
+
+ public DeserializerResultBuilder expandOption(final ExpandOption expandOption) {
+ this.expandOption = expandOption;
+ return this;
+ }
+
+ public DeserializerResultBuilder property(final Property property) {
+ this.property = property;
+ return this;
+ }
+
+ public DeserializerResultBuilder entityReferences(final List<URI> entityReferences) {
+ this.entityReferences = entityReferences;
+ return this;
+ }
+
+ public DeserializerResultBuilder actionParameters(final List<Parameter> actionParameters) {
+ this.actionParametes = actionParameters;
+ return this;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/helper/ExpandTreeBuilder.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/helper/ExpandTreeBuilder.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/helper/ExpandTreeBuilder.java
new file mode 100644
index 0000000..5e279bd
--- /dev/null
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/helper/ExpandTreeBuilder.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.core.deserializer.helper;
+
+import org.apache.olingo.commons.api.edm.EdmNavigationProperty;
+import org.apache.olingo.server.core.uri.UriInfoImpl;
+import org.apache.olingo.server.core.uri.UriResourceNavigationPropertyImpl;
+import org.apache.olingo.server.core.uri.queryoption.ExpandItemImpl;
+
+public abstract class ExpandTreeBuilder {
+ public abstract ExpandTreeBuilder expand(EdmNavigationProperty edmNavigationProperty);
+
+ protected ExpandItemImpl buildExpandItem(final EdmNavigationProperty edmNavigationProperty) {
+ final ExpandItemImpl expandItem = new ExpandItemImpl();
+ final UriInfoImpl uriInfo = new UriInfoImpl();
+ final UriResourceNavigationPropertyImpl resourceNavigation = new UriResourceNavigationPropertyImpl();
+
+ resourceNavigation.setNavigationProperty(edmNavigationProperty);
+ uriInfo.addResourcePart(resourceNavigation);
+ expandItem.setResourcePath(uriInfo);
+
+ return expandItem;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/helper/ExpandTreeBuilderImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/helper/ExpandTreeBuilderImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/helper/ExpandTreeBuilderImpl.java
new file mode 100644
index 0000000..4161af1
--- /dev/null
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/helper/ExpandTreeBuilderImpl.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.core.deserializer.helper;
+
+import org.apache.olingo.commons.api.edm.EdmNavigationProperty;
+import org.apache.olingo.server.api.uri.queryoption.ExpandOption;
+import org.apache.olingo.server.core.uri.queryoption.ExpandItemImpl;
+import org.apache.olingo.server.core.uri.queryoption.ExpandOptionImpl;
+
+public class ExpandTreeBuilderImpl extends ExpandTreeBuilder {
+
+ private ExpandOptionImpl expandOption = null;
+
+ @Override
+ public ExpandTreeBuilder expand(EdmNavigationProperty edmNavigationProperty) {
+ ExpandItemImpl expandItem = buildExpandItem(edmNavigationProperty);
+
+ if(expandOption == null) {
+ expandOption = new ExpandOptionImpl();
+ }
+ expandOption.addExpandItem(expandItem);
+
+ return new ExpandTreeBuilderInner(expandItem);
+ }
+
+ public ExpandOption build() {
+ return expandOption;
+ }
+
+ private class ExpandTreeBuilderInner extends ExpandTreeBuilder {
+ private ExpandItemImpl parent;
+
+ public ExpandTreeBuilderInner(ExpandItemImpl expandItem) {
+ parent = expandItem;
+ }
+
+ @Override
+ public ExpandTreeBuilder expand(EdmNavigationProperty edmNavigationProperty) {
+ if(parent.getExpandOption() == null) {
+ final ExpandOptionImpl expandOption = new ExpandOptionImpl();
+ parent.setSystemQueryOption(expandOption);
+ }
+
+ final ExpandItemImpl expandItem = buildExpandItem(edmNavigationProperty);
+ ((ExpandOptionImpl)parent.getExpandOption()).addExpandItem(expandItem);
+
+ return new ExpandTreeBuilderInner(expandItem);
+ }
+
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
index 8d2701e..538e95c 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
@@ -57,7 +57,11 @@ import org.apache.olingo.commons.core.data.LinkImpl;
import org.apache.olingo.commons.core.data.ParameterImpl;
import org.apache.olingo.commons.core.data.PropertyImpl;
import org.apache.olingo.server.api.deserializer.DeserializerException;
+import org.apache.olingo.server.api.deserializer.DeserializerResult;
import org.apache.olingo.server.api.deserializer.ODataDeserializer;
+import org.apache.olingo.server.core.deserializer.DeserializerResultImpl;
+import org.apache.olingo.server.core.deserializer.helper.ExpandTreeBuilder;
+import org.apache.olingo.server.core.deserializer.helper.ExpandTreeBuilderImpl;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParseException;
@@ -76,11 +80,13 @@ public class ODataJsonDeserializer implements ODataDeserializer {
private static final String ODATA_CONTROL_INFORMATION_PREFIX = "@odata.";
@Override
- public EntitySet entityCollection(InputStream stream, EdmEntityType edmEntityType) throws DeserializerException {
+ public DeserializerResult entityCollection(InputStream stream, EdmEntityType edmEntityType)
+ throws DeserializerException {
try {
final ObjectNode tree = parseJsonTree(stream);
-
- return consumeEntitySetNode(edmEntityType, tree);
+
+ return DeserializerResultImpl.with().entityCollection(consumeEntitySetNode(edmEntityType, tree, null))
+ .build();
} catch (JsonParseException e) {
throw new DeserializerException("An JsonParseException occurred", e,
DeserializerException.MessageKeys.JSON_SYNTAX_EXCEPTION);
@@ -92,8 +98,8 @@ public class ODataJsonDeserializer implements ODataDeserializer {
}
}
- private EntitySet consumeEntitySetNode(EdmEntityType edmEntityType, final ObjectNode tree)
- throws DeserializerException {
+ private EntitySet consumeEntitySetNode(EdmEntityType edmEntityType, final ObjectNode tree,
+ final ExpandTreeBuilder expandBuilder) throws DeserializerException {
EntitySetImpl entitySet = new EntitySetImpl();
// Consume entities
@@ -104,7 +110,7 @@ public class ODataJsonDeserializer implements ODataDeserializer {
DeserializerException.MessageKeys.VALUE_TAG_MUST_BE_AN_ARRAY);
}
- entitySet.getEntities().addAll(consumeEntitySetArray(edmEntityType, jsonNode));
+ entitySet.getEntities().addAll(consumeEntitySetArray(edmEntityType, jsonNode, expandBuilder));
tree.remove(Constants.VALUE);
} else {
throw new DeserializerException("Could not find value array.",
@@ -131,8 +137,8 @@ public class ODataJsonDeserializer implements ODataDeserializer {
return entitySet;
}
- private List<Entity> consumeEntitySetArray(EdmEntityType edmEntityType, JsonNode jsonNode)
- throws DeserializerException {
+ private List<Entity> consumeEntitySetArray(EdmEntityType edmEntityType, JsonNode jsonNode,
+ final ExpandTreeBuilder expandBuilder) throws DeserializerException {
List<Entity> entities = new ArrayList<Entity>();
for (JsonNode arrayElement : jsonNode) {
if (arrayElement.isArray() || arrayElement.isValueNode()) {
@@ -140,17 +146,20 @@ public class ODataJsonDeserializer implements ODataDeserializer {
DeserializerException.MessageKeys.INVALID_ENTITY);
}
- entities.add(consumeEntityNode(edmEntityType, (ObjectNode) arrayElement));
+ entities.add(consumeEntityNode(edmEntityType, (ObjectNode) arrayElement, expandBuilder));
}
return entities;
}
@Override
- public Entity entity(InputStream stream, EdmEntityType edmEntityType) throws DeserializerException {
+ public DeserializerResult entity(InputStream stream, EdmEntityType edmEntityType) throws DeserializerException {
try {
final ObjectNode tree = parseJsonTree(stream);
-
- return consumeEntityNode(edmEntityType, tree);
+ final ExpandTreeBuilderImpl expandBuilder = new ExpandTreeBuilderImpl();
+
+ return DeserializerResultImpl.with().entity(consumeEntityNode(edmEntityType, tree, expandBuilder))
+ .expandOption(expandBuilder.build())
+ .build();
} catch (JsonParseException e) {
throw new DeserializerException("An JsonParseException occurred", e,
@@ -164,7 +173,8 @@ public class ODataJsonDeserializer implements ODataDeserializer {
}
- private Entity consumeEntityNode(EdmEntityType edmEntityType, final ObjectNode tree) throws DeserializerException {
+ private Entity consumeEntityNode(EdmEntityType edmEntityType, final ObjectNode tree,
+ final ExpandTreeBuilder expandBuilder) throws DeserializerException {
EntityImpl entity = new EntityImpl();
entity.setType(edmEntityType.getFullQualifiedName().getFullQualifiedNameAsString());
@@ -172,7 +182,7 @@ public class ODataJsonDeserializer implements ODataDeserializer {
consumeEntityProperties(edmEntityType, tree, entity);
// Check and consume all expanded Navigation Properties
- consumeExpandedNavigationProperties(edmEntityType, tree, entity);
+ consumeExpandedNavigationProperties(edmEntityType, tree, entity, expandBuilder);
// consume remaining json node fields
consumeRemainingJsonNodeFields(edmEntityType, tree, entity);
@@ -183,13 +193,14 @@ public class ODataJsonDeserializer implements ODataDeserializer {
}
@Override
- public List<Parameter> actionParameters(InputStream stream, final EdmAction edmAction) throws DeserializerException {
+ public DeserializerResult actionParameters(InputStream stream, final EdmAction edmAction)
+ throws DeserializerException {
try {
ObjectNode tree = parseJsonTree(stream);
List<Parameter> parameters = new ArrayList<Parameter>();
consumeParameters(edmAction, tree, parameters);
assertJsonNodeIsEmpty(tree);
- return parameters;
+ return DeserializerResultImpl.with().actionParameters(parameters).build();
} catch (final JsonParseException e) {
throw new DeserializerException("An JsonParseException occurred", e,
@@ -203,7 +214,8 @@ public class ODataJsonDeserializer implements ODataDeserializer {
}
}
- private ObjectNode parseJsonTree(InputStream stream) throws IOException, JsonParseException, JsonProcessingException {
+ private ObjectNode parseJsonTree(InputStream stream)
+ throws IOException, JsonParseException, JsonProcessingException {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_READING_DUP_TREE_KEY, true);
JsonParser parser = new JsonFactory(objectMapper).createParser(stream);
@@ -314,7 +326,7 @@ public class ODataJsonDeserializer implements ODataDeserializer {
}
private void consumeExpandedNavigationProperties(final EdmEntityType edmEntityType, final ObjectNode node,
- final EntityImpl entity) throws DeserializerException {
+ final EntityImpl entity, final ExpandTreeBuilder expandBuilder) throws DeserializerException {
List<String> navigationPropertyNames = edmEntityType.getNavigationPropertyNames();
for (String navigationPropertyName : navigationPropertyNames) {
// read expanded navigation property
@@ -329,16 +341,20 @@ public class ODataJsonDeserializer implements ODataDeserializer {
LinkImpl link = new LinkImpl();
link.setTitle(navigationPropertyName);
+ final ExpandTreeBuilder childExpandBuilder = (expandBuilder != null) ?
+ expandBuilder.expand(edmNavigationProperty) : null;
if (jsonNode.isArray() && edmNavigationProperty.isCollection()) {
link.setType(ODataLinkType.ENTITY_SET_NAVIGATION.toString());
EntitySetImpl inlineEntitySet = new EntitySetImpl();
- inlineEntitySet.getEntities().addAll(consumeEntitySetArray(edmNavigationProperty.getType(), jsonNode));
+ inlineEntitySet.getEntities().addAll(consumeEntitySetArray(edmNavigationProperty.getType(), jsonNode,
+ childExpandBuilder));
link.setInlineEntitySet(inlineEntitySet);
} else if (!jsonNode.isArray() && (!jsonNode.isValueNode() || jsonNode.isNull())
&& !edmNavigationProperty.isCollection()) {
link.setType(ODataLinkType.ENTITY_NAVIGATION.toString());
if (!jsonNode.isNull()) {
- Entity inlineEntity = consumeEntityNode(edmNavigationProperty.getType(), (ObjectNode) jsonNode);
+ Entity inlineEntity = consumeEntityNode(edmNavigationProperty.getType(), (ObjectNode) jsonNode,
+ childExpandBuilder);
link.setInlineEntity(inlineEntity);
}
} else {
@@ -732,7 +748,7 @@ public class ODataJsonDeserializer implements ODataDeserializer {
}
@Override
- public Property property(InputStream stream, EdmProperty edmProperty)
+ public DeserializerResult property(InputStream stream, EdmProperty edmProperty)
throws DeserializerException {
try {
ObjectMapper objectMapper = new ObjectMapper();
@@ -756,7 +772,7 @@ public class ODataJsonDeserializer implements ODataDeserializer {
edmProperty.isUnicode(), edmProperty.getMapping(),
tree);
}
- return property;
+ return DeserializerResultImpl.with().property(property).build();
} catch (JsonParseException e) {
throw new DeserializerException("An JsonParseException occurred", e,
DeserializerException.MessageKeys.JSON_SYNTAX_EXCEPTION);
@@ -768,7 +784,7 @@ public class ODataJsonDeserializer implements ODataDeserializer {
}
}
- public List<URI> entityReferences(InputStream stream) throws DeserializerException {
+ public DeserializerResult entityReferences(InputStream stream) throws DeserializerException {
try {
ArrayList<URI> parsedValues = new ArrayList<URI>();
ObjectMapper objectMapper = new ObjectMapper();
@@ -789,10 +805,10 @@ public class ODataJsonDeserializer implements ODataDeserializer {
}
tree.remove(Constants.VALUE);
// if this is value there can be only one property
- return parsedValues;
+ return DeserializerResultImpl.with().entityReferences(parsedValues).build();
}
parsedValues.add(new URI(tree.get(key).asText()));
- return parsedValues;
+ return DeserializerResultImpl.with().entityReferences(parsedValues).build();
} catch (JsonParseException e) {
throw new DeserializerException("An JsonParseException occurred", e,
DeserializerException.MessageKeys.JSON_SYNTAX_EXCEPTION);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java
new file mode 100644
index 0000000..b7b16a2
--- /dev/null
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.core.serializer;
+
+import java.io.InputStream;
+
+import org.apache.olingo.server.api.serializer.SerializerResult;
+
+public class SerializerResultImpl implements SerializerResult {
+ private InputStream content;
+
+ @Override
+ public InputStream getContent() {
+ return content;
+ }
+
+ public static SerializerResultBuilder with() {
+ return new SerializerResultBuilder();
+ }
+
+ public static class SerializerResultBuilder {
+ private InputStream content;
+
+ public SerializerResultBuilder content(final InputStream input) {
+ content = input;
+
+ return this;
+ }
+
+ public SerializerResult build() {
+ SerializerResultImpl result = new SerializerResultImpl();
+ result.content = content;
+
+ return result;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
index a7ce16b..c9944c7 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
@@ -19,7 +19,6 @@
package org.apache.olingo.server.core.serializer.json;
import java.io.IOException;
-import java.io.InputStream;
import java.util.Collections;
import java.util.List;
import java.util.Set;
@@ -52,9 +51,11 @@ import org.apache.olingo.server.api.serializer.EntitySerializerOptions;
import org.apache.olingo.server.api.serializer.ODataSerializer;
import org.apache.olingo.server.api.serializer.PrimitiveSerializerOptions;
import org.apache.olingo.server.api.serializer.SerializerException;
+import org.apache.olingo.server.api.serializer.SerializerResult;
import org.apache.olingo.server.api.uri.queryoption.ExpandItem;
import org.apache.olingo.server.api.uri.queryoption.ExpandOption;
import org.apache.olingo.server.api.uri.queryoption.SelectOption;
+import org.apache.olingo.server.core.serializer.SerializerResultImpl;
import org.apache.olingo.server.core.serializer.utils.CircleStreamBuffer;
import org.apache.olingo.server.core.serializer.utils.ContextURLBuilder;
import org.apache.olingo.server.core.serializer.utils.ExpandSelectHelper;
@@ -76,7 +77,7 @@ public class ODataJsonSerializer implements ODataSerializer {
}
@Override
- public InputStream serviceDocument(final Edm edm, final String serviceRoot) throws SerializerException {
+ public SerializerResult serviceDocument(final Edm edm, final String serviceRoot) throws SerializerException {
CircleStreamBuffer buffer;
JsonGenerator gen = null;
@@ -89,7 +90,7 @@ public class ODataJsonSerializer implements ODataSerializer {
gen.close();
- return buffer.getInputStream();
+ return SerializerResultImpl.with().content(buffer.getInputStream()).build();
} catch (final IOException e) {
log.error(e.getMessage(), e);
@@ -108,13 +109,13 @@ public class ODataJsonSerializer implements ODataSerializer {
}
@Override
- public InputStream metadataDocument(final ServiceMetadata serviceMetadata) throws SerializerException {
+ public SerializerResult metadataDocument(final ServiceMetadata serviceMetadata) throws SerializerException {
throw new SerializerException("Metadata in JSON format not supported!",
SerializerException.MessageKeys.JSON_METADATA);
}
@Override
- public InputStream error(final ODataServerError error) throws SerializerException {
+ public SerializerResult error(final ODataServerError error) throws SerializerException {
CircleStreamBuffer buffer = new CircleStreamBuffer();
try {
JsonGenerator json = new JsonFactory().createGenerator(buffer.getOutputStream());
@@ -124,11 +125,11 @@ public class ODataJsonSerializer implements ODataSerializer {
throw new SerializerException("An I/O exception occurred.", e,
SerializerException.MessageKeys.IO_EXCEPTION);
}
- return buffer.getInputStream();
+ return SerializerResultImpl.with().content(buffer.getInputStream()).build();
}
@Override
- public InputStream entityCollection(final ServiceMetadata metadata,
+ public SerializerResult entityCollection(final ServiceMetadata metadata,
final EdmEntityType entityType, final EntitySet entitySet,
final EntityCollectionSerializerOptions options) throws SerializerException {
CircleStreamBuffer buffer = new CircleStreamBuffer();
@@ -161,11 +162,11 @@ public class ODataJsonSerializer implements ODataSerializer {
throw new SerializerException("An I/O exception occurred.", e,
SerializerException.MessageKeys.IO_EXCEPTION);
}
- return buffer.getInputStream();
+ return SerializerResultImpl.with().content(buffer.getInputStream()).build();
}
@Override
- public InputStream entity(final ServiceMetadata metadata, final EdmEntityType entityType,
+ public SerializerResult entity(final ServiceMetadata metadata, final EdmEntityType entityType,
final Entity entity, final EntitySerializerOptions options) throws SerializerException {
final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL());
CircleStreamBuffer buffer = new CircleStreamBuffer();
@@ -180,7 +181,7 @@ public class ODataJsonSerializer implements ODataSerializer {
throw new SerializerException("An I/O exception occurred.", e,
SerializerException.MessageKeys.IO_EXCEPTION);
}
- return buffer.getInputStream();
+ return SerializerResultImpl.with().content(buffer.getInputStream()).build();
}
private ContextURL checkContextURL(final ContextURL contextURL) throws SerializerException {
@@ -515,7 +516,7 @@ public class ODataJsonSerializer implements ODataSerializer {
}
@Override
- public InputStream primitive(final EdmPrimitiveType type, final Property property,
+ public SerializerResult primitive(final EdmPrimitiveType type, final Property property,
final PrimitiveSerializerOptions options) throws SerializerException {
final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL());
CircleStreamBuffer buffer = new CircleStreamBuffer();
@@ -544,11 +545,11 @@ public class ODataJsonSerializer implements ODataSerializer {
SerializerException.MessageKeys.WRONG_PROPERTY_VALUE,
property.getName(), property.getValue().toString());
}
- return buffer.getInputStream();
+ return SerializerResultImpl.with().content(buffer.getInputStream()).build();
}
@Override
- public InputStream complex(final ServiceMetadata metadata, final EdmComplexType type,
+ public SerializerResult complex(final ServiceMetadata metadata, final EdmComplexType type,
final Property property, final ComplexSerializerOptions options) throws SerializerException {
final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL());
CircleStreamBuffer buffer = new CircleStreamBuffer();
@@ -575,11 +576,11 @@ public class ODataJsonSerializer implements ODataSerializer {
throw new SerializerException("An I/O exception occurred.", e,
SerializerException.MessageKeys.IO_EXCEPTION);
}
- return buffer.getInputStream();
+ return SerializerResultImpl.with().content(buffer.getInputStream()).build();
}
@Override
- public InputStream primitiveCollection(final EdmPrimitiveType type, final Property property,
+ public SerializerResult primitiveCollection(final EdmPrimitiveType type, final Property property,
final PrimitiveSerializerOptions options) throws SerializerException {
final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL());
CircleStreamBuffer buffer = new CircleStreamBuffer();
@@ -604,11 +605,11 @@ public class ODataJsonSerializer implements ODataSerializer {
SerializerException.MessageKeys.WRONG_PROPERTY_VALUE,
property.getName(), property.getValue().toString());
}
- return buffer.getInputStream();
+ return SerializerResultImpl.with().content(buffer.getInputStream()).build();
}
@Override
- public InputStream complexCollection(final ServiceMetadata metadata, final EdmComplexType type,
+ public SerializerResult complexCollection(final ServiceMetadata metadata, final EdmComplexType type,
final Property property, final ComplexSerializerOptions options) throws SerializerException {
final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL());
CircleStreamBuffer buffer = new CircleStreamBuffer();
@@ -630,6 +631,6 @@ public class ODataJsonSerializer implements ODataSerializer {
SerializerException.MessageKeys.WRONG_PROPERTY_VALUE,
property.getName(), property.getValue().toString());
}
- return buffer.getInputStream();
+ return SerializerResultImpl.with().content(buffer.getInputStream()).build();
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerImpl.java
index 34756c1..6143727 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerImpl.java
@@ -18,8 +18,6 @@
*/
package org.apache.olingo.server.core.serializer.xml;
-import java.io.InputStream;
-
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
@@ -39,6 +37,8 @@ import org.apache.olingo.server.api.serializer.EntitySerializerOptions;
import org.apache.olingo.server.api.serializer.ODataSerializer;
import org.apache.olingo.server.api.serializer.PrimitiveSerializerOptions;
import org.apache.olingo.server.api.serializer.SerializerException;
+import org.apache.olingo.server.api.serializer.SerializerResult;
+import org.apache.olingo.server.core.serializer.SerializerResultImpl;
import org.apache.olingo.server.core.serializer.utils.CircleStreamBuffer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -51,13 +51,13 @@ public class ODataXmlSerializerImpl implements ODataSerializer {
private static final Logger log = LoggerFactory.getLogger(ODataXmlSerializerImpl.class);
@Override
- public InputStream serviceDocument(final Edm edm, final String serviceRoot) throws SerializerException {
+ public SerializerResultImpl serviceDocument(final Edm edm, final String serviceRoot) throws SerializerException {
throw new SerializerException("Service Document not implemented for XML format",
SerializerException.MessageKeys.NOT_IMPLEMENTED);
}
@Override
- public InputStream metadataDocument(final ServiceMetadata serviceMetadata) throws SerializerException {
+ public SerializerResult metadataDocument(final ServiceMetadata serviceMetadata) throws SerializerException {
CircleStreamBuffer buffer;
XMLStreamWriter xmlStreamWriter = null;
@@ -69,7 +69,7 @@ public class ODataXmlSerializerImpl implements ODataSerializer {
xmlStreamWriter.flush();
xmlStreamWriter.close();
- return buffer.getInputStream();
+ return SerializerResultImpl.with().content(buffer.getInputStream()).build();
} catch (final XMLStreamException e) {
log.error(e.getMessage(), e);
throw new SerializerException("An I/O exception occurred.", e,
@@ -87,14 +87,14 @@ public class ODataXmlSerializerImpl implements ODataSerializer {
}
@Override
- public InputStream entity(final ServiceMetadata metadata, final EdmEntityType entityType,
+ public SerializerResult entity(final ServiceMetadata metadata, final EdmEntityType entityType,
final Entity entity, final EntitySerializerOptions options) throws SerializerException {
throw new SerializerException("Entity serialization not implemented for XML format",
SerializerException.MessageKeys.NOT_IMPLEMENTED);
}
@Override
- public InputStream entityCollection(final ServiceMetadata metadata,
+ public SerializerResult entityCollection(final ServiceMetadata metadata,
final EdmEntityType entityType, final EntitySet entitySet,
final EntityCollectionSerializerOptions options) throws SerializerException {
throw new SerializerException("Entityset serialization not implemented for XML format",
@@ -102,34 +102,34 @@ public class ODataXmlSerializerImpl implements ODataSerializer {
}
@Override
- public InputStream error(ODataServerError error) throws SerializerException {
+ public SerializerResult error(ODataServerError error) throws SerializerException {
throw new SerializerException("error serialization not implemented for XML format",
SerializerException.MessageKeys.NOT_IMPLEMENTED);
}
@Override
- public InputStream primitive(final EdmPrimitiveType type, final Property property,
+ public SerializerResult primitive(final EdmPrimitiveType type, final Property property,
final PrimitiveSerializerOptions options) throws SerializerException {
throw new SerializerException("Serialization not implemented for XML format.",
SerializerException.MessageKeys.NOT_IMPLEMENTED);
}
@Override
- public InputStream complex(final ServiceMetadata metadata, final EdmComplexType type,
+ public SerializerResult complex(final ServiceMetadata metadata, final EdmComplexType type,
final Property property, final ComplexSerializerOptions options) throws SerializerException {
throw new SerializerException("Serialization not implemented for XML format.",
SerializerException.MessageKeys.NOT_IMPLEMENTED);
}
@Override
- public InputStream primitiveCollection(final EdmPrimitiveType type, final Property property,
+ public SerializerResult primitiveCollection(final EdmPrimitiveType type, final Property property,
final PrimitiveSerializerOptions options) throws SerializerException {
throw new SerializerException("Serialization not implemented for XML format.",
SerializerException.MessageKeys.NOT_IMPLEMENTED);
}
@Override
- public InputStream complexCollection(final ServiceMetadata metadata, final EdmComplexType type,
+ public SerializerResult complexCollection(final ServiceMetadata metadata, final EdmComplexType type,
final Property property, final ComplexSerializerOptions options) throws SerializerException {
throw new SerializerException("Serialization not implemented for XML format.",
SerializerException.MessageKeys.NOT_IMPLEMENTED);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerBasicTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerBasicTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerBasicTest.java
index a301c3d..b63181d 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerBasicTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerBasicTest.java
@@ -57,7 +57,8 @@ public class ODataJsonDeserializerBasicTest {
" ]\n" +
"}";
ODataDeserializer deserializer = OData.newInstance().createDeserializer(ODataFormat.JSON);
- List<URI> values = deserializer.entityReferences(new ByteArrayInputStream(payload.getBytes()));
+ List<URI> values = deserializer.entityReferences(new ByteArrayInputStream(payload.getBytes()))
+ .getEntityReferences();
assertEquals(2, values.size());
assertEquals("Orders(10643)", values.get(0).toASCIIString());
assertEquals("Orders(10759)", values.get(1).toASCIIString());
@@ -71,7 +72,7 @@ public class ODataJsonDeserializerBasicTest {
"}";
ODataDeserializer deserializer = OData.newInstance().createDeserializer(ODataFormat.JSON);
List<URI> values = deserializer.entityReferences(new ByteArrayInputStream(payload
- .getBytes()));
+ .getBytes())).getEntityReferences();
assertEquals(1, values.size());
assertEquals("Orders(10643)", values.get(0).toASCIIString());
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataErrorSerializerTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataErrorSerializerTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataErrorSerializerTest.java
index 4e44db4..de5a25e 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataErrorSerializerTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataErrorSerializerTest.java
@@ -52,7 +52,7 @@ public class ODataErrorSerializerTest {
public void basicODataErrorNoCode() throws Exception {
ODataServerError error = new ODataServerError();
error.setMessage("ErrorMessage");
- InputStream stream = ser.error(error);
+ InputStream stream = ser.error(error).getContent();
String jsonString = IOUtils.toString(stream);
assertEquals("{\"error\":{\"code\":null,\"message\":\"ErrorMessage\"}}", jsonString);
}
@@ -61,7 +61,7 @@ public class ODataErrorSerializerTest {
public void basicODataErrorWithCode() throws Exception {
ODataServerError error = new ODataServerError();
error.setCode("Code").setMessage("ErrorMessage");
- InputStream stream = ser.error(error);
+ InputStream stream = ser.error(error).getContent();
String jsonString = IOUtils.toString(stream);
assertEquals("{\"error\":{\"code\":\"Code\",\"message\":\"ErrorMessage\"}}", jsonString);
}
@@ -70,7 +70,7 @@ public class ODataErrorSerializerTest {
public void basicODataErrorWithCodeAndTarget() throws Exception {
ODataServerError error = new ODataServerError();
error.setCode("Code").setMessage("ErrorMessage").setTarget("Target");
- InputStream stream = ser.error(error);
+ InputStream stream = ser.error(error).getContent();
String jsonString = IOUtils.toString(stream);
assertEquals("{\"error\":{\"code\":\"Code\",\"message\":\"ErrorMessage\",\"target\":\"Target\"}}", jsonString);
}
@@ -84,7 +84,7 @@ public class ODataErrorSerializerTest {
public void emptyDetailsList() throws Exception {
ODataServerError error = new ODataServerError();
error.setMessage("ErrorMessage").setDetails(new ArrayList<ODataErrorDetail>());
- InputStream stream = ser.error(error);
+ InputStream stream = ser.error(error).getContent();
String jsonString = IOUtils.toString(stream);
assertEquals("{\"error\":{\"code\":null,\"message\":\"ErrorMessage\",\"details\":[]}}", jsonString);
}
@@ -92,7 +92,7 @@ public class ODataErrorSerializerTest {
@Test
public void nothingSetAtODataErrorObject() throws Exception {
ODataServerError error = new ODataServerError();
- InputStream stream = ser.error(error);
+ InputStream stream = ser.error(error).getContent();
String jsonString = IOUtils.toString(stream);
assertEquals("{\"error\":{\"code\":null,\"message\":null}}", jsonString);
}
@@ -102,7 +102,7 @@ public class ODataErrorSerializerTest {
List<ODataErrorDetail> details = new ArrayList<ODataErrorDetail>();
details.add(new ODataErrorDetail());
ODataServerError error = new ODataServerError().setDetails(details);
- InputStream stream = ser.error(error);
+ InputStream stream = ser.error(error).getContent();
String jsonString = IOUtils.toString(stream);
assertEquals("{\"error\":{\"code\":null,\"message\":null,\"details\":[{\"code\":null,\"message\":null}]}}",
jsonString);
@@ -114,7 +114,7 @@ public class ODataErrorSerializerTest {
details.add(new ODataErrorDetail().setCode("detailCode").setMessage("detailMessage").setTarget("detailTarget"));
ODataServerError error =
new ODataServerError().setCode("Code").setMessage("Message").setTarget("Target").setDetails(details);
- InputStream stream = ser.error(error);
+ InputStream stream = ser.error(error).getContent();
JsonNode tree = new ObjectMapper().readTree(stream);
assertNotNull(tree);
tree = tree.get("error");
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
index 1e4537f..1fc89e8 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
@@ -50,7 +50,7 @@ public class ODataJsonSerializerTest {
final ComplexSerializerOptions options = ComplexSerializerOptions.with()
.contextURL(ContextURL.with().selectList("ComplexCollection").build()).build();
final InputStream in = serializer.complexCollection(null, ComplexTypeHelper.createType(),
- complexCollection, options);
+ complexCollection, options).getContent();
final BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String line;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializerTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializerTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializerTest.java
index d092ae9..a7bd86e 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializerTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializerTest.java
@@ -88,7 +88,7 @@ public class MetadataDocumentXmlSerializerTest {
assertEquals("<?xml version='1.0' encoding='UTF-8'?>"
+ "<edmx:Edmx Version=\"4.0\" xmlns:edmx=\"http://docs.oasis-open.org/odata/ns/edmx\">"
+ "<edmx:DataServices/></edmx:Edmx>",
- IOUtils.toString(serializer.metadataDocument(metadata)));
+ IOUtils.toString(serializer.metadataDocument(metadata).getContent()));
}
/** Writes simplest (empty) Schema. */
@@ -101,7 +101,7 @@ public class MetadataDocumentXmlSerializerTest {
ServiceMetadata serviceMetadata = mock(ServiceMetadata.class);
when(serviceMetadata.getEdm()).thenReturn(edm);
- InputStream metadata = serializer.metadataDocument(serviceMetadata);
+ InputStream metadata = serializer.metadataDocument(serviceMetadata).getContent();
assertNotNull(metadata);
assertEquals("<?xml version='1.0' encoding='UTF-8'?>" +
"<edmx:Edmx Version=\"4.0\" xmlns:edmx=\"http://docs.oasis-open.org/odata/ns/edmx\">" +
@@ -167,7 +167,7 @@ public class MetadataDocumentXmlSerializerTest {
when(serviceMetadata.getEdm()).thenReturn(edm);
when(serviceMetadata.getReferences()).thenReturn(edmxReferences);
- InputStream metadata = serializer.metadataDocument(serviceMetadata);
+ InputStream metadata = serializer.metadataDocument(serviceMetadata).getContent();
assertNotNull(metadata);
final String metadataString = IOUtils.toString(metadata);
// edmx reference
@@ -214,7 +214,7 @@ public class MetadataDocumentXmlSerializerTest {
public void aliasTest() throws Exception {
EdmProvider provider = new LocalProvider();
ServiceMetadata serviceMetadata = new ServiceMetadataImpl(provider, Collections.<EdmxReference> emptyList());
- InputStream metadataStream = serializer.metadataDocument(serviceMetadata);
+ InputStream metadataStream = serializer.metadataDocument(serviceMetadata).getContent();
String metadata = IOUtils.toString(metadataStream);
assertNotNull(metadata);
@@ -255,7 +255,7 @@ public class MetadataDocumentXmlSerializerTest {
when(schema.getComplexTypes()).thenReturn(complexTypes);
- InputStream metadataStream = serializer.metadataDocument(serviceMetadata);
+ InputStream metadataStream = serializer.metadataDocument(serviceMetadata).getContent();
String metadata = IOUtils.toString(metadataStream);
assertTrue(metadata.contains("<ComplexType Name=\"ComplexType\" Abstract=\"true\">"
+ "<Property Name=\"prop1\" Type=\"Edm.String\"/>"