diff options
Diffstat (limited to 'graph-inventory')
20 files changed, 188 insertions, 26 deletions
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 @@ <singularClass>org.onap.aaiclient.client.aai.AAIObjectType</singularClass> <pluralClass>org.onap.aaiclient.client.aai.AAIObjectPlurals</pluralClass> <nameClass>org.onap.aaiclient.client.aai.AAIObjectName</nameClass> + <singleFragmentClass>org.onap.aaiclient.client.aai.entities.uri.AAISingleFragment</singleFragmentClass> + <pluralFragmentClass>org.onap.aaiclient.client.aai.entities.uri.AAIPluralFragment</pluralFragmentClass> </configuration> </execution> </executions> diff --git a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIObjectPlurals.java b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIObjectPlurals.java index 5b68d0c69a..78f8350eff 100644 --- a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIObjectPlurals.java +++ b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIObjectPlurals.java @@ -74,6 +74,8 @@ public class AAIObjectPlurals implements AAIObjectBase, GraphInventoryObjectPlur new AAIObjectPlurals(AAIObjectType.INSTANCE_GROUP, AAINamespaceConstants.NETWORK, "/instance-groups"); public static final AAIObjectPlurals PNF = new AAIObjectPlurals(AAIObjectType.PNF, AAINamespaceConstants.NETWORK, "/pnfs"); + public static final AAIObjectPlurals PROJECT = + new AAIObjectPlurals(AAIObjectType.PROJECT, AAINamespaceConstants.BUSINESS, "/projects"); private final String uriTemplate; private final String partialUri; 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<AAIFluentPluralType> { + + 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<AAIResourceUri, AAIObjectType>, - GraphInventorySingleResourceUri<AAIResourceUri, AAIPluralResourceUri, AAIObjectType, AAIObjectPlurals> { + GraphInventorySingleResourceUri<AAIResourceUri, AAIPluralResourceUri, AAIObjectType, AAIObjectPlurals, AAISingleFragment, AAIPluralFragment> { } 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<AAIResourceUri, AAIPluralResourceUri, AAIObjectType, AAIObjectPlurals> +public class AAISimpleUri extends + SimpleUri<AAIResourceUri, AAIPluralResourceUri, AAIObjectType, AAIObjectPlurals, AAISingleFragment, AAIPluralFragment> implements AAIResourceUri { private static final long serialVersionUID = -6397024057188453229L; @@ -70,4 +71,16 @@ public class AAISimpleUri extends SimpleUri<AAIResourceUri, AAIPluralResourceUri return new AAISimplePluralUri(this, plural); } + @Override + public AAISimpleUri relatedTo(AAISingleFragment fragment) { + this.internalURI.path(relatedTo); + return new AAISimpleUri(this, fragment.get().build(), fragment.get().values()); + } + + @Override + public AAISimplePluralUri relatedTo(AAIPluralFragment fragment) { + this.internalURI.path(relatedTo); + return new AAISimplePluralUri(this, fragment.get().build()); + } + } diff --git a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/entities/uri/AAISingleFragment.java b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/entities/uri/AAISingleFragment.java new file mode 100644 index 0000000000..a988899ed2 --- /dev/null +++ b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/entities/uri/AAISingleFragment.java @@ -0,0 +1,19 @@ +package org.onap.aaiclient.client.aai.entities.uri; + +import java.io.Serializable; +import org.onap.aaiclient.client.graphinventory.GraphInventorySingleFragment; + +public class AAISingleFragment implements Serializable, GraphInventorySingleFragment<AAIFluentSingleType> { + + 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<String> getPaths(); + default List<String> 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> { + + 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<T extends GraphInventoryFluentType<? extends GraphInventoryObjectPlurals>> + extends GraphInventoryFragmentBase<T> { + + +} 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<Self, Uri extends GraphInventoryResourceUri<?, ?>, SingleUri extends GraphInventorySingleResourceUri<?, ?, ?, ?>, PluralUri extends GraphInventoryPluralResourceUri<?, ?>, EdgeLabel extends GraphInventoryEdgeLabel, Wrapper extends GraphInventoryResultWrapper, TransactionalClient, SingleTransactionClient> { +public abstract class GraphInventoryResourcesClient<Self, Uri extends GraphInventoryResourceUri<?, ?>, 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<Self, Uri extends GraphInven * @return */ public void connect(SingleUri uriA, SingleUri uriB) { - GraphInventorySingleResourceUri<?, ?, ?, ?> 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<Self, Uri extends GraphInven * @return */ public void connect(SingleUri uriA, SingleUri uriB, EdgeLabel label) { - GraphInventorySingleResourceUri<?, ?, ?, ?> 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<Self, Uri extends GraphInven * @return */ public void disconnect(SingleUri uriA, SingleUri uriB) { - GraphInventorySingleResourceUri<?, ?, ?, ?> 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<Self, Uri extends GraphInven * @return */ public void delete(SingleUri uri) { - GraphInventorySingleResourceUri<?, ?, ?, ?> clone = (SingleUri) uri.clone(); + GraphInventorySingleResourceUri<?, ?, ?, ?, ?, ?> clone = (SingleUri) uri.clone(); RestClient giRC = client.createClient(clone); Map<String, Object> result = giRC.get(new GenericType<Map<String, Object>>() {}).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<T extends GraphInventoryFluentType<? extends GraphInventoryObjectType>> + extends GraphInventoryFragmentBase<T> { + + +} 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<Self, Uri extends GraphInventoryResourceUri<?, ?>, SingleUri extends GraphInventorySingleResourceUri<?, ?, ?, ?>, EdgeLabel extends GraphInventoryEdgeLabel> { +public abstract class GraphInventoryTransactionClient<Self, Uri extends GraphInventoryResourceUri<?, ?>, 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<Wrapper extends GraphInventoryResultWrapper<?>, Uri extends GraphInventorySingleResourceUri<?, ?, ?, ?>, Type extends GraphInventoryObjectType> { +public abstract class GraphInventoryRelationships<Wrapper extends GraphInventoryResultWrapper<?>, Uri extends GraphInventorySingleResourceUri<?, ?, ?, ?, ?, ?>, Type extends GraphInventoryObjectType> { protected final ObjectMapper mapper; protected Map<String, Object> 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<T extends GraphInventorySingleResourceUri<?, ?, ?, ?>, P extends GraphInventoryPluralResourceUri<?, ?>, SingleObject extends GraphInventoryObjectType, PluralObject extends GraphInventoryObjectPlurals> +public interface GraphInventorySingleResourceUri<T extends GraphInventorySingleResourceUri<?, ?, ?, ?, ?, ?>, P extends GraphInventoryPluralResourceUri<?, ?>, SingleObject extends GraphInventoryObjectType, PluralObject extends GraphInventoryObjectPlurals, SingleFragment extends GraphInventorySingleFragment, PluralFragment extends GraphInventoryPluralFragment> extends GraphInventoryResourceUri<T, SingleObject> { public T resourceVersion(String version); @@ -13,4 +15,8 @@ public interface GraphInventorySingleResourceUri<T extends GraphInventorySingleR public P relatedTo(PluralObject plural); public T relatedTo(SingleObject type, String... values); + + public P relatedTo(PluralFragment fragment); + + public T relatedTo(SingleFragment fragment); } diff --git a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/entities/uri/SimpleBaseUri.java b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/entities/uri/SimpleBaseUri.java index b668f465e9..d1e9e91f48 100644 --- a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/entities/uri/SimpleBaseUri.java +++ b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/entities/uri/SimpleBaseUri.java @@ -22,7 +22,7 @@ import org.onap.aaiclient.client.graphinventory.entities.uri.parsers.UriParserSp import org.onap.aaiclient.client.graphinventory.exceptions.IncorrectNumberOfUriKeys; import org.springframework.web.util.UriUtils; -public abstract class SimpleBaseUri<T extends GraphInventoryResourceUri<?, ?>, Parent extends GraphInventorySingleResourceUri<?, ?, ?, ?>, S extends GraphInventoryObjectBase> +public abstract class SimpleBaseUri<T extends GraphInventoryResourceUri<?, ?>, Parent extends GraphInventorySingleResourceUri<?, ?, ?, ?, ?, ?>, S extends GraphInventoryObjectBase> implements GraphInventoryResourceUri<T, S> { 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<T extends GraphInventoryPluralResourceUri<?, ?>, Parent extends GraphInventorySingleResourceUri<?, ?, ?, ?>, PT extends GraphInventoryObjectPlurals, OT extends GraphInventoryObjectType> +public abstract class SimplePluralUri<T extends GraphInventoryPluralResourceUri<?, ?>, Parent extends GraphInventorySingleResourceUri<?, ?, ?, ?, ?, ?>, PT extends GraphInventoryObjectPlurals, OT extends GraphInventoryObjectType> extends SimpleBaseUri<T, Parent, PT> implements GraphInventoryPluralResourceUri<T, PT>, 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<T extends GraphInventorySingleResourceUri<?, ?, ?, ?>, PT extends GraphInventoryPluralResourceUri<?, ?>, S extends GraphInventoryObjectType, P extends GraphInventoryObjectPlurals> - extends SimpleBaseUri<T, T, S> implements GraphInventorySingleResourceUri<T, PT, S, P> { +public abstract class SimpleUri<T extends GraphInventorySingleResourceUri<?, ?, ?, ?, ?, ?>, PT extends GraphInventoryPluralResourceUri<?, ?>, S extends GraphInventoryObjectType, P extends GraphInventoryObjectPlurals, SF extends GraphInventorySingleFragment<?>, PF extends GraphInventoryPluralFragment<?>> + extends SimpleBaseUri<T, T, S> implements GraphInventorySingleResourceUri<T, PT, S, P, SF, PF> { 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 diff --git a/graph-inventory/fluent-builder-maven-plugin/src/main/java/org/onap/graphinventory/generate/FluentGenerator.java b/graph-inventory/fluent-builder-maven-plugin/src/main/java/org/onap/graphinventory/generate/FluentGenerator.java index 4a8b7d90c6..efbeba203c 100644 --- a/graph-inventory/fluent-builder-maven-plugin/src/main/java/org/onap/graphinventory/generate/FluentGenerator.java +++ b/graph-inventory/fluent-builder-maven-plugin/src/main/java/org/onap/graphinventory/generate/FluentGenerator.java @@ -39,11 +39,13 @@ public class FluentGenerator { private final String pluralClass; private final String builderName; private final String nameClass; + private final String singleFragmentClass; + private final String pluralFragmentClass; public FluentGenerator(Log log, String location, String destinationClasspath, String swaggerLocation, String builderName, String singularBuilderClass, String pluralBuilderClass, String topLevelBuilderClass, - String baseBuilderClass, String singularClass, String pluralClass, String nameClass) - throws JsonProcessingException { + String baseBuilderClass, String singularClass, String pluralClass, String nameClass, + String singleFragmentClass, String pluralFragmentClass) throws JsonProcessingException { this.location = location; this.CLASSPATH = destinationClasspath; @@ -55,6 +57,8 @@ public class FluentGenerator { this.singularClass = singularClass; this.pluralClass = pluralClass; this.nameClass = nameClass; + this.singleFragmentClass = singleFragmentClass; + this.pluralFragmentClass = pluralFragmentClass; doc = new SwaggerConverter(log).getDoc(swaggerLocation); } @@ -241,7 +245,8 @@ public class FluentGenerator { } protected TypeSpec createTypes() { - List<FieldSpec> params = doc.values().stream().filter(item -> item.getType().equals("singular")) + List<FieldSpec> params = doc.values().stream() + .filter(item -> item.getType().equals("singular") || item.getType().equals("plural")) .sorted(Comparator.comparing(item -> item.getName())).map(item -> { ClassName nameType = ClassName.get(CLASSPATH, CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, item.getName())) @@ -274,6 +279,18 @@ public class FluentGenerator { "\"" + oType.getPaths().stream().collect(Collectors.joining("\", \"")) + "\"") .build()); + if (oType.getType().equals("plural")) { + Pair<String, String> path = splitClasspath(this.pluralFragmentClass); + ClassName fragmentClass = ClassName.get(path.getLeft(), path.getRight()); + path = splitClasspath(this.baseBuilderClass); + ClassName baseClass = ClassName.get(path.getLeft(), path.getRight()); + + classFields.add(FieldSpec.builder(fragmentClass, "fragment") + .addModifiers(Modifier.PRIVATE, Modifier.FINAL, Modifier.STATIC) + .initializer("new $T(new $L(new $T(){}))", fragmentClass, upperCamel(oType.getName()), baseClass) + .build()); + } + ClassName superInterface; String name; if (oType.getType().equals("plural")) { @@ -294,6 +311,34 @@ public class FluentGenerator { .addModifiers(Modifier.PUBLIC).addAnnotation(Override.class).addStatement("return Info.paths").build()); methods.add(MethodSpec.methodBuilder("getPartialUri").returns(String.class).addModifiers(Modifier.PUBLIC) .addAnnotation(Override.class).addStatement("return Info.partialUri").build()); + + if (oType.getType().equals("plural")) { + Pair<String, String> path = splitClasspath(this.pluralFragmentClass); + ClassName fragmentClass = ClassName.get(path.getLeft(), path.getRight()); + methods.add(MethodSpec.methodBuilder("getFragment").returns(fragmentClass).addModifiers(Modifier.PUBLIC) + .addStatement("return fragment").build()); + } else if (oType.getType().equals("singular")) { + Pair<String, String> path = splitClasspath(this.singleFragmentClass); + ClassName fragmentClass = ClassName.get(path.getLeft(), path.getRight()); + path = splitClasspath(this.baseBuilderClass); + ClassName baseClass = ClassName.get(path.getLeft(), path.getRight()); + List<ParameterSpec> typeParams = new ArrayList<>(); + + for (ObjectField oF : oType.getFields()) { + if (oF.getType().equals("string")) { + typeParams.add(ParameterSpec.builder(String.class, lowerCamel(makeValidJavaVariable(oF.getName()))) + .build()); + } else if (oF.getType().equals("integer")) { + typeParams.add( + ParameterSpec.builder(int.class, lowerCamel(makeValidJavaVariable(oF.getName()))).build()); + } + } + methods.add(MethodSpec.methodBuilder("getFragment").returns(fragmentClass).addParameters(typeParams) + .addModifiers(Modifier.PUBLIC) + .addStatement("return new $T(new $L(new $T(){}, $L))", fragmentClass, upperCamel(oType.getName()), + baseClass, typeParams.stream().map(item -> item.name).collect(Collectors.joining(", "))) + .build()); + } if (!oType.getType().equals("top level")) { classFields.add(FieldSpec.builder(String.class, "name") .addModifiers(Modifier.PRIVATE, Modifier.FINAL, Modifier.STATIC).initializer("$S", name).build()); diff --git a/graph-inventory/fluent-builder-maven-plugin/src/main/java/org/onap/graphinventory/generate/FluentGeneratorMojo.java b/graph-inventory/fluent-builder-maven-plugin/src/main/java/org/onap/graphinventory/generate/FluentGeneratorMojo.java index 9de249faa2..8c672e3e7d 100644 --- a/graph-inventory/fluent-builder-maven-plugin/src/main/java/org/onap/graphinventory/generate/FluentGeneratorMojo.java +++ b/graph-inventory/fluent-builder-maven-plugin/src/main/java/org/onap/graphinventory/generate/FluentGeneratorMojo.java @@ -34,13 +34,17 @@ public class FluentGeneratorMojo extends AbstractMojo { private String pluralClass; @Parameter private String nameClass; + @Parameter + private String singleFragmentClass; + @Parameter + private String pluralFragmentClass; public void execute() throws MojoExecutionException, MojoFailureException { try { new FluentGenerator(getLog(), destination, destinationClasspath, swaggerLocation, builderName, singularBuilderClass, pluralBuilderClass, topLevelBuilderClass, baseBuilderClass, singularClass, - pluralClass, nameClass).run(); + pluralClass, nameClass, singleFragmentClass, pluralFragmentClass).run(); } catch (JsonProcessingException e) { // TODO Auto-generated catch block e.printStackTrace(); |