[OLINGO-507] server support for property delete Change-Id: Ie2c3107204f59d34e37d919d275a2e0cf998cb3f
Signed-off-by: Christian Amend <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/6d9ac226 Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/6d9ac226 Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/6d9ac226 Branch: refs/heads/master Commit: 6d9ac226df3dead8e4f781247d249545362fb378 Parents: 8f794ac Author: Klaus Straubinger <[email protected]> Authored: Wed Dec 17 15:45:42 2014 +0100 Committer: Christian Amend <[email protected]> Committed: Wed Dec 17 15:49:34 2014 +0100 ---------------------------------------------------------------------- .../olingo/fit/tecsvc/client/BasicITCase.java | 114 ---------- .../olingo/fit/tecsvc/client/MediaITCase.java | 2 + .../tecsvc/client/PrimitiveComplexITCase.java | 212 +++++++++++++++++++ .../TechnicalPrimitiveComplexProcessor.java | 127 ++++++----- 4 files changed, 284 insertions(+), 171 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6d9ac226/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java ---------------------------------------------------------------------- diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java index adb1d91..023729c 100644 --- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java @@ -32,15 +32,12 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; -import org.apache.commons.io.IOUtils; import org.apache.olingo.client.api.CommonODataClient; import org.apache.olingo.client.api.communication.ODataClientErrorException; import org.apache.olingo.client.api.communication.request.retrieve.EdmMetadataRequest; import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest; import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetRequest; -import org.apache.olingo.client.api.communication.request.retrieve.ODataPropertyRequest; import org.apache.olingo.client.api.communication.request.retrieve.ODataServiceDocumentRequest; -import org.apache.olingo.client.api.communication.request.retrieve.ODataValueRequest; import org.apache.olingo.client.api.communication.request.retrieve.XMLMetadataRequest; import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse; import org.apache.olingo.client.api.edm.xml.XMLMetadata; @@ -48,7 +45,6 @@ import org.apache.olingo.client.api.edm.xml.v4.Reference; import org.apache.olingo.client.api.v4.ODataClient; import org.apache.olingo.client.core.ODataClientFactory; import org.apache.olingo.commons.api.domain.ODataError; -import org.apache.olingo.commons.api.domain.ODataPrimitiveValue; import org.apache.olingo.commons.api.domain.ODataServiceDocument; import org.apache.olingo.commons.api.domain.v4.ODataAnnotation; import org.apache.olingo.commons.api.domain.v4.ODataEntity; @@ -192,116 +188,6 @@ public class BasicITCase extends AbstractBaseTestITCase { assertEquals(30112, iterator.next().asPrimitive().toValue()); } - @Test - public void readSimpleProperty() throws Exception { - ODataPropertyRequest<ODataProperty> request = getClient().getRetrieveRequestFactory() - .getPropertyRequest(getClient().newURIBuilder(SERVICE_URI) - .appendEntitySetSegment("ESTwoPrim") - .appendKeySegment(32766) - .appendPropertySegment("PropertyString") - .build()); - - assertNotNull(request); - - ODataRetrieveResponse<ODataProperty> response = request.execute(); - assertEquals(HttpStatusCode.OK.getStatusCode(), response.getStatusCode()); - assertThat(response.getContentType(), containsString(ContentType.APPLICATION_JSON.toContentTypeString())); - - final ODataProperty property = response.getBody(); - assertNotNull(property); - assertNotNull(property.getPrimitiveValue()); - assertEquals("Test String1", property.getPrimitiveValue().toValue()); - } - - @Test - public void readSimplePropertyContextURL() throws Exception { - ODataPropertyRequest<ODataProperty> request = getClient().getRetrieveRequestFactory() - .getPropertyRequest(getClient().newURIBuilder(SERVICE_URI) - .appendEntitySetSegment("ESTwoPrim") - .appendKeySegment(32766) - .appendPropertySegment("PropertyString") - .build()); - ODataRetrieveResponse<ODataProperty> response = request.execute(); - String expectedResult = - "{\"@odata.context\":\"$metadata#ESTwoPrim(32766)/PropertyString\"," + - "\"value\":\"Test String1\"}"; - assertEquals(expectedResult, IOUtils.toString(response.getRawResponse(), "UTF-8")); - } - - @Test - public void readComplexProperty() throws Exception { - ODataPropertyRequest<ODataProperty> request = getClient().getRetrieveRequestFactory() - .getPropertyRequest(getClient().newURIBuilder(SERVICE_URI) - .appendEntitySetSegment("ESMixPrimCollComp") - .appendKeySegment(7) - .appendPropertySegment("PropertyComp") - .build()); - ODataRetrieveResponse<ODataProperty> response = request.execute(); - assertEquals(HttpStatusCode.OK.getStatusCode(), response.getStatusCode()); - assertThat(response.getContentType(), containsString(ContentType.APPLICATION_JSON.toContentTypeString())); - - final ODataProperty property = response.getBody(); - assertNotNull(property); - assertNotNull(property.getComplexValue()); - assertEquals("TEST B", property.getComplexValue().get("PropertyString").getPrimitiveValue().toValue()); - } - - @Test - public void readComplexPropertyContextURL() throws Exception { - ODataPropertyRequest<ODataProperty> request = getClient().getRetrieveRequestFactory() - .getPropertyRequest(getClient().newURIBuilder(SERVICE_URI) - .appendEntitySetSegment("ESMixPrimCollComp") - .appendKeySegment(7) - .appendPropertySegment("PropertyComp") - .build()); - ODataRetrieveResponse<ODataProperty> response = request.execute(); - String expectedResult = - "{\"@odata.context\":\"$metadata#ESMixPrimCollComp(7)/PropertyComp\"," + - "\"PropertyInt16\":222,\"PropertyString\":\"TEST B\"}"; - assertEquals(expectedResult, IOUtils.toString(response.getRawResponse(), "UTF-8")); - } - - @Test - public void readUnknownProperty() throws Exception { - ODataPropertyRequest<ODataProperty> request = getClient().getRetrieveRequestFactory() - .getPropertyRequest(getClient().newURIBuilder(SERVICE_URI) - .appendEntitySetSegment("ESTwoPrim") - .appendKeySegment(32766) - .appendPropertySegment("Unknown") - .build()); - try { - request.execute(); - fail("Expected exception not thrown!"); - } catch (final ODataClientErrorException e) { - assertEquals(HttpStatusCode.NOT_FOUND.getStatusCode(), e.getStatusLine().getStatusCode()); - } - } - - @Test - public void readNoContentProperty() throws Exception { - ODataPropertyRequest<ODataProperty> request = getClient().getRetrieveRequestFactory() - .getPropertyRequest(getClient().newURIBuilder(SERVICE_URI) - .appendEntitySetSegment("ESTwoPrim") - .appendKeySegment(-32766) - .appendPropertySegment("PropertyString") - .build()); - ODataRetrieveResponse<ODataProperty> response = request.execute(); - assertEquals(HttpStatusCode.NO_CONTENT.getStatusCode(), response.getStatusCode()); - } - - @Test - public void readPropertyValue() throws Exception { - final ODataValueRequest request = getClient().getRetrieveRequestFactory() - .getPropertyValueRequest(getClient().newURIBuilder(SERVICE_URI) - .appendEntitySetSegment("ESTwoPrim") - .appendKeySegment(32766) - .appendPropertySegment("PropertyString") - .appendValueSegment() - .build()); - ODataRetrieveResponse<ODataPrimitiveValue> response = request.execute(); - assertEquals("Test String1", response.getBody().toValue()); - } - @Override protected CommonODataClient<?> getClient() { ODataClient odata = ODataClientFactory.getV4(); http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6d9ac226/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/MediaITCase.java ---------------------------------------------------------------------- diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/MediaITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/MediaITCase.java index e7e4f78..18fa834 100644 --- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/MediaITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/MediaITCase.java @@ -22,6 +22,7 @@ import static org.hamcrest.CoreMatchers.startsWith; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; +import static org.junit.Assert.fail; import java.io.InputStream; import java.net.URI; @@ -85,6 +86,7 @@ public final class MediaITCase extends AbstractBaseTestITCase { mediaRequest.addCustomHeader(HttpHeader.COOKIE, response.getHeader(HttpHeader.SET_COOKIE).iterator().next()); try { mediaRequest.execute(); + fail("Expected exception not thrown!"); } catch (final ODataClientErrorException e) { assertEquals(HttpStatusCode.NOT_FOUND.getStatusCode(), e.getStatusLine().getStatusCode()); } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6d9ac226/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/PrimitiveComplexITCase.java ---------------------------------------------------------------------- diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/PrimitiveComplexITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/PrimitiveComplexITCase.java new file mode 100644 index 0000000..0e4fe17 --- /dev/null +++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/PrimitiveComplexITCase.java @@ -0,0 +1,212 @@ +/* + * 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.fit.tecsvc.client; + +import static org.hamcrest.CoreMatchers.containsString; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.fail; + +import java.net.URI; + +import org.apache.commons.io.IOUtils; +import org.apache.olingo.client.api.CommonODataClient; +import org.apache.olingo.client.api.communication.ODataClientErrorException; +import org.apache.olingo.client.api.communication.request.cud.ODataDeleteRequest; +import org.apache.olingo.client.api.communication.request.retrieve.ODataPropertyRequest; +import org.apache.olingo.client.api.communication.request.retrieve.ODataValueRequest; +import org.apache.olingo.client.api.communication.response.ODataDeleteResponse; +import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse; +import org.apache.olingo.client.api.v4.ODataClient; +import org.apache.olingo.client.core.ODataClientFactory; +import org.apache.olingo.commons.api.domain.ODataPrimitiveValue; +import org.apache.olingo.commons.api.domain.v4.ODataProperty; +import org.apache.olingo.commons.api.format.ContentType; +import org.apache.olingo.commons.api.format.ODataFormat; +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.Test; + +public class PrimitiveComplexITCase extends AbstractBaseTestITCase { + + private static final String SERVICE_URI = TecSvcConst.BASE_URI; + + @Test + public void readSimpleProperty() throws Exception { + ODataPropertyRequest<ODataProperty> request = getClient().getRetrieveRequestFactory() + .getPropertyRequest(getClient().newURIBuilder(SERVICE_URI) + .appendEntitySetSegment("ESTwoPrim") + .appendKeySegment(32766) + .appendPropertySegment("PropertyString") + .build()); + + assertNotNull(request); + + ODataRetrieveResponse<ODataProperty> response = request.execute(); + assertEquals(HttpStatusCode.OK.getStatusCode(), response.getStatusCode()); + assertThat(response.getContentType(), containsString(ContentType.APPLICATION_JSON.toContentTypeString())); + + final ODataProperty property = response.getBody(); + assertNotNull(property); + assertNotNull(property.getPrimitiveValue()); + assertEquals("Test String1", property.getPrimitiveValue().toValue()); + } + + @Test + public void readSimplePropertyContextURL() throws Exception { + ODataPropertyRequest<ODataProperty> request = getClient().getRetrieveRequestFactory() + .getPropertyRequest(getClient().newURIBuilder(SERVICE_URI) + .appendEntitySetSegment("ESTwoPrim") + .appendKeySegment(32766) + .appendPropertySegment("PropertyString") + .build()); + ODataRetrieveResponse<ODataProperty> response = request.execute(); + String expectedResult = + "{\"@odata.context\":\"$metadata#ESTwoPrim(32766)/PropertyString\"," + + "\"value\":\"Test String1\"}"; + assertEquals(expectedResult, IOUtils.toString(response.getRawResponse(), "UTF-8")); + } + + @Test + public void deletePrimitive() throws Exception { + final URI uri = getClient().newURIBuilder(SERVICE_URI) + .appendEntitySetSegment("ESTwoPrim").appendKeySegment(32766).appendPropertySegment("PropertyString") + .build(); + final ODataDeleteRequest request = getClient().getCUDRequestFactory().getDeleteRequest(uri); + final ODataDeleteResponse response = request.execute(); + assertEquals(HttpStatusCode.NO_CONTENT.getStatusCode(), response.getStatusCode()); + + // Check that the property is really gone. + // This check has to be in the same session in order to access the same data provider. + ODataPropertyRequest<ODataProperty> propertyRequest = getClient().getRetrieveRequestFactory() + .getPropertyRequest(uri); + propertyRequest.addCustomHeader(HttpHeader.COOKIE, response.getHeader(HttpHeader.SET_COOKIE).iterator().next()); + assertEquals(HttpStatusCode.NO_CONTENT.getStatusCode(), propertyRequest.execute().getStatusCode()); + + try { + getClient().getCUDRequestFactory().getDeleteRequest(getClient().newURIBuilder(SERVICE_URI) + .appendEntitySetSegment("ESTwoPrim").appendKeySegment(32766).appendPropertySegment("PropertyInt16") + .build()).execute(); + fail("Expected exception not thrown!"); + } catch (final ODataClientErrorException e) { + assertEquals(HttpStatusCode.BAD_REQUEST.getStatusCode(), e.getStatusLine().getStatusCode()); + } + } + + @Test + public void readComplexProperty() throws Exception { + ODataPropertyRequest<ODataProperty> request = getClient().getRetrieveRequestFactory() + .getPropertyRequest(getClient().newURIBuilder(SERVICE_URI) + .appendEntitySetSegment("ESMixPrimCollComp") + .appendKeySegment(7) + .appendPropertySegment("PropertyComp") + .build()); + ODataRetrieveResponse<ODataProperty> response = request.execute(); + assertEquals(HttpStatusCode.OK.getStatusCode(), response.getStatusCode()); + assertThat(response.getContentType(), containsString(ContentType.APPLICATION_JSON.toContentTypeString())); + + final ODataProperty property = response.getBody(); + assertNotNull(property); + assertNotNull(property.getComplexValue()); + assertEquals("TEST B", property.getComplexValue().get("PropertyString").getPrimitiveValue().toValue()); + } + + @Test + public void readComplexPropertyContextURL() throws Exception { + ODataPropertyRequest<ODataProperty> request = getClient().getRetrieveRequestFactory() + .getPropertyRequest(getClient().newURIBuilder(SERVICE_URI) + .appendEntitySetSegment("ESMixPrimCollComp") + .appendKeySegment(7) + .appendPropertySegment("PropertyComp") + .build()); + ODataRetrieveResponse<ODataProperty> response = request.execute(); + String expectedResult = + "{\"@odata.context\":\"$metadata#ESMixPrimCollComp(7)/PropertyComp\"," + + "\"PropertyInt16\":222,\"PropertyString\":\"TEST B\"}"; + assertEquals(expectedResult, IOUtils.toString(response.getRawResponse(), "UTF-8")); + } + + @Test + public void deleteComplex() throws Exception { + final URI uri = getClient().newURIBuilder(SERVICE_URI) + .appendEntitySetSegment("ESMixPrimCollComp").appendKeySegment(7).appendPropertySegment("PropertyComp") + .build(); + final ODataDeleteRequest request = getClient().getCUDRequestFactory().getDeleteRequest(uri); + final ODataDeleteResponse response = request.execute(); + assertEquals(HttpStatusCode.NO_CONTENT.getStatusCode(), response.getStatusCode()); + + // Check that the property is really gone. + // This check has to be in the same session in order to access the same data provider. + ODataPropertyRequest<ODataProperty> propertyRequest = getClient().getRetrieveRequestFactory() + .getPropertyRequest(uri); + propertyRequest.addCustomHeader(HttpHeader.COOKIE, response.getHeader(HttpHeader.SET_COOKIE).iterator().next()); + assertEquals(HttpStatusCode.NO_CONTENT.getStatusCode(), propertyRequest.execute().getStatusCode()); + } + + @Test + public void readUnknownProperty() throws Exception { + ODataPropertyRequest<ODataProperty> request = getClient().getRetrieveRequestFactory() + .getPropertyRequest(getClient().newURIBuilder(SERVICE_URI) + .appendEntitySetSegment("ESTwoPrim") + .appendKeySegment(32766) + .appendPropertySegment("Unknown") + .build()); + try { + request.execute(); + fail("Expected exception not thrown!"); + } catch (final ODataClientErrorException e) { + assertEquals(HttpStatusCode.NOT_FOUND.getStatusCode(), e.getStatusLine().getStatusCode()); + } + } + + @Test + public void readNoContentProperty() throws Exception { + ODataPropertyRequest<ODataProperty> request = getClient().getRetrieveRequestFactory() + .getPropertyRequest(getClient().newURIBuilder(SERVICE_URI) + .appendEntitySetSegment("ESTwoPrim") + .appendKeySegment(-32766) + .appendPropertySegment("PropertyString") + .build()); + ODataRetrieveResponse<ODataProperty> response = request.execute(); + assertEquals(HttpStatusCode.NO_CONTENT.getStatusCode(), response.getStatusCode()); + } + + @Test + public void readPropertyValue() throws Exception { + final ODataValueRequest request = getClient().getRetrieveRequestFactory() + .getPropertyValueRequest(getClient().newURIBuilder(SERVICE_URI) + .appendEntitySetSegment("ESTwoPrim") + .appendKeySegment(32766) + .appendPropertySegment("PropertyString") + .appendValueSegment() + .build()); + ODataRetrieveResponse<ODataPrimitiveValue> response = request.execute(); + assertEquals("Test String1", response.getBody().toValue()); + } + + @Override + protected CommonODataClient<?> getClient() { + ODataClient odata = ODataClientFactory.getV4(); + odata.getConfiguration().setDefaultPubFormat(ODataFormat.JSON); + return odata; + } +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6d9ac226/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 94d7257..1cb7691 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 @@ -67,8 +67,8 @@ 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, PrimitiveValueProcessor, PrimitiveCollectionProcessor, - ComplexProcessor, ComplexCollectionProcessor { + implements PrimitiveProcessor, PrimitiveValueProcessor, PrimitiveCollectionProcessor, + ComplexProcessor, ComplexCollectionProcessor { public TechnicalPrimitiveComplexProcessor(final DataProvider dataProvider) { super(dataProvider); @@ -76,22 +76,21 @@ public class TechnicalPrimitiveComplexProcessor extends TechnicalProcessor @Override public void readPrimitive(final ODataRequest request, ODataResponse response, final UriInfo uriInfo, - final ContentType contentType) throws ODataApplicationException, SerializerException { + final ContentType contentType) throws ODataApplicationException, SerializerException { readProperty(response, uriInfo, contentType, RepresentationType.PRIMITIVE); } @Override - public void updatePrimitive(final ODataRequest request, final ODataResponse response, - final UriInfo uriInfo, final ContentType requestFormat, - final ContentType responseFormat) - throws ODataApplicationException, DeserializerException, SerializerException { + public void updatePrimitive(final ODataRequest request, ODataResponse response, final UriInfo uriInfo, + final ContentType requestFormat, final ContentType responseFormat) + throws ODataApplicationException, DeserializerException, SerializerException { throw new UnsupportedOperationException("Actual not yet supported"); } @Override - public void deletePrimitive(ODataRequest request, ODataResponse response, UriInfo uriInfo) throws - ODataApplicationException { - throw new UnsupportedOperationException("Actual not yet supported"); + public void deletePrimitive(final ODataRequest request, ODataResponse response, final UriInfo uriInfo) + throws ODataApplicationException { + deleteProperty(response, uriInfo); } @Override @@ -102,36 +101,34 @@ public class TechnicalPrimitiveComplexProcessor extends TechnicalProcessor @Override public void updatePrimitiveCollection(final ODataRequest request, final ODataResponse response, - final UriInfo uriInfo, final ContentType requestFormat, - final ContentType responseFormat) - throws ODataApplicationException, DeserializerException, SerializerException { + final UriInfo uriInfo, final ContentType requestFormat, final ContentType responseFormat) + throws ODataApplicationException, DeserializerException, SerializerException { throw new UnsupportedOperationException("Actual not yet supported"); } @Override - public void deletePrimitiveCollection(final ODataRequest request, final ODataResponse response, - final UriInfo uriInfo) throws ODataApplicationException { - throw new UnsupportedOperationException("Actual not yet supported"); + public void deletePrimitiveCollection(final ODataRequest request, ODataResponse response, final UriInfo uriInfo) + throws ODataApplicationException { + deleteProperty(response, uriInfo); } @Override public void readComplex(final ODataRequest request, ODataResponse response, final UriInfo uriInfo, - final ContentType contentType) throws ODataApplicationException, SerializerException { + final ContentType contentType) throws ODataApplicationException, SerializerException { readProperty(response, uriInfo, contentType, RepresentationType.COMPLEX); } @Override - public void updateComplex(final ODataRequest request, final ODataResponse response, - final UriInfo uriInfo, final ContentType requestFormat, - final ContentType responseFormat) - throws ODataApplicationException, DeserializerException, SerializerException { + public void updateComplex(final ODataRequest request, final ODataResponse response, final UriInfo uriInfo, + final ContentType requestFormat, final ContentType responseFormat) + throws ODataApplicationException, DeserializerException, SerializerException { throw new UnsupportedOperationException("Actual not yet supported"); } @Override public void deleteComplex(final ODataRequest request, final ODataResponse response, final UriInfo uriInfo) - throws ODataApplicationException { - throw new UnsupportedOperationException("Actual not yet supported"); + throws ODataApplicationException { + deleteProperty(response, uriInfo); } @Override @@ -141,22 +138,20 @@ public class TechnicalPrimitiveComplexProcessor extends TechnicalProcessor } @Override - public void updateComplexCollection(final ODataRequest request, final ODataResponse response, - final UriInfo uriInfo, final ContentType requestFormat, - final ContentType responseFormat) - throws ODataApplicationException, DeserializerException, SerializerException { + public void updateComplexCollection(final ODataRequest request, final ODataResponse response, final UriInfo uriInfo, + final ContentType requestFormat, final ContentType responseFormat) + throws ODataApplicationException, DeserializerException, SerializerException { throw new UnsupportedOperationException("Actual not yet supported"); } @Override - public void deleteComplexCollection(final ODataRequest request, final ODataResponse response, final UriInfo uriInfo) - throws ODataApplicationException { - throw new UnsupportedOperationException("Actual not yet supported"); + public void deleteComplexCollection(final ODataRequest request, ODataResponse response, final UriInfo uriInfo) + throws ODataApplicationException { + deleteProperty(response, uriInfo); } private void readProperty(final ODataResponse response, final UriInfo uriInfo, final ContentType contentType, - final RepresentationType representationType) - throws ODataApplicationException, SerializerException { + final RepresentationType representationType) throws ODataApplicationException, SerializerException { final UriInfoResource resource = uriInfo.asUriInfoResource(); validateOptions(resource); validatePath(resource); @@ -182,34 +177,33 @@ public class TechnicalPrimitiveComplexProcessor extends TechnicalProcessor final SelectOption select = uriInfo.getSelectOption(); final UriHelper helper = odata.createUriHelper(); final ContextURL contextURL = format == ODataFormat.JSON_NO_METADATA ? null : - ContextURL.with().entitySet(edmEntitySet) - .keyPath(helper.buildContextURLKeyPredicate( - ((UriResourceEntitySet) resourceParts.get(0)).getKeyPredicates())) - .navOrPropertyPath(buildPropertyPath(path)) - .selectList(edmProperty.isPrimitive() ? null : - helper.buildContextURLSelectList((EdmStructuredType) edmProperty.getType(), expand, - select)) - .build(); + ContextURL.with().entitySet(edmEntitySet) + .keyPath(helper.buildContextURLKeyPredicate( + ((UriResourceEntitySet) resourceParts.get(0)).getKeyPredicates())) + .navOrPropertyPath(buildPropertyPath(path)) + .selectList(edmProperty.isPrimitive() ? null : + helper.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())); + 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())); + 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())); + 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())); + ComplexSerializerOptions.with().contextURL(contextURL) + .expand(expand).select(select) + .build())); break; default: break; @@ -220,6 +214,25 @@ public class TechnicalPrimitiveComplexProcessor extends TechnicalProcessor } } + private void deleteProperty(final ODataResponse response, final UriInfo uriInfo) throws ODataApplicationException { + final UriInfoResource resource = uriInfo.asUriInfoResource(); + validatePath(resource); + + final List<UriResource> resourceParts = resource.getUriResourceParts(); + final UriResourceEntitySet resourceEntitySet = (UriResourceEntitySet) resourceParts.get(0); + final List<String> path = getPropertyPath(resourceParts); + + final EdmProperty edmProperty = ((UriResourceProperty) resourceParts.get(path.size())).getProperty(); + final Property property = getPropertyData(resourceEntitySet, path); + + if (edmProperty.isNullable() == null || edmProperty.isNullable()) { + property.setValue(property.getValueType(), null); + response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode()); + } else { + throw new ODataApplicationException("Not nullable.", HttpStatusCode.BAD_REQUEST.getStatusCode(), Locale.ROOT); + } + } + private Property getPropertyData(final UriResourceEntitySet resourceEntitySet, final List<String> path) throws ODataApplicationException { final Entity entity = dataProvider.read(resourceEntitySet.getEntitySet(), resourceEntitySet.getKeyPredicates()); @@ -230,7 +243,7 @@ public class TechnicalPrimitiveComplexProcessor extends TechnicalProcessor for (final String name : path.subList(1, path.size())) { if (property != null && (property.isLinkedComplex() || property.isComplex())) { final List<Property> complex = property.isLinkedComplex() ? - property.asLinkedComplex().getValue() : property.asComplex(); + property.asLinkedComplex().getValue() : property.asComplex(); property = null; for (final Property innerProperty : complex) { if (innerProperty.getName().equals(name)) { @@ -264,7 +277,7 @@ public class TechnicalPrimitiveComplexProcessor extends TechnicalProcessor @Override public void readPrimitiveValue(final ODataRequest request, ODataResponse response, final UriInfo uriInfo, - final ContentType contentType) throws ODataApplicationException, SerializerException { + final ContentType contentType) throws ODataApplicationException, SerializerException { final UriInfoResource resource = uriInfo.asUriInfoResource(); validateOptions(resource); validatePath(resource); @@ -282,9 +295,9 @@ public class TechnicalPrimitiveComplexProcessor extends TechnicalProcessor final EdmPrimitiveType type = (EdmPrimitiveType) edmProperty.getType(); 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())); + 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()); } @@ -295,11 +308,11 @@ public class TechnicalPrimitiveComplexProcessor extends TechnicalProcessor for (final UriResource segment : resourcePaths.subList(1, resourcePaths.size())) { final UriResourceKind kind = segment.getKind(); if (kind != UriResourceKind.primitiveProperty - && kind != UriResourceKind.complexProperty - && kind != UriResourceKind.count - && kind != UriResourceKind.value) { + && kind != UriResourceKind.complexProperty + && kind != UriResourceKind.count + && kind != UriResourceKind.value) { throw new ODataApplicationException("Invalid resource type.", - HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ROOT); + HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ROOT); } } }
