olingo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject [1/4] olingo-odata4 git commit: [OLINGO-545] Entity-update implementation in technical service
Date Fri, 30 Jan 2015 11:30:01 GMT
Repository: olingo-odata4
Updated Branches:
  refs/heads/master 15df71c85 -> b0a6b8478


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/483b417c/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
index f86a64c..3400b0d 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
@@ -30,11 +30,13 @@ import org.apache.olingo.commons.api.format.ContentType;
 import org.apache.olingo.commons.api.format.ODataFormat;
 import org.apache.olingo.commons.api.http.HttpContentType;
 import org.apache.olingo.commons.api.http.HttpHeader;
+import org.apache.olingo.commons.api.http.HttpMethod;
 import org.apache.olingo.commons.api.http.HttpStatusCode;
 import org.apache.olingo.server.api.ODataApplicationException;
 import org.apache.olingo.server.api.ODataRequest;
 import org.apache.olingo.server.api.ODataResponse;
 import org.apache.olingo.server.api.deserializer.DeserializerException;
+import org.apache.olingo.server.api.deserializer.ODataDeserializer;
 import org.apache.olingo.server.api.processor.ActionEntityCollectionProcessor;
 import org.apache.olingo.server.api.processor.ActionEntityProcessor;
 import org.apache.olingo.server.api.processor.CountEntityCollectionProcessor;
@@ -94,16 +96,15 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
 
   @Override
   public void processActionEntityCollection(final ODataRequest request, final ODataResponse
response,
-                                      final UriInfo uriInfo,
-                                      final ContentType requestFormat, final ContentType
 responseFormat)
