From c05a742002beefa826c60532c7cb110464ed4f16 Mon Sep 17 00:00:00 2001 From: "Benjamin, Max (mb388a)" Date: Tue, 5 Jan 2021 11:03:15 -0500 Subject: Change to not exception on delete when object Change to not exception on delete when object doesnt exist Added a new deleteIfExist method to the graph client and unit test Issue-ID: SO-3464 Signed-off-by: Benjamin, Max (mb388a) Change-Id: If73721cd83b94bd5a1db1af26aba212b12236fe1 --- .../GraphInventoryResourcesClient.java | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'graph-inventory/aai-client/src/main/java/org') diff --git a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/GraphInventoryResourcesClient.java b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/GraphInventoryResourcesClient.java index 343e888ce1..5dbe91586a 100644 --- a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/GraphInventoryResourcesClient.java +++ b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/GraphInventoryResourcesClient.java @@ -42,9 +42,13 @@ import org.onap.aaiclient.client.graphinventory.entities.uri.HttpAwareUri; import org.onap.aaiclient.client.graphinventory.exceptions.GraphInventoryMultipleItemsException; import org.onap.so.client.RestClient; import org.onap.so.client.RestProperties; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public abstract class GraphInventoryResourcesClient, SingleUri extends GraphInventorySingleResourceUri, PluralUri extends GraphInventoryPluralResourceUri, EdgeLabel extends GraphInventoryEdgeLabel, Wrapper extends GraphInventoryResultWrapper, TransactionalClient, SingleTransactionClient> { + private static final Logger logger = LoggerFactory.getLogger(GraphInventoryResourcesClient.class); + protected GraphInventoryClient client; protected GraphInventoryResourcesClient(GraphInventoryClient client) { @@ -147,6 +151,27 @@ public abstract class GraphInventoryResourcesClient clone = (SingleUri) uri.clone(); + RestClient giRC = client.createClient(clone); + Optional> result = giRC.get(new GenericType>() {}); + if (result.isPresent()) { + String resourceVersion = (String) result.get().get("resource-version"); + giRC = client.createClient(clone.resourceVersion(resourceVersion)); + giRC.delete(); + } else { + logger.warn(clone.build() + " already does not exist in " + client.getGraphDBName() + + " therefore delete call not executed"); + } } /** -- cgit 1.2.3-korg