summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFiete Ostkamp <Fiete.Ostkamp@telekom.de>2022-11-10 11:03:00 +0000
committerFiete Ostkamp <Fiete.Ostkamp@telekom.de>2022-11-10 11:03:00 +0000
commitf8c058b2be718ab825f88e10e43ed59d5ca75de2 (patch)
tree7078532cf899cc9d618345aac2c865e233663e01
parenta8e838713d168e7cd81c9765d5e5a56b88e48def (diff)
Reduce the number of problems in schema-service
Issue-ID: AAI-3590 Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de> Change-Id: I7a5d3e5a4db75efb8a8fcc6c8598d6cab80dca4a
-rw-r--r--aai-queries/src/main/java/org/onap/aai/queries/GetCustomQueryConfig.java12
-rw-r--r--aai-queries/src/test/java/org/onap/aai/queries/AAISetup.java3
-rw-r--r--aai-queries/src/test/java/org/onap/aai/queries/OnapQueryTest.java11
-rw-r--r--aai-schema-gen/src/main/java/org/onap/aai/schemagen/AutoGenerateHtml.java57
-rw-r--r--aai-schema-gen/src/main/java/org/onap/aai/schemagen/GenerateXsd.java283
-rw-r--r--aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/HTMLfromOXM.java2
-rw-r--r--aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/NodesYAMLfromOXM.java2
-rw-r--r--aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/OxmFileProcessor.java9
-rw-r--r--aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/YAMLfromOXM.java3
-rw-r--r--aai-schema-gen/src/main/java/org/onap/aai/schemagen/swagger/GenerateSwagger.java18
-rw-r--r--aai-schema-service/src/main/java/org/onap/aai/schemaservice/SchemaServiceApp.java5
-rw-r--r--aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/PropertyPasswordConfiguration.java3
-rw-r--r--aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/post/InvalidResponseStatus.java2
-rw-r--r--aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/NodeIngestor.java12
-rw-r--r--aai-schema-service/src/main/java/org/onap/aai/schemaservice/web/JerseyConfiguration.java2
-rw-r--r--aai-schema-service/src/test/java/org/onap/aai/schemaservice/SchemaServiceTest.java26
-rw-r--r--aai-schema/src/test/java/org/onap/aai/schema/ValidateOXMTest.java3
-rw-r--r--pom.xml1
18 files changed, 234 insertions, 220 deletions
diff --git a/aai-queries/src/main/java/org/onap/aai/queries/GetCustomQueryConfig.java b/aai-queries/src/main/java/org/onap/aai/queries/GetCustomQueryConfig.java
index 07f7724..f9cebf2 100644
--- a/aai-queries/src/main/java/org/onap/aai/queries/GetCustomQueryConfig.java
+++ b/aai-queries/src/main/java/org/onap/aai/queries/GetCustomQueryConfig.java
@@ -20,7 +20,11 @@
package org.onap.aai.queries;
-import com.google.gson.*;
+import com.google.gson.Gson;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;
@@ -38,16 +42,12 @@ public class GetCustomQueryConfig {
private final static String STORED_QUERIES_CONFIG = "stored-queries";
private final static String STORED_QUERY_CONFIG = "stored-query";
- // public static final String AAI_HOME_ETC_QUERY_JSON = AAIConstants.AAI_HOME_ETC + "query" +
- // AAIConstants.AAI_FILESEP + "stored-queries.json";
-
public GetCustomQueryConfig(String customQueryJson) {
init(customQueryJson);
}
private void init(String customQueryJson) {
- JsonParser parser = new JsonParser();
- JsonObject queriesObject = parser.parse(customQueryJson).getAsJsonObject();
+ JsonObject queriesObject = JsonParser.parseString(customQueryJson).getAsJsonObject();
if (queriesObject.has(STORED_QUERIES_CONFIG)) {
storedQueries = queriesObject.getAsJsonArray(STORED_QUERIES_CONFIG);
diff --git a/aai-queries/src/test/java/org/onap/aai/queries/AAISetup.java b/aai-queries/src/test/java/org/onap/aai/queries/AAISetup.java
index 2ca90ea..99d74a1 100644
--- a/aai-queries/src/test/java/org/onap/aai/queries/AAISetup.java
+++ b/aai-queries/src/test/java/org/onap/aai/queries/AAISetup.java
@@ -24,6 +24,7 @@ import static org.junit.Assert.assertNotNull;
import java.io.IOException;
import java.io.InputStream;
+import java.nio.charset.Charset;
import java.util.Map;
import org.apache.commons.io.IOUtils;
@@ -108,7 +109,7 @@ public abstract class AAISetup {
String message = String.format("Unable to find the %s in src/test/resources", filename);
assertNotNull(message, inputStream);
- String resource = IOUtils.toString(inputStream);
+ String resource = IOUtils.toString(inputStream, Charset.defaultCharset());
return resource;
}
}
diff --git a/aai-queries/src/test/java/org/onap/aai/queries/OnapQueryTest.java b/aai-queries/src/test/java/org/onap/aai/queries/OnapQueryTest.java
index 7c766c9..84051b0 100644
--- a/aai-queries/src/test/java/org/onap/aai/queries/OnapQueryTest.java
+++ b/aai-queries/src/test/java/org/onap/aai/queries/OnapQueryTest.java
@@ -24,16 +24,7 @@ import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.when;
-import com.google.gson.Gson;
-import com.google.gson.stream.JsonReader;
-import com.jayway.jsonpath.JsonPath;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
import java.io.IOException;
-import java.nio.charset.Charset;
-import java.nio.file.Files;
import java.util.*;
import java.util.stream.Collectors;
@@ -42,7 +33,6 @@ import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSo
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
-import org.json.JSONObject;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.ClassRule;
@@ -61,7 +51,6 @@ import org.onap.aai.introspection.Loader;
import org.onap.aai.introspection.LoaderFactory;
import org.onap.aai.introspection.ModelType;
import org.onap.aai.nodes.NodeIngestor;
-import org.onap.aai.queries.GremlinServerSingleton;
import org.onap.aai.query.builder.GremlinTraversal;
import org.onap.aai.restcore.search.GremlinGroovyShell;
import org.onap.aai.restcore.search.GroovyQueryBuilder;
diff --git a/aai-schema-gen/src/main/java/org/onap/aai/schemagen/AutoGenerateHtml.java b/aai-schema-gen/src/main/java/org/onap/aai/schemagen/AutoGenerateHtml.java
index ae5426f..9460175 100644
--- a/aai-schema-gen/src/main/java/org/onap/aai/schemagen/AutoGenerateHtml.java
+++ b/aai-schema-gen/src/main/java/org/onap/aai/schemagen/AutoGenerateHtml.java
@@ -33,10 +33,14 @@ import java.util.ListIterator;
import org.onap.aai.schemagen.swagger.GenerateSwagger;
import org.onap.aai.setup.SchemaVersion;
import org.onap.aai.setup.SchemaVersions;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.BeansException;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
public class AutoGenerateHtml {
+ private static Logger logger = LoggerFactory.getLogger(AutoGenerateHtml.class);
private static final String AAI_GENERATE_VERSION = "aai.generate.version";
public static final String DEFAULT_SCHEMA_DIR = "../aai-schema";
// if the program is run from aai-common, use this directory as default"
@@ -47,34 +51,37 @@ public class AutoGenerateHtml {
public static void main(String[] args) throws IOException, TemplateException {
String savedProperty = System.getProperty(AAI_GENERATE_VERSION);
- AnnotationConfigApplicationContext ctx =
- new AnnotationConfigApplicationContext("org.onap.aai.setup", "org.onap.aai.schemagen");
+ try (AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(
+ "org.onap.aai.setup", "org.onap.aai.schemagen")) {
+ SchemaVersions schemaVersions = ctx.getBean(SchemaVersions.class);
- SchemaVersions schemaVersions = ctx.getBean(SchemaVersions.class);
-
- List<SchemaVersion> versionsToGen = schemaVersions.getVersions();
- Collections.sort(versionsToGen);
- Collections.reverse(versionsToGen);
- ListIterator<SchemaVersion> versionIterator = versionsToGen.listIterator();
- String schemaDir;
- if (System.getProperty("user.dir") != null
- && !System.getProperty("user.dir").contains(DEFAULT_RUN_DIR)) {
- schemaDir = ALT_SCHEMA_DIR;
- } else {
- schemaDir = DEFAULT_SCHEMA_DIR;
- }
- String release = System.getProperty("aai.release", "onap");
- while (versionIterator.hasNext()) {
- System.setProperty(AAI_GENERATE_VERSION, versionIterator.next().toString());
- String yamlFile =
- schemaDir + "/src/main/resources/" + release + "/aai_swagger_yaml/aai_swagger_"
- + System.getProperty(AAI_GENERATE_VERSION) + ".yaml";
- File swaggerYamlFile = new File(yamlFile);
- if (swaggerYamlFile.exists()) {
- GenerateSwagger.schemaVersions = schemaVersions;
- GenerateSwagger.main(args);
+ List<SchemaVersion> versionsToGen = schemaVersions.getVersions();
+ Collections.sort(versionsToGen);
+ Collections.reverse(versionsToGen);
+ ListIterator<SchemaVersion> versionIterator = versionsToGen.listIterator();
+ String schemaDir;
+ if (System.getProperty("user.dir") != null
+ && !System.getProperty("user.dir").contains(DEFAULT_RUN_DIR)) {
+ schemaDir = ALT_SCHEMA_DIR;
+ } else {
+ schemaDir = DEFAULT_SCHEMA_DIR;
}
+ String release = System.getProperty("aai.release", "onap");
+ while (versionIterator.hasNext()) {
+ System.setProperty(AAI_GENERATE_VERSION, versionIterator.next().toString());
+ String yamlFile =
+ schemaDir + "/src/main/resources/" + release + "/aai_swagger_yaml/aai_swagger_"
+ + System.getProperty(AAI_GENERATE_VERSION) + ".yaml";
+ File swaggerYamlFile = new File(yamlFile);
+ if (swaggerYamlFile.exists()) {
+ GenerateSwagger.schemaVersions = schemaVersions;
+ GenerateSwagger.main(args);
+ }
+ }
+ } catch (BeansException e) {
+ logger.warn("Unable to initialize AnnotationConfigApplicationContext ", e);
}
+
System.setProperty(AAI_GENERATE_VERSION, savedProperty);
}
}
diff --git a/aai-schema-gen/src/main/java/org/onap/aai/schemagen/GenerateXsd.java b/aai-schema-gen/src/main/java/org/onap/aai/schemagen/GenerateXsd.java
index 490e290..2655e3c 100644
--- a/aai-schema-gen/src/main/java/org/onap/aai/schemagen/GenerateXsd.java
+++ b/aai-schema-gen/src/main/java/org/onap/aai/schemagen/GenerateXsd.java
@@ -28,7 +28,11 @@ import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import org.onap.aai.schemagen.genxsd.HTMLfromOXM;
import org.onap.aai.schemagen.genxsd.NodesYAMLfromOXM;
@@ -37,12 +41,13 @@ import org.onap.aai.setup.SchemaVersion;
import org.onap.aai.setup.SchemaVersions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.beans.BeansException;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.w3c.dom.NodeList;
public class GenerateXsd {
- private static final Logger logger = LoggerFactory.getLogger("GenerateXsd.class");
+ private static final Logger logger = LoggerFactory.getLogger(GenerateXsd.class);
protected static String apiVersion = null;
public static AnnotationConfigApplicationContext ctx = null;
static String apiVersionFmt = null;
@@ -149,170 +154,174 @@ public class GenerateXsd {
fileTypeToGen = fileTypeToGen.toLowerCase();
}
- AnnotationConfigApplicationContext ctx =
- new AnnotationConfigApplicationContext("org.onap.aai.setup", "org.onap.aai.schemagen");
+ try (AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(
+ "org.onap.aai.setup", "org.onap.aai.schemagen")) {
+ SchemaVersions schemaVersions = ctx.getBean(SchemaVersions.class);
- SchemaVersions schemaVersions = ctx.getBean(SchemaVersions.class);
-
- if (!fileTypeToGen.equals(GENERATE_TYPE_XSD) && !fileTypeToGen.equals(GENERATE_TYPE_YAML)) {
- System.err.println("Invalid gen_type passed. " + fileTypeToGen);
- System.exit(1);
- }
-
- String responsesLabel = System.getProperty("yamlresponses_url");
- responsesUrl = responsesLabel;
+ if (!fileTypeToGen.equals(GENERATE_TYPE_XSD)
+ && !fileTypeToGen.equals(GENERATE_TYPE_YAML)) {
+ System.err.println("Invalid gen_type passed. " + fileTypeToGen);
+ System.exit(1);
+ }
- List<SchemaVersion> versionsToGen = new ArrayList<>();
- if (!"ALL".equalsIgnoreCase(versionToGen) && !versionToGen.matches("v\\d+")
- && !validVersion(versionToGen)) {
- System.err.println("Invalid version passed. " + versionToGen);
- System.exit(1);
- } else if ("ALL".equalsIgnoreCase(versionToGen)) {
- versionsToGen = schemaVersions.getVersions();
- Collections.sort(versionsToGen);
- Collections.reverse(versionsToGen);
- } else {
- versionsToGen.add(new SchemaVersion(versionToGen));
- }
+ String responsesLabel = System.getProperty("yamlresponses_url");
+ responsesUrl = responsesLabel;
- // process file type System property
- if (fileTypeToGen.equals(GENERATE_TYPE_YAML)) {
- if (responsesUrl == null || responsesUrl.length() < 1 || responsesLabel == null
- || responsesLabel.length() < 1) {
- System.err.println(
- "generating swagger yaml file requires yamlresponses_url and yamlresponses_label properties");
+ List<SchemaVersion> versionsToGen = new ArrayList<>();
+ if (!"ALL".equalsIgnoreCase(versionToGen) && versionToGen != null
+ && !versionToGen.matches("v\\d+") && !validVersion(versionToGen)) {
+ System.err.println("Invalid version passed. " + versionToGen);
System.exit(1);
+ } else if ("ALL".equalsIgnoreCase(versionToGen)) {
+ versionsToGen = schemaVersions.getVersions();
+ Collections.sort(versionsToGen);
+ Collections.reverse(versionsToGen);
} else {
- responsesUrl = "description: " + "Response codes found in [response codes]("
- + responsesLabel + ").\n";
+ versionsToGen.add(new SchemaVersion(versionToGen));
}
- }
- /*
- * TODO: Oxm Path is config driveb
- */
- String oxmPath;
- if (System.getProperty("user.dir") != null
- && !System.getProperty("user.dir").contains(NORMAL_START_DIR)) {
- oxmPath = BASE_AUTO_GEN_ROOT + NODE_DIR;
- } else {
- oxmPath = BASE_ROOT + NODE_DIR;
- }
- String outfileName = null;
- File outfile;
- String nodesfileName = null;
- File nodesfile;
- String fileContent = null;
- String nodesContent = null;
-
- for (SchemaVersion v : versionsToGen) {
- apiVersion = v.toString();
- logger.debug("YAMLdir = " + YAML_DIR);
- logger.debug("Generating " + apiVersion + " " + fileTypeToGen);
- apiVersionFmt = "." + apiVersion + ".";
- generatedJavaType = new HashMap<String, String>();
- appliedPaths = new HashMap<String, String>();
- File edgeRuleFile = null;
- String fileName = EDGE_DIR + "DbEdgeRules_" + apiVersion + ".json";
- logger.debug("user.dir = " + System.getProperty("user.dir"));
+ // process file type System property
+ if (fileTypeToGen.equals(GENERATE_TYPE_YAML)) {
+ if (responsesUrl == null || responsesUrl.length() < 1 || responsesLabel == null
+ || responsesLabel.length() < 1) {
+ System.err.println(
+ "generating swagger yaml file requires yamlresponses_url and yamlresponses_label properties");
+ System.exit(1);
+ } else {
+ responsesUrl = "description: " + "Response codes found in [response codes]("
+ + responsesLabel + ").\n";
+ }
+ }
+ /*
+ * TODO: Oxm Path is config driven
+ */
+ String oxmPath;
if (System.getProperty("user.dir") != null
&& !System.getProperty("user.dir").contains(NORMAL_START_DIR)) {
- fileName = BASE_AUTO_GEN_ROOT + fileName;
-
+ oxmPath = BASE_AUTO_GEN_ROOT + NODE_DIR;
} else {
- fileName = BASE_ROOT + fileName;
-
+ oxmPath = BASE_ROOT + NODE_DIR;
}
- edgeRuleFile = new File(fileName);
- // Document doc = ni.getSchema(translateVersion(v));
- if (fileTypeToGen.equals(GENERATE_TYPE_XSD)) {
- outfileName = XSD_DIR + "/aai_schema_" + apiVersion + "." + GENERATE_TYPE_XSD;
- try {
- HTMLfromOXM swagger = ctx.getBean(HTMLfromOXM.class);
- swagger.setVersion(v);
- fileContent = swagger.process();
- if (fileContent.startsWith("Schema format issue")) {
- throw new Exception(fileContent);
- }
- } catch (Exception e) {
- logger.error("Exception creating output file " + outfileName);
- logger.error(e.getMessage());
- System.exit(-1);
+ String outfileName = null;
+ File outfile;
+ String nodesfileName = null;
+ File nodesfile;
+ String fileContent = null;
+ String nodesContent = null;
+
+ for (SchemaVersion v : versionsToGen) {
+ apiVersion = v.toString();
+ logger.debug("YAMLdir = " + YAML_DIR);
+ logger.debug("Generating " + apiVersion + " " + fileTypeToGen);
+ apiVersionFmt = "." + apiVersion + ".";
+ generatedJavaType = new HashMap<String, String>();
+ appliedPaths = new HashMap<String, String>();
+ File edgeRuleFile = null;
+ String fileName = EDGE_DIR + "DbEdgeRules_" + apiVersion + ".json";
+ logger.debug("user.dir = " + System.getProperty("user.dir"));
+ if (System.getProperty("user.dir") != null
+ && !System.getProperty("user.dir").contains(NORMAL_START_DIR)) {
+ fileName = BASE_AUTO_GEN_ROOT + fileName;
+
+ } else {
+ fileName = BASE_ROOT + fileName;
+
}
- } else if (versionSupportsSwagger(apiVersion)) {
- outfileName = YAML_DIR + "/aai_swagger_" + apiVersion + "." + GENERATE_TYPE_YAML;
- nodesfileName = YAML_DIR + "/aai_swagger_" + apiVersion + "." + "nodes" + "."
- + GENERATE_TYPE_YAML;
- try {
- YAMLfromOXM swagger = (YAMLfromOXM) ctx.getBean(YAMLfromOXM.class);
- swagger.setVersion(v);
- fileContent = swagger.process();
- Map combinedJavaTypes = swagger.getCombinedJavaTypes();
- NodesYAMLfromOXM nodesSwagger = ctx.getBean(NodesYAMLfromOXM.class);
- nodesSwagger.setVersion(v);
- nodesSwagger.setCombinedJavaTypes(combinedJavaTypes);
- nodesContent = nodesSwagger.process();
- } catch (Exception e) {
- logger.error("Exception creating output file " + outfileName, e);
+ edgeRuleFile = new File(fileName);
+ // Document doc = ni.getSchema(translateVersion(v));
+
+ if (fileTypeToGen.equals(GENERATE_TYPE_XSD)) {
+ outfileName = XSD_DIR + "/aai_schema_" + apiVersion + "." + GENERATE_TYPE_XSD;
+ try {
+ HTMLfromOXM swagger = ctx.getBean(HTMLfromOXM.class);
+ swagger.setVersion(v);
+ fileContent = swagger.process();
+ if (fileContent.startsWith("Schema format issue")) {
+ throw new Exception(fileContent);
+ }
+ } catch (Exception e) {
+ logger.error("Exception creating output file " + outfileName);
+ logger.error(e.getMessage());
+ System.exit(-1);
+ }
+ } else if (versionSupportsSwagger(apiVersion)) {
+ outfileName =
+ YAML_DIR + "/aai_swagger_" + apiVersion + "." + GENERATE_TYPE_YAML;
+ nodesfileName = YAML_DIR + "/aai_swagger_" + apiVersion + "." + "nodes" + "."
+ + GENERATE_TYPE_YAML;
+ try {
+ YAMLfromOXM swagger = (YAMLfromOXM) ctx.getBean(YAMLfromOXM.class);
+ swagger.setVersion(v);
+ fileContent = swagger.process();
+ Map<String, Integer> combinedJavaTypes = swagger.getCombinedJavaTypes();
+ NodesYAMLfromOXM nodesSwagger = ctx.getBean(NodesYAMLfromOXM.class);
+ nodesSwagger.setVersion(v);
+ nodesSwagger.setCombinedJavaTypes(combinedJavaTypes);
+ nodesContent = nodesSwagger.process();
+ } catch (Exception e) {
+ logger.error("Exception creating output file " + outfileName, e);
+ }
+ } else {
+ continue;
}
- } else {
- continue;
- }
- outfile = new File(outfileName);
- File parentDir = outfile.getParentFile();
- if (!parentDir.exists()) {
- parentDir.mkdirs();
- }
- if (nodesfileName != null) {
- BufferedWriter nodesBW = null;
- nodesfile = new File(nodesfileName);
- parentDir = nodesfile.getParentFile();
+ outfile = new File(outfileName);
+ File parentDir = outfile.getParentFile();
if (!parentDir.exists()) {
parentDir.mkdirs();
}
+ if (nodesfileName != null) {
+ BufferedWriter nodesBW = null;
+ nodesfile = new File(nodesfileName);
+ parentDir = nodesfile.getParentFile();
+ if (!parentDir.exists()) {
+ parentDir.mkdirs();
+ }
+ try {
+ if (!nodesfile.createNewFile()) {
+ logger.error("File {} already exist", nodesfileName);
+ }
+ } catch (IOException e) {
+ logger.error("Exception creating output file " + nodesfileName, e);
+ }
+ try {
+ Charset charset = StandardCharsets.UTF_8;
+ Path path = Paths.get(nodesfileName);
+ nodesBW = Files.newBufferedWriter(path, charset);
+ nodesBW.write(nodesContent);
+ } catch (IOException e) {
+ logger.error("Exception writing output file " + outfileName, e);
+ } finally {
+ if (nodesBW != null) {
+ nodesBW.close();
+ }
+ }
+ }
+
try {
- if (!nodesfile.createNewFile()) {
- logger.error("File {} already exist", nodesfileName);
+ if (!outfile.createNewFile()) {
+ logger.error("File {} already exist", outfileName);
}
} catch (IOException e) {
- logger.error("Exception creating output file " + nodesfileName, e);
+ logger.error("Exception creating output file " + outfileName, e);
}
+ BufferedWriter bw = null;
try {
Charset charset = StandardCharsets.UTF_8;
- Path path = Paths.get(nodesfileName);
- nodesBW = Files.newBufferedWriter(path, charset);
- nodesBW.write(nodesContent);
+ Path path = Paths.get(outfileName);
+ bw = Files.newBufferedWriter(path, charset);
+ bw.write(fileContent);
} catch (IOException e) {
logger.error("Exception writing output file " + outfileName, e);
} finally {
- if (nodesBW != null) {
- nodesBW.close();
+ if (bw != null) {
+ bw.close();
}
}
+ logger.debug("GeneratedXSD successful, saved in " + outfileName);
}
-
- try {
- if (!outfile.createNewFile()) {
- logger.error("File {} already exist", outfileName);
- }
- } catch (IOException e) {
- logger.error("Exception creating output file " + outfileName, e);
- }
- BufferedWriter bw = null;
- try {
- Charset charset = StandardCharsets.UTF_8;
- Path path = Paths.get(outfileName);
- bw = Files.newBufferedWriter(path, charset);
- bw.write(fileContent);
- } catch (IOException e) {
- logger.error("Exception writing output file " + outfileName, e);
- } finally {
- if (bw != null) {
- bw.close();
- }
- }
- logger.debug("GeneratedXSD successful, saved in " + outfileName);
+ } catch (BeansException e) {
+ logger.warn("Unable to initialize AnnotationConfigApplicationContext ", e);
}
}
diff --git a/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/HTMLfromOXM.java b/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/HTMLfromOXM.java
index 980a3f3..c1cf5ac 100644
--- a/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/HTMLfromOXM.java
+++ b/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/HTMLfromOXM.java
@@ -106,7 +106,7 @@ public class HTMLfromOXM extends OxmFileProcessor {
StringBuilder sbInventory = new StringBuilder();
Element elem;
String javaTypeName;
- combinedJavaTypes = new HashMap();
+ combinedJavaTypes = new HashMap<>();
for (int i = 0; i < javaTypeNodes.getLength(); ++i) {
elem = (Element) javaTypeNodes.item(i);
javaTypeName = elem.getAttribute("name");
diff --git a/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/NodesYAMLfromOXM.java b/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/NodesYAMLfromOXM.java
index 8bceb5c..77c76cb 100644
--- a/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/NodesYAMLfromOXM.java
+++ b/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/NodesYAMLfromOXM.java
@@ -461,7 +461,7 @@ public class NodesYAMLfromOXM extends OxmFileProcessor {
}
pathParams.append(sbParameters);
}
- if (indexedProps.isEmpty() && containerProps.isEmpty()) {
+ if (indexedProps != null && indexedProps.isEmpty() && containerProps.isEmpty()) {
NodeGetOperation get =
new NodeGetOperation(useOpId, xmlRootElementName, tag, path, null);
String operation = get.toString();
diff --git a/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/OxmFileProcessor.java b/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/OxmFileProcessor.java
index fde0877..150bab7 100644
--- a/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/OxmFileProcessor.java
+++ b/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/OxmFileProcessor.java
@@ -24,7 +24,6 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.StringReader;
-import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -72,7 +71,7 @@ public abstract class OxmFileProcessor {
protected Document doc = null;
protected String apiVersion = null;
protected SchemaVersions schemaVersions;
- protected Map combinedJavaTypes;
+ protected Map<String, Integer> combinedJavaTypes;
protected String apiVersionFmt = null;
protected List<String> topLevelPaths = new ArrayList<String>();
protected HashMap<String, String> generatedJavaType = new HashMap<String, String>();
@@ -299,11 +298,11 @@ public abstract class OxmFileProcessor {
return null;
}
- public Map getCombinedJavaTypes() {
+ public Map<String, Integer> getCombinedJavaTypes() {
return combinedJavaTypes;
}
- public void setCombinedJavaTypes(Map combinedJavaTypes) {
+ public void setCombinedJavaTypes(Map<String, Integer> combinedJavaTypes) {
this.combinedJavaTypes = combinedJavaTypes;
}
@@ -479,7 +478,7 @@ public abstract class OxmFileProcessor {
int useElement = -1;
if (combinedJavaTypes.containsKey(javaTypeName)) {
- return combineElementList.get((int) combinedJavaTypes.get(javaTypeName));
+ return combineElementList.get(combinedJavaTypes.get(javaTypeName));
}
for (int i = 0; i < combineElementList.size(); ++i) {
javaTypeElement = combineElementList.get(i);
diff --git a/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/YAMLfromOXM.java b/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/YAMLfromOXM.java
index ff6f7dd..3b8fa4d 100644
--- a/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/YAMLfromOXM.java
+++ b/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/YAMLfromOXM.java
@@ -20,7 +20,6 @@
package org.onap.aai.schemagen.genxsd;
-import com.google.common.base.CharMatcher;
import com.google.common.collect.Multimap;
import java.io.BufferedWriter;
@@ -153,7 +152,7 @@ public class YAMLfromOXM extends OxmFileProcessor {
StringBuilder definitionsSb = new StringBuilder();
Element elem;
String javaTypeName;
- combinedJavaTypes = new HashMap();
+ combinedJavaTypes = new HashMap<>();
for (int i = 0; i < javaTypeNodes.getLength(); ++i) {
elem = (Element) javaTypeNodes.item(i);
javaTypeName = elem.getAttribute("name");
diff --git a/aai-schema-gen/src/main/java/org/onap/aai/schemagen/swagger/GenerateSwagger.java b/aai-schema-gen/src/main/java/org/onap/aai/schemagen/swagger/GenerateSwagger.java
index 39b1e83..b467e33 100644
--- a/aai-schema-gen/src/main/java/org/onap/aai/schemagen/swagger/GenerateSwagger.java
+++ b/aai-schema-gen/src/main/java/org/onap/aai/schemagen/swagger/GenerateSwagger.java
@@ -27,8 +27,22 @@ import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
-import java.io.*;
-import java.util.*;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
import java.util.stream.Collectors;
import org.onap.aai.setup.SchemaVersions;
diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/SchemaServiceApp.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/SchemaServiceApp.java
index 291e0a6..1cc7a36 100644
--- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/SchemaServiceApp.java
+++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/SchemaServiceApp.java
@@ -20,9 +20,6 @@
package org.onap.aai.schemaservice;
-import java.util.Map;
-import java.util.UUID;
-
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
@@ -31,7 +28,6 @@ import org.onap.aai.exceptions.AAIException;
import org.onap.aai.schemaservice.config.PropertyPasswordConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@@ -41,7 +37,6 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerA
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.env.Environment;
-import org.springframework.web.context.request.RequestContextListener;
@SpringBootApplication
// Component Scan provides a way to look for spring beans
diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/PropertyPasswordConfiguration.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/PropertyPasswordConfiguration.java
index 2292577..bd8ce6e 100644
--- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/PropertyPasswordConfiguration.java
+++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/PropertyPasswordConfiguration.java
@@ -24,6 +24,7 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.nio.charset.Charset;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;
@@ -61,7 +62,7 @@ public class PropertyPasswordConfiguration
try (InputStream passwordStream = new FileInputStream(passwordFile)) {
String keystorePassword = null;
- keystorePassword = IOUtils.toString(passwordStream);
+ keystorePassword = IOUtils.toString(passwordStream, Charset.defaultCharset());
if (keystorePassword != null) {
keystorePassword = keystorePassword.trim();
sslProps.put("server.ssl.key-store-password", keystorePassword);
diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/post/InvalidResponseStatus.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/post/InvalidResponseStatus.java
index 5f80b2b..5a09615 100644
--- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/post/InvalidResponseStatus.java
+++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/post/InvalidResponseStatus.java
@@ -25,12 +25,10 @@ import java.util.ArrayList;
import java.util.List;
import javax.annotation.Priority;
-import javax.print.attribute.standard.Media;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerResponseContext;
import javax.ws.rs.container.ContainerResponseFilter;
import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.UriInfo;
import org.onap.aai.exceptions.AAIException;
import org.onap.aai.logging.ErrorLogHelper;
diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/NodeIngestor.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/NodeIngestor.java
index e7b9167..ad39e49 100644
--- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/NodeIngestor.java
+++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/NodeIngestor.java
@@ -20,6 +20,12 @@
package org.onap.aai.schemaservice.nodeschema;
+import com.google.common.base.CaseFormat;
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Multimap;
+
+import jakarta.xml.bind.JAXBException;
+
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
@@ -58,12 +64,6 @@ import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
-import com.google.common.base.CaseFormat;
-import com.google.common.collect.ArrayListMultimap;
-import com.google.common.collect.Multimap;
-
-import jakarta.xml.bind.JAXBException;
-
/**
* NodeIngestor - ingests A&amp;AI OXM files per given config, serves DynamicJAXBContext per version
*/
diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/web/JerseyConfiguration.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/web/JerseyConfiguration.java
index 8b3a936..ad7e546 100644
--- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/web/JerseyConfiguration.java
+++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/web/JerseyConfiguration.java
@@ -77,7 +77,7 @@ public class JerseyConfiguration extends ResourceConfig {
// Check to ensure that each of the filter has the @Priority annotation and if not throw
// exception
- for (Class filterClass : filters) {
+ for (Class<?> filterClass : filters) {
if (filterClass.getAnnotation(Priority.class) == null) {
throw new RuntimeException("Container filter " + filterClass.getName()
+ " does not have @Priority annotation");
diff --git a/aai-schema-service/src/test/java/org/onap/aai/schemaservice/SchemaServiceTest.java b/aai-schema-service/src/test/java/org/onap/aai/schemaservice/SchemaServiceTest.java
index c874038..c687a58 100644
--- a/aai-schema-service/src/test/java/org/onap/aai/schemaservice/SchemaServiceTest.java
+++ b/aai-schema-service/src/test/java/org/onap/aai/schemaservice/SchemaServiceTest.java
@@ -38,7 +38,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.context.annotation.Import;
-import org.springframework.http.*;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
@@ -56,7 +60,7 @@ public class SchemaServiceTest {
private HttpHeaders headers;
- private HttpEntity httpEntity;
+ private HttpEntity<String> httpEntity;
private String baseUrl;
@@ -89,7 +93,7 @@ public class SchemaServiceTest {
headers.add("X-FromAppId", "JUNIT");
headers.add("X-TransactionId", "JUNIT");
headers.add("Authorization", "Basic " + authorization);
- httpEntity = new HttpEntity(headers);
+ httpEntity = new HttpEntity<String>(headers);
baseUrl = "http://localhost:" + randomPort;
}
@@ -103,9 +107,9 @@ public class SchemaServiceTest {
headers.add("X-FromAppId", "JUNIT");
headers.add("X-TransactionId", "JUNIT");
headers.add("Authorization", "Basic " + authorization);
- httpEntity = new HttpEntity(headers);
+ httpEntity = new HttpEntity<String>(headers);
- ResponseEntity responseEntity;
+ ResponseEntity<String> responseEntity;
responseEntity = restTemplate.exchange(baseUrl + "/aai/schema-service/v1/nodes?version=v20",
HttpMethod.GET, httpEntity, String.class);
@@ -113,7 +117,7 @@ public class SchemaServiceTest {
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
headers.setContentType(MediaType.APPLICATION_JSON);
- httpEntity = new HttpEntity(headers);
+ httpEntity = new HttpEntity<String>(headers);
responseEntity =
restTemplate.exchange(baseUrl + "/aai/schema-service/v1/edgerules?version=v20",
@@ -132,9 +136,9 @@ public class SchemaServiceTest {
headers.add("X-FromAppId", "JUNIT");
headers.add("X-TransactionId", "JUNIT");
headers.add("Authorization", "Basic " + authorization);
- httpEntity = new HttpEntity(headers);
+ httpEntity = new HttpEntity<String>(headers);
- ResponseEntity responseEntity;
+ ResponseEntity<String> responseEntity;
responseEntity =
restTemplate.exchange(baseUrl + "/aai/schema-service/v1/nodes?version=blah",
@@ -144,7 +148,7 @@ public class SchemaServiceTest {
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
headers.setContentType(MediaType.APPLICATION_JSON);
- httpEntity = new HttpEntity(headers);
+ httpEntity = new HttpEntity<String>(headers);
responseEntity =
restTemplate.exchange(baseUrl + "/aai/schema-service/v1/edgerules?version=blah",
@@ -156,7 +160,7 @@ public class SchemaServiceTest {
@Test
public void testVersions() {
- ResponseEntity responseEntity;
+ ResponseEntity<String> responseEntity;
responseEntity = restTemplate.exchange(baseUrl + "/aai/schema-service/v1/versions",
HttpMethod.GET, httpEntity, String.class);
@@ -167,7 +171,7 @@ public class SchemaServiceTest {
@Test
public void testGetStoredQueriesSuccess() {
- ResponseEntity responseEntity;
+ ResponseEntity<String> responseEntity;
responseEntity = restTemplate.exchange(baseUrl + "/aai/schema-service/v1/stored-queries",
HttpMethod.GET, httpEntity, String.class);
diff --git a/aai-schema/src/test/java/org/onap/aai/schema/ValidateOXMTest.java b/aai-schema/src/test/java/org/onap/aai/schema/ValidateOXMTest.java
index 0106dda..c228e77 100644
--- a/aai-schema/src/test/java/org/onap/aai/schema/ValidateOXMTest.java
+++ b/aai-schema/src/test/java/org/onap/aai/schema/ValidateOXMTest.java
@@ -24,7 +24,6 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.*;
-import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
@@ -40,8 +39,6 @@ import javax.xml.xpath.XPathFactory;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.DirectoryFileFilter;
-import org.apache.commons.io.filefilter.FileFileFilter;
-import org.apache.commons.io.filefilter.FileFilterUtils;
import org.apache.commons.io.filefilter.RegexFileFilter;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
diff --git a/pom.xml b/pom.xml
index 603217d..bc8ab56 100644
--- a/pom.xml
+++ b/pom.xml
@@ -84,6 +84,7 @@
<importOrder>
<order>com,java,javax,org</order>
</importOrder>
+ <removeUnusedImports/>
</java>
</configuration>
<!-- https://github.com/diffplug/spotless/tree/master/plugin-maven