You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by fm...@apache.org on 2014/07/18 18:07:54 UTC

[15/15] git commit: [OLINGO-366,OLINGO-367,OLINGO-370] merge

[OLINGO-366,OLINGO-367,OLINGO-370] merge


Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/cdc98eac
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/cdc98eac
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/cdc98eac

Branch: refs/heads/master
Commit: cdc98eacd83ca22044f1b22f71dcd57e4098a0ae
Parents: 989babb 3e81f05
Author: fmartelli <fa...@gmail.com>
Authored: Fri Jul 18 18:07:15 2014 +0200
Committer: fmartelli <fa...@gmail.com>
Committed: Fri Jul 18 18:07:15 2014 +0200

----------------------------------------------------------------------
 .../ext/proxy/api/PersistenceManager.java       |  7 +-
 .../commons/AbstractPersistenceManager.java     |  8 +-
 .../EntityContainerInvocationHandler.java       |  5 +-
 .../NonTransactionalPersistenceManagerImpl.java | 25 ++++--
 .../TransactionalPersistenceManagerImpl.java    | 61 +++++++++++---
 .../java/org/apache/olingo/fit/V4Services.java  | 35 ++++++--
 .../olingo/fit/proxy/v3/ContextTestITCase.java  |  1 -
 .../fit/proxy/v4/APIBasicDesignTestITCase.java  |  1 -
 .../olingo/fit/proxy/v4/ContextTestITCase.java  | 89 ++++++++++++++++++++
 .../v4/OperationImportInvokeTestITCase.java     |  1 -
 .../apache/olingo/fit/v4/BatchTestITCase.java   | 72 ++++++++--------
 .../apache/olingo/client/api/Configuration.java | 68 +++++++++------
 .../ODataClientErrorException.java              |  3 +-
 .../ODataServerErrorException.java              |  3 +-
 .../request/batch/v4/ODataBatchRequest.java     |  4 -
 .../olingo/client/core/ConfigurationImpl.java   | 14 ++-
 .../header/ODataErrorResponseChecker.java       | 85 +++++++++++++++++++
 .../communication/request/AbstractRequest.java  | 60 +++----------
 .../request/batch/AbstractBatchManager.java     | 23 ++---
 .../batch/ODataChangesetResponseItem.java       | 14 ++-
 .../request/batch/v3/ODataBatchRequestImpl.java | 19 +----
 .../request/batch/v4/ODataBatchRequestImpl.java | 43 +++-------
 .../commons/api/ODataRuntimeException.java      | 10 +--
 .../server/api/TranslatedExceptionsTest.java    |  5 ++
 .../serializer/json/ODataErrorSerializer.java   | 33 ++++----
 .../serializer/json/ODataJsonSerializer.java    | 47 +++++------
 .../json/ServiceDocumentJsonSerializer.java     | 43 +++++-----
 .../olingo/server/tecsvc/data/DataProvider.java | 47 ++++++++---
 .../json/ODataJsonSerializerTest.java           | 80 +++++++++++++++++-
 29 files changed, 597 insertions(+), 309 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/cdc98eac/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractPersistenceManager.java
----------------------------------------------------------------------
diff --cc ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractPersistenceManager.java
index d4799c9,5d128a5..04e5d2a
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractPersistenceManager.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractPersistenceManager.java
@@@ -61,16 -62,16 +62,16 @@@ abstract class AbstractPersistenceManag
  
    private static final long serialVersionUID = 2065240290461241515L;
  
 -  protected final Service<?> factory;
 +  protected final Service<?> service;
  
    AbstractPersistenceManager(final Service<?> factory) {
 -    this.factory = factory;
 +    this.service = factory;
    }
  
-   protected abstract void doFlush(final PersistenceChanges changes, final TransactionItems items);
+   protected abstract List<ODataRuntimeException> doFlush(PersistenceChanges changes, TransactionItems items);
  
    @Override
