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 +++++++++- .../graphinventory/generate/FluentGenerator.java | 51 ++++++++++++++++++++-- .../generate/FluentGeneratorMojo.java | 6 ++- 19 files changed, 186 insertions(+), 26 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 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 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 params = doc.values().stream().filter(item -> item.getType().equals("singular")) + List 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 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 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 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 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(); -- cgit 1.2.3-korg