do not attempt to commit empty transactions 90/79190/1
authorBenjamin, Max (mb388a) <mb388a@us.att.com>
Tue, 26 Feb 2019 14:51:06 +0000 (09:51 -0500)
committerBenjamin, Max (mb388a) <mb388a@us.att.com>
Tue, 26 Feb 2019 14:51:21 +0000 (09:51 -0500)
do not attempt to commit empty transactions

Change-Id: I0db4f87449e7362dbbc2dc6ccfffca9f75c077eb
Issue-ID: SO-1569
Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
common/src/main/java/org/onap/so/client/aai/AAISingleTransactionClient.java
common/src/main/java/org/onap/so/client/aai/AAITransactionalClient.java
common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryTransactionClient.java

index ee15e10..fecbf59 100644 (file)
@@ -60,16 +60,18 @@ public class AAISingleTransactionClient extends GraphInventoryTransactionClient<
         */
        @Override
        public void execute() throws BulkProcessFailed {
-               RestClient client = aaiClient.createClient(AAIUriFactory.createResourceUri(AAIObjectType.SINGLE_TRANSACTION));
                try {
-                       SingleTransactionResponse response = client.post(this.request, SingleTransactionResponse.class);
-                       if (response != null) {
-                               final Optional<String> errorMessage = this.locateErrorMessages(response);
-                               if (errorMessage.isPresent()) {
-                                       throw new BulkProcessFailed("One or more transactions failed in A&AI. Check logs for payloads.\nMessages:\n" + errorMessage.get());
+                       if (!this.request.getOperations().isEmpty()) {
+                               RestClient client = aaiClient.createClient(AAIUriFactory.createResourceUri(AAIObjectType.SINGLE_TRANSACTION));
+                               SingleTransactionResponse response = client.post(this.request, SingleTransactionResponse.class);
+                               if (response != null) {
+                                       final Optional<String> errorMessage = this.locateErrorMessages(response);
+                                       if (errorMessage.isPresent()) {
+                                               throw new BulkProcessFailed("One or more transactions failed in A&AI. Check logs for payloads.\nMessages:\n" + errorMessage.get());
+                                       }
+                               } else {
+                                       throw new BulkProcessFailed("Transactions acccepted by A&AI, but there was no response. Unsure of result.");
                                }
-                       } else {
-                               throw new BulkProcessFailed("Transactions acccepted by A&AI, but there was no response. Unsure of result.");
                        }
                } finally {
                        this.request.getOperations().clear();
index 474ae89..9fb6cd7 100644 (file)
@@ -82,16 +82,18 @@ public class AAITransactionalClient extends GraphInventoryTransactionClient<AAIT
         */
        @Override
        public void execute() throws BulkProcessFailed {
-               RestClient client = aaiClient.createClient(AAIUriFactory.createResourceUri(AAIObjectType.BULK_PROCESS));
                try {
-                       Response response = client.put(this.transactions);
-                       if (response.hasEntity()) {
-                               final Optional<String> errorMessage = this.locateErrorMessages(response.readEntity(String.class));
-                               if (errorMessage.isPresent()) {
-                                       throw new BulkProcessFailed("One or more transactions failed in A&AI. Check logs for payloads.\nMessages:\n" + errorMessage.get());
+                       if (!this.transactions.getTransactions().isEmpty()) {
+                               RestClient client = aaiClient.createClient(AAIUriFactory.createResourceUri(AAIObjectType.BULK_PROCESS));
+                               Response response = client.put(this.transactions);
+                               if (response.hasEntity()) {
+                                       final Optional<String> errorMessage = this.locateErrorMessages(response.readEntity(String.class));
+                                       if (errorMessage.isPresent()) {
+                                               throw new BulkProcessFailed("One or more transactions failed in A&AI. Check logs for payloads.\nMessages:\n" + errorMessage.get());
+                                       }
+                               } else {
+                                       throw new BulkProcessFailed("Transactions acccepted by A&AI, but there was no response. Unsure of result.");
                                }
-                       } else {
-                               throw new BulkProcessFailed("Transactions acccepted by A&AI, but there was no response. Unsure of result.");
                        }
                } finally {
                        this.transactions.getTransactions().clear();
index 8d1a945..4c228b2 100644 (file)
@@ -84,10 +84,8 @@ public abstract class GraphInventoryTransactionClient<Self, Uri extends GraphInv
                if(!this.exists(uri)){
                        if (obj.isPresent()) {
                                this.create(uri, obj.get());
-                               incrementActionAmount();
                        } else {
                                this.createEmpty(uri);
-                               incrementActionAmount();
                        }
                        
                }
@@ -194,7 +192,7 @@ public abstract class GraphInventoryTransactionClient<Self, Uri extends GraphInv
        protected abstract boolean exists(Uri uri);
        
        protected abstract String getGraphDBName();
-
+       
        /**
         * @param obj - can be any object which will marshal into a valid A&AI payload
         * @param uri