Return an index of invalid bulk operation if there are missing parameters on request 54/136954/3
authorMichal Jagiello <michal.jagiello@t-mobile.pl>
Tue, 9 Jan 2024 18:28:36 +0000 (19:28 +0100)
committerMichal Jagiello <michal.jagiello@t-mobile.pl>
Wed, 10 Jan 2024 13:07:41 +0000 (14:07 +0100)
Catch AAIException on AAI Bulk poplulateIntrospectors method to prepare an exception body with failing operation number.

Issue-ID: AAI-3722
Change-Id: I38b2e1c802ae7f2843cda5c188365890a86f65af
Signed-off-by: Michal Jagiello <michal.jagiello@t-mobile.pl>
aai-resources/src/main/java/org/onap/aai/rest/bulk/BulkSingleTransactionConsumer.java
aai-resources/src/test/java/org/onap/aai/rest/bulk/BulkSingleTransactionConsumerTest.java
aai-resources/src/test/resources/payloads/bulk/single-transaction/put-complex-with-missing-properties.json [new file with mode: 0644]

index 1b274b9..900da96 100644 (file)
@@ -213,7 +213,7 @@ public class BulkSingleTransactionConsumer extends RESTAPI {
 
     /**
      * Builds the response
-     * 
+     *
      * @param transaction the input transactions
      * @param results the response of all of he operations
      * @return TansactionResponse obj representing the result of the transaction
@@ -242,7 +242,7 @@ public class BulkSingleTransactionConsumer extends RESTAPI {
 
     /**
      * Generate one DBRequest per BulkOperation
-     * 
+     *
      * @param headers request headers
      * @param transId transaction id
      * @param bulkOperations operations to convert
@@ -268,7 +268,7 @@ public class BulkSingleTransactionConsumer extends RESTAPI {
 
     /**
      * Sets the uriquery for each bulk operation
-     * 
+     *
      * @param bulkOperations operations to generate queries for
      * @param dbEngine engine for query builder generation
      * @throws AAIException thrown for issues with generating uri query
@@ -289,7 +289,7 @@ public class BulkSingleTransactionConsumer extends RESTAPI {
 
     /**
      * Sets the introspector for each bulk operation. requires that uriquery is set per operation
-     * 
+     *
      * @param bulkOperations operations to generate introspector for
      * @param loader Loader for generating introspector
      * @throws AAIException thrown for issues with generating introspector
@@ -315,6 +315,8 @@ public class BulkSingleTransactionConsumer extends RESTAPI {
                     }
                     bulkOperation.setIntrospector(obj);
                 }
+            } catch (AAIException e) {
+                throw new AAIException(e.getCode(), "Error with operation " + i + ": " + e.getMessage());
             } catch (UnsupportedEncodingException e) {
                 throw new AAIException("AAI_3000", String.format(objectUnMarshallMsg, i, bulkOperation.getRawReq()));
             }
@@ -327,7 +329,7 @@ public class BulkSingleTransactionConsumer extends RESTAPI {
      * - Integer.MAX_VALUE if override limit is configured
      * - Property in aaiconfig
      * - 30 by default
-     * 
+     *
      * @param headers request header
      */
     private void setOperationCount(HttpHeaders headers) {
@@ -348,7 +350,7 @@ public class BulkSingleTransactionConsumer extends RESTAPI {
 
     /**
      * Converts the request transaction into a list of bulk operations
-     * 
+     *
      * @param transaction transaction to extract bulk operations from
      * @return list of bulk operations
      */
@@ -381,7 +383,7 @@ public class BulkSingleTransactionConsumer extends RESTAPI {
 
     /**
      * Map action to httpmethod
-     * 
+     *
      * @param action action to be mapped
      * @param uri uri of the action
      * @return HttpMethod thats action/uri maps to
@@ -415,7 +417,7 @@ public class BulkSingleTransactionConsumer extends RESTAPI {
      * - action is provided and correct.
      * - uri exists
      * - body exists
-     * 
+     *
      * @param transaction parsed payload
      * @throws AAIException with the violations in the msg
      */
index 7629178..fb9f13f 100644 (file)
@@ -354,6 +354,19 @@ public class BulkSingleTransactionConsumerTest extends BulkProcessorTestAbstract
         assertEquals("Request success", Response.Status.CREATED.getStatusCode(), response.getStatus());
     }
 
+    @Test
+    public void invalidNodeCreationPaylodTest() throws IOException {
+        String payload = getBulkPayload("single-transaction/put-complex-with-missing-properties")
+                .replaceAll("<methodName>", name.getMethodName());
+        Response response = executeRequest(payload);
+
+        assertEquals("Request fails with 400", Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());
+        assertThat("Response contains correct index of failed operation.", response.getEntity().toString(),
+                containsString("Error with operation 0"));
+        assertThat("Response contains information about missing properties.", response.getEntity().toString(),
+                containsString("Missing required property:"));
+    }
+
     protected Response executeRequest(String finalPayload) {
         MockHttpServletRequest mockReq = new MockHttpServletRequest(HttpMethod.POST, "http://www.test.com");
 
diff --git a/aai-resources/src/test/resources/payloads/bulk/single-transaction/put-complex-with-missing-properties.json b/aai-resources/src/test/resources/payloads/bulk/single-transaction/put-complex-with-missing-properties.json
new file mode 100644 (file)
index 0000000..b371583
--- /dev/null
@@ -0,0 +1,9 @@
+{
+    "operations": [
+        {
+            "action": "put",
+            "uri": "cloud-infrastructure/complexes/complex/complex-<methodName>",
+            "body": {}
+        }
+    ]
+}
\ No newline at end of file