From f687d9f4ae7500556d78fff1b5dd461412440e01 Mon Sep 17 00:00:00 2001 From: "Benjamin, Max" Date: Thu, 10 Sep 2020 11:15:57 -0400 Subject: added fragment support to generated objects added fragment support to generated objects updated objects to support singular and plural fragments Issue-ID: SO-3240 Signed-off-by: Benjamin, Max (mb388a) Change-Id: Ia010c99ad36422db5f5b3729af3991767fe5138f --- graph-inventory/aai-client/pom.xml | 2 ++ .../client/aai/entities/uri/AAIPluralFragment.java | 20 ++++++++++++++++++++ .../client/aai/entities/uri/AAIResourceUri.java | 2 +- .../client/aai/entities/uri/AAISimpleUri.java | 15 ++++++++++++++- .../client/aai/entities/uri/AAISingleFragment.java | 19 +++++++++++++++++++ .../GraphInventoryFluentTypeBase.java | 17 +++++++++++++---- .../graphinventory/GraphInventoryFragmentBase.java | 6 ++++++ .../GraphInventoryPluralFragment.java | 9 +++++++++ .../GraphInventoryResourcesClient.java | 14 +++++++------- .../GraphInventorySingleFragment.java | 7 +++++++ .../GraphInventoryTransactionClient.java | 2 +- .../entities/GraphInventoryRelationships.java | 2 +- .../uri/GraphInventorySingleResourceUri.java | 8 +++++++- .../graphinventory/entities/uri/SimpleBaseUri.java | 2 +- .../entities/uri/SimplePluralUri.java | 2 +- .../graphinventory/entities/uri/SimpleUri.java | 6 ++++-- .../client/aai/entities/uri/AAISimpleUriTest.java | 22 ++++++++++++++++++++-- 17 files changed, 133 insertions(+), 22 deletions(-) create mode 100644 graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/entities/uri/AAIPluralFragment.java create mode 100644 graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/entities/uri/AAISingleFragment.java create mode 100644 graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/GraphInventoryFragmentBase.java create mode 100644 graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/GraphInventoryPluralFragment.java create mode 100644 graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/GraphInventorySingleFragment.java (limited to 'graph-inventory/aai-client') diff --git a/graph-inventory/aai-client/pom.xml b/graph-inventory/aai-client/pom.xml index dc9bf47070..d95ef8d1c0 100644 --- a/graph-inventory/aai-client/pom.xml +++ b/graph-inventory/aai-client/pom.xml @@ -101,6 +101,8 @@ org.onap.aaiclient.client.aai.AAIObjectType org.onap.aaiclient.client.aai.AAIObjectPlurals org.onap.aaiclient.client.aai.AAIObjectName + org.onap.aaiclient.client.aai.entities.uri.AAISingleFragment + org.onap.aaiclient.client.aai.entities.uri.AAIPluralFragment diff --git a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/entities/uri/AAIPluralFragment.java b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/entities/uri/AAIPluralFragment.java new file mode 100644 index 0000000000..4733c55bf8 --- /dev/null +++ b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/entities/uri/AAIPluralFragment.java @@ -0,0 +1,20 @@ +package org.onap.aaiclient.client.aai.entities.uri; + +import java.io.Serializable; +import org.onap.aaiclient.client.graphinventory.GraphInventoryPluralFragment; + +public class AAIPluralFragment implements Serializable, GraphInventoryPluralFragment { + + private static final long serialVersionUID = 1L; + + private final AAIFluentPluralType type; + + public AAIPluralFragment(AAIFluentPluralType type) { + this.type = type; + } + + public AAIFluentPluralType get() { + return type; + } + +} diff --git a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/entities/uri/AAIResourceUri.java b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/entities/uri/AAIResourceUri.java index 3d01258f71..3d7fc0e198 100644 --- a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/entities/uri/AAIResourceUri.java +++ b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/entities/uri/AAIResourceUri.java @@ -5,6 +5,6 @@ import org.onap.aaiclient.client.aai.AAIObjectType; import org.onap.aaiclient.client.graphinventory.entities.uri.GraphInventorySingleResourceUri; public interface AAIResourceUri extends AAIBaseResourceUri, - GraphInventorySingleResourceUri { + GraphInventorySingleResourceUri { } diff --git a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/entities/uri/AAISimpleUri.java b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/entities/uri/AAISimpleUri.java index 40184b028b..041c02ff2d 100644 --- a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/entities/uri/AAISimpleUri.java +++ b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/entities/uri/AAISimpleUri.java @@ -26,7 +26,8 @@ import org.onap.aaiclient.client.aai.AAIObjectPlurals; import org.onap.aaiclient.client.aai.AAIObjectType; import org.onap.aaiclient.client.graphinventory.entities.uri.SimpleUri; -public class AAISimpleUri extends SimpleUri +public class AAISimpleUri extends + SimpleUri implements AAIResourceUri { private static final long serialVersionUID = -6397024057188453229L; @@ -70,4 +71,16 @@ public class AAISimpleUri extends SimpleUri { + + private static final long serialVersionUID = 1L; + + private final AAIFluentSingleType type; + + public AAISingleFragment(AAIFluentSingleType type) { + this.type = type; + } + + public AAIFluentSingleType get() { + return type; + } +} diff --git a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/GraphInventoryFluentTypeBase.java b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/GraphInventoryFluentTypeBase.java index 1a258fcd88..3970a36a0b 100644 --- a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/GraphInventoryFluentTypeBase.java +++ b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/GraphInventoryFluentTypeBase.java @@ -1,16 +1,25 @@ package org.onap.aaiclient.client.graphinventory; +import java.util.Collections; import java.util.List; public interface GraphInventoryFluentTypeBase { public interface Info { - String getPartialUri(); + default String getPartialUri() { + return ""; + } - List getPaths(); + default List getPaths() { + return Collections.emptyList(); + } } - Object[] values(); + default Object[] values() { + return new Object[] {}; + } - String uriTemplate(); + default String uriTemplate() { + return ""; + } } diff --git a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/GraphInventoryFragmentBase.java b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/GraphInventoryFragmentBase.java new file mode 100644 index 0000000000..b8cb64de30 --- /dev/null +++ b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/GraphInventoryFragmentBase.java @@ -0,0 +1,6 @@ +package org.onap.aaiclient.client.graphinventory; + +public interface GraphInventoryFragmentBase { + + T get(); +} diff --git a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/GraphInventoryPluralFragment.java b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/GraphInventoryPluralFragment.java new file mode 100644 index 0000000000..9fe3cda384 --- /dev/null +++ b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/GraphInventoryPluralFragment.java @@ -0,0 +1,9 @@ +package org.onap.aaiclient.client.graphinventory; + + + +public interface GraphInventoryPluralFragment> + extends GraphInventoryFragmentBase { + + +} 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 c564c5d5cb..343e888ce1 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 @@ -33,8 +33,6 @@ import javax.ws.rs.core.GenericType; import javax.ws.rs.core.Response; 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.aaiclient.client.graphinventory.entities.GraphInventoryEdgeLabel; import org.onap.aaiclient.client.graphinventory.entities.GraphInventoryResultWrapper; import org.onap.aaiclient.client.graphinventory.entities.uri.GraphInventoryPluralResourceUri; @@ -42,8 +40,10 @@ import org.onap.aaiclient.client.graphinventory.entities.uri.GraphInventoryResou import org.onap.aaiclient.client.graphinventory.entities.uri.GraphInventorySingleResourceUri; 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; -public abstract class GraphInventoryResourcesClient, SingleUri extends GraphInventorySingleResourceUri, PluralUri extends GraphInventoryPluralResourceUri, EdgeLabel extends GraphInventoryEdgeLabel, Wrapper extends GraphInventoryResultWrapper, TransactionalClient, SingleTransactionClient> { +public abstract class GraphInventoryResourcesClient, SingleUri extends GraphInventorySingleResourceUri, PluralUri extends GraphInventoryPluralResourceUri, EdgeLabel extends GraphInventoryEdgeLabel, Wrapper extends GraphInventoryResultWrapper, TransactionalClient, SingleTransactionClient> { protected GraphInventoryClient client; @@ -101,7 +101,7 @@ public abstract class GraphInventoryResourcesClient uriAClone = (SingleUri) uriA.clone(); + GraphInventorySingleResourceUri uriAClone = (SingleUri) uriA.clone(); RestClient giRC = client.createClient(uriAClone.relationshipAPI()); giRC.put(this.buildRelationship(uriB)); } @@ -115,7 +115,7 @@ public abstract class GraphInventoryResourcesClient uriAClone = (SingleUri) uriA.clone(); + GraphInventorySingleResourceUri uriAClone = (SingleUri) uriA.clone(); RestClient giRC = client.createClient(uriAClone.relationshipAPI()); giRC.put(this.buildRelationship(uriB, label)); } @@ -128,7 +128,7 @@ public abstract class GraphInventoryResourcesClient uriAClone = (SingleUri) uriA.clone(); + GraphInventorySingleResourceUri uriAClone = (SingleUri) uriA.clone(); RestClient giRC = client.createClient(uriAClone.relationshipAPI()); giRC.delete(this.buildRelationship(uriB)); } @@ -140,7 +140,7 @@ public abstract class GraphInventoryResourcesClient clone = (SingleUri) uri.clone(); + GraphInventorySingleResourceUri clone = (SingleUri) uri.clone(); RestClient giRC = client.createClient(clone); Map result = giRC.get(new GenericType>() {}).orElseThrow( () -> new NotFoundException(clone.build() + " does not exist in " + client.getGraphDBName())); diff --git a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/GraphInventorySingleFragment.java b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/GraphInventorySingleFragment.java new file mode 100644 index 0000000000..711b93d5b8 --- /dev/null +++ b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/GraphInventorySingleFragment.java @@ -0,0 +1,7 @@ +package org.onap.aaiclient.client.graphinventory; + +public interface GraphInventorySingleFragment> + extends GraphInventoryFragmentBase { + + +} diff --git a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/GraphInventoryTransactionClient.java b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/GraphInventoryTransactionClient.java index 7f7822b900..4390e7e6bc 100644 --- a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/GraphInventoryTransactionClient.java +++ b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/GraphInventoryTransactionClient.java @@ -34,7 +34,7 @@ import org.onap.aaiclient.client.graphinventory.exceptions.BulkProcessFailed; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public abstract class GraphInventoryTransactionClient, SingleUri extends GraphInventorySingleResourceUri, EdgeLabel extends GraphInventoryEdgeLabel> { +public abstract class GraphInventoryTransactionClient, SingleUri extends GraphInventorySingleResourceUri, EdgeLabel extends GraphInventoryEdgeLabel> { protected static Logger logger = LoggerFactory.getLogger(GraphInventoryTransactionClient.class); diff --git a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/entities/GraphInventoryRelationships.java b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/entities/GraphInventoryRelationships.java index 881b7e9a8e..cc286a6a6b 100644 --- a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/entities/GraphInventoryRelationships.java +++ b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/entities/GraphInventoryRelationships.java @@ -36,7 +36,7 @@ import org.onap.so.jsonpath.JsonPathUtil; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; -public abstract class GraphInventoryRelationships, Uri extends GraphInventorySingleResourceUri, Type extends GraphInventoryObjectType> { +public abstract class GraphInventoryRelationships, Uri extends GraphInventorySingleResourceUri, Type extends GraphInventoryObjectType> { protected final ObjectMapper mapper; protected Map map; diff --git a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/entities/uri/GraphInventorySingleResourceUri.java b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/entities/uri/GraphInventorySingleResourceUri.java index ac0e4a0c94..fbd4130fb0 100644 --- a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/entities/uri/GraphInventorySingleResourceUri.java +++ b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/entities/uri/GraphInventorySingleResourceUri.java @@ -2,8 +2,10 @@ package org.onap.aaiclient.client.graphinventory.entities.uri; import org.onap.aaiclient.client.graphinventory.GraphInventoryObjectPlurals; import org.onap.aaiclient.client.graphinventory.GraphInventoryObjectType; +import org.onap.aaiclient.client.graphinventory.GraphInventoryPluralFragment; +import org.onap.aaiclient.client.graphinventory.GraphInventorySingleFragment; -public interface GraphInventorySingleResourceUri, P extends GraphInventoryPluralResourceUri, SingleObject extends GraphInventoryObjectType, PluralObject extends GraphInventoryObjectPlurals> +public interface GraphInventorySingleResourceUri, P extends GraphInventoryPluralResourceUri, SingleObject extends GraphInventoryObjectType, PluralObject extends GraphInventoryObjectPlurals, SingleFragment extends GraphInventorySingleFragment, PluralFragment extends GraphInventoryPluralFragment> extends GraphInventoryResourceUri { public T resourceVersion(String version); @@ -13,4 +15,8 @@ public interface GraphInventorySingleResourceUri, Parent extends GraphInventorySingleResourceUri, S extends GraphInventoryObjectBase> +public abstract class SimpleBaseUri, Parent extends GraphInventorySingleResourceUri, S extends GraphInventoryObjectBase> implements GraphInventoryResourceUri { private static final long serialVersionUID = -1011069933894179423L; diff --git a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/entities/uri/SimplePluralUri.java b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/entities/uri/SimplePluralUri.java index d76661526c..1a3b38aff5 100644 --- a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/entities/uri/SimplePluralUri.java +++ b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/entities/uri/SimplePluralUri.java @@ -28,7 +28,7 @@ import javax.ws.rs.core.UriBuilder; import org.onap.aaiclient.client.graphinventory.GraphInventoryObjectPlurals; import org.onap.aaiclient.client.graphinventory.GraphInventoryObjectType; -public abstract class SimplePluralUri, Parent extends GraphInventorySingleResourceUri, PT extends GraphInventoryObjectPlurals, OT extends GraphInventoryObjectType> +public abstract class SimplePluralUri, Parent extends GraphInventorySingleResourceUri, PT extends GraphInventoryObjectPlurals, OT extends GraphInventoryObjectType> extends SimpleBaseUri implements GraphInventoryPluralResourceUri, Serializable { private static final long serialVersionUID = -337701171277616439L; diff --git a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/entities/uri/SimpleUri.java b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/entities/uri/SimpleUri.java index e6a162bfda..570856d7f4 100644 --- a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/entities/uri/SimpleUri.java +++ b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/entities/uri/SimpleUri.java @@ -27,9 +27,11 @@ import java.net.URI; import javax.ws.rs.core.UriBuilder; import org.onap.aaiclient.client.graphinventory.GraphInventoryObjectPlurals; import org.onap.aaiclient.client.graphinventory.GraphInventoryObjectType; +import org.onap.aaiclient.client.graphinventory.GraphInventoryPluralFragment; +import org.onap.aaiclient.client.graphinventory.GraphInventorySingleFragment; -public abstract class SimpleUri, PT extends GraphInventoryPluralResourceUri, S extends GraphInventoryObjectType, P extends GraphInventoryObjectPlurals> - extends SimpleBaseUri implements GraphInventorySingleResourceUri { +public abstract class SimpleUri, PT extends GraphInventoryPluralResourceUri, S extends GraphInventoryObjectType, P extends GraphInventoryObjectPlurals, SF extends GraphInventorySingleFragment, PF extends GraphInventoryPluralFragment> + extends SimpleBaseUri implements GraphInventorySingleResourceUri { private static final long serialVersionUID = -337701171277616439L; protected static final String relationshipAPI = "/relationship-list/relationship"; diff --git a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/entities/uri/AAISimpleUriTest.java b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/entities/uri/AAISimpleUriTest.java index f8dd1726d3..92e74163a7 100644 --- a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/entities/uri/AAISimpleUriTest.java +++ b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/entities/uri/AAISimpleUriTest.java @@ -32,6 +32,7 @@ import org.junit.Test; import org.onap.aaiclient.client.aai.AAIObjectPlurals; import org.onap.aaiclient.client.aai.AAIObjectType; import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder; +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types; import org.onap.aaiclient.client.graphinventory.entities.uri.Depth; public class AAISimpleUriTest { @@ -43,7 +44,14 @@ public class AAISimpleUriTest { AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1").relatedTo(AAIObjectPlurals.PSERVER); String uriOutput = uri.build().toString(); - assertEquals("/network/generic-vnfs/generic-vnf/test1/related-to/pservers", uriOutput); + + String expected = "/network/generic-vnfs/generic-vnf/test1/related-to/pservers"; + assertEquals(expected, uriOutput); + + uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1") + .relatedTo(Types.PSERVERS.getFragment()); + uriOutput = uri.build().toString(); + assertEquals(expected, uriOutput); } @Test @@ -51,7 +59,17 @@ public class AAISimpleUriTest { AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1") .relatedTo(AAIObjectType.PSERVER, "test2"); String uriOutput = uri.build().toString(); - assertEquals("/network/generic-vnfs/generic-vnf/test1/related-to/pservers/pserver/test2", uriOutput); + + String expected = "/network/generic-vnfs/generic-vnf/test1/related-to/pservers/pserver/test2"; + assertEquals(expected, uriOutput); + + uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1") + .relatedTo(Types.PSERVER.getFragment("test2")); + + uriOutput = uri.build().toString(); + + assertEquals(expected, uriOutput); + } @Test -- cgit 1.2.3-korg