You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by sk...@apache.org on 2014/01/14 09:04:31 UTC

[1/2] git commit: [OLINGO-83] Added more javadoc

Updated Branches:
  refs/heads/olingo-117 [created] f23e8c7a8


[OLINGO-83] Added more javadoc


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/f294302f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/f294302f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/f294302f

Branch: refs/heads/olingo-117
Commit: f294302fa84c9d88993f8af28c92f6b5967560c3
Parents: e4ebe86
Author: Michael Bolz <mi...@apache.org>
Authored: Wed Jan 8 14:33:03 2014 +0100
Committer: Stephan Klevenz <sk...@apache.org>
Committed: Mon Jan 13 15:10:21 2014 +0100

----------------------------------------------------------------------
 .../annotation/processor/api/package-info.java  | 25 ++++++++++++++++++
 .../odata2/api/annotation/edm/package-info.java | 27 ++++++++++++++++++++
 .../api/annotation/edmx/package-info.java       | 23 +++++++++++++++++
 3 files changed, 75 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/f294302f/odata2-annotation-processor/annotation-processor-api/src/main/java/org/apache/olingo/odata2/annotation/processor/api/package-info.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-api/src/main/java/org/apache/olingo/odata2/annotation/processor/api/package-info.java b/odata2-annotation-processor/annotation-processor-api/src/main/java/org/apache/olingo/odata2/annotation/processor/api/package-info.java
new file mode 100644
index 0000000..fd4dbcb
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-api/src/main/java/org/apache/olingo/odata2/annotation/processor/api/package-info.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.
+ ******************************************************************************/
+/**
+ * <h1>Annotations-API for Entity Data Model definition</h1>
+ * <p>The core API package contains contains the AnnotationServiceFactory as entry point
+ * to an implementation (core) of the Annotations-API for Entity Data Model definition.</p>
+ */
+package org.apache.olingo.odata2.annotation.processor.api;
+

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/f294302f/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/package-info.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/package-info.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/package-info.java
new file mode 100644
index 0000000..4a11181
--- /dev/null
+++ b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/package-info.java
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * 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.
+ ******************************************************************************/
+/**
+ * <h1>Annotations-API for Entity Data Model definition</h1>
+ * <p>The edm package contains all annotations necessary for definition
+ * of the Entity Data Model (as described in the OData protocol specification
+ * as well as in the Conceptual Schema Definition for the OData Protocol which
+ * both can be found at <a href="http://www.odata.org/">http://www.odata.org/</a>).</p>
+ */
+package org.apache.olingo.odata2.api.annotation.edm;
+

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/f294302f/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edmx/package-info.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edmx/package-info.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edmx/package-info.java
new file mode 100644
index 0000000..e836ab7
--- /dev/null
+++ b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edmx/package-info.java
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * 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.
+ ******************************************************************************/
+/**
+ * The edmx package contains annotations necessary for EDMX definition.
+ */
+package org.apache.olingo.odata2.api.annotation.edmx;
+


[2/2] git commit: [OLINGO-117] delta link support

Posted by sk...@apache.org.
[OLINGO-117] delta link support


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/f23e8c7a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/f23e8c7a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/f23e8c7a

Branch: refs/heads/olingo-117
Commit: f23e8c7a81c12bb329ff84304d75f2cf01ff4bf8
Parents: f294302
Author: Stephan Klevenz <sk...@apache.org>
Authored: Mon Jan 13 17:54:48 2014 +0100
Committer: Stephan Klevenz <sk...@apache.org>
Committed: Mon Jan 13 17:54:48 2014 +0100

----------------------------------------------------------------------
 .../ep/producer/JsonFeedEntityProducer.java     | 47 ++++++++--
 .../JsonFeedWithDeltaLinkProducerTest.java      | 99 ++++++++++++++++++++
 2 files changed, 138 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/f23e8c7a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/JsonFeedEntityProducer.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/JsonFeedEntityProducer.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/JsonFeedEntityProducer.java
index 9be2fb0..eb84b5b 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/JsonFeedEntityProducer.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/JsonFeedEntityProducer.java
@@ -26,6 +26,8 @@ import java.util.Map;
 import org.apache.olingo.odata2.api.commons.InlineCount;
 import org.apache.olingo.odata2.api.ep.EntityProviderException;
 import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties;
+import org.apache.olingo.odata2.api.ep.callback.TombstoneCallback;
+import org.apache.olingo.odata2.api.ep.callback.TombstoneCallbackResult;
 import org.apache.olingo.odata2.core.ep.aggregator.EntityInfoAggregator;
 import org.apache.olingo.odata2.core.ep.util.FormatJson;
 import org.apache.olingo.odata2.core.ep.util.JsonStreamWriter;
@@ -46,6 +48,8 @@ public class JsonFeedEntityProducer {
       final boolean isRootElement) throws EntityProviderException {
     JsonStreamWriter jsonStreamWriter = new JsonStreamWriter(writer);
 
+    TombstoneCallback callback = getTombstoneCallback();
+
     try {
       jsonStreamWriter.beginObject();
 
@@ -73,14 +77,8 @@ public class JsonFeedEntityProducer {
       }
       jsonStreamWriter.endArray();
 
-      // Write "next" link.
-      // To be compatible with other implementations out there, the link is
-      // written directly after "__next" and not as "{"uri":"next link"}",
-      // deviating from the OData 2.0 specification.
-      if (properties.getNextLink() != null) {
-        jsonStreamWriter.separator()
-            .namedStringValue(FormatJson.NEXT, properties.getNextLink());
-      }
+      appendNextLink(jsonStreamWriter);
+      appendDeltaLink(callback, jsonStreamWriter);
 
       if (isRootElement) {
         jsonStreamWriter.endObject();
@@ -92,4 +90,37 @@ public class JsonFeedEntityProducer {
           .getSimpleName()), e);
     }
   }
