diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/AbstractODataBinder.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/AbstractODataBinder.java index a678834e6..36ff32bed 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/AbstractODataBinder.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/AbstractODataBinder.java @@ -91,7 +91,6 @@ public abstract class AbstractODataBinder implements CommonODataBinder { public Feed getFeed(final ODataEntitySet entitySet, final Class reference) { final Feed feed = ResourceFactory.newFeed(reference); - feed.setContextURL(entitySet.getContextURL()); feed.setCount(entitySet.getCount()); final URI next = entitySet.getNext(); @@ -115,7 +114,6 @@ public abstract class AbstractODataBinder implements CommonODataBinder { public Entry getEntry(final ODataEntity entity, final Class reference, final boolean setType) { final Entry entry = ResourceFactory.newEntry(reference); - entry.setContextURL(entity.getContextURL()); entry.setId(entity.getReference()); entry.setType(entity.getName()); @@ -281,8 +279,6 @@ public abstract class AbstractODataBinder implements CommonODataBinder { ? client.getObjectFactory().newEntitySet() : client.getObjectFactory().newEntitySet(URIUtils.getURI(base, next.toASCIIString())); - entitySet.setContextURL(resource.getContextURL()); - if (resource.getCount() != null) { entitySet.setCount(resource.getCount()); } @@ -315,7 +311,6 @@ public abstract class AbstractODataBinder implements CommonODataBinder { : client.getObjectFactory().newEntity(resource.getType(), URIUtils.getURI(base, resource.getSelfLink().getHref())); - entity.setContextURL(resource.getContextURL()); entity.setReference(resource.getId()); if (StringUtils.isNotBlank(resource.getETag())) { @@ -380,9 +375,9 @@ public abstract class AbstractODataBinder implements CommonODataBinder { private ODataValue getODataValue(final Property resource) { ODataValue value = null; - if (resource.getValue().isSimple()) { + if (resource.getValue().isPrimitive()) { value = client.getPrimitiveValueBuilder(). - setText(resource.getValue().asSimple().get()). + setText(resource.getValue().asPrimitive().get()). setType(resource.getType() == null ? null : EdmPrimitiveTypeKind.valueOfFQN(client.getServiceVersion(), resource.getType())).build(); diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/AtomTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/AtomTest.java index 1be265bdd..ce2ef71b4 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/AtomTest.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/AtomTest.java @@ -53,7 +53,7 @@ public class AtomTest extends AbstractTest { private String cleanup(final String input) throws Exception { final TransformerFactory factory = TransformerFactory.newInstance(); - final Source xslt = new StreamSource(getClass().getResourceAsStream("../atom_cleanup.xsl")); + final Source xslt = new StreamSource(getClass().getResourceAsStream("atom_cleanup.xsl")); final Transformer transformer = factory.newTransformer(xslt); final StringWriter result = new StringWriter(); diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/JSONTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/JSONTest.java index c3b155248..bae0bdde8 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/JSONTest.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/JSONTest.java @@ -30,6 +30,7 @@ import java.util.List; import java.util.Map; import org.apache.commons.io.IOUtils; import org.apache.olingo.commons.api.Constants; +import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; import org.apache.olingo.commons.api.format.ODataFormat; import org.apache.olingo.commons.api.format.ODataPubFormat; @@ -48,20 +49,23 @@ public class JSONTest extends AtomTest { } private void cleanup(final ObjectNode node) { - if (node.has(Constants.JSON_TYPE)) { - node.remove(Constants.JSON_TYPE); + if (node.has(Constants.JSON_METADATA)) { + node.remove(Constants.JSON_METADATA); } - if (node.has(Constants.JSON_EDIT_LINK)) { - node.remove(Constants.JSON_EDIT_LINK); + if (node.has(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_TYPE))) { + node.remove(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_TYPE)); } - if (node.has(Constants.JSON_READ_LINK)) { - node.remove(Constants.JSON_READ_LINK); + if (node.has(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_EDIT_LINK))) { + node.remove(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_EDIT_LINK)); } - if (node.has(Constants.JSON_MEDIAEDIT_LINK)) { - node.remove(Constants.JSON_MEDIAEDIT_LINK); + if (node.has(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_READ_LINK))) { + node.remove(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_READ_LINK)); } - if (node.has(Constants.JSON_MEDIAREAD_LINK)) { - node.remove(Constants.JSON_MEDIAREAD_LINK); + if (node.has(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_MEDIAEDIT_LINK))) { + node.remove(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_MEDIAEDIT_LINK)); + } + if (node.has(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_MEDIAREAD_LINK))) { + node.remove(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_MEDIAREAD_LINK)); } if (node.has(Constants.JSON_MEDIA_CONTENT_TYPE)) { node.remove(Constants.JSON_MEDIA_CONTENT_TYPE); @@ -71,10 +75,13 @@ public class JSONTest extends AtomTest { final Map.Entry field = itor.next(); if (field.getKey().charAt(0) == '#' - || field.getKey().endsWith(Constants.JSON_TYPE_SUFFIX) - || field.getKey().endsWith(Constants.JSON_MEDIAEDIT_LINK_SUFFIX) + || field.getKey().endsWith( + getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_TYPE)) + || field.getKey().endsWith( + getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_MEDIAEDIT_LINK)) || field.getKey().endsWith(Constants.JSON_MEDIA_CONTENT_TYPE_SUFFIX) - || field.getKey().endsWith(Constants.JSON_ASSOCIATION_LINK_SUFFIX) + || field.getKey().endsWith( + getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_ASSOCIATION_LINK)) || field.getKey().endsWith(Constants.JSON_MEDIA_ETAG_SUFFIX)) { toRemove.add(field.getKey()); @@ -95,10 +102,12 @@ public class JSONTest extends AtomTest { @Override protected void assertSimilar(final String filename, final String actual) throws Exception { final JsonNode orig = OBJECT_MAPPER.readTree(IOUtils.toString(getClass().getResourceAsStream(filename)). - replace("Categories" + Constants.JSON_NAVIGATION_LINK_SUFFIX, + replace("Categories" + getClient().getServiceVersion().getJSONMap(). + get(ODataServiceVersion.JSON_NAVIGATION_LINK), "Categories" + Constants.JSON_BIND_LINK_SUFFIX). replace("\"Products(0)/Categories\"", "[\"Products(0)/Categories\"]"). - replace(Constants.JSON_NAVIGATION_LINK_SUFFIX, Constants.JSON_BIND_LINK_SUFFIX)); + replace(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_NAVIGATION_LINK), + Constants.JSON_BIND_LINK_SUFFIX)); cleanup((ObjectNode) orig); assertEquals(orig, OBJECT_MAPPER.readTree(new ByteArrayInputStream(actual.getBytes()))); } diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/AtomTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/AtomTest.java new file mode 100644 index 000000000..ed6b8c089 --- /dev/null +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/AtomTest.java @@ -0,0 +1,74 @@ +/* + * 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.v4; + +import java.io.ByteArrayInputStream; +import java.io.StringWriter; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; +import org.apache.commons.io.IOUtils; +import org.apache.olingo.client.api.v4.ODataClient; +import org.apache.olingo.client.core.AtomLinksQualifier; +import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ODataPubFormat; +import org.custommonkey.xmlunit.Diff; +import static org.junit.Assert.assertTrue; + +public class AtomTest extends JSONTest { + + @Override + protected ODataClient getClient() { + return v4Client; + } + + @Override + protected ODataPubFormat getODataPubFormat() { + return ODataPubFormat.ATOM; + } + + @Override + protected ODataFormat getODataFormat() { + return ODataFormat.XML; + } + + private String cleanup(final String input) throws Exception { + final TransformerFactory factory = TransformerFactory.newInstance(); + final Source xslt = new StreamSource(getClass().getResourceAsStream("atom_cleanup.xsl")); + final Transformer transformer = factory.newTransformer(xslt); + + final StringWriter result = new StringWriter(); + transformer.transform(new StreamSource(new ByteArrayInputStream(input.getBytes())), new StreamResult(result)); + return result.toString(); + } + + protected void assertSimilar(final String filename, final String actual) throws Exception { + final Diff diff = new Diff(cleanup(IOUtils.toString(getClass().getResourceAsStream(filename))), actual); + diff.overrideElementQualifier(new AtomLinksQualifier()); + assertTrue(diff.similar()); + } + + @Override + public void additionalEntries() throws Exception { + // no test + } + +} 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 new file mode 100644 index 000000000..272ab13c5 --- /dev/null +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/JSONTest.java @@ -0,0 +1,152 @@ +/* + * 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.v4; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; +import java.io.ByteArrayInputStream; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import org.apache.commons.io.IOUtils; +import org.apache.olingo.client.api.v4.ODataClient; +import org.apache.olingo.client.core.AbstractTest; +import org.apache.olingo.commons.api.Constants; +import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; +import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ODataPubFormat; +import static org.junit.Assert.assertEquals; +import org.junit.Test; + +public class JSONTest extends AbstractTest { + + private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + + @Override + protected ODataClient getClient() { + return v4Client; + } + + protected ODataPubFormat getODataPubFormat() { + return ODataPubFormat.JSON; + } + + protected ODataFormat getODataFormat() { + return ODataFormat.JSON; + } + + private void cleanup(final ObjectNode node) { + if (node.has(Constants.JSON_CONTEXT)) { + node.remove(Constants.JSON_CONTEXT); + } + if (node.has(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_TYPE))) { + node.remove(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_TYPE)); + } + if (node.has(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_EDIT_LINK))) { + node.remove(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_EDIT_LINK)); + } + if (node.has(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_READ_LINK))) { + node.remove(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_READ_LINK)); + } + if (node.has(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_MEDIAEDIT_LINK))) { + node.remove(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_MEDIAEDIT_LINK)); + } + if (node.has(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_MEDIAREAD_LINK))) { + node.remove(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_MEDIAREAD_LINK)); + } + if (node.has(Constants.JSON_MEDIA_CONTENT_TYPE)) { + node.remove(Constants.JSON_MEDIA_CONTENT_TYPE); + } + final List toRemove = new ArrayList(); + for (final Iterator> itor = node.fields(); itor.hasNext();) { + final Map.Entry field = itor.next(); + + if (field.getKey().charAt(0) == '#' + || field.getKey().endsWith( + getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_TYPE)) + || field.getKey().endsWith( + getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_MEDIAEDIT_LINK)) + || field.getKey().endsWith(Constants.JSON_MEDIA_CONTENT_TYPE_SUFFIX) + || field.getKey().endsWith( + getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_ASSOCIATION_LINK)) + || field.getKey().endsWith(Constants.JSON_MEDIA_ETAG_SUFFIX)) { + + toRemove.add(field.getKey()); + } else if (field.getValue().isObject()) { + cleanup((ObjectNode) field.getValue()); + } else if (field.getValue().isArray()) { + for (final Iterator arrayItems = field.getValue().elements(); arrayItems.hasNext();) { + final JsonNode arrayItem = arrayItems.next(); + if (arrayItem.isObject()) { + cleanup((ObjectNode) arrayItem); + } + } + } + } + node.remove(toRemove); + } + + protected void assertSimilar(final String filename, final String actual) throws Exception { + final JsonNode orig = OBJECT_MAPPER.readTree(IOUtils.toString(getClass().getResourceAsStream(filename)). + replace(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_NAVIGATION_LINK), + Constants.JSON_BIND_LINK_SUFFIX)); + cleanup((ObjectNode) orig); + assertEquals(orig, OBJECT_MAPPER.readTree(new ByteArrayInputStream(actual.getBytes()))); + } + + protected void entry(final String filename, final ODataPubFormat format) throws Exception { + final StringWriter writer = new StringWriter(); + getClient().getSerializer().entry(getClient().getDeserializer().toEntry( + getClass().getResourceAsStream(filename + "." + getSuffix(format)), format).getObject(), writer); + + assertSimilar(filename + "." + getSuffix(format), writer.toString()); + } + + @Test + public void additionalEntries() throws Exception { + entry("entity.minimal", getODataPubFormat()); +// entry("entity.full", getODataPubFormat()); + entry("entity.primitive", getODataPubFormat()); + entry("entity.complex", getODataPubFormat()); + entry("entity.collection.primitive", getODataPubFormat()); + entry("entity.collection.complex", getODataPubFormat()); + } + + @Test + public void entries() throws Exception { + entry("Products_5", getODataPubFormat()); + entry("VipCustomer", getODataPubFormat()); + } + + protected void property(final String filename, final ODataFormat format) throws Exception { + final StringWriter writer = new StringWriter(); + getClient().getSerializer().property(getClient().getDeserializer(). + toProperty(getClass().getResourceAsStream(filename + "." + getSuffix(format)), format).getObject(), writer); + + assertSimilar(filename + "." + getSuffix(format), writer.toString()); + } + + @Test + public void properties() throws Exception { + property("Products_5_SkinColor", getODataFormat()); + } +} diff --git a/lib/client-core/src/test/resources/org/apache/olingo/client/core/atom_cleanup.xsl b/lib/client-core/src/test/resources/org/apache/olingo/client/core/v3/atom_cleanup.xsl similarity index 100% rename from lib/client-core/src/test/resources/org/apache/olingo/client/core/atom_cleanup.xsl rename to lib/client-core/src/test/resources/org/apache/olingo/client/core/v3/atom_cleanup.xsl diff --git a/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/Products_5.json b/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/Products_5.json new file mode 100644 index 000000000..22c8473cc --- /dev/null +++ b/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/Products_5.json @@ -0,0 +1 @@ +{"@odata.context":"http://odatae2etest.azurewebsites.net/javatest/DefaultService/$metadata#Products/$entity","@odata.type":"#Microsoft.Test.OData.Services.ODataWCFService.Product","@odata.id":"http://odatae2etest.azurewebsites.net/javatest/DefaultService/Products(5)","@odata.editLink":"http://odatae2etest.azurewebsites.net/javatest/DefaultService/Products(5)","ProductID":5,"Name":"Cheetos","QuantityPerUnit":"100g Bag","UnitPrice@odata.type":"#Single","UnitPrice":3.24,"QuantityInStock":100,"Discontinued":true,"UserAccess@odata.type":"#Microsoft.Test.OData.Services.ODataWCFService.AccessLevel","UserAccess":"None","SkinColor@odata.type":"#Microsoft.Test.OData.Services.ODataWCFService.Color","SkinColor":"Red","CoverColors@odata.type":"#Collection(Microsoft.Test.OData.Services.ODataWCFService.Color)","CoverColors":["Green","Blue","Blue"],"Details@odata.associationLink":"http://odatae2etest.azurewebsites.net/javatest/DefaultService/Products(5)/Details/$ref","Details@odata.navigationLink":"http://odatae2etest.azurewebsites.net/javatest/DefaultService/Products(5)/Details","#Microsoft.Test.OData.Services.ODataWCFService.AddAccessRight":{"title":"Microsoft.Test.OData.Services.ODataWCFService.AddAccessRight","target":"http://odatae2etest.azurewebsites.net/javatest/DefaultService/Products(5)/Microsoft.Test.OData.Services.ODataWCFService.AddAccessRight"},"#Microsoft.Test.OData.Services.ODataWCFService.GetProductDetails":{"title":"Microsoft.Test.OData.Services.ODataWCFService.GetProductDetails","target":"http://odatae2etest.azurewebsites.net/javatest/DefaultService/Products(5)/Microsoft.Test.OData.Services.ODataWCFService.GetProductDetails"}} diff --git a/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/Products_5.xml b/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/Products_5.xml new file mode 100644 index 000000000..9109f2dde --- /dev/null +++ b/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/Products_5.xml @@ -0,0 +1,49 @@ + + + + http://odatae2etest.azurewebsites.net/javatest/DefaultService/Products(5) + + + + + <updated>2014-03-28T11:24:49Z</updated> + <author> + <name /> + </author> + <content type="application/xml"> + <m:properties> + <d:ProductID m:type="Int32">5</d:ProductID> + <d:Name>Cheetos</d:Name> + <d:QuantityPerUnit>100g Bag</d:QuantityPerUnit> + <d:UnitPrice m:type="Single">3.24</d:UnitPrice> + <d:QuantityInStock m:type="Int32">100</d:QuantityInStock> + <d:Discontinued m:type="Boolean">true</d:Discontinued> + <d:UserAccess m:type="#Microsoft.Test.OData.Services.ODataWCFService.AccessLevel">None</d:UserAccess> + <d:SkinColor m:type="#Microsoft.Test.OData.Services.ODataWCFService.Color">Red</d:SkinColor> + <d:CoverColors m:type="#Collection(Microsoft.Test.OData.Services.ODataWCFService.Color)"> + <m:element>Green</m:element> + <m:element>Blue</m:element> + <m:element>Blue</m:element> + </d:CoverColors> + </m:properties> + </content> +</entry> diff --git a/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/Products_5_SkinColor.json b/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/Products_5_SkinColor.json new file mode 100644 index 000000000..b5e26daea --- /dev/null +++ b/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/Products_5_SkinColor.json @@ -0,0 +1,5 @@ +{ + "@odata.context": "http://odatae2etest.azurewebsites.net/javatest/DefaultService/$metadata#Products(5)/SkinColor", + "@odata.type": "#Microsoft.Test.OData.Services.ODataWCFService.Color", + "value": "Red" +} diff --git a/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/Products_5_SkinColor.xml b/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/Products_5_SkinColor.xml new file mode 100644 index 000000000..be392fd60 --- /dev/null +++ b/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/Products_5_SkinColor.xml @@ -0,0 +1,27 @@ +<?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. + +--> +<m:value xmlns:d="http://docs.oasis-open.org/odata/ns/data" + xmlns:georss="http://www.georss.org/georss" + xmlns:gml="http://www.opengis.net/gml" + m:context="http://odatae2etest.azurewebsites.net/javatest/DefaultService/$metadata#Products(5)/SkinColor" + m:type="#Microsoft.Test.OData.Services.ODataWCFService.Color" + xmlns:m="http://docs.oasis-open.org/odata/ns/metadata">Red</m:value> \ No newline at end of file diff --git a/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/VipCustomer.json b/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/VipCustomer.json new file mode 100644 index 000000000..5f3f6976e --- /dev/null +++ b/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/VipCustomer.json @@ -0,0 +1,50 @@ +{ + "@odata.context": "http://odatae2etest.azurewebsites.net/javatest/DefaultService/$metadata#VipCustomer", + "@odata.type": "#Microsoft.Test.OData.Services.ODataWCFService.Customer", + "@odata.id": "http://odatae2etest.azurewebsites.net/javatest/DefaultService/VipCustomer", + "@odata.editLink": "http://odatae2etest.azurewebsites.net/javatest/DefaultService/VipCustomer", + "PersonID": 1, + "FirstName": "Bob", + "LastName": "Cat", + "MiddleName": "Vat", + "HomeAddress": { + "@odata.type": "#Microsoft.Test.OData.Services.ODataWCFService.Address", + "Street": "1 Microsoft Way", + "City": "London", + "PostalCode": "98052" + }, + "Home@odata.type": "#GeographyPoint", + "Home": { + "type": "Point", + "coordinates": [23.1, 32.1], + "crs": { + "type": "name", + "properties": { + "name": "EPSG:4326" + } + } + }, + "Numbers@odata.type": "#Collection(String)", + "Numbers": ["111-111-1111"], + "Emails@odata.type": "#Collection(String)", + "Emails": ["abc@abc.com"], + "City": "London", + "Birthday@odata.type": "#DateTimeOffset", + "Birthday": "1957-04-03T00:00:00Z", + "TimeBetweenLastTwoOrders@odata.type": "#Duration", + "TimeBetweenLastTwoOrders": "PT0.0000001S", + "Parent@odata.associationLink": "http://odatae2etest.azurewebsites.net/javatest/DefaultService/VipCustomer/Parent/$ref", + "Parent@odata.navigationLink": "http://odatae2etest.azurewebsites.net/javatest/DefaultService/VipCustomer/Parent", + "Orders@odata.associationLink": "http://odatae2etest.azurewebsites.net/javatest/DefaultService/VipCustomer/Orders/$ref", + "Orders@odata.navigationLink": "http://odatae2etest.azurewebsites.net/javatest/DefaultService/VipCustomer/Orders", + "Company@odata.associationLink": "http://odatae2etest.azurewebsites.net/javatest/DefaultService/VipCustomer/Company/$ref", + "Company@odata.navigationLink": "http://odatae2etest.azurewebsites.net/javatest/DefaultService/VipCustomer/Company", + "#Microsoft.Test.OData.Services.ODataWCFService.ResetAddress": { + "title": "Microsoft.Test.OData.Services.ODataWCFService.ResetAddress", + "target": "http://odatae2etest.azurewebsites.net/javatest/DefaultService/VipCustomer/Microsoft.Test.OData.Services.ODataWCFService.ResetAddress" + }, + "#Microsoft.Test.OData.Services.ODataWCFService.GetHomeAddress": { + "title": "Microsoft.Test.OData.Services.ODataWCFService.GetHomeAddress", + "target": "http://odatae2etest.azurewebsites.net/javatest/DefaultService/VipCustomer/Microsoft.Test.OData.Services.ODataWCFService.GetHomeAddress" + } +} diff --git a/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/VipCustomer.xml b/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/VipCustomer.xml new file mode 100644 index 000000000..001c1a93e --- /dev/null +++ b/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/VipCustomer.xml @@ -0,0 +1,67 @@ +<?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. + +--> +<entry xml:base="http://odatae2etest.azurewebsites.net/javatest/DefaultService/" + xmlns="http://www.w3.org/2005/Atom" + xmlns:d="http://docs.oasis-open.org/odata/ns/data" + xmlns:m="http://docs.oasis-open.org/odata/ns/metadata" + xmlns:georss="http://www.georss.org/georss" + xmlns:gml="http://www.opengis.net/gml" + m:context="http://odatae2etest.azurewebsites.net/javatest/DefaultService/$metadata#VipCustomer"> + <id>http://odatae2etest.azurewebsites.net/javatest/DefaultService/VipCustomer</id> + <category term="#Microsoft.Test.OData.Services.ODataWCFService.Customer" scheme="http://docs.oasis-open.org/odata/ns/scheme" /> + <link rel="edit" href="http://odatae2etest.azurewebsites.net/javatest/DefaultService/VipCustomer" /> + <link rel="http://docs.oasis-open.org/odata/ns/related/Parent" type="application/atom+xml;type=entry" title="Parent" href="http://odatae2etest.azurewebsites.net/javatest/DefaultService/VipCustomer/Parent" /> + <link rel="http://docs.oasis-open.org/odata/ns/related/Orders" type="application/atom+xml;type=feed" title="Orders" href="http://odatae2etest.azurewebsites.net/javatest/DefaultService/VipCustomer/Orders" /> + <link rel="http://docs.oasis-open.org/odata/ns/related/Company" type="application/atom+xml;type=entry" title="Company" href="http://odatae2etest.azurewebsites.net/javatest/DefaultService/VipCustomer/Company" /> + <title /> + <updated>2014-03-28T13:03:32Z</updated> + <author> + <name /> + </author> + <content type="application/xml"> + <m:properties> + <d:PersonID m:type="Int32">1</d:PersonID> + <d:FirstName>Bob</d:FirstName> + <d:LastName>Cat</d:LastName> + <d:MiddleName>Vat</d:MiddleName> + <d:HomeAddress m:type="#Microsoft.Test.OData.Services.ODataWCFService.Address"> + <d:Street>1 Microsoft Way</d:Street> + <d:City>London</d:City> + <d:PostalCode>98052</d:PostalCode> + </d:HomeAddress> + <d:Home m:type="GeographyPoint"> + <gml:Point gml:srsName="http://www.opengis.net/def/crs/EPSG/0/4326"> + <gml:pos>32.1 23.1</gml:pos> + </gml:Point> + </d:Home> + <d:Numbers m:type="#Collection(String)"> + <m:element>111-111-1111</m:element> + </d:Numbers> + <d:Emails m:type="#Collection(String)"> + <m:element>abc@abc.com</m:element> + </d:Emails> + <d:City>London</d:City> + <d:Birthday m:type="DateTimeOffset">1957-04-03T00:00:00Z</d:Birthday> + <d:TimeBetweenLastTwoOrders m:type="Duration">PT0.0000001S</d:TimeBetweenLastTwoOrders> + </m:properties> + </content> +</entry> diff --git a/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/atom_cleanup.xsl b/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/atom_cleanup.xsl new file mode 100644 index 000000000..ed302017b --- /dev/null +++ b/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/atom_cleanup.xsl @@ -0,0 +1,48 @@ +<?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. + +--> +<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns="http://www.w3.org/2005/Atom" + xmlns:atom="http://www.w3.org/2005/Atom" + xmlns:m="http://docs.oasis-open.org/odata/ns/metadata" + version="1.0"> + + <xsl:template match="atom:updated"/> + <xsl:template match="atom:author"/> + <xsl:template match="atom:title"> + <xsl:if test="string-length(.) > 0"> + <title type="{@type}"> + <xsl:apply-templates/> + + + + + + + + + + + + + + + diff --git a/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/complexProperty.json b/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/complexProperty.json deleted file mode 100644 index 53af94c58..000000000 --- a/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/complexProperty.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "Address": { - "Street": "Obere Str. 57", - "City": "Berlin", - "Region": null, - "PostalCode": "D-12209" - } -} \ No newline at end of file diff --git a/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/setOfComplexProperties.json b/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/entity.collection.complex.json similarity index 71% rename from lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/setOfComplexProperties.json rename to lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/entity.collection.complex.json index 24ec160ad..0bf131ee8 100644 --- a/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/setOfComplexProperties.json +++ b/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/entity.collection.complex.json @@ -3,11 +3,12 @@ { "Number": "425-555-1212", "Type": "Home" - }, { - "odata.type": "#Model.CellPhoneNumber", + }, + { + "@odata.type": "#Model.CellPhoneNumber", "Number": "425-555-0178", "Type": "Cell", "Carrier": "Sprint" - } + } ] } \ No newline at end of file diff --git a/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/setOfPrimitiveProperties.json b/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/entity.collection.primitive.json similarity index 54% rename from lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/setOfPrimitiveProperties.json rename to lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/entity.collection.primitive.json index 61b3d2c4e..dc811b4ba 100644 --- a/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/setOfPrimitiveProperties.json +++ b/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/entity.collection.primitive.json @@ -1,8 +1,7 @@ { - "odata.context": "http://host/service/$metadata#Customers/$entity", - + "@odata.context": "http://host/service/$metadata#Customers/$entity", "EmailAddresses": [ "Julie@Swansworth.com", "Julie.Swansworth@work.com" ] -} \ No newline at end of file +} diff --git a/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/entity.complex.json b/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/entity.complex.json new file mode 100644 index 000000000..189613f15 --- /dev/null +++ b/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/entity.complex.json @@ -0,0 +1,12 @@ +{ + "CompanyID": 0, + "CompanyCategory": "IT", + "Revenue": 100000, + "Name": "MS", + "Address": { + "Street": "1 Microsoft Way", + "City": "Redmond", + "PostalCode": "98052", + "CompanyName": "Microsoft" + } +} \ No newline at end of file diff --git a/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/entity.full.json b/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/entity.full.json new file mode 100644 index 000000000..bcd1dbaf4 --- /dev/null +++ b/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/entity.full.json @@ -0,0 +1,22 @@ +{ + "@odata.context": "http://host/service/$metadata#Customers/$entity", + "@odata.id": "Customers('ALFKI')", + "@odata.etag": "W/\"MjAxMy0wNS0yN1QxMTo1OFo=\"", + "@odata.editLink": "Customers('ALFKI')", + "ID": "ALFKI", + "CompanyName": "Alfreds Futterkiste", + "ContactName": "Maria Anders", + "ContactTitle": "Sales Representative", + "Phone": "030-0074321", + "Fax": "030-0076545", + "Address": { + "Street": "Obere Str. 57", + "City": "Berlin", + "Region": null, + "PostalCode": "D-12209", + "Country@odata.associationLink": "Customers('ALFKI')/Address/Country/$ref", + "Country@odata.navigationLink": "Customers('ALFKI')/Address/Country" + }, + "Orders@odata.associationLink": "Customers('ALFKI')/Orders/$ref", + "Orders@odata.navigationLink": "Customers('ALFKI')/Orders" +} \ No newline at end of file diff --git a/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/entity.minimal.json b/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/entity.minimal.json new file mode 100644 index 000000000..de0a50b0e --- /dev/null +++ b/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/entity.minimal.json @@ -0,0 +1,15 @@ +{ + "@odata.context": "http://host/service/$metadata#Customers/$entity", + "ID": "ALFKI", + "CompanyName": "Alfreds Futterkiste", + "ContactName": "Maria Anders", + "ContactTitle": "Sales Representative", + "Phone": "030-0074321", + "Fax": "030-0076545", + "Address": { + "Street": "Obere Str. 57", + "City": "Berlin", + "Region": null, + "PostalCode": "D-12209" + } +} \ No newline at end of file diff --git a/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/entity.primitive.json b/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/entity.primitive.json new file mode 100644 index 000000000..db12081fe --- /dev/null +++ b/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/entity.primitive.json @@ -0,0 +1,22 @@ +{ + "NullValue": null, + "TrueValue": true, + "FalseValue": false, + "BinaryValue": "T0RhdGE", + "IntegerValue": -128, + "DoubleValue": 3.1415926535897931, + "SingleValue": "INF", + "DecimalValue": 34.95, + "StringValue": "Say \"Hello\",\nthen go", + "DateValue": "2012-12-03", + "DateTimeOffsetValue": "2012-12-03T07:16:23Z", + "DurationValue": "P12DT23H59M59.999999999999S", + "TimeOfDayValue": "07:59:59.999", + "GuidValue": "01234567-89ab-cdef-0123-456789abcdef", + "Int64Value": 0, + "ColorEnumValue": "Yellow", + "GeographyPoint": { + "type": "point", + "coordinates": [142.1, 64.1] + } +} \ No newline at end of file diff --git a/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/fullEntity.json b/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/fullEntity.json deleted file mode 100644 index 4d8499542..000000000 --- a/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/fullEntity.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "odata.context": "http://host/service/$metadata#Customers/$entity", - "odata.id": "Customers('ALFKI')", - "odata.etag": "W/\"MjAxMy0wNS0yN1QxMTo1OFo=\"", - "odata.editLink": "Customers('ALFKI')", - "Orders@odata.navigationLink": "Customers('ALFKI')/Orders", - "Orders@odata.associationLink": "Customers('ALFKI')/Orders/$ref", - "ID": "ALFKI", - "CompanyName": "Alfreds Futterkiste", - "ContactName": "Maria Anders", - "ContactTitle": "Sales Representative", - "Phone": "030-0074321", - "Fax": "030-0076545", - "Address": { - "Street": "Obere Str. 57", - "City": "Berlin", - "Region": null, - "PostalCode": "D-12209", - "Country@odata.navigationLink": "Customers('ALFKI')/Address/Country", - "Country@odata.associationLink":"Customers('ALFKI')/Address/Country/$ref" - } -} \ No newline at end of file diff --git a/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/fullEntitySet.json b/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/fullEntitySet.json deleted file mode 100644 index b3ddf63cb..000000000 --- a/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/fullEntitySet.json +++ /dev/null @@ -1,29 +0,0 @@ -{ -"odata.context": "http://host/service/$metadata#Customers/$entity", -"odata.count": 1, -"value": [ -{ -"odata.context": "http://host/service/$metadata#Customers/$entity", -"odata.id": "Customers('ALFKI')", -"odata.etag": "W/\"MjAxMy0wNS0yN1QxMTo1OFo=\"", -"odata.editLink": "Customers('ALFKI')", -"Orders@odata.navigationLink": "Customers('ALFKI')/Orders", -"Orders@odata.associationLink": "Customers('ALFKI')/Orders/$ref", -"ID": "ALFKI", -"CompanyName": "Alfreds Futterkiste", -"ContactName": "Maria Anders", -"ContactTitle": "Sales Representative", -"Phone": "030-0074321", -"Fax": "030-0076545", -"Address": { - "Street": "Obere Str. 57", - "City": "Berlin", - "Region": null, - "PostalCode": "D-12209", - "Country@odata.navigationLink": "Customers('ALFKI')/Address/Country", - "Country@odata.associationLink":"Customers('ALFKI')/Address/Country/$ref" - } -} -], -"odata.nextLink": "http://host/service/EntitySet?$skiptoken=342r89" -} diff --git a/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/fullEntitySetWithTwoEntities.json b/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/fullEntitySetWithTwoEntities.json deleted file mode 100644 index 96854acb0..000000000 --- a/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/fullEntitySetWithTwoEntities.json +++ /dev/null @@ -1,49 +0,0 @@ -{ -"odata.context": "http://host/service/$metadata#Customers/$entity", -"odata.count": 1, -"value": [ - { - "odata.context": "http://host/service/$metadata#Customers/$entity", - "odata.id": "Customers('ALFKI')", - "odata.etag": "W/\"MjAxMy0wNS0yN1QxMTo1OFo=\"", - "odata.editLink": "Customers('ALFKI')", - "Orders@odata.navigationLink": "Customers('ALFKI')/Orders", - "Orders@odata.associationLink": "Customers('ALFKI')/Orders/$ref", - "ID": "ALFKI", - "CompanyName": "Alfreds Futterkiste", - "ContactName": "Maria Anders", - "ContactTitle": "Sales Representative", - "Phone": "030-0074321", - "Fax": "030-0076545", - "Address": { - "Street": "Obere Str. 57", - "City": "Berlin", - "Region": null, - "PostalCode": "D-12209", - "Country@odata.navigationLink": "Customers('ALFKI')/Address/Country", - "Country@odata.associationLink":"Customers('ALFKI')/Address/Country/$ref" - } - }, - { - "odata.context": "http://host/service/$metadata#Customers/$entity", - "odata.id": "Customers('MUSKI')", - "odata.etag": "W/\"MjAxMy0wNS0yN1QxMTo1OFo=\"", - "odata.editLink": "Customers('MUSKI')", - "Orders@odata.navigationLink": "Customers('MUSKI')/Orders", - "Orders@odata.associationLink": "Customers('MUSKI')/Orders/$ref", - "ID": "MUSKI", - "CompanyName": "Mustermanns Futterkiste", - "ContactName": "Mustermann Max", - "ContactTitle": "Some Guy", - "Phone": "030-002222", - "Fax": "030-004444", - "Address": { - "Street": "Musterstrasse 42", - "City": "Musterstadt", - "Region": "SomeRegion", - "PostalCode": "D-42042" - } - } -], -"odata.nextLink": "http://host/service/EntitySet?$skiptoken=342r89" -} diff --git a/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/fullEntityWithCollectionOfComplexValues.json b/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/fullEntityWithCollectionOfComplexValues.json deleted file mode 100644 index cbdfd1c33..000000000 --- a/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/fullEntityWithCollectionOfComplexValues.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "odata.context": "http://host/service/$metadata#Customers/$entity", - "odata.id": "Customers('ALFKI')", - "odata.etag": "W/\"MjAxMy0wNS0yN1QxMTo1OFo=\"", - "odata.editLink": "Customers('ALFKI')", - "Orders@odata.navigationLink": "Customers('ALFKI')/Orders", - "Orders@odata.associationLink": "Customers('ALFKI')/Orders/$ref", - "ID": "ALFKI", - "CompanyName": "Alfreds Futterkiste", - "ContactName": "Maria Anders", - "ContactTitle": "Sales Representative", - "Phone": "030-0074321", - "Fax": "030-0076545", - "Address": [ { - "Street": "Obere Str. 57", - "City": "Berlin", - "Region": null, - "PostalCode": "D-12209", - "Country@odata.navigationLink": "Customers('ALFKI')/Address/Country", - "Country@odata.associationLink":"Customers('ALFKI')/Address/Country/$ref" - }, { - "Street": "Musterstrasse 42", - "City": "Musterstadt", - "Region": "SomeRegion", - "PostalCode": "D-42042" - } - ] -} \ No newline at end of file diff --git a/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/primitiveNullValue.json b/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/primitiveNullValue.json deleted file mode 100644 index 5774413a4..000000000 --- a/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/primitiveNullValue.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "NullValue" : null -} \ No newline at end of file diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/Constants.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/Constants.java index 39d961432..0a8bafb08 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/Constants.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/Constants.java @@ -137,44 +137,24 @@ public interface Constants { public static final String ELEM_URI = "uri"; // JSON stuff - public final static String JSON_CONTEXT = "@odata.context"; - public final static String JSON_METADATA = "odata.metadata"; + public final static String JSON_CONTEXT = "@odata.context"; + public final static String JSON_METADATA_ETAG = "@odata.metadataEtag"; - public final static String JSON_TYPE = "odata.type"; - - public final static String JSON_TYPE_SUFFIX = "@" + JSON_TYPE; - public final static String JSON_ETAG = "odata.etag"; public final static String JSON_MEDIA_ETAG = "odata.mediaETag"; public final static String JSON_MEDIA_ETAG_SUFFIX = "@" + JSON_MEDIA_ETAG; - public final static String JSON_ID = "odata.id"; - - public final static String JSON_READ_LINK = "odata.readLink"; - - public final static String JSON_EDIT_LINK = "odata.editLink"; - - public final static String JSON_MEDIAREAD_LINK = "odata.mediaReadLink"; - - public final static String JSON_MEDIAEDIT_LINK = "odata.mediaEditLink"; - - public final static String JSON_MEDIAEDIT_LINK_SUFFIX = "@" + JSON_MEDIAEDIT_LINK; - public final static String JSON_MEDIA_CONTENT_TYPE = "odata.mediaContentType"; public final static String JSON_MEDIA_CONTENT_TYPE_SUFFIX = "@" + JSON_MEDIA_CONTENT_TYPE; - public final static String JSON_NAVIGATION_LINK_SUFFIX = "@odata.navigationLinkUrl"; - public final static String JSON_BIND_LINK_SUFFIX = "@odata.bind"; - public final static String JSON_ASSOCIATION_LINK_SUFFIX = "@odata.associationLinkUrl"; - public final static String JSON_NULL = "odata.null"; public final static String VALUE = "value"; diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Entry.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Entry.java index 5ac0dbd86..c064216ad 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Entry.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Entry.java @@ -38,21 +38,6 @@ public interface Entry { */ URI getBaseURI(); - /** - * The context URL describes the content of the payload. It consists of the canonical metadata document URL and a - * fragment identifying the relevant portion of the metadata document. - * - * @return context URL. - */ - URI getContextURL(); - - /** - * Set context URL. - * - * @param contextURL context URL. - */ - void setContextURL(final URI contextURL); - /** * Gets entry type. * diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EnumValue.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EnumValue.java new file mode 100644 index 000000000..2f13fa752 --- /dev/null +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EnumValue.java @@ -0,0 +1,25 @@ +/* + * 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.data; + +public interface EnumValue extends Value { + + @Override + String get(); +} diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Feed.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Feed.java index 45b28d9ac..4f6a54235 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Feed.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Feed.java @@ -30,21 +30,6 @@ public interface Feed { */ URI getBaseURI(); - /** - * The context URL describes the content of the payload. It consists of the canonical metadata document URL and a - * fragment identifying the relevant portion of the metadata document. - * - * @return context URL. - */ - URI getContextURL(); - - /** - * Set context URL. - * - * @param contextURL context URL. - */ - void setContextURL(final URI contextURL); - /** * Sets number of entries. * diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Property.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Property.java index da34c169e..feb8f71a7 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Property.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Property.java @@ -18,18 +18,8 @@ */ package org.apache.olingo.commons.api.data; -import java.net.URI; - public interface Property { - /** - * The context URL describes the content of the payload. It consists of the canonical metadata document URL and a - * fragment identifying the relevant portion of the metadata document. - * - * @return context URL. - */ - URI getContextURL(); - String getName(); void setName(String name); diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Value.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Value.java index 045751da4..b02f1ba28 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Value.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Value.java @@ -22,10 +22,12 @@ public interface Value { boolean isNull(); - boolean isSimple(); + boolean isPrimitive(); boolean isGeospatial(); + boolean isEnum(); + boolean isComplex(); boolean isCollection(); @@ -34,7 +36,9 @@ public interface Value { NullValue asNull(); - PrimitiveValue asSimple(); + PrimitiveValue asPrimitive(); + + EnumValue asEnum(); GeospatialValue asGeospatial(); diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataPropertyType.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataPropertyType.java index d173e50bb..99126f745 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataPropertyType.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataPropertyType.java @@ -21,11 +21,15 @@ package org.apache.olingo.commons.api.domain; public enum ODataPropertyType { /** - * Primitive (including geospatial and enum). + * Primitive (including geospatial). */ PRIMITIVE, /** - * Collection + * Enum. + */ + ENUM, + /** + * Collection. */ COLLECTION, /** diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/constants/ODataServiceVersion.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/constants/ODataServiceVersion.java index d637814cf..96d99377c 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/constants/ODataServiceVersion.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/constants/ODataServiceVersion.java @@ -48,6 +48,22 @@ public enum ODataServiceVersion { public static final String MEDIA_EDIT_LINK_REL = "mediaEditLinkRel"; + public static final String JSON_TYPE = "jsonType"; + + public static final String JSON_ID = "jsonId"; + + public static final String JSON_READ_LINK = "jsonReadLink"; + + public static final String JSON_EDIT_LINK = "jsonEditLink"; + + public static final String JSON_MEDIAREAD_LINK = "jsonMediaReadLink"; + + public static final String JSON_MEDIAEDIT_LINK = "jsonMediaEditLink"; + + public static final String JSON_ASSOCIATION_LINK = "jsonAssociationLink"; + + public static final String JSON_NAVIGATION_LINK = "jsonNavigationLink"; + private static final Map V30_NAMESPACES = Collections.unmodifiableMap(new HashMap() { private static final long serialVersionUID = 3109256773218160485L; @@ -62,6 +78,22 @@ public enum ODataServiceVersion { } }); + private static final Map V30_JSON = Collections.unmodifiableMap(new HashMap() { + + private static final long serialVersionUID = 3109256773218160485L; + + { + put(JSON_TYPE, "odata.type"); + put(JSON_ID, "odata.id"); + put(JSON_READ_LINK, "odata.readLink"); + put(JSON_EDIT_LINK, "odata.editLink"); + put(JSON_MEDIAREAD_LINK, "odata.mediaReadLink"); + put(JSON_MEDIAEDIT_LINK, "odata.mediaEditLink"); + put(JSON_ASSOCIATION_LINK, "@odata.associationLinkUrl"); + put(JSON_NAVIGATION_LINK, "@odata.navigationLinkUrl"); + } + }); + private static final Map V40_NAMESPACES = Collections.unmodifiableMap(new HashMap() { private static final long serialVersionUID = 3109256773218160485L; @@ -76,6 +108,22 @@ public enum ODataServiceVersion { } }); + private static final Map V40_JSON = Collections.unmodifiableMap(new HashMap() { + + private static final long serialVersionUID = 3109256773218160485L; + + { + put(JSON_TYPE, "@odata.type"); + put(JSON_ID, "@odata.id"); + put(JSON_READ_LINK, "@odata.readLink"); + put(JSON_EDIT_LINK, "@odata.editLink"); + put(JSON_MEDIAREAD_LINK, "@odata.mediaReadLink"); + put(JSON_MEDIAEDIT_LINK, "@odata.mediaEditLink"); + put(JSON_ASSOCIATION_LINK, "@odata.associationLink"); + put(JSON_NAVIGATION_LINK, "@odata.navigationLink"); + } + }); + /** * Validates format and range of a data service version string. * @@ -135,6 +183,14 @@ public enum ODataServiceVersion { : V40_NAMESPACES; } + public Map getJSONMap() { + return this == V10 || this == V20 + ? Collections.emptyMap() + : this == V30 + ? V30_JSON + : V40_JSON; + } + @Override public String toString() { return version; diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractAtomDealer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractAtomDealer.java index e258219cd..656207c59 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractAtomDealer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractAtomDealer.java @@ -75,8 +75,9 @@ abstract class AbstractAtomDealer { new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.PROPERTIES); this.typeQName = new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ATTR_TYPE); this.nullQName = new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ATTR_NULL); - this.elementQName = - new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES), Constants.ELEM_ELEMENT); + this.elementQName = version == ODataServiceVersion.V30 + ? new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES), Constants.ELEM_ELEMENT) + : new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ELEM_ELEMENT); this.countQName = new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ATOM_ELEM_COUNT); this.uriQName = diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractJsonDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractJsonDeserializer.java index 4c92ae695..4ba96716d 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractJsonDeserializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractJsonDeserializer.java @@ -23,7 +23,6 @@ import com.fasterxml.jackson.databind.node.ObjectNode; import java.util.Iterator; import java.util.Map; 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.ComplexValue; import org.apache.olingo.commons.api.data.Value; @@ -95,7 +94,7 @@ abstract class AbstractJsonDeserializer extends ODataJacksonDeserializer { for (final Iterator> itor = node.fields(); itor.hasNext();) { final Map.Entry field = itor.next(); - if (type == null && field.getKey().endsWith(Constants.JSON_TYPE_SUFFIX)) { + if (type == null && field.getKey().endsWith(getJSONAnnotation(jsonType))) { type = field.getValue().asText(); } else { final JSONPropertyImpl property = new JSONPropertyImpl(); @@ -122,10 +121,14 @@ abstract class AbstractJsonDeserializer extends ODataJacksonDeserializer { final JsonNode child = nodeItor.next(); if (child.isValueNode()) { - value.get().add(fromPrimitive(child, type)); + if (typeInfo == null || typeInfo.isPrimitiveType()) { + value.get().add(fromPrimitive(child, type)); + } else { + value.get().add(new EnumValueImpl(child.asText())); + } } else if (child.isContainerNode()) { - if (child.has(Constants.JSON_TYPE)) { - ((ObjectNode) child).remove(Constants.JSON_TYPE); + if (child.has(jsonType)) { + ((ObjectNode) child).remove(jsonType); } value.get().add(fromComplex(child)); } @@ -145,6 +148,8 @@ abstract class AbstractJsonDeserializer extends ODataJacksonDeserializer { ? ODataPropertyType.COLLECTION : typeInfo.isPrimitiveType() ? ODataPropertyType.PRIMITIVE + : node.isValueNode() + ? ODataPropertyType.ENUM : ODataPropertyType.COMPLEX; switch (propType) { @@ -153,13 +158,17 @@ abstract class AbstractJsonDeserializer extends ODataJacksonDeserializer { break; case COMPLEX: - if (node.has(Constants.JSON_TYPE)) { - property.setType(node.get(Constants.JSON_TYPE).asText()); - ((ObjectNode) node).remove(Constants.JSON_TYPE); + if (node.has(jsonType)) { + property.setType(node.get(jsonType).asText()); + ((ObjectNode) node).remove(jsonType); } property.setValue(fromComplex(node)); break; + case ENUM: + property.setValue(new EnumValueImpl(node.asText())); + break; + case PRIMITIVE: if (property.getType() == null) { property.setType(getPrimitiveType(node).getFullQualifiedName().toString()); diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractJsonSerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractJsonSerializer.java index 1380dd54d..dede6aaad 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractJsonSerializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractJsonSerializer.java @@ -56,22 +56,24 @@ abstract class AbstractJsonSerializer extends ODataJacksonSerializer { if (value.isNull()) { jgen.writeNull(); - } else if (value.isSimple()) { + } else if (value.isPrimitive()) { final boolean isNumber = typeInfo == null - ? NumberUtils.isNumber(value.asSimple().get()) + ? NumberUtils.isNumber(value.asPrimitive().get()) : ArrayUtils.contains(NUMBER_TYPES, typeInfo.getPrimitiveTypeKind()); final boolean isBoolean = typeInfo == null - ? (value.asSimple().get().equalsIgnoreCase(Boolean.TRUE.toString()) - || value.asSimple().get().equalsIgnoreCase(Boolean.FALSE.toString())) + ? (value.asPrimitive().get().equalsIgnoreCase(Boolean.TRUE.toString()) + || value.asPrimitive().get().equalsIgnoreCase(Boolean.FALSE.toString())) : typeInfo.getPrimitiveTypeKind() == EdmPrimitiveTypeKind.Boolean; if (isNumber) { - jgen.writeNumber(value.asSimple().get()); + jgen.writeNumber(value.asPrimitive().get()); } else if (isBoolean) { - jgen.writeBoolean(BooleanUtils.toBoolean(value.asSimple().get())); + jgen.writeBoolean(BooleanUtils.toBoolean(value.asPrimitive().get())); } else { - jgen.writeString(value.asSimple().get()); + jgen.writeString(value.asPrimitive().get()); } + } else if (value.isEnum()) { + jgen.writeString(value.asEnum().get()); } else if (value.isGeospatial()) { jgen.writeStartObject(); geoSerializer.serialize(jgen, value.asGeospatial().get()); diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractODataObject.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractODataObject.java index 3bcef747e..6dd86a28d 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractODataObject.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractODataObject.java @@ -31,8 +31,6 @@ abstract class AbstractODataObject extends AbstractPayloadObject { private URI baseURI; - private URI contextURL; - private String id; private String title; @@ -49,20 +47,6 @@ abstract class AbstractODataObject extends AbstractPayloadObject { this.baseURI = URI.create(baseURI); } - /** - * The context URL describes the content of the payload. It consists of the canonical metadata document URL and a - * fragment identifying the relevant portion of the metadata document. - * - * @return context URL. - */ - public URI getContextURL() { - return contextURL; - } - - public void setContextURL(final URI contextURL) { - this.contextURL = contextURL; - } - public String getId() { return id; } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractPropertyImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractPropertyImpl.java index b3ca45906..e005f98fe 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractPropertyImpl.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractPropertyImpl.java @@ -18,7 +18,6 @@ */ package org.apache.olingo.commons.core.data; -import java.net.URI; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; import org.apache.commons.lang3.builder.ReflectionToStringBuilder; @@ -28,29 +27,12 @@ import org.apache.olingo.commons.api.data.Value; public abstract class AbstractPropertyImpl implements Property { - private URI contextURL; - private String name; private String type; private Value value; - /** - * The context URL describes the content of the payload. It consists of the canonical metadata document URL and a - * fragment identifying the relevant portion of the metadata document. - * - * @return context URL. - */ - @Override - public URI getContextURL() { - return contextURL; - } - - public void setContextURL(final URI contextURL) { - this.contextURL = contextURL; - } - @Override public String getName() { return name; diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractValue.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractValue.java index 31629e2e9..629592fd4 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractValue.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractValue.java @@ -24,6 +24,7 @@ import org.apache.commons.lang3.builder.ReflectionToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; import org.apache.olingo.commons.api.data.CollectionValue; import org.apache.olingo.commons.api.data.ComplexValue; +import org.apache.olingo.commons.api.data.EnumValue; import org.apache.olingo.commons.api.data.GeospatialValue; import org.apache.olingo.commons.api.data.NullValue; import org.apache.olingo.commons.api.data.PrimitiveValue; @@ -37,7 +38,7 @@ public abstract class AbstractValue implements Value { } @Override - public boolean isSimple() { + public boolean isPrimitive() { return false; } @@ -46,6 +47,11 @@ public abstract class AbstractValue implements Value { return false; } + @Override + public boolean isEnum() { + return false; + } + @Override public boolean isComplex() { return false; @@ -62,8 +68,8 @@ public abstract class AbstractValue implements Value { } @Override - public PrimitiveValue asSimple() { - return isSimple() ? (PrimitiveValue) this : null; + public PrimitiveValue asPrimitive() { + return isPrimitive() ? (PrimitiveValue) this : null; } @Override @@ -71,6 +77,11 @@ public abstract class AbstractValue implements Value { return isGeospatial() ? (GeospatialValue) this : null; } + @Override + public EnumValue asEnum() { + return isEnum() ? (EnumValue) this : null; + } + @Override public ComplexValue asComplex() { return isComplex() ? (ComplexValue) this : null; 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 d863eb6f5..a16d4ed26 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 @@ -384,6 +384,7 @@ public class AtomDeserializer extends AbstractAtomDealer { @SuppressWarnings("unchecked") public Container read(final InputStream input, final Class reference) throws XMLStreamException { + if (AtomFeedImpl.class.equals(reference)) { return (Container) feed(input); } else if (AtomEntryImpl.class.equals(reference)) { diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomPropertyDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomPropertyDeserializer.java index fd466ea9d..1e60a3c71 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomPropertyDeserializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomPropertyDeserializer.java @@ -18,8 +18,6 @@ */ package org.apache.olingo.commons.core.data; -import java.net.URI; -import javax.xml.namespace.QName; import javax.xml.stream.XMLEventReader; import javax.xml.stream.XMLStreamException; import javax.xml.stream.events.Attribute; @@ -28,7 +26,6 @@ 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.ComplexValue; import org.apache.olingo.commons.api.data.Value; import org.apache.olingo.commons.api.domain.ODataPropertyType; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; @@ -73,17 +70,24 @@ class AtomPropertyDeserializer extends AbstractAtomDealer { return value; } - private ComplexValue fromComplex(final XMLEventReader reader, final StartElement start) + private Value fromComplexOrEnum(final XMLEventReader reader, final StartElement start) throws XMLStreamException { - final ComplexValue value = new ComplexValueImpl(); + Value value = null; boolean foundEndProperty = false; while (reader.hasNext() && !foundEndProperty) { final XMLEvent event = reader.nextEvent(); if (event.isStartElement()) { - value.get().add(deserialize(reader, event.asStartElement())); + if (value == null) { + value = new ComplexValueImpl(); + } + value.asComplex().get().add(deserialize(reader, event.asStartElement())); + } + + if (event.isCharacters() && !event.asCharacters().isWhiteSpace()) { + value = new EnumValueImpl(event.asCharacters().getData()); } if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) { @@ -108,9 +112,10 @@ class AtomPropertyDeserializer extends AbstractAtomDealer { final XMLEvent event = reader.nextEvent(); if (event.isStartElement()) { - switch (guessPropertyType(reader)) { + switch (guessPropertyType(reader, typeInfo)) { case COMPLEX: - value.get().add(fromComplex(reader, event.asStartElement())); + case ENUM: + value.get().add(fromComplexOrEnum(reader, event.asStartElement())); break; case PRIMITIVE: @@ -130,7 +135,9 @@ class AtomPropertyDeserializer extends AbstractAtomDealer { return value; } - private ODataPropertyType guessPropertyType(final XMLEventReader reader) throws XMLStreamException { + private ODataPropertyType guessPropertyType(final XMLEventReader reader, final EdmTypeInfo typeInfo) + throws XMLStreamException { + XMLEvent child = null; while (reader.hasNext() && child == null) { final XMLEvent event = reader.peek(); @@ -143,7 +150,9 @@ class AtomPropertyDeserializer extends AbstractAtomDealer { final ODataPropertyType type; if (child == null) { - type = ODataPropertyType.PRIMITIVE; + type = typeInfo == null || typeInfo.isPrimitiveType() + ? ODataPropertyType.PRIMITIVE + : ODataPropertyType.ENUM; } else { if (child.isStartElement()) { if (Constants.NS_GML.equals(child.asStartElement().getName().getNamespaceURI())) { @@ -154,7 +163,9 @@ class AtomPropertyDeserializer extends AbstractAtomDealer { type = ODataPropertyType.COMPLEX; } } else if (child.isCharacters()) { - type = ODataPropertyType.PRIMITIVE; + type = typeInfo == null || typeInfo.isPrimitiveType() + ? ODataPropertyType.PRIMITIVE + : ODataPropertyType.ENUM; } else { type = ODataPropertyType.EMPTY; } @@ -165,20 +176,17 @@ class AtomPropertyDeserializer extends AbstractAtomDealer { public AtomPropertyImpl deserialize(final XMLEventReader reader, final StartElement start) throws XMLStreamException { + final AtomPropertyImpl property = new AtomPropertyImpl(); - final Attribute context = start.getAttributeByName(contextQName); - - property.setContextURL(context == null ? null : URI.create(context.getValue())); - - final QName name = start.getName(); - - if (ODataServiceVersion.V40 == version && v4PropertyValueQName.equals(name)) { + if (ODataServiceVersion.V40 == version && v4PropertyValueQName.equals(start.getName())) { // retrieve name from context - final String contextURL = property.getContextURL().toASCIIString(); - property.setName(contextURL.substring(contextURL.lastIndexOf("/") + 1)); + final Attribute context = start.getAttributeByName(contextQName); + if (context != null) { + property.setName(StringUtils.substringAfterLast(context.getValue(), "/")); + } } else { - property.setName(name.getLocalPart()); + property.setName(start.getName().getLocalPart()); } final Attribute nullAttr = start.getAttributeByName(this.nullQName); @@ -197,7 +205,7 @@ class AtomPropertyDeserializer extends AbstractAtomDealer { } final ODataPropertyType propType = typeInfo == null - ? guessPropertyType(reader) + ? guessPropertyType(reader, typeInfo) : typeInfo.isCollection() ? ODataPropertyType.COLLECTION : typeInfo.isPrimitiveType() @@ -210,7 +218,7 @@ class AtomPropertyDeserializer extends AbstractAtomDealer { break; case COMPLEX: - value = fromComplex(reader, start); + value = fromComplexOrEnum(reader, start); break; case PRIMITIVE: diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomPropertySerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomPropertySerializer.java index 412a127a0..0461ad2aa 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomPropertySerializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomPropertySerializer.java @@ -26,6 +26,7 @@ import org.apache.olingo.commons.api.data.CollectionValue; import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.commons.api.data.Value; import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; +import org.apache.olingo.commons.core.edm.EdmTypeInfo; class AtomPropertySerializer extends AbstractAtomDealer { @@ -38,16 +39,23 @@ class AtomPropertySerializer extends AbstractAtomDealer { private void collection(final XMLStreamWriter writer, final CollectionValue value) throws XMLStreamException { for (Value item : value.get()) { - writer.writeStartElement(Constants.PREFIX_DATASERVICES, Constants.ELEM_ELEMENT, - version.getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES)); + if (version == ODataServiceVersion.V30) { + writer.writeStartElement(Constants.PREFIX_DATASERVICES, Constants.ELEM_ELEMENT, + version.getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES)); + } else { + writer.writeStartElement(Constants.PREFIX_METADATA, Constants.ELEM_ELEMENT, + version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA)); + } value(writer, item); writer.writeEndElement(); } } private void value(final XMLStreamWriter writer, final Value value) throws XMLStreamException { - if (value.isSimple()) { - writer.writeCharacters(value.asSimple().get()); + if (value.isPrimitive()) { + writer.writeCharacters(value.asPrimitive().get()); + } else if (value.isEnum()) { + writer.writeCharacters(value.asEnum().get()); } else if (value.isGeospatial()) { this.geoSerializer.serialize(writer, value.asGeospatial().get()); } else if (value.isCollection()) { @@ -62,22 +70,34 @@ class AtomPropertySerializer extends AbstractAtomDealer { public void property(final XMLStreamWriter writer, final Property property, final boolean standalone) throws XMLStreamException { - writer.writeStartElement(Constants.PREFIX_DATASERVICES, property.getName(), - version.getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES)); - - if (version == ODataServiceVersion.V40 && property.getContextURL() != null) { - writer.writeAttribute( - version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), - Constants.CONTEXT, - property.getContextURL().toASCIIString()); + if (version == ODataServiceVersion.V40 && standalone) { + writer.writeStartElement(Constants.PREFIX_METADATA, Constants.VALUE, + version.getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES)); + } else { + writer.writeStartElement(Constants.PREFIX_DATASERVICES, property.getName(), + version.getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES)); } if (standalone) { namespaces(writer); } + if (StringUtils.isNotBlank(property.getType())) { + String type = property.getType(); + if (version == ODataServiceVersion.V40) { + final EdmTypeInfo typeInfo = new EdmTypeInfo.Builder().setTypeExpression(property.getType()).build(); + if (typeInfo.isPrimitiveType()) { + if (typeInfo.isCollection()) { + type = "#Collection(" + typeInfo.getFullQualifiedName().getName() + ")"; + } else { + type = typeInfo.getFullQualifiedName().getName(); + } + } else { + type = "#" + property.getType(); + } + } writer.writeAttribute(Constants.PREFIX_METADATA, version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), - Constants.ATTR_TYPE, property.getType()); + Constants.ATTR_TYPE, type); } if (property.getValue().isNull()) { diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomSerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomSerializer.java index 4bcd3bff7..c3be42036 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomSerializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomSerializer.java @@ -127,13 +127,6 @@ public class AtomSerializer extends AbstractAtomDealer { } private void entry(final XMLStreamWriter writer, final Entry entry) throws XMLStreamException { - if (version == ODataServiceVersion.V40 && entry.getContextURL() != null) { - writer.writeAttribute( - version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), - Constants.CONTEXT, - entry.getContextURL().toASCIIString()); - } - if (entry.getBaseURI() != null) { writer.writeAttribute(XMLConstants.XML_NS_URI, Constants.ATTR_XML_BASE, entry.getBaseURI().toASCIIString()); } @@ -191,13 +184,6 @@ public class AtomSerializer extends AbstractAtomDealer { } private void feed(final XMLStreamWriter writer, final Feed feed) throws XMLStreamException { - if (version == ODataServiceVersion.V40 && feed.getContextURL() != null) { - writer.writeAttribute( - version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), - Constants.CONTEXT, - feed.getContextURL().toASCIIString()); - } - if (feed.getBaseURI() != null) { writer.writeAttribute(XMLConstants.XML_NS_URI, Constants.ATTR_XML_BASE, feed.getBaseURI().toASCIIString()); } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/EnumValueImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/EnumValueImpl.java new file mode 100644 index 000000000..5d79d2279 --- /dev/null +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/EnumValueImpl.java @@ -0,0 +1,41 @@ +/* + * 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.data; + +import org.apache.olingo.commons.api.data.EnumValue; + +public class EnumValueImpl extends AbstractValue implements EnumValue { + + private final String value; + + public EnumValueImpl(final String value) { + this.value = value; + } + + @Override + public boolean isEnum() { + return true; + } + + @Override + public String get() { + return value; + } + +} diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntryDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntryDeserializer.java index e87daa0e9..eaaa65369 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntryDeserializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntryDeserializer.java @@ -88,13 +88,17 @@ public class JSONEntryDeserializer extends AbstractJsonDeserializer> itor = tree.fields(); itor.hasNext();) { final Map.Entry field = itor.next(); - if (field.getKey().endsWith(Constants.JSON_NAVIGATION_LINK_SUFFIX)) { + if (field.getKey().endsWith(jsonNavigationLink)) { final LinkImpl link = new LinkImpl(); link.setTitle(getTitle(field)); link.setRel(version.getNamespaceMap().get(ODataServiceVersion.NAVIGATION_LINK_REL) + getTitle(field)); @@ -168,8 +172,8 @@ public class JSONEntryDeserializer extends AbstractJsonDeserializer> itor = tree.fields(); itor.hasNext();) { final Map.Entry field = itor.next(); - if (type == null && field.getKey().endsWith(Constants.JSON_TYPE_SUFFIX)) { + if (type == null && field.getKey().endsWith(getJSONAnnotation(jsonType))) { type = field.getValue().asText(); } else { final JSONPropertyImpl property = new JSONPropertyImpl(); diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntryImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntryImpl.java index 10123d452..a83332ab0 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntryImpl.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntryImpl.java @@ -20,8 +20,6 @@ package org.apache.olingo.commons.core.data; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import java.net.URI; -import org.apache.olingo.commons.api.Constants; /** * A single entry, represented via JSON. @@ -34,17 +32,6 @@ public class JSONEntryImpl extends AbstractEntry { private String mediaETag; - @Override - public URI getBaseURI() { - URI baseURI = null; - if (getContextURL() != null) { - final String metadataURI = getContextURL().toASCIIString(); - baseURI = URI.create(metadataURI.substring(0, metadataURI.indexOf(Constants.METADATA))); - } - - return baseURI; - } - /** * The odata.mediaEtag annotation MAY be included; its value MUST be the ETag of the binary stream represented by this * media entity or named stream property. diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntrySerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntrySerializer.java index bd5a145c6..eb51362c8 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntrySerializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntrySerializer.java @@ -45,14 +45,8 @@ public class JSONEntrySerializer extends AbstractJsonSerializer { jgen.writeStartObject(); - if (entry.getContextURL() != null) { - jgen.writeStringField( - version == ODataServiceVersion.V40 ? Constants.JSON_CONTEXT : Constants.JSON_METADATA, - entry.getContextURL().toASCIIString()); - } - if (entry.getId() != null) { - jgen.writeStringField(Constants.JSON_ID, entry.getId()); + jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_ID), entry.getId()); } final Map> entitySetLinks = new HashMap>(); @@ -100,7 +94,7 @@ public class JSONEntrySerializer extends AbstractJsonSerializer { for (Link link : entry.getMediaEditLinks()) { if (link.getTitle() == null) { - jgen.writeStringField(Constants.JSON_MEDIAEDIT_LINK, link.getHref()); + jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_MEDIAEDIT_LINK), link.getHref()); } if (link.getInlineEntry() != null) { diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONFeedImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONFeedImpl.java index e89bb1f6b..8994e880a 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONFeedImpl.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONFeedImpl.java @@ -51,22 +51,14 @@ public class JSONFeedImpl extends AbstractPayloadObject implements Feed { @Override public URI getBaseURI() { URI baseURI = null; - if (getContextURL() != null) { - final String metadataURI = getContextURL().toASCIIString(); + if (contextURL != null) { + final String metadataURI = contextURL.toASCIIString(); baseURI = URI.create(metadataURI.substring(0, metadataURI.indexOf(Constants.METADATA))); } return baseURI; } - /** - * {@inheritDoc} - */ - @Override - public URI getContextURL() { - return contextURL; - } - public void setContextURL(final URI context) { this.contextURL = context; } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONFeedSerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONFeedSerializer.java index df359b888..649bc990c 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONFeedSerializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONFeedSerializer.java @@ -34,13 +34,8 @@ public class JSONFeedSerializer extends AbstractJsonSerializer { jgen.writeStartObject(); - if (feed.getContextURL() != null) { - jgen.writeStringField( - version == ODataServiceVersion.V40 ? Constants.JSON_CONTEXT : Constants.JSON_METADATA, - feed.getContextURL().toASCIIString()); - } if (feed.getId() != null) { - jgen.writeStringField(Constants.JSON_ID, feed.getId()); + jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_ID), feed.getId()); } if (feed.getCount() != null) { jgen.writeNumberField(Constants.JSON_COUNT, feed.getCount()); diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONPropertyDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONPropertyDeserializer.java index 8af23e1ed..1215c5db2 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONPropertyDeserializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONPropertyDeserializer.java @@ -23,7 +23,6 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.node.ObjectNode; import java.io.IOException; -import java.net.URI; import org.apache.olingo.commons.api.Constants; /** @@ -41,24 +40,24 @@ public class JSONPropertyDeserializer extends AbstractJsonDeserializerJSONPropertyImpl. @@ -39,16 +38,12 @@ public class JSONPropertySerializer extends AbstractJsonSerializer extends JsonDeserializer { protected ODataServiceVersion version; + protected String jsonType; + + protected String jsonId; + + protected String jsonReadLink; + + protected String jsonEditLink; + + protected String jsonMediaEditLink; + + protected String jsonMediaReadLink; + + protected String jsonAssociationLink; + + protected String jsonNavigationLink; + protected abstract T doDeserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException; + protected String getJSONAnnotation(final String string) { + return string.startsWith("@") ? string : "@" + string; + } + @Override public T deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException, JsonProcessingException { version = (ODataServiceVersion) ctxt.findInjectableValue(ODataServiceVersion.class.getName(), null, null); + + jsonType = version.getJSONMap().get(ODataServiceVersion.JSON_TYPE); + jsonId = version.getJSONMap().get(ODataServiceVersion.JSON_ID); + jsonReadLink = version.getJSONMap().get(ODataServiceVersion.JSON_READ_LINK); + jsonEditLink = version.getJSONMap().get(ODataServiceVersion.JSON_EDIT_LINK); + jsonMediaReadLink = version.getJSONMap().get(ODataServiceVersion.JSON_MEDIAREAD_LINK); + jsonMediaEditLink = version.getJSONMap().get(ODataServiceVersion.JSON_MEDIAEDIT_LINK); + jsonAssociationLink = version.getJSONMap().get(ODataServiceVersion.JSON_ASSOCIATION_LINK); + jsonNavigationLink = version.getJSONMap().get(ODataServiceVersion.JSON_NAVIGATION_LINK); + return doDeserialize(jp, ctxt); } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/PrimitiveValueImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/PrimitiveValueImpl.java index 2d0a6bc0c..b3334ae33 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/PrimitiveValueImpl.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/PrimitiveValueImpl.java @@ -29,7 +29,7 @@ public class PrimitiveValueImpl extends AbstractValue implements PrimitiveValue } @Override - public boolean isSimple() { + public boolean isPrimitive() { return true; }