Repository: olingo-odata4
Updated Branches:
  refs/heads/master 6dfdee2ef -> 9fa8fbc31


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9fa8fbc3/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/v4/ODataOutsideUpdateResponseItem.java
----------------------------------------------------------------------
diff --git 
a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/v4/ODataOutsideUpdateResponseItem.java
 
b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/v4/ODataOutsideUpdateResponseItem.java
new file mode 100644
index 0000000..149c24a
--- /dev/null
+++ 
b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/v4/ODataOutsideUpdateResponseItem.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.client.core.communication.request.batch.v4;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import org.apache.olingo.client.api.communication.response.ODataResponse;
+import 
org.apache.olingo.client.core.communication.request.batch.AbstractODataBatchResponseItem;
+import 
org.apache.olingo.client.core.communication.request.batch.ODataBatchUtilities;
+import 
org.apache.olingo.client.core.communication.response.batch.ODataBatchErrorResponse;
+
+/**
+ * Retrieve response wrapper for the corresponding batch item.
+ */
+public class ODataOutsideUpdateResponseItem extends 
AbstractODataBatchResponseItem {
+
+  public static final String OUTSIDE_CONTENT_ID = "__OUTSIDEUPDATE__";
+
+  /**
+   * Constructor.
+   */
+  public ODataOutsideUpdateResponseItem() {
+    super(false);
+  }
+
+  /**
+   * {@inheritDoc }
+   */
+  @Override
+  public ODataResponse next() {
+    if (closed) {
+      throw new IllegalStateException("Invalid request - the item has been 
closed");
+    }
+
+    final Map.Entry<Integer, String> responseLine = 
ODataBatchUtilities.readResponseLine(batchLineIterator);
+    LOG.debug("Retrieved item response {}", responseLine);
+
+    final Map<String, Collection<String>> headers = 
ODataBatchUtilities.readHeaders(batchLineIterator);
+    LOG.debug("Retrieved item headers {}", headers);
+
+    final ODataResponse res;
+
+    if (responseLine.getKey() >= 400) {
+      // generate error response
+      res = new ODataBatchErrorResponse(responseLine, headers, 
batchLineIterator, boundary);
+    } else {
+      if (!hasNext()) {
+        throw new NoSuchElementException("No item found");
+      }
+      res = expectedItemsIterator.next().initFromBatch(responseLine, headers, 
batchLineIterator, boundary);
+    }
+
+    return res;
+  }
+
+  /**
+   * Unsupported operation.
+   */
+  @Override
+  public void remove() {
+    throw new UnsupportedOperationException("Operation not supported.");
+  }
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9fa8fbc3/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/AbstractODataStreamedRequest.java
----------------------------------------------------------------------
diff --git 
a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/AbstractODataStreamedRequest.java
 
b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/AbstractODataStreamedRequest.java
index efd0cf2..17b8161 100644
--- 
a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/AbstractODataStreamedRequest.java
+++ 
b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/AbstractODataStreamedRequest.java
@@ -32,7 +32,7 @@ import org.apache.olingo.client.api.CommonODataClient;
 import org.apache.olingo.client.api.communication.request.ODataStreamManager;
 import org.apache.olingo.client.api.communication.request.ODataStreamedRequest;
 import org.apache.olingo.client.api.communication.request.ODataStreamer;
-import 
org.apache.olingo.client.api.communication.request.batch.ODataBatchRequest;
+import 
org.apache.olingo.client.api.communication.request.batch.CommonODataBatchRequest;
 import org.apache.olingo.client.api.communication.response.ODataResponse;
 import org.apache.olingo.commons.api.format.ODataMediaFormat;
 import org.apache.olingo.client.api.http.HttpMethod;
@@ -112,7 +112,7 @@ public abstract class AbstractODataStreamedRequest<V 
extends ODataResponse, T ex
    *
    * @param req destination batch request.
    */
-  public void batch(final ODataBatchRequest req) {
+  public void batch(final CommonODataBatchRequest req) {
     batch(req, null);
   }
 
@@ -124,7 +124,7 @@ public abstract class AbstractODataStreamedRequest<V 
extends ODataResponse, T ex
    * @param req destination batch request.
    * @param contentId ContentId header value to be added to the serialization. 
Use this in case of changeset items.
    */
-  public void batch(final ODataBatchRequest req, final String contentId) {
+  public void batch(final CommonODataBatchRequest req, final String contentId) 
{
     final InputStream input = getStreamManager().getBody();
 
     try {

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9fa8fbc3/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/ODataMediaEntityCreateRequestImpl.java
----------------------------------------------------------------------
diff --git 
a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/ODataMediaEntityCreateRequestImpl.java
 
b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/ODataMediaEntityCreateRequestImpl.java
index cbd292d..188891c 100644
--- 
a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/ODataMediaEntityCreateRequestImpl.java
+++ 
b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/ODataMediaEntityCreateRequestImpl.java
@@ -24,7 +24,6 @@ import java.util.concurrent.TimeUnit;
 import org.apache.http.HttpResponse;
 import org.apache.http.client.HttpClient;
 import org.apache.olingo.client.api.CommonODataClient;
-import 
org.apache.olingo.client.api.communication.request.ODataBatchableRequest;
 import 
org.apache.olingo.client.api.communication.request.streamed.MediaEntityCreateStreamManager;
 import 
org.apache.olingo.client.api.communication.request.streamed.ODataMediaEntityCreateRequest;
 import 
org.apache.olingo.client.api.communication.response.ODataMediaEntityCreateResponse;
@@ -42,7 +41,7 @@ import org.apache.olingo.commons.api.data.Entry;
  */
 public class ODataMediaEntityCreateRequestImpl<E extends CommonODataEntity>
         extends 
AbstractODataStreamedEntityRequest<ODataMediaEntityCreateResponse<E>, 
MediaEntityCreateStreamManager<E>>
-        implements ODataMediaEntityCreateRequest<E>, ODataBatchableRequest {
+        implements ODataMediaEntityCreateRequest<E> {
 
   private final InputStream media;
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9fa8fbc3/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/ODataMediaEntityUpdateRequestImpl.java
----------------------------------------------------------------------
diff --git 
a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/ODataMediaEntityUpdateRequestImpl.java
 
b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/ODataMediaEntityUpdateRequestImpl.java
index 5967906..bb8ef64 100644
--- 
a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/ODataMediaEntityUpdateRequestImpl.java
+++ 
b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/ODataMediaEntityUpdateRequestImpl.java
@@ -24,7 +24,6 @@ import java.util.concurrent.TimeUnit;
 import org.apache.http.HttpResponse;
 import org.apache.http.client.HttpClient;
 import org.apache.olingo.client.api.CommonODataClient;
-import 
org.apache.olingo.client.api.communication.request.ODataBatchableRequest;
 import 
org.apache.olingo.client.api.communication.request.streamed.MediaEntityUpdateStreamManager;
 import 
org.apache.olingo.client.api.communication.request.streamed.ODataMediaEntityUpdateRequest;
 import 
org.apache.olingo.client.api.communication.response.ODataMediaEntityUpdateResponse;
@@ -42,7 +41,7 @@ import org.apache.olingo.commons.api.data.Entry;
  */
 public class ODataMediaEntityUpdateRequestImpl<E extends CommonODataEntity>
         extends 
AbstractODataStreamedEntityRequest<ODataMediaEntityUpdateResponse<E>, 
MediaEntityUpdateStreamManager<E>>
-        implements ODataMediaEntityUpdateRequest<E>, ODataBatchableRequest {
+        implements ODataMediaEntityUpdateRequest<E> {
 
   private final InputStream media;
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9fa8fbc3/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/BatchTestITCase.java
----------------------------------------------------------------------
diff --git 
a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/BatchTestITCase.java
 
b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/BatchTestITCase.java
index e909b7a..0e67a07 100644
--- 
a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/BatchTestITCase.java
+++ 
b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/BatchTestITCase.java
@@ -32,10 +32,10 @@ import org.apache.http.HttpResponse;
 import org.apache.olingo.client.api.ODataBatchConstants;
 import org.apache.olingo.client.api.communication.request.ODataStreamManager;
 import 
org.apache.olingo.client.api.communication.request.batch.BatchStreamManager;
-import 
org.apache.olingo.client.api.communication.request.batch.ODataBatchRequest;
 import 
org.apache.olingo.client.api.communication.request.batch.ODataBatchResponseItem;
 import org.apache.olingo.client.api.communication.request.batch.ODataChangeset;
 import org.apache.olingo.client.api.communication.request.batch.ODataRetrieve;
+import 
org.apache.olingo.client.api.communication.request.batch.v3.ODataBatchRequest;
 import 
org.apache.olingo.client.api.communication.request.cud.ODataEntityCreateRequest;
 import 
org.apache.olingo.client.api.communication.request.cud.ODataEntityUpdateRequest;
 import org.apache.olingo.client.api.communication.request.cud.v3.UpdateType;

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9fa8fbc3/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/BatchTestITCase.java
----------------------------------------------------------------------
diff --git 
a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/BatchTestITCase.java
 
b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/BatchTestITCase.java
index dcff42f..aabcd6d 100644
--- 
a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/BatchTestITCase.java
+++ 
b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/BatchTestITCase.java
@@ -18,8 +18,6 @@
  */
 package org.apache.olingo.client.core.it.v4;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.fail;
 
@@ -35,11 +33,12 @@ import org.apache.olingo.client.api.ODataBatchConstants;
 import org.apache.olingo.client.api.communication.header.HeaderName;
 import org.apache.olingo.client.api.communication.header.ODataPreferences;
 import org.apache.olingo.client.api.communication.request.ODataStreamManager;
-import 
org.apache.olingo.client.api.communication.request.batch.BatchStreamManager;
-import 
org.apache.olingo.client.api.communication.request.batch.ODataBatchRequest;
 import 
org.apache.olingo.client.api.communication.request.batch.ODataBatchResponseItem;
 import org.apache.olingo.client.api.communication.request.batch.ODataChangeset;
 import org.apache.olingo.client.api.communication.request.batch.ODataRetrieve;
+import 
org.apache.olingo.client.api.communication.request.batch.v4.BatchStreamManager;
+import 
org.apache.olingo.client.api.communication.request.batch.v4.ODataBatchRequest;
+import 
org.apache.olingo.client.api.communication.request.batch.v4.ODataOutsideUpdate;
 import 
org.apache.olingo.client.api.communication.request.cud.ODataEntityCreateRequest;
 import 
org.apache.olingo.client.api.communication.request.cud.ODataEntityUpdateRequest;
 import org.apache.olingo.client.api.communication.request.cud.v4.UpdateType;
@@ -54,15 +53,20 @@ import 
org.apache.olingo.client.core.communication.request.AbstractODataStreamMa
 import org.apache.olingo.client.core.communication.request.Wrapper;
 import 
org.apache.olingo.client.core.communication.request.batch.ODataChangesetResponseItem;
 import 
org.apache.olingo.client.core.communication.request.batch.ODataRetrieveResponseItem;
+import 
org.apache.olingo.client.core.communication.request.batch.v4.ODataOutsideUpdateResponseItem;
 import 
org.apache.olingo.client.core.communication.request.retrieve.ODataEntityRequestImpl;
 import 
org.apache.olingo.client.core.communication.request.retrieve.ODataEntityRequestImpl.ODataEntityResponseImpl;
+import static org.apache.olingo.client.core.it.v4.AbstractTestITCase.client;
 import org.apache.olingo.client.core.uri.URIUtils;
 import org.apache.olingo.commons.api.domain.v4.ODataEntity;
 import org.apache.olingo.commons.api.domain.v4.ODataEntitySet;
 import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
 import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
 import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.format.ContentType;
 import org.apache.olingo.commons.api.format.ODataPubFormat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 import org.junit.Test;
 
 public class BatchTestITCase extends AbstractTestITCase {
@@ -73,6 +77,14 @@ public class BatchTestITCase extends AbstractTestITCase {
 
   private static final int MAX = 10000;
 
+  // ------------------------
+  // Uncomment to performe check externally ...
+  // ------------------------
+  // private final static String testStaticServiceRootURL= 
"http://odatae2etest.azurewebsites.net/javatest/DefaultService/";;
+  // private final static String ACCEPT = ContentType.MULTIPART_MIXED;
+  // ------------------------
+  private final static String ACCEPT = ContentType.APPLICATION_OCTET_STREAM;
+
   @Test
   public void stringStreaming() {
     final TestStreamManager streaming = new TestStreamManager();
@@ -93,6 +105,7 @@ public class BatchTestITCase extends AbstractTestITCase {
   public void emptyBatchRequest() {
     // create your request
     final ODataBatchRequest request = 
client.getBatchRequestFactory().getBatchRequest(testStaticServiceRootURL);
+    request.setAccept(ACCEPT);
 
     final BatchStreamManager payload = request.execute();
     final ODataBatchResponse response = payload.getResponse();
@@ -108,6 +121,7 @@ public class BatchTestITCase extends AbstractTestITCase {
   public void changesetWithError() {
     // create your request
     final ODataBatchRequest request = 
client.getBatchRequestFactory().getBatchRequest(testStaticServiceRootURL);
+    request.setAccept(ACCEPT);
 
     final BatchStreamManager payload = request.execute();
     final ODataChangeset changeset = payload.addChangeset();
@@ -164,6 +178,7 @@ public class BatchTestITCase extends AbstractTestITCase {
   private void continueOnError(final boolean continueOnError) {
     // create your request
     final ODataBatchRequest request = 
client.getBatchRequestFactory().getBatchRequest(testStaticServiceRootURL);
+    request.setAccept(ACCEPT);
 
     if (continueOnError) {
       request.addCustomHeader(HeaderName.prefer, new 
ODataPreferences(client.getServiceVersion()).continueOnError());
@@ -232,6 +247,7 @@ public class BatchTestITCase extends AbstractTestITCase {
   public void changesetWithReference() throws EdmPrimitiveTypeException {
     // create your request
     final ODataBatchRequest request = 
client.getBatchRequestFactory().getBatchRequest(testStaticServiceRootURL);
+    request.setAccept(ACCEPT);
     final BatchStreamManager streamManager = request.execute();
 
     final ODataChangeset changeset = streamManager.addChangeset();
@@ -312,9 +328,81 @@ public class BatchTestITCase extends AbstractTestITCase {
 
   @Test
   @SuppressWarnings("unchecked")
+  public void batchRequestWithOutsideUpdates() throws 
EdmPrimitiveTypeException {
+    // create your request
+    final ODataBatchRequest request = 
client.getBatchRequestFactory().getBatchRequest(testStaticServiceRootURL);
+    request.setAccept(ACCEPT);
+    final BatchStreamManager streamManager = request.execute();
+
+    // -------------------------------------------
+    // Add retrieve item
+    // -------------------------------------------
+    ODataRetrieve retrieve = streamManager.addRetrieve();
+
+    // prepare URI
+    URIBuilder targetURI = client.getURIBuilder(testStaticServiceRootURL);
+    targetURI.appendEntitySetSegment("Customers").appendKeySegment(1).
+            expand("Orders").select("PersonID,Orders/OrderID");
+
+    // create new request
+    ODataEntityRequest<ODataEntity> queryReq = 
client.getRetrieveRequestFactory().getEntityRequest(targetURI.build());
+    queryReq.setFormat(ODataPubFormat.ATOM);
+
+    retrieve.setRequest(queryReq);
+    // -------------------------------------------
+
+    // -------------------------------------------
+    // Add new order with outside item
+    // -------------------------------------------
+    final ODataOutsideUpdate outside = streamManager.addOutsideUpdate();
+
+    // prepare URI
+    targetURI = 
client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Orders");
+    final ODataEntity original = newOrder(2000);
+    final ODataEntityCreateRequest<ODataEntity> createReq =
+            
client.getCUDRequestFactory().getEntityCreateRequest(targetURI.build(), 
original);
+    createReq.setFormat(ODataPubFormat.ATOM);
+    outside.setRequest(createReq);
+    // -------------------------------------------
+
+    final ODataBatchResponse response = streamManager.getResponse();
+    assertEquals(200, response.getStatusCode());
+    assertEquals("OK", response.getStatusMessage());
+    final Iterator<ODataBatchResponseItem> iter = response.getBody();
+
+    // retrieve the first item (ODataRetrieve)
+    ODataBatchResponseItem item = iter.next();
+    assertTrue(item instanceof ODataRetrieveResponseItem);
+
+    ODataRetrieveResponseItem retitem = (ODataRetrieveResponseItem) item;
+    ODataResponse res = retitem.next();
+    assertTrue(res instanceof ODataEntityResponseImpl);
+    assertEquals(200, res.getStatusCode());
+    assertEquals("OK", res.getStatusMessage());
+
+    // retrieve the second item (ODataChangeset)
+    item = iter.next();
+    assertTrue(item instanceof ODataOutsideUpdateResponseItem);
+
+    final ODataOutsideUpdateResponseItem outitem = 
(ODataOutsideUpdateResponseItem) item;
+    res = outitem.next();
+    assertTrue(res instanceof ODataEntityCreateResponse);
+    assertEquals(201, res.getStatusCode());
+    assertEquals("Created", res.getStatusMessage());
+
+    final ODataEntityCreateResponse<ODataEntity> entres = 
(ODataEntityCreateResponse<ODataEntity>) res;
+    final ODataEntity entity = entres.getBody();
+    assertEquals(2000, 
entity.getProperty("OrderID").getPrimitiveValue().toCastValue(Integer.class).intValue());
+
+    assertFalse(iter.hasNext());
+  }
+
+  @Test
+  @SuppressWarnings("unchecked")
   public void batchRequest() throws EdmPrimitiveTypeException {
     // create your request
     final ODataBatchRequest request = 
client.getBatchRequestFactory().getBatchRequest(testStaticServiceRootURL);
+    request.setAccept(ACCEPT);
 
     final BatchStreamManager streamManager = request.execute();
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9fa8fbc3/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/ContentType.java
----------------------------------------------------------------------
diff --git 
a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/ContentType.java
 
b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/ContentType.java
index c41cfc5..9e6cfed 100644
--- 
a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/ContentType.java
+++ 
b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/ContentType.java
@@ -33,6 +33,8 @@ public abstract class ContentType {
 
   public static final String APPLICATION_OCTET_STREAM = 
"application/octet-stream";
 
+  public static final String MULTIPART_MIXED = "multipart/mixed";
+
   public static final String APPLICATION_SVG_XML = "application/svg+xml";
 
   public static final String APPLICATION_XHTML_XML = "application/xhtml+xml";

Reply via email to