Repository: olingo-odata2 Updated Branches: refs/heads/master 7d71cee8f -> 9a8261a1c
[OLINGO-308] rollback Project: http://git-wip-us.apache.org/repos/asf/olingo-odata2/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata2/commit/9a8261a1 Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata2/tree/9a8261a1 Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata2/diff/9a8261a1 Branch: refs/heads/master Commit: 9a8261a1c7948f459614fb37414757f366eac726 Parents: 7d71cee Author: Stephan Klevenz <[email protected]> Authored: Mon Jun 2 16:06:09 2014 +0200 Committer: Stephan Klevenz <[email protected]> Committed: Mon Jun 2 16:06:09 2014 +0200 ---------------------------------------------------------------------- .../api/ep/EntityProviderWriteProperties.java | 11 -- .../ep/producer/AtomEntryEntityProducer.java | 131 ++++++++----------- .../ep/producer/JsonEntryEntityProducer.java | 35 ++--- .../core/ep/producer/AtomEntryProducerTest.java | 22 ---- .../producer/JsonEntryEntityProducerTest.java | 25 ---- 5 files changed, 69 insertions(+), 155 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/9a8261a1/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/ep/EntityProviderWriteProperties.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/ep/EntityProviderWriteProperties.java b/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/ep/EntityProviderWriteProperties.java index 1fa674f..822fc84 100644 --- a/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/ep/EntityProviderWriteProperties.java +++ b/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/ep/EntityProviderWriteProperties.java @@ -44,7 +44,6 @@ public class EntityProviderWriteProperties { private URI selfLink; private boolean includeSimplePropertyType; private Map<String, Map<String, Object>> additionalLinks; - private boolean ignoreKey = false; private EntityProviderWriteProperties() {} @@ -240,12 +239,6 @@ public class EntityProviderWriteProperties { this.properties.selfLink = properties.getSelfLink(); this.properties.includeSimplePropertyType = properties.includeSimplePropertyType; this.properties.additionalLinks = properties.additionalLinks; - this.properties.ignoreKey = properties.ignoreKey; - return this; - } - - public ODataEntityProviderPropertiesBuilder ignoreKey(boolean ignoreKey) { - properties.ignoreKey = ignoreKey; return this; } } @@ -255,8 +248,4 @@ public class EntityProviderWriteProperties { EntityProviderWriteProperties.serviceRoot(properties.getServiceRoot()); return builder.fromProperties(properties); } - - public boolean isIgnoreKey() { - return ignoreKey; - } } http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/9a8261a1/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryEntityProducer.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryEntityProducer.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryEntityProducer.java index 4036df5..95702dd 100644 --- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryEntityProducer.java +++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryEntityProducer.java @@ -95,11 +95,7 @@ public class AtomEntryEntityProducer { } // write all atom infos (mandatory and optional) - String selfLink = null; - if (!properties.isIgnoreKey()) { - selfLink = createSelfLink(eia, data, null); - } - + String selfLink = createSelfLink(eia, data, null); appendAtomMandatoryParts(writer, eia, data, selfLink); appendAtomOptionalParts(writer, eia, data); @@ -189,9 +185,7 @@ public class AtomEntryEntityProducer { final Map<String, Map<String, Object>> links = properties.getAdditionalLinks(); final Map<String, Object> key = links == null ? null : links.get(name); if (key == null || key.isEmpty()) { - if (!properties.isIgnoreKey()) { - appendAtomNavigationLink(writer, createSelfLink(eia, data, name), name, isFeed, eia, data); - } + appendAtomNavigationLink(writer, createSelfLink(eia, data, name), name, isFeed, eia, data); } else { final EntityInfoAggregator targetEntityInfo = EntityInfoAggregator.create( eia.getEntitySet().getRelatedEntitySet((EdmNavigationProperty) eia.getEntityType().getProperty(name))); @@ -312,13 +306,11 @@ public class AtomEntryEntityProducer { private void appendAtomEditLink(final XMLStreamWriter writer, final EntityInfoAggregator eia, final Map<String, Object> data, final String selfLink) throws EntityProviderException { try { - if (selfLink != null) { - writer.writeStartElement(FormatXml.ATOM_LINK); - writer.writeAttribute(FormatXml.ATOM_HREF, selfLink); - writer.writeAttribute(FormatXml.ATOM_REL, Edm.LINK_REL_EDIT); - writer.writeAttribute(FormatXml.ATOM_TITLE, eia.getEntityType().getName()); - writer.writeEndElement(); - } + writer.writeStartElement(FormatXml.ATOM_LINK); + writer.writeAttribute(FormatXml.ATOM_HREF, selfLink); + writer.writeAttribute(FormatXml.ATOM_REL, Edm.LINK_REL_EDIT); + writer.writeAttribute(FormatXml.ATOM_TITLE, eia.getEntityType().getName()); + writer.writeEndElement(); } catch (XMLStreamException e) { throw new EntityProviderException(EntityProviderException.COMMON, e); } catch (EdmException e) { @@ -329,27 +321,25 @@ public class AtomEntryEntityProducer { private void appendAtomContentLink(final XMLStreamWriter writer, final EntityInfoAggregator eia, final Map<String, Object> data, final String selfLink) throws EntityProviderException, EdmException { try { - if (selfLink != null) { - String mediaResourceMimeType = properties.getMediaResourceMimeType(); - if (mediaResourceMimeType == null) { - EdmMapping entityTypeMapping = eia.getEntityType().getMapping(); - if (entityTypeMapping != null) { - String mediaResourceMimeTypeKey = entityTypeMapping.getMediaResourceMimeTypeKey(); - if (mediaResourceMimeTypeKey != null) { - mediaResourceMimeType = (String) data.get(mediaResourceMimeTypeKey); - } - } - if (mediaResourceMimeType == null) { - mediaResourceMimeType = ContentType.APPLICATION_OCTET_STREAM.toString(); + String mediaResourceMimeType = properties.getMediaResourceMimeType(); + if (mediaResourceMimeType == null) { + EdmMapping entityTypeMapping = eia.getEntityType().getMapping(); + if (entityTypeMapping != null) { + String mediaResourceMimeTypeKey = entityTypeMapping.getMediaResourceMimeTypeKey(); + if (mediaResourceMimeTypeKey != null) { + mediaResourceMimeType = (String) data.get(mediaResourceMimeTypeKey); } } - - writer.writeStartElement(FormatXml.ATOM_LINK); - writer.writeAttribute(FormatXml.ATOM_HREF, selfLink + "/$value"); - writer.writeAttribute(FormatXml.ATOM_REL, Edm.LINK_REL_EDIT_MEDIA); - writer.writeAttribute(FormatXml.ATOM_TYPE, mediaResourceMimeType); - writer.writeEndElement(); + if (mediaResourceMimeType == null) { + mediaResourceMimeType = ContentType.APPLICATION_OCTET_STREAM.toString(); + } } + + writer.writeStartElement(FormatXml.ATOM_LINK); + writer.writeAttribute(FormatXml.ATOM_HREF, selfLink + "/$value"); + writer.writeAttribute(FormatXml.ATOM_REL, Edm.LINK_REL_EDIT_MEDIA); + writer.writeAttribute(FormatXml.ATOM_TYPE, mediaResourceMimeType); + writer.writeEndElement(); } catch (XMLStreamException e) { throw new EntityProviderException(EntityProviderException.COMMON, e); } @@ -358,44 +348,42 @@ public class AtomEntryEntityProducer { private void appendAtomContentPart(final XMLStreamWriter writer, final EntityInfoAggregator eia, final Map<String, Object> data, final String selfLink) throws EntityProviderException, EdmException { try { - if (selfLink != null) { - // We have to support the media resource mime type at the properties till version 1.2 then this can be - // refactored - String mediaResourceMimeType = properties.getMediaResourceMimeType(); - EdmMapping entityTypeMapping = eia.getEntityType().getMapping(); - String self = null; - if (entityTypeMapping != null) { - String mediaResourceSourceKey = entityTypeMapping.getMediaResourceSourceKey(); - if (mediaResourceSourceKey != null) { - self = (String) data.get(mediaResourceSourceKey); - } - if (self == null) { - self = selfLink + "/$value"; - } - if (mediaResourceMimeType == null) { - String mediaResourceMimeTypeKey = - entityTypeMapping.getMimeType() != null ? entityTypeMapping.getMimeType() - : entityTypeMapping.getMediaResourceMimeTypeKey(); - if (mediaResourceMimeTypeKey != null) { - mediaResourceMimeType = (String) data.get(mediaResourceMimeTypeKey); - } - if (mediaResourceMimeType == null) { - mediaResourceMimeType = ContentType.APPLICATION_OCTET_STREAM.toString(); - } - } - } else { + // We have to support the media resource mime type at the properties till version 1.2 then this can be refactored + String mediaResourceMimeType = properties.getMediaResourceMimeType(); + EdmMapping entityTypeMapping = eia.getEntityType().getMapping(); + String self = null; + + if (entityTypeMapping != null) { + String mediaResourceSourceKey = entityTypeMapping.getMediaResourceSourceKey(); + if (mediaResourceSourceKey != null) { + self = (String) data.get(mediaResourceSourceKey); + } + if (self == null) { self = selfLink + "/$value"; + } + if (mediaResourceMimeType == null) { + String mediaResourceMimeTypeKey = + entityTypeMapping.getMimeType() != null ? entityTypeMapping.getMimeType() + : entityTypeMapping.getMediaResourceMimeTypeKey(); + if (mediaResourceMimeTypeKey != null) { + mediaResourceMimeType = (String) data.get(mediaResourceMimeTypeKey); + } if (mediaResourceMimeType == null) { mediaResourceMimeType = ContentType.APPLICATION_OCTET_STREAM.toString(); } } - - writer.writeStartElement(FormatXml.ATOM_CONTENT); - writer.writeAttribute(FormatXml.ATOM_TYPE, mediaResourceMimeType); - writer.writeAttribute(FormatXml.ATOM_SRC, self); - writer.writeEndElement(); + } else { + self = selfLink + "/$value"; + if (mediaResourceMimeType == null) { + mediaResourceMimeType = ContentType.APPLICATION_OCTET_STREAM.toString(); + } } + + writer.writeStartElement(FormatXml.ATOM_CONTENT); + writer.writeAttribute(FormatXml.ATOM_TYPE, mediaResourceMimeType); + writer.writeAttribute(FormatXml.ATOM_SRC, self); + writer.writeEndElement(); } catch (XMLStreamException e) { throw new EntityProviderException(EntityProviderException.COMMON, e); } @@ -404,12 +392,10 @@ public class AtomEntryEntityProducer { private void appendAtomMandatoryParts(final XMLStreamWriter writer, final EntityInfoAggregator eia, final Map<String, Object> data, final String selfLink) throws EntityProviderException { try { - if (selfLink != null) { - writer.writeStartElement(FormatXml.ATOM_ID); - location = properties.getServiceRoot().toASCIIString() + selfLink; - writer.writeCharacters(location); - writer.writeEndElement(); - } + writer.writeStartElement(FormatXml.ATOM_ID); + location = properties.getServiceRoot().toASCIIString() + selfLink; + writer.writeCharacters(location); + writer.writeEndElement(); writer.writeStartElement(FormatXml.ATOM_TITLE); writer.writeAttribute(FormatXml.ATOM_TYPE, FormatXml.ATOM_TEXT); @@ -585,10 +571,7 @@ public class AtomEntryEntityProducer { if (isNotMappedViaCustomMapping(propertyInfo)) { Object value = data.get(propertyName); XmlPropertyEntityProducer aps = new XmlPropertyEntityProducer(properties.isIncludeSimplePropertyType()); - - if (!(eia.getKeyPropertyInfos().contains(propertyInfo) && properties.isIgnoreKey())) { - aps.append(writer, propertyInfo.getName(), propertyInfo, value); - } + aps.append(writer, propertyInfo.getName(), propertyInfo, value); } } http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/9a8261a1/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/JsonEntryEntityProducer.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/JsonEntryEntityProducer.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/JsonEntryEntityProducer.java index c1b52fa..8ad5d42 100644 --- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/JsonEntryEntityProducer.java +++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/JsonEntryEntityProducer.java @@ -45,7 +45,6 @@ import org.apache.olingo.odata2.api.exception.ODataApplicationException; import org.apache.olingo.odata2.core.commons.ContentType; import org.apache.olingo.odata2.core.commons.Encoder; import org.apache.olingo.odata2.core.ep.aggregator.EntityInfoAggregator; -import org.apache.olingo.odata2.core.ep.aggregator.EntityPropertyInfo; import org.apache.olingo.odata2.core.ep.util.FormatJson; import org.apache.olingo.odata2.core.ep.util.JsonStreamWriter; @@ -81,10 +80,8 @@ public class JsonEntryEntityProducer { writeProperties(entityInfo, data, type); - if (!properties.isIgnoreKey()) { - writeNavigationProperties(writer, entityInfo, data, type); - } - + writeNavigationProperties(writer, entityInfo, data, type); + jsonStreamWriter.endObject(); if (isRootElement) { @@ -178,15 +175,10 @@ public class JsonEntryEntityProducer { final EdmEntityType type) throws EdmException, EntityProviderException, IOException { for (final String propertyName : type.getPropertyNames()) { if (entityInfo.getSelectedPropertyNames().contains(propertyName)) { - - EntityPropertyInfo propertyInfo = entityInfo.getPropertyInfo(propertyName); - if (!(entityInfo.getKeyPropertyInfos().contains(propertyInfo) && properties.isIgnoreKey())) { - - jsonStreamWriter.separator(); - jsonStreamWriter.name(propertyName); - JsonPropertyEntityProducer.appendPropertyValue(jsonStreamWriter, entityInfo.getPropertyInfo(propertyName), - data.get(propertyName)); - } + jsonStreamWriter.separator(); + jsonStreamWriter.name(propertyName); + JsonPropertyEntityProducer.appendPropertyValue(jsonStreamWriter, entityInfo.getPropertyInfo(propertyName), + data.get(propertyName)); } } } @@ -195,15 +187,12 @@ public class JsonEntryEntityProducer { final EdmEntityType type) throws IOException, EntityProviderException, EdmException { jsonStreamWriter.name(FormatJson.METADATA); jsonStreamWriter.beginObject(); - String self = null; - if (!properties.isIgnoreKey()) { - self = AtomEntryEntityProducer.createSelfLink(entityInfo, data, null); - location = (properties.getServiceRoot() == null ? "" : properties.getServiceRoot().toASCIIString()) + self; - jsonStreamWriter.namedStringValue(FormatJson.ID, location); - jsonStreamWriter.separator(); - jsonStreamWriter.namedStringValue(FormatJson.URI, location); - jsonStreamWriter.separator(); - } + final String self = AtomEntryEntityProducer.createSelfLink(entityInfo, data, null); + location = (properties.getServiceRoot() == null ? "" : properties.getServiceRoot().toASCIIString()) + self; + jsonStreamWriter.namedStringValue(FormatJson.ID, location); + jsonStreamWriter.separator(); + jsonStreamWriter.namedStringValue(FormatJson.URI, location); + jsonStreamWriter.separator(); jsonStreamWriter.namedStringValueRaw(FormatJson.TYPE, type.getNamespace() + Edm.DELIMITER + type.getName()); eTag = AtomEntryEntityProducer.createETag(entityInfo, data); if (eTag != null) { http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/9a8261a1/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryProducerTest.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryProducerTest.java b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryProducerTest.java index cd65a8c..a87698d 100644 --- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryProducerTest.java +++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryProducerTest.java @@ -56,7 +56,6 @@ import org.apache.olingo.odata2.api.processor.ODataResponse; import org.apache.olingo.odata2.core.commons.ContentType; import org.apache.olingo.odata2.core.ep.AbstractProviderTest; import org.apache.olingo.odata2.core.ep.AtomEntityProvider; -import org.apache.olingo.odata2.core.ep.consumer.XmlEntityConsumer; import org.apache.olingo.odata2.testutil.helper.StringHelper; import org.apache.olingo.odata2.testutil.helper.XMLUnitHelper; import org.apache.olingo.odata2.testutil.mock.MockFacade; @@ -863,25 +862,4 @@ public class AtomEntryProducerTest extends AbstractProviderTest { private void verifyTagOrdering(final String xmlString, final String... toCheckTags) { XMLUnitHelper.verifyTagOrdering(xmlString, toCheckTags); } - - @Test - public void testPostEntryWithoutId() throws Exception { - roomData.remove("Id"); - - final EntityProviderWriteProperties properties = - EntityProviderWriteProperties.serviceRoot(BASE_URI).ignoreKey(true).build(); - AtomEntityProvider ser = createAtomEntityProvider(); - ODataResponse response = - ser.writeEntry(MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms"), roomData, properties); - - String xmlString = verifyResponse(response); - - assertXpathExists("/a:entry", xmlString); - assertXpathEvaluatesTo(BASE_URI.toASCIIString(), "/a:entry/@xml:base", xmlString); - - assertXpathExists("/a:entry/a:content", xmlString); - assertXpathEvaluatesTo(ContentType.APPLICATION_XML.toString(), "/a:entry/a:content/@type", xmlString); - - assertXpathExists("/a:entry/a:content/m:properties", xmlString); - } } http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/9a8261a1/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonEntryEntityProducerTest.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonEntryEntityProducerTest.java b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonEntryEntityProducerTest.java index 7593349..8efd99a 100644 --- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonEntryEntityProducerTest.java +++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonEntryEntityProducerTest.java @@ -18,8 +18,6 @@ ******************************************************************************/ package org.apache.olingo.odata2.core.ep.producer; -import static org.custommonkey.xmlunit.XMLAssert.assertXpathEvaluatesTo; -import static org.custommonkey.xmlunit.XMLAssert.assertXpathExists; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; @@ -55,8 +53,6 @@ import org.apache.olingo.odata2.api.ep.callback.WriteFeedCallbackResult; import org.apache.olingo.odata2.api.exception.ODataApplicationException; import org.apache.olingo.odata2.api.processor.ODataResponse; import org.apache.olingo.odata2.api.uri.ExpandSelectTreeNode; -import org.apache.olingo.odata2.core.commons.ContentType; -import org.apache.olingo.odata2.core.ep.AtomEntityProvider; import org.apache.olingo.odata2.core.ep.JsonEntityProvider; import org.apache.olingo.odata2.testutil.fit.BaseTest; import org.apache.olingo.odata2.testutil.helper.StringHelper; @@ -774,25 +770,4 @@ public class JsonEntryEntityProducerTest extends BaseTest { assertNotNull(json); return json; } - - @Test - public void testPostEntryWithoutId() throws Exception { - HashMap<String, Object> roomData = new HashMap<String, Object>(); - - roomData.put("Name", "Neu Schwanstein"); - roomData.put("Seats", new Integer(20)); - roomData.put("Version", new Integer(3)); - - final EntityProviderWriteProperties properties = - EntityProviderWriteProperties.serviceRoot(URI.create(BASE_URI)).ignoreKey(true).build(); - ODataResponse response = - new JsonEntityProvider().writeEntry(MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms"), - roomData, properties); - - String json = verifyResponse(response); - - assertEquals("{\"d\":{\"__metadata\":{\"type\":\"RefScenario.Room\",\"etag\":\"W/\\\"3\\\"\"}," - + "\"Name\":\"Neu Schwanstein\",\"Seats\":20,\"Version\":3}}", json); - } - }