-   public void flush() {
+   public List<ODataRuntimeException> flush() {
      final PersistenceChanges changes = new PersistenceChanges();
      final TransactionItems items = new TransactionItems();
  
@@@ -89,9 -90,11 +90,10 @@@
  
      processDelayedUpdates(delayedUpdates, pos, items, changes);
  
-     doFlush(changes, items);
+     final List<ODataRuntimeException> result = doFlush(changes, items);
  
 -    factory.getContext().detachAll();
 -
 +    service.getContext().detachAll();
+     return result;
    }
  
    private ODataLink buildNavigationLink(final String name, final URI uri, final ODataLinkType type) {

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/cdc98eac/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityContainerInvocationHandler.java
----------------------------------------------------------------------
diff --cc ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityContainerInvocationHandler.java
index a892081,fb7d361..68a8801
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityContainerInvocationHandler.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityContainerInvocationHandler.java
@@@ -80,8 -80,7 +78,7 @@@ public final class EntityContainerInvoc
      if (isSelfMethod(method, args)) {
        return invokeSelfMethod(method, args);
      } else if ("flush".equals(method.getName()) && ArrayUtils.isEmpty(args)) {
-       service.getPersistenceManager().flush();
-       return ClassUtils.returnVoid();
 -      return factory.getPersistenceManager().flush();
++      return service.getPersistenceManager().flush();
      } else if ("operations".equals(method.getName()) && ArrayUtils.isEmpty(args)) {
        final Class<?> returnType = method.getReturnType();
  

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/cdc98eac/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/NonTransactionalPersistenceManagerImpl.java
----------------------------------------------------------------------
diff --cc ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/NonTransactionalPersistenceManagerImpl.java
index 1757397,a92068b..c436cbd
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/NonTransactionalPersistenceManagerImpl.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/NonTransactionalPersistenceManagerImpl.java
@@@ -18,13 -18,12 +18,15 @@@
   */
  package org.apache.olingo.ext.proxy.commons;
  
 +import java.net.URI;
+ import java.util.ArrayList;
 -import java.util.Iterator;
 +import java.util.HashMap;
+ import java.util.List;
  import java.util.Map;
- 
  import org.apache.olingo.client.api.communication.request.ODataBasicRequest;
  import org.apache.olingo.client.api.communication.request.ODataBatchableRequest;
 +import org.apache.olingo.client.api.communication.request.ODataRequest;
++import org.apache.olingo.client.api.communication.request.ODataStreamedRequest;
  import org.apache.olingo.client.api.communication.response.ODataEntityCreateResponse;
  import org.apache.olingo.client.api.communication.response.ODataEntityUpdateResponse;
  import org.apache.olingo.client.api.communication.response.ODataResponse;
@@@ -45,31 -43,15 +46,33 @@@ public class NonTransactionalPersistenc
    }
  
    @Override
-   protected void doFlush(final PersistenceChanges changes, final TransactionItems items) {
+   protected List<ODataRuntimeException> doFlush(final PersistenceChanges changes, final TransactionItems items) {
+     final List<ODataRuntimeException> result = new ArrayList<ODataRuntimeException>();
+ 
 -    for (final Iterator<Map.Entry<ODataBatchableRequest, EntityInvocationHandler>> itor =
 -            changes.getChanges().entrySet().iterator(); itor.hasNext();) {
 +    final Map<Integer, URI> responses = new HashMap<Integer, URI>();
 +    int virtualContentID = 0;
 +
 +    for (Map.Entry<ODataBatchableRequest, EntityInvocationHandler> entry : changes.getChanges().entrySet()) {
 +      virtualContentID++;
  
 -      final Map.Entry<ODataBatchableRequest, EntityInvocationHandler> entry = itor.next();
        try {
 -        final ODataResponse response = ((ODataBasicRequest<?>) entry.getKey()).execute();
 +        final ODataRequest req = ODataRequest.class.cast(entry.getKey());
 +        String uri = req.getURI().toASCIIString();
 +        if (uri.startsWith("$")) {
 +          int slashIndex = uri.indexOf('/');
 +          final Integer toBeReplaced = Integer.valueOf(uri.substring(1, slashIndex < 0 ? uri.length() : slashIndex));
 +          if (responses.containsKey(toBeReplaced)) {
 +            uri = uri.replace("$" + toBeReplaced, responses.get(Integer.valueOf(toBeReplaced)).toASCIIString());
 +            req.setURI(URI.create(uri));
 +          }
 +        }
 +
 +        final ODataResponse response;
 +        if (ODataStreamedRequest.class.isAssignableFrom(req.getClass())) {
 +          response = ((ODataStreamedRequest<?, ?>) req).payloadManager().getResponse();
 +        } else {
 +          response = ((ODataBasicRequest<?>) req).execute();
 +        }
  
          if (response instanceof ODataEntityCreateResponse && response.getStatusCode() == 201) {
            entry.getValue().setEntity(((ODataEntityCreateResponse<?>) response).getBody());
@@@ -77,14 -58,21 +80,24 @@@
            LOG.debug("Upgrade created object '{}'", entry.getValue());
          } else if (response instanceof ODataEntityUpdateResponse && response.getStatusCode() == 200) {
            entry.getValue().setEntity(((ODataEntityUpdateResponse<?>) response).getBody());
 +          responses.put(virtualContentID, entry.getValue().getEntityURI());
            LOG.debug("Upgrade updated object '{}'", entry.getValue());
 +        } else {
 +          responses.put(virtualContentID, null);
          }
-       } catch (Exception e) {
+ 
+         result.add(null);
+       } catch (ODataRuntimeException e) {
          LOG.error("While performing {}", entry.getKey().getURI(), e);
+ 
 -        if (factory.getClient().getConfiguration().isContinueOnError()) {
++        if (service.getClient().getConfiguration().isContinueOnError()) {
+           result.add(e);
+         } else {
+           throw e;
+         }
        }
      }
+ 
+     return result;
    }
  }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/cdc98eac/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/TransactionalPersistenceManagerImpl.java
----------------------------------------------------------------------
diff --cc ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/TransactionalPersistenceManagerImpl.java
index 80807ad,44be983..6660d93
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/TransactionalPersistenceManagerImpl.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/TransactionalPersistenceManagerImpl.java
@@@ -52,15 -57,15 +57,15 @@@ public class TransactionalPersistenceMa
     * Transactional changes commit.
     */
    @Override
-   protected void doFlush(final PersistenceChanges changes, final TransactionItems items) {
+   protected List<ODataRuntimeException> doFlush(final PersistenceChanges changes, final TransactionItems items) {
      final CommonODataBatchRequest request =
 -            factory.getClient().getBatchRequestFactory().getBatchRequest(factory.getClient().getServiceRoot());
 +            service.getClient().getBatchRequestFactory().getBatchRequest(service.getClient().getServiceRoot());
      ((ODataRequest) request).setAccept(
 -            factory.getClient().getConfiguration().getDefaultBatchAcceptFormat().toContentTypeString());
 +            service.getClient().getConfiguration().getDefaultBatchAcceptFormat().toContentTypeString());
  
-     final BatchManager streamManager = (BatchManager) ((ODataStreamedRequest) request).payloadManager();
+     final BatchManager batchManager = (BatchManager) ((ODataStreamedRequest) request).payloadManager();
  
-     final ODataChangeset changeset = streamManager.addChangeset();
+     final ODataChangeset changeset = batchManager.addChangeset();
      for (Map.Entry<ODataBatchableRequest, EntityInvocationHandler> entry : changes.getChanges().entrySet()) {
        changeset.addRequest(entry.getKey());
      }
@@@ -86,11 -93,39 +93,39 @@@
  
        final ODataChangesetResponseItem chgres = (ODataChangesetResponseItem) item;
  
-       for (Integer changesetItemId : items.sortedValues()) {
+       for (final Iterator<Integer> itor = items.sortedValues().iterator(); itor.hasNext();) {
+         final Integer changesetItemId = itor.next();
          LOG.debug("Expected changeset item {}", changesetItemId);
+ 
          final ODataResponse res = chgres.next();
          if (res.getStatusCode() >= 400) {
-           throw new IllegalStateException("Transaction failed: " + res.getStatusMessage());
 -          if (factory.getClient().getConfiguration().isContinueOnError()) {
++          if (service.getClient().getConfiguration().isContinueOnError()) {
+             result.add(ODataErrorResponseChecker.checkResponse(
 -                    factory.getClient(),
++                    service.getClient(),
+                     new StatusLine() {
+ 
+                       @Override
+                       public ProtocolVersion getProtocolVersion() {
+                         return null;
+                       }
+ 
+                       @Override
+                       public int getStatusCode() {
+                         return res.getStatusCode();
+                       }
+ 
+                       @Override
+                       public String getReasonPhrase() {
+                         return res.getStatusMessage();
+                       }
+                     },
+                     res.getRawResponse(),
+                     ((ODataRequest) request).getAccept()));
+           } else {
+             throw new IllegalStateException("Transaction failed: " + res.getStatusMessage());
+           }
+         } else {
+           result.add(null);
          }
  
          final EntityInvocationHandler handler = items.get(changesetItemId);

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/cdc98eac/fit/src/test/java/org/apache/olingo/fit/proxy/v3/ContextTestITCase.java
----------------------------------------------------------------------
diff --cc fit/src/test/java/org/apache/olingo/fit/proxy/v3/ContextTestITCase.java
index 97fec2f,82a5648..1c5071a
--- a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/ContextTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/ContextTestITCase.java
@@@ -16,10 -16,8 +16,9 @@@
   * specific language governing permissions and limitations
   * under the License.
   */
- 
  package org.apache.olingo.fit.proxy.v3;
  
 +//CHECKSTYLE:OFF (Maven checkstyle)
  import org.apache.olingo.ext.proxy.api.annotations.NavigationProperty;
  import org.apache.olingo.ext.proxy.commons.EntityInvocationHandler;
  import org.apache.olingo.ext.proxy.context.AttachedEntityStatus;

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/cdc98eac/fit/src/test/java/org/apache/olingo/fit/proxy/v4/APIBasicDesignTestITCase.java
----------------------------------------------------------------------
diff --cc fit/src/test/java/org/apache/olingo/fit/proxy/v4/APIBasicDesignTestITCase.java
index 717ddf6,907dea6..117e12e
--- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/APIBasicDesignTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/APIBasicDesignTestITCase.java
@@@ -16,10 -16,8 +16,9 @@@
   * specific language governing permissions and limitations
   * under the License.
   */
- 
  package org.apache.olingo.fit.proxy.v4;
  
 +//CHECKSTYLE:OFF (Maven checkstyle)
  import org.apache.olingo.client.api.v4.EdmEnabledODataClient;
  import org.apache.olingo.ext.proxy.Service;
  import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.InMemoryEntities;

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/cdc98eac/fit/src/test/java/org/apache/olingo/fit/proxy/v4/ContextTestITCase.java
----------------------------------------------------------------------
diff --cc fit/src/test/java/org/apache/olingo/fit/proxy/v4/ContextTestITCase.java
index 0000000,936351a..5e57385
mode 000000,100644..100644
--- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/ContextTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/ContextTestITCase.java
@@@ -1,0 -1,91 +1,89 @@@
+ /*
+  * 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.fit.proxy.v4;
+ 
+ import static org.junit.Assert.assertEquals;
+ import static org.junit.Assert.assertNull;
+ import static org.junit.Assert.assertTrue;
+ 
 -import java.lang.reflect.Proxy;
+ import java.sql.Timestamp;
+ import java.util.Arrays;
+ import java.util.Calendar;
+ import java.util.Collections;
+ import java.util.List;
+ import java.util.TimeZone;
+ import org.apache.olingo.client.api.communication.ODataClientErrorException;
+ import org.apache.olingo.client.api.v4.EdmEnabledODataClient;
+ import org.apache.olingo.commons.api.ODataRuntimeException;
+ import org.apache.olingo.commons.api.format.ContentType;
+ import org.apache.olingo.ext.proxy.Service;
 -import org.apache.olingo.ext.proxy.commons.EntityInvocationHandler;
+ import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.InMemoryEntities;
+ import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Address;
+ import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Employee;
+ import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Person;
+ import org.junit.Test;
+ 
+ public class ContextTestITCase extends AbstractTestITCase {
+ 
+   private void continueOnError(final Service<EdmEnabledODataClient> service, final InMemoryEntities container) {
 -    final Person person = container.getPeople().newPerson();
++    final Person person = service.newEntity(Person.class);
++    container.getPeople().add(person);
+ 
 -    final EntityInvocationHandler handler = (EntityInvocationHandler) Proxy.getInvocationHandler(person);
 -    assertTrue(service.getContext().entityContext().isAttached(handler));
 -
 -    final Employee employee = container.getPeople().newEmployee();
++    final Employee employee = service.newEntity(Employee.class);
+     employee.setPersonID(199);
+     employee.setFirstName("Fabio");
+     employee.setLastName("Martelli");
+     employee.setEmails(Collections.<String>singleton("fabio.martelli@tirasa.net"));
+     final Calendar date = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
+     date.clear();
+     date.set(2011, 3, 4, 9, 0, 0);
+     employee.setDateHired(new Timestamp(date.getTimeInMillis()));
 -    final Address homeAddress = employee.factory().newHomeAddress();
++    final Address homeAddress = service.newComplex(Address.class);
+     homeAddress.setCity("Pescara");
+     homeAddress.setPostalCode("65100");
+     homeAddress.setStreet("viale Gabriele D'Annunzio 256");
+     employee.setHomeAddress(homeAddress);
+     employee.setNumbers(Arrays.asList(new String[] {"3204725072", "08569930"}));
+ 
++    container.getPeople().add(employee);
++
+     final List<ODataRuntimeException> result = container.flush();
+     assertEquals(2, result.size());
+     assertTrue(result.get(0) instanceof ODataClientErrorException);
+     assertNull(result.get(1));
+   }
+ 
+   @Test
+   public void transactionalContinueOnError() {
+     service.getClient().getConfiguration().setContinueOnError(true);
+     continueOnError(service, container);
+     service.getClient().getConfiguration().setContinueOnError(false);
+   }
+ 
+   @Test
+   public void nonTransactionalContinueOnError() {
+     final Service<EdmEnabledODataClient> _service = Service.getV4(testStaticServiceRootURL, false);
+     _service.getClient().getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM);
+     _service.getClient().getConfiguration().setContinueOnError(true);
+ 
+     final InMemoryEntities _container = _service.getEntityContainer(InMemoryEntities.class);
+ 
+     continueOnError(_service, _container);
+   }
+ }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/cdc98eac/fit/src/test/java/org/apache/olingo/fit/proxy/v4/OperationImportInvokeTestITCase.java
----------------------------------------------------------------------
diff --cc fit/src/test/java/org/apache/olingo/fit/proxy/v4/OperationImportInvokeTestITCase.java
index a188017,0c16801..4b1e8ec
--- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/OperationImportInvokeTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/OperationImportInvokeTestITCase.java
@@@ -16,10 -16,8 +16,9 @@@
   * specific language governing permissions and limitations
   * under the License.
   */
- 
  package org.apache.olingo.fit.proxy.v4;
  
 +//CHECKSTYLE:OFF (Maven checkstyle)
  import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.AccessLevel;
  import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Address;
  import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Color;