[OLINGO-545] TecSvc: Allow upserts

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

Branch: refs/heads/OLINGO-573
Commit: 62214d2d87ca4bcdb5505d71a243527315a25380
Parents: d692d12
Author: Christian Holzer <[email protected]>
Authored: Tue Apr 7 12:14:38 2015 +0200
Committer: Christian Holzer <[email protected]>
Committed: Tue Apr 7 15:27:16 2015 +0200

----------------------------------------------------------------------
 .../processor/TechnicalEntityProcessor.java     | 21 ++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/62214d2d/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 01f2c90..623d22d 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
@@ -117,9 +117,10 @@ public class TechnicalEntityProcessor extends 
TechnicalProcessor
       ODataSerializer serializer = odata.createSerializer(format);
       final ExpandOption expand = uriInfo.getExpandOption();
       final SelectOption select = uriInfo.getSelectOption();
-
-      // Create a shallow copy of each entity. So the expanded navigation 
properties can be modified for serialization,
-      // without affecting the data stored in the database.
+      
+      // Transform the entity graph to a tree. The construction is controlled 
by the expand tree.
+      // Apply all expand system query options to the tree.So the expanded 
navigation properties can be modified 
+      // for serialization,without affecting the data stored in the database.
       final ExpandSystemQueryOptionHandler expandHandler = new 
ExpandSystemQueryOptionHandler();
       final EntityCollection entitySetSerialization = 
expandHandler.transformEntitySetGraphToTree(entitySet, 
                                                                                
            edmEntitySet, 
@@ -270,7 +271,19 @@ public class TechnicalEntityProcessor extends 
TechnicalProcessor
       final ContentType requestFormat, final ContentType responseFormat)
       throws ODataApplicationException, DeserializerException, 
SerializerException {
     final EdmEntitySet edmEntitySet = getEdmEntitySet(uriInfo);
-    Entity entity = readEntity(uriInfo);
+    Entity entity;
+    
+    try {
+      entity = readEntity(uriInfo);
+    } catch(ODataApplicationException e) {
+      if(e.getStatusCode() == HttpStatusCode.NOT_FOUND.getStatusCode()) {
+        // Perform upsert
+        createEntity(request, response, uriInfo, requestFormat, 
responseFormat);
+        return;
+      } else {
+        throw e;
+      }
+    }
     checkRequestFormat(requestFormat);
     final ODataDeserializer deserializer = 
odata.createDeserializer(ODataFormat.fromContentType(requestFormat));
     final Entity changedEntity = deserializer.entity(request.getBody(), 
edmEntitySet.getEntityType()).getEntity();

Reply via email to