summaryrefslogtreecommitdiffstats
path: root/graph-inventory/aai-client/src/main/java/org
diff options
context:
space:
mode:
authorSteve Smokowski <ss835w@att.com>2021-01-05 19:22:41 +0000
committerGerrit Code Review <gerrit@onap.org>2021-01-05 19:22:41 +0000
commit1514e6f8fd5aec7f0929b1d4af64fbaeb5738e49 (patch)
tree4cfc68fc8673adec719b93f4d00c23cd90407666 /graph-inventory/aai-client/src/main/java/org
parent88f5917edae8c50ddfbe9b0538c2e33502bf50a3 (diff)
parentc05a742002beefa826c60532c7cb110464ed4f16 (diff)
Merge "Change to not exception on delete when object"
Diffstat (limited to 'graph-inventory/aai-client/src/main/java/org')
-rw-r--r--graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/GraphInventoryResourcesClient.java25
1 files changed, 25 insertions, 0 deletions
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<Self, Uri extends GraphInventoryResourceUri<?, ?>, 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<Self, Uri extends GraphInven
String resourceVersion = (String) result.get("resource-version");
giRC = client.createClient(clone.resourceVersion(resourceVersion));
giRC.delete();
+
+ }
+
+ /**
+ * Deletes object from GraphInventory only if exists. Automatically handles resource-version.
+ *
+ * @param uri
+ * @return
+ */
+ public void deleteIfExists(SingleUri uri) {
+ GraphInventorySingleResourceUri<?, ?, ?, ?, ?, ?> clone = (SingleUri) uri.clone();
+ RestClient giRC = client.createClient(clone);
+ Optional<Map<String, Object>> result = giRC.get(new GenericType<Map<String, Object>>() {});
+ 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");
+ }
}
/**