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/01/16 17:44:44 UTC

git commit: [OLINGO-121] Introduce includeSimplePropertyType

Updated Branches:
  refs/heads/master 6bfbe8fb8 -> 0bbc1edee


[OLINGO-121] Introduce includeSimplePropertyType

Introduced the flag includeSimplePropertyType at the
EntityProviderWriteProperties. With this simple property type information
will be shown inside entries of a feed or a single entry if set.
Information is based on the EDM.


Project: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/commit/0bbc1ede
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/0bbc1ede
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/0bbc1ede

Branch: refs/heads/master
Commit: 0bbc1edee23d43337f36d657604de0742ca3ba0e
Parents: 6bfbe8f
Author: Christian Amend <ch...@apache.org>
Authored: Thu Jan 16 17:17:29 2014 +0100
Committer: Christian Amend <ch...@apache.org>
Committed: Thu Jan 16 17:17:29 2014 +0100

----------------------------------------------------------------------
 .../api/ep/EntityProviderWriteProperties.java    | 19 +++++++++++++++++++
 .../odata2/core/ep/AtomEntityProvider.java       |  2 +-
 .../core/ep/consumer/XmlMetadataConsumer.java    |  4 ++--
 .../ep/producer/AtomEntryEntityProducer.java     |  4 ++--
 .../ep/producer/XmlCollectionEntityProducer.java |  2 +-
 .../ep/producer/XmlPropertyEntityProducer.java   | 11 +++++++++++
 .../ep/ODataEntityProviderPropertiesTest.java    |  4 ++++
 .../core/ep/ProducerConsumerIntegrationTest.java |  3 ++-
 .../core/ep/producer/AtomEntryProducerTest.java  | 16 ++++++++++++++++
 .../core/ep/producer/AtomFeedProducerTest.java   | 16 ++++++++++++++++
 10 files changed, 74 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/0bbc1ede/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 9186550..98cabb8 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
