Repository: olingo-odata4 Updated Branches: refs/heads/master 118b779bc -> e8ac1c749
[OLINGO-259] Request / Response handling + test Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/e8ac1c74 Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/e8ac1c74 Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/e8ac1c74 Branch: refs/heads/master Commit: e8ac1c749b01e9c28864ddbbb530b2ea3065d85d Parents: 118b779 Author: Francesco Chicchiriccò <[email protected]> Authored: Mon Apr 28 18:13:34 2014 +0200 Committer: Francesco Chicchiriccò <[email protected]> Committed: Mon Apr 28 18:13:34 2014 +0200 ---------------------------------------------------------------------- .../java/org/apache/olingo/fit/V4Services.java | 30 +++++++ fit/src/main/resources/V40/delta.full.json | 39 +++++++++ fit/src/main/resources/V40/delta.xml | 87 ++++++++++++++++++++ .../request/retrieve/ODataEntityRequest.java | 2 +- .../request/retrieve/v4/ODataDeltaRequest.java | 29 +++++++ .../retrieve/v4/RetrieveRequestFactory.java | 2 + .../olingo/client/api/op/v4/ODataBinder.java | 4 + .../retrieve/ODataPropertyRequestImpl.java | 8 +- .../retrieve/v4/ODataDeltaRequestImpl.java | 81 ++++++++++++++++++ .../retrieve/v4/RetrieveRequestFactoryImpl.java | 6 ++ .../client/core/op/impl/v4/ODataBinderImpl.java | 59 +++++++++++++ .../client/core/it/v4/DeltaTestITCase.java | 78 ++++++++++++++++++ .../apache/olingo/client/core/v4/JSONTest.java | 2 +- .../olingo/commons/api/data/DeletedEntity.java | 13 ++- .../commons/api/domain/v4/ODataDelta.java | 48 +++++++++++ .../api/domain/v4/ODataObjectFactory.java | 4 + .../commons/core/data/AtomDeserializer.java | 5 +- .../commons/core/data/DeletedEntityImpl.java | 13 +-- .../commons/core/domain/v4/ODataDeltaImpl.java | 73 ++++++++++++++++ .../core/domain/v4/ODataObjectFactoryImpl.java | 11 +++ 20 files changed, 575 insertions(+), 19 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e8ac1c74/fit/src/main/java/org/apache/olingo/fit/V4Services.java ---------------------------------------------------------------------- diff --git a/fit/src/main/java/org/apache/olingo/fit/V4Services.java b/fit/src/main/java/org/apache/olingo/fit/V4Services.java index 386d97b..40111ee 100644 --- a/fit/src/main/java/org/apache/olingo/fit/V4Services.java +++ b/fit/src/main/java/org/apache/olingo/fit/V4Services.java @@ -345,6 +345,36 @@ public class V4Services extends AbstractServices { } @GET + @Path("/Customers") + public Response getEntitySet( + @Context UriInfo uriInfo, + @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept, + @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format, + @QueryParam("$deltatoken") @DefaultValue(StringUtils.EMPTY) String deltatoken) { + + if (StringUtils.isBlank(deltatoken)) { + return getEntitySet(uriInfo, accept, "Customers", null, null, format, null, null, null, null); + } else { + try { + final Accept acceptType; + if (StringUtils.isNotBlank(format)) { + acceptType = Accept.valueOf(format.toUpperCase()); + } else { + acceptType = Accept.parse(accept, version); + } + + return xml.createResponse( + null, + FSManager.instance(version).readFile("delta", acceptType), + null, + acceptType); + } catch (Exception e) { + return xml.createFaultResponse(accept, e); + } + } + } + + @GET @Path("/Company/Microsoft.Test.OData.Services.ODataWCFService.GetEmployeesCount") public Response functionGetEmployeesCount( @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept, http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e8ac1c74/fit/src/main/resources/V40/delta.full.json ---------------------------------------------------------------------- diff --git a/fit/src/main/resources/V40/delta.full.json b/fit/src/main/resources/V40/delta.full.json new file mode 100644 index 0000000..58f109e --- /dev/null +++ b/fit/src/main/resources/V40/delta.full.json @@ -0,0 +1,39 @@ +{ + "@odata.context": "http://localhost:${cargo.servlet.port}/StaticService/V40/Static.svc/$metadata#Customers/$delta", + "@odata.count": 5, + "value": + [ + { + "@odata.id": "Customers('BOTTM')'", + "ContactName": "Susan Halvenstern" + }, + { + "@odata.context": "#Customers/$deletedLink", + "source": "Customers('ALFKI')", + "relationship": "Orders", + "target": "Orders(10643)" + }, + { + "@odata.context": "#Customers/$link", + "source": "Customers('BOTTM')", + "relationship": "Orders", + "target": "Orders(10645)" + }, + { + "@odata.context": "#Orders/$entity", + "@odata.id": "Orders(10643)", + "ShippingAddress": { + "Street": "23 Tsawassen Blvd.", + "City": " Tsawassen ", + "Region": "BC", + "PostalCode": "T2F 8M4" + } + }, + { + "@odata.context": "#Customers/$deletedEntity", + "id": "Customers('ANTON')", + "reason": "deleted" + } + ], + "@odata.deltaLink": "Customers?$expand=Orders&$deltatoken=8015" +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e8ac1c74/fit/src/main/resources/V40/delta.xml ---------------------------------------------------------------------- diff --git a/fit/src/main/resources/V40/delta.xml b/fit/src/main/resources/V40/delta.xml new file mode 100644 index 0000000..7fc6f7b --- /dev/null +++ b/fit/src/main/resources/V40/delta.xml @@ -0,0 +1,87 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + + 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. + +--> +<feed xml:base="http://localhost:${cargo.servlet.port}/StaticService/V40/Static.svc/" + xmlns:data="http://docs.oasis-open.org/odata/ns/data" + xmlns:metadata="http://docs.oasis-open.org/odata/ns/metadata" + xmlns="http://www.w3.org/2005/Atom" + xmlns:at="http://purl.org/atompub/tombstones/1.0" + metadata:context="$metadata#Customers/$delta"> + <title type="text">Customers</title> + <id>http://localhost:${cargo.servlet.port}/StaticService/V40/Static.svc/Customers</id> + <updated>2012-11-27T15:38:25Z</updated> + <metadata:count>5</metadata:count> + <entry> + <id>http://localhost:${cargo.servlet.port}/StaticService/V40/Static.svc/Customers('BOTTM')</id> + <title type="text" /> + <updated>2012-11-17T15:38:22Z</updated> + <author> + <name /> + </author> + <link rel="edit" title="Customer" href="Customers('BOTTM')"/> + <category term="#Model.Customer" + scheme="http://docs.oasis-open.org/odata/ns/scheme"/> + <content type="application/xml"> + <metadata:properties> + <data:ContactName>Susan Halvenstern</data:ContactName> + </metadata:properties> + </content> + </entry> + <metadata:deleted-link + metadata:context="$metadata#Customers/$deleted-link" + source="http://localhost:${cargo.servlet.port}/StaticService/V40/Static.svc/Customers('ALFKI')" + relationship="Orders" + target="http://localhost:${cargo.servlet.port}/StaticService/V40/Static.svc/Orders(10643)"/> + <metadata:link + metadata:context="$metadata#Customers/$link" + source="http://localhost:${cargo.servlet.port}/StaticService/V40/Static.svc/Customers('BOTTM')" + relationship="Orders" + target="http://localhost:${cargo.servlet.port}/StaticService/V40/Static.svc/Orders(10645)"/> + <entry metadata:context="$metadata#Orders/$entity"> + <id>http://localhost:${cargo.servlet.port}/StaticService/V40/Static.svc/Orders(10643)</id> + <title type="text" /> + <updated>2012-11-27T15:38:24Z</updated> + <author> + <name/> + </author> + <link rel="edit" title="Order" href="Orders(10643)" /> + <category term="#Model.Order" + scheme="http://docs.oasis-open.org/odata/ns/scheme" /> + <content type="application/xml"> + <metadata:properties> + <data:ShippingAddress> + <data:Street>23 Tsawassen Blvd.</data:Street> + <data:City>Tsawassen</data:City> + <data:Region>BC</data:Region> + <data:PostalCode>T2F 8M4</data:PostalCode> + </data:ShippingAddress> + </metadata:properties> + </content> + </entry> + <at:deleted-entry + metadata:context="$metadata#Customers/$deleted-entry" + ref="http://localhost:${cargo.servlet.port}/StaticService/V40/Static.svc/Customers('ANTON')" + when="2012-11-27T15:38:25Z" + metadata:reason="deleted"/> + <link + rel="http://docs.oasis-open.org/odata/ns/delta" + href="http://localhost:${cargo.servlet.port}/StaticService/V40/Static.svc/Customers?$expand=Orders&$deltatoken=8015"/> +</feed> http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e8ac1c74/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/retrieve/ODataEntityRequest.java ---------------------------------------------------------------------- diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/retrieve/ODataEntityRequest.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/retrieve/ODataEntityRequest.java index 6fc7b09..1e65ae8 100644 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/retrieve/ODataEntityRequest.java +++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/retrieve/ODataEntityRequest.java @@ -22,7 +22,7 @@ import org.apache.olingo.commons.api.domain.CommonODataEntity; import org.apache.olingo.commons.api.format.ODataPubFormat; /** - * This class implements an OData retrieve query request returning a single entity. + * Describes an OData retrieve query request returning a single entity. */ public interface ODataEntityRequest<E extends CommonODataEntity> extends ODataRetrieveRequest<E, ODataPubFormat> { } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e8ac1c74/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/retrieve/v4/ODataDeltaRequest.java ---------------------------------------------------------------------- diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/retrieve/v4/ODataDeltaRequest.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/retrieve/v4/ODataDeltaRequest.java new file mode 100644 index 0000000..6f75d62 --- /dev/null +++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/retrieve/v4/ODataDeltaRequest.java @@ -0,0 +1,29 @@ +/* + * 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.client.api.communication.request.retrieve.v4; + +import org.apache.olingo.client.api.communication.request.retrieve.ODataRetrieveRequest; +import org.apache.olingo.commons.api.domain.v4.ODataDelta; +import org.apache.olingo.commons.api.format.ODataPubFormat; + +/** + * Describes an OData retrieve request returning a delta object. + */ +public interface ODataDeltaRequest extends ODataRetrieveRequest<ODataDelta, ODataPubFormat> { +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e8ac1c74/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/retrieve/v4/RetrieveRequestFactory.java ---------------------------------------------------------------------- diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/retrieve/v4/RetrieveRequestFactory.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/retrieve/v4/RetrieveRequestFactory.java index ab8dade..639ac68 100644 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/retrieve/v4/RetrieveRequestFactory.java +++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/retrieve/v4/RetrieveRequestFactory.java @@ -42,4 +42,6 @@ public interface RetrieveRequestFactory extends CommonRetrieveRequestFactory { @Override ODataPropertyRequest<ODataProperty> getPropertyRequest(URI uri); + + ODataDeltaRequest getDeltaRequest(URI uri); } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e8ac1c74/lib/client-api/src/main/java/org/apache/olingo/client/api/op/v4/ODataBinder.java ---------------------------------------------------------------------- diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/op/v4/ODataBinder.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/op/v4/ODataBinder.java index c6c53b3..0f5657f 100644 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/op/v4/ODataBinder.java +++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/op/v4/ODataBinder.java @@ -19,10 +19,12 @@ package org.apache.olingo.client.api.op.v4; import org.apache.olingo.client.api.op.CommonODataBinder; +import org.apache.olingo.commons.api.data.Delta; import org.apache.olingo.commons.api.data.Entity; import org.apache.olingo.commons.api.data.EntitySet; import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.commons.api.data.ResWrap; +import org.apache.olingo.commons.api.domain.v4.ODataDelta; import org.apache.olingo.commons.api.domain.v4.ODataEntity; import org.apache.olingo.commons.api.domain.v4.ODataEntitySet; import org.apache.olingo.commons.api.domain.v4.ODataProperty; @@ -37,4 +39,6 @@ public interface ODataBinder extends CommonODataBinder { @Override ODataProperty getODataProperty(ResWrap<Property> resource); + + ODataDelta getODataDelta(ResWrap<Delta> resource); } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e8ac1c74/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataPropertyRequestImpl.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataPropertyRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataPropertyRequestImpl.java index d97e7b3..f0d6924 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataPropertyRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataPropertyRequestImpl.java @@ -43,13 +43,10 @@ public class ODataPropertyRequestImpl<T extends CommonODataProperty> * @param odataClient client instance getting this request * @param query query to be executed. */ - public ODataPropertyRequestImpl(final CommonODataClient odataClient, final URI query) { + public ODataPropertyRequestImpl(final CommonODataClient<?> odataClient, final URI query) { super(odataClient, ODataFormat.class, query); } - /** - * {@inheritDoc } - */ @Override public ODataRetrieveResponse<T> execute() { final HttpResponse res = doExecute(); @@ -78,9 +75,6 @@ public class ODataPropertyRequestImpl<T extends CommonODataProperty> super(client, res); } - /** - * {@inheritDoc } - */ @Override @SuppressWarnings("unchecked") public T getBody() { http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e8ac1c74/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v4/ODataDeltaRequestImpl.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v4/ODataDeltaRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v4/ODataDeltaRequestImpl.java new file mode 100644 index 0000000..570eb36 --- /dev/null +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v4/ODataDeltaRequestImpl.java @@ -0,0 +1,81 @@ +/* + * 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.client.core.communication.request.retrieve.v4; + +import java.io.IOException; +import java.net.URI; +import org.apache.http.HttpResponse; +import org.apache.http.client.HttpClient; +import org.apache.olingo.client.api.CommonODataClient; +import org.apache.olingo.client.api.communication.request.retrieve.v4.ODataDeltaRequest; +import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse; +import org.apache.olingo.client.api.http.HttpClientException; +import org.apache.olingo.client.api.v4.ODataClient; +import org.apache.olingo.client.core.communication.request.retrieve.AbstractODataRetrieveRequest; +import org.apache.olingo.commons.api.data.Delta; +import org.apache.olingo.commons.api.data.ResWrap; +import org.apache.olingo.commons.api.domain.v4.ODataDelta; +import org.apache.olingo.commons.api.format.ODataPubFormat; + +public class ODataDeltaRequestImpl extends AbstractODataRetrieveRequest<ODataDelta, ODataPubFormat> + implements ODataDeltaRequest { + + public ODataDeltaRequestImpl(final CommonODataClient<?> odataClient, final URI query) { + super(odataClient, ODataPubFormat.class, query); + } + + @Override + public ODataRetrieveResponse<ODataDelta> execute() { + final HttpResponse res = doExecute(); + return new ODataDeltaResponseImpl(httpClient, res); + } + + protected class ODataDeltaResponseImpl extends AbstractODataRetrieveResponse { + + private ODataDelta delta = null; + + /** + * Constructor. + * + * @param client HTTP client. + * @param res HTTP response. + */ + private ODataDeltaResponseImpl(final HttpClient client, final HttpResponse res) { + super(client, res); + } + + @Override + public ODataDelta getBody() { + if (delta == null) { + try { + final ResWrap<Delta> resource = ((ODataClient) odataClient).getDeserializer().toDelta( + res.getEntity().getContent(), ODataPubFormat.fromString(getContentType())); + + delta = ((ODataClient) odataClient).getBinder().getODataDelta(resource); + } catch (IOException e) { + throw new HttpClientException(e); + } finally { + this.close(); + } + } + return delta; + } + } + +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e8ac1c74/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v4/RetrieveRequestFactoryImpl.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v4/RetrieveRequestFactoryImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v4/RetrieveRequestFactoryImpl.java index 879417b..f766de6 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v4/RetrieveRequestFactoryImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v4/RetrieveRequestFactoryImpl.java @@ -24,6 +24,7 @@ import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySe 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.XMLMetadataRequest; +import org.apache.olingo.client.api.communication.request.retrieve.v4.ODataDeltaRequest; import org.apache.olingo.client.api.communication.request.retrieve.v4.RetrieveRequestFactory; import org.apache.olingo.client.api.v4.ODataClient; import org.apache.olingo.client.core.communication.request.retrieve.AbstractRetrieveRequestFactory; @@ -70,4 +71,9 @@ public class RetrieveRequestFactoryImpl extends AbstractRetrieveRequestFactory public ODataPropertyRequest<ODataProperty> getPropertyRequest(final URI uri) { return new ODataPropertyRequestImpl<ODataProperty>(client, uri); } + + @Override + public ODataDeltaRequest getDeltaRequest(final URI uri) { + return new ODataDeltaRequestImpl(client, uri); + } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e8ac1c74/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataBinderImpl.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataBinderImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataBinderImpl.java index cbdd773..64ae222 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataBinderImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataBinderImpl.java @@ -18,6 +18,7 @@ */ package org.apache.olingo.client.core.op.impl.v4; +import java.net.URI; import org.apache.olingo.client.api.data.ServiceDocument; import org.apache.olingo.client.api.data.ServiceDocumentItem; import org.apache.olingo.client.api.op.v4.ODataBinder; @@ -25,6 +26,9 @@ import org.apache.olingo.client.api.v4.EdmEnabledODataClient; import org.apache.olingo.client.api.v4.ODataClient; import org.apache.olingo.client.core.op.AbstractODataBinder; import org.apache.olingo.client.core.uri.URIUtils; +import org.apache.olingo.commons.api.data.DeletedEntity; +import org.apache.olingo.commons.api.data.Delta; +import org.apache.olingo.commons.api.data.DeltaLink; import org.apache.olingo.commons.api.data.Entity; import org.apache.olingo.commons.api.data.EntitySet; import org.apache.olingo.commons.api.data.LinkedComplexValue; @@ -36,11 +40,14 @@ import org.apache.olingo.commons.api.domain.CommonODataEntitySet; import org.apache.olingo.commons.api.domain.CommonODataProperty; import org.apache.olingo.commons.api.domain.ODataServiceDocument; import org.apache.olingo.commons.api.domain.ODataValue; +import org.apache.olingo.commons.api.domain.v4.ODataDelta; import org.apache.olingo.commons.api.domain.v4.ODataEntity; import org.apache.olingo.commons.api.domain.v4.ODataEntitySet; import org.apache.olingo.commons.api.domain.v4.ODataLinkedComplexValue; import org.apache.olingo.commons.api.domain.v4.ODataProperty; import org.apache.olingo.commons.api.edm.EdmComplexType; +import org.apache.olingo.commons.core.data.DeletedEntityImpl; +import org.apache.olingo.commons.core.data.DeltaLinkImpl; import org.apache.olingo.commons.core.data.EnumValueImpl; import org.apache.olingo.commons.core.data.LinkedComplexValueImpl; import org.apache.olingo.commons.core.domain.v4.ODataPropertyImpl; @@ -194,4 +201,56 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder return value; } + + @Override + public ODataDelta getODataDelta(final ResWrap<Delta> resource) { + final URI base = resource.getContextURL() == null + ? resource.getPayload().getBaseURI() : resource.getContextURL().getServiceRoot(); + + final URI next = resource.getPayload().getNext(); + + final ODataDelta delta = next == null + ? ((ODataClient) client).getObjectFactory().newDelta() + : ((ODataClient) client).getObjectFactory().newDelta(URIUtils.getURI(base, next.toASCIIString())); + + if (resource.getPayload().getCount() != null) { + delta.setCount(resource.getPayload().getCount()); + } + + if (resource.getPayload().getDeltaLink() != null) { + delta.setDeltaLink(URIUtils.getURI(base, resource.getPayload().getDeltaLink())); + } + + for (Entity entityResource : resource.getPayload().getEntities()) { + add(delta, getODataEntity( + new ResWrap<Entity>(resource.getContextURL(), resource.getMetadataETag(), entityResource))); + } + for (DeletedEntity deletedEntity : resource.getPayload().getDeletedEntities()) { + final DeletedEntityImpl impl = new DeletedEntityImpl(); + impl.setId(URIUtils.getURI(base, deletedEntity.getId())); + impl.setReason(deletedEntity.getReason()); + + delta.getDeletedEntities().add(impl); + } + + for (DeltaLink link : resource.getPayload().getAddedLinks()) { + final DeltaLinkImpl impl = new DeltaLinkImpl(); + impl.setRelationship(link.getRelationship()); + impl.setSource(URIUtils.getURI(base, link.getSource())); + impl.setTarget(URIUtils.getURI(base, link.getTarget())); + + delta.getAddedLinks().add(impl); + } + for (DeltaLink link : resource.getPayload().getDeletedLinks()) { + final DeltaLinkImpl impl = new DeltaLinkImpl(); + impl.setRelationship(link.getRelationship()); + impl.setSource(URIUtils.getURI(base, link.getSource())); + impl.setTarget(URIUtils.getURI(base, link.getTarget())); + + delta.getDeletedLinks().add(impl); + } + + return delta; + } + } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e8ac1c74/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/DeltaTestITCase.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/DeltaTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/DeltaTestITCase.java new file mode 100644 index 0000000..f0f8fca --- /dev/null +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/DeltaTestITCase.java @@ -0,0 +1,78 @@ +/* + * 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.client.core.it.v4; + +import java.net.URI; +import org.apache.olingo.client.api.communication.request.retrieve.v4.ODataDeltaRequest; +import org.apache.olingo.commons.api.domain.v4.ODataDelta; +import org.apache.olingo.commons.api.domain.v4.ODataProperty; +import org.apache.olingo.commons.api.format.ODataPubFormat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import org.junit.Test; + +public class DeltaTestITCase extends AbstractTestITCase { + + private void parse(final ODataPubFormat format) { + final URI deltaLink = URI.create(testStaticServiceRootURL + "/Customers?$expand=Orders&$deltatoken=565656"); + final ODataDeltaRequest req = client.getRetrieveRequestFactory().getDeltaRequest(deltaLink); + req.setFormat(format); + + final ODataDelta delta = req.execute().getBody(); + assertNotNull(delta); + + assertNotNull(delta.getDeltaLink()); + assertTrue(delta.getDeltaLink().isAbsolute()); + assertEquals(5, delta.getCount(), 0); + + assertEquals(1, delta.getDeletedEntities().size()); + assertTrue(delta.getDeletedEntities().get(0).getId().isAbsolute()); + assertTrue(delta.getDeletedEntities().get(0).getId().toASCIIString().endsWith("Customers('ANTON')")); + + assertEquals(1, delta.getAddedLinks().size()); + assertTrue(delta.getAddedLinks().get(0).getSource().isAbsolute()); + assertTrue(delta.getAddedLinks().get(0).getSource().toASCIIString().endsWith("Customers('BOTTM')")); + assertEquals("Orders", delta.getAddedLinks().get(0).getRelationship()); + + assertEquals(1, delta.getDeletedLinks().size()); + assertTrue(delta.getDeletedLinks().get(0).getSource().isAbsolute()); + assertTrue(delta.getDeletedLinks().get(0).getSource().toASCIIString().endsWith("Customers('ALFKI')")); + assertEquals("Orders", delta.getDeletedLinks().get(0).getRelationship()); + + assertEquals(2, delta.getEntities().size()); + ODataProperty property = delta.getEntities().get(0).getProperty("ContactName"); + assertNotNull(property); + assertTrue(property.hasPrimitiveValue()); + property = delta.getEntities().get(1).getProperty("ShippingAddress"); + assertNotNull(property); + assertTrue(property.hasComplexValue()); + } + + @Test + public void atomParse() { + parse(ODataPubFormat.ATOM); + } + + @Test + public void jsonParse() { + parse(ODataPubFormat.JSON); + + } +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e8ac1c74/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/JSONTest.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/JSONTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/JSONTest.java index 663cff1..efc7dac 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/JSONTest.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/JSONTest.java @@ -200,7 +200,7 @@ public class JSONTest extends AbstractTest { assertEquals(5, delta.getCount(), 0); assertEquals(1, delta.getDeletedEntities().size()); - assertTrue(delta.getDeletedEntities().get(0).getId().endsWith("Customers('ANTON')")); + assertTrue(delta.getDeletedEntities().get(0).getId().toASCIIString().endsWith("Customers('ANTON')")); assertEquals(1, delta.getAddedLinks().size()); assertTrue(delta.getAddedLinks().get(0).getSource().toASCIIString().endsWith("Customers('BOTTM')")); http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e8ac1c74/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/DeletedEntity.java ---------------------------------------------------------------------- diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/DeletedEntity.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/DeletedEntity.java index 98f2a89..49ef737 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/DeletedEntity.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/DeletedEntity.java @@ -18,10 +18,19 @@ */ package org.apache.olingo.commons.api.data; +import java.net.URI; + public interface DeletedEntity { - String getId(); + enum Reason { + + deleted, + changed; + + } + + URI getId(); - String getReason(); + Reason getReason(); } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e8ac1c74/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/v4/ODataDelta.java ---------------------------------------------------------------------- diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/v4/ODataDelta.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/v4/ODataDelta.java new file mode 100644 index 0000000..f6b0b4f --- /dev/null +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/v4/ODataDelta.java @@ -0,0 +1,48 @@ +/* + * 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.commons.api.domain.v4; + +import java.net.URI; +import java.util.List; +import org.apache.olingo.commons.api.data.DeletedEntity; +import org.apache.olingo.commons.api.data.DeltaLink; + +public interface ODataDelta extends ODataEntitySet { + + List<DeletedEntity> getDeletedEntities(); + + List<DeltaLink> getAddedLinks(); + + List<DeltaLink> getDeletedLinks(); + + /** + * Gets delta link if exists. + * + * @return delta link if exists; null otherwise. + */ + URI getDeltaLink(); + + /** + * Sets delta link. + * + * @param deltaLink delta link. + */ + void setDeltaLink(URI deltaLink); + +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e8ac1c74/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/v4/ODataObjectFactory.java ---------------------------------------------------------------------- diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/v4/ODataObjectFactory.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/v4/ODataObjectFactory.java index 6d0d11d..13abadc 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/v4/ODataObjectFactory.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/v4/ODataObjectFactory.java @@ -62,4 +62,8 @@ public interface ODataObjectFactory extends CommonODataObjectFactory { ODataProperty newCollectionProperty(String name, ODataCollectionValue<? extends org.apache.olingo.commons.api.domain.ODataValue> value); + ODataDelta newDelta(); + + ODataDelta newDelta(URI next); + } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e8ac1c74/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomDeserializer.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomDeserializer.java index 080b4aa..fdbfb48 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomDeserializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomDeserializer.java @@ -31,6 +31,7 @@ import javax.xml.stream.events.XMLEvent; import org.apache.commons.lang3.StringUtils; import org.apache.olingo.commons.api.Constants; import org.apache.olingo.commons.api.data.CollectionValue; +import org.apache.olingo.commons.api.data.DeletedEntity.Reason; import org.apache.olingo.commons.api.data.EntitySet; import org.apache.olingo.commons.api.data.ResWrap; import org.apache.olingo.commons.api.data.Value; @@ -420,11 +421,11 @@ public class AtomDeserializer extends AbstractAtomDealer { final Attribute ref = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATTR_REF)); if (ref != null) { - deletedEntity.setId(ref.getValue()); + deletedEntity.setId(URI.create(ref.getValue())); } final Attribute reason = event.asStartElement().getAttributeByName(reasonQName); if (reason != null) { - deletedEntity.setReason(reason.getValue()); + deletedEntity.setReason(Reason.valueOf(reason.getValue())); } delta.getDeletedEntities().add(deletedEntity); http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e8ac1c74/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/DeletedEntityImpl.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/DeletedEntityImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/DeletedEntityImpl.java index 0c97e9a..d3cbdf5 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/DeletedEntityImpl.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/DeletedEntityImpl.java @@ -18,31 +18,32 @@ */ package org.apache.olingo.commons.core.data; +import java.net.URI; import org.apache.olingo.commons.api.data.DeletedEntity; public class DeletedEntityImpl extends AbstractPayloadObject implements DeletedEntity { private static final long serialVersionUID = -3841730551749114664L; - private String id; + private URI id; - private String reason; + private Reason reason; @Override - public String getId() { + public URI getId() { return id; } - public void setId(final String id) { + public void setId(final URI id) { this.id = id; } @Override - public String getReason() { + public Reason getReason() { return reason; } - public void setReason(final String reason) { + public void setReason(final Reason reason) { this.reason = reason; } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e8ac1c74/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/v4/ODataDeltaImpl.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/v4/ODataDeltaImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/v4/ODataDeltaImpl.java new file mode 100644 index 0000000..b226be8 --- /dev/null +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/v4/ODataDeltaImpl.java @@ -0,0 +1,73 @@ +/* + * 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.commons.core.domain.v4; + +import java.net.URI; +import java.util.ArrayList; +import java.util.List; +import org.apache.olingo.commons.api.data.DeletedEntity; +import org.apache.olingo.commons.api.data.DeltaLink; +import org.apache.olingo.commons.api.domain.v4.ODataDelta; + +public class ODataDeltaImpl extends ODataEntitySetImpl implements ODataDelta { + + private static final long serialVersionUID = -418357452933455313L; + + private URI deltaLink; + + private final List<DeletedEntity> deletedEntities = new ArrayList<DeletedEntity>(); + + private final List<DeltaLink> addedLinks = new ArrayList<DeltaLink>(); + + private final List<DeltaLink> deletedLinks = new ArrayList<DeltaLink>(); + + public ODataDeltaImpl() { + super(); + } + + public ODataDeltaImpl(final URI next) { + super(next); + } + + @Override + public List<DeletedEntity> getDeletedEntities() { + return deletedEntities; + } + + @Override + public List<DeltaLink> getAddedLinks() { + return addedLinks; + } + + @Override + public List<DeltaLink> getDeletedLinks() { + return deletedLinks; + } + + @Override + public URI getDeltaLink() { + return deltaLink; + } + + @Override + public void setDeltaLink(final URI deltaLink) { + this.deltaLink = deltaLink; + } + +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e8ac1c74/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/v4/ODataObjectFactoryImpl.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/v4/ODataObjectFactoryImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/v4/ODataObjectFactoryImpl.java index fdef28e..d52624b 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/v4/ODataObjectFactoryImpl.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/v4/ODataObjectFactoryImpl.java @@ -23,6 +23,7 @@ import org.apache.olingo.commons.api.domain.CommonODataProperty; import org.apache.olingo.commons.api.domain.ODataCollectionValue; import org.apache.olingo.commons.api.domain.ODataComplexValue; import org.apache.olingo.commons.api.domain.ODataPrimitiveValue; +import org.apache.olingo.commons.api.domain.v4.ODataDelta; import org.apache.olingo.commons.api.domain.v4.ODataEntitySet; import org.apache.olingo.commons.api.domain.v4.ODataObjectFactory; import org.apache.olingo.commons.api.domain.v4.ODataEntity; @@ -111,4 +112,14 @@ public class ODataObjectFactoryImpl extends AbstractODataObjectFactory implement return new ODataPropertyImpl(name, value); } + @Override + public ODataDelta newDelta() { + return new ODataDeltaImpl(); + } + + @Override + public ODataDelta newDelta(final URI next) { + return new ODataDeltaImpl(next); + } + }
