From 828d4db9f5ace2e8df651292832e6bf6babc7245 Mon Sep 17 00:00:00 2001 From: Sergej Turkan Date: Wed, 6 Feb 2019 17:20:09 +0100 Subject: [PATCH 01/41] Adding Spotless plugin to enforce codestyle & sample formattings --- cool.importorder | 8 ++ eclipse-formatter.xml | 314 ++++++++++++++++++++++++++++++++++++++++++ pom.xml | 31 ++++- 3 files changed, 350 insertions(+), 3 deletions(-) create mode 100644 cool.importorder create mode 100644 eclipse-formatter.xml diff --git a/cool.importorder b/cool.importorder new file mode 100644 index 00000000..cd4f3d96 --- /dev/null +++ b/cool.importorder @@ -0,0 +1,8 @@ +#Organize Import Order +#Fri Nov 03 08:00:24 CET 2017 +5=liquibase +4=lombok +3=com +2=org +1=javax +0=java diff --git a/eclipse-formatter.xml b/eclipse-formatter.xml new file mode 100644 index 00000000..f0db3e7e --- /dev/null +++ b/eclipse-formatter.xml @@ -0,0 +1,314 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pom.xml b/pom.xml index 0eb098e2..b51a990b 100644 --- a/pom.xml +++ b/pom.xml @@ -57,10 +57,10 @@ sdk-src - sdk-integration-tests - sdk-usage-examples + + sdk-generate-entity-models-maven-plugin - sdk-extension + UTF-8 @@ -75,6 +75,7 @@ 2.0 1.9.2 + 3.8.1 2.5.3 2.19.1 @@ -143,6 +144,11 @@ commons-beanutils ${commons-beanutils.version} + + org.apache.commons + commons-lang3 + ${commons-lang.version} + junit junit @@ -188,6 +194,25 @@ + + com.diffplug.spotless + spotless-maven-plugin + 1.17.0 + + + + sdk-generate-entity-models-maven-plugin/src/**/java/**/*.java + + + ${session.executionRootDirectory}/eclipse-formatter.xml + 4.7.1 + + + ${session.executionRootDirectory}/cool.importorder + + + + com.mycila license-maven-plugin From e45dc84c86a56dd3699f83875d4723800a53fc11 Mon Sep 17 00:00:00 2001 From: Sergej Turkan Date: Wed, 6 Feb 2019 17:21:18 +0100 Subject: [PATCH 02/41] Apply spotless plugin on generator module --- .../adm/nga/sdk/generate/GenerateModels.java | 628 ++++++++++-------- .../sdk/generate/GenerateModelsPlugin.java | 51 +- .../adm/nga/sdk/generate/GeneratorHelper.java | 562 ++++++++-------- 3 files changed, 657 insertions(+), 584 deletions(-) diff --git a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java index 5ec15d63..39c86af8 100644 --- a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java +++ b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java @@ -13,6 +13,16 @@ */ package com.hpe.adm.nga.sdk.generate; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.*; +import java.util.stream.Collectors; + +import org.apache.velocity.Template; +import org.apache.velocity.VelocityContext; +import org.apache.velocity.app.VelocityEngine; + import com.hpe.adm.nga.sdk.Octane; import com.hpe.adm.nga.sdk.authentication.SimpleClientAuthentication; import com.hpe.adm.nga.sdk.metadata.EntityMetadata; @@ -24,292 +34,352 @@ import com.hpe.adm.nga.sdk.model.EntityModel; import com.hpe.adm.nga.sdk.model.ReferenceFieldModel; import com.hpe.adm.nga.sdk.model.StringFieldModel; -import org.apache.velocity.Template; -import org.apache.velocity.VelocityContext; -import org.apache.velocity.app.VelocityEngine; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.util.*; -import java.util.stream.Collectors; /** - *

The class that generates entities based on the metadata from the given ALM Octane server - * This class generates models based on the {@link com.hpe.adm.nga.sdk.model.TypedEntityModel}, - * entity lists based on {@link com.hpe.adm.nga.sdk.entities.TypedEntityList} and Lists & Phases objects - * which represents those entities on the server and turns them into typed enums. + *

+ * The class that generates entities based on the metadata from the given ALM + * Octane server This class generates models based on the + * {@link com.hpe.adm.nga.sdk.model.TypedEntityModel}, entity lists based on + * {@link com.hpe.adm.nga.sdk.entities.TypedEntityList} and Lists & Phases + * objects which represents those entities on the server and turns them into + * typed enums. *

*

- * The user that calls the generation must have the workspace member of the given workspace. + * The user that calls the generation must have the workspace member of the + * given workspace. *

*

- * UDFs are generated if they are part of the metadata for that workspace. That means that the generated - * entities should be able to be reused over different workspaces within the same shared space. However - * some business rules could cause different behaviour in different Workspaces. See the ALM Octane documentation - * for more information + * UDFs are generated if they are part of the metadata for that workspace. That + * means that the generated entities should be able to be reused over different + * workspaces within the same shared space. However some business rules could + * cause different behaviour in different Workspaces. See the ALM Octane + * documentation for more information *