@@ -42,10 +42,19 @@ public class EntityProviderWriteProperties {
   private ExpandSelectTreeNode expandSelectTree;
   private Map<String, ODataCallback> callbacks = Collections.emptyMap();
   private URI selfLink;
+  private boolean includeSimplePropertyType;
 
   private EntityProviderWriteProperties() {}
 
   /**
+   * Returns if type information of simple properties should be in the payload.
+   * @return true if information should be in the payload.
+   */
+  public final boolean isIncludeSimplePropertyType() {
+    return includeSimplePropertyType;
+  }
+
+  /**
    * Gets the self link from an application. May be null.
    * @return the self link
    */
@@ -117,6 +126,15 @@ public class EntityProviderWriteProperties {
     private final EntityProviderWriteProperties properties = new EntityProviderWriteProperties();
 
     /**
+     * @param includeSimplePropertyType true to include simple property type information in the payload
+     */
+    public final ODataEntityProviderPropertiesBuilder includeSimplePropertyType(
+        final boolean includeSimplePropertyType) {
+      properties.includeSimplePropertyType = includeSimplePropertyType;
+      return this;
+    }
+
+    /**
      * @param mediaResourceMimeType the mediaResourceMimeType to set
      * @deprecated use instead the functionality of 'EdmMapping -> mediaResourceMimeTypeKey' to reference via a key
      * to the 'mime type' of the media resource provided in the entity data map
@@ -197,6 +215,7 @@ public class EntityProviderWriteProperties {
       this.properties.expandSelectTree = properties.getExpandSelectTree();
       this.properties.callbacks = properties.getCallbacks();
       this.properties.selfLink = properties.getSelfLink();
+      this.properties.includeSimplePropertyType = properties.includeSimplePropertyType;
       return this;
     }
   }

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/0bbc1ede/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/AtomEntityProvider.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/AtomEntityProvider.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/AtomEntityProvider.java
index 9fc9945..9f67d2f 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/AtomEntityProvider.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/AtomEntityProvider.java
@@ -202,7 +202,7 @@ public class AtomEntityProvider implements ContentTypeBasedEntityProvider {
       XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(outStream, DEFAULT_CHARSET);
       writer.writeStartDocument(DEFAULT_CHARSET, XML_VERSION);
 
-      XmlPropertyEntityProducer ps = new XmlPropertyEntityProducer();
+      XmlPropertyEntityProducer ps = new XmlPropertyEntityProducer(false);
       ps.append(writer, propertyInfo, value);
 
       writer.flush();

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/0bbc1ede/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlMetadataConsumer.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlMetadataConsumer.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlMetadataConsumer.java
index f51bf33..e8677a1 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlMetadataConsumer.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlMetadataConsumer.java
@@ -1061,8 +1061,8 @@ public class XmlMetadataConsumer {
 
   private void validateAssociationEnd(final AssociationSetEnd end, final Association association)
       throws EntityProviderException {
-    if (!(association.getEnd1().getRole().equals(end.getRole()) ^ 
-        association.getEnd2().getRole().equals(end.getRole()))) {
+    if (!(association.getEnd1().getRole().equals(end.getRole()) ^ association
+        .getEnd2().getRole().equals(end.getRole()))) {
       throw new EntityProviderException(EntityProviderException.COMMON.addContent("Invalid Association"));
     }
   }

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/0bbc1ede/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 1b24a9a..307c828 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
@@ -140,7 +140,7 @@ public class AtomEntryEntityProducer {
     for (String tpName : noneSyndicationTargetPaths) {
       EntityPropertyInfo info = eia.getTargetPathInfo(tpName);
       final String name = info.getName();
-      XmlPropertyEntityProducer aps = new XmlPropertyEntityProducer();
+      XmlPropertyEntityProducer aps = new XmlPropertyEntityProducer(properties.isIncludeSimplePropertyType());
       aps.appendCustomProperty(writer, name, info, data.get(name));
     }
   }
@@ -564,7 +564,7 @@ public class AtomEntryEntityProducer {
 
           if (isNotMappedViaCustomMapping(propertyInfo)) {
             Object value = data.get(propertyName);
-            XmlPropertyEntityProducer aps = new XmlPropertyEntityProducer();
+            XmlPropertyEntityProducer aps = new XmlPropertyEntityProducer(properties.isIncludeSimplePropertyType());
             aps.append(writer, propertyInfo.getName(), propertyInfo, value);
           }
         }

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/0bbc1ede/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/XmlCollectionEntityProducer.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/XmlCollectionEntityProducer.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/XmlCollectionEntityProducer.java
index ea36828..ef6fcb7 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/XmlCollectionEntityProducer.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/XmlCollectionEntityProducer.java
@@ -42,7 +42,7 @@ public class XmlCollectionEntityProducer {
       if (propertyInfo.isComplex()) {
         writer.writeNamespace(Edm.PREFIX_M, Edm.NAMESPACE_M_2007_08);
       }
-      XmlPropertyEntityProducer provider = new XmlPropertyEntityProducer();
+      XmlPropertyEntityProducer provider = new XmlPropertyEntityProducer(false);
       for (final Object propertyData : data) {
         provider.append(writer, FormatXml.D_ELEMENT, propertyInfo, propertyData);
       }

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/0bbc1ede/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/XmlPropertyEntityProducer.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/XmlPropertyEntityProducer.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/XmlPropertyEntityProducer.java
index 90931d6..b36205a 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/XmlPropertyEntityProducer.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/XmlPropertyEntityProducer.java
@@ -40,6 +40,12 @@ import org.apache.olingo.odata2.core.ep.util.FormatXml;
  */
 public class XmlPropertyEntityProducer {
 
+  private final boolean inculdeSimplePropertyType;
+
+  public XmlPropertyEntityProducer(final boolean inculdeSimplePropertyType) {
+    this.inculdeSimplePropertyType = inculdeSimplePropertyType;
+  }
+
   /**
    * Append {@link Object} <code>value</code> based on {@link EntityPropertyInfo} to {@link XMLStreamWriter} in an
    * already existing XML structure inside the d namespace.
@@ -187,6 +193,11 @@ public class XmlPropertyEntityProducer {
     }
 
     final EdmSimpleType type = (EdmSimpleType) prop.getType();
+    if (inculdeSimplePropertyType) {
+      String fqnTypeName = type.getNamespace() + Edm.DELIMITER + type.getName();
+      writer.writeAttribute(Edm.NAMESPACE_M_2007_08, FormatXml.ATOM_TYPE, fqnTypeName);
+    }
+
     final String valueAsString = type.valueToString(contentValue, EdmLiteralKind.DEFAULT, prop.getFacets());
     if (valueAsString == null) {
       writer.writeAttribute(Edm.NAMESPACE_M_2007_08, FormatXml.ATOM_NULL, FormatXml.ATOM_VALUE_TRUE);

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/0bbc1ede/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 0605628..e0e85f6 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
@@ -69,6 +69,7 @@ public class ODataEntityProviderPropertiesTest extends BaseTest {
         .mediaResourceMimeType("image/png")
         .nextLink("http://localhost")
         .selfLink(selfLink)
+        .includeSimplePropertyType(true)
         .build();
 
     assertEquals("Wrong amount of callbacks.", 1, properties.getCallbacks().size());
@@ -80,6 +81,7 @@ public class ODataEntityProviderPropertiesTest extends BaseTest {
     assertEquals("Wrong inline count type.", InlineCount.ALLPAGES, properties.getInlineCountType());
     assertEquals("Wrong inline count.", Integer.valueOf(1), properties.getInlineCount());
     assertEquals("Wrong nextLink", "http://localhost", properties.getNextLink());
+    assertTrue("Simple property types should be true", properties.isIncludeSimplePropertyType());
   }
 
   @Test
@@ -107,6 +109,7 @@ public class ODataEntityProviderPropertiesTest extends BaseTest {
         .mediaResourceMimeType("image/png")
         .nextLink("http://localhost")
         .selfLink(selfLink)
+        .includeSimplePropertyType(true)
         .build();
 
     //
@@ -123,5 +126,6 @@ public class ODataEntityProviderPropertiesTest extends BaseTest {
     assertEquals("Wrong inline count type.", InlineCount.ALLPAGES, fromProperties.getInlineCountType());
     assertEquals("Wrong inline count.", Integer.valueOf(1), fromProperties.getInlineCount());
     assertEquals("Wrong nextLink", "http://localhost", fromProperties.getNextLink());
+    assertTrue("Simple property types should be true", fromProperties.isIncludeSimplePropertyType());
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/0bbc1ede/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/ProducerConsumerIntegrationTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/ProducerConsumerIntegrationTest.java b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/ProducerConsumerIntegrationTest.java
index e7aec79..04d3f92 100644
--- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/ProducerConsumerIntegrationTest.java
+++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/ProducerConsumerIntegrationTest.java
@@ -70,7 +70,8 @@ public class ProducerConsumerIntegrationTest {
     assertEquals("Neu \n Schwanstein蝴蝶", properties2.get("Name"));
   }
 
-  private Map<String, Object> execute(Map<String, Object> localRoomData, EdmEntitySet roomSet, String contentType)
+  private Map<String, Object> execute(final Map<String, Object> localRoomData, final EdmEntitySet roomSet,
+      final String contentType)
       throws EntityProviderException {
     ODataResponse response = EntityProvider.writeEntry(contentType, roomSet, localRoomData, DEFAULT_WRITE_PROPERTIES);
     InputStream content = (InputStream) response.getEntity();

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/0bbc1ede/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 b50a072..dd36e11 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
@@ -491,6 +491,22 @@ public class AtomEntryProducerTest extends AbstractProviderTest {
   }
 
   @Test
+  public void serializeAtomEntryWithSimplePropertyTypeInformation() throws Exception {
+    final EntityProviderWriteProperties properties =
+        EntityProviderWriteProperties.serviceRoot(BASE_URI).includeSimplePropertyType(true).build();
+    AtomEntityProvider ser = createAtomEntityProvider();
+    ODataResponse response =
+        ser.writeEntry(MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms"), roomData, properties);
+    String xmlString = verifyResponse(response);
+
+    assertXpathExists("/a:entry/a:content/m:properties", xmlString);
+    assertXpathExists("/a:entry/a:content/m:properties/d:Id[@m:type=\"Edm.String\"]", xmlString);
+    assertXpathExists("/a:entry/a:content/m:properties/d:Name[@m:type=\"Edm.String\"]", xmlString);
+    assertXpathExists("/a:entry/a:content/m:properties/d:Seats[@m:type=\"Edm.Int16\"]", xmlString);
+    assertXpathExists("/a:entry/a:content/m:properties/d:Version[@m:type=\"Edm.Int16\"]", xmlString);
+  }
+
+  @Test
   public void serializeEntryId() throws IOException, XpathException, SAXException, XMLStreamException,
       FactoryConfigurationError, ODataException {
     AtomEntityProvider ser = createAtomEntityProvider();

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/0bbc1ede/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomFeedProducerTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomFeedProducerTest.java b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomFeedProducerTest.java
index 61efdf2..6608558 100644
--- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomFeedProducerTest.java
+++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomFeedProducerTest.java
@@ -65,6 +65,22 @@ public class AtomFeedProducerTest extends AbstractProviderTest {
   }
 
   @Test
+  public void testWithIncludeSimplePropertyTypes() throws Exception {
+    AtomEntityProvider ser = createAtomEntityProvider();
+    EntityProviderWriteProperties properties =
+        EntityProviderWriteProperties.serviceRoot(BASE_URI).includeSimplePropertyType(true).build();
+    ODataResponse response = ser.writeFeed(view.getTargetEntitySet(), roomsData, properties);
+    String xmlString = verifyResponse(response);
+
+    assertXpathExists("/a:feed", xmlString);
+    assertXpathExists("/a:feed/a:entry/a:content/m:properties", xmlString);
+    assertXpathExists("/a:feed/a:entry/a:content/m:properties/d:Id[@m:type=\"Edm.String\"]", xmlString);
+    assertXpathExists("/a:feed/a:entry/a:content/m:properties/d:Name[@m:type=\"Edm.String\"]", xmlString);
+    assertXpathExists("/a:feed/a:entry/a:content/m:properties/d:Seats[@m:type=\"Edm.Int16\"]", xmlString);
+    assertXpathExists("/a:feed/a:entry/a:content/m:properties/d:Version[@m:type=\"Edm.Int16\"]", xmlString);
+  }
+
+  @Test
   public void testFeedNamespaces() throws Exception {
     AtomEntityProvider ser = createAtomEntityProvider();
     EntityProviderWriteProperties properties =