diff options
Diffstat (limited to 'graph-inventory')
9 files changed, 126 insertions, 55 deletions
diff --git a/graph-inventory/aai-client/pom.xml b/graph-inventory/aai-client/pom.xml index 39555f3f4a..8c7be3eb7e 100644 --- a/graph-inventory/aai-client/pom.xml +++ b/graph-inventory/aai-client/pom.xml @@ -72,7 +72,6 @@ <artifactItem> <groupId>org.onap.aai.schema-service</groupId> <artifactId>aai-schema</artifactId> - <version>1.6.5</version> <outputDirectory>${project.build.directory}/swagger</outputDirectory> <includes>**/*.yaml</includes> </artifactItem> @@ -276,7 +275,6 @@ <dependency> <groupId>org.onap.aai.schema-service</groupId> <artifactId>aai-schema</artifactId> - <version>1.6.5</version> </dependency> <dependency> <groupId>com.jayway.jsonpath</groupId> diff --git a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIObjectName.java b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIObjectName.java index 180a99e88b..d2b2300ee9 100644 --- a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIObjectName.java +++ b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIObjectName.java @@ -1,23 +1,7 @@ package org.onap.aaiclient.client.aai; import org.onap.aaiclient.client.graphinventory.GraphInventoryObjectName; -import com.google.common.base.CaseFormat; -public class AAIObjectName implements GraphInventoryObjectName { +public interface AAIObjectName extends GraphInventoryObjectName { - private final String name; - - public AAIObjectName(String name) { - this.name = name; - } - - @Override - public String typeName() { - return name; - } - - @Override - public String typeName(CaseFormat format) { - return CaseFormat.LOWER_HYPHEN.to(format, this.name); - } } diff --git a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIVersion.java b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIVersion.java index 0ddbb8fae5..ef43717b4f 100644 --- a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIVersion.java +++ b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIVersion.java @@ -32,7 +32,8 @@ public enum AAIVersion implements GraphInventoryVersion { V16("v16"), V17("v17"), V18("v18"), - V19("v19"); + V19("v19"), + V20("v20"); public static final AAIVersion LATEST = AAIVersion.values()[AAIVersion.values().length - 1]; private final String value; diff --git a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/entities/uri/AAIFluentSingleType.java b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/entities/uri/AAIFluentSingleType.java index 9310933499..519e49335d 100644 --- a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/entities/uri/AAIFluentSingleType.java +++ b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/entities/uri/AAIFluentSingleType.java @@ -1,12 +1,25 @@ package org.onap.aaiclient.client.aai.entities.uri; +import org.onap.aaiclient.client.aai.AAIObjectName; import org.onap.aaiclient.client.aai.AAIObjectType; import org.onap.aaiclient.client.graphinventory.GraphInventoryFluentType; +import com.google.common.base.CaseFormat; public interface AAIFluentSingleType extends GraphInventoryFluentType<AAIObjectType> { - public interface Info extends GraphInventoryFluentType.Info { + public interface Info extends GraphInventoryFluentType.Info, AAIObjectName { + public default String typeName() { + return this.getName(); + } + + public default String typeName(CaseFormat format) { + return CaseFormat.LOWER_HYPHEN.to(format, this.getName()); + } + + public interface UriParams extends GraphInventoryFluentType.Info.UriParams { + + } } } diff --git a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/GraphInventoryFluentType.java b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/GraphInventoryFluentType.java index 94fa240244..5741bf36eb 100644 --- a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/GraphInventoryFluentType.java +++ b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/GraphInventoryFluentType.java @@ -4,6 +4,12 @@ public interface GraphInventoryFluentType<T> extends GraphInventoryFluentTypeBas public interface Info extends GraphInventoryFluentTypeBase.Info { String getName(); + + UriParams getUriParams(); + + public interface UriParams { + + } } T build(); diff --git a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAIObjectTypeTest.java b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAIObjectTypeTest.java index 829ef1d646..000521bdf6 100644 --- a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAIObjectTypeTest.java +++ b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAIObjectTypeTest.java @@ -24,10 +24,10 @@ import static org.junit.Assert.assertEquals; import org.junit.Test; import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri; import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory; +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder; public class AAIObjectTypeTest { - @Test public void fromTypeNameTest() throws IllegalArgumentException, IllegalAccessException, InstantiationException { AAIObjectType type = AAIObjectType.fromTypeName("allotted-resource"); @@ -88,4 +88,27 @@ public class AAIObjectTypeTest { AAIResourceUri aaiUri = AAIUriFactory.createResourceUri(AAIObjectType.NETWORK_POLICY, id); assertEquals("/network/network-policies/network-policy/test1", aaiUri.build().toString()); } + + @Test + public void equalityTest() { + + AAIObjectType genericVnf = AAIFluentTypeBuilder.network().genericVnf("test").build(); + + assertEquals(AAIObjectType.GENERIC_VNF, genericVnf); + + } + + @Test + public void uriParamTest() { + + assertEquals("vnf-id", AAIFluentTypeBuilder.Types.GENERIC_VNF.getUriParams().vnfId); + + assertEquals("l-interface.interface-name", AAIFluentTypeBuilder.Types.L_INTERFACE.getUriParams().interfaceName); + + assertEquals("cloud-owner", AAIFluentTypeBuilder.Types.CLOUD_REGION.getUriParams().cloudOwner); + + assertEquals("cloud-region-id", AAIFluentTypeBuilder.Types.CLOUD_REGION.getUriParams().cloudRegionId); + + + } } 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 f9c664389b..23a1a812df 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 @@ -8,6 +8,7 @@ import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.regex.Matcher; import java.util.stream.Collectors; import javax.lang.model.element.Modifier; import org.apache.commons.lang3.ArrayUtils; @@ -240,19 +241,17 @@ public class FluentGenerator { } protected TypeSpec createTypes() { - Pair<String, String> path = splitClasspath(this.nameClass); - ClassName nameType = ClassName.get(path.getLeft(), path.getRight()); - - List<FieldSpec> params = - doc.values().stream().filter(item -> item.getType().equals("singular")) - .sorted(Comparator - .comparing(item -> item.getName())) - .map(item -> FieldSpec - .builder(nameType, - CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_UNDERSCORE, item.getName()), - Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL) - .initializer("new $T($S)", nameType, item.getName()).build()) - .collect(Collectors.toList()); + List<FieldSpec> params = doc.values().stream().filter(item -> item.getType().equals("singular")) + .sorted(Comparator.comparing(item -> item.getName())).map(item -> { + ClassName nameType = + ClassName.get(CLASSPATH, CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, item.getName())) + .nestedClass("Info"); + FieldSpec field = FieldSpec + .builder(nameType, CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_UNDERSCORE, item.getName()), + Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL) + .initializer("new $T()", nameType).build(); + return field; + }).collect(Collectors.toList()); TypeSpec type = TypeSpec.classBuilder("Types").addModifiers(Modifier.PUBLIC, Modifier.FINAL, Modifier.STATIC) .addFields(params).build(); @@ -276,30 +275,71 @@ public class FluentGenerator { .build()); ClassName superInterface; + String name; if (oType.getType().equals("plural")) { - classFields.add(FieldSpec.builder(String.class, "name") - .addModifiers(Modifier.PRIVATE, Modifier.FINAL, Modifier.STATIC) - .initializer("$S", oType.getAdditionalName()).build()); - superInterface = ClassName.get(this.pluralBuilderClass, "Info"); + Pair<String, String> path = splitClasspath(this.pluralBuilderClass); + superInterface = ClassName.get(path.getLeft(), path.getRight()); + name = oType.getAdditionalName(); } else if (oType.getType().equals("singular")) { - classFields.add(FieldSpec.builder(String.class, "name") - .addModifiers(Modifier.PRIVATE, Modifier.FINAL, Modifier.STATIC).initializer("$S", oType.getName()) - .build()); - superInterface = ClassName.get(this.singularBuilderClass, "Info"); + Pair<String, String> path = splitClasspath(this.singularBuilderClass); + superInterface = ClassName.get(path.getLeft(), path.getRight()); + name = oType.getName(); } else { - superInterface = ClassName.get(this.topLevelBuilderClass, "Info"); + Pair<String, String> path = splitClasspath(this.topLevelBuilderClass); + superInterface = ClassName.get(path.getLeft(), path.getRight()); + name = oType.getName(); } + superInterface = superInterface.nestedClass("Info"); methods.add(MethodSpec.methodBuilder("getPaths").returns(ParameterizedTypeName.get(List.class, String.class)) .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("top level")) { + classFields.add(FieldSpec.builder(String.class, "name") + .addModifiers(Modifier.PRIVATE, Modifier.FINAL, Modifier.STATIC).initializer("$S", name).build()); + classFields.add(FieldSpec.builder(ClassName.get("", "UriParams"), "uriParams") + .addModifiers(Modifier.PRIVATE, Modifier.FINAL, Modifier.STATIC) + .initializer("new $T()", ClassName.get("", "UriParams")).build()); methods.add(MethodSpec.methodBuilder("getName").returns(String.class).addModifiers(Modifier.PUBLIC) .addAnnotation(Override.class).addStatement("return Info.name").build()); + + methods.add(MethodSpec.methodBuilder("getUriParams").returns(ClassName.get("", "UriParams")) + .addModifiers(Modifier.PUBLIC).addAnnotation(Override.class).addStatement("return Info.uriParams") + .build()); + } + TypeSpec.Builder returnTypeSpec = TypeSpec.classBuilder("Info").addModifiers(Modifier.PUBLIC, Modifier.STATIC) + .addSuperinterface(superInterface).addFields(classFields).addMethods(methods); + if (!oType.getType().equals("top level")) { + returnTypeSpec.addType(createUriParamsClass(superInterface, oType)); + } + return returnTypeSpec.build(); + + } + + protected TypeSpec createUriParamsClass(ClassName parent, ObjectType oType) { + + List<FieldSpec> classFields = new ArrayList<>(); + Matcher params = Patterns.urlTemplatePattern.matcher(oType.getPartialUri()); + + while (params.find()) { + String value; + String name; + + if (params.group(2) != null) { + name = params.group(2); + } else { + name = params.group(1); + } + value = params.group(1); + + name = CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL, name); + + classFields.add(FieldSpec.builder(String.class, name, Modifier.PUBLIC, Modifier.FINAL) + .initializer("$S", value).build()); } - return TypeSpec.classBuilder("Info").addModifiers(Modifier.PUBLIC, Modifier.STATIC) - .addSuperinterface(superInterface).addFields(classFields).addMethods(methods).build(); + return TypeSpec.classBuilder("UriParams").addModifiers(Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL) + .addFields(classFields).addSuperinterface(parent.nestedClass("UriParams")).build(); } protected String makeValidJavaVariable(String name) { diff --git a/graph-inventory/fluent-builder-maven-plugin/src/main/java/org/onap/graphinventory/generate/Patterns.java b/graph-inventory/fluent-builder-maven-plugin/src/main/java/org/onap/graphinventory/generate/Patterns.java new file mode 100644 index 0000000000..8be22e1dcc --- /dev/null +++ b/graph-inventory/fluent-builder-maven-plugin/src/main/java/org/onap/graphinventory/generate/Patterns.java @@ -0,0 +1,11 @@ +package org.onap.graphinventory.generate; + +import java.util.regex.Pattern; + +public class Patterns { + + public static final Pattern pluralPattern = Pattern.compile(".*(?<partial>/(?<name>[^{]*$))"); + public static final Pattern singularPattern = Pattern.compile(".*(?<partial>/(?<name>[^/{}]*)/\\{.*$)"); + public static final Pattern topLevelPattern = Pattern.compile("^/([^/]+)/.*"); + public static final Pattern urlTemplatePattern = Pattern.compile("\\{([^}.]+(?:\\.([^}]+))?)\\}"); +} 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 b3ced65390..42305488bc 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 @@ -7,7 +7,6 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.regex.Matcher; -import java.util.regex.Pattern; import java.util.stream.Collectors; import org.apache.maven.plugin.logging.Log; import com.fasterxml.jackson.core.JsonProcessingException; @@ -33,10 +32,6 @@ public class SwaggerConverter { .filter(item -> !item.getKey().endsWith("/relationship-list/relationship")) .collect(Collectors.toMap(item -> item.getKey(), item -> item.getValue())); - Pattern pluralPattern = Pattern.compile(".*(?<partial>/(?<name>[^{]*$))"); - Pattern singularPattern = Pattern.compile(".*(?<partial>/(?<name>[^/{}]*)/\\{.*$)"); - Pattern topLevelPattern = Pattern.compile("^/([^/]+)/.*"); - Pattern urlTemplatePattern = Pattern.compile("\\{([^}]+)\\}"); Matcher pluralMatcher; Matcher singularMatcher; Matcher topLevelMatcher; @@ -44,9 +39,9 @@ public class SwaggerConverter { Map<String, ObjectType> output = new HashMap<>(); for (Map.Entry<String, Path> entry : paths.entrySet()) { - pluralMatcher = pluralPattern.matcher(entry.getKey()); - singularMatcher = singularPattern.matcher(entry.getKey()); - topLevelMatcher = topLevelPattern.matcher(entry.getKey()); + pluralMatcher = Patterns.pluralPattern.matcher(entry.getKey()); + singularMatcher = Patterns.singularPattern.matcher(entry.getKey()); + topLevelMatcher = Patterns.topLevelPattern.matcher(entry.getKey()); ObjectType item; if (pluralMatcher.matches()) { if (!output.containsKey(pluralMatcher.group("name"))) { @@ -158,7 +153,7 @@ public class SwaggerConverter { } if (!item.getValue().getFields().isEmpty()) { - Matcher templates = urlTemplatePattern.matcher(item.getValue().getPartialUri()); + Matcher templates = Patterns.urlTemplatePattern.matcher(item.getValue().getPartialUri()); List<String> localFields = new ArrayList<>(); while (templates.find()) { localFields.add(templates.group(1)); |