*/ public class GenerateModels { - private final Template template, interfaceTemplate, entityListTemplate, phasesTemplate, listsTemplate; - private final File modelDirectory, entitiesDirectory, enumsDirectory; - - /** - * Initialise the class with the output directory. This should normally be in a project that would be - * imported into the main Java project - * @param outputDirectory Where all the generated files will be placed - */ - public GenerateModels(final File outputDirectory) { - final File packageDirectory = new File(outputDirectory, "/com/hpe/adm/nga/sdk"); - modelDirectory = new File(packageDirectory, "model"); - modelDirectory.mkdirs(); - entitiesDirectory = new File(packageDirectory, "entities"); - entitiesDirectory.mkdirs(); - enumsDirectory = new File(packageDirectory, "enums"); - enumsDirectory.mkdirs(); - - final VelocityEngine velocityEngine = new VelocityEngine(); - velocityEngine.setProperty("resource.loader", "class"); - velocityEngine.setProperty("class.resource.loader.description", "Velocity Classpath Resource Loader"); - velocityEngine.setProperty("runtime.log.logsystem.log4j.logger", "root"); - velocityEngine.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); - - velocityEngine.init(); - - template = velocityEngine.getTemplate("/EntityModel.vm"); - interfaceTemplate = velocityEngine.getTemplate("/Entity.vm"); - entityListTemplate = velocityEngine.getTemplate("/TypedEntityList.vm"); - phasesTemplate = velocityEngine.getTemplate("/Phases.vm"); - listsTemplate = velocityEngine.getTemplate("/Lists.vm"); - } - - /** - * Run the actual generation - * @param clientId The client id - * @param clientSecret The client secret - * @param server The server including the protocol and port - * @param sharedSpace The SS id - * @param workSpace The WS id - * @throws IOException A problem with the generation of the entities - */ - public void generate(String clientId, String clientSecret, String server, long sharedSpace, long workSpace) throws IOException { - // work around for work_items_root - final Octane octanePrivate = new Octane.Builder(new SimpleClientAuthentication(clientId, clientSecret, "HPE_REST_API_TECH_PREVIEW")).sharedSpace(sharedSpace).workSpace(workSpace).Server(server).build(); - final EntityMetadata work_items_root = octanePrivate.metadata().entities("work_item_root").execute().iterator().next(); - final Collection work_items_rootFields = octanePrivate.metadata().fields("work_item_root").execute(); - octanePrivate.signOut(); - - final Octane octane = new Octane.Builder(new SimpleClientAuthentication(clientId, clientSecret)).sharedSpace(sharedSpace).workSpace(workSpace).Server(server).build(); - final Metadata metadata = octane.metadata(); - final Collection entityMetadata = metadata.entities().execute(); - entityMetadata.add(work_items_root); - - final Map logicalNameToListsMap = generateLists(octane); - final Set availablePhases = generatePhases(octane); - - for (EntityMetadata entityMetadatum : entityMetadata) { - final String name = entityMetadatum.getName(); - final String interfaceName = GeneratorHelper.camelCaseFieldName(name) + "Entity"; - final Collection fieldMetadata = generateEntity(work_items_rootFields, metadata, entityMetadata, entityMetadatum, name, interfaceName, logicalNameToListsMap, availablePhases); - generateInterface(entityMetadatum, name, interfaceName); - generateEntityList(entityMetadatum, name, fieldMetadata); - } - } - - private Map generateLists(Octane octane) throws IOException { - final Collection listNodes = octane.entityList("list_nodes").get().addFields("name", "list_root", "id", "logical_name").execute(); - final Map> mappedListNodes = new HashMap<>(); - final Map logicalNameToNameMap = new HashMap<>(); - listNodes.forEach(listNode -> { - final String rootId; - final ReferenceFieldModel list_root = (ReferenceFieldModel) listNode.getValue("list_root"); - final EntityModel list_rootValue = list_root.getValue(); - final String name; - if (list_rootValue != null) { - rootId = list_rootValue.getId(); - name = ((StringFieldModel) listNode.getValue("name")).getValue().replaceAll(" ", "_").replaceAll("^\\d", "_$0").replaceAll("\\W", "_").toUpperCase(); - } else { - rootId = listNode.getId(); - name = GeneratorHelper.camelCaseFieldName(((StringFieldModel) listNode.getValue("name")).getValue().replaceAll("\\W", "_")); - logicalNameToNameMap.put(((StringFieldModel) listNode.getValue("logical_name")).getValue(), name); - } - final List listHierarchy = mappedListNodes.computeIfAbsent(rootId, k -> new ArrayList<>()); - - final String[] listNodeInfo = {name, ((StringFieldModel) listNode.getValue("id")).getValue()}; - if (list_rootValue == null) { - listHierarchy.add(0, listNodeInfo); - } else { - listHierarchy.add(listNodeInfo); - } - }); - - final VelocityContext velocityContext = new VelocityContext(); - velocityContext.put("listNodes", mappedListNodes); - final FileWriter fileWriter = new FileWriter(new File(enumsDirectory, "Lists.java")); - listsTemplate.merge(velocityContext, fileWriter); - fileWriter.close(); - - return logicalNameToNameMap; - } - - private Set generatePhases(Octane octane) throws IOException { - final Map> phaseMap = new HashMap<>(); - final Collection phases = octane.entityList("phases").get().addFields("id", "name", "entity").execute(); - phases.forEach(phase -> { - final Set phaseValueSet = new HashSet<>(); - phaseValueSet.add(new String[]{phase.getId(), ((StringFieldModel) phase.getValue("name")).getValue() - .replaceAll(" ", "_") - .replaceAll("&", "N") - .toUpperCase()}); - phaseMap.merge(GeneratorHelper.camelCaseFieldName(((StringFieldModel) phase.getValue("entity")).getValue(), true), phaseValueSet, (existingValues, newValues) -> { - existingValues.addAll(newValues); - return existingValues; - }); - }); - - final VelocityContext velocityContext = new VelocityContext(); - velocityContext.put("phaseMap", phaseMap); - final FileWriter fileWriter = new FileWriter(new File(enumsDirectory, "Phases.java")); - phasesTemplate.merge(velocityContext, fileWriter); - fileWriter.close(); - - return phaseMap.keySet(); - } - - private Collection generateEntity(Collection work_items_rootFields, Metadata metadata, Collection entityMetadata, EntityMetadata entityMetadatum, String name, String interfaceName, Map logicalNameToListsMap, Set availablePhases) throws IOException { - final Collection fieldMetadata = name.equals("work_item_root") ? work_items_rootFields : metadata.fields(name).execute(); - - final TreeMap> collectedReferences = fieldMetadata.stream() - .filter(FieldMetadata::isRequired) - .collect(Collectors.toMap(FieldMetadata::getName, fieldMetadata1 -> { - final List references = new ArrayList<>(); - final String className = GeneratorHelper.camelCaseFieldName(entityMetadatum.getName()); - if (fieldMetadata1.getName().equals("phase") && availablePhases.contains(className)) { - references.add("com.hpe.adm.nga.sdk.enums.Phases." + className + "Phase"); - } else if (fieldMetadata1.getFieldType() == FieldMetadata.FieldType.Reference) { - if ((!entityMetadatum.getName().equals("list_node")) && (fieldMetadata1.getFieldTypedata().getTargets()[0].getType().equals("list_node"))) { - final String listName = logicalNameToListsMap.get(fieldMetadata1.getFieldTypedata().getTargets()[0].logicalName()); - references.add("com.hpe.adm.nga.sdk.enums.Lists." + listName); - } else { - final GeneratorHelper.ReferenceMetadata referenceMetadata = GeneratorHelper.getAllowedSuperTypesForReference(fieldMetadata1, entityMetadata); - if (fieldMetadata1.getFieldTypedata().isMultiple()) { - references.add(referenceMetadata.getReferenceClassForSignature()); - } else { - if (referenceMetadata.hasTypedReturn()) { - references.addAll(referenceMetadata.getReferenceTypes() - .stream() - .map(type -> GeneratorHelper.camelCaseFieldName(type).concat("EntityModel")) - .collect(Collectors.toSet())); - } - if (referenceMetadata.hasNonTypedReturn()) { - references.add("EntityModel"); - } - } - } - } else { - references.add(GeneratorHelper.getFieldTypeAsJava(fieldMetadata1.getFieldType())); - } - - return references; - }, (strings, strings2) -> { - throw new IllegalStateException("problem merging map"); - }, TreeMap::new)); - - final Set> requiredFields = new HashSet<>(); - if (!collectedReferences.isEmpty()) { - expandCollectedReferences(collectedReferences, new int[collectedReferences.size()], 0, requiredFields); - } - - final VelocityContext velocityContext = new VelocityContext(); - velocityContext.put("interfaceName", interfaceName); - velocityContext.put("entityMetadata", entityMetadatum); - velocityContext.put("fieldMetadata", fieldMetadata); - velocityContext.put("logicalNameToListsMap", logicalNameToListsMap); - velocityContext.put("entityMetadataCollection", entityMetadata); - velocityContext.put("GeneratorHelper", GeneratorHelper.class); - velocityContext.put("entityMetadataWrapper", GeneratorHelper.entityMetadataWrapper(entityMetadatum)); - velocityContext.put("availablePhases", availablePhases); - velocityContext.put("requiredFields", requiredFields); - - final FileWriter fileWriter = new FileWriter(new File(modelDirectory, GeneratorHelper.camelCaseFieldName(name) + "EntityModel.java")); - template.merge(velocityContext, fileWriter); - - fileWriter.close(); - return fieldMetadata; - } - - private void expandCollectedReferences(final TreeMap> collectedReferences, final int[] positions, final int pointer, final Set> output) { - final Object[] keyArray = collectedReferences.keySet().toArray(); - final Object o = keyArray[pointer]; - for (int i = 0; i < collectedReferences.get(o).size(); ++i) { - if (pointer == positions.length - 1) { - final List outputLine = new ArrayList<>(positions.length); - for (int j = 0; j < positions.length; ++j) { - outputLine.add(new String[]{(String) keyArray[j], collectedReferences.get(keyArray[j]).get(positions[j])}); - } - output.add(outputLine); - } else { - expandCollectedReferences(collectedReferences, positions, pointer + 1, output); - } - positions[pointer]++; - } - positions[pointer] = 0; - } - - private void generateInterface(EntityMetadata entityMetadatum, String name, String interfaceName) throws IOException { - // interface - final VelocityContext interfaceVelocityContext = new VelocityContext(); - final Optional subTypeOfFeature = entityMetadatum.features().stream().filter(feature -> feature instanceof SubTypesOfFeature).findAny(); - - interfaceVelocityContext.put("interfaceName", interfaceName); - interfaceVelocityContext.put("superInterfaceName", - (subTypeOfFeature.map(feature -> GeneratorHelper.camelCaseFieldName(((SubTypesOfFeature) feature).getType())).orElse("")) + "Entity"); - - final FileWriter interfaceFileWriter = new FileWriter(new File(modelDirectory, GeneratorHelper.camelCaseFieldName(name) + "Entity.java")); - interfaceTemplate.merge(interfaceVelocityContext, interfaceFileWriter); - - interfaceFileWriter.close(); - } - - private void generateEntityList(EntityMetadata entityMetadatum, String name, Collection fieldMetadata) throws IOException { - // entityList - final Optional hasRestFeature = entityMetadatum.features().stream() - .filter(feature -> feature instanceof RestFeature) - .findFirst(); - // if not then something is wrong! - if (hasRestFeature.isPresent()) { - final RestFeature restFeature = (RestFeature) hasRestFeature.get(); - - final VelocityContext entityListVelocityContext = new VelocityContext(); - entityListVelocityContext.put("helper", GeneratorHelper.class); - entityListVelocityContext.put("type", GeneratorHelper.camelCaseFieldName(name)); - entityListVelocityContext.put("url", restFeature.getUrl()); - entityListVelocityContext.put("availableFields", fieldMetadata.stream().map(FieldMetadata::getName).collect(Collectors.toList())); - entityListVelocityContext.put("sortableFields", fieldMetadata.stream().filter(FieldMetadata::isSortable).map(FieldMetadata::getName).collect(Collectors.toList())); - - final String[] restFeatureMethods = restFeature.getMethods(); - for (String restFeatureMethod : restFeatureMethods) { - switch (restFeatureMethod) { - case "GET": - entityListVelocityContext.put("hasGet", true); - break; - case "POST": - entityListVelocityContext.put("hasCreate", true); - break; - case "PUT": - entityListVelocityContext.put("hasUpdate", true); - break; - case "DELETE": - entityListVelocityContext.put("hasDelete", true); - break; - } - } - - final FileWriter entityListFileWriter = new FileWriter(new File(entitiesDirectory, GeneratorHelper.camelCaseFieldName(name) + "EntityList.java")); - entityListTemplate.merge(entityListVelocityContext, entityListFileWriter); - - entityListFileWriter.close(); - } - } -} \ No newline at end of file + private final Template template, interfaceTemplate, entityListTemplate, phasesTemplate, listsTemplate; + private final File modelDirectory, entitiesDirectory, enumsDirectory; + + /** + * Initialise the class with the output directory. This should normally be + * in a project that would be imported into the main Java project + * + * @param outputDirectory + * Where all the generated files will be placed + */ + public GenerateModels(final File outputDirectory) { + final File packageDirectory = new File(outputDirectory, "/com/hpe/adm/nga/sdk"); + modelDirectory = new File(packageDirectory, "model"); + modelDirectory.mkdirs(); + entitiesDirectory = new File(packageDirectory, "entities"); + entitiesDirectory.mkdirs(); + enumsDirectory = new File(packageDirectory, "enums"); + enumsDirectory.mkdirs(); + + final VelocityEngine velocityEngine = new VelocityEngine(); + velocityEngine.setProperty("resource.loader", "class"); + velocityEngine.setProperty("class.resource.loader.description", "Velocity Classpath Resource Loader"); + velocityEngine.setProperty("runtime.log.logsystem.log4j.logger", "root"); + velocityEngine.setProperty("class.resource.loader.class", + "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); + + velocityEngine.init(); + + template = velocityEngine.getTemplate("/EntityModel.vm"); + interfaceTemplate = velocityEngine.getTemplate("/Entity.vm"); + entityListTemplate = velocityEngine.getTemplate("/TypedEntityList.vm"); + phasesTemplate = velocityEngine.getTemplate("/Phases.vm"); + listsTemplate = velocityEngine.getTemplate("/Lists.vm"); + } + + /** + * Run the actual generation + * + * @param clientId + * The client id + * @param clientSecret + * The client secret + * @param server + * The server including the protocol and port + * @param sharedSpace + * The SS id + * @param workSpace + * The WS id + * @throws IOException + * A problem with the generation of the entities + */ + public void generate(String clientId, String clientSecret, String server, long sharedSpace, long workSpace) + throws IOException { + // work around for work_items_root + final Octane octanePrivate = new Octane.Builder( + new SimpleClientAuthentication(clientId, clientSecret, "HPE_REST_API_TECH_PREVIEW")) + .sharedSpace(sharedSpace) + .workSpace(workSpace) + .Server(server) + .build(); + final EntityMetadata work_items_root = octanePrivate.metadata() + .entities("work_item_root") + .execute() + .iterator() + .next(); + final Collection work_items_rootFields = octanePrivate.metadata() + .fields("work_item_root") + .execute(); + octanePrivate.signOut(); + + final Octane octane = new Octane.Builder(new SimpleClientAuthentication(clientId, clientSecret)) + .sharedSpace(sharedSpace) + .workSpace(workSpace) + .Server(server) + .build(); + final Metadata metadata = octane.metadata(); + final Collection entityMetadata = metadata.entities().execute(); + entityMetadata.add(work_items_root); + + final Map logicalNameToListsMap = generateLists(octane); + final Set availablePhases = generatePhases(octane); + + for (EntityMetadata entityMetadatum : entityMetadata) { + final String name = entityMetadatum.getName(); + final String interfaceName = GeneratorHelper.camelCaseFieldName(name) + "Entity"; + final Collection fieldMetadata = generateEntity(work_items_rootFields, metadata, + entityMetadata, entityMetadatum, name, interfaceName, logicalNameToListsMap, availablePhases); + generateInterface(entityMetadatum, name, interfaceName); + generateEntityList(entityMetadatum, name, fieldMetadata); + } + } + + private Map generateLists(Octane octane) throws IOException { + final Collection listNodes = octane.entityList("list_nodes") + .get() + .addFields("name", "list_root", "id", "logical_name") + .execute(); + final Map> mappedListNodes = new HashMap<>(); + final Map logicalNameToNameMap = new HashMap<>(); + listNodes.forEach(listNode -> { + final String rootId; + final ReferenceFieldModel list_root = (ReferenceFieldModel) listNode.getValue("list_root"); + final EntityModel list_rootValue = list_root.getValue(); + final String name; + if (list_rootValue != null) { + rootId = list_rootValue.getId(); + name = ((StringFieldModel) listNode.getValue("name")).getValue() + .replaceAll(" ", "_") + .replaceAll("^\\d", "_$0") + .replaceAll("\\W", "_") + .toUpperCase(); + } else { + rootId = listNode.getId(); + name = GeneratorHelper.camelCaseFieldName( + ((StringFieldModel) listNode.getValue("name")).getValue().replaceAll("\\W", "_")); + logicalNameToNameMap.put(((StringFieldModel) listNode.getValue("logical_name")).getValue(), name); + } + final List listHierarchy = mappedListNodes.computeIfAbsent(rootId, k -> new ArrayList<>()); + + final String[] listNodeInfo = { name, ((StringFieldModel) listNode.getValue("id")).getValue() }; + if (list_rootValue == null) { + listHierarchy.add(0, listNodeInfo); + } else { + listHierarchy.add(listNodeInfo); + } + }); + + final VelocityContext velocityContext = new VelocityContext(); + velocityContext.put("listNodes", mappedListNodes); + final FileWriter fileWriter = new FileWriter(new File(enumsDirectory, "Lists.java")); + listsTemplate.merge(velocityContext, fileWriter); + fileWriter.close(); + + return logicalNameToNameMap; + } + + private Set generatePhases(Octane octane) throws IOException { + final Map> phaseMap = new HashMap<>(); + final Collection phases = octane.entityList("phases") + .get() + .addFields("id", "name", "entity") + .execute(); + phases.forEach(phase -> { + final Set phaseValueSet = new HashSet<>(); + phaseValueSet.add(new String[] { phase.getId(), + ((StringFieldModel) phase.getValue("name")).getValue() + .replaceAll(" ", "_") + .replaceAll("&", "N") + .toUpperCase() }); + phaseMap.merge( + GeneratorHelper.camelCaseFieldName(((StringFieldModel) phase.getValue("entity")).getValue(), true), + phaseValueSet, (existingValues, newValues) -> { + existingValues.addAll(newValues); + return existingValues; + }); + }); + + final VelocityContext velocityContext = new VelocityContext(); + velocityContext.put("phaseMap", phaseMap); + final FileWriter fileWriter = new FileWriter(new File(enumsDirectory, "Phases.java")); + phasesTemplate.merge(velocityContext, fileWriter); + fileWriter.close(); + + return phaseMap.keySet(); + } + + private Collection generateEntity(Collection work_items_rootFields, Metadata metadata, + Collection entityMetadata, EntityMetadata entityMetadatum, String name, + String interfaceName, Map logicalNameToListsMap, Set availablePhases) + throws IOException { + final Collection fieldMetadata = name.equals("work_item_root") ? work_items_rootFields + : metadata.fields(name).execute(); + + final TreeMap> collectedReferences = fieldMetadata.stream() + .filter(FieldMetadata::isRequired) + .collect(Collectors.toMap(FieldMetadata::getName, fieldMetadata1 -> { + final List references = new ArrayList<>(); + final String className = GeneratorHelper.camelCaseFieldName(entityMetadatum.getName()); + if (fieldMetadata1.getName().equals("phase") && availablePhases.contains(className)) { + references.add("com.hpe.adm.nga.sdk.enums.Phases." + className + "Phase"); + } else if (fieldMetadata1.getFieldType() == FieldMetadata.FieldType.Reference) { + if ((!entityMetadatum.getName().equals("list_node")) + && (fieldMetadata1.getFieldTypedata().getTargets()[0].getType().equals("list_node"))) { + final String listName = logicalNameToListsMap + .get(fieldMetadata1.getFieldTypedata().getTargets()[0].logicalName()); + references.add("com.hpe.adm.nga.sdk.enums.Lists." + listName); + } else { + final GeneratorHelper.ReferenceMetadata referenceMetadata = GeneratorHelper + .getAllowedSuperTypesForReference(fieldMetadata1, entityMetadata); + if (fieldMetadata1.getFieldTypedata().isMultiple()) { + references.add(referenceMetadata.getReferenceClassForSignature()); + } else { + if (referenceMetadata.hasTypedReturn()) { + references.addAll(referenceMetadata.getReferenceTypes() + .stream() + .map(type -> GeneratorHelper.camelCaseFieldName(type).concat("EntityModel")) + .collect(Collectors.toSet())); + } + if (referenceMetadata.hasNonTypedReturn()) { + references.add("EntityModel"); + } + } + } + } else { + references.add(GeneratorHelper.getFieldTypeAsJava(fieldMetadata1.getFieldType())); + } + + return references; + }, (strings, strings2) -> { + throw new IllegalStateException("problem merging map"); + }, TreeMap::new)); + + final Set> requiredFields = new HashSet<>(); + if (!collectedReferences.isEmpty()) { + expandCollectedReferences(collectedReferences, new int[collectedReferences.size()], 0, requiredFields); + } + + final VelocityContext velocityContext = new VelocityContext(); + velocityContext.put("interfaceName", interfaceName); + velocityContext.put("entityMetadata", entityMetadatum); + velocityContext.put("fieldMetadata", fieldMetadata); + velocityContext.put("logicalNameToListsMap", logicalNameToListsMap); + velocityContext.put("entityMetadataCollection", entityMetadata); + velocityContext.put("GeneratorHelper", GeneratorHelper.class); + velocityContext.put("entityMetadataWrapper", GeneratorHelper.entityMetadataWrapper(entityMetadatum)); + velocityContext.put("availablePhases", availablePhases); + velocityContext.put("requiredFields", requiredFields); + + final FileWriter fileWriter = new FileWriter( + new File(modelDirectory, GeneratorHelper.camelCaseFieldName(name) + "EntityModel.java")); + template.merge(velocityContext, fileWriter); + + fileWriter.close(); + return fieldMetadata; + } + + private void expandCollectedReferences(final TreeMap> collectedReferences, + final int[] positions, final int pointer, final Set> output) { + final Object[] keyArray = collectedReferences.keySet().toArray(); + final Object o = keyArray[pointer]; + for (int i = 0; i < collectedReferences.get(o).size(); ++i) { + if (pointer == positions.length - 1) { + final List outputLine = new ArrayList<>(positions.length); + for (int j = 0; j < positions.length; ++j) { + outputLine.add(new String[] { (String) keyArray[j], + collectedReferences.get(keyArray[j]).get(positions[j]) }); + } + output.add(outputLine); + } else { + expandCollectedReferences(collectedReferences, positions, pointer + 1, output); + } + positions[pointer]++; + } + positions[pointer] = 0; + } + + private void generateInterface(EntityMetadata entityMetadatum, String name, String interfaceName) + throws IOException { + // interface + final VelocityContext interfaceVelocityContext = new VelocityContext(); + final Optional subTypeOfFeature = entityMetadatum.features() + .stream() + .filter(feature -> feature instanceof SubTypesOfFeature) + .findAny(); + + interfaceVelocityContext.put("interfaceName", interfaceName); + interfaceVelocityContext.put("superInterfaceName", + (subTypeOfFeature + .map(feature -> GeneratorHelper.camelCaseFieldName(((SubTypesOfFeature) feature).getType())) + .orElse("")) + "Entity"); + + final FileWriter interfaceFileWriter = new FileWriter( + new File(modelDirectory, GeneratorHelper.camelCaseFieldName(name) + "Entity.java")); + interfaceTemplate.merge(interfaceVelocityContext, interfaceFileWriter); + + interfaceFileWriter.close(); + } + + private void generateEntityList(EntityMetadata entityMetadatum, String name, + Collection fieldMetadata) throws IOException { + // entityList + final Optional hasRestFeature = entityMetadatum.features() + .stream() + .filter(feature -> feature instanceof RestFeature) + .findFirst(); + // if not then something is wrong! + if (hasRestFeature.isPresent()) { + final RestFeature restFeature = (RestFeature) hasRestFeature.get(); + + final VelocityContext entityListVelocityContext = new VelocityContext(); + entityListVelocityContext.put("helper", GeneratorHelper.class); + entityListVelocityContext.put("type", GeneratorHelper.camelCaseFieldName(name)); + entityListVelocityContext.put("url", restFeature.getUrl()); + entityListVelocityContext.put("availableFields", + fieldMetadata.stream().map(FieldMetadata::getName).collect(Collectors.toList())); + entityListVelocityContext.put("sortableFields", + fieldMetadata.stream().filter(FieldMetadata::isSortable).map(FieldMetadata::getName).collect( + Collectors.toList())); + + final String[] restFeatureMethods = restFeature.getMethods(); + for (String restFeatureMethod : restFeatureMethods) { + switch (restFeatureMethod) { + case "GET": + entityListVelocityContext.put("hasGet", true); + break; + case "POST": + entityListVelocityContext.put("hasCreate", true); + break; + case "PUT": + entityListVelocityContext.put("hasUpdate", true); + break; + case "DELETE": + entityListVelocityContext.put("hasDelete", true); + break; + } + } + + final FileWriter entityListFileWriter = new FileWriter( + new File(entitiesDirectory, GeneratorHelper.camelCaseFieldName(name) + "EntityList.java")); + entityListTemplate.merge(entityListVelocityContext, entityListFileWriter); + + entityListFileWriter.close(); + } + } +} diff --git a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModelsPlugin.java b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModelsPlugin.java index 66b5b1d8..fc22acb2 100644 --- a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModelsPlugin.java +++ b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModelsPlugin.java @@ -13,6 +13,9 @@ */ package com.hpe.adm.nga.sdk.generate; +import java.io.File; +import java.io.IOException; + import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; @@ -20,33 +23,31 @@ import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; -import java.io.File; -import java.io.IOException; - @Mojo(name = "generate", defaultPhase = LifecyclePhase.GENERATE_SOURCES, threadSafe = true) public class GenerateModelsPlugin extends AbstractMojo { - @Parameter(defaultValue = "${project.build.directory}/generated-sources") - private File generatedSourcesDirectory; - @Parameter(required = true) - private String clientId; - @Parameter(required = true) - private String clientSecret; - @Parameter(required = true) - private String server; - @Parameter(required = true) - private long sharedSpace; - @Parameter(required = true) - private long workSpace; + @Parameter(defaultValue = "${project.build.directory}/generated-sources") + private File generatedSourcesDirectory; + @Parameter(required = true) + private String clientId; + @Parameter(required = true) + private String clientSecret; + @Parameter(required = true) + private String server; + @Parameter(required = true) + private long sharedSpace; + @Parameter(required = true) + private long workSpace; - @Override - public void execute() throws MojoExecutionException, MojoFailureException { - getLog().info("Starting to generate entities"); - try { - new GenerateModels(generatedSourcesDirectory).generate(clientId, clientSecret, server, sharedSpace, workSpace); - } catch (IOException e) { - throw new MojoExecutionException("Problem generating entities", e); - } - getLog().info("Finished generating entities"); - } + @Override + public void execute() throws MojoExecutionException, MojoFailureException { + getLog().info("Starting to generate entities"); + try { + new GenerateModels(generatedSourcesDirectory).generate(clientId, clientSecret, server, sharedSpace, + workSpace); + } catch (IOException e) { + throw new MojoExecutionException("Problem generating entities", e); + } + getLog().info("Finished generating entities"); + } } diff --git a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GeneratorHelper.java b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GeneratorHelper.java index 05c7e0c5..ab8c3190 100644 --- a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GeneratorHelper.java +++ b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GeneratorHelper.java @@ -13,6 +13,8 @@ */ package com.hpe.adm.nga.sdk.generate; +import java.util.*; + import com.hpe.adm.nga.sdk.metadata.EntityMetadata; import com.hpe.adm.nga.sdk.metadata.FieldMetadata; import com.hpe.adm.nga.sdk.metadata.features.Feature; @@ -20,290 +22,290 @@ import com.hpe.adm.nga.sdk.metadata.features.SubTypesOfFeature; import com.hpe.adm.nga.sdk.model.*; -import java.util.*; - /** * A class that is used to help with entity generation */ @SuppressWarnings("ALL") public final class GeneratorHelper { - private static final String keywords[] = {"abstract", "assert", "boolean", - "break", "byte", "case", "catch", "char", "class", "const", - "continue", "default", "do", "double", "else", "extends", "false", - "final", "finally", "float", "for", "goto", "if", "implements", - "import", "instanceof", "int", "interface", "long", "native", - "new", "null", "package", "private", "protected", "public", - "return", "short", "static", "strictfp", "super", "switch", - "synchronized", "this", "throw", "throws", "transient", "true", - "try", "void", "volatile", "while"}; - - public static String camelCaseFieldName(final String fieldName) { - return camelCaseFieldName(fieldName, true); - } - - /** - * Convert fieldName to camelCase form. - * - * @param fieldName the field name - * @param theFirstLetterIsCapital - set true if the first letter in first world should be capital - * @return the name in camelCase - */ - public static String camelCaseFieldName(final String fieldName, boolean theFirstLetterIsCapital) { - final StringBuffer stringBuffer = new StringBuffer(); - final String[] splitFields = fieldName.split("_"); - int wordCounter = 0; - for (final String splitField : splitFields) { - wordCounter++; - try { - if (wordCounter > 1 || theFirstLetterIsCapital) { - stringBuffer.append(splitField.substring(0, 1).toUpperCase()); - } else { - stringBuffer.append(splitField.substring(0, 1).toLowerCase()); - } - stringBuffer.append(splitField.substring(1)); - } catch (StringIndexOutOfBoundsException e) { - e.getCause(); - // we do nothing here and move to the next wordcounter - } - - } - - return getSanitisedFieldName(stringBuffer.toString()); - } - - public static String convertToUpperCase(final String fieldName) { - final StringBuffer stringBuffer = new StringBuffer(); - final String[] splitFields = fieldName.split("_"); - for (final String splitField : splitFields) { - stringBuffer.append(splitField.toUpperCase()); - } - - return stringBuffer.toString(); - } - - public static String getSanitisedFieldName(final String fieldName) { - return Arrays.binarySearch(keywords, fieldName) >= 0 ? "_" + fieldName : fieldName; - } - - public static String getFieldTypeAsJava(FieldMetadata.FieldType fieldType) { - switch (fieldType) { - case Date: - case DateTime: - return "java.time.ZonedDateTime"; - case Boolean: - return "Boolean"; - case Float: - return "Float"; - case Integer: - return "Long"; - case Memo: - case String: - return "String"; - case Object: - return "String"; - case Reference: - return "Object"; - } - - throw new UnsupportedOperationException("type: " + fieldType + "is not supported!"); - } - - public static String getFieldModel(FieldMetadata field) { - switch (field.getFieldType()) { - case Date: - case DateTime: - return DateFieldModel.class.getName(); - case Boolean: - return BooleanFieldModel.class.getName(); - case Float: - return FloatFieldModel.class.getName(); - case Integer: - return LongFieldModel.class.getName(); - case Memo: - case String: - return StringFieldModel.class.getName(); - case Object: - return StringFieldModel.class.getName(); - case Reference: - return field.getFieldTypedata().isMultiple() ? MultiReferenceFieldModel.class.getName() : ReferenceFieldModel.class.getName(); - } - - throw new UnsupportedOperationException("type: " + field.getFieldType() + "is not supported!"); - } - - public static String getSubTypeOf(final EntityMetadata entityMetadata) { - final Optional subTypeOfFeature = getSubTypeOfFeature(entityMetadata); - return (subTypeOfFeature.isPresent() ? camelCaseFieldName(((SubTypesOfFeature) subTypeOfFeature.get()).getType()) : "Typed") + "EntityModel"; - } - - private static Optional getSubTypeOfFeature(EntityMetadata entityMetadata) { - final Collection features = entityMetadata.features(); - return features.stream().filter(feature -> feature instanceof SubTypesOfFeature).findFirst(); - } - - public static final class ReferenceMetadata { - private String referenceClassForSignature; - private final Set allowedReferencesForAnnotation = new HashSet<>(); - private boolean hasNonTypedReturn = false; - private boolean hasTypedReturn = false; - private final Set referenceTypes = new HashSet<>(); - private String typedType; - - public String getReferenceClassForSignature() { - return referenceClassForSignature; - } - - public String getTypedType() { - return typedType; - } - - public Set getAllowedReferencesForAnnotation() { - return allowedReferencesForAnnotation; - } - - public Set getReferenceTypes() { - return referenceTypes; - } - - public boolean hasNonTypedReturn() { - return hasNonTypedReturn; - } - - public boolean hasTypedReturn() { - return hasTypedReturn; - } - } - - public static ReferenceMetadata getAllowedSuperTypesForReference(final FieldMetadata fieldMetadata, final Collection entityMetadataCollection) { - final ReferenceMetadata referenceMetadata = new ReferenceMetadata(); - - if (fieldMetadata.getFieldType() != FieldMetadata.FieldType.Reference) { - return null; - } - - final FieldMetadata.FieldTypeData fieldTypedata = fieldMetadata.getFieldTypedata(); - final FieldMetadata.Target[] targets = fieldTypedata.getTargets(); - - for (FieldMetadata.Target target : targets) { - final String type = target.getType(); - final Optional matchingEntityMetadata = entityMetadataCollection.stream().filter(entityMetadata -> entityMetadata.getName().equals(type)).findAny(); - if (matchingEntityMetadata.isPresent()) { - String camelCaseFieldName = camelCaseFieldName(type); - referenceMetadata.allowedReferencesForAnnotation.add(camelCaseFieldName + "EntityModel.class"); - referenceMetadata.referenceTypes.add(type); - final EntityMetadata matchedEntityMetadata = matchingEntityMetadata.get(); - final Optional subTypeOfFeature = getSubTypeOfFeature(matchedEntityMetadata); - final String typedType = camelCaseFieldName(subTypeOfFeature.isPresent() ? (((SubTypesOfFeature) subTypeOfFeature.get()).getType()) : type); - referenceMetadata.typedType = typedType + "Entity"; - - boolean hasMultipleTypes = false; - if (!referenceMetadata.hasNonTypedReturn) { - if (referenceMetadata.hasTypedReturn) { - camelCaseFieldName = typedType; - hasMultipleTypes = true; - } - referenceMetadata.referenceClassForSignature = - getReferenceSignature(fieldTypedata.isMultiple(), hasMultipleTypes, camelCaseFieldName + "Entity"); - } - referenceMetadata.hasTypedReturn = true; - } else { - referenceMetadata.allowedReferencesForAnnotation.add("EntityModel.class"); - referenceMetadata.hasNonTypedReturn = true; - referenceMetadata.referenceClassForSignature = - getReferenceSignature(fieldTypedata.isMultiple(), referenceMetadata.hasTypedReturn, "Entity"); - } - } - - return referenceMetadata; - } - - private static String getReferenceSignature(final boolean isMultiple, final boolean hasMulipleTypes, final String referenceEntity) { - final StringBuilder stringBuilder = new StringBuilder(); - if (isMultiple) { - stringBuilder.append("java.util.Collection<"); - /* - If 1 type of Definitive: - BlaEntityModel - Else If 1 type of non definitive - EntityModel - Else If >1 type of Definitive - ? extends BlaEntity - Else if >1 type of non definitive - ? extends Entity - */ - if (hasMulipleTypes) { - stringBuilder.append("? extends "); - } - stringBuilder.append(referenceEntity); - if (!hasMulipleTypes) { - stringBuilder.append("Model"); - } - stringBuilder.append(">"); - } else { - /* - If 1 type of Definitive: - BlaEntityModel - Else If 1 type of non definitive - EntityModel - Else If >1 type of Definitive - T - Else if >1 type of non definitive - T - */ - if (hasMulipleTypes) { - stringBuilder.append(" T"); - } - } - return stringBuilder.toString(); - } - - public static final class EntityMetadataWrapper { - com.hpe.adm.nga.sdk.model.EntityMetadata.AvailableMethods[] availableMethods = new com.hpe.adm.nga.sdk.model.EntityMetadata.AvailableMethods[0]; - String url; - - public com.hpe.adm.nga.sdk.model.EntityMetadata.AvailableMethods[] getAvailableMethods() { - return availableMethods; - } - - public String getUrl() { - return url; - } - } - - public static EntityMetadataWrapper entityMetadataWrapper(final EntityMetadata entityMetadata) { - final EntityMetadataWrapper entityMetadataWrapper = new EntityMetadataWrapper(); - final Optional restFeatureOptional = entityMetadata.features().stream().filter(feature -> feature instanceof RestFeature).findAny(); - if (!restFeatureOptional.isPresent()) { - return entityMetadataWrapper; - } - - final RestFeature restFeature = (RestFeature) restFeatureOptional.get(); - final String[] methods = restFeature.getMethods(); - entityMetadataWrapper.availableMethods = new com.hpe.adm.nga.sdk.model.EntityMetadata.AvailableMethods[methods.length]; - for (int i = 0; i < methods.length; ++i) { - switch (methods[i]) { - case "GET": - entityMetadataWrapper.availableMethods[i] = com.hpe.adm.nga.sdk.model.EntityMetadata.AvailableMethods.GET; - break; - case "POST": - entityMetadataWrapper.availableMethods[i] = com.hpe.adm.nga.sdk.model.EntityMetadata.AvailableMethods.CREATE; - break; - case "PUT": - entityMetadataWrapper.availableMethods[i] = com.hpe.adm.nga.sdk.model.EntityMetadata.AvailableMethods.UPDATE; - break; - case "DELETE": - entityMetadataWrapper.availableMethods[i] = com.hpe.adm.nga.sdk.model.EntityMetadata.AvailableMethods.DELETE; - break; - } - } - entityMetadataWrapper.url = restFeature.getUrl(); - return entityMetadataWrapper; - } + private static final String keywords[] = { "abstract", "assert", "boolean", "break", "byte", "case", "catch", + "char", "class", "const", "continue", "default", "do", "double", "else", "extends", "false", "final", + "finally", "float", "for", "goto", "if", "implements", "import", "instanceof", "int", "interface", "long", + "native", "new", "null", "package", "private", "protected", "public", "return", "short", "static", + "strictfp", "super", "switch", "synchronized", "this", "throw", "throws", "transient", "true", "try", + "void", "volatile", "while" }; + + public static String camelCaseFieldName(final String fieldName) { + return camelCaseFieldName(fieldName, true); + } + + /** + * Convert fieldName to camelCase form. + * + * @param fieldName + * the field name + * @param theFirstLetterIsCapital + * - set true if the first letter in first world should be + * capital + * @return the name in camelCase + */ + public static String camelCaseFieldName(final String fieldName, boolean theFirstLetterIsCapital) { + final StringBuffer stringBuffer = new StringBuffer(); + final String[] splitFields = fieldName.split("_"); + int wordCounter = 0; + for (final String splitField : splitFields) { + wordCounter++; + try { + if (wordCounter > 1 || theFirstLetterIsCapital) { + stringBuffer.append(splitField.substring(0, 1).toUpperCase()); + } else { + stringBuffer.append(splitField.substring(0, 1).toLowerCase()); + } + stringBuffer.append(splitField.substring(1)); + } catch (StringIndexOutOfBoundsException e) { + e.getCause(); + // we do nothing here and move to the next wordcounter + } + + } + + return getSanitisedFieldName(stringBuffer.toString()); + } + + public static String convertToUpperCase(final String fieldName) { + final StringBuffer stringBuffer = new StringBuffer(); + final String[] splitFields = fieldName.split("_"); + for (final String splitField : splitFields) { + stringBuffer.append(splitField.toUpperCase()); + } + + return stringBuffer.toString(); + } + + public static String getSanitisedFieldName(final String fieldName) { + return Arrays.binarySearch(keywords, fieldName) >= 0 ? "_" + fieldName : fieldName; + } + + public static String getFieldTypeAsJava(FieldMetadata.FieldType fieldType) { + switch (fieldType) { + case Date: + case DateTime: + return "java.time.ZonedDateTime"; + case Boolean: + return "Boolean"; + case Float: + return "Float"; + case Integer: + return "Long"; + case Memo: + case String: + return "String"; + case Object: + return "String"; + case Reference: + return "Object"; + } + + throw new UnsupportedOperationException("type: " + fieldType + "is not supported!"); + } + + public static String getFieldModel(FieldMetadata field) { + switch (field.getFieldType()) { + case Date: + case DateTime: + return DateFieldModel.class.getName(); + case Boolean: + return BooleanFieldModel.class.getName(); + case Float: + return FloatFieldModel.class.getName(); + case Integer: + return LongFieldModel.class.getName(); + case Memo: + case String: + return StringFieldModel.class.getName(); + case Object: + return StringFieldModel.class.getName(); + case Reference: + return field.getFieldTypedata().isMultiple() ? MultiReferenceFieldModel.class.getName() + : ReferenceFieldModel.class.getName(); + } + + throw new UnsupportedOperationException("type: " + field.getFieldType() + "is not supported!"); + } + + public static String getSubTypeOf(final EntityMetadata entityMetadata) { + final Optional subTypeOfFeature = getSubTypeOfFeature(entityMetadata); + return (subTypeOfFeature.isPresent() + ? camelCaseFieldName(((SubTypesOfFeature) subTypeOfFeature.get()).getType()) + : "Typed") + "EntityModel"; + } + + private static Optional getSubTypeOfFeature(EntityMetadata entityMetadata) { + final Collection features = entityMetadata.features(); + return features.stream().filter(feature -> feature instanceof SubTypesOfFeature).findFirst(); + } + + public static final class ReferenceMetadata { + private String referenceClassForSignature; + private final Set allowedReferencesForAnnotation = new HashSet<>(); + private boolean hasNonTypedReturn = false; + private boolean hasTypedReturn = false; + private final Set referenceTypes = new HashSet<>(); + private String typedType; + + public String getReferenceClassForSignature() { + return referenceClassForSignature; + } + + public String getTypedType() { + return typedType; + } + + public Set getAllowedReferencesForAnnotation() { + return allowedReferencesForAnnotation; + } + + public Set getReferenceTypes() { + return referenceTypes; + } + + public boolean hasNonTypedReturn() { + return hasNonTypedReturn; + } + + public boolean hasTypedReturn() { + return hasTypedReturn; + } + } + + public static ReferenceMetadata getAllowedSuperTypesForReference(final FieldMetadata fieldMetadata, + final Collection entityMetadataCollection) { + final ReferenceMetadata referenceMetadata = new ReferenceMetadata(); + + if (fieldMetadata.getFieldType() != FieldMetadata.FieldType.Reference) { + return null; + } + + final FieldMetadata.FieldTypeData fieldTypedata = fieldMetadata.getFieldTypedata(); + final FieldMetadata.Target[] targets = fieldTypedata.getTargets(); + + for (FieldMetadata.Target target : targets) { + final String type = target.getType(); + final Optional matchingEntityMetadata = entityMetadataCollection.stream() + .filter(entityMetadata -> entityMetadata.getName().equals(type)) + .findAny(); + if (matchingEntityMetadata.isPresent()) { + String camelCaseFieldName = camelCaseFieldName(type); + referenceMetadata.allowedReferencesForAnnotation.add(camelCaseFieldName + "EntityModel.class"); + referenceMetadata.referenceTypes.add(type); + final EntityMetadata matchedEntityMetadata = matchingEntityMetadata.get(); + final Optional subTypeOfFeature = getSubTypeOfFeature(matchedEntityMetadata); + final String typedType = camelCaseFieldName( + subTypeOfFeature.isPresent() ? (((SubTypesOfFeature) subTypeOfFeature.get()).getType()) : type); + referenceMetadata.typedType = typedType + "Entity"; + + boolean hasMultipleTypes = false; + if (!referenceMetadata.hasNonTypedReturn) { + if (referenceMetadata.hasTypedReturn) { + camelCaseFieldName = typedType; + hasMultipleTypes = true; + } + referenceMetadata.referenceClassForSignature = getReferenceSignature(fieldTypedata.isMultiple(), + hasMultipleTypes, camelCaseFieldName + "Entity"); + } + referenceMetadata.hasTypedReturn = true; + } else { + referenceMetadata.allowedReferencesForAnnotation.add("EntityModel.class"); + referenceMetadata.hasNonTypedReturn = true; + referenceMetadata.referenceClassForSignature = getReferenceSignature(fieldTypedata.isMultiple(), + referenceMetadata.hasTypedReturn, "Entity"); + } + } + + return referenceMetadata; + } + + private static String getReferenceSignature(final boolean isMultiple, final boolean hasMulipleTypes, + final String referenceEntity) { + final StringBuilder stringBuilder = new StringBuilder(); + if (isMultiple) { + stringBuilder.append("java.util.Collection<"); + /* + * If 1 type of Definitive: BlaEntityModel Else If 1 type of non + * definitive EntityModel Else If >1 type of Definitive ? extends + * BlaEntity Else if >1 type of non definitive ? extends Entity + */ + if (hasMulipleTypes) { + stringBuilder.append("? extends "); + } + stringBuilder.append(referenceEntity); + if (!hasMulipleTypes) { + stringBuilder.append("Model"); + } + stringBuilder.append(">"); + } else { + /* + * If 1 type of Definitive: BlaEntityModel Else If 1 type of non + * definitive EntityModel Else If >1 type of Definitive T Else if >1 type of non definitive + * T + */ + if (hasMulipleTypes) { + stringBuilder.append(" T"); + } + } + return stringBuilder.toString(); + } + + public static final class EntityMetadataWrapper { + com.hpe.adm.nga.sdk.model.EntityMetadata.AvailableMethods[] availableMethods = new com.hpe.adm.nga.sdk.model.EntityMetadata.AvailableMethods[0]; + String url; + + public com.hpe.adm.nga.sdk.model.EntityMetadata.AvailableMethods[] getAvailableMethods() { + return availableMethods; + } + + public String getUrl() { + return url; + } + } + + public static EntityMetadataWrapper entityMetadataWrapper(final EntityMetadata entityMetadata) { + final EntityMetadataWrapper entityMetadataWrapper = new EntityMetadataWrapper(); + final Optional restFeatureOptional = entityMetadata.features() + .stream() + .filter(feature -> feature instanceof RestFeature) + .findAny(); + if (!restFeatureOptional.isPresent()) { + return entityMetadataWrapper; + } + + final RestFeature restFeature = (RestFeature) restFeatureOptional.get(); + final String[] methods = restFeature.getMethods(); + entityMetadataWrapper.availableMethods = new com.hpe.adm.nga.sdk.model.EntityMetadata.AvailableMethods[methods.length]; + for (int i = 0; i < methods.length; ++i) { + switch (methods[i]) { + case "GET": + entityMetadataWrapper.availableMethods[i] = com.hpe.adm.nga.sdk.model.EntityMetadata.AvailableMethods.GET; + break; + case "POST": + entityMetadataWrapper.availableMethods[i] = com.hpe.adm.nga.sdk.model.EntityMetadata.AvailableMethods.CREATE; + break; + case "PUT": + entityMetadataWrapper.availableMethods[i] = com.hpe.adm.nga.sdk.model.EntityMetadata.AvailableMethods.UPDATE; + break; + case "DELETE": + entityMetadataWrapper.availableMethods[i] = com.hpe.adm.nga.sdk.model.EntityMetadata.AvailableMethods.DELETE; + break; + } + } + entityMetadataWrapper.url = restFeature.getUrl(); + return entityMetadataWrapper; + } } From 6d933c7671a19e3141cde8ce81997a124c9bb9be Mon Sep 17 00:00:00 2001 From: Sergej Turkan Date: Wed, 6 Feb 2019 18:21:18 +0100 Subject: [PATCH 03/41] Reenable submodules --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index b51a990b..c7e946a5 100644 --- a/pom.xml +++ b/pom.xml @@ -57,10 +57,10 @@ sdk-src - - + sdk-integration-tests + sdk-usage-examples sdk-generate-entity-models-maven-plugin - + sdk-extension UTF-8 From cad14cb31014e54c08473c83480f4b1082ab966d Mon Sep 17 00:00:00 2001 From: Sergej Turkan Date: Wed, 6 Feb 2019 18:24:38 +0100 Subject: [PATCH 04/41] Adding some license headers --- cool.importorder | 13 ++++++++++++- eclipse-formatter.xml | 15 +++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/cool.importorder b/cool.importorder index cd4f3d96..b8e08817 100644 --- a/cool.importorder +++ b/cool.importorder @@ -1,5 +1,16 @@ +# Copyright 2017 EntIT Software LLC, a Micro Focus company, L.P. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + #Organize Import Order -#Fri Nov 03 08:00:24 CET 2017 5=liquibase 4=lombok 3=com diff --git a/eclipse-formatter.xml b/eclipse-formatter.xml index f0db3e7e..9c231746 100644 --- a/eclipse-formatter.xml +++ b/eclipse-formatter.xml @@ -1,4 +1,19 @@ + From 65a6acbee4103bb55b3cfa6e636b8b5390982484 Mon Sep 17 00:00:00 2001 From: Sergej Turkan Date: Wed, 6 Feb 2019 18:25:39 +0100 Subject: [PATCH 05/41] Changed phase generation to sort entities & phases in ASC --- .../adm/nga/sdk/generate/GenerateModels.java | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java index 39c86af8..384dace5 100644 --- a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java +++ b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java @@ -195,25 +195,29 @@ private Map generateLists(Octane octane) throws IOException { } private Set generatePhases(Octane octane) throws IOException { - final Map> phaseMap = new HashMap<>(); + final Map> phaseMap = new TreeMap<>(); final Collection phases = octane.entityList("phases") .get() .addFields("id", "name", "entity") .execute(); - phases.forEach(phase -> { - final Set phaseValueSet = new HashSet<>(); - phaseValueSet.add(new String[] { phase.getId(), - ((StringFieldModel) phase.getValue("name")).getValue() - .replaceAll(" ", "_") - .replaceAll("&", "N") - .toUpperCase() }); - phaseMap.merge( - GeneratorHelper.camelCaseFieldName(((StringFieldModel) phase.getValue("entity")).getValue(), true), - phaseValueSet, (existingValues, newValues) -> { - existingValues.addAll(newValues); - return existingValues; - }); - }); + phases.stream() + .sorted(Comparator.comparing(phase -> ((StringFieldModel) phase.getValue("name")).getValue())) + .forEach(phase -> { + final List phaseValueList = new ArrayList<>(); + phaseValueList.add(new String[] { phase.getId(), + ((StringFieldModel) phase.getValue("name")).getValue() + .replaceAll(" ", "_") + .replaceAll("&", "N") + .toUpperCase() }); + phaseMap.merge( + GeneratorHelper.camelCaseFieldName(((StringFieldModel) phase.getValue("entity")).getValue(), + true), + phaseValueList, // + (existingValues, newValues) -> { + existingValues.addAll(newValues); + return existingValues; + }); + }); final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("phaseMap", phaseMap); From 9d7751bc633a64708fa9e5c3234064aabebcad53 Mon Sep 17 00:00:00 2001 From: Sergej Turkan Date: Wed, 6 Feb 2019 18:32:58 +0100 Subject: [PATCH 06/41] Fixing import order file after addind license header. No empty lines allowed --- cool.importorder | 1 - 1 file changed, 1 deletion(-) diff --git a/cool.importorder b/cool.importorder index b8e08817..518fc628 100644 --- a/cool.importorder +++ b/cool.importorder @@ -9,7 +9,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - #Organize Import Order 5=liquibase 4=lombok From 0dc7777fcbe11e2902c3c825f5ac447921174ed5 Mon Sep 17 00:00:00 2001 From: "Robert.Schreib" Date: Thu, 7 Feb 2019 17:05:00 +0100 Subject: [PATCH 07/41] Generated Lists generates ordered file now --- .../adm/nga/sdk/generate/GenerateModels.java | 37 ++++++++++++++----- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java index 384dace5..e6f74ed6 100644 --- a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java +++ b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java @@ -16,7 +16,16 @@ import java.io.File; import java.io.FileWriter; import java.io.IOException; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.TreeMap; import java.util.stream.Collectors; import org.apache.velocity.Template; @@ -64,7 +73,7 @@ public class GenerateModels { /** * Initialise the class with the output directory. This should normally be * in a project that would be imported into the main Java project - * + * * @param outputDirectory * Where all the generated files will be placed */ @@ -95,7 +104,7 @@ public GenerateModels(final File outputDirectory) { /** * Run the actual generation - * + * * @param clientId * The client id * @param clientSecret @@ -157,18 +166,15 @@ private Map generateLists(Octane octane) throws IOException { .execute(); final Map> mappedListNodes = new HashMap<>(); final Map logicalNameToNameMap = new HashMap<>(); - listNodes.forEach(listNode -> { + + listNodes.stream().sorted(Comparator.comparing(this::getEntityModelName)).forEach(listNode -> { final String rootId; final ReferenceFieldModel list_root = (ReferenceFieldModel) listNode.getValue("list_root"); final EntityModel list_rootValue = list_root.getValue(); final String name; if (list_rootValue != null) { rootId = list_rootValue.getId(); - name = ((StringFieldModel) listNode.getValue("name")).getValue() - .replaceAll(" ", "_") - .replaceAll("^\\d", "_$0") - .replaceAll("\\W", "_") - .toUpperCase(); + name = getEntityModelName(listNode); } else { rootId = listNode.getId(); name = GeneratorHelper.camelCaseFieldName( @@ -185,8 +191,11 @@ private Map generateLists(Octane octane) throws IOException { } }); + final Map> sortedMappedListNodes = new TreeMap<>(); + mappedListNodes.values().forEach(strings -> sortedMappedListNodes.put(strings.get(0)[0], strings)); + final VelocityContext velocityContext = new VelocityContext(); - velocityContext.put("listNodes", mappedListNodes); + velocityContext.put("listNodes", sortedMappedListNodes); final FileWriter fileWriter = new FileWriter(new File(enumsDirectory, "Lists.java")); listsTemplate.merge(velocityContext, fileWriter); fileWriter.close(); @@ -194,6 +203,14 @@ private Map generateLists(Octane octane) throws IOException { return logicalNameToNameMap; } + private String getEntityModelName(EntityModel listNode) { + return ((StringFieldModel) listNode.getValue("name")).getValue() + .replaceAll(" ", "_") + .replaceAll("^\\d", "_$0") + .replaceAll("\\W", "_") + .toUpperCase(); + } + private Set generatePhases(Octane octane) throws IOException { final Map> phaseMap = new TreeMap<>(); final Collection phases = octane.entityList("phases") From 032ce191fb98d7958c1afce54f097ea90beb3974 Mon Sep 17 00:00:00 2001 From: Sergej Turkan Date: Thu, 7 Feb 2019 18:51:48 +0100 Subject: [PATCH 08/41] Changed Entity generation to sort getter & setters by field name in ASC order --- .../java/com/hpe/adm/nga/sdk/generate/GenerateModels.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java index e6f74ed6..5800d757 100644 --- a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java +++ b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java @@ -249,9 +249,9 @@ private Collection generateEntity(Collection work_ Collection entityMetadata, EntityMetadata entityMetadatum, String name, String interfaceName, Map logicalNameToListsMap, Set availablePhases) throws IOException { - final Collection fieldMetadata = name.equals("work_item_root") ? work_items_rootFields - : metadata.fields(name).execute(); - + final List fieldMetadata = new ArrayList<>( + name.equals("work_item_root") ? work_items_rootFields : metadata.fields(name).execute()); + fieldMetadata.sort(Comparator.comparing(FieldMetadata::getName)); final TreeMap> collectedReferences = fieldMetadata.stream() .filter(FieldMetadata::isRequired) .collect(Collectors.toMap(FieldMetadata::getName, fieldMetadata1 -> { From e39ae06a9e4978a96838061b950e44d12f28bfc8 Mon Sep 17 00:00:00 2001 From: Sergej Turkan Date: Thu, 7 Feb 2019 18:58:19 +0100 Subject: [PATCH 09/41] Changed if else chains in EntityModel template with string switch cases statement introduced in java 1.7 --- .../src/main/resources/EntityModel.vm | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/sdk-generate-entity-models-maven-plugin/src/main/resources/EntityModel.vm b/sdk-generate-entity-models-maven-plugin/src/main/resources/EntityModel.vm index 053b4d8a..ed886d2f 100644 --- a/sdk-generate-entity-models-maven-plugin/src/main/resources/EntityModel.vm +++ b/sdk-generate-entity-models-maven-plugin/src/main/resources/EntityModel.vm @@ -153,13 +153,15 @@ public ${referenceMetadata.getReferenceClassForSignature()} get${GeneratorHelper return value.stream().map(entityModel -> { final StringFieldModel type = (StringFieldModel) entityModel.getValue("type"); final String referenceType = type.getValue(); + switch(referenceType) { #foreach($type in ${referenceMetadata.getReferenceTypes()}) - #if($foreach.count > 1)else #{end}if (referenceType.equals("${type}")) { - return new ${GeneratorHelper.camelCaseFieldName(${type})}EntityModel(entityModel); - }#{end}else { - return#if(${referenceMetadata.hasNonTypedReturn()}) entityModel; - #else new ${referenceMetadata.getTypedType()}Model(entityModel); - #end} + case "${type}": + return new ${GeneratorHelper.camelCaseFieldName(${type})}EntityModel(entityModel); + #{end} + default: + return#if(${referenceMetadata.hasNonTypedReturn()}) entityModel; + #else new ${referenceMetadata.getTypedType()}Model(entityModel);#end + } }) #else return value.stream().map(${GeneratorHelper.camelCaseFieldName(${referenceMetadata.getReferenceTypes().iterator().next()})}EntityModel::new) @@ -291,4 +293,4 @@ public ${referenceMetadata.getReferenceClassForSignature()} get${GeneratorHelper return this; } -#end \ No newline at end of file +#end From bcb69ebd027e5a97d7dcbc6296c7999341a487aa Mon Sep 17 00:00:00 2001 From: Sergej Turkan Date: Thu, 7 Feb 2019 19:10:52 +0100 Subject: [PATCH 10/41] Changed EntityList AvailableFields & SortableFields generation to sort enums by name in ASC order --- .../com/hpe/adm/nga/sdk/generate/GenerateModels.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java index 5800d757..0aa39605 100644 --- a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java +++ b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java @@ -373,10 +373,13 @@ private void generateEntityList(EntityMetadata entityMetadatum, String name, entityListVelocityContext.put("type", GeneratorHelper.camelCaseFieldName(name)); entityListVelocityContext.put("url", restFeature.getUrl()); entityListVelocityContext.put("availableFields", - fieldMetadata.stream().map(FieldMetadata::getName).collect(Collectors.toList())); + fieldMetadata.stream().map(FieldMetadata::getName).sorted().collect(Collectors.toList())); entityListVelocityContext.put("sortableFields", - fieldMetadata.stream().filter(FieldMetadata::isSortable).map(FieldMetadata::getName).collect( - Collectors.toList())); + fieldMetadata.stream() + .filter(FieldMetadata::isSortable) + .map(FieldMetadata::getName) + .sorted() + .collect(Collectors.toList())); final String[] restFeatureMethods = restFeature.getMethods(); for (String restFeatureMethod : restFeatureMethods) { From a8e08495583e87cf5ca063b60b95a2d964595e3b Mon Sep 17 00:00:00 2001 From: Sergej Turkan Date: Fri, 8 Feb 2019 21:43:17 +0100 Subject: [PATCH 11/41] Tuning spotless settings --- pom.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pom.xml b/pom.xml index c7e946a5..b70131f5 100644 --- a/pom.xml +++ b/pom.xml @@ -200,6 +200,8 @@ 1.17.0 + + sdk-generate-entity-models-maven-plugin/src/**/java/**/*.java From 54e8a1c435a9588fb4c859ffa00f8da1f2a41b07 Mon Sep 17 00:00:00 2001 From: Sergej Turkan Date: Fri, 8 Feb 2019 21:49:29 +0100 Subject: [PATCH 12/41] Changed Octane & GoogleHttpClient to allow disabling validating server SSL certificates --- .../main/java/com/hpe/adm/nga/sdk/Octane.java | 12 +++- .../sdk/network/google/GoogleHttpClient.java | 69 +++++++++++++++---- 2 files changed, 65 insertions(+), 16 deletions(-) diff --git a/sdk-src/src/main/java/com/hpe/adm/nga/sdk/Octane.java b/sdk-src/src/main/java/com/hpe/adm/nga/sdk/Octane.java index 49227393..a2c3d4f2 100644 --- a/sdk-src/src/main/java/com/hpe/adm/nga/sdk/Octane.java +++ b/sdk-src/src/main/java/com/hpe/adm/nga/sdk/Octane.java @@ -272,13 +272,23 @@ public Builder Server(String domain) { * @return a new Octane instance which has the set context and is correctly authenticated */ public Octane build() { + return this.build(false); + } + + /** + * The main build procedure which creates the {@link Octane} object and authenticates against the server + * + * @param doNotValidateCertificate - Disables validating server SSL certificates + * @return a new Octane instance which has the set context and is correctly authenticated + */ + public Octane build(final boolean doNotValidateCertificate) { Octane objOctane = null; logger.info("Building Octane context using {}", this); // Init default http client if it wasn't specified - this.octaneHttpClient = this.octaneHttpClient == null ? new GoogleHttpClient(urlDomain) : this.octaneHttpClient; + this.octaneHttpClient = this.octaneHttpClient == null ? new GoogleHttpClient(urlDomain, doNotValidateCertificate) : this.octaneHttpClient; if (octaneHttpClient.authenticate(authentication)) { objOctane = new Octane(octaneHttpClient, urlDomain, idsharedSpaceId, workSpaceId); diff --git a/sdk-src/src/main/java/com/hpe/adm/nga/sdk/network/google/GoogleHttpClient.java b/sdk-src/src/main/java/com/hpe/adm/nga/sdk/network/google/GoogleHttpClient.java index 12079a38..3bf8cc42 100644 --- a/sdk-src/src/main/java/com/hpe/adm/nga/sdk/network/google/GoogleHttpClient.java +++ b/sdk-src/src/main/java/com/hpe/adm/nga/sdk/network/google/GoogleHttpClient.java @@ -13,25 +13,51 @@ */ package com.hpe.adm.nga.sdk.network.google; -import com.google.api.client.http.*; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.net.HttpCookie; +import java.net.Proxy; +import java.net.ProxySelector; +import java.net.URI; +import java.security.GeneralSecurityException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.api.client.http.ByteArrayContent; +import com.google.api.client.http.FileContent; +import com.google.api.client.http.GenericUrl; +import com.google.api.client.http.HttpContent; +import com.google.api.client.http.HttpHeaders; +import com.google.api.client.http.HttpMediaType; +import com.google.api.client.http.HttpRequest; +import com.google.api.client.http.HttpRequestFactory; +import com.google.api.client.http.HttpRequestInitializer; +import com.google.api.client.http.HttpResponse; +import com.google.api.client.http.HttpResponseException; +import com.google.api.client.http.HttpStatusCodes; +import com.google.api.client.http.HttpTransport; +import com.google.api.client.http.InputStreamContent; +import com.google.api.client.http.MultipartContent; import com.google.api.client.http.javanet.NetHttpTransport; import com.hpe.adm.nga.sdk.authentication.Authentication; import com.hpe.adm.nga.sdk.exception.OctaneException; import com.hpe.adm.nga.sdk.exception.OctanePartialException; -import com.hpe.adm.nga.sdk.model.*; +import com.hpe.adm.nga.sdk.model.EntityModel; +import com.hpe.adm.nga.sdk.model.ErrorModel; +import com.hpe.adm.nga.sdk.model.LongFieldModel; +import com.hpe.adm.nga.sdk.model.ModelParser; +import com.hpe.adm.nga.sdk.model.StringFieldModel; import com.hpe.adm.nga.sdk.network.OctaneHttpClient; import com.hpe.adm.nga.sdk.network.OctaneHttpRequest; import com.hpe.adm.nga.sdk.network.OctaneHttpResponse; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.net.HttpCookie; -import java.net.Proxy; -import java.net.ProxySelector; -import java.net.URI; -import java.util.*; /** * HTTP Client using Google's API @@ -98,13 +124,26 @@ public class GoogleHttpClient implements OctaneHttpClient { }; public GoogleHttpClient(final String urlDomain) { + this(urlDomain, false); + } + + public GoogleHttpClient(final String urlDomain, final boolean doNotValidateCertificate) { this.urlDomain = urlDomain; logProxySystemProperties(); logSystemProxyForUrlDomain(urlDomain); - HttpTransport HTTP_TRANSPORT = new NetHttpTransport(); - requestFactory = HTTP_TRANSPORT.createRequestFactory(requestInitializer); + try { + final HttpTransport HTTP_TRANSPORT; + if (doNotValidateCertificate) { + HTTP_TRANSPORT = new NetHttpTransport.Builder().doNotValidateCertificate().build(); + } else { + HTTP_TRANSPORT = new NetHttpTransport(); + } + requestFactory = HTTP_TRANSPORT.createRequestFactory(requestInitializer); + } catch (final GeneralSecurityException e) { + throw new RuntimeException(e); + } } /** @@ -466,4 +505,4 @@ private static void logSystemProxyForUrlDomain(String urlDomain) { } } -} \ No newline at end of file +} From 19796be19bd70fbd32f6add2d26d57d9ffdb02cd Mon Sep 17 00:00:00 2001 From: Sergej Turkan Date: Fri, 8 Feb 2019 21:55:36 +0100 Subject: [PATCH 13/41] Adding helper to replace accented characters in field names --- pom.xml | 6 +- .../adm/nga/sdk/generate/GeneratorHelper.java | 138 ++++++++++++++++++ 2 files changed, 141 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index b70131f5..289ce27c 100644 --- a/pom.xml +++ b/pom.xml @@ -57,10 +57,10 @@ sdk-src - sdk-integration-tests - sdk-usage-examples + + sdk-generate-entity-models-maven-plugin - sdk-extension + UTF-8 diff --git a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GeneratorHelper.java b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GeneratorHelper.java index ab8c3190..af84c987 100644 --- a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GeneratorHelper.java +++ b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GeneratorHelper.java @@ -308,4 +308,142 @@ public static EntityMetadataWrapper entityMetadataWrapper(final EntityMetadata e entityMetadataWrapper.url = restFeature.getUrl(); return entityMetadataWrapper; } + + /** + * Replaces accented characters in a String by unaccented equivalents. + * + * @see https://www.mail-archive.com/java-user@lucene.apache.org/msg23562.html + * @param input - String + * @return cleaned String + */ + public final static String removeAccents(final String input) { + final StringBuffer result = new StringBuffer(); + for (int i = 0; i < input.length(); i++) { + switch (input.charAt(i)) { + case '\u00C0': // À + case '\u00C1': // Á + case '\u00C2': //  + case '\u00C3': // à + case '\u00C5': // Å + result.append("A"); + break; + case '\u00C4': // Ä + case '\u00C6': // Æ + result.append("AE"); + break; + case '\u00C7': // Ç + result.append("C"); + break; + case '\u00C8': // È + case '\u00C9': // É + case '\u00CA': // Ê + case '\u00CB': // Ë + result.append("E"); + break; + case '\u00CC': // Ì + case '\u00CD': // Í + case '\u00CE': // Î + case '\u00CF': // Ï + result.append("I"); + break; + case '\u00D0': // Ð + result.append("D"); + break; + case '\u00D1': // Ñ + result.append("N"); + break; + case '\u00D2': // Ò + case '\u00D3': // Ó + case '\u00D4': // Ô + case '\u00D5': // Õ + case '\u00D8': // Ø + result.append("O"); + break; + case '\u00D6': // Ö + case '\u0152': // Œ + result.append("OE"); + break; + case '\u00DE': // Þ + result.append("TH"); + break; + case '\u00D9': // Ù + case '\u00DA': // Ú + case '\u00DB': // Û + result.append("U"); + break; + case '\u00DC': // Ü + result.append("UE"); + break; + case '\u00DD': // Ý + case '\u0178': // Ÿ + result.append("Y"); + break; + case '\u00E0': // à + case '\u00E1': // á + case '\u00E2': // â + case '\u00E3': // ã + case '\u00E5': // å + result.append("a"); + break; + case '\u00E4': // ä + case '\u00E6': // æ + result.append("ae"); + break; + case '\u00E7': // ç + result.append("c"); + break; + case '\u00E8': // è + case '\u00E9': // é + case '\u00EA': // ê + case '\u00EB': // ë + result.append("e"); + break; + case '\u00EC': // ì + case '\u00ED': // í + case '\u00EE': // î + case '\u00EF': // ï + result.append("i"); + break; + case '\u00F0': // ð + result.append("d"); + break; + case '\u00F1': // ñ + result.append("n"); + break; + case '\u00F2': // ò + case '\u00F3': // ó + case '\u00F4': // ô + case '\u00F5': // õ + case '\u00F8': // ø + result.append("o"); + break; + case '\u00F6': // ö + case '\u0153': // œ + result.append("oe"); + break; + case '\u00DF': // ß + result.append("ss"); + break; + case '\u00FE': // þ + result.append("th"); + break; + case '\u00F9': // ù + case '\u00FA': // ú + case '\u00FB': // û + result.append("u"); + break; + case '\u00FC': // ü + result.append("ue"); + break; + case '\u00FD': // ý + case '\u00FF': // ÿ + result.append("y"); + break; + default: + result.append(input.charAt(i)); + break; + } + } + return result.toString(); + } } From 20040e10dc8f92b2d18d7d1e69b18db1074c23b6 Mon Sep 17 00:00:00 2001 From: Sergej Turkan Date: Fri, 8 Feb 2019 22:08:39 +0100 Subject: [PATCH 14/41] Added maven parameter to ignore ssl certificates --- .../adm/nga/sdk/generate/GenerateModels.java | 27 +++++++++++++++++-- .../sdk/generate/GenerateModelsPlugin.java | 4 ++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java index 0aa39605..83c04017 100644 --- a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java +++ b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java @@ -120,13 +120,36 @@ public GenerateModels(final File outputDirectory) { */ public void generate(String clientId, String clientSecret, String server, long sharedSpace, long workSpace) throws IOException { + this.generate(clientId, clientSecret, server, sharedSpace, workSpace, false); + } + + /** + * Run the actual generation + * + * @param clientId + * The client id + * @param clientSecret + * The client secret + * @param server + * The server including the protocol and port + * @param sharedSpace + * The SS id + * @param workSpace + * The WS id + * @param doNotValidateCertificate + * Disables validating server SSL certificates + * @throws IOException + * A problem with the generation of the entities + */ + public void generate(String clientId, String clientSecret, String server, long sharedSpace, long workSpace, + final boolean doNotValidateCertificate) throws IOException { // work around for work_items_root final Octane octanePrivate = new Octane.Builder( new SimpleClientAuthentication(clientId, clientSecret, "HPE_REST_API_TECH_PREVIEW")) .sharedSpace(sharedSpace) .workSpace(workSpace) .Server(server) - .build(); + .build(doNotValidateCertificate); final EntityMetadata work_items_root = octanePrivate.metadata() .entities("work_item_root") .execute() @@ -141,7 +164,7 @@ public void generate(String clientId, String clientSecret, String server, long s .sharedSpace(sharedSpace) .workSpace(workSpace) .Server(server) - .build(); + .build(doNotValidateCertificate); final Metadata metadata = octane.metadata(); final Collection entityMetadata = metadata.entities().execute(); entityMetadata.add(work_items_root); diff --git a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModelsPlugin.java b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModelsPlugin.java index fc22acb2..ea4cd3a6 100644 --- a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModelsPlugin.java +++ b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModelsPlugin.java @@ -38,13 +38,15 @@ public class GenerateModelsPlugin extends AbstractMojo { private long sharedSpace; @Parameter(required = true) private long workSpace; + @Parameter(defaultValue = "false") + private boolean doNotValidateCertificate; @Override public void execute() throws MojoExecutionException, MojoFailureException { getLog().info("Starting to generate entities"); try { new GenerateModels(generatedSourcesDirectory).generate(clientId, clientSecret, server, sharedSpace, - workSpace); + workSpace, doNotValidateCertificate); } catch (IOException e) { throw new MojoExecutionException("Problem generating entities", e); } From f5f3734e09218984826663702da91e2470d06e28 Mon Sep 17 00:00:00 2001 From: Sergej Turkan Date: Fri, 8 Feb 2019 22:21:20 +0100 Subject: [PATCH 15/41] Renamed import order file --- cool.importorder | 18 ------------------ importorder.properties | 7 +++++++ pom.xml | 13 ++++--------- 3 files changed, 11 insertions(+), 27 deletions(-) delete mode 100644 cool.importorder create mode 100644 importorder.properties diff --git a/cool.importorder b/cool.importorder deleted file mode 100644 index 518fc628..00000000 --- a/cool.importorder +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright 2017 EntIT Software LLC, a Micro Focus company, L.P. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#Organize Import Order -5=liquibase -4=lombok -3=com -2=org -1=javax -0=java diff --git a/importorder.properties b/importorder.properties new file mode 100644 index 00000000..eef2d923 --- /dev/null +++ b/importorder.properties @@ -0,0 +1,7 @@ +# Organize Import Order +5=liquibase +4=lombok +3=com +2=org +1=javax +0=java diff --git a/pom.xml b/pom.xml index 289ce27c..b5d11c3c 100644 --- a/pom.xml +++ b/pom.xml @@ -57,10 +57,10 @@ sdk-src - - + sdk-integration-tests + sdk-usage-examples sdk-generate-entity-models-maven-plugin - + sdk-extension UTF-8 @@ -144,11 +144,6 @@ commons-beanutils ${commons-beanutils.version}
- - org.apache.commons - commons-lang3 - ${commons-lang.version} - junit junit @@ -210,7 +205,7 @@ 4.7.1 - ${session.executionRootDirectory}/cool.importorder + ${session.executionRootDirectory}/importorder.properties From 67a1aef43f2e3c934e2dee127a640cef9cdc0538 Mon Sep 17 00:00:00 2001 From: Sergej Turkan Date: Fri, 8 Feb 2019 22:22:11 +0100 Subject: [PATCH 16/41] Changed generator to sign out after everything is done --- .../main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java | 1 + 1 file changed, 1 insertion(+) diff --git a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java index 83c04017..85c8b988 100644 --- a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java +++ b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java @@ -180,6 +180,7 @@ public void generate(String clientId, String clientSecret, String server, long s generateInterface(entityMetadatum, name, interfaceName); generateEntityList(entityMetadatum, name, fieldMetadata); } + octane.signOut(); } private Map generateLists(Octane octane) throws IOException { From e3642cc7c178764164876264094ecd5b9b7bc8ee Mon Sep 17 00:00:00 2001 From: Sergej Turkan Date: Fri, 8 Feb 2019 22:24:26 +0100 Subject: [PATCH 17/41] Changed list generator to query root list_nodes improved List template --- .../adm/nga/sdk/generate/GenerateModels.java | 54 +++++++++++-------- .../src/main/resources/Lists.vm | 25 +++++++-- 2 files changed, 54 insertions(+), 25 deletions(-) diff --git a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java index 85c8b988..3add1783 100644 --- a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java +++ b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java @@ -187,32 +187,42 @@ private Map generateLists(Octane octane) throws IOException { final Collection listNodes = octane.entityList("list_nodes") .get() .addFields("name", "list_root", "id", "logical_name") + .query(Query.not("list_root", QueryMethod.EqualTo, null).build()) .execute(); final Map> mappedListNodes = new HashMap<>(); final Map logicalNameToNameMap = new HashMap<>(); - listNodes.stream().sorted(Comparator.comparing(this::getEntityModelName)).forEach(listNode -> { - final String rootId; - final ReferenceFieldModel list_root = (ReferenceFieldModel) listNode.getValue("list_root"); - final EntityModel list_rootValue = list_root.getValue(); - final String name; - if (list_rootValue != null) { - rootId = list_rootValue.getId(); - name = getEntityModelName(listNode); - } else { - rootId = listNode.getId(); - name = GeneratorHelper.camelCaseFieldName( - ((StringFieldModel) listNode.getValue("name")).getValue().replaceAll("\\W", "_")); - logicalNameToNameMap.put(((StringFieldModel) listNode.getValue("logical_name")).getValue(), name); - } - final List listHierarchy = mappedListNodes.computeIfAbsent(rootId, k -> new ArrayList<>()); + listNodes.stream() + .sorted(Comparator.comparing(listNode -> ((StringFieldModel) listNode.getValue("name")).getValue())) + .forEach(listNode -> { + final String rootId; + final ReferenceFieldModel list_root = (ReferenceFieldModel) listNode.getValue("list_root"); + final EntityModel list_rootValue = list_root.getValue(); + rootId = list_rootValue.getId(); + mappedListNodes.computeIfAbsent(rootId, k -> new ArrayList<>()).add(new String[] { // + getEntityModelName(listNode), // + ((StringFieldModel) listNode.getValue("id")).getValue(), // + ((StringFieldModel) listNode.getValue("name")).getValue() // + }); + }); - final String[] listNodeInfo = { name, ((StringFieldModel) listNode.getValue("id")).getValue() }; - if (list_rootValue == null) { - listHierarchy.add(0, listNodeInfo); - } else { - listHierarchy.add(listNodeInfo); - } + // since octane v12.60.35.103 does not return root list_nodes with + // previus call, we need to query them + final Collection rootNodes = octane.entityList("list_nodes") + .get() + .addFields("name", "id", "logical_name") + .query(Query.statement("list_root", QueryMethod.EqualTo, null).build()) + .execute(); + + rootNodes.forEach(rootNode -> { + final String name = getEntityModelName(rootNode); + logicalNameToNameMap.put(((StringFieldModel) rootNode.getValue("logical_name")).getValue(), name); + final List strings = mappedListNodes.computeIfAbsent(rootNode.getId(), k -> new ArrayList<>()); + strings.add(0, new String[] { // + name, // + rootNode.getId(), // + ((StringFieldModel) rootNode.getValue("name")).getValue() // + }); }); final Map> sortedMappedListNodes = new TreeMap<>(); @@ -228,7 +238,7 @@ private Map generateLists(Octane octane) throws IOException { } private String getEntityModelName(EntityModel listNode) { - return ((StringFieldModel) listNode.getValue("name")).getValue() + return GeneratorHelper.removeAccents(((StringFieldModel) listNode.getValue("name")).getValue()) .replaceAll(" ", "_") .replaceAll("^\\d", "_$0") .replaceAll("\\W", "_") diff --git a/sdk-generate-entity-models-maven-plugin/src/main/resources/Lists.vm b/sdk-generate-entity-models-maven-plugin/src/main/resources/Lists.vm index 4ca5b33a..19c4cba0 100644 --- a/sdk-generate-entity-models-maven-plugin/src/main/resources/Lists.vm +++ b/sdk-generate-entity-models-maven-plugin/src/main/resources/Lists.vm @@ -1,22 +1,41 @@ package com.hpe.adm.nga.sdk.enums; +import java.util.Arrays; + +import javax.annotation.Generated; + import com.hpe.adm.nga.sdk.model.EntityModel; import com.hpe.adm.nga.sdk.model.StringFieldModel; -import java.util.Arrays; /** * Generated class - do not edit! */ +@Generated("sdk-generate-entity-models-maven-plugin") public final class Lists { #foreach($listItemsSet in ${listNodes.entrySet()}) #set($listItems = $listItemsSet.getValue()) #set($rootModel = $listItems.get(0)) #set($rootModelName = ${rootModel[0]}) + + /** + * #if($listItems.size() <= 1)EMPTY! #end${rootModel[2]} + */ public enum $rootModelName { #foreach($listModel in $listItems)#if(!$foreach.first) - #if($foreach.count > 2), #end${listModel[0]}("${listModel[1]}")#end - #end; + /** + * ${listModel[2]} + */ + ${listModel[0]}("${listModel[1]}")#if($foreach.hasNext),#else;#end + #end#end + + #if($listItems.size() <= 1) + /** + * List is empty! + * @deprecated this list should be regenerated + */ + DEADBEEF("$rootModelName is empty!!1"); + #end public static final String ROOT_ID = "${rootModel[1]}"; From 341ef8f29d89e7efa2584a2a707169970c15dd1f Mon Sep 17 00:00:00 2001 From: Sergej Turkan Date: Fri, 8 Feb 2019 22:28:44 +0100 Subject: [PATCH 18/41] Changed phase generator to build proper enum names Improved Phase template --- .../hpe/adm/nga/sdk/generate/GenerateModels.java | 11 ++++++----- .../src/main/resources/Phases.vm | 16 ++++++++++++++-- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java index 3add1783..f63f4c14 100644 --- a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java +++ b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java @@ -255,11 +255,12 @@ private Set generatePhases(Octane octane) throws IOException { .sorted(Comparator.comparing(phase -> ((StringFieldModel) phase.getValue("name")).getValue())) .forEach(phase -> { final List phaseValueList = new ArrayList<>(); - phaseValueList.add(new String[] { phase.getId(), - ((StringFieldModel) phase.getValue("name")).getValue() - .replaceAll(" ", "_") - .replaceAll("&", "N") - .toUpperCase() }); + phaseValueList.add(new String[] { // + phase.getId(), // + getEntityModelName(phase).toUpperCase(), // + ((StringFieldModel) phase.getValue("name")).getValue(), // + ((StringFieldModel) phase.getValue("entity")).getValue() // + }); phaseMap.merge( GeneratorHelper.camelCaseFieldName(((StringFieldModel) phase.getValue("entity")).getValue(), true), diff --git a/sdk-generate-entity-models-maven-plugin/src/main/resources/Phases.vm b/sdk-generate-entity-models-maven-plugin/src/main/resources/Phases.vm index 1ad79e3c..3441f8e1 100644 --- a/sdk-generate-entity-models-maven-plugin/src/main/resources/Phases.vm +++ b/sdk-generate-entity-models-maven-plugin/src/main/resources/Phases.vm @@ -1,19 +1,31 @@ package com.hpe.adm.nga.sdk.enums; +import java.util.Arrays; + +import javax.annotation.Generated; + import com.hpe.adm.nga.sdk.model.EntityModel; import com.hpe.adm.nga.sdk.model.StringFieldModel; -import java.util.Arrays; /** * Generated class - do not edit! */ +@Generated("sdk-generate-entity-models-maven-plugin") public final class Phases { #foreach($phase in ${phaseMap.entrySet()}) #set($phaseType = $phase.getKey()) + + /** + * Phases for "$phase.getValue().get(0)[3]" entity + */ public enum ${phaseType}Phase { #foreach($phaseValue in $phase.getValue()) - #if($foreach.count > 1), #end${phaseValue[1]}("${phaseValue[0]}")#end; + /** + * ${phaseValue[2]} + */ + ${phaseValue[1]}("${phaseValue[0]}")#if($foreach.hasNext),#else;#end + #end private final String id; From 02f4fa59772117b3fb89b6f2b7230ea4af6787b9 Mon Sep 17 00:00:00 2001 From: Sergej Turkan Date: Fri, 8 Feb 2019 22:30:26 +0100 Subject: [PATCH 19/41] Improved interface generation & template --- .../java/com/hpe/adm/nga/sdk/generate/GenerateModels.java | 1 + .../src/main/resources/Entity.vm | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java index f63f4c14..13a91eab 100644 --- a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java +++ b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java @@ -380,6 +380,7 @@ private void generateInterface(EntityMetadata entityMetadatum, String name, Stri .findAny(); interfaceVelocityContext.put("interfaceName", interfaceName); + interfaceVelocityContext.put("name", name); interfaceVelocityContext.put("superInterfaceName", (subTypeOfFeature .map(feature -> GeneratorHelper.camelCaseFieldName(((SubTypesOfFeature) feature).getType())) diff --git a/sdk-generate-entity-models-maven-plugin/src/main/resources/Entity.vm b/sdk-generate-entity-models-maven-plugin/src/main/resources/Entity.vm index e1a21613..f1b18c60 100644 --- a/sdk-generate-entity-models-maven-plugin/src/main/resources/Entity.vm +++ b/sdk-generate-entity-models-maven-plugin/src/main/resources/Entity.vm @@ -1,3 +1,9 @@ package com.hpe.adm.nga.sdk.model; -interface ${interfaceName} extends ${superInterfaceName} {} \ No newline at end of file +import javax.annotation.Generated; + +/** + * ${name} entity + */ +@Generated("sdk-generate-entity-models-maven-plugin") +interface ${interfaceName} extends ${superInterfaceName} {} From 46d8536cbfc21890fc9a5c503e5fb6c8f16f5f22 Mon Sep 17 00:00:00 2001 From: Sergej Turkan Date: Fri, 8 Feb 2019 22:31:43 +0100 Subject: [PATCH 20/41] Improved EntityList generation & template --- .../adm/nga/sdk/generate/GenerateModels.java | 10 ++-- .../src/main/resources/EntityModel.vm | 22 +++++--- .../src/main/resources/TypedEntityList.vm | 53 ++++++++++++------- 3 files changed, 56 insertions(+), 29 deletions(-) diff --git a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java index 13a91eab..4a04a798 100644 --- a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java +++ b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java @@ -43,6 +43,8 @@ import com.hpe.adm.nga.sdk.model.EntityModel; import com.hpe.adm.nga.sdk.model.ReferenceFieldModel; import com.hpe.adm.nga.sdk.model.StringFieldModel; +import com.hpe.adm.nga.sdk.query.Query; +import com.hpe.adm.nga.sdk.query.QueryMethod; /** *

@@ -189,6 +191,7 @@ private Map generateLists(Octane octane) throws IOException { .addFields("name", "list_root", "id", "logical_name") .query(Query.not("list_root", QueryMethod.EqualTo, null).build()) .execute(); + final Map> mappedListNodes = new HashMap<>(); final Map logicalNameToNameMap = new HashMap<>(); @@ -251,6 +254,7 @@ private Set generatePhases(Octane octane) throws IOException { .get() .addFields("id", "name", "entity") .execute(); + phases.stream() .sorted(Comparator.comparing(phase -> ((StringFieldModel) phase.getValue("name")).getValue())) .forEach(phase -> { @@ -409,12 +413,12 @@ private void generateEntityList(EntityMetadata entityMetadatum, String name, entityListVelocityContext.put("type", GeneratorHelper.camelCaseFieldName(name)); entityListVelocityContext.put("url", restFeature.getUrl()); entityListVelocityContext.put("availableFields", - fieldMetadata.stream().map(FieldMetadata::getName).sorted().collect(Collectors.toList())); + fieldMetadata.stream().sorted(Comparator.comparing(FieldMetadata::getName)).collect( + Collectors.toList())); entityListVelocityContext.put("sortableFields", fieldMetadata.stream() .filter(FieldMetadata::isSortable) - .map(FieldMetadata::getName) - .sorted() + .sorted(Comparator.comparing(FieldMetadata::getName)) .collect(Collectors.toList())); final String[] restFeatureMethods = restFeature.getMethods(); diff --git a/sdk-generate-entity-models-maven-plugin/src/main/resources/EntityModel.vm b/sdk-generate-entity-models-maven-plugin/src/main/resources/EntityModel.vm index ed886d2f..b5a312da 100644 --- a/sdk-generate-entity-models-maven-plugin/src/main/resources/EntityModel.vm +++ b/sdk-generate-entity-models-maven-plugin/src/main/resources/EntityModel.vm @@ -2,12 +2,16 @@ #set ($subTypeOf = ${GeneratorHelper.getSubTypeOf(${entityMetadata})}) package com.hpe.adm.nga.sdk.model; +import javax.annotation.Generated; + /** - *

Entity Name: ${entityMetadata.name}

- *

Label: ${entityMetadata.getLabel()}

+ * Entity Name: ${entityMetadata.name} + *
+ * Label: ${entityMetadata.getLabel()} * - * Generated class. Do not manually edit. + * Generated class. Do not manually edit. */ +@Generated("sdk-generate-entity-models-maven-plugin") @EntityMetadata(url = "${entityMetadataWrapper.getUrl()}", availableMethods = {#foreach(${availableMethod} in ${entityMetadataWrapper.getAvailableMethods()})EntityMetadata.AvailableMethods.${availableMethod}, #end} ) public class ${className}EntityModel extends TypedEntityModel implements ${interfaceName} { @@ -59,11 +63,13 @@ public class ${className}EntityModel extends TypedEntityModel implements ${inter #macro (getter $field) /** - * Label: ${field.getLabel()} - * Description: ${field.getDescription()} - */ - #if ((${field.getName()} == "phase") && (${availablePhases.contains(${className})}))#getPhase()#elseif(${field.getFieldType()} == "Reference")#getReference($field)#{else}#getNonReference($field)#end - + * Label: ${field.getLabel()} +#if($field.getDescription() != "") + *
+ * Description: ${field.getDescription()} +#end + */ +#if ((${field.getName()} == "phase") && (${availablePhases.contains(${className})}))#getPhase()#elseif(${field.getFieldType()} == "Reference")#getReference($field)#{else}#getNonReference($field)#end #end #macro (getPhase) diff --git a/sdk-generate-entity-models-maven-plugin/src/main/resources/TypedEntityList.vm b/sdk-generate-entity-models-maven-plugin/src/main/resources/TypedEntityList.vm index 965414fb..0b005f1f 100644 --- a/sdk-generate-entity-models-maven-plugin/src/main/resources/TypedEntityList.vm +++ b/sdk-generate-entity-models-maven-plugin/src/main/resources/TypedEntityList.vm @@ -1,5 +1,7 @@ package com.hpe.adm.nga.sdk.entities; +import javax.annotation.Generated; + import com.hpe.adm.nga.sdk.entities.create.CreateTypedEntities; import com.hpe.adm.nga.sdk.entities.delete.DeleteTypedEntities; import com.hpe.adm.nga.sdk.entities.delete.DeleteTypedEntity; @@ -11,14 +13,22 @@ import com.hpe.adm.nga.sdk.model.${type}EntityModel; import com.hpe.adm.nga.sdk.network.OctaneHttpClient; /** -* Generated file. Do not edit! -*/ + * Generated file. Do not edit! + */ +@Generated("sdk-generate-entity-models-maven-plugin") public final class ${type}EntityList extends TypedEntityList { public enum AvailableFields implements TypedEntityList.AvailableFields { #foreach($field in $availableFields) - #if($foreach.count > 1), #end${helper.convertToUpperCase(${field})}("${field}") - #end; + /** + * Label: ${field.getLabel()} + #if($field.getDescription() != "") + *
+ * Description: ${field.getDescription()} + #end + */ + ${helper.convertToUpperCase(${field.name})}("${field.name}")#if($foreach.hasNext),#else;#end + #end private final String fieldName; @@ -33,8 +43,15 @@ public final class ${type}EntityList extends TypedEntityList { public enum SortableFields implements TypedEntityList.SortableFields { #foreach($field in $sortableFields) - #if($foreach.count > 1), #end${helper.convertToUpperCase(${field})}("${field}") - #end; + /** + * Label: ${field.getLabel()} + #if($field.getDescription() != "") + *
+ * Description: ${field.getDescription()} + #end + */ + ${helper.convertToUpperCase(${field.name})}("${field.name}")#if($foreach.hasNext),#else;#end + #end private final String fieldName; @@ -51,7 +68,7 @@ public final class ${type}EntityList extends TypedEntityList { super(octaneHttpClient, baseDomain); } - public ${type}Entities at(String entityId) { + public ${type}Entities at(final String entityId) { return new ${type}Entities(entityId); } @@ -79,27 +96,27 @@ public final class ${type}EntityList extends TypedEntityList { #end /** - * This class hold the ${type}Entities object(An object that represent one ${type}Entity ) - */ + * This class hold the ${type}Entities object(An object that represent one ${type}Entity ) + */ public class ${type}Entities { private final String entityId; /** - * Set entityId parameter - * - * @param entityId The entity id - */ - ${type}Entities(String entityId) { + * Set entityId parameter + * + * @param entityId The entity id + */ + ${type}Entities(final String entityId) { this.entityId = entityId; } #macro (outputEntityGetter $crudMethod, $type) /** - * getter of a ${crudMethod}${type}Entity object with specific entity - * - * @return The ${crudMethod}${type}Entity object - */ + * getter of a ${crudMethod}${type}Entity object with specific entity + * + * @return The ${crudMethod}${type}Entity object + */ public ${crudMethod}${type}Entity ${crudMethod.toLowerCase()}() { return new ${crudMethod}${type}Entity(octaneHttpClient, baseDomain, entityId); } From 670949da78e94b28f9a9e4b47b64c5ee338c3d7b Mon Sep 17 00:00:00 2001 From: Sergej Turkan Date: Fri, 8 Feb 2019 22:33:50 +0100 Subject: [PATCH 21/41] Fixed GeneratorHelper.convertToUpperCase --- .../com/hpe/adm/nga/sdk/generate/GeneratorHelper.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GeneratorHelper.java b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GeneratorHelper.java index af84c987..6395d385 100644 --- a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GeneratorHelper.java +++ b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GeneratorHelper.java @@ -73,13 +73,7 @@ public static String camelCaseFieldName(final String fieldName, boolean theFirst } public static String convertToUpperCase(final String fieldName) { - final StringBuffer stringBuffer = new StringBuffer(); - final String[] splitFields = fieldName.split("_"); - for (final String splitField : splitFields) { - stringBuffer.append(splitField.toUpperCase()); - } - - return stringBuffer.toString(); + return fieldName.toUpperCase(); } public static String getSanitisedFieldName(final String fieldName) { @@ -313,7 +307,8 @@ public static EntityMetadataWrapper entityMetadataWrapper(final EntityMetadata e * Replaces accented characters in a String by unaccented equivalents. * * @see https://www.mail-archive.com/java-user@lucene.apache.org/msg23562.html - * @param input - String + * @param input + * String * @return cleaned String */ public final static String removeAccents(final String input) { From 6018c538ad9891fa8802f21bc842fa2a732bd904 Mon Sep 17 00:00:00 2001 From: Sergej Turkan Date: Mon, 11 Feb 2019 08:49:43 +0100 Subject: [PATCH 22/41] Added SortHelper to sort required fields list of lists --- .../adm/nga/sdk/generate/GenerateModels.java | 1 + .../adm/nga/sdk/generate/GeneratorHelper.java | 2 +- .../hpe/adm/nga/sdk/generate/SortHelper.java | 29 +++++++++++++++++++ .../src/main/resources/EntityModel.vm | 2 +- 4 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/SortHelper.java diff --git a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java index 4a04a798..46f832d1 100644 --- a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java +++ b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java @@ -342,6 +342,7 @@ private Collection generateEntity(Collection work_ velocityContext.put("logicalNameToListsMap", logicalNameToListsMap); velocityContext.put("entityMetadataCollection", entityMetadata); velocityContext.put("GeneratorHelper", GeneratorHelper.class); + velocityContext.put("SortHelper", SortHelper.class); velocityContext.put("entityMetadataWrapper", GeneratorHelper.entityMetadataWrapper(entityMetadatum)); velocityContext.put("availablePhases", availablePhases); velocityContext.put("requiredFields", requiredFields); diff --git a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GeneratorHelper.java b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GeneratorHelper.java index 6395d385..e2285fee 100644 --- a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GeneratorHelper.java +++ b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GeneratorHelper.java @@ -144,7 +144,7 @@ public static final class ReferenceMetadata { private final Set allowedReferencesForAnnotation = new HashSet<>(); private boolean hasNonTypedReturn = false; private boolean hasTypedReturn = false; - private final Set referenceTypes = new HashSet<>(); + private final Set referenceTypes = new TreeSet<>(); private String typedType; public String getReferenceClassForSignature() { diff --git a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/SortHelper.java b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/SortHelper.java new file mode 100644 index 00000000..c4816b10 --- /dev/null +++ b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/SortHelper.java @@ -0,0 +1,29 @@ +package com.hpe.adm.nga.sdk.generate; + +import java.util.Collection; +import java.util.Comparator; +import java.util.List; +import java.util.stream.Collectors; + +public final class SortHelper { + + /** + * Sorts RequiredFields by given Fieldname ASC + * + * @param requiredFields + * Collection of FieldLists with Array of field data + * @param fieldName + * Name of the field + * @return Sorted List + */ + public static List> sortRequiredFieldsByFieldName(final Collection> requiredFields, + final String fieldName) { + return requiredFields.stream() + .sorted(Comparator.comparing( + fieldList -> fieldList.stream().map(fields -> String.join("", fields)).sorted().collect( + Collectors.joining()) + + )) + .collect(Collectors.toList()); + } +} diff --git a/sdk-generate-entity-models-maven-plugin/src/main/resources/EntityModel.vm b/sdk-generate-entity-models-maven-plugin/src/main/resources/EntityModel.vm index b5a312da..b497c6e3 100644 --- a/sdk-generate-entity-models-maven-plugin/src/main/resources/EntityModel.vm +++ b/sdk-generate-entity-models-maven-plugin/src/main/resources/EntityModel.vm @@ -27,7 +27,7 @@ public class ${className}EntityModel extends TypedEntityModel implements ${inter #requiredFieldsForConstructor() #macro (requiredFieldsForConstructor) - #foreach($requiredFieldList in $requiredFields) + #foreach($requiredFieldList in ${SortHelper.sortRequiredFieldsByFieldName($requiredFields, 'parent')}) public ${className}EntityModel(#outputRequiredFieldsConstructorSignature($requiredFieldList)) { this(); #outputRequiredFieldsSetters($requiredFieldList) From 6a6443e16d35eb1cd8d27e01afb9f672eb25e6c0 Mon Sep 17 00:00:00 2001 From: Sergej Turkan Date: Mon, 11 Feb 2019 09:09:34 +0100 Subject: [PATCH 23/41] Added documentation for SortHelper --- .../com/hpe/adm/nga/sdk/generate/SortHelper.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/SortHelper.java b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/SortHelper.java index c4816b10..78fb90b1 100644 --- a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/SortHelper.java +++ b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/SortHelper.java @@ -1,3 +1,16 @@ +/* + * Copyright 2017 EntIT Software LLC, a Micro Focus company, L.P. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.hpe.adm.nga.sdk.generate; import java.util.Collection; @@ -5,6 +18,9 @@ import java.util.List; import java.util.stream.Collectors; +/** + * A class that is used to help with sorting stuff + */ public final class SortHelper { /** From 01a280d7057a3bafd97a53f2ddc69cb01dc8eb0e Mon Sep 17 00:00:00 2001 From: Sergej Turkan Date: Tue, 12 Feb 2019 07:10:02 +0100 Subject: [PATCH 24/41] Changed interfaces visibility to public --- .../src/main/resources/Entity.vm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk-generate-entity-models-maven-plugin/src/main/resources/Entity.vm b/sdk-generate-entity-models-maven-plugin/src/main/resources/Entity.vm index f1b18c60..df9e08ab 100644 --- a/sdk-generate-entity-models-maven-plugin/src/main/resources/Entity.vm +++ b/sdk-generate-entity-models-maven-plugin/src/main/resources/Entity.vm @@ -6,4 +6,4 @@ import javax.annotation.Generated; * ${name} entity */ @Generated("sdk-generate-entity-models-maven-plugin") -interface ${interfaceName} extends ${superInterfaceName} {} +public interface ${interfaceName} extends ${superInterfaceName} {} From af94adaa44e08decf3402c4da5f92befc3175696 Mon Sep 17 00:00:00 2001 From: Sergej Turkan Date: Tue, 12 Feb 2019 07:10:46 +0100 Subject: [PATCH 25/41] Changed list_nodes queries --- .../adm/nga/sdk/generate/GenerateModels.java | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java index 46f832d1..d9daaa0a 100644 --- a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java +++ b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java @@ -34,6 +34,7 @@ import com.hpe.adm.nga.sdk.Octane; import com.hpe.adm.nga.sdk.authentication.SimpleClientAuthentication; +import com.hpe.adm.nga.sdk.entities.OctaneCollection; import com.hpe.adm.nga.sdk.metadata.EntityMetadata; import com.hpe.adm.nga.sdk.metadata.FieldMetadata; import com.hpe.adm.nga.sdk.metadata.Metadata; @@ -160,6 +161,7 @@ public void generate(String clientId, String clientSecret, String server, long s final Collection work_items_rootFields = octanePrivate.metadata() .fields("work_item_root") .execute(); + octanePrivate.signOut(); final Octane octane = new Octane.Builder(new SimpleClientAuthentication(clientId, clientSecret)) @@ -186,12 +188,27 @@ public void generate(String clientId, String clientSecret, String server, long s } private Map generateLists(Octane octane) throws IOException { - final Collection listNodes = octane.entityList("list_nodes") + // since octane v12.60.35.103 does not return root list_nodes within + // list_nodes call + final Collection rootNodes = octane.entityList("list_nodes") .get() - .addFields("name", "list_root", "id", "logical_name") - .query(Query.not("list_root", QueryMethod.EqualTo, null).build()) + .addFields("name", "id", "logical_name") + .query(Query.statement("list_root", QueryMethod.EqualTo, null).build()) .execute(); + final List listNodes = new ArrayList<>(4000); + rootNodes.forEach(rootNode -> { + final OctaneCollection models = octane.entityList("list_nodes") + .get() + .addFields("name", "list_root", "id", "logical_name") + .query(Query + .statement("list_root", QueryMethod.EqualTo, + Query.statement("id", QueryMethod.EqualTo, rootNode.getId())) + .build()) + .execute(); + listNodes.addAll(models); + }); + final Map> mappedListNodes = new HashMap<>(); final Map logicalNameToNameMap = new HashMap<>(); @@ -209,14 +226,6 @@ private Map generateLists(Octane octane) throws IOException { }); }); - // since octane v12.60.35.103 does not return root list_nodes with - // previus call, we need to query them - final Collection rootNodes = octane.entityList("list_nodes") - .get() - .addFields("name", "id", "logical_name") - .query(Query.statement("list_root", QueryMethod.EqualTo, null).build()) - .execute(); - rootNodes.forEach(rootNode -> { final String name = getEntityModelName(rootNode); logicalNameToNameMap.put(((StringFieldModel) rootNode.getValue("logical_name")).getValue(), name); From 5b073e18f11406667d66d86bb8ba94130aac0483 Mon Sep 17 00:00:00 2001 From: Sergej Turkan Date: Tue, 12 Feb 2019 13:51:50 +0100 Subject: [PATCH 26/41] Handle only active phases --- .../main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java index d9daaa0a..7748f165 100644 --- a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java +++ b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java @@ -257,11 +257,12 @@ private String getEntityModelName(EntityModel listNode) { .toUpperCase(); } - private Set generatePhases(Octane octane) throws IOException { + private Set generatePhases(final Octane octane) throws IOException { final Map> phaseMap = new TreeMap<>(); final Collection phases = octane.entityList("phases") .get() .addFields("id", "name", "entity") + .query(Query.statement("activity_level", QueryMethod.EqualTo, 0).build()) .execute(); phases.stream() From 980f569d36b7987dea4390c987e0cea1122d9cad Mon Sep 17 00:00:00 2001 From: Sergej Turkan Date: Wed, 13 Feb 2019 09:56:04 +0100 Subject: [PATCH 27/41] Added list resolution by their labels --- .../adm/nga/sdk/generate/GenerateModels.java | 2 +- .../src/main/resources/Lists.vm | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java index 7748f165..9468dab9 100644 --- a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java +++ b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java @@ -196,7 +196,7 @@ private Map generateLists(Octane octane) throws IOException { .query(Query.statement("list_root", QueryMethod.EqualTo, null).build()) .execute(); - final List listNodes = new ArrayList<>(4000); + final List listNodes = new ArrayList<>(); rootNodes.forEach(rootNode -> { final OctaneCollection models = octane.entityList("list_nodes") .get() diff --git a/sdk-generate-entity-models-maven-plugin/src/main/resources/Lists.vm b/sdk-generate-entity-models-maven-plugin/src/main/resources/Lists.vm index 19c4cba0..f4e99fb5 100644 --- a/sdk-generate-entity-models-maven-plugin/src/main/resources/Lists.vm +++ b/sdk-generate-entity-models-maven-plugin/src/main/resources/Lists.vm @@ -26,7 +26,7 @@ public final class Lists { /** * ${listModel[2]} */ - ${listModel[0]}("${listModel[1]}")#if($foreach.hasNext),#else;#end + ${listModel[0]}("${listModel[1]}", "${listModel[2]}")#if($foreach.hasNext),#else;#end #end#end #if($listItems.size() <= 1) @@ -40,17 +40,27 @@ public final class Lists { public static final String ROOT_ID = "${rootModel[1]}"; private final String id; + private final String value; - $rootModelName(final String id) { + $rootModelName(final String id, final String value) { this.id = id; + this.value = value; } public final String getId() { return id; } - public static $rootModelName getListNodeFromId(String id) { - return Arrays.stream(${rootModelName}.values()).filter(listNode -> listNode.id.equals(id)).findFirst().orElse(null); + public final String getValue() { + return value; + } + + public static $rootModelName getListNodeFromId(final String id) { + return Arrays.stream(${rootModelName}.values()).filter(listNode -> listNode.getId().equals(id)).findFirst().orElse(null); + } + + public static $rootModelName getListNodeFromValue(final String value) { + return Arrays.stream(${rootModelName}.values()).filter(listNode -> listNode.getValue().equalsIgnoreCase(value)).findFirst().orElse(null); } public final EntityModel getAsEntityModel() { From 85d89bf42682be1803e3b83bab696d966f2d97bd Mon Sep 17 00:00:00 2001 From: Sergej Turkan Date: Wed, 13 Feb 2019 15:46:55 +0100 Subject: [PATCH 28/41] Changed list enum generation to handle duplicated list entries --- .../adm/nga/sdk/generate/GenerateModels.java | 39 +++++++++++++------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java index 9468dab9..d5037c83 100644 --- a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java +++ b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java @@ -26,6 +26,7 @@ import java.util.Optional; import java.util.Set; import java.util.TreeMap; +import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; import org.apache.velocity.Template; @@ -212,19 +213,33 @@ private Map generateLists(Octane octane) throws IOException { final Map> mappedListNodes = new HashMap<>(); final Map logicalNameToNameMap = new HashMap<>(); - listNodes.stream() - .sorted(Comparator.comparing(listNode -> ((StringFieldModel) listNode.getValue("name")).getValue())) - .forEach(listNode -> { - final String rootId; - final ReferenceFieldModel list_root = (ReferenceFieldModel) listNode.getValue("list_root"); - final EntityModel list_rootValue = list_root.getValue(); - rootId = list_rootValue.getId(); - mappedListNodes.computeIfAbsent(rootId, k -> new ArrayList<>()).add(new String[] { // - getEntityModelName(listNode), // - ((StringFieldModel) listNode.getValue("id")).getValue(), // - ((StringFieldModel) listNode.getValue("name")).getValue() // + listNodes.stream().sorted(Comparator.comparing(this::getEntityModelName)).forEach(listNode -> { + final String rootId; + final ReferenceFieldModel list_root = (ReferenceFieldModel) listNode.getValue("list_root"); + final EntityModel list_rootValue = list_root.getValue(); + rootId = list_rootValue.getId(); + mappedListNodes.computeIfAbsent(rootId, k -> new ArrayList<>()).add(new String[] { // + getEntityModelName(listNode), // + ((StringFieldModel) listNode.getValue("id")).getValue(), // + ((StringFieldModel) listNode.getValue("name")).getValue() // + }); + }); + + // deduplicate list entries + mappedListNodes.forEach((key, value) -> { + final Map> deDupMap = new TreeMap<>(); + value.forEach(strings -> { + deDupMap.computeIfAbsent(strings[0], k -> new ArrayList<>()).add(strings); + }); + value = deDupMap.values().stream().peek(list -> { + if (list.size() > 1) { + final AtomicInteger counter = new AtomicInteger(); + list.forEach(strings -> { + strings[0] += "__" + (counter.getAndIncrement() + 1); }); - }); + } + }).flatMap(Collection::stream).collect(Collectors.toList()); + }); rootNodes.forEach(rootNode -> { final String name = getEntityModelName(rootNode); From 87c8e53fc6e15034bced803b2f1361c2cbb0f0ec Mon Sep 17 00:00:00 2001 From: Sergej Turkan Date: Mon, 4 Mar 2019 10:50:30 +0100 Subject: [PATCH 29/41] Take care of enums containing only '_' in name --- .../hpe/adm/nga/sdk/generate/GenerateModels.java | 11 ++++++----- .../hpe/adm/nga/sdk/generate/GeneratorHelper.java | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java index d5037c83..3a1e000f 100644 --- a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java +++ b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java @@ -265,11 +265,12 @@ private Map generateLists(Octane octane) throws IOException { } private String getEntityModelName(EntityModel listNode) { - return GeneratorHelper.removeAccents(((StringFieldModel) listNode.getValue("name")).getValue()) - .replaceAll(" ", "_") - .replaceAll("^\\d", "_$0") - .replaceAll("\\W", "_") - .toUpperCase(); + return GeneratorHelper.handleSingeUnderscoreEnum( + GeneratorHelper.removeAccents(((StringFieldModel) listNode.getValue("name")).getValue()) + .replaceAll(" ", "_") + .replaceAll("^\\d", "_$0") + .replaceAll("\\W", "_") + .toUpperCase()); } private Set generatePhases(final Octane octane) throws IOException { diff --git a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GeneratorHelper.java b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GeneratorHelper.java index e2285fee..c95859b5 100644 --- a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GeneratorHelper.java +++ b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GeneratorHelper.java @@ -441,4 +441,19 @@ public final static String removeAccents(final String input) { } return result.toString(); } + + /** + * Takes care of wild enums containing only '_' in name. deduplication + * should run after this step + * + * @param input + * enum name + * @return "_NONE" if enum has name '_', else original name wil be returned + */ + public final static String handleSingeUnderscoreEnum(final String input) { + if (input.replaceAll("\\_", "").length() == 0) { + return "_NONE"; + } + return input; + } } From 8b9afb3531d20f773441ce25d694dc4ef392dbff Mon Sep 17 00:00:00 2001 From: Sergej Turkan Date: Tue, 12 Mar 2019 10:51:05 +0100 Subject: [PATCH 30/41] Extend FieldMetadata with selectable field --- .../java/com/hpe/adm/nga/sdk/metadata/FieldMetadata.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sdk-src/src/main/java/com/hpe/adm/nga/sdk/metadata/FieldMetadata.java b/sdk-src/src/main/java/com/hpe/adm/nga/sdk/metadata/FieldMetadata.java index 4992beff..390369e8 100644 --- a/sdk-src/src/main/java/com/hpe/adm/nga/sdk/metadata/FieldMetadata.java +++ b/sdk-src/src/main/java/com/hpe/adm/nga/sdk/metadata/FieldMetadata.java @@ -60,6 +60,7 @@ public enum FieldType { private boolean filterable; private boolean groupable; private boolean sortable; + private boolean selectable; private boolean auditable; private boolean can_modify_auditable; private boolean returned_by_default; @@ -320,4 +321,8 @@ public class FieldTypeData { * @return whether the sanitization can be modified */ public boolean canModifySanitization() {return can_modify_sanitization;} + + public boolean isSelectable() { + return selectable; + } } From b724e108afb3b933fe6b8302e3a1902f34448836 Mon Sep 17 00:00:00 2001 From: Sergej Turkan Date: Tue, 12 Mar 2019 10:51:38 +0100 Subject: [PATCH 31/41] Added null checks to EntityModel getters --- .../src/main/resources/EntityModel.vm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sdk-generate-entity-models-maven-plugin/src/main/resources/EntityModel.vm b/sdk-generate-entity-models-maven-plugin/src/main/resources/EntityModel.vm index b497c6e3..68d6732b 100644 --- a/sdk-generate-entity-models-maven-plugin/src/main/resources/EntityModel.vm +++ b/sdk-generate-entity-models-maven-plugin/src/main/resources/EntityModel.vm @@ -99,7 +99,7 @@ public com.hpe.adm.nga.sdk.enums.Phases.${className}Phase getPhase() { #macro (getSingleListNode $field $listName) public com.hpe.adm.nga.sdk.enums.Lists.${listName} get${GeneratorHelper.camelCaseFieldName(${field.name})}() { final ReferenceFieldModel ${GeneratorHelper.getSanitisedFieldName(${field.name})} = (ReferenceFieldModel) wrappedEntityModel.getValue("${field.name}"); - if (${GeneratorHelper.getSanitisedFieldName(${field.name})} == null) { + if (${GeneratorHelper.getSanitisedFieldName(${field.name})} == null || ${GeneratorHelper.getSanitisedFieldName(${field.name})}.getValue() == null) { return null; } final EntityModel referenceFieldModel = ${GeneratorHelper.getSanitisedFieldName(${field.name})}.getValue(); @@ -110,7 +110,7 @@ public com.hpe.adm.nga.sdk.enums.Lists.${listName} get${GeneratorHelper.camelCas #macro (getMultiListNode $field $listName) public java.util.Collection get${GeneratorHelper.camelCaseFieldName(${field.name})}() { final MultiReferenceFieldModel ${GeneratorHelper.getSanitisedFieldName(${field.name})} = (MultiReferenceFieldModel) wrappedEntityModel.getValue("${field.name}"); - if (${GeneratorHelper.getSanitisedFieldName(${field.name})} == null) { + if (${GeneratorHelper.getSanitisedFieldName(${field.name})} == null || ${GeneratorHelper.getSanitisedFieldName(${field.name})}.getValue() == null) { return java.util.Collections.emptyList(); } final java.util.Collection value = ${GeneratorHelper.getSanitisedFieldName(${field.name})}.getValue(); @@ -130,7 +130,7 @@ public ${GeneratorHelper.getFieldTypeAsJava(${field.getFieldType()})} get${Gener #multipleReferenceAnnotations (${referenceMetadata}) public ${referenceMetadata.getReferenceClassForSignature()} get${GeneratorHelper.camelCaseFieldName(${field.name})}(){ final ReferenceFieldModel ${GeneratorHelper.getSanitisedFieldName(${field.name})} = (ReferenceFieldModel) wrappedEntityModel.getValue("${field.name}"); - if (${GeneratorHelper.getSanitisedFieldName(${field.name})} == null) { + if (${GeneratorHelper.getSanitisedFieldName(${field.name})} == null || ${GeneratorHelper.getSanitisedFieldName(${field.name})}.getValue() == null) { return null; } final EntityModel referenceFieldModel = ${GeneratorHelper.getSanitisedFieldName(${field.name})}.getValue(); @@ -150,7 +150,7 @@ final StringFieldModel type = (StringFieldModel) referenceFieldModel.getValue("t #multipleReferenceAnnotations (${referenceMetadata}) public ${referenceMetadata.getReferenceClassForSignature()} get${GeneratorHelper.camelCaseFieldName(${field.name})}(){ final MultiReferenceFieldModel ${GeneratorHelper.getSanitisedFieldName(${field.name})} = (MultiReferenceFieldModel) wrappedEntityModel.getValue("${field.name}"); - if (${GeneratorHelper.getSanitisedFieldName(${field.name})} == null) { + if (${GeneratorHelper.getSanitisedFieldName(${field.name})} == null || ${GeneratorHelper.getSanitisedFieldName(${field.name})}.getValue() == null) { return java.util.Collections.emptyList(); } final java.util.Collection value = ${GeneratorHelper.getSanitisedFieldName(${field.name})}.getValue(); From 48452dc83ab8b0d02b34c3105a8bf816fbf5f14f Mon Sep 17 00:00:00 2001 From: Lukas Lisowski Date: Mon, 2 Sep 2019 20:12:49 +0200 Subject: [PATCH 32/41] =?UTF-8?q?F=C3=BCge=20weiteren=20Konstruktor=20hinz?= =?UTF-8?q?u?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/Lists.vm | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sdk-generate-entity-models-maven-plugin/src/main/resources/Lists.vm b/sdk-generate-entity-models-maven-plugin/src/main/resources/Lists.vm index f4e99fb5..37db74e4 100644 --- a/sdk-generate-entity-models-maven-plugin/src/main/resources/Lists.vm +++ b/sdk-generate-entity-models-maven-plugin/src/main/resources/Lists.vm @@ -34,7 +34,7 @@ public final class Lists { * List is empty! * @deprecated this list should be regenerated */ - DEADBEEF("$rootModelName is empty!!1"); + DEADBEEF("$rootModelName is empty!!!"); #end public static final String ROOT_ID = "${rootModel[1]}"; @@ -42,6 +42,11 @@ public final class Lists { private final String id; private final String value; + $rootModelName(final String id) { + this.id = id; + this.value = null; + } + $rootModelName(final String id, final String value) { this.id = id; this.value = value; From 064c5eae9baa7091c1b513dbf2f05ed1351d1792 Mon Sep 17 00:00:00 2001 From: Lukas Lisowski Date: Mon, 2 Sep 2019 20:18:18 +0200 Subject: [PATCH 33/41] Update Lists.vm --- .../src/main/resources/Lists.vm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk-generate-entity-models-maven-plugin/src/main/resources/Lists.vm b/sdk-generate-entity-models-maven-plugin/src/main/resources/Lists.vm index 37db74e4..cf568f52 100644 --- a/sdk-generate-entity-models-maven-plugin/src/main/resources/Lists.vm +++ b/sdk-generate-entity-models-maven-plugin/src/main/resources/Lists.vm @@ -34,7 +34,7 @@ public final class Lists { * List is empty! * @deprecated this list should be regenerated */ - DEADBEEF("$rootModelName is empty!!!"); + DEADBEEF("$rootModelName is empty!!1"); #end public static final String ROOT_ID = "${rootModel[1]}"; From 847e956ac0985ba4e7ac86b33b60ce7c692b3871 Mon Sep 17 00:00:00 2001 From: Lukas Lisowski Date: Mon, 2 Sep 2019 20:19:46 +0200 Subject: [PATCH 34/41] Update Lists.vm --- .../src/main/resources/Lists.vm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk-generate-entity-models-maven-plugin/src/main/resources/Lists.vm b/sdk-generate-entity-models-maven-plugin/src/main/resources/Lists.vm index cf568f52..b73138af 100644 --- a/sdk-generate-entity-models-maven-plugin/src/main/resources/Lists.vm +++ b/sdk-generate-entity-models-maven-plugin/src/main/resources/Lists.vm @@ -44,7 +44,7 @@ public final class Lists { $rootModelName(final String id) { this.id = id; - this.value = null; + this.value = "DEADBEEF"; } $rootModelName(final String id, final String value) { From 66d37c0d16b6c8fdca6b805448c0661df36c60c1 Mon Sep 17 00:00:00 2001 From: "Robert.Schreib" Date: Tue, 3 Sep 2019 15:31:32 +0200 Subject: [PATCH 35/41] Remove main method --- .../adm/nga/sdk/generate/GenerateModels.java | 173 ++++++++---------- .../adm/nga/sdk/metadata/FieldMetadata.java | 8 + 2 files changed, 85 insertions(+), 96 deletions(-) diff --git a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java index 3a1e000f..ed5dbfee 100644 --- a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java +++ b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java @@ -13,6 +13,24 @@ */ package com.hpe.adm.nga.sdk.generate; +import com.hpe.adm.nga.sdk.Octane; +import com.hpe.adm.nga.sdk.authentication.SimpleClientAuthentication; +import com.hpe.adm.nga.sdk.entities.OctaneCollection; +import com.hpe.adm.nga.sdk.metadata.EntityMetadata; +import com.hpe.adm.nga.sdk.metadata.FieldMetadata; +import com.hpe.adm.nga.sdk.metadata.Metadata; +import com.hpe.adm.nga.sdk.metadata.features.Feature; +import com.hpe.adm.nga.sdk.metadata.features.RestFeature; +import com.hpe.adm.nga.sdk.metadata.features.SubTypesOfFeature; +import com.hpe.adm.nga.sdk.model.EntityModel; +import com.hpe.adm.nga.sdk.model.ReferenceFieldModel; +import com.hpe.adm.nga.sdk.model.StringFieldModel; +import com.hpe.adm.nga.sdk.query.Query; +import com.hpe.adm.nga.sdk.query.QueryMethod; +import org.apache.velocity.Template; +import org.apache.velocity.VelocityContext; +import org.apache.velocity.app.VelocityEngine; + import java.io.File; import java.io.FileWriter; import java.io.IOException; @@ -29,25 +47,6 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; -import org.apache.velocity.Template; -import org.apache.velocity.VelocityContext; -import org.apache.velocity.app.VelocityEngine; - -import com.hpe.adm.nga.sdk.Octane; -import com.hpe.adm.nga.sdk.authentication.SimpleClientAuthentication; -import com.hpe.adm.nga.sdk.entities.OctaneCollection; -import com.hpe.adm.nga.sdk.metadata.EntityMetadata; -import com.hpe.adm.nga.sdk.metadata.FieldMetadata; -import com.hpe.adm.nga.sdk.metadata.Metadata; -import com.hpe.adm.nga.sdk.metadata.features.Feature; -import com.hpe.adm.nga.sdk.metadata.features.RestFeature; -import com.hpe.adm.nga.sdk.metadata.features.SubTypesOfFeature; -import com.hpe.adm.nga.sdk.model.EntityModel; -import com.hpe.adm.nga.sdk.model.ReferenceFieldModel; -import com.hpe.adm.nga.sdk.model.StringFieldModel; -import com.hpe.adm.nga.sdk.query.Query; -import com.hpe.adm.nga.sdk.query.QueryMethod; - /** *

* The class that generates entities based on the metadata from the given ALM @@ -78,8 +77,7 @@ public class GenerateModels { * Initialise the class with the output directory. This should normally be * in a project that would be imported into the main Java project * - * @param outputDirectory - * Where all the generated files will be placed + * @param outputDirectory Where all the generated files will be placed */ public GenerateModels(final File outputDirectory) { final File packageDirectory = new File(outputDirectory, "/com/hpe/adm/nga/sdk"); @@ -109,51 +107,35 @@ public GenerateModels(final File outputDirectory) { /** * Run the actual generation * - * @param clientId - * The client id - * @param clientSecret - * The client secret - * @param server - * The server including the protocol and port - * @param sharedSpace - * The SS id - * @param workSpace - * The WS id - * @throws IOException - * A problem with the generation of the entities + * @param clientId The client id + * @param clientSecret The client secret + * @param server The server including the protocol and port + * @param sharedSpace The SS id + * @param workSpace The WS id + * @throws IOException A problem with the generation of the entities */ - public void generate(String clientId, String clientSecret, String server, long sharedSpace, long workSpace) - throws IOException { + public void generate(final String clientId, final String clientSecret, final String server, final long sharedSpace, + final long workSpace) throws IOException { this.generate(clientId, clientSecret, server, sharedSpace, workSpace, false); } /** * Run the actual generation * - * @param clientId - * The client id - * @param clientSecret - * The client secret - * @param server - * The server including the protocol and port - * @param sharedSpace - * The SS id - * @param workSpace - * The WS id - * @param doNotValidateCertificate - * Disables validating server SSL certificates - * @throws IOException - * A problem with the generation of the entities + * @param clientId The client id + * @param clientSecret The client secret + * @param server The server including the protocol and port + * @param sharedSpace The SS id + * @param workSpace The WS id + * @param doNotValidateCertificate Disables validating server SSL certificates + * @throws IOException A problem with the generation of the entities */ - public void generate(String clientId, String clientSecret, String server, long sharedSpace, long workSpace, - final boolean doNotValidateCertificate) throws IOException { + public void generate(final String clientId, final String clientSecret, final String server, final long sharedSpace, + final long workSpace, final boolean doNotValidateCertificate) throws IOException { // work around for work_items_root final Octane octanePrivate = new Octane.Builder( - new SimpleClientAuthentication(clientId, clientSecret, "HPE_REST_API_TECH_PREVIEW")) - .sharedSpace(sharedSpace) - .workSpace(workSpace) - .Server(server) - .build(doNotValidateCertificate); + new SimpleClientAuthentication(clientId, clientSecret, "HPE_REST_API_TECH_PREVIEW")).sharedSpace( + sharedSpace).workSpace(workSpace).Server(server).build(doNotValidateCertificate); final EntityMetadata work_items_root = octanePrivate.metadata() .entities("work_item_root") .execute() @@ -165,11 +147,8 @@ public void generate(String clientId, String clientSecret, String server, long s octanePrivate.signOut(); - final Octane octane = new Octane.Builder(new SimpleClientAuthentication(clientId, clientSecret)) - .sharedSpace(sharedSpace) - .workSpace(workSpace) - .Server(server) - .build(doNotValidateCertificate); + final Octane octane = new Octane.Builder(new SimpleClientAuthentication(clientId, clientSecret)).sharedSpace( + sharedSpace).workSpace(workSpace).Server(server).build(doNotValidateCertificate); final Metadata metadata = octane.metadata(); final Collection entityMetadata = metadata.entities().execute(); entityMetadata.add(work_items_root); @@ -177,7 +156,7 @@ public void generate(String clientId, String clientSecret, String server, long s final Map logicalNameToListsMap = generateLists(octane); final Set availablePhases = generatePhases(octane); - for (EntityMetadata entityMetadatum : entityMetadata) { + for (final EntityMetadata entityMetadatum : entityMetadata) { final String name = entityMetadatum.getName(); final String interfaceName = GeneratorHelper.camelCaseFieldName(name) + "Entity"; final Collection fieldMetadata = generateEntity(work_items_rootFields, metadata, @@ -188,7 +167,7 @@ public void generate(String clientId, String clientSecret, String server, long s octane.signOut(); } - private Map generateLists(Octane octane) throws IOException { + private Map generateLists(final Octane octane) throws IOException { // since octane v12.60.35.103 does not return root list_nodes within // list_nodes call final Collection rootNodes = octane.entityList("list_nodes") @@ -202,10 +181,8 @@ private Map generateLists(Octane octane) throws IOException { final OctaneCollection models = octane.entityList("list_nodes") .get() .addFields("name", "list_root", "id", "logical_name") - .query(Query - .statement("list_root", QueryMethod.EqualTo, - Query.statement("id", QueryMethod.EqualTo, rootNode.getId())) - .build()) + .query(Query.statement("list_root", QueryMethod.EqualTo, + Query.statement("id", QueryMethod.EqualTo, rootNode.getId())).build()) .execute(); listNodes.addAll(models); }); @@ -264,7 +241,7 @@ private Map generateLists(Octane octane) throws IOException { return logicalNameToNameMap; } - private String getEntityModelName(EntityModel listNode) { + private String getEntityModelName(final EntityModel listNode) { return GeneratorHelper.handleSingeUnderscoreEnum( GeneratorHelper.removeAccents(((StringFieldModel) listNode.getValue("name")).getValue()) .replaceAll(" ", "_") @@ -293,8 +270,7 @@ private Set generatePhases(final Octane octane) throws IOException { }); phaseMap.merge( GeneratorHelper.camelCaseFieldName(((StringFieldModel) phase.getValue("entity")).getValue(), - true), - phaseValueList, // + true), phaseValueList, // (existingValues, newValues) -> { existingValues.addAll(newValues); return existingValues; @@ -310,10 +286,10 @@ private Set generatePhases(final Octane octane) throws IOException { return phaseMap.keySet(); } - private Collection generateEntity(Collection work_items_rootFields, Metadata metadata, - Collection entityMetadata, EntityMetadata entityMetadatum, String name, - String interfaceName, Map logicalNameToListsMap, Set availablePhases) - throws IOException { + private Collection generateEntity(final Collection work_items_rootFields, + final Metadata metadata, final Collection entityMetadata, + final EntityMetadata entityMetadatum, final String name, final String interfaceName, + final Map logicalNameToListsMap, final Set availablePhases) throws IOException { final List fieldMetadata = new ArrayList<>( name.equals("work_item_root") ? work_items_rootFields : metadata.fields(name).execute()); fieldMetadata.sort(Comparator.comparing(FieldMetadata::getName)); @@ -325,14 +301,14 @@ private Collection generateEntity(Collection work_ if (fieldMetadata1.getName().equals("phase") && availablePhases.contains(className)) { references.add("com.hpe.adm.nga.sdk.enums.Phases." + className + "Phase"); } else if (fieldMetadata1.getFieldType() == FieldMetadata.FieldType.Reference) { - if ((!entityMetadatum.getName().equals("list_node")) - && (fieldMetadata1.getFieldTypedata().getTargets()[0].getType().equals("list_node"))) { - final String listName = logicalNameToListsMap - .get(fieldMetadata1.getFieldTypedata().getTargets()[0].logicalName()); + if ((!entityMetadatum.getName().equals("list_node")) && (fieldMetadata1.getFieldTypedata() + .getTargets()[0].getType().equals("list_node"))) { + final String listName = logicalNameToListsMap.get( + fieldMetadata1.getFieldTypedata().getTargets()[0].logicalName()); references.add("com.hpe.adm.nga.sdk.enums.Lists." + listName); } else { - final GeneratorHelper.ReferenceMetadata referenceMetadata = GeneratorHelper - .getAllowedSuperTypesForReference(fieldMetadata1, entityMetadata); + final GeneratorHelper.ReferenceMetadata referenceMetadata = GeneratorHelper.getAllowedSuperTypesForReference( + fieldMetadata1, entityMetadata); if (fieldMetadata1.getFieldTypedata().isMultiple()) { references.add(referenceMetadata.getReferenceClassForSignature()); } else { @@ -360,6 +336,13 @@ private Collection generateEntity(Collection work_ if (!collectedReferences.isEmpty()) { expandCollectedReferences(collectedReferences, new int[collectedReferences.size()], 0, requiredFields); } + // Die Id muss immer vom Typ String sein, da es sonst Compile fehler gibt. siehe com.hpe.adm.nga.sdk.model.Entity + + fieldMetadata.forEach(field -> { + if (field.getName().equalsIgnoreCase("id")) { + field.setFieldType(FieldMetadata.FieldType.String); + } + }); final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("interfaceName", interfaceName); @@ -401,7 +384,7 @@ private void expandCollectedReferences(final TreeMap> colle positions[pointer] = 0; } - private void generateInterface(EntityMetadata entityMetadatum, String name, String interfaceName) + private void generateInterface(final EntityMetadata entityMetadatum, final String name, final String interfaceName) throws IOException { // interface final VelocityContext interfaceVelocityContext = new VelocityContext(); @@ -412,10 +395,9 @@ private void generateInterface(EntityMetadata entityMetadatum, String name, Stri interfaceVelocityContext.put("interfaceName", interfaceName); interfaceVelocityContext.put("name", name); - interfaceVelocityContext.put("superInterfaceName", - (subTypeOfFeature - .map(feature -> GeneratorHelper.camelCaseFieldName(((SubTypesOfFeature) feature).getType())) - .orElse("")) + "Entity"); + interfaceVelocityContext.put("superInterfaceName", (subTypeOfFeature.map( + feature -> GeneratorHelper.camelCaseFieldName(((SubTypesOfFeature) feature).getType())).orElse("")) + + "Entity"); final FileWriter interfaceFileWriter = new FileWriter( new File(modelDirectory, GeneratorHelper.camelCaseFieldName(name) + "Entity.java")); @@ -424,8 +406,8 @@ private void generateInterface(EntityMetadata entityMetadatum, String name, Stri interfaceFileWriter.close(); } - private void generateEntityList(EntityMetadata entityMetadatum, String name, - Collection fieldMetadata) throws IOException { + private void generateEntityList(final EntityMetadata entityMetadatum, final String name, + final Collection fieldMetadata) throws IOException { // entityList final Optional hasRestFeature = entityMetadatum.features() .stream() @@ -439,17 +421,16 @@ private void generateEntityList(EntityMetadata entityMetadatum, String name, entityListVelocityContext.put("helper", GeneratorHelper.class); entityListVelocityContext.put("type", GeneratorHelper.camelCaseFieldName(name)); entityListVelocityContext.put("url", restFeature.getUrl()); - entityListVelocityContext.put("availableFields", - fieldMetadata.stream().sorted(Comparator.comparing(FieldMetadata::getName)).collect( - Collectors.toList())); - entityListVelocityContext.put("sortableFields", - fieldMetadata.stream() - .filter(FieldMetadata::isSortable) - .sorted(Comparator.comparing(FieldMetadata::getName)) - .collect(Collectors.toList())); + entityListVelocityContext.put("availableFields", fieldMetadata.stream() + .sorted(Comparator.comparing(FieldMetadata::getName)) + .collect(Collectors.toList())); + entityListVelocityContext.put("sortableFields", fieldMetadata.stream() + .filter(FieldMetadata::isSortable) + .sorted(Comparator.comparing(FieldMetadata::getName)) + .collect(Collectors.toList())); final String[] restFeatureMethods = restFeature.getMethods(); - for (String restFeatureMethod : restFeatureMethods) { + for (final String restFeatureMethod : restFeatureMethods) { switch (restFeatureMethod) { case "GET": entityListVelocityContext.put("hasGet", true); diff --git a/sdk-src/src/main/java/com/hpe/adm/nga/sdk/metadata/FieldMetadata.java b/sdk-src/src/main/java/com/hpe/adm/nga/sdk/metadata/FieldMetadata.java index 390369e8..e8bfaa4f 100644 --- a/sdk-src/src/main/java/com/hpe/adm/nga/sdk/metadata/FieldMetadata.java +++ b/sdk-src/src/main/java/com/hpe/adm/nga/sdk/metadata/FieldMetadata.java @@ -274,6 +274,14 @@ public class FieldTypeData { */ public FieldType getFieldType(){return field_type;} + /** + * set {@link FieldMetadata} field Type + * @param fieldType the type of the field + */ + public void setFieldType(FieldType fieldType){ + field_type = fieldType; + } + /** * get FieldMetadata's Field Type data * @return the typedata of the field From 72e6bf0402a2ceca7b2e68eae8f4a094411f8b13 Mon Sep 17 00:00:00 2001 From: "Robert.Schreib" Date: Wed, 4 Sep 2019 16:17:50 +0200 Subject: [PATCH 36/41] Add @deprecated to deprecated list values --- .../adm/nga/sdk/generate/GenerateModels.java | 22 ++++++++++++++----- .../src/main/resources/Lists.vm | 8 ++++++- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java index ed5dbfee..040c15b8 100644 --- a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java +++ b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java @@ -23,6 +23,7 @@ import com.hpe.adm.nga.sdk.metadata.features.RestFeature; import com.hpe.adm.nga.sdk.metadata.features.SubTypesOfFeature; import com.hpe.adm.nga.sdk.model.EntityModel; +import com.hpe.adm.nga.sdk.model.LongFieldModel; import com.hpe.adm.nga.sdk.model.ReferenceFieldModel; import com.hpe.adm.nga.sdk.model.StringFieldModel; import com.hpe.adm.nga.sdk.query.Query; @@ -172,7 +173,7 @@ private Map generateLists(final Octane octane) throws IOExceptio // list_nodes call final Collection rootNodes = octane.entityList("list_nodes") .get() - .addFields("name", "id", "logical_name") + .addFields("name", "id", "logical_name", "activity_level") .query(Query.statement("list_root", QueryMethod.EqualTo, null).build()) .execute(); @@ -180,9 +181,11 @@ private Map generateLists(final Octane octane) throws IOExceptio rootNodes.forEach(rootNode -> { final OctaneCollection models = octane.entityList("list_nodes") .get() - .addFields("name", "list_root", "id", "logical_name") + .addFields("name", "list_root", "id", "logical_name", "activity_level") .query(Query.statement("list_root", QueryMethod.EqualTo, - Query.statement("id", QueryMethod.EqualTo, rootNode.getId())).build()) + Query.statement("id", QueryMethod.EqualTo, rootNode.getId())) + .and(Query.statement("activity_level", QueryMethod.LessThan, 2)) + .build()) .execute(); listNodes.addAll(models); }); @@ -195,11 +198,17 @@ private Map generateLists(final Octane octane) throws IOExceptio final ReferenceFieldModel list_root = (ReferenceFieldModel) listNode.getValue("list_root"); final EntityModel list_rootValue = list_root.getValue(); rootId = list_rootValue.getId(); + + if (((LongFieldModel) listNode.getValue("activity_level")).getValue().equals(1L)) { + System.out.println(((StringFieldModel) listNode.getValue("name")).getValue()); + } + mappedListNodes.computeIfAbsent(rootId, k -> new ArrayList<>()).add(new String[] { // getEntityModelName(listNode), // ((StringFieldModel) listNode.getValue("id")).getValue(), // - ((StringFieldModel) listNode.getValue("name")).getValue() // - }); + ((StringFieldModel) listNode.getValue("name")).getValue(), // + ((LongFieldModel) listNode.getValue("activity_level")).getValue().toString() }); + }); // deduplicate list entries @@ -225,7 +234,8 @@ private Map generateLists(final Octane octane) throws IOExceptio strings.add(0, new String[] { // name, // rootNode.getId(), // - ((StringFieldModel) rootNode.getValue("name")).getValue() // + ((StringFieldModel) rootNode.getValue("name")).getValue(), // + ((LongFieldModel) rootNode.getValue("activity_level")).getValue().toString() }); }); diff --git a/sdk-generate-entity-models-maven-plugin/src/main/resources/Lists.vm b/sdk-generate-entity-models-maven-plugin/src/main/resources/Lists.vm index b73138af..2ac0e91a 100644 --- a/sdk-generate-entity-models-maven-plugin/src/main/resources/Lists.vm +++ b/sdk-generate-entity-models-maven-plugin/src/main/resources/Lists.vm @@ -21,11 +21,17 @@ public final class Lists { /** * #if($listItems.size() <= 1)EMPTY! #end${rootModel[2]} */ + #if($rootModel[3] == "1") + @Deprecated + #end public enum $rootModelName { #foreach($listModel in $listItems)#if(!$foreach.first) /** * ${listModel[2]} */ + #if($listModel[3] == "1") + @Deprecated + #end ${listModel[0]}("${listModel[1]}", "${listModel[2]}")#if($foreach.hasNext),#else;#end #end#end @@ -34,7 +40,7 @@ public final class Lists { * List is empty! * @deprecated this list should be regenerated */ - DEADBEEF("$rootModelName is empty!!1"); + DEADBEEF("$rootModelName is empty!!"); #end public static final String ROOT_ID = "${rootModel[1]}"; From b406b37f85220dfef54b78749a98c75d9933e59f Mon Sep 17 00:00:00 2001 From: "Robert.Schreib" Date: Fri, 6 Sep 2019 10:08:59 +0200 Subject: [PATCH 37/41] Add ci script --- .gitlab-ci.yaml | 14 ++++++++++++++ .m2/settings.xml | 10 ++++++++++ pom.xml | 4 ++-- 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 .gitlab-ci.yaml create mode 100644 .m2/settings.xml diff --git a/.gitlab-ci.yaml b/.gitlab-ci.yaml new file mode 100644 index 00000000..018975c8 --- /dev/null +++ b/.gitlab-ci.yaml @@ -0,0 +1,14 @@ +stages: + - publish + +publish-sdk: + image: maven:3-jdk-8-slim + stage: publish + only: + - tags + script: + - mvn versions:set -DnewVersion=${CI_COMMIT_TAG} + - mvn clean install -DskipTests + - mvn deploy -DskipTests -Dmaven.install.skip=true + + diff --git a/.m2/settings.xml b/.m2/settings.xml new file mode 100644 index 00000000..be2f79fb --- /dev/null +++ b/.m2/settings.xml @@ -0,0 +1,10 @@ + + + + snapshot-repository + ${env.MAVEN_REPO_USER} + ${env.MAVEN_REPO_PASS} + + + diff --git a/pom.xml b/pom.xml index b5d11c3c..04d47466 100644 --- a/pom.xml +++ b/pom.xml @@ -373,12 +373,12 @@ release-repository - https://oss.sonatype.org/service/local/staging/deploy/maven2 + ${env.MAVEN_RELEASE_REPOSITORY} snapshot-repository Maven2 Snapshot Repository - https://oss.sonatype.org/content/repositories/snapshots + ${env.MAVEN_SNAPSHOT_REPOSITORY} false From 5a4f38f56c16f6f3810ddc4aa1aff09c4885db31 Mon Sep 17 00:00:00 2001 From: "Robert.Schreib" Date: Fri, 6 Sep 2019 10:12:46 +0200 Subject: [PATCH 38/41] Correct CI script naming --- .gitlab-ci.yaml => .gitlab-ci.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .gitlab-ci.yaml => .gitlab-ci.yml (100%) diff --git a/.gitlab-ci.yaml b/.gitlab-ci.yml similarity index 100% rename from .gitlab-ci.yaml rename to .gitlab-ci.yml From e10becd89b8a0c0deb2b4d4ca483e0c8579be90f Mon Sep 17 00:00:00 2001 From: "Robert.Schreib" Date: Fri, 6 Sep 2019 10:18:35 +0200 Subject: [PATCH 39/41] Add license headers ci cache and reformat code --- .gitlab-ci.yml | 22 ++++ .m2/settings.xml | 15 +++ .../adm/nga/sdk/generate/GenerateModels.java | 104 +++++++++++------- 3 files changed, 101 insertions(+), 40 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 018975c8..cbafcfe9 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,6 +1,28 @@ +# +# Copyright 2017 EntIT Software LLC, a Micro Focus company, L.P. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + stages: - publish +variables: + MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository" + +cache: + paths: + - .m2/repository/ + - target/ + publish-sdk: image: maven:3-jdk-8-slim stage: publish diff --git a/.m2/settings.xml b/.m2/settings.xml index be2f79fb..b0838333 100644 --- a/.m2/settings.xml +++ b/.m2/settings.xml @@ -1,3 +1,18 @@ + diff --git a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java index 040c15b8..d97cb7cc 100644 --- a/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java +++ b/sdk-generate-entity-models-maven-plugin/src/main/java/com/hpe/adm/nga/sdk/generate/GenerateModels.java @@ -78,7 +78,8 @@ public class GenerateModels { * Initialise the class with the output directory. This should normally be * in a project that would be imported into the main Java project * - * @param outputDirectory Where all the generated files will be placed + * @param outputDirectory + * Where all the generated files will be placed */ public GenerateModels(final File outputDirectory) { final File packageDirectory = new File(outputDirectory, "/com/hpe/adm/nga/sdk"); @@ -108,12 +109,18 @@ public GenerateModels(final File outputDirectory) { /** * Run the actual generation * - * @param clientId The client id - * @param clientSecret The client secret - * @param server The server including the protocol and port - * @param sharedSpace The SS id - * @param workSpace The WS id - * @throws IOException A problem with the generation of the entities + * @param clientId + * The client id + * @param clientSecret + * The client secret + * @param server + * The server including the protocol and port + * @param sharedSpace + * The SS id + * @param workSpace + * The WS id + * @throws IOException + * A problem with the generation of the entities */ public void generate(final String clientId, final String clientSecret, final String server, final long sharedSpace, final long workSpace) throws IOException { @@ -123,20 +130,30 @@ public void generate(final String clientId, final String clientSecret, final Str /** * Run the actual generation * - * @param clientId The client id - * @param clientSecret The client secret - * @param server The server including the protocol and port - * @param sharedSpace The SS id - * @param workSpace The WS id - * @param doNotValidateCertificate Disables validating server SSL certificates - * @throws IOException A problem with the generation of the entities + * @param clientId + * The client id + * @param clientSecret + * The client secret + * @param server + * The server including the protocol and port + * @param sharedSpace + * The SS id + * @param workSpace + * The WS id + * @param doNotValidateCertificate + * Disables validating server SSL certificates + * @throws IOException + * A problem with the generation of the entities */ public void generate(final String clientId, final String clientSecret, final String server, final long sharedSpace, final long workSpace, final boolean doNotValidateCertificate) throws IOException { // work around for work_items_root final Octane octanePrivate = new Octane.Builder( - new SimpleClientAuthentication(clientId, clientSecret, "HPE_REST_API_TECH_PREVIEW")).sharedSpace( - sharedSpace).workSpace(workSpace).Server(server).build(doNotValidateCertificate); + new SimpleClientAuthentication(clientId, clientSecret, "HPE_REST_API_TECH_PREVIEW")) + .sharedSpace(sharedSpace) + .workSpace(workSpace) + .Server(server) + .build(doNotValidateCertificate); final EntityMetadata work_items_root = octanePrivate.metadata() .entities("work_item_root") .execute() @@ -148,8 +165,11 @@ public void generate(final String clientId, final String clientSecret, final Str octanePrivate.signOut(); - final Octane octane = new Octane.Builder(new SimpleClientAuthentication(clientId, clientSecret)).sharedSpace( - sharedSpace).workSpace(workSpace).Server(server).build(doNotValidateCertificate); + final Octane octane = new Octane.Builder(new SimpleClientAuthentication(clientId, clientSecret)) + .sharedSpace(sharedSpace) + .workSpace(workSpace) + .Server(server) + .build(doNotValidateCertificate); final Metadata metadata = octane.metadata(); final Collection entityMetadata = metadata.entities().execute(); entityMetadata.add(work_items_root); @@ -182,8 +202,9 @@ private Map generateLists(final Octane octane) throws IOExceptio final OctaneCollection models = octane.entityList("list_nodes") .get() .addFields("name", "list_root", "id", "logical_name", "activity_level") - .query(Query.statement("list_root", QueryMethod.EqualTo, - Query.statement("id", QueryMethod.EqualTo, rootNode.getId())) + .query(Query + .statement("list_root", QueryMethod.EqualTo, + Query.statement("id", QueryMethod.EqualTo, rootNode.getId())) .and(Query.statement("activity_level", QueryMethod.LessThan, 2)) .build()) .execute(); @@ -235,8 +256,7 @@ private Map generateLists(final Octane octane) throws IOExceptio name, // rootNode.getId(), // ((StringFieldModel) rootNode.getValue("name")).getValue(), // - ((LongFieldModel) rootNode.getValue("activity_level")).getValue().toString() - }); + ((LongFieldModel) rootNode.getValue("activity_level")).getValue().toString() }); }); final Map> sortedMappedListNodes = new TreeMap<>(); @@ -280,7 +300,8 @@ private Set generatePhases(final Octane octane) throws IOException { }); phaseMap.merge( GeneratorHelper.camelCaseFieldName(((StringFieldModel) phase.getValue("entity")).getValue(), - true), phaseValueList, // + true), + phaseValueList, // (existingValues, newValues) -> { existingValues.addAll(newValues); return existingValues; @@ -311,14 +332,14 @@ private Collection generateEntity(final Collection if (fieldMetadata1.getName().equals("phase") && availablePhases.contains(className)) { references.add("com.hpe.adm.nga.sdk.enums.Phases." + className + "Phase"); } else if (fieldMetadata1.getFieldType() == FieldMetadata.FieldType.Reference) { - if ((!entityMetadatum.getName().equals("list_node")) && (fieldMetadata1.getFieldTypedata() - .getTargets()[0].getType().equals("list_node"))) { - final String listName = logicalNameToListsMap.get( - fieldMetadata1.getFieldTypedata().getTargets()[0].logicalName()); + if ((!entityMetadatum.getName().equals("list_node")) + && (fieldMetadata1.getFieldTypedata().getTargets()[0].getType().equals("list_node"))) { + final String listName = logicalNameToListsMap + .get(fieldMetadata1.getFieldTypedata().getTargets()[0].logicalName()); references.add("com.hpe.adm.nga.sdk.enums.Lists." + listName); } else { - final GeneratorHelper.ReferenceMetadata referenceMetadata = GeneratorHelper.getAllowedSuperTypesForReference( - fieldMetadata1, entityMetadata); + final GeneratorHelper.ReferenceMetadata referenceMetadata = GeneratorHelper + .getAllowedSuperTypesForReference(fieldMetadata1, entityMetadata); if (fieldMetadata1.getFieldTypedata().isMultiple()) { references.add(referenceMetadata.getReferenceClassForSignature()); } else { @@ -346,7 +367,8 @@ private Collection generateEntity(final Collection if (!collectedReferences.isEmpty()) { expandCollectedReferences(collectedReferences, new int[collectedReferences.size()], 0, requiredFields); } - // Die Id muss immer vom Typ String sein, da es sonst Compile fehler gibt. siehe com.hpe.adm.nga.sdk.model.Entity + // Die Id muss immer vom Typ String sein, da es sonst Compile fehler + // gibt. siehe com.hpe.adm.nga.sdk.model.Entity fieldMetadata.forEach(field -> { if (field.getName().equalsIgnoreCase("id")) { @@ -405,9 +427,10 @@ private void generateInterface(final EntityMetadata entityMetadatum, final Strin interfaceVelocityContext.put("interfaceName", interfaceName); interfaceVelocityContext.put("name", name); - interfaceVelocityContext.put("superInterfaceName", (subTypeOfFeature.map( - feature -> GeneratorHelper.camelCaseFieldName(((SubTypesOfFeature) feature).getType())).orElse("")) - + "Entity"); + interfaceVelocityContext.put("superInterfaceName", + (subTypeOfFeature + .map(feature -> GeneratorHelper.camelCaseFieldName(((SubTypesOfFeature) feature).getType())) + .orElse("")) + "Entity"); final FileWriter interfaceFileWriter = new FileWriter( new File(modelDirectory, GeneratorHelper.camelCaseFieldName(name) + "Entity.java")); @@ -431,13 +454,14 @@ private void generateEntityList(final EntityMetadata entityMetadatum, final Stri entityListVelocityContext.put("helper", GeneratorHelper.class); entityListVelocityContext.put("type", GeneratorHelper.camelCaseFieldName(name)); entityListVelocityContext.put("url", restFeature.getUrl()); - entityListVelocityContext.put("availableFields", fieldMetadata.stream() - .sorted(Comparator.comparing(FieldMetadata::getName)) - .collect(Collectors.toList())); - entityListVelocityContext.put("sortableFields", fieldMetadata.stream() - .filter(FieldMetadata::isSortable) - .sorted(Comparator.comparing(FieldMetadata::getName)) - .collect(Collectors.toList())); + entityListVelocityContext.put("availableFields", + fieldMetadata.stream().sorted(Comparator.comparing(FieldMetadata::getName)).collect( + Collectors.toList())); + entityListVelocityContext.put("sortableFields", + fieldMetadata.stream() + .filter(FieldMetadata::isSortable) + .sorted(Comparator.comparing(FieldMetadata::getName)) + .collect(Collectors.toList())); final String[] restFeatureMethods = restFeature.getMethods(); for (final String restFeatureMethod : restFeatureMethods) { From fa34361b6e06ff5af3b1639adff4947b7671f9ee Mon Sep 17 00:00:00 2001 From: "Robert.Schreib" Date: Fri, 6 Sep 2019 10:21:09 +0200 Subject: [PATCH 40/41] Remove cache because of license header problems --- .gitlab-ci.yml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index cbafcfe9..5056cdc0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -15,14 +15,6 @@ stages: - publish -variables: - MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository" - -cache: - paths: - - .m2/repository/ - - target/ - publish-sdk: image: maven:3-jdk-8-slim stage: publish From fef7b184561d6a1ee1dc2bcea337ba1e41248d3e Mon Sep 17 00:00:00 2001 From: "Robert.Schreib" Date: Fri, 6 Sep 2019 13:44:46 +0200 Subject: [PATCH 41/41] Settings xml setzen --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5056cdc0..a12bd63b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -23,6 +23,6 @@ publish-sdk: script: - mvn versions:set -DnewVersion=${CI_COMMIT_TAG} - mvn clean install -DskipTests - - mvn deploy -DskipTests -Dmaven.install.skip=true + - mvn deploy --settings .m2/settings.xml -DskipTests -Dmaven.install.skip=true