From 4cd8072f009e5a9820f281ce31a1444a52246e78 Mon Sep 17 00:00:00 2001 From: "Benjamin, Max (mb388a)" Date: Fri, 10 Aug 2018 17:32:29 -0400 Subject: added edge label support to A&AI client you can now specify an edge label when connecting two objects Issue-ID: SO-849 Change-Id: I851d523c271823911cdc344ac8c28beec993cb09 Signed-off-by: Benjamin, Max (mb388a) --- .../org/onap/so/client/aai/AAIResourcesClient.java | 26 ++++++++++++++++++++++ .../onap/so/client/aai/entities/AAIEdgeLabel.java | 21 +++++++++++++++++ .../entities/GraphInventoryEdgeLabel.java | 8 +++++++ 3 files changed, 55 insertions(+) create mode 100644 common/src/main/java/org/onap/so/client/aai/entities/AAIEdgeLabel.java create mode 100644 common/src/main/java/org/onap/so/client/graphinventory/entities/GraphInventoryEdgeLabel.java (limited to 'common/src/main') diff --git a/common/src/main/java/org/onap/so/client/aai/AAIResourcesClient.java b/common/src/main/java/org/onap/so/client/aai/AAIResourcesClient.java index 04757c6fc2..96cc397e13 100644 --- a/common/src/main/java/org/onap/so/client/aai/AAIResourcesClient.java +++ b/common/src/main/java/org/onap/so/client/aai/AAIResourcesClient.java @@ -32,6 +32,7 @@ import javax.ws.rs.core.Response.Status; import org.onap.aai.domain.yang.Relationship; import org.onap.so.client.RestClient; import org.onap.so.client.RestProperties; +import org.onap.so.client.aai.entities.AAIEdgeLabel; import org.onap.so.client.aai.entities.AAIResultWrapper; import org.onap.so.client.aai.entities.uri.AAIResourceUri; import org.onap.so.client.aai.entities.uri.AAIUri; @@ -99,6 +100,21 @@ public class AAIResourcesClient extends AAIClient { return; } + /** + * Adds a relationship between two objects in A&AI + * with a given edge label + * @param uriA + * @param uriB + * @param edge label + * @return + */ + public void connect(AAIResourceUri uriA, AAIResourceUri uriB, AAIEdgeLabel label) { + AAIResourceUri uriAClone = uriA.clone(); + RestClient aaiRC = this.createClient(uriAClone.relationshipAPI()); + aaiRC.put(this.buildRelationship(uriB, label)); + return; + } + /** * Removes relationship from two objects in A&AI * @@ -203,8 +219,18 @@ public class AAIResourcesClient extends AAIClient { } private Relationship buildRelationship(AAIResourceUri uri) { + return buildRelationship(uri, Optional.empty()); + } + + private Relationship buildRelationship(AAIResourceUri uri, AAIEdgeLabel label) { + return buildRelationship(uri, Optional.of(label)); + } + private Relationship buildRelationship(AAIResourceUri uri, Optional label) { final Relationship result = new Relationship(); result.setRelatedLink(uri.build().toString()); + if (label.isPresent()) { + result.setRelationshipLabel(label.toString()); + } return result; } diff --git a/common/src/main/java/org/onap/so/client/aai/entities/AAIEdgeLabel.java b/common/src/main/java/org/onap/so/client/aai/entities/AAIEdgeLabel.java new file mode 100644 index 0000000000..0356e86861 --- /dev/null +++ b/common/src/main/java/org/onap/so/client/aai/entities/AAIEdgeLabel.java @@ -0,0 +1,21 @@ +package org.onap.so.client.aai.entities; + +import org.onap.so.client.graphinventory.entities.GraphInventoryEdgeLabel; + +public enum AAIEdgeLabel implements GraphInventoryEdgeLabel { + + BELONGS_TO("org.onap.relationships.inventory.BelongsTo"), + USES("org.onap.relationships.inventory.Uses"); + + + private final String label; + private AAIEdgeLabel(String label) { + this.label = label; + } + + + @Override + public String toString() { + return this.label; + } +} diff --git a/common/src/main/java/org/onap/so/client/graphinventory/entities/GraphInventoryEdgeLabel.java b/common/src/main/java/org/onap/so/client/graphinventory/entities/GraphInventoryEdgeLabel.java new file mode 100644 index 0000000000..1ede2f9e1b --- /dev/null +++ b/common/src/main/java/org/onap/so/client/graphinventory/entities/GraphInventoryEdgeLabel.java @@ -0,0 +1,8 @@ +package org.onap.so.client.graphinventory.entities; + +public interface GraphInventoryEdgeLabel { + + + @Override + public String toString(); +} -- cgit 1.2.3-korg