+
+  private TombstoneCallback getTombstoneCallback() {
+    if (properties.getCallbacks() != null
+        && properties.getCallbacks().containsKey(TombstoneCallback.CALLBACK_KEY_TOMBSTONE)) {
+      TombstoneCallback callback =
+          (TombstoneCallback) properties.getCallbacks().get(TombstoneCallback.CALLBACK_KEY_TOMBSTONE);
+      return callback;
+    } else {
+      return null;
+    }
+  }
+
+  private void appendNextLink(JsonStreamWriter jsonStreamWriter) throws IOException {
+    // Write "next" link.
+    // To be compatible with other implementations out there, the link is
+    // written directly after "__next" and not as "{"uri":"next link"}",
+    // deviating from the OData 2.0 specification.
+    if (properties.getNextLink() != null) {
+      jsonStreamWriter.separator()
+          .namedStringValue(FormatJson.NEXT, properties.getNextLink());
+    }
+  }
+
+  private void appendDeltaLink(TombstoneCallback callback, JsonStreamWriter jsonStreamWriter) throws IOException {
+    if (callback != null) {
+      TombstoneCallbackResult callbackResult = callback.getTombstoneCallbackResult();
+
+      String deltaLink = callbackResult.getDeltaLink();
+      if (deltaLink != null) {
+        jsonStreamWriter.separator().namedStringValue(FormatJson.DELTA, deltaLink);
+      }
+    }
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/f23e8c7a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonFeedWithDeltaLinkProducerTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonFeedWithDeltaLinkProducerTest.java b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonFeedWithDeltaLinkProducerTest.java
new file mode 100644
index 0000000..7927b02
--- /dev/null
+++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonFeedWithDeltaLinkProducerTest.java
@@ -0,0 +1,99 @@
+package org.apache.olingo.odata2.core.ep.producer;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.*;
+
+import java.io.InputStream;
+import java.lang.reflect.Type;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.olingo.odata2.api.ODataCallback;
+import org.apache.olingo.odata2.api.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties;
+import org.apache.olingo.odata2.api.ep.callback.TombstoneCallback;
+import org.apache.olingo.odata2.api.processor.ODataResponse;
+import org.apache.olingo.odata2.core.ep.JsonEntityProvider;
+import org.apache.olingo.odata2.testutil.fit.BaseTest;
+import org.apache.olingo.odata2.testutil.helper.StringHelper;
+import org.apache.olingo.odata2.testutil.mock.MockFacade;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.gson.Gson;
+import com.google.gson.internal.StringMap;
+import com.google.gson.reflect.TypeToken;
+
+public class JsonFeedWithDeltaLinkProducerTest extends BaseTest {
+
+  protected static final String BASE_URI = "http://host:80/service/";
+  protected static final EntityProviderWriteProperties DEFAULT_PROPERTIES =
+      EntityProviderWriteProperties.serviceRoot(URI.create(BASE_URI)).build();
+
+  private ArrayList<Map<String, Object>> deletedRoomData;
+  protected ArrayList<Map<String, Object>> roomsData;
+
+  private void initializeRoomData() {
+    Map<String, Object> roomData1 = new HashMap<String, Object>();
+    roomData1.put("Id", "1");
+    roomData1.put("Seats", 123);
+    roomData1.put("Version", 1);
+    Map<String, Object> roomData2 = new HashMap<String, Object>();
+    roomData2.put("Id", "2");
+    roomData2.put("Seats", 66);
+    roomData2.put("Version", 2);
+
+    roomsData = new ArrayList<Map<String, Object>>();
+    roomsData.add(roomData1);
+    roomsData.add(roomData2);
+  }
+
+  private void initializeDeletedRoomData() {
+    deletedRoomData = new ArrayList<Map<String, Object>>();
+    for (int i = 2; i <= roomsData.size(); i = i + 2) {
+      HashMap<String, Object> tmp = new HashMap<String, Object>();
+      tmp.put("Id", "" + i);
+      tmp.put("Name", "Neu Schwanstein" + i);
+      tmp.put("Seats", new Integer(20));
+      tmp.put("Version", new Integer(3));
+      deletedRoomData.add(tmp);
+    }
+  }
+
+  @Before
+  public void before() {
+    initializeRoomData();
+    initializeDeletedRoomData();
+  }
+
+  @Test
+  public void deltaLink() throws Exception {
+    final EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms");
+
+    TombstoneCallback tombstoneCallback =
+        new TombstoneCallbackImpl(deletedRoomData, BASE_URI + "Rooms?!deltatoken=1234");
+
+    Map<String, ODataCallback> callbacks = new HashMap<String, ODataCallback>();
+    callbacks.put(TombstoneCallback.CALLBACK_KEY_TOMBSTONE, tombstoneCallback);
+
+    EntityProviderWriteProperties properties =
+        EntityProviderWriteProperties.serviceRoot(new URI(BASE_URI)).callbacks(callbacks).build();
+
+    final ODataResponse response = new JsonEntityProvider().writeFeed(entitySet, roomsData,
+        properties);
+    assertNotNull(response);
+    assertNotNull(response.getEntity());
+    assertNull("EntitypProvider must not set content header", response.getContentHeader());
+
+    final String json = StringHelper.inputStreamToString((InputStream) response.getEntity());
+    assertNotNull(json);
+
+    assertTrue("Delta Link missing or wrong!", json.contains("__delta\":\"http://host:80/service/Rooms?!deltatoken=1234"));
+    
+  }
+
+}