Allow patch operation in bulk request 69/28069/1
authorsblimkie <steven.blimkie@amdocs.com>
Fri, 12 Jan 2018 19:50:36 +0000 (14:50 -0500)
committersblimkie <steven.blimkie@amdocs.com>
Fri, 12 Jan 2018 19:52:01 +0000 (14:52 -0500)
Support the patch operation in a bulk request.

Change-Id: I10054f60315632812bed18997272a5c9728a3f67
Issue-ID: AAI-482
Signed-off-by: sblimkie <steven.blimkie@amdocs.com>
BULK.md
src/main/java/org/onap/crud/service/AbstractGraphDataService.java
src/main/java/org/onap/crud/service/CrudRestService.java

diff --git a/BULK.md b/BULK.md
index f5dc68c..ba94846 100644 (file)
--- a/BULK.md
+++ b/BULK.md
@@ -1,8 +1,8 @@
 ## Bulk API
 
-The bulk API allows a client to add/update/delete mutliple verticies and/or edges within a single request.  This request will be treated as an atomic transaction in that all operations within the bulk request will either fail or succeed together.
+The bulk API allows a client to add/modify/patch/delete multiple vertexes and/or edges within a single request.  This request will be treated as an atomic transaction in that all operations within the bulk request will either fail or succeed together.
 
-This is often useful when attempting to add an entire subgraph.  The following example shows how a client could create 2 verticies (pserver and vserver) and link them with an edge.
+This is often useful when attempting to add an entire subgraph.  The following example shows how a client could create 2 vertexes (pserver and vserver) and link them with an edge.
 
        URL: https://<host>:9520/services/inventory/v11/bulk
        Method: POST
index 654ebfb..60241cc 100644 (file)
@@ -155,6 +155,23 @@ public abstract class AbstractGraphDataService {
           Vertex outgoingVertex = OxmModelValidator.validateOutgoingPayload(version, persistedVertex);
           vertices.put(item.getKey(), outgoingVertex);
         }
+        
+        // Patch vertex 
+        else if (opr.getValue().getAsString().equalsIgnoreCase("patch")) {
+          if ( (vertexPayload.getId() == null) || (vertexPayload.getType() == null) ) {
+            throw new CrudException("id and type must be specified for patch request", Status.BAD_REQUEST);
+          }
+          
+          vertexPayload.setProperties(CrudServiceUtil.mergeHeaderInFoToPayload(vertexPayload.getProperties(), 
+              headers, false));
+          
+          Vertex existingVertex = dao.getVertex(vertexPayload.getId(), OxmModelValidator.resolveCollectionType(version, vertexPayload.getType()));
+          Vertex validatedVertex = OxmModelValidator.validateIncomingPatchPayload(vertexPayload.getId(), 
+              version, vertexPayload.getType(), vertexPayload.getProperties(), existingVertex);
+          Vertex persistedVertex = updateBulkVertex(validatedVertex, vertexPayload.getId(), version, txId);
+          Vertex outgoingVertex = OxmModelValidator.validateOutgoingPayload(version, persistedVertex);
+          vertices.put(item.getKey(), outgoingVertex);
+        }
       }
 
       // Step 4: Handle edge add/modify 
@@ -171,7 +188,8 @@ public abstract class AbstractGraphDataService {
 
         // Add/Update edge
         if (opr.getValue().getAsString().equalsIgnoreCase("add")
-            || opr.getValue().getAsString().equalsIgnoreCase("modify")) {
+            || opr.getValue().getAsString().equalsIgnoreCase("modify") 
+            || opr.getValue().getAsString().equalsIgnoreCase("patch")) {
           Edge validatedEdge;
           Edge persistedEdge;
           if (opr.getValue().getAsString().equalsIgnoreCase("add")) {
@@ -197,11 +215,19 @@ public abstract class AbstractGraphDataService {
             validatedEdge = RelationshipSchemaValidator.validateIncomingAddPayload(version, edgePayload.getType(),
                 edgePayload);
             persistedEdge = addBulkEdge(validatedEdge, version, txId);
-          } else {
+          } else if (opr.getValue().getAsString().equalsIgnoreCase("modify")) {
             Edge edge = dao.getEdge(edgePayload.getId(), edgePayload.getType(), txId);
             validatedEdge = RelationshipSchemaValidator.validateIncomingUpdatePayload(edge, version, edgePayload);
             persistedEdge = updateBulkEdge(validatedEdge, version, txId);
+          } else {
+            if ( (edgePayload.getId() == null) || (edgePayload.getType() == null) ) {
+              throw new CrudException("id and type must be specified for patch request", Status.BAD_REQUEST);
+            }
+            Edge existingEdge = dao.getEdge(edgePayload.getId(), edgePayload.getType(), txId);
+            Edge patchedEdge = RelationshipSchemaValidator.validateIncomingPatchPayload(existingEdge, version, edgePayload);
+            persistedEdge = updateBulkEdge(patchedEdge, version, txId);
           }
+          
 
           Edge outgoingEdge = RelationshipSchemaValidator.validateOutgoingPayload(version, persistedEdge);
           edges.put(item.getKey(), outgoingEdge);
index d00323e..0ea07f0 100644 (file)
@@ -451,11 +451,13 @@ public class CrudRestService {
 
       if (!opr.getValue().getAsString().equalsIgnoreCase("add")
           && !opr.getValue().getAsString().equalsIgnoreCase("modify")
+          && !opr.getValue().getAsString().equalsIgnoreCase("patch")
           && !opr.getValue().getAsString().equalsIgnoreCase("delete")) {
         throw new CrudException("Invalid operation at item: " + item.getKey(), Status.BAD_REQUEST);
       }
-      // check if ID is populate for modify/delete operation
+      // check if ID is populate for modify/patch/delete operation
       if ((opr.getValue().getAsString().equalsIgnoreCase("modify")
+          || opr.getValue().getAsString().equalsIgnoreCase("patch")
           || opr.getValue().getAsString().equalsIgnoreCase("delete")) && (vertexPayload.getId() == null)) {
 
         throw new CrudException("Mising ID at item: " + item.getKey(), Status.BAD_REQUEST);
@@ -491,11 +493,13 @@ public class CrudRestService {
 
       if (!opr.getValue().getAsString().equalsIgnoreCase("add")
           && !opr.getValue().getAsString().equalsIgnoreCase("modify")
+          && !opr.getValue().getAsString().equalsIgnoreCase("patch")
           && !opr.getValue().getAsString().equalsIgnoreCase("delete")) {
         throw new CrudException("Invalid operation at item: " + item.getKey(), Status.BAD_REQUEST);
       }
-      // check if ID is populate for modify/delete operation
+      // check if ID is populate for modify/patch/delete operation
       if ((edgePayload.getId() == null) && (opr.getValue().getAsString().equalsIgnoreCase("modify")
+          || opr.getValue().getAsString().equalsIgnoreCase("patch") 
           || opr.getValue().getAsString().equalsIgnoreCase("delete"))) {
 
         throw new CrudException("Mising ID at item: " + item.getKey(), Status.BAD_REQUEST);