summaryrefslogtreecommitdiffstats
path: root/graph-inventory
diff options
context:
space:
mode:
Diffstat (limited to 'graph-inventory')
-rw-r--r--graph-inventory/aai-client/pom.xml2
-rw-r--r--graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/GraphInventoryResourcesClient.java25
-rw-r--r--graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAIResourcesClientTest.java21
-rw-r--r--graph-inventory/fluent-builder-maven-plugin/src/main/java/org/onap/graphinventory/generate/SwaggerConverter.java22
4 files changed, 69 insertions, 1 deletions
diff --git a/graph-inventory/aai-client/pom.xml b/graph-inventory/aai-client/pom.xml
index d1c9742cea..d532103c40 100644
--- a/graph-inventory/aai-client/pom.xml
+++ b/graph-inventory/aai-client/pom.xml
@@ -93,7 +93,7 @@
<destination>${project.build.directory}/generated-sources</destination>
<destinationClasspath>org.onap.aaiclient.client.generated.fluentbuilders</destinationClasspath>
<builderName>AAIFluentTypeBuilder</builderName>
- <swaggerLocation>${project.build.directory}/swagger/onap/aai_swagger_yaml/aai_swagger_v21.yaml</swaggerLocation>
+ <swaggerLocation>${project.build.directory}/swagger/onap/aai_swagger_yaml/aai_swagger_LATEST.yaml</swaggerLocation>
<singularBuilderClass>org.onap.aaiclient.client.aai.entities.uri.AAIFluentSingleType</singularBuilderClass>
<pluralBuilderClass>org.onap.aaiclient.client.aai.entities.uri.AAIFluentPluralType</pluralBuilderClass>
<topLevelBuilderClass>org.onap.aaiclient.client.aai.entities.uri.AAIFluentTopLevelType</topLevelBuilderClass>
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");
+ }
}
/**
diff --git a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAIResourcesClientTest.java b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAIResourcesClientTest.java
index 36ba1f3e76..03fd0acd4f 100644
--- a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAIResourcesClientTest.java
+++ b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAIResourcesClientTest.java
@@ -108,6 +108,27 @@ public class AAIResourcesClientTest {
}
@Test
+ public void verifyDeleteIfExists() {
+ AAIResourceUri path = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf("test2"));
+ wireMockRule.stubFor(get(urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build()))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(404)));
+ AAIResourcesClient client = aaiClient;
+ client.deleteIfExists(path);
+ }
+
+ @Test
+ public void verifyDeleteIfExists_exists() {
+ AAIResourceUri path = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf("test2"));
+ wireMockRule.stubFor(get(urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build()))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withBodyFile("aai/resources/mockObject.json").withStatus(200)));
+ wireMockRule.stubFor(delete(urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build()))
+ .withQueryParam("resource-version", equalTo("1234")).willReturn(aResponse().withStatus(204)));
+ AAIResourcesClient client = aaiClient;
+ client.deleteIfExists(path);
+ }
+
+ @Test
public void verifyBasicAuth() {
AAIResourceUri path = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf("test3"));
wireMockRule.stubFor(get(urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build().toString()))
diff --git a/graph-inventory/fluent-builder-maven-plugin/src/main/java/org/onap/graphinventory/generate/SwaggerConverter.java b/graph-inventory/fluent-builder-maven-plugin/src/main/java/org/onap/graphinventory/generate/SwaggerConverter.java
index ec09af8a4e..fc42d9ca0d 100644
--- a/graph-inventory/fluent-builder-maven-plugin/src/main/java/org/onap/graphinventory/generate/SwaggerConverter.java
+++ b/graph-inventory/fluent-builder-maven-plugin/src/main/java/org/onap/graphinventory/generate/SwaggerConverter.java
@@ -1,6 +1,10 @@
package org.onap.graphinventory.generate;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
import java.util.ArrayList;
+import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -26,6 +30,9 @@ public class SwaggerConverter {
}
public Map<String, ObjectType> getDoc(String swaggerLocation) throws JsonProcessingException {
+
+
+ swaggerLocation = processLocation(swaggerLocation);
Swagger swagger = new SwaggerParser().read(swaggerLocation);
Map<String, Path> paths = swagger.getPaths().entrySet().stream()
@@ -168,4 +175,19 @@ public class SwaggerConverter {
return output;
}
+
+ private String processLocation(String swaggerLocation) {
+
+ java.nio.file.Path path = Paths.get(swaggerLocation);
+ try {
+ return Files.list(path.getParent())
+ .filter(it -> it.getFileName().toString()
+ .matches(path.getFileName().toString().replaceFirst("LATEST", "v\\\\\\d+")))
+ .sorted(Comparator.reverseOrder()).map(it -> it.toString()).findFirst().orElseGet(null);
+ } catch (IOException e) {
+ log.error(e);
+ }
+
+ return null;
+ }
}