You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ch...@apache.org on 2014/06/26 09:44:48 UTC
[2/3] git commit: [OLINGO-310] ContentOnly flag
[OLINGO-310] ContentOnly flag
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata2/commit/f14dfd46
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata2/tree/f14dfd46
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata2/diff/f14dfd46
Branch: refs/heads/master
Commit: f14dfd46b2a80954fba2feac49405fea5c2cfaf1
Parents: ebc5c79
Author: Christian Amend <ch...@apache.org>
Authored: Wed Jun 25 14:36:38 2014 +0200
Committer: Christian Amend <ch...@apache.org>
Committed: Wed Jun 25 14:37:32 2014 +0200
----------------------------------------------------------------------
.../api/ep/EntityProviderWriteProperties.java | 22 +-
.../ep/producer/AtomEntryEntityProducer.java | 54 +++-
.../ep/producer/JsonEntryEntityProducer.java | 58 ++++-
.../ep/ODataEntityProviderPropertiesTest.java | 4 +
.../core/ep/producer/AtomEntryProducerTest.java | 245 +++++++++++++++++++
.../producer/JsonEntryEntityProducerTest.java | 139 +++++++++++
6 files changed, 497 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/f14dfd46/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 df99f21..b4422ee 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
@@ -24,7 +24,6 @@ import java.util.Map;
import org.apache.olingo.odata2.api.ODataCallback;
import org.apache.olingo.odata2.api.commons.InlineCount;
-import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties.ODataEntityProviderPropertiesBuilder;
import org.apache.olingo.odata2.api.uri.ExpandSelectTreeNode;
/**
@@ -46,9 +45,14 @@ public class EntityProviderWriteProperties {
private boolean includeSimplePropertyType;
private Map<String, Map<String, Object>> additionalLinks;
private boolean omitJsonWrapper;
+ private boolean contentOnly;
private EntityProviderWriteProperties() {}
+ public final boolean isContentOnly() {
+ return contentOnly;
+ }
+
public final boolean isOmitJsonWrapper() {
return omitJsonWrapper;
}
@@ -235,6 +239,17 @@ public class EntityProviderWriteProperties {
return this;
}
+ public ODataEntityProviderPropertiesBuilder omitJsonWrapper(boolean omitJsonWrapper) {
+ properties.omitJsonWrapper = omitJsonWrapper;
+ return this;
+ }
+
+ public ODataEntityProviderPropertiesBuilder contentOnly(boolean contentOnly) {
+ properties.contentOnly = contentOnly;
+ return this;
+ }
+
+
public ODataEntityProviderPropertiesBuilder fromProperties(final EntityProviderWriteProperties properties) {
this.properties.mediaResourceMimeType = properties.getMediaResourceMimeType();
this.properties.inlineCountType = properties.getInlineCountType();
@@ -246,13 +261,10 @@ public class EntityProviderWriteProperties {
this.properties.includeSimplePropertyType = properties.includeSimplePropertyType;
this.properties.additionalLinks = properties.additionalLinks;
this.properties.omitJsonWrapper = properties.omitJsonWrapper;
+ this.properties.contentOnly = properties.contentOnly;
return this;
}
- public ODataEntityProviderPropertiesBuilder omitJsonWrapper(boolean omitJsonWrapper) {
- properties.omitJsonWrapper = omitJsonWrapper;
- return this;
- }
}
public static ODataEntityProviderPropertiesBuilder fromProperties(final EntityProviderWriteProperties properties) {
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/f14dfd46/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 95702dd..bd519e0 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
@@ -25,6 +25,7 @@ import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
@@ -58,6 +59,7 @@ import org.apache.olingo.odata2.core.commons.Encoder;
import org.apache.olingo.odata2.core.edm.EdmDateTimeOffset;
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.FormatXml;
/**
@@ -94,25 +96,36 @@ public class AtomEntryEntityProducer {
writer.writeAttribute(Edm.NAMESPACE_M_2007_08, FormatXml.M_ETAG, etag);
}
- // write all atom infos (mandatory and optional)
- String selfLink = createSelfLink(eia, data, null);
- appendAtomMandatoryParts(writer, eia, data, selfLink);
- appendAtomOptionalParts(writer, eia, data);
-
+ String selfLink = null;
+ if (!properties.isContentOnly()) {
+ // write all atom infos (mandatory and optional)
+ selfLink = createSelfLink(eia, data, null);
+ appendAtomMandatoryParts(writer, eia, data, selfLink);
+ appendAtomOptionalParts(writer, eia, data);
+ }
if (eia.getEntityType().hasStream()) {
// write all links
- appendAtomEditLink(writer, eia, data, selfLink);
- // TODO: fix
- appendAtomContentLink(writer, eia, data, selfLink);
- appendAtomNavigationLinks(writer, eia, data);
+ if (!properties.isContentOnly()) {
+ appendAtomEditLink(writer, eia, data, selfLink);
+ appendAtomContentLink(writer, eia, data, selfLink);
+ appendAtomNavigationLinks(writer, eia, data);
+ } else {
+ appendAdditinalLinks(writer, eia, data);
+ }
// write properties/content
appendCustomProperties(writer, eia, data);
- appendAtomContentPart(writer, eia, data, selfLink);
+ if (!properties.isContentOnly()) {
+ appendAtomContentPart(writer, eia, data, selfLink);
+ }
appendProperties(writer, eia, data);
} else {
// write all links
- appendAtomEditLink(writer, eia, data, selfLink);
- appendAtomNavigationLinks(writer, eia, data);
+ if (!properties.isContentOnly()) {
+ appendAtomEditLink(writer, eia, data, selfLink);
+ appendAtomNavigationLinks(writer, eia, data);
+ } else {
+ appendAdditinalLinks(writer, eia, data);
+ }
// write properties/content
appendCustomProperties(writer, eia, data);
writer.writeStartElement(FormatXml.ATOM_CONTENT);
@@ -133,6 +146,23 @@ public class AtomEntryEntityProducer {
}
}
+ private void appendAdditinalLinks(XMLStreamWriter writer, EntityInfoAggregator eia, Map<String, Object> data)
+ throws EntityProviderException, EdmException, URISyntaxException {
+ final Map<String, Map<String, Object>> links = properties.getAdditionalLinks();
+ if (links != null && !links.isEmpty()) {
+ for (Entry<String, Map<String, Object>> entry : links.entrySet()) {
+ Map<String, Object> navigationKeyMap = entry.getValue();
+ if (navigationKeyMap != null && !navigationKeyMap.isEmpty()) {
+ final EntityInfoAggregator targetEntityInfo = EntityInfoAggregator.create(
+ eia.getEntitySet().getRelatedEntitySet(
+ (EdmNavigationProperty) eia.getEntityType().getProperty(entry.getKey())));
+ appendAtomNavigationLink(writer, createSelfLink(targetEntityInfo, navigationKeyMap, null), entry.getKey(),
+ null, eia, data);
+ }
+ }
+ }
+ }
+
private void appendCustomProperties(final XMLStreamWriter writer, final EntityInfoAggregator eia,
final Map<String, Object> data) throws EntityProviderException {
List<String> noneSyndicationTargetPaths = eia.getNoneSyndicationTargetPathNames();
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/f14dfd46/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 1f3693b..5369f95 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
@@ -23,6 +23,8 @@ import java.io.Writer;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
import org.apache.olingo.odata2.api.ODataCallback;
import org.apache.olingo.odata2.api.edm.Edm;
@@ -76,11 +78,17 @@ public class JsonEntryEntityProducer {
jsonStreamWriter.beginObject();
- writeMetadata(entityInfo, data, type);
+ if (!properties.isContentOnly()) {
+ writeMetadata(entityInfo, data, type);
+ }
writeProperties(entityInfo, data, type);
- writeNavigationProperties(writer, entityInfo, data, type);
+ if (!properties.isContentOnly()) {
+ writeNavigationProperties(writer, entityInfo, data, type);
+ } else {
+ writeAdditonalLinksInContentOnlyCase(entityInfo);
+ }
jsonStreamWriter.endObject();
@@ -173,9 +181,17 @@ public class JsonEntryEntityProducer {
private void writeProperties(final EntityInfoAggregator entityInfo, final Map<String, Object> data,
final EdmEntityType type) throws EdmException, EntityProviderException, IOException {
+ boolean omitComma = false;
+ if (properties.isContentOnly()) {
+ omitComma = true;
+ }
for (final String propertyName : type.getPropertyNames()) {
if (entityInfo.getSelectedPropertyNames().contains(propertyName)) {
- jsonStreamWriter.separator();
+ if (omitComma == true) {
+ omitComma = false;
+ } else {
+ jsonStreamWriter.separator();
+ }
jsonStreamWriter.name(propertyName);
JsonPropertyEntityProducer.appendPropertyValue(jsonStreamWriter, entityInfo.getPropertyInfo(propertyName),
data.get(propertyName));
@@ -250,16 +266,42 @@ public class JsonEntryEntityProducer {
if (key == null || key.isEmpty()) {
target = location + "/" + Encoder.encode(navigationPropertyName);
} else {
- final EntityInfoAggregator targetEntityInfo = EntityInfoAggregator.create(
- entityInfo.getEntitySet().getRelatedEntitySet(
- (EdmNavigationProperty) entityInfo.getEntityType().getProperty(navigationPropertyName)));
- target = (properties.getServiceRoot() == null ? "" : properties.getServiceRoot().toASCIIString())
- + AtomEntryEntityProducer.createSelfLink(targetEntityInfo, key, null);
+ target = createCustomTargetLink(entityInfo, navigationPropertyName, key);
}
JsonLinkEntityProducer.appendUri(jsonStreamWriter, target);
jsonStreamWriter.endObject();
}
+ private String createCustomTargetLink(final EntityInfoAggregator entityInfo, final String navigationPropertyName,
+ final Map<String, Object> key) throws EntityProviderException, EdmException {
+ String target;
+ final EntityInfoAggregator targetEntityInfo = EntityInfoAggregator.create(
+ entityInfo.getEntitySet().getRelatedEntitySet(
+ (EdmNavigationProperty) entityInfo.getEntityType().getProperty(navigationPropertyName)));
+ target = (properties.getServiceRoot() == null ? "" : properties.getServiceRoot().toASCIIString())
+ + AtomEntryEntityProducer.createSelfLink(targetEntityInfo, key, null);
+ return target;
+ }
+
+ private void writeAdditonalLinksInContentOnlyCase(final EntityInfoAggregator entityInfo)
+ throws IOException, EntityProviderException, EdmException {
+ final Map<String, Map<String, Object>> links = properties.getAdditionalLinks();
+ if (links != null && !links.isEmpty()) {
+ for (Entry<String, Map<String, Object>> entry : links.entrySet()) {
+ Map<String, Object> navigationKeyMap = entry.getValue();
+ if (navigationKeyMap != null && !navigationKeyMap.isEmpty()) {
+ String target = createCustomTargetLink(entityInfo, entry.getKey(), navigationKeyMap);
+ jsonStreamWriter.separator();
+ jsonStreamWriter.name(entry.getKey());
+ jsonStreamWriter.beginObject()
+ .name(FormatJson.DEFERRED);
+ JsonLinkEntityProducer.appendUri(jsonStreamWriter, target);
+ jsonStreamWriter.endObject();
+ }
+ }
+ }
+ }
+
public String getETag() {
return eTag;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/f14dfd46/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/ODataEntityProviderPropertiesTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/ODataEntityProviderPropertiesTest.java b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/ODataEntityProviderPropertiesTest.java
index 51f39a8..73c957a 100644
--- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/ODataEntityProviderPropertiesTest.java
+++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/ODataEntityProviderPropertiesTest.java
@@ -75,6 +75,7 @@ public class ODataEntityProviderPropertiesTest extends BaseTest {
.includeSimplePropertyType(true)
.additionalLinks(links)
.omitJsonWrapper(true)
+ .contentOnly(true)
.build();
assertEquals("Wrong amount of callbacks.", 1, properties.getCallbacks().size());
@@ -89,6 +90,7 @@ public class ODataEntityProviderPropertiesTest extends BaseTest {
assertTrue("Simple property types should be true", properties.isIncludeSimplePropertyType());
assertEquals(Collections.emptyMap(), properties.getAdditionalLinks().get("aNavigationProperty"));
assertTrue("Json Wrapper should be omitted", properties.isOmitJsonWrapper());
+ assertTrue("ContentOnlyFlag should be set", properties.isContentOnly());
}
@Test
@@ -121,6 +123,7 @@ public class ODataEntityProviderPropertiesTest extends BaseTest {
.includeSimplePropertyType(true)
.additionalLinks(links)
.omitJsonWrapper(true)
+ .contentOnly(true)
.build();
//
@@ -140,5 +143,6 @@ public class ODataEntityProviderPropertiesTest extends BaseTest {
assertTrue("Simple property types should be true", fromProperties.isIncludeSimplePropertyType());
assertEquals(Collections.emptyMap(), fromProperties.getAdditionalLinks().get("aNavigationProperty"));
assertTrue("Json Wrapper should be omitted", properties.isOmitJsonWrapper());
+ assertTrue("ContentOnlyFlag should be set", properties.isContentOnly());
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/f14dfd46/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 a87698d..db59c1e 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
@@ -53,6 +53,7 @@ import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties;
import org.apache.olingo.odata2.api.exception.ODataException;
import org.apache.olingo.odata2.api.exception.ODataMessageException;
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.AbstractProviderTest;
import org.apache.olingo.odata2.core.ep.AtomEntityProvider;
@@ -75,6 +76,250 @@ public class AtomEntryProducerTest extends AbstractProviderTest {
}
@Test
+ public void contentOnly() throws Exception {
+ final EntityProviderWriteProperties properties =
+ EntityProviderWriteProperties.serviceRoot(BASE_URI).contentOnly(true).build();
+
+ AtomEntityProvider ser = createAtomEntityProvider();
+ ODataResponse response =
+ ser.writeEntry(MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees"), employeeData,
+ properties);
+ String xmlString = verifyResponse(response);
+ assertXpathExists("/a:entry", xmlString);
+ assertXpathEvaluatesTo(BASE_URI.toASCIIString(), "/a:entry/@xml:base", xmlString);
+
+ assertXpathNotExists("/a:entry/a:id", xmlString);
+ assertXpathNotExists("/a:entry/a:title", xmlString);
+ assertXpathNotExists("/a:entry/a:updated", xmlString);
+ assertXpathNotExists("/a:entry/a:category", xmlString);
+ assertXpathNotExists("/a:entry/a:link[@title=\"ne_Team\"and @href=\"Employees('1')/ne_Team\"]", xmlString);
+ assertXpathNotExists("/a:entry/a:link[@title=\"ne_Room\"and @href=\"Employees('1')/ne_Room\"]", xmlString);
+ assertXpathNotExists("/a:entry/a:link[@title=\"ne_Manager\" and @href=\"Employees('1')/ne_Manager\"]", xmlString);
+ assertXpathNotExists("/a:entry/a:content", xmlString);
+
+ assertXpathExists("/a:entry/m:properties", xmlString);
+ }
+
+ @Test
+ public void contentOnlyRoom() throws Exception {
+ EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms");
+ List<String> selectedPropertyNames = new ArrayList<String>();
+ selectedPropertyNames.add("Name");
+ ExpandSelectTreeNode expandSelectTree =
+ ExpandSelectTreeNode.entitySet(entitySet).selectedProperties(selectedPropertyNames).build();
+ final EntityProviderWriteProperties properties =
+ EntityProviderWriteProperties.serviceRoot(BASE_URI).contentOnly(true).expandSelectTree(expandSelectTree)
+ .build();
+
+ Map<String, Object> localRoomData = new HashMap<String, Object>();
+ localRoomData.put("Name", "Neu Schwanstein");
+
+ AtomEntityProvider ser = createAtomEntityProvider();
+ ODataResponse response = ser.writeEntry(entitySet, localRoomData, properties);
+ String xmlString = verifyResponse(response);
+ assertXpathExists("/a:entry", xmlString);
+ assertXpathEvaluatesTo(BASE_URI.toASCIIString(), "/a:entry/@xml:base", xmlString);
+
+ assertXpathNotExists("/a:entry/a:id", xmlString);
+ assertXpathNotExists("/a:entry/a:title", xmlString);
+ assertXpathNotExists("/a:entry/a:updated", xmlString);
+ assertXpathNotExists("/a:entry/a:category", xmlString);
+ assertXpathNotExists("/a:entry/a:link[@title=\"nr_Employees\"and @href=\"Rooms('1')/nr_Employees\"]", xmlString);
+ assertXpathNotExists("/a:entry/a:link[@title=\"nr_Building\"and @href=\"Rooms('1')/nr_Building\"]", xmlString);
+
+ assertXpathExists("/a:entry/a:content/m:properties/d:Name", xmlString);
+ }
+
+ @Test
+ public void contentOnlyRoomSelectedOrExpandedLinksMustBeIgnored() throws Exception {
+ EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms");
+ List<String> selectedPropertyNames = new ArrayList<String>();
+ selectedPropertyNames.add("Name");
+ List<String> navigationPropertyNames = new ArrayList<String>();
+ navigationPropertyNames.add("nr_Employees");
+ navigationPropertyNames.add("nr_Building");
+ ExpandSelectTreeNode expandSelectTree =
+ ExpandSelectTreeNode.entitySet(entitySet).selectedProperties(selectedPropertyNames).expandedLinks(
+ navigationPropertyNames).build();
+ final EntityProviderWriteProperties properties =
+ EntityProviderWriteProperties.serviceRoot(BASE_URI).contentOnly(true).expandSelectTree(expandSelectTree)
+ .build();
+
+ Map<String, Object> localRoomData = new HashMap<String, Object>();
+ localRoomData.put("Name", "Neu Schwanstein");
+
+ AtomEntityProvider ser = createAtomEntityProvider();
+ ODataResponse response = ser.writeEntry(entitySet, localRoomData, properties);
+ String xmlString = verifyResponse(response);
+ assertXpathExists("/a:entry", xmlString);
+ assertXpathEvaluatesTo(BASE_URI.toASCIIString(), "/a:entry/@xml:base", xmlString);
+
+ assertXpathNotExists("/a:entry/a:id", xmlString);
+ assertXpathNotExists("/a:entry/a:title", xmlString);
+ assertXpathNotExists("/a:entry/a:updated", xmlString);
+ assertXpathNotExists("/a:entry/a:category", xmlString);
+ assertXpathNotExists("/a:entry/a:link[@title=\"nr_Employees\"and @href=\"Rooms('1')/nr_Employees\"]", xmlString);
+ assertXpathNotExists("/a:entry/a:link[@title=\"nr_Building\"and @href=\"Rooms('1')/nr_Building\"]", xmlString);
+
+ assertXpathExists("/a:entry/a:content/m:properties/d:Name", xmlString);
+ }
+
+ @Test
+ public void contentOnlyRoomWithAdditionalLink() throws Exception {
+ EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms");
+ List<String> selectedPropertyNames = new ArrayList<String>();
+ selectedPropertyNames.add("Name");
+ ExpandSelectTreeNode expandSelectTree =
+ ExpandSelectTreeNode.entitySet(entitySet).selectedProperties(selectedPropertyNames).build();
+ Map<String, Map<String, Object>> additinalLinks = new HashMap<String, Map<String, Object>>();
+ Map<String, Object> buildingLink = new HashMap<String, Object>();
+ buildingLink.put("Id", "1");
+ additinalLinks.put("nr_Building", buildingLink);
+ final EntityProviderWriteProperties properties =
+ EntityProviderWriteProperties.serviceRoot(BASE_URI).contentOnly(true).expandSelectTree(expandSelectTree)
+ .additionalLinks(additinalLinks).build();
+
+ Map<String, Object> localRoomData = new HashMap<String, Object>();
+ localRoomData.put("Name", "Neu Schwanstein");
+
+ AtomEntityProvider ser = createAtomEntityProvider();
+ ODataResponse response = ser.writeEntry(entitySet, localRoomData, properties);
+ String xmlString = verifyResponse(response);
+ assertXpathExists("/a:entry", xmlString);
+ assertXpathEvaluatesTo(BASE_URI.toASCIIString(), "/a:entry/@xml:base", xmlString);
+
+ assertXpathNotExists("/a:entry/a:id", xmlString);
+ assertXpathNotExists("/a:entry/a:title", xmlString);
+ assertXpathNotExists("/a:entry/a:updated", xmlString);
+ assertXpathNotExists("/a:entry/a:category", xmlString);
+ assertXpathNotExists("/a:entry/a:link[@title=\"nr_Employees\"and @href=\"Rooms('1')/nr_Employees\"]", xmlString);
+
+ assertXpathExists("/a:entry/a:content/m:properties/d:Name", xmlString);
+ assertXpathExists("/a:entry/a:link[@title=\"nr_Building\"and @href=\"Buildings('1')\"]", xmlString);
+ }
+
+ @Test
+ public void contentOnlyWithoutKey() throws Exception {
+ EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees");
+ List<String> selectedPropertyNames = new ArrayList<String>();
+ selectedPropertyNames.add("ManagerId");
+ ExpandSelectTreeNode select =
+ ExpandSelectTreeNode.entitySet(entitySet).selectedProperties(selectedPropertyNames).build();
+
+ final EntityProviderWriteProperties properties =
+ EntityProviderWriteProperties.serviceRoot(BASE_URI).contentOnly(true).expandSelectTree(select).build();
+
+ Map<String, Object> localEmployeeData = new HashMap<String, Object>();
+ localEmployeeData.put("ManagerId", "1");
+
+ AtomEntityProvider ser = createAtomEntityProvider();
+ ODataResponse response =
+ ser.writeEntry(entitySet, localEmployeeData,
+ properties);
+ String xmlString = verifyResponse(response);
+ assertXpathExists("/a:entry", xmlString);
+ assertXpathEvaluatesTo(BASE_URI.toASCIIString(), "/a:entry/@xml:base", xmlString);
+
+ assertXpathNotExists("/a:entry/a:id", xmlString);
+ assertXpathNotExists("/a:entry/a:title", xmlString);
+ assertXpathNotExists("/a:entry/a:updated", xmlString);
+ assertXpathNotExists("/a:entry/a:category", xmlString);
+ assertXpathNotExists("/a:entry/a:link[@title=\"ne_Manager\"]", xmlString);
+ assertXpathNotExists("/a:entry/a:link[@title=\"ne_Team\"]", xmlString);
+ assertXpathNotExists("/a:entry/a:link[@title=\"ne_Room\"]", xmlString);
+ assertXpathNotExists("/a:entry/a:content", xmlString);
+
+ assertXpathExists("/a:entry/m:properties", xmlString);
+ assertXpathNotExists("/a:entry/m:properties/d:EmployeeId", xmlString);
+ assertXpathExists("/a:entry/m:properties/d:ManagerId", xmlString);
+ }
+
+ @Test
+ public void contentOnlySelectedOrExpandedLinksMustBeIgnored() throws Exception {
+ EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees");
+ List<String> selectedPropertyNames = new ArrayList<String>();
+ selectedPropertyNames.add("ManagerId");
+
+ List<String> expandedNavigationNames = new ArrayList<String>();
+ expandedNavigationNames.add("ne_Manager");
+ expandedNavigationNames.add("ne_Team");
+ expandedNavigationNames.add("ne_Room");
+
+ ExpandSelectTreeNode select =
+ ExpandSelectTreeNode.entitySet(entitySet).selectedProperties(selectedPropertyNames).expandedLinks(
+ expandedNavigationNames).build();
+
+ final EntityProviderWriteProperties properties =
+ EntityProviderWriteProperties.serviceRoot(BASE_URI).contentOnly(true).expandSelectTree(select).build();
+
+ Map<String, Object> localEmployeeData = new HashMap<String, Object>();
+ localEmployeeData.put("ManagerId", "1");
+
+ AtomEntityProvider ser = createAtomEntityProvider();
+ ODataResponse response =
+ ser.writeEntry(entitySet, localEmployeeData,
+ properties);
+ String xmlString = verifyResponse(response);
+ assertXpathExists("/a:entry", xmlString);
+ assertXpathEvaluatesTo(BASE_URI.toASCIIString(), "/a:entry/@xml:base", xmlString);
+
+ assertXpathNotExists("/a:entry/a:id", xmlString);
+ assertXpathNotExists("/a:entry/a:title", xmlString);
+ assertXpathNotExists("/a:entry/a:updated", xmlString);
+ assertXpathNotExists("/a:entry/a:category", xmlString);
+ assertXpathNotExists("/a:entry/a:link[@title=\"ne_Manager\"]", xmlString);
+ assertXpathNotExists("/a:entry/a:link[@title=\"ne_Team\"]", xmlString);
+ assertXpathNotExists("/a:entry/a:link[@title=\"ne_Room\"]", xmlString);
+ assertXpathNotExists("/a:entry/a:content", xmlString);
+
+ assertXpathExists("/a:entry/m:properties", xmlString);
+ assertXpathNotExists("/a:entry/m:properties/d:EmployeeId", xmlString);
+ assertXpathExists("/a:entry/m:properties/d:ManagerId", xmlString);
+ }
+
+ @Test
+ public void contentOnlyWithAdditinalLink() throws Exception {
+ EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees");
+ List<String> selectedPropertyNames = new ArrayList<String>();
+ selectedPropertyNames.add("ManagerId");
+ ExpandSelectTreeNode select =
+ ExpandSelectTreeNode.entitySet(entitySet).selectedProperties(selectedPropertyNames).build();
+
+ Map<String, Map<String, Object>> additinalLinks = new HashMap<String, Map<String, Object>>();
+ Map<String, Object> managerLink = new HashMap<String, Object>();
+ managerLink.put("EmployeeId", "1");
+ additinalLinks.put("ne_Manager", managerLink);
+ final EntityProviderWriteProperties properties =
+ EntityProviderWriteProperties.serviceRoot(BASE_URI).contentOnly(true).expandSelectTree(select).additionalLinks(
+ additinalLinks).build();
+
+ Map<String, Object> localEmployeeData = new HashMap<String, Object>();
+ localEmployeeData.put("ManagerId", "1");
+
+ AtomEntityProvider ser = createAtomEntityProvider();
+ ODataResponse response =
+ ser.writeEntry(entitySet, localEmployeeData,
+ properties);
+ String xmlString = verifyResponse(response);
+ assertXpathExists("/a:entry", xmlString);
+ assertXpathEvaluatesTo(BASE_URI.toASCIIString(), "/a:entry/@xml:base", xmlString);
+
+ assertXpathNotExists("/a:entry/a:id", xmlString);
+ assertXpathNotExists("/a:entry/a:title", xmlString);
+ assertXpathNotExists("/a:entry/a:updated", xmlString);
+ assertXpathNotExists("/a:entry/a:category", xmlString);
+ assertXpathNotExists("/a:entry/a:link[@title=\"ne_Team\"]", xmlString);
+ assertXpathNotExists("/a:entry/a:link[@title=\"ne_Room\"]", xmlString);
+ assertXpathNotExists("/a:entry/a:content", xmlString);
+
+ assertXpathExists("/a:entry/m:properties", xmlString);
+ assertXpathNotExists("/a:entry/m:properties/d:EmployeeId", xmlString);
+ assertXpathExists("/a:entry/m:properties/d:ManagerId", xmlString);
+
+ assertXpathExists("/a:entry/a:link[@href=\"Managers('1')\" and @title=\"ne_Manager\"]", xmlString);
+ }
+
+ @Test
public void noneSyndicationKeepInContentFalseMustNotShowInProperties() throws Exception {
// prepare Mock
EdmEntitySet employeesSet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees");
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/f14dfd46/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 942edf5..7040e2a 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
@@ -87,6 +87,145 @@ public class JsonEntryEntityProducerTest extends BaseTest {
json);
}
+ @SuppressWarnings("unchecked")
+ @Test
+ public void contentOnly() throws Exception {
+ HashMap<String, Object> employeeData = new HashMap<String, Object>();
+ Calendar date = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
+ date.clear();
+ date.set(1999, 0, 1);
+ employeeData.put("EmployeeId", "1");
+ employeeData.put("ImmageUrl", null);
+ employeeData.put("ManagerId", "1");
+ employeeData.put("Age", new Integer(52));
+ employeeData.put("RoomId", "1");
+ employeeData.put("EntryDate", date);
+ employeeData.put("TeamId", "42");
+ employeeData.put("EmployeeName", "Walter Winter");
+ Map<String, Object> locationData = new HashMap<String, Object>();
+ Map<String, Object> cityData = new HashMap<String, Object>();
+ cityData.put("PostalCode", "33470");
+ cityData.put("CityName", "Duckburg");
+ locationData.put("City", cityData);
+ locationData.put("Country", "Calisota");
+ employeeData.put("Location", locationData);
+
+ final EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees");
+ EntityProviderWriteProperties properties =
+ EntityProviderWriteProperties.fromProperties(DEFAULT_PROPERTIES).omitJsonWrapper(true).contentOnly(true)
+ .build();
+ final ODataResponse response = new JsonEntityProvider().writeEntry(entitySet, employeeData, properties);
+ Map<String, Object> employee =
+ (Map<String, Object>) new Gson().fromJson(new InputStreamReader((InputStream) response.getEntity()), Map.class);
+ assertNull(employee.get("__metadata"));
+ assertNull(employee.get("ne_Manager"));
+ assertNull(employee.get("ne_Team"));
+ assertNull(employee.get("ne_Room"));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void contentOnlyWithoutKey() throws Exception {
+ HashMap<String, Object> employeeData = new HashMap<String, Object>();
+ employeeData.put("ManagerId", "1");
+ employeeData.put("Age", new Integer(52));
+ employeeData.put("RoomId", "1");
+ employeeData.put("TeamId", "42");
+
+ List<String> selectedProperties = new ArrayList<String>();
+ selectedProperties.add("ManagerId");
+ selectedProperties.add("Age");
+ selectedProperties.add("RoomId");
+ selectedProperties.add("TeamId");
+ final EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees");
+
+ ExpandSelectTreeNode expandSelectTreeNode =
+ ExpandSelectTreeNode.entitySet(entitySet).selectedProperties(selectedProperties).build();
+ EntityProviderWriteProperties properties =
+ EntityProviderWriteProperties.fromProperties(DEFAULT_PROPERTIES).omitJsonWrapper(true).contentOnly(true)
+ .expandSelectTree(expandSelectTreeNode).build();
+ final ODataResponse response = new JsonEntityProvider().writeEntry(entitySet, employeeData, properties);
+ Map<String, Object> employee =
+ (Map<String, Object>) new Gson().fromJson(new InputStreamReader((InputStream) response.getEntity()), Map.class);
+ assertNull(employee.get("__metadata"));
+ assertNull(employee.get("ne_Manager"));
+ assertNull(employee.get("ne_Team"));
+ assertNull(employee.get("ne_Room"));
+
+ assertEquals("1", employee.get("ManagerId"));
+ assertEquals("1", employee.get("RoomId"));
+ assertEquals("42", employee.get("TeamId"));
+ assertEquals(new Double(52), employee.get("Age"));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void contentOnlySelectedOrExpandedLinksMustBeIgnored() throws Exception {
+ final EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees");
+
+ HashMap<String, Object> employeeData = new HashMap<String, Object>();
+ employeeData.put("ManagerId", "1");
+
+ List<String> selectedProperties = new ArrayList<String>();
+ selectedProperties.add("ManagerId");
+
+ List<String> expandedLinks = new ArrayList<String>();
+ expandedLinks.add("ne_Manager");
+ expandedLinks.add("ne_Team");
+ expandedLinks.add("ne_Room");
+
+ ExpandSelectTreeNode expandSelectTreeNode =
+ ExpandSelectTreeNode.entitySet(entitySet).selectedProperties(selectedProperties).expandedLinks(expandedLinks)
+ .build();
+ EntityProviderWriteProperties properties =
+ EntityProviderWriteProperties.fromProperties(DEFAULT_PROPERTIES).omitJsonWrapper(true).contentOnly(true)
+ .expandSelectTree(expandSelectTreeNode).build();
+ final ODataResponse response = new JsonEntityProvider().writeEntry(entitySet, employeeData, properties);
+ Map<String, Object> employee =
+ (Map<String, Object>) new Gson().fromJson(new InputStreamReader((InputStream) response.getEntity()), Map.class);
+ assertNull(employee.get("__metadata"));
+ assertNull(employee.get("ne_Manager"));
+ assertNull(employee.get("ne_Team"));
+ assertNull(employee.get("ne_Room"));
+
+ assertEquals("1", employee.get("ManagerId"));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void contentOnlyWithAdditinalLink() throws Exception {
+ final EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees");
+ HashMap<String, Object> employeeData = new HashMap<String, Object>();
+ employeeData.put("ManagerId", "1");
+
+ List<String> selectedProperties = new ArrayList<String>();
+ selectedProperties.add("ManagerId");
+
+ ExpandSelectTreeNode expandSelectTreeNode =
+ ExpandSelectTreeNode.entitySet(entitySet).selectedProperties(selectedProperties).build();
+
+ Map<String, Map<String, Object>> additinalLinks = new HashMap<String, Map<String, Object>>();
+ Map<String, Object> managerLink = new HashMap<String, Object>();
+ managerLink.put("EmployeeId", "1");
+ additinalLinks.put("ne_Manager", managerLink);
+
+ EntityProviderWriteProperties properties =
+ EntityProviderWriteProperties.fromProperties(DEFAULT_PROPERTIES).omitJsonWrapper(true).contentOnly(true)
+ .expandSelectTree(expandSelectTreeNode).additionalLinks(additinalLinks).build();
+ final ODataResponse response = new JsonEntityProvider().writeEntry(entitySet, employeeData, properties);
+ //System.out.println(StringHelper.inputStreamToString((InputStream) response.getEntity()));
+ Map<String, Object> employee =
+ (Map<String, Object>) new Gson().fromJson(new InputStreamReader((InputStream) response.getEntity()), Map.class);
+ assertNull(employee.get("__metadata"));
+ assertNull(employee.get("ne_Team"));
+ assertNull(employee.get("ne_Room"));
+
+ assertEquals("1", employee.get("ManagerId"));
+ Map<String, Object> map = (Map<String, Object>) employee.get("ne_Manager");
+ map = (Map<String, Object>) map.get("__deferred");
+ assertEquals("http://host:80/service/Managers('1')", map.get("uri"));
+ }
+
@Test
public void omitJsonWrapper() throws Exception {
final EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Teams");