+      final UriInfo uriInfo, final ContentType requestFormat, final ContentType responseFormat)
           throws ODataApplicationException, DeserializerException, SerializerException {
     throw new ODataApplicationException("Process entity collection is not supported yet.",
-            HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ROOT);
+        HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ROOT);
   }
 
   @Override
   public void countEntityCollection(final ODataRequest request, ODataResponse response, final
UriInfo uriInfo)
-          throws ODataApplicationException, SerializerException {
+      throws ODataApplicationException, SerializerException {
     validateOptions(uriInfo.asUriInfoResource());
     blockNavigation(uriInfo);
 
@@ -129,43 +130,37 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
     final EdmEntitySet edmEntitySet = getEdmEntitySet(uriInfo.asUriInfoResource());
     final UriResourceEntitySet resourceEntitySet = (UriResourceEntitySet) uriInfo.getUriResourceParts().get(0);
     final Entity entity = dataProvider.read(edmEntitySet, resourceEntitySet.getKeyPredicates());
+    checkEntity(entity);
 
-    if (entity == null) {
-      throw new ODataApplicationException("Nothing found.", HttpStatusCode.NOT_FOUND.getStatusCode(),
Locale.ROOT);
-    } else {
-      final ODataFormat format = ODataFormat.fromContentType(requestedContentType);
-      ODataSerializer serializer = odata.createSerializer(format);
-      final ExpandOption expand = uriInfo.getExpandOption();
-      final SelectOption select = uriInfo.getSelectOption();
-      response.setContent(serializer.entity(edmEntitySet.getEntityType(), entity,
-          EntitySerializerOptions.with()
-              .contextURL(format == ODataFormat.JSON_NO_METADATA ? null :
-                  getContextUrl(edmEntitySet, true, expand, select))
-              .expand(expand).select(select)
-              .build()));
-      response.setStatusCode(HttpStatusCode.OK.getStatusCode());
-      response.setHeader(HttpHeader.CONTENT_TYPE, requestedContentType.toContentTypeString());
-    }
+    final ODataFormat format = ODataFormat.fromContentType(requestedContentType);
+    ODataSerializer serializer = odata.createSerializer(format);
+    final ExpandOption expand = uriInfo.getExpandOption();
+    final SelectOption select = uriInfo.getSelectOption();
+    response.setContent(serializer.entity(edmEntitySet.getEntityType(), entity,
+        EntitySerializerOptions.with()
+            .contextURL(format == ODataFormat.JSON_NO_METADATA ? null :
+                getContextUrl(edmEntitySet, true, expand, select))
+            .expand(expand).select(select)
+            .build()));
+    response.setStatusCode(HttpStatusCode.OK.getStatusCode());
+    response.setHeader(HttpHeader.CONTENT_TYPE, requestedContentType.toContentTypeString());
   }
 
   @Override
   public void readMediaEntity(final ODataRequest request, ODataResponse response, final UriInfo
uriInfo,
-                              final ContentType responseFormat) throws ODataApplicationException,
SerializerException {
+      final ContentType responseFormat) throws ODataApplicationException, SerializerException
{
     blockNavigation(uriInfo);
     final UriResourceEntitySet resourceEntitySet = (UriResourceEntitySet) uriInfo.getUriResourceParts().get(0);
     final Entity entity = dataProvider.read(resourceEntitySet.getEntitySet(), resourceEntitySet.getKeyPredicates());
-    if (entity == null) {
-      throw new ODataApplicationException("Nothing found.", HttpStatusCode.NOT_FOUND.getStatusCode(),
Locale.ROOT);
-    } else {
-      response.setContent(odata.createFixedFormatSerializer().binary(dataProvider.readMedia(entity)));
-      response.setStatusCode(HttpStatusCode.OK.getStatusCode());
-      response.setHeader(HttpHeader.CONTENT_TYPE, entity.getMediaContentType());
-    }
+    checkEntity(entity);
+    response.setContent(odata.createFixedFormatSerializer().binary(dataProvider.readMedia(entity)));
+    response.setStatusCode(HttpStatusCode.OK.getStatusCode());
+    response.setHeader(HttpHeader.CONTENT_TYPE, entity.getMediaContentType());
   }
 
   @Override
   public void createMediaEntity(final ODataRequest request, ODataResponse response, final
UriInfo uriInfo,
-                                final ContentType requestFormat, final ContentType responseFormat)
+      final ContentType requestFormat, final ContentType responseFormat)
           throws ODataApplicationException, DeserializerException, SerializerException {
 
     blockNavigation(uriInfo);
@@ -173,76 +168,65 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
     final EdmEntitySet edmEntitySet = resourceEntitySet.getEntitySet();
     Entity entity = null;
     if (edmEntitySet.getEntityType().hasStream()) {
-      if (requestFormat == null) {
-        throw new ODataApplicationException("The content type has not been set in the request.",
-                HttpStatusCode.BAD_REQUEST.getStatusCode(), Locale.ROOT);
-      }
+      checkRequestFormat(requestFormat);
       entity = dataProvider.create(edmEntitySet);
       dataProvider.setMedia(entity, odata.createFixedFormatDeserializer().binary(request.getBody()),
               requestFormat.toContentTypeString());
     } else {
       throw new ODataApplicationException("Requested Entity is not a media resource.",
-              HttpStatusCode.BAD_REQUEST.getStatusCode(), Locale.ROOT);
+          HttpStatusCode.BAD_REQUEST.getStatusCode(), Locale.ROOT);
     }
 
     final ODataFormat format = ODataFormat.fromContentType(responseFormat);
     ODataSerializer serializer = odata.createSerializer(format);
     response.setContent(serializer.entity(edmEntitySet.getEntityType(), entity,
-            EntitySerializerOptions.with()
-                    .contextURL(format == ODataFormat.JSON_NO_METADATA ? null :
-                            getContextUrl(edmEntitySet, true, null, null))
-                    .build()));
+        EntitySerializerOptions.with()
+            .contextURL(format == ODataFormat.JSON_NO_METADATA ? null :
+                getContextUrl(edmEntitySet, true, null, null))
+            .build()));
     response.setStatusCode(HttpStatusCode.CREATED.getStatusCode());
     response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString());
     response.setHeader(HttpHeader.LOCATION,
-            request.getRawBaseUri() + '/' + odata.createUriHelper().buildCanonicalURL(edmEntitySet,
entity));
+        request.getRawBaseUri() + '/' + odata.createUriHelper().buildCanonicalURL(edmEntitySet,
entity));
   }
 
   @Override
   public void createEntity(final ODataRequest request, ODataResponse response, final UriInfo
uriInfo,
-                           final ContentType requestFormat, final ContentType responseFormat)
-      throws ODataApplicationException, DeserializerException, SerializerException {
-
+      final ContentType requestFormat, final ContentType responseFormat)
+          throws ODataApplicationException, DeserializerException, SerializerException {
     throw new ODataApplicationException("Entity creation is not supported yet.",
-            HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ROOT);
+        HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ROOT);
   }
 
   @Override
-  public void updateEntity(final ODataRequest request, final ODataResponse response,
-                           final UriInfo uriInfo, final ContentType requestFormat,
-                           final ContentType responseFormat)
+  public void updateEntity(final ODataRequest request, final ODataResponse response, final
UriInfo uriInfo,
+      final ContentType requestFormat, final ContentType responseFormat)
           throws ODataApplicationException, DeserializerException, SerializerException {
-    throw new ODataApplicationException("Entity update is not supported yet.",
-            HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ROOT);
+    blockNavigation(uriInfo);
+    final UriResourceEntitySet resourceEntitySet = (UriResourceEntitySet) uriInfo.getUriResourceParts().get(0);
+    final EdmEntitySet edmEntitySet = resourceEntitySet.getEntitySet();
+    Entity entity = dataProvider.read(edmEntitySet, resourceEntitySet.getKeyPredicates());
+    checkEntity(entity);
+    checkRequestFormat(requestFormat);
+    ODataDeserializer deserializer = odata.createDeserializer(ODataFormat.fromContentType(requestFormat));
+    final Entity changedEntity = deserializer.entity(request.getBody(), edmEntitySet.getEntityType());
+    dataProvider.update(edmEntitySet, entity, changedEntity, request.getMethod() == HttpMethod.PATCH);
+    response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
   }
 
   @Override
   public void updateMediaEntity(final ODataRequest request, ODataResponse response, final
UriInfo uriInfo,
-                                final ContentType requestFormat, final ContentType responseFormat)
-      throws ODataApplicationException, DeserializerException, SerializerException {
+      final ContentType requestFormat, final ContentType responseFormat)
+          throws ODataApplicationException, DeserializerException, SerializerException {
     blockNavigation(uriInfo);
     final UriResourceEntitySet resourceEntitySet = (UriResourceEntitySet) uriInfo.getUriResourceParts().get(0);
     final EdmEntitySet edmEntitySet = resourceEntitySet.getEntitySet();
     final Entity entity = dataProvider.read(edmEntitySet, resourceEntitySet.getKeyPredicates());
-    if (entity == null) {
-      throw new ODataApplicationException("Nothing found.", HttpStatusCode.NOT_FOUND.getStatusCode(),
Locale.ROOT);
-    }
-    if (requestFormat == null) {
-      throw new ODataApplicationException("The content type has not been set in the request.",
-          HttpStatusCode.BAD_REQUEST.getStatusCode(), Locale.ROOT);
-    }
+    checkEntity(entity);
+    checkRequestFormat(requestFormat);
     dataProvider.setMedia(entity, odata.createFixedFormatDeserializer().binary(request.getBody()),
         requestFormat.toContentTypeString());
-
-    final ODataFormat format = ODataFormat.fromContentType(responseFormat);
-    ODataSerializer serializer = odata.createSerializer(format);
-    response.setContent(serializer.entity(edmEntitySet.getEntityType(), entity,
-        EntitySerializerOptions.with()
-            .contextURL(format == ODataFormat.JSON_NO_METADATA ? null :
-                getContextUrl(edmEntitySet, true, null, null))
-            .build()));
-    response.setStatusCode(HttpStatusCode.OK.getStatusCode());
-    response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString());
+    response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
   }
 
   @Override
@@ -251,21 +235,17 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
     blockNavigation(uriInfo);
     final UriResourceEntitySet resourceEntitySet = (UriResourceEntitySet) uriInfo.getUriResourceParts().get(0);
     final Entity entity = dataProvider.read(resourceEntitySet.getEntitySet(), resourceEntitySet.getKeyPredicates());
-    if (entity == null) {
-      throw new ODataApplicationException("Nothing found.", HttpStatusCode.NOT_FOUND.getStatusCode(),
Locale.ROOT);
-    } else {
-      dataProvider.delete(resourceEntitySet.getEntitySet(), entity);
-      response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
-    }
+    checkEntity(entity);
+    dataProvider.delete(resourceEntitySet.getEntitySet(), entity);
+    response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
   }
 
   @Override
-  public void processActionEntity(final ODataRequest request, final ODataResponse response,
-                            final UriInfo uriInfo, final ContentType requestFormat,
-                            final ContentType responseFormat)
+  public void processActionEntity(final ODataRequest request, final ODataResponse response,
final UriInfo uriInfo,
+      final ContentType requestFormat, final ContentType responseFormat)
           throws ODataApplicationException, DeserializerException, SerializerException {
     throw new ODataApplicationException("Process entity is not supported yet.",
-            HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ROOT);
+        HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ROOT);
   }
 
   private void blockNavigation(final UriInfo uriInfo) throws ODataApplicationException {
@@ -289,6 +269,19 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
     return entitySet;
   }
 
+  private void checkEntity(final Entity entity) throws ODataApplicationException {
+    if (entity == null) {
+      throw new ODataApplicationException("Nothing found.", HttpStatusCode.NOT_FOUND.getStatusCode(),
Locale.ROOT);
+    }
+  }
+
+  private void checkRequestFormat(final ContentType requestFormat) throws ODataApplicationException
{
+    if (requestFormat == null) {
+      throw new ODataApplicationException("The content type has not been set in the request.",
+          HttpStatusCode.BAD_REQUEST.getStatusCode(), Locale.ROOT);
+    }
+  }
+
   private ContextURL getContextUrl(final EdmEntitySet entitySet, final boolean isSingleEntity,
       final ExpandOption expand, final SelectOption select) throws SerializerException {
     return ContextURL.with().entitySet(entitySet)

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/483b417c/lib/server-test/pom.xml
----------------------------------------------------------------------
diff --git a/lib/server-test/pom.xml b/lib/server-test/pom.xml
index dd986b1..490f511 100644
--- a/lib/server-test/pom.xml
+++ b/lib/server-test/pom.xml
@@ -30,7 +30,7 @@
   <parent>
     <groupId>org.apache.olingo</groupId>
     <artifactId>odata-lib</artifactId>
-    <version>4.0.0-beta-02-RC01</version>
+    <version>4.0.0-beta-03-SNAPSHOT</version>
     <relativePath>..</relativePath>
   </parent>
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/483b417c/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 4fd025a..e12deed 100644
--- a/pom.xml
+++ b/pom.xml
@@ -25,7 +25,7 @@
 
   <groupId>org.apache.olingo</groupId>
   <artifactId>odata-parent</artifactId>
-  <version>4.0.0-beta-02-RC01</version>
+  <version>4.0.0-beta-03-SNAPSHOT</version>
   <packaging>pom</packaging>
 
   <name>Olingo-OData</name>

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/483b417c/samples/client/pom.xml
----------------------------------------------------------------------
diff --git a/samples/client/pom.xml b/samples/client/pom.xml
index 4e5e6e4..eba21d0 100644
--- a/samples/client/pom.xml
+++ b/samples/client/pom.xml
@@ -31,7 +31,7 @@
   <parent>
     <groupId>org.apache.olingo</groupId>
     <artifactId>odata-samples</artifactId>
-    <version>4.0.0-beta-02-RC01</version>
+    <version>4.0.0-beta-03-SNAPSHOT</version>
     <relativePath>..</relativePath>
   </parent>
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/483b417c/samples/pom.xml
----------------------------------------------------------------------
diff --git a/samples/pom.xml b/samples/pom.xml
index fc7f4b6..8166c1d 100644
--- a/samples/pom.xml
+++ b/samples/pom.xml
@@ -31,7 +31,7 @@
   <parent>
     <groupId>org.apache.olingo</groupId>
     <artifactId>odata-parent</artifactId>
-    <version>4.0.0-beta-02-RC01</version>
+    <version>4.0.0-beta-03-SNAPSHOT</version>
     <relativePath>..</relativePath>
   </parent>
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/483b417c/samples/server/pom.xml
----------------------------------------------------------------------
diff --git a/samples/server/pom.xml b/samples/server/pom.xml
index 31ad7a1..900142c 100644
--- a/samples/server/pom.xml
+++ b/samples/server/pom.xml
@@ -30,7 +30,7 @@
   <parent>
     <groupId>org.apache.olingo</groupId>
     <artifactId>odata-samples</artifactId>
-    <version>4.0.0-beta-02-RC01</version>
+    <version>4.0.0-beta-03-SNAPSHOT</version>
     <relativePath>..</relativePath>
   </parent>
 


Mime
View raw message