aboutsummaryrefslogtreecommitdiffstats
path: root/aai-schema-gen
diff options
context:
space:
mode:
authorLiard Samuel <samuel.liard@orange.com>2021-07-20 15:30:27 +0200
committerSamuel Liard <samuel.liard@gmail.com>2021-07-22 14:47:03 +0200
commitef5474303d17f1d6fedc6d6bfb8fbc99fd19c0d7 (patch)
tree6b3b0c95b1d365538a47012bbac3ec6aada54d60 /aai-schema-gen
parente4156ab1214268e88716d6153cd7216ef918d1eb (diff)
Fix sonar issues + merge
Issue-ID: AAI-3362 Signed-off-by: sliard <samuel.liard@gmail.com> Change-Id: Ibd62021424c7c69467fef8af897709e89ce499a3
Diffstat (limited to 'aai-schema-gen')
-rw-r--r--aai-schema-gen/src/main/java/org/onap/aai/schemagen/GenerateXsd.java150
-rw-r--r--aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/DeleteOperation.java162
-rw-r--r--aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/EdgeDescription.java355
-rw-r--r--aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/GetOperation.java166
-rw-r--r--aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/HTMLfromOXM.java443
-rw-r--r--aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/NodeGetOperation.java249
-rw-r--r--aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/NodesYAMLfromOXM.java287
-rw-r--r--aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/OxmFileProcessor.java135
-rw-r--r--aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/PatchOperation.java209
-rw-r--r--aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/PutOperation.java170
-rw-r--r--aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/PutRelationPathSet.java397
-rw-r--r--aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/XSDElement.java1490
-rw-r--r--aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/XSDJavaType.java80
-rw-r--r--aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/YAMLfromOXM.java338
-rw-r--r--aai-schema-gen/src/main/java/org/onap/aai/schemagen/swagger/GenerateSwagger.java57
15 files changed, 2446 insertions, 2242 deletions
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 227df63..a85ecac 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
@@ -20,6 +20,7 @@
package org.onap.aai.schemagen;
+import java.nio.charset.StandardCharsets;
import org.onap.aai.setup.SchemaVersion;
import org.onap.aai.setup.SchemaVersions;
import org.onap.aai.schemagen.genxsd.HTMLfromOXM;
@@ -58,7 +59,7 @@ public class GenerateXsd {
static Map<String,String> javaTypeDefinitions = createJavaTypeDefinitions();
private static Map<String, String> createJavaTypeDefinitions()
{
- StringBuffer aaiInternal = new StringBuffer();
+ StringBuilder aaiInternal = new StringBuilder();
Map<String,String> javaTypeDefinitions = new HashMap<String, String>();
aaiInternal.append(" aai-internal:\n");
aaiInternal.append(" properties:\n");
@@ -75,25 +76,29 @@ public class GenerateXsd {
public static final int VALUE_INDEXED_PROPS = 2;
public static final int VALUE_CONTAINER = 3;
- private static final String generateTypeXSD = "xsd";
- private static final String generateTypeYAML = "yaml";
+ private static final String GENERATE_TYPE_XSD = "xsd";
+ private static final String GENERATE_TYPE_YAML = "yaml";
- private final static String nodeDir = System.getProperty("nodes.configuration.location");
- private final static String edgeDir = System.getProperty("edges.configuration.location");
- private static final String baseRoot = "aai-schema/";
- private static final String baseAutoGenRoot = "aai-schema/";
+ private final static String NODE_DIR = System.getProperty("nodes.configuration.location");
+ private final static String EDGE_DIR = System.getProperty("edges.configuration.location");
+ private static final String BASE_ROOT = "aai-schema/";
+ private static final String BASE_AUTO_GEN_ROOT = "aai-schema/";
- private static final String root = baseRoot + "src/main/resources";
- private static final String autoGenRoot = baseAutoGenRoot + "src/main/resources";
+ private static final String ROOT = BASE_ROOT + "src/main/resources";
+ private static final String AUTO_GEN_ROOT = BASE_AUTO_GEN_ROOT + "src/main/resources";
- private static final String normalStartDir = "aai-schema-gen";
- private static final String xsd_dir = root + "/" + RELEASE +"/aai_schema";
+ private static final String NORMAL_START_DIR = "aai-schema-gen";
+ private static final String XSD_DIR = ROOT + "/" + RELEASE +"/aai_schema";
- private static final String yaml_dir = (((System.getProperty("user.dir") != null) && (!System.getProperty("user.dir").contains(normalStartDir))) ? autoGenRoot : root) + "/" + RELEASE + "/aai_swagger_yaml";
+ private static final String
+ YAML_DIR = (((System.getProperty("user.dir") != null) && (!System.getProperty("user.dir").contains(
+ NORMAL_START_DIR))) ?
+ AUTO_GEN_ROOT :
+ ROOT) + "/" + RELEASE + "/aai_swagger_yaml";
/* These three strings are for yaml auto-generation from aai-common class*/
- private static int swaggerSupportStartsVersion = 1; // minimum version to support swagger documentation
+ private static final int SWAGGER_SUPPORT_STARTS_VERSION = 1; // minimum version to support swagger documentation
private static boolean validVersion(String versionToGen) {
@@ -103,8 +108,11 @@ public class GenerateXsd {
}
SchemaVersions schemaVersions = SpringContextAware.getBean(SchemaVersions.class);
+ if (schemaVersions == null) {
+ return false;
+ }
for (SchemaVersion v : schemaVersions.getVersions()) {
- if (v.equals(versionToGen)) {
+ if (v.toString().equals(versionToGen)) {
return true;
}
}
@@ -112,40 +120,45 @@ public class GenerateXsd {
return false;
}
- private static boolean versionSupportsSwagger( String version) {
- if (new Integer(version.substring(1)).intValue() >= swaggerSupportStartsVersion ) {
- return true;
- }
- return false;
- }
+ private static boolean versionSupportsSwagger(String version) {
+ return Integer.parseInt(version.substring(1)) >= SWAGGER_SUPPORT_STARTS_VERSION;
+ }
public static String getAPIVersion() {
return apiVersion;
}
public static String getYamlDir() {
- return yaml_dir;
+ return YAML_DIR;
}
public static String getResponsesUrl() {
return responsesUrl;
}
public static void main(String[] args) throws IOException {
- String versionToGen = System.getProperty("gen_version").toLowerCase();
- String fileTypeToGen = System.getProperty("gen_type").toLowerCase();
-
- AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(
+ String versionToGen = System.getProperty("gen_version");
+ if (versionToGen == null) {
+ System.err.println("Version is required, ie v<n> or ALL.");
+ System.exit(1);
+ } else {
+ versionToGen = versionToGen.toLowerCase();
+ }
+
+ String fileTypeToGen = System.getProperty("gen_type");
+ if (fileTypeToGen == null) {
+ fileTypeToGen = GENERATE_TYPE_XSD;
+ } else {
+ fileTypeToGen = fileTypeToGen.toLowerCase();
+ }
+
+ AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(
"org.onap.aai.setup",
"org.onap.aai.schemagen"
);
SchemaVersions schemaVersions = ctx.getBean(SchemaVersions.class);
- if ( fileTypeToGen == null ) {
- fileTypeToGen = generateTypeXSD;
- }
-
- if ( !fileTypeToGen.equals( generateTypeXSD ) && !fileTypeToGen.equals( generateTypeYAML )) {
+ if ( !fileTypeToGen.equals(GENERATE_TYPE_XSD) && !fileTypeToGen.equals(GENERATE_TYPE_YAML)) {
System.err.println("Invalid gen_type passed. " + fileTypeToGen);
System.exit(1);
}
@@ -154,11 +167,7 @@ public class GenerateXsd {
responsesUrl = responsesLabel;
List<SchemaVersion> versionsToGen = new ArrayList<>();
- if ( versionToGen == null ) {
- System.err.println("Version is required, ie v<n> or ALL.");
- System.exit(1);
- }
- else if (!"ALL".equalsIgnoreCase(versionToGen) && !versionToGen.matches("v\\d+") && !validVersion(versionToGen)) {
+ if (!"ALL".equalsIgnoreCase(versionToGen) && !versionToGen.matches("v\\d+") && !validVersion(versionToGen)) {
System.err.println("Invalid version passed. " + versionToGen);
System.exit(1);
}
@@ -171,11 +180,7 @@ public class GenerateXsd {
}
//process file type System property
- fileTypeToGen = (fileTypeToGen == null ? generateTypeXSD : fileTypeToGen.toLowerCase());
- if ( !fileTypeToGen.equals( generateTypeXSD ) && !fileTypeToGen.equals( generateTypeYAML )) {
- System.err.println("Invalid gen_type passed. " + fileTypeToGen);
- System.exit(1);
- } else if ( fileTypeToGen.equals(generateTypeYAML) ) {
+ 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" );
@@ -188,11 +193,12 @@ public class GenerateXsd {
* TODO: Oxm Path is config driveb
*/
String oxmPath;
- if(System.getProperty("user.dir") != null && !System.getProperty("user.dir").contains(normalStartDir)) {
- oxmPath = baseAutoGenRoot + nodeDir;
+ if(System.getProperty("user.dir") != null && !System.getProperty("user.dir").contains(
+ NORMAL_START_DIR)) {
+ oxmPath = BASE_AUTO_GEN_ROOT + NODE_DIR;
}
else {
- oxmPath = baseRoot + nodeDir;
+ oxmPath = BASE_ROOT + NODE_DIR;
}
String outfileName = null;
@@ -205,27 +211,28 @@ public class GenerateXsd {
for (SchemaVersion v : versionsToGen) {
apiVersion = v.toString();
- logger.debug("YAMLdir = "+yaml_dir);
+ 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 = edgeDir + "DbEdgeRules_" + apiVersion + ".json";
+ 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(normalStartDir)) {
- fileName = baseAutoGenRoot + fileName;
+ if(System.getProperty("user.dir") != null && !System.getProperty("user.dir").contains(
+ NORMAL_START_DIR)) {
+ fileName = BASE_AUTO_GEN_ROOT + fileName;
}
else {
- fileName = baseRoot + fileName;
+ fileName = BASE_ROOT + fileName;
}
edgeRuleFile = new File( fileName);
// Document doc = ni.getSchema(translateVersion(v));
- if ( fileTypeToGen.equals(generateTypeXSD) ) {
- outfileName = xsd_dir + "/aai_schema_" + apiVersion + "." + generateTypeXSD;
+ 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);
@@ -236,12 +243,12 @@ public class GenerateXsd {
} catch(Exception e) {
logger.error( "Exception creating output file " + outfileName);
logger.error( e.getMessage());
- e.printStackTrace();
System.exit(-1);
}
} else if ( versionSupportsSwagger(apiVersion )) {
- outfileName = yaml_dir + "/aai_swagger_" + apiVersion + "." + generateTypeYAML;
- nodesfileName = yaml_dir + "/aai_swagger_" + apiVersion + "." + "nodes"+"."+generateTypeYAML;
+ 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);
@@ -252,36 +259,37 @@ public class GenerateXsd {
nodesSwagger.setCombinedJavaTypes(combinedJavaTypes);
nodesContent = nodesSwagger.process();
} catch(Exception e) {
- logger.error( "Exception creating output file " + outfileName);
- e.printStackTrace();
+ logger.error("Exception creating output file " + outfileName, e);
}
} else {
continue;
}
outfile = new File(outfileName);
File parentDir = outfile.getParentFile();
- if(! parentDir.exists())
- parentDir.mkdirs();
+ if(!parentDir.exists()) {
+ parentDir.mkdirs();
+ }
if(nodesfileName != null) {
BufferedWriter nodesBW = null;
nodesfile = new File(nodesfileName);
parentDir = nodesfile.getParentFile();
- if(! parentDir.exists())
- parentDir.mkdirs();
+ if(!parentDir.exists()){
+ parentDir.mkdirs();
+ }
try {
- nodesfile.createNewFile();
+ if(!nodesfile.createNewFile()) {
+ logger.error( "File {} already exist", nodesfileName);
+ }
} catch (IOException e) {
- logger.error( "Exception creating output file " + nodesfileName);
- e.printStackTrace();
+ logger.error( "Exception creating output file " + nodesfileName, e);
}
try {
- Charset charset = Charset.forName("UTF-8");
+ 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.printStackTrace();
+ logger.error( "Exception writing output file " + outfileName, e);
} finally {
if ( nodesBW != null ) {
nodesBW.close();
@@ -290,20 +298,20 @@ public class GenerateXsd {
}
try {
- outfile.createNewFile();
+ if(!outfile.createNewFile()) {
+ logger.error( "File {} already exist", outfileName);
+ }
} catch (IOException e) {
- logger.error( "Exception creating output file " + outfileName);
- e.printStackTrace();
+ logger.error( "Exception creating output file " + outfileName, e);
}
BufferedWriter bw = null;
try {
- Charset charset = Charset.forName("UTF-8");
+ 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.printStackTrace();
+ logger.error( "Exception writing output file " + outfileName, e);
} finally {
if ( bw != null ) {
bw.close();
diff --git a/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/DeleteOperation.java b/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/DeleteOperation.java
index e1d993f..c59e8f0 100644
--- a/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/DeleteOperation.java
+++ b/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/DeleteOperation.java
@@ -7,9 +7,9 @@
* 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
- *
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
* 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.
@@ -17,90 +17,96 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-package org.onap.aai.schemagen.genxsd;
-import org.apache.commons.lang3.StringUtils;
-import org.onap.aai.schemagen.GenerateXsd;
+package org.onap.aai.schemagen.genxsd;
import java.util.HashMap;
import java.util.StringTokenizer;
+import org.apache.commons.lang3.StringUtils;
+import org.onap.aai.schemagen.GenerateXsd;
public class DeleteOperation {
- private String useOpId;
- private String xmlRootElementName;
- private String tag;
- private String path;
- private String pathParams;
+ private String useOpId;
+ private String xmlRootElementName;
+ private String tag;
+ private String path;
+ private String pathParams;
+
+ public static HashMap<String, String> deletePaths = new HashMap<String, String>();
+
+ public DeleteOperation(String useOpId, String xmlRootElementName, String tag, String path,
+ String pathParams) {
+ super();
+ this.useOpId = useOpId;
+ this.xmlRootElementName = xmlRootElementName;
+ this.tag = tag;
+ this.path = path;
+ this.pathParams = pathParams;
+ }
+
+ @Override
+ public String toString() {
+ StringTokenizer st;
+ st = new StringTokenizer(path, "/");
+ //a valid tag is necessary
+ if (StringUtils.isEmpty(tag)) {
+ return "";
+ }
+ if (path.contains("/relationship/")) { // filter paths with relationship-list
+ return "";
+ }
+ if (path.endsWith("/relationship-list")) {
+ return "";
+ }
+ if (path.startsWith("/search")) {
+ return "";
+ }
+ //All Delete operation paths end with "relationship"
+ //or there is a parameter at the end of the path
+ //and there is a parameter in the path
- public static HashMap<String, String> deletePaths = new HashMap<String, String>();
- public DeleteOperation(String useOpId, String xmlRootElementName, String tag, String path, String pathParams) {
- super();
- this.useOpId = useOpId;
- this.xmlRootElementName = xmlRootElementName;
- this.tag = tag;
- this.path = path;
- this.pathParams = pathParams;
- }
- @Override
- public String toString() {
- StringTokenizer st;
- st = new StringTokenizer(path, "/");
- //a valid tag is necessary
- if ( StringUtils.isEmpty(tag) ) {
- return "";
- }
- if ( path.contains("/relationship/") ) { // filter paths with relationship-list
- return "";
- }
- if ( path.endsWith("/relationship-list")) {
- return "";
- }
- if ( path.startsWith("/search")) {
- return "";
- }
- //All Delete operation paths end with "relationship"
- //or there is a parameter at the end of the path
- //and there is a parameter in the path
+ if (!path.endsWith("/relationship") && !path.endsWith("}")) {
+ return "";
+ }
+ StringBuilder pathSb = new StringBuilder();
+ pathSb.append(" delete:\n");
+ pathSb.append(" tags:\n");
+ pathSb.append(" - ").append(tag).append("\n");
+ pathSb.append(" summary: delete an existing ").append(xmlRootElementName)
+ .append("\n");
- if ( !path.endsWith("/relationship") && !path.endsWith("}") ) {
- return "";
- }
- StringBuffer pathSb = new StringBuffer();
- pathSb.append(" delete:\n");
- pathSb.append(" tags:\n");
- pathSb.append(" - " + tag + "\n");
- pathSb.append(" summary: delete an existing " + xmlRootElementName + "\n");
+ pathSb.append(" description: delete an existing ").append(xmlRootElementName)
+ .append("\n");
- pathSb.append(" description: delete an existing " + xmlRootElementName + "\n");
+ pathSb.append(" operationId: delete").append(useOpId).append("\n");
+ pathSb.append(" consumes:\n");
+ pathSb.append(" - application/json\n");
+ pathSb.append(" - application/xml\n");
+ pathSb.append(" produces:\n");
+ pathSb.append(" - application/json\n");
+ pathSb.append(" - application/xml\n");
+ pathSb.append(" responses:\n");
+ pathSb.append(" \"default\":\n");
+ pathSb.append(" ").append(GenerateXsd.getResponsesUrl());
+ pathSb.append(" parameters:\n");
- pathSb.append(" operationId: delete" + useOpId + "\n");
- pathSb.append(" consumes:\n");
- pathSb.append(" - application/json\n");
- pathSb.append(" - application/xml\n");
- pathSb.append(" produces:\n");
- pathSb.append(" - application/json\n");
- pathSb.append(" - application/xml\n");
- pathSb.append(" responses:\n");
- pathSb.append(" \"default\":\n");
- pathSb.append(" " + GenerateXsd.getResponsesUrl());
- pathSb.append(" parameters:\n");
+ pathSb.append(pathParams); // for nesting
+ if (!path.endsWith("/relationship")) {
+ pathSb.append(" - name: resource-version\n");
- pathSb.append(pathParams); // for nesting
- if ( !path.endsWith("/relationship") ) {
- pathSb.append(" - name: resource-version\n");
+ pathSb.append(" in: query\n");
+ pathSb.append(" description: resource-version for concurrency\n");
+ pathSb.append(" required: true\n");
+ pathSb.append(" type: string\n");
+ }
+ this.objectPathMapEntry();
+ return pathSb.toString();
+ }
- pathSb.append(" in: query\n");
- pathSb.append(" description: resource-version for concurrency\n");
- pathSb.append(" required: true\n");
- pathSb.append(" type: string\n");
- }
- this.objectPathMapEntry();
- return pathSb.toString();
- }
- public String objectPathMapEntry() {
- if (! path.endsWith("/relationship") ) {
- deletePaths.put(path, xmlRootElementName);
- }
- return (xmlRootElementName+":"+path);
- }
- }
+ public String objectPathMapEntry() {
+ if (!path.endsWith("/relationship")) {
+ deletePaths.put(path, xmlRootElementName);
+ }
+ return (xmlRootElementName + ":" + path);
+ }
+}
diff --git a/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/EdgeDescription.java b/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/EdgeDescription.java
index f472896..5bdb87e 100644
--- a/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/EdgeDescription.java
+++ b/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/EdgeDescription.java
@@ -7,9 +7,9 @@
* 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
- *
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
* 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.
@@ -17,6 +17,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.schemagen.genxsd;
import org.apache.commons.lang3.StringUtils;
@@ -27,170 +28,186 @@ import org.slf4j.LoggerFactory;
public class EdgeDescription {
- private static final Logger logger = LoggerFactory.getLogger("EdgeDescription.class");
- EdgeRule ed;
- public static enum LineageType {
- PARENT, CHILD, UNRELATED;
- }
- private String ruleKey;
-// private String to;
-// private String from;
- private LineageType lineageType = LineageType.UNRELATED;
-// private String direction;
-// private String multiplicity;
-// private String preventDelete;
-// private String deleteOtherV;
-// private String label;
-// private String description;
-
- public EdgeDescription(EdgeRule ed) {
- super();
- if ( ed.getDirection().toString().equals(ed.getContains()) &&
- AAIDirection.getValue("OUT").equals(AAIDirection.getValue(ed.getDirection()))) {
- this.lineageType= LineageType.PARENT;
- } else if ( AAIDirection.getValue("IN").equals(AAIDirection.getValue(ed.getContains())) &&
- ed.getDirection().toString().equals(ed.getContains())) {
- this.lineageType= LineageType.CHILD;
- } else if ( AAIDirection.getValue("OUT").equals(AAIDirection.getValue(ed.getContains())) &&
- AAIDirection.getValue("IN").equals(AAIDirection.getValue(ed.getDirection()))) {
- this.lineageType= LineageType.PARENT;
- } else if ( AAIDirection.getValue("IN").equals(AAIDirection.getValue(ed.getContains())) &&
- AAIDirection.getValue("OUT").equals(AAIDirection.getValue(ed.getDirection()))) {
- this.lineageType= LineageType.PARENT;
- } else {
- this.lineageType= LineageType.UNRELATED;
- }
- this.ruleKey = ed.getFrom()+"|"+ed.getTo();
- this.ed=ed;
- }
- /**
- * @return the deleteOtherV
- */
- public String getDeleteOtherV() {
- return ed.getDeleteOtherV();
- }
- /**
- * @return the preventDelete
- */
- public String getPreventDelete() {
- return ed.getPreventDelete();
- }
- public String getAlsoDeleteFootnote(String targetNode) {
- String returnVal = "";
- if(ed.getDeleteOtherV().equals("IN") && ed.getTo().equals(targetNode) ) {
- logger.debug("Edge: "+this.ruleKey);
- logger.debug("IF this "+targetNode+" node is deleted, this FROM node is DELETED also");
- returnVal = "(1)";
- }
- if(ed.getDeleteOtherV().equals("OUT") && ed.getFrom().equals(targetNode) ) {
- logger.debug("Edge: "+this.ruleKey);
- logger.debug("IF this "+targetNode+" is deleted, this TO node is DELETED also");
- returnVal = "(2)";
- }
- if(ed.getDeleteOtherV().equals("OUT") && ed.getTo().equals(targetNode) ) {
- logger.debug("Edge: "+this.ruleKey);
- logger.debug("IF this FROM node is deleted, this "+targetNode+" is DELETED also");
- returnVal = "(3)";
- }
- if(ed.getDeleteOtherV().equals("IN") && ed.getFrom().equals(targetNode) ) {
- logger.debug("Edge: "+this.ruleKey);
- logger.debug("IF this TO node is deleted, this "+targetNode+" node is DELETED also");
- returnVal = "(4)";
- }
- return returnVal;
- }
- /**
- * @return the to
- */
- public String getTo() {
- return ed.getTo();
- }
- /**
- * @return the from
- */
- public String getFrom() {
- return ed.getFrom();
- }
- public String getRuleKey() {
- return ruleKey;
- }
- public String getMultiplicity() {
- return ed.getMultiplicityRule().toString();
- }
- public AAIDirection getDirection() {
- return AAIDirection.getValue(ed.getDirection());
- }
- public String getDescription() {
- return ed.getDescription();
- }
- public String getRelationshipDescription(String fromTo, String otherNodeName) {
-
- String result = "";
-
- if ("FROM".equals(fromTo)) {
- if (AAIDirection.getValue("OUT").equals(AAIDirection.getValue(ed.getDirection()))) {
- if (LineageType.PARENT == lineageType) {
- result = " (PARENT of "+otherNodeName;
- result = String.join(" ", result+",", ed.getFrom(), this.getShortLabel(), ed.getTo()+",", this.getMultiplicity());
- }
- }
- else {
- if (LineageType.CHILD == lineageType) {
- result = " (CHILD of "+otherNodeName;
- result = String.join(" ", result+",", ed.getFrom(), this.getShortLabel(), ed.getTo()+",", this.getMultiplicity());
- }
- else if (LineageType.PARENT == lineageType) {
- result = " (PARENT of "+otherNodeName;
- result = String.join(" ", result+",", ed.getFrom(), this.getShortLabel(), ed.getTo()+",", this.getMultiplicity());
- }
- }
- if (result.length() == 0) result = String.join(" ", "(", ed.getFrom(), this.getShortLabel(), ed.getTo()+",", this.getMultiplicity());
- } else {
- //if ("TO".equals(fromTo)
- if (AAIDirection.getValue("OUT").equals(AAIDirection.getValue(ed.getDirection()))) {
- if (LineageType.PARENT == lineageType) {
- result = " (PARENT of "+otherNodeName;
- result = String.join(" ", result+",", ed.getFrom(), this.getShortLabel(), ed.getTo()+",", this.getMultiplicity());
- }
- } else {
- if (LineageType.PARENT == lineageType) {
- result = " (PARENT of "+otherNodeName;
- result = String.join(" ", result+",", ed.getFrom(), this.getShortLabel(), ed.getTo()+",", this.getMultiplicity());
- }
- }
- if (result.length() == 0) result = String.join(" ", "(", ed.getFrom(), this.getShortLabel(), ed.getTo()+",", this.getMultiplicity());
- }
-
- if (result.length() > 0) result = result + ")";
-
- if (ed.getDescription() != null && ed.getDescription().length() > 0) result = result + "\n "+ ed.getDescription(); // 6 spaces is important for yaml
-
- return result;
- }
-
- /**
- * @return the hasDelTarget
- */
-
- public boolean hasDelTarget() {
- return StringUtils.isNotEmpty(ed.getDeleteOtherV()) && (! "NONE".equalsIgnoreCase(ed.getDeleteOtherV()));
- }
-
- /**
- * @return the type
- */
- public LineageType getType() {
-
- return lineageType;
- }
- /**
- * @return the label
- */
- public String getLabel() {
- return ed.getLabel();
- }
- public String getShortLabel() {
- String[] pieces = this.getLabel().split("[.]");
- return pieces[pieces.length-1];
- }
+ private static final Logger logger = LoggerFactory.getLogger(EdgeDescription.class);
+ EdgeRule ed;
+
+ public enum LineageType {
+ PARENT, CHILD, UNRELATED
+ }
+
+ private final String ruleKey;
+ private LineageType lineageType = LineageType.UNRELATED;
+
+ public EdgeDescription(EdgeRule ed) {
+ super();
+ if (ed.getDirection().toString().equals(ed.getContains()) &&
+ AAIDirection.getValue("OUT").equals(AAIDirection.getValue(ed.getDirection()))) {
+ this.lineageType = LineageType.PARENT;
+ } else if (AAIDirection.getValue("IN").equals(AAIDirection.getValue(ed.getContains())) &&
+ ed.getDirection().toString().equals(ed.getContains())) {
+ this.lineageType = LineageType.CHILD;
+ } else if (AAIDirection.getValue("OUT").equals(AAIDirection.getValue(ed.getContains())) &&
+ AAIDirection.getValue("IN").equals(AAIDirection.getValue(ed.getDirection()))) {
+ this.lineageType = LineageType.PARENT;
+ } else if (AAIDirection.getValue("IN").equals(AAIDirection.getValue(ed.getContains())) &&
+ AAIDirection.getValue("OUT").equals(AAIDirection.getValue(ed.getDirection()))) {
+ this.lineageType = LineageType.PARENT;
+ } else {
+ this.lineageType = LineageType.UNRELATED;
+ }
+ this.ruleKey = ed.getFrom() + "|" + ed.getTo();
+ this.ed = ed;
+ }
+
+ /**
+ * @return the deleteOtherV
+ */
+ public String getDeleteOtherV() {
+ return ed.getDeleteOtherV();
+ }
+
+ /**
+ * @return the preventDelete
+ */
+ public String getPreventDelete() {
+ return ed.getPreventDelete();
+ }
+
+ public String getAlsoDeleteFootnote(String targetNode) {
+ String returnVal = "";
+ if (ed.getDeleteOtherV().equals("IN") && ed.getTo().equals(targetNode)) {
+ logger.debug("Edge: " + this.ruleKey);
+ logger.debug(
+ "IF this " + targetNode + " node is deleted, this FROM node is DELETED also");
+ returnVal = "(1)";
+ }
+ if (ed.getDeleteOtherV().equals("OUT") && ed.getFrom().equals(targetNode)) {
+ logger.debug("Edge: " + this.ruleKey);
+ logger.debug("IF this " + targetNode + " is deleted, this TO node is DELETED also");
+ returnVal = "(2)";
+ }
+ if (ed.getDeleteOtherV().equals("OUT") && ed.getTo().equals(targetNode)) {
+ logger.debug("Edge: " + this.ruleKey);
+ logger.debug("IF this FROM node is deleted, this " + targetNode + " is DELETED also");
+ returnVal = "(3)";
+ }
+ if (ed.getDeleteOtherV().equals("IN") && ed.getFrom().equals(targetNode)) {
+ logger.debug("Edge: " + this.ruleKey);
+ logger
+ .debug("IF this TO node is deleted, this " + targetNode + " node is DELETED also");
+ returnVal = "(4)";
+ }
+ return returnVal;
+ }
+
+ /**
+ * @return the to
+ */
+ public String getTo() {
+ return ed.getTo();
+ }
+
+ /**
+ * @return the from
+ */
+ public String getFrom() {
+ return ed.getFrom();
+ }
+
+ public String getRuleKey() {
+ return ruleKey;
+ }
+
+ public String getMultiplicity() {
+ return ed.getMultiplicityRule().toString();
+ }
+
+ public AAIDirection getDirection() {
+ return AAIDirection.getValue(ed.getDirection());
+ }
+
+ public String getDescription() {
+ return ed.getDescription();
+ }
+
+ public String getRelationshipDescription(String fromTo, String otherNodeName) {
+
+ String result = "";
+
+ if ("FROM".equals(fromTo)) {
+ if (AAIDirection.getValue("OUT").equals(AAIDirection.getValue(ed.getDirection()))) {
+ if (LineageType.PARENT == lineageType) {
+ result = " (PARENT of " + otherNodeName;
+ result = String.join(" ", result + ",", ed.getFrom(), this.getShortLabel(),
+ ed.getTo() + ",", this.getMultiplicity());
+ }
+ } else {
+ if (LineageType.CHILD == lineageType) {
+ result = " (CHILD of " + otherNodeName;
+ result = String.join(" ", result + ",", ed.getFrom(), this.getShortLabel(),
+ ed.getTo() + ",", this.getMultiplicity());
+ } else if (LineageType.PARENT == lineageType) {
+ result = " (PARENT of " + otherNodeName;
+ result = String.join(" ", result + ",", ed.getFrom(), this.getShortLabel(),
+ ed.getTo() + ",", this.getMultiplicity());
+ }
+ }
+ if (result.length() == 0) {
+ result = String
+ .join(" ", "(", ed.getFrom(), this.getShortLabel(), ed.getTo() + ",",
+ this.getMultiplicity());
+ }
+ } else {
+ if (LineageType.PARENT == lineageType) {
+ result = " (PARENT of " + otherNodeName;
+ result = String
+ .join(" ", result + ",", ed.getFrom(), this.getShortLabel(), ed.getTo() + ",",
+ this.getMultiplicity());
+ }
+ if (result.length() == 0) {
+ result = String
+ .join(" ", "(", ed.getFrom(), this.getShortLabel(), ed.getTo() + ",",
+ this.getMultiplicity());
+ }
+ }
+
+ if (result.length() > 0) {
+ result = result + ")";
+ }
+
+ if (ed.getDescription() != null && ed.getDescription().length() > 0) {
+ result = result + "\n " + ed.getDescription(); // 6 spaces is important for yaml
+ }
+
+ return result;
+ }
+
+ /**
+ * @return the hasDelTarget
+ */
+
+ public boolean hasDelTarget() {
+ return StringUtils.isNotEmpty(ed.getDeleteOtherV()) &&
+ (!"NONE".equalsIgnoreCase(ed.getDeleteOtherV()));
+ }
+
+ /**
+ * @return the type
+ */
+ public LineageType getType() {
+
+ return lineageType;
+ }
+
+ /**
+ * @return the label
+ */
+ public String getLabel() {
+ return ed.getLabel();
+ }
+
+ public String getShortLabel() {
+ String[] pieces = this.getLabel().split("[.]");
+ return pieces[pieces.length - 1];
+ }
}
diff --git a/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/GetOperation.java b/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/GetOperation.java
index b942e1b..a22dfd5 100644
--- a/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/GetOperation.java
+++ b/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/GetOperation.java
@@ -7,9 +7,9 @@
* 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
- *
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
* 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.
@@ -17,105 +17,111 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-package org.onap.aai.schemagen.genxsd;
-import org.apache.commons.lang3.StringUtils;
-import org.onap.aai.schemagen.GenerateXsd;
+package org.onap.aai.schemagen.genxsd;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.Vector;
+import org.apache.commons.lang3.StringUtils;
+import org.onap.aai.schemagen.GenerateXsd;
public class GetOperation {
- static Map<String, Vector<String>> containers = new HashMap<String, Vector<String>>();
- public static void addContainerProps(String container, Vector<String> containerProps) {
- containers.put(container, containerProps);;
- }
- private String useOpId;
- private String xmlRootElementName;
- private String tag;
- private String path;
- private String pathParams;
- private String queryParams;
+ static Map<String, Vector<String>> containers = new HashMap<String, Vector<String>>();
- public GetOperation(String useOpId, String xmlRootElementName, String tag, String path, String pathParams) {
- super();
- this.useOpId = useOpId;
- this.xmlRootElementName = xmlRootElementName;
- this.tag = tag;
- this.path = path;
- this.pathParams = pathParams;
+ public static void addContainerProps(String container, Vector<String> containerProps) {
+ containers.put(container, containerProps);
+ ;
+ }
+
+ private String useOpId;
+ private String xmlRootElementName;
+ private String tag;
+ private String path;
+ private String pathParams;
+ private String queryParams;
+
+ public GetOperation(String useOpId, String xmlRootElementName, String tag, String path,
+ String pathParams) {
+ super();
+ this.useOpId = useOpId;
+ this.xmlRootElementName = xmlRootElementName;
+ this.tag = tag;
+ this.path = path;
+ this.pathParams = pathParams;
// StringBuilder p = new StringBuilder();
- if(containers.get(xmlRootElementName) == null) {
- this.queryParams = "";
- } else {
- this.queryParams= String.join("", containers.get(xmlRootElementName));
+ if (containers.get(xmlRootElementName) == null) {
+ this.queryParams = "";
+ } else {
+ this.queryParams = String.join("", containers.get(xmlRootElementName));
// for(String param : containers.get(xmlRootElementName)) {
// p.append(param);
// }
// this.queryParams = p.toString();
- }
- }
- @Override
- public String toString() {
- StringTokenizer st;
- st = new StringTokenizer(path, "/");
- //Path has to be longer than one element
+ }
+ }
+
+ @Override
+ public String toString() {
+ StringTokenizer st;
+ st = new StringTokenizer(path, "/");
+ //Path has to be longer than one element
/*
if ( st.countTokens() <= 1) {
return "";
}
*/
- //a valid tag is necessary
- if ( StringUtils.isEmpty(tag) ) {
- return "";
- }
- if ( path.endsWith("/relationship") ) {
- return "";
- }
- if ( path.contains("/relationship/") ) { // filter paths with relationship-list
- return "";
- }
- if ( path.endsWith("/relationship-list")) {
- return "";
- }
- if ( path.startsWith("/search")) {
- return "";
- }
- StringBuffer pathSb = new StringBuffer();
- pathSb.append(" " + path + ":\n" );
- pathSb.append(" get:\n");
- pathSb.append(" tags:\n");
- pathSb.append(" - " + tag + "\n");
- pathSb.append(" summary: returns " + xmlRootElementName + "\n");
+ //a valid tag is necessary
+ if (StringUtils.isEmpty(tag)) {
+ return "";
+ }
+ if (path.endsWith("/relationship")) {
+ return "";
+ }
+ if (path.contains("/relationship/")) { // filter paths with relationship-list
+ return "";
+ }
+ if (path.endsWith("/relationship-list")) {
+ return "";
+ }
+ if (path.startsWith("/search")) {
+ return "";
+ }
+ StringBuilder pathSb = new StringBuilder();
+ pathSb.append(" ").append(path).append(":\n");
+ pathSb.append(" get:\n");
+ pathSb.append(" tags:\n");
+ pathSb.append(" - ").append(tag).append("\n");
+ pathSb.append(" summary: returns ").append(xmlRootElementName).append("\n");
- pathSb.append(" description: returns " + xmlRootElementName + "\n");
- pathSb.append(" operationId: get" + useOpId + "\n");
- pathSb.append(" produces:\n");
- pathSb.append(" - application/json\n");
- pathSb.append(" - application/xml\n");
+ pathSb.append(" description: returns ").append(xmlRootElementName).append("\n");
+ pathSb.append(" operationId: get").append(useOpId).append("\n");
+ pathSb.append(" produces:\n");
+ pathSb.append(" - application/json\n");
+ pathSb.append(" - application/xml\n");
- pathSb.append(" responses:\n");
- pathSb.append(" \"200\":\n");
- pathSb.append(" description: successful operation\n");
- pathSb.append(" schema:\n");
- pathSb.append(" $ref: \"#/definitions/" + xmlRootElementName + "\"\n");
- pathSb.append(" \"default\":\n");
- pathSb.append(" " + GenerateXsd.getResponsesUrl());
- if ( StringUtils.isNotEmpty(pathParams) || StringUtils.isNotEmpty(queryParams)) {
- pathSb.append(" parameters:\n");
- }
- if ( StringUtils.isNotEmpty(pathParams)) {
- pathSb.append(pathParams);
- }
+ pathSb.append(" responses:\n");
+ pathSb.append(" \"200\":\n");
+ pathSb.append(" description: successful operation\n");
+ pathSb.append(" schema:\n");
+ pathSb.append(" $ref: \"#/definitions/").append(xmlRootElementName)
+ .append("\"\n");
+ pathSb.append(" \"default\":\n");
+ pathSb.append(" ").append(GenerateXsd.getResponsesUrl());
+ if (StringUtils.isNotEmpty(pathParams) || StringUtils.isNotEmpty(queryParams)) {
+ pathSb.append(" parameters:\n");
+ }
+ if (StringUtils.isNotEmpty(pathParams)) {
+ pathSb.append(pathParams);
+ }
// if ( StringUtils.isNotEmpty(pathParams) && StringUtils.isNotEmpty(queryParams)) {
// pathSb.append("\n");
// }
- if ( StringUtils.isNotEmpty(queryParams)) {
- pathSb.append(queryParams);
- }
- return pathSb.toString();
- }
- }
+ if (StringUtils.isNotEmpty(queryParams)) {
+ pathSb.append(queryParams);
+ }
+ return pathSb.toString();
+ }
+}
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 35f0665..ce45236 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
@@ -7,9 +7,9 @@
* 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
- *
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
* 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.
@@ -17,8 +17,16 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.schemagen.genxsd;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import javax.xml.parsers.ParserConfigurationException;
import org.onap.aai.edges.EdgeIngestor;
import org.onap.aai.edges.exceptions.EdgeRuleNotFoundException;
import org.onap.aai.nodes.NodeIngestor;
@@ -32,245 +40,242 @@ import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
-import javax.xml.parsers.ParserConfigurationException;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-
public class HTMLfromOXM extends OxmFileProcessor {
- private static final Logger logger = LoggerFactory.getLogger("HTMLfromOXM.class");
+ private static final Logger logger = LoggerFactory.getLogger("HTMLfromOXM.class");
+
+ private String maxOccurs;
+
+ public HTMLfromOXM(String maxOccurs, SchemaVersions schemaVersions, NodeIngestor ni,
+ EdgeIngestor ei) {
+ super(schemaVersions, ni, ei);
+ this.maxOccurs = maxOccurs;
+ }
+
+ public void setOxmVersion(File oxmFile, SchemaVersion v) {
+ super.setOxmVersion(oxmFile, v);
+ this.v = v;
+ }
- private String maxOccurs;
+ public void setXmlVersion(String xml, SchemaVersion v) {
+ super.setXmlVersion(xml, v);
+ this.v = v;
+ }
- public HTMLfromOXM(String maxOccurs, SchemaVersions schemaVersions, NodeIngestor ni, EdgeIngestor ei ){
- super(schemaVersions, ni,ei);
- this.maxOccurs = maxOccurs;
- }
- public void setOxmVersion(File oxmFile, SchemaVersion v) {
- super.setOxmVersion(oxmFile, v);
- this.v = v;
- }
- public void setXmlVersion(String xml, SchemaVersion v) {
- super.setXmlVersion(xml, v);
- this.v = v;
- }
- public void setVersion(SchemaVersion v) {
- super.setVersion(v);
- this.v = v;
- }
+ public void setVersion(SchemaVersion v) {
+ super.setVersion(v);
+ this.v = v;
+ }
- @Override
- public String getDocumentHeader() {
- StringBuffer sb = new StringBuffer();
- logger.trace("processing starts");
- sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + LINE_SEPARATOR);
- String namespace = "org.onap";
- if (v.compareTo(getSchemaVersions().getNamespaceChangeVersion()) < 0 ) {
- namespace = "org.openecomp";
- }
- if ( versionUsesAnnotations(v.toString()) ) {
- sb.append("<xs:schema elementFormDefault=\"qualified\" version=\"1.0\" targetNamespace=\"http://" + namespace + ".aai.inventory/"
- + v.toString() + "\" xmlns:tns=\"http://" + namespace + ".aai.inventory/" + v.toString() + "\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\""
- + LINE_SEPARATOR
- + "xmlns:jaxb=\"http://java.sun.com/xml/ns/jaxb\"" + LINE_SEPARATOR +
- " jaxb:version=\"2.1\"" + LINE_SEPARATOR +
- " xmlns:annox=\"http://annox.dev.java.net\"" + LINE_SEPARATOR +
- " jaxb:extensionBindingPrefixes=\"annox\">" + DOUBLE_LINE_SEPARATOR);
- } else {
- sb.append("<xs:schema elementFormDefault=\"qualified\" version=\"1.0\" targetNamespace=\"http://" + namespace + ".aai.inventory/"
- + v.toString() + "\" xmlns:tns=\"http://" + namespace + ".aai.inventory/" + v.toString() + "\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">" + DOUBLE_LINE_SEPARATOR);
- }
- return sb.toString();
- }
+ @Override
+ public String getDocumentHeader() {
+ StringBuilder sb = new StringBuilder();
+ logger.trace("processing starts");
+ sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>")
+ .append(LINE_SEPARATOR);
+ String namespace = "org.onap";
+ if (v.compareTo(getSchemaVersions().getNamespaceChangeVersion()) < 0) {
+ namespace = "org.openecomp";
+ }
+ sb.append(
+ "<xs:schema elementFormDefault=\"qualified\" version=\"1.0\" targetNamespace=\"http://")
+ .append(namespace).append(".aai.inventory/").append(v.toString())
+ .append("\" xmlns:tns=\"http://").append(namespace).append(".aai.inventory/")
+ .append(v.toString()).append("\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"")
+ .append(LINE_SEPARATOR).append("xmlns:jaxb=\"http://java.sun.com/xml/ns/jaxb\"")
+ .append(LINE_SEPARATOR).append(" jaxb:version=\"2.1\"").append(LINE_SEPARATOR)
+ .append(" xmlns:annox=\"http://annox.dev.java.net\"").append(LINE_SEPARATOR)
+ .append(" jaxb:extensionBindingPrefixes=\"annox\">")
+ .append(DOUBLE_LINE_SEPARATOR);
+ return sb.toString();
+ }
- @Override
- public String process() throws ParserConfigurationException, SAXException, IOException, FileNotFoundException, EdgeRuleNotFoundException {
- StringBuilder sb = new StringBuilder();
+ @Override
+ public String process()
+ throws ParserConfigurationException, SAXException, IOException, FileNotFoundException,
+ EdgeRuleNotFoundException {
+ StringBuilder sb = new StringBuilder();
- try {
- init();
- } catch(Exception e) {
- logger.error( "Error initializing " + this.getClass());
- throw e;
- }
- sb.append(getDocumentHeader());
- StringBuilder sbInventory = new StringBuilder();
- Element elem;
- String javaTypeName;
- combinedJavaTypes = new HashMap();
- for ( int i = 0; i < javaTypeNodes.getLength(); ++ i ) {
- elem = (Element)javaTypeNodes.item(i);
- javaTypeName = elem.getAttribute("name");
- if ( !"Inventory".equals(javaTypeName ) ) {
- if ( generatedJavaType.containsKey(javaTypeName) ) {
- continue;
- }
- // will combine all matching java-types
- elem = getJavaTypeElement(javaTypeName,false );
- }
- XSDElement javaTypeElement = new XSDElement(elem, maxOccurs);
- //javaTypeName = javaTypeElement.name();
- if ( javaTypeName == null ) {
- String msg = "Invalid OXM file: <java-type> has no name attribute in " + oxmFile;
- logger.error(msg);
- throw new SAXException(msg);
- }
- if ("Nodes".equals(javaTypeName)) {
- logger.debug("skipping Nodes entry (temporary feature)");
- continue;
- }
- logger.debug(getXmlRootElementName(javaTypeName)+" vs "+ javaTypeName+":"+generatedJavaType.containsKey(getXmlRootElementName(javaTypeName)));
+ try {
+ init();
+ } catch (Exception e) {
+ logger.error("Error initializing " + this.getClass());
+ throw e;
+ }
+ sb.append(getDocumentHeader());
+ StringBuilder sbInventory = new StringBuilder();
+ Element elem;
+ String javaTypeName;
+ combinedJavaTypes = new HashMap();
+ for (int i = 0; i < javaTypeNodes.getLength(); ++i) {
+ elem = (Element) javaTypeNodes.item(i);
+ javaTypeName = elem.getAttribute("name");
+ if (!"Inventory".equals(javaTypeName)) {
+ if (generatedJavaType.containsKey(javaTypeName)) {
+ continue;
+ }
+ // will combine all matching java-types
+ elem = getJavaTypeElement(javaTypeName, false);
+ }
+ XSDElement javaTypeElement = new XSDElement(elem, maxOccurs);
+ //javaTypeName = javaTypeElement.name();
+ if (javaTypeName == null) {
+ String msg = "Invalid OXM file: <java-type> has no name attribute in " + oxmFile;
+ logger.error(msg);
+ throw new SAXException(msg);
+ }
+ if ("Nodes".equals(javaTypeName)) {
+ logger.debug("skipping Nodes entry (temporary feature)");
+ continue;
+ }
+ logger.debug(getXmlRootElementName(javaTypeName) + " vs " + javaTypeName + ":" +
+ generatedJavaType.containsKey(getXmlRootElementName(javaTypeName)));
- if ( !"Inventory".equals(javaTypeName)) {
- generatedJavaType.put(javaTypeName, null);
- }
- sb.append(processJavaTypeElement( javaTypeName, javaTypeElement, sbInventory ));
- }
- sb.append(sbInventory);
- sb.append(" </xs:sequence>" + LINE_SEPARATOR);
- sb.append(" </xs:complexType>" + LINE_SEPARATOR);
- sb.append(" </xs:element>" + LINE_SEPARATOR);
- sb.append("</xs:schema>" + LINE_SEPARATOR);
- return sb.toString();
- }
+ if (!"Inventory".equals(javaTypeName)) {
+ generatedJavaType.put(javaTypeName, null);
+ }
+ sb.append(processJavaTypeElement(javaTypeName, javaTypeElement, sbInventory));
+ }
+ sb.append(sbInventory);
+ sb.append(" </xs:sequence>" + LINE_SEPARATOR);
+ sb.append(" </xs:complexType>" + LINE_SEPARATOR);
+ sb.append(" </xs:element>" + LINE_SEPARATOR);
+ sb.append("</xs:schema>" + LINE_SEPARATOR);
+ return sb.toString();
+ }
- protected boolean isValidName( String name ) {
- if ( name == null || name.length() == 0 ) {
- return false;
- }
- String pattern = "^[a-z0-9-]*$";
- return name.matches(pattern);
- }
+ protected boolean isValidName(String name) {
+ if (name == null || name.length() == 0) {
+ return false;
+ }
+ String pattern = "^[a-z0-9-]*$";
+ return name.matches(pattern);
+ }
- protected boolean skipCheck( String javaAttribute ) {
- if ( javaAttribute.equals("model")
- || javaAttribute.equals("eventHeader") ) {
- return true;
- }
- return false;
- }
+ protected boolean skipCheck(String javaAttribute) {
+ if (javaAttribute.equals("model")
+ || javaAttribute.equals("eventHeader")) {
+ return true;
+ }
+ return false;
+ }
- public String processJavaTypeElement( String javaTypeName, Element javaType_Element, StringBuilder sbInventory) {
- String xmlRootElementName = getXMLRootElementName(javaType_Element);
+ public String processJavaTypeElement(String javaTypeName, Element javaType_Element,
+ StringBuilder sbInventory) {
+ String xmlRootElementName = getXMLRootElementName(javaType_Element);
- NodeList parentNodes = javaType_Element.getElementsByTagName("java-attributes");
- StringBuffer sb = new StringBuffer();
- if ( parentNodes.getLength() == 0 ) {
- logger.trace( "no java-attributes for java-type " + javaTypeName);
- return "";
- }
+ NodeList parentNodes = javaType_Element.getElementsByTagName("java-attributes");
+ StringBuilder sb = new StringBuilder();
+ if (parentNodes.getLength() == 0) {
+ logger.trace("no java-attributes for java-type " + javaTypeName);
+ return "";
+ }
- Element parentElement = (Element)parentNodes.item(0);
- NodeList xmlElementNodes = parentElement.getElementsByTagName("xml-element");
- // support for multiple inventory elements across oxm files
- boolean processingInventory = false;
- boolean hasPreviousInventory = false;
- if ( "inventory".equals(xmlRootElementName) && sbInventory != null ) {
- processingInventory = true;
- if ( sbInventory.toString().contains("xs:complexType") ) {
- hasPreviousInventory = true;
- }
- }
+ Element parentElement = (Element) parentNodes.item(0);
+ NodeList xmlElementNodes = parentElement.getElementsByTagName("xml-element");
+ // support for multiple inventory elements across oxm files
+ boolean processingInventory = false;
+ boolean hasPreviousInventory = false;
+ if ("inventory".equals(xmlRootElementName) && sbInventory != null) {
+ processingInventory = true;
+ if (sbInventory.toString().contains("xs:complexType")) {
+ hasPreviousInventory = true;
+ }
+ }
- StringBuffer sb1 = new StringBuffer();
- if ( xmlElementNodes.getLength() > 0 ) {
+ StringBuilder sb1 = new StringBuilder();
+ if (xmlElementNodes.getLength() > 0) {
- if ( !processingInventory || !hasPreviousInventory ) {
- sb1.append(" <xs:element name=\"" + xmlRootElementName + "\">" + LINE_SEPARATOR);
- sb1.append(" <xs:complexType>" + LINE_SEPARATOR);
+ if (!processingInventory || !hasPreviousInventory) {
+ sb1.append(" <xs:element name=\"").append(xmlRootElementName).append("\">")
+ .append(LINE_SEPARATOR);
+ sb1.append(" <xs:complexType>").append(LINE_SEPARATOR);
- XSDElement javaTypeElement = new XSDElement(javaType_Element, maxOccurs);
- logger.debug("XSDElement name: "+javaTypeElement.name());
- if(versionUsesAnnotations(v.toString())) {
- sb1.append(javaTypeElement.getHTMLAnnotation("class", " "));
- }
- sb1.append(" <xs:sequence>" + LINE_SEPARATOR);
- }
- Element javatypeElement;
- for ( int i = 0; i < xmlElementNodes.getLength(); ++i ) {
+ XSDElement javaTypeElement = new XSDElement(javaType_Element, maxOccurs);
+ logger.debug("XSDElement name: " + javaTypeElement.name());
+ sb1.append(javaTypeElement.getHTMLAnnotation("class", " "));
+ sb1.append(" <xs:sequence>").append(LINE_SEPARATOR);
+ }
+ Element javatypeElement;
+ for (int i = 0; i < xmlElementNodes.getLength(); ++i) {
- XSDElement xmlElementElement = new XSDElement((Element)xmlElementNodes.item(i), maxOccurs);
+ XSDElement xmlElementElement =
+ new XSDElement((Element) xmlElementNodes.item(i), maxOccurs);
// String elementName = xmlElementElement.getAttribute("name");
- String elementType = xmlElementElement.getAttribute("type");
- //No simple types; only AAI custom types
- String addType = elementType.contains("." + v.toString() + ".") ? elementType.substring(elementType.lastIndexOf('.')+1) : null;
- if ( elementType.contains("." + v.toString() + ".") && !generatedJavaType.containsKey(addType) ) {
- generatedJavaType.put(addType, elementType);
- javatypeElement = getJavaTypeElement(addType, processingInventory);
- sb.append(processJavaTypeElement( addType, javatypeElement, null ));
- }
- if ("Nodes".equals(addType)) {
- logger.trace("Skipping nodes, temporary testing");
- continue;
- }
- //assembles the basic <element>
- sb1.append(xmlElementElement.getHTMLElement(v, versionUsesAnnotations(v.toString()), this));
- }
- if ( !processingInventory ) {
- sb1.append(" </xs:sequence>" + LINE_SEPARATOR);
- sb1.append(" </xs:complexType>" + LINE_SEPARATOR);
- sb1.append(" </xs:element>" + LINE_SEPARATOR);
- }
- }
+ String elementType = xmlElementElement.getAttribute("type");
+ //No simple types; only AAI custom types
+ String addType = elementType.contains("." + v.toString() + ".") ?
+ elementType.substring(elementType.lastIndexOf('.') + 1) : null;
+ if (elementType.contains("." + v.toString() + ".") &&
+ !generatedJavaType.containsKey(addType)) {
+ generatedJavaType.put(addType, elementType);
+ javatypeElement = getJavaTypeElement(addType, processingInventory);
+ sb.append(processJavaTypeElement(addType, javatypeElement, null));
+ }
+ if ("Nodes".equals(addType)) {
+ logger.trace("Skipping nodes, temporary testing");
+ continue;
+ }
+ //assembles the basic <element>
+ sb1.append(xmlElementElement.getHTMLElement(v, true, this));
+ }
+ if (!processingInventory) {
+ sb1.append(" </xs:sequence>" + LINE_SEPARATOR);
+ sb1.append(" </xs:complexType>" + LINE_SEPARATOR);
+ sb1.append(" </xs:element>" + LINE_SEPARATOR);
+ }
+ }
- if ( xmlElementNodes.getLength() < 1 ) {
- sb.append(" <xs:element name=\"" + xmlRootElementName + "\">" + LINE_SEPARATOR);
- sb.append(" <xs:complexType>" + LINE_SEPARATOR);
- sb.append(" <xs:sequence/>" + LINE_SEPARATOR);
- sb.append(" </xs:complexType>" + LINE_SEPARATOR);
- sb.append(" </xs:element>" + LINE_SEPARATOR);
- generatedJavaType.put(javaTypeName, null);
- return sb.toString();
- }
- if ( processingInventory && sbInventory != null ) {
- sbInventory.append(sb1);
- } else {
- sb.append( sb1 );
- }
- return sb.toString();
- }
+ if (xmlElementNodes.getLength() < 1) {
+ sb.append(" <xs:element name=\"" + xmlRootElementName + "\">" + LINE_SEPARATOR);
+ sb.append(" <xs:complexType>" + LINE_SEPARATOR);
+ sb.append(" <xs:sequence/>" + LINE_SEPARATOR);
+ sb.append(" </xs:complexType>" + LINE_SEPARATOR);
+ sb.append(" </xs:element>" + LINE_SEPARATOR);
+ generatedJavaType.put(javaTypeName, null);
+ return sb.toString();
+ }
+ if (processingInventory && sbInventory != null) {
+ sbInventory.append(sb1);
+ } else {
+ sb.append(sb1);
+ }
+ return sb.toString();
+ }
- private Element getJavaTypeElement( String javaTypeName, boolean processingInventory )
- {
- String attrName, attrValue;
- Attr attr;
- Element javaTypeElement;
+ private Element getJavaTypeElement(String javaTypeName, boolean processingInventory) {
+ String attrName, attrValue;
+ Attr attr;
+ Element javaTypeElement;
- List<Element> combineElementList = new ArrayList<Element>();
- for ( int i = 0; i < javaTypeNodes.getLength(); ++ i ) {
- javaTypeElement = (Element) javaTypeNodes.item(i);
- NamedNodeMap attributes = javaTypeElement.getAttributes();
- for ( int j = 0; j < attributes.getLength(); ++j ) {
- attr = (Attr) attributes.item(j);
- attrName = attr.getNodeName();
- attrValue = attr.getNodeValue();
- if ( attrName.equals("name") && attrValue.equals(javaTypeName)) {
- if ( processingInventory ) {
- return javaTypeElement;
- } else {
- combineElementList.add(javaTypeElement);
- }
- }
- }
- }
- if ( combineElementList.size() == 0 ) {
- logger.error( "oxm file format error, missing java-type " + javaTypeName);
- return (Element) null;
- } else if ( combineElementList.size() > 1 ) {
- // need to combine java-attributes
- return combineElements( javaTypeName, combineElementList);
- }
- return combineElementList.get(0);
+ List<Element> combineElementList = new ArrayList<Element>();
+ for (int i = 0; i < javaTypeNodes.getLength(); ++i) {
+ javaTypeElement = (Element) javaTypeNodes.item(i);
+ NamedNodeMap attributes = javaTypeElement.getAttributes();
+ for (int j = 0; j < attributes.getLength(); ++j) {
+ attr = (Attr) attributes.item(j);
+ attrName = attr.getNodeName();
+ attrValue = attr.getNodeValue();
+ if (attrName.equals("name") && attrValue.equals(javaTypeName)) {
+ if (processingInventory) {
+ return javaTypeElement;
+ } else {
+ combineElementList.add(javaTypeElement);
+ }
+ }
+ }
+ }
+ if (combineElementList.size() == 0) {
+ logger.error("oxm file format error, missing java-type " + javaTypeName);
+ return (Element) null;
+ } else if (combineElementList.size() > 1) {
+ // need to combine java-attributes
+ return combineElements(javaTypeName, combineElementList);
+ }
+ return combineElementList.get(0);
- }
+ }
- private boolean versionUsesAnnotations( String version) {
- return true;
- }
}
diff --git a/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/NodeGetOperation.java b/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/NodeGetOperation.java
index 8c8f844..2561593 100644
--- a/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/NodeGetOperation.java
+++ b/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/NodeGetOperation.java
@@ -7,9 +7,9 @@
* 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
- *
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
* 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.
@@ -17,135 +17,146 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.schemagen.genxsd;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.StringTokenizer;
+import java.util.Vector;
import org.apache.commons.lang3.StringUtils;
import org.onap.aai.schemagen.GenerateXsd;
-import java.util.*;
-
public class NodeGetOperation {
- static Map<String, Vector<String>> containers = new HashMap<String, Vector<String>>();
- static ArrayList<String> checklist = createChecklist();
- private static ArrayList<String> createChecklist()
- {
- ArrayList<String> list = new ArrayList<String>();
- return list;
+ static Map<String, Vector<String>> containers = new HashMap<String, Vector<String>>();
+ static ArrayList<String> checklist = createChecklist();
+
+ private static ArrayList<String> createChecklist() {
+ ArrayList<String> list = new ArrayList<String>();
+ return list;
}
- public static void addContainerProps(String container, Vector<String> containerProps) {
- containers.put(container, containerProps);
- }
- public static void resetContainers() {
- containers = new HashMap<String, Vector<String>>();
- checklist = createChecklist();
- }
- private String useOpId;
- private String xmlRootElementName;
- private String tag;
- private String path;
- private String CRUDpath;
- private String pathParams;
- private String queryParams;
- public NodeGetOperation(String useOpId, String xmlRootElementName, String tag, String path, String pathParams) {
- super();
- this.useOpId = useOpId;
- this.xmlRootElementName = xmlRootElementName;
- this.tag = tag;
- this.CRUDpath = path;
- this.path = nodePath();
- this.pathParams = pathParams;
- StringBuilder p = new StringBuilder();
+ public static void addContainerProps(String container, Vector<String> containerProps) {
+ containers.put(container, containerProps);
+ }
- if(containers.get(xmlRootElementName) == null) {
- this.queryParams = "";
- } else {
- this.queryParams= String.join("", containers.get(xmlRootElementName));
- for(String param : containers.get(xmlRootElementName)) {
- p.append(param);
- }
- this.queryParams = p.toString();
- }
- }
- String nodePath() {
- String path = null;
- int loc = CRUDpath.indexOf(xmlRootElementName);
- if(loc > 0) {
- path = "/nodes/"+CRUDpath.substring(loc);
- }
- return path;
- }
- @Override
- public String toString() {
- StringTokenizer st;
- st = new StringTokenizer(CRUDpath, "/");
- //Path has to be longer than one element
+ public static void resetContainers() {
+ containers = new HashMap<String, Vector<String>>();
+ checklist = createChecklist();
+ }
+
+ private String useOpId;
+ private String xmlRootElementName;
+ private String tag;
+ private String path;
+ private String CRUDpath;
+ private String pathParams;
+ private String queryParams;
+
+ public NodeGetOperation(String useOpId, String xmlRootElementName, String tag, String path,
+ String pathParams) {
+ super();
+ this.useOpId = useOpId;
+ this.xmlRootElementName = xmlRootElementName;
+ this.tag = tag;
+ this.CRUDpath = path;
+ this.path = nodePath();
+ this.pathParams = pathParams;
+ StringBuilder p = new StringBuilder();
+
+ if (containers.get(xmlRootElementName) == null) {
+ this.queryParams = "";
+ } else {
+ this.queryParams = String.join("", containers.get(xmlRootElementName));
+ for (String param : containers.get(xmlRootElementName)) {
+ p.append(param);
+ }
+ this.queryParams = p.toString();
+ }
+ }
+
+ String nodePath() {
+ String path = null;
+ int loc = CRUDpath.indexOf(xmlRootElementName);
+ if (loc > 0) {
+ path = "/nodes/" + CRUDpath.substring(loc);
+ }
+ return path;
+ }
+
+ @Override
+ public String toString() {
+ StringTokenizer st;
+ st = new StringTokenizer(CRUDpath, "/");
+ //Path has to be longer than one element
/*
if ( st.countTokens() <= 1) {
return "";
}
*/
- //a valid tag is necessary
- if ( StringUtils.isEmpty(tag) ) {
- return "";
- }
- if ( CRUDpath.endsWith("/relationship") ) {
- return "";
- }
- if ( CRUDpath.contains("/relationship/") ) { // filter paths with relationship-list
- return "";
- }
- if ( CRUDpath.endsWith("/relationship-list")) {
- return "";
- }
- if ( CRUDpath.startsWith("/search")) {
- return "";
- }
- if ( CRUDpath.startsWith("/actions")) {
- return "";
- }
- if ( CRUDpath.startsWith("/nodes")) {
- return "";
- }
- if (checklist.contains(xmlRootElementName)) {
- return "";
- }
- StringBuffer pathSb = new StringBuffer();
- if(path.indexOf('{') == -1) {
- path += "?parameter=value[&parameter2=value2]";
- }
- pathSb.append(" " + path + ":\n" );
- pathSb.append(" get:\n");
- pathSb.append(" tags:\n");
- pathSb.append(" - Operations" + "\n");
- pathSb.append(" summary: returns " + xmlRootElementName + "\n");
+ //a valid tag is necessary
+ if (StringUtils.isEmpty(tag)) {
+ return "";
+ }
+ if (CRUDpath.endsWith("/relationship")) {
+ return "";
+ }
+ if (CRUDpath.contains("/relationship/")) { // filter paths with relationship-list
+ return "";
+ }
+ if (CRUDpath.endsWith("/relationship-list")) {
+ return "";
+ }
+ if (CRUDpath.startsWith("/search")) {
+ return "";
+ }
+ if (CRUDpath.startsWith("/actions")) {
+ return "";
+ }
+ if (CRUDpath.startsWith("/nodes")) {
+ return "";
+ }
+ if (checklist.contains(xmlRootElementName)) {
+ return "";
+ }
+ StringBuilder pathSb = new StringBuilder();
+ if (path.indexOf('{') == -1) {
+ path += "?parameter=value[&parameter2=value2]";
+ }
+ pathSb.append(" ").append(path).append(":\n");
+ pathSb.append(" get:\n");
+ pathSb.append(" tags:\n");
+ pathSb.append(" - Operations" + "\n");
+ pathSb.append(" summary: returns ").append(xmlRootElementName).append("\n");
- pathSb.append(" description: returns " + xmlRootElementName + "\n");
- pathSb.append(" operationId: get" + useOpId + "\n");
- pathSb.append(" produces:\n");
- pathSb.append(" - application/json\n");
- pathSb.append(" - application/xml\n");
+ pathSb.append(" description: returns ").append(xmlRootElementName).append("\n");
+ pathSb.append(" operationId: get").append(useOpId).append("\n");
+ pathSb.append(" produces:\n");
+ pathSb.append(" - application/json\n");
+ pathSb.append(" - application/xml\n");
- pathSb.append(" responses:\n");
- pathSb.append(" \"200\":\n");
- pathSb.append(" description: successful operation\n");
- pathSb.append(" schema:\n");
- pathSb.append(" $ref: \"#/definitions/" + xmlRootElementName + "\"\n");
- pathSb.append(" \"default\":\n");
- pathSb.append(" " + GenerateXsd.getResponsesUrl());
- if ( StringUtils.isNotEmpty(pathParams) || StringUtils.isNotEmpty(queryParams)) {
- pathSb.append("\n parameters:\n");
- }
- if ( StringUtils.isNotEmpty(pathParams)) {
- pathSb.append(pathParams);
- }
- if ( StringUtils.isNotEmpty(pathParams) && StringUtils.isNotEmpty(queryParams)) {
- pathSb.append("\n");
- }
- if ( StringUtils.isNotEmpty(queryParams)) {
- pathSb.append(queryParams);
- }
- checklist.add(xmlRootElementName);
- return pathSb.toString();
- }
- }
+ pathSb.append(" responses:\n");
+ pathSb.append(" \"200\":\n");
+ pathSb.append(" description: successful operation\n");
+ pathSb.append(" schema:\n");
+ pathSb.append(" $ref: \"#/definitions/").append(xmlRootElementName)
+ .append("\"\n");
+ pathSb.append(" \"default\":\n");
+ pathSb.append(" ").append(GenerateXsd.getResponsesUrl());
+ if (StringUtils.isNotEmpty(pathParams) || StringUtils.isNotEmpty(queryParams)) {
+ pathSb.append("\n parameters:\n");
+ }
+ if (StringUtils.isNotEmpty(pathParams)) {
+ pathSb.append(pathParams);
+ }
+ if (StringUtils.isNotEmpty(pathParams) && StringUtils.isNotEmpty(queryParams)) {
+ pathSb.append("\n");
+ }
+ if (StringUtils.isNotEmpty(queryParams)) {
+ pathSb.append(queryParams);
+ }
+ checklist.add(xmlRootElementName);
+ return pathSb.toString();
+ }
+}
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 1de4466..c42aaed 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
@@ -7,9 +7,9 @@
* 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
- *
+ * <p>
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ * <p>
* 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.
@@ -17,9 +17,29 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.schemagen.genxsd;
import com.google.common.collect.Multimap;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.HashMap;
+import java.util.LinkedHashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.StringTokenizer;
+import java.util.TreeMap;
+import java.util.TreeSet;
+import java.util.Vector;
+import javax.xml.parsers.ParserConfigurationException;
import org.apache.commons.lang3.StringUtils;
import org.onap.aai.edges.EdgeIngestor;
import org.onap.aai.edges.EdgeRule;
@@ -34,33 +54,22 @@ import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
-import javax.xml.parsers.ParserConfigurationException;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.nio.charset.Charset;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.*;
-
public class NodesYAMLfromOXM extends OxmFileProcessor {
private static final Logger logger = LoggerFactory.getLogger("GenerateXsd.class");
- private static final String root = "../aai-schema/src/main/resources";
- private static final String autoGenRoot = "aai-schema/src/main/resources";
- private static final String generateTypeYAML = "yaml";
- private static final String normalStartDir = "aai-schema-gen";
- private static final String yaml_dir = (((System.getProperty("user.dir") != null)
- && (!System.getProperty("user.dir").contains(normalStartDir))) ? autoGenRoot : root)
+ private static final String ROOT = "../aai-schema/src/main/resources";
+ private static final String AUTO_GEN_ROOT = "aai-schema/src/main/resources";
+ private static final String GENERATE_TYPE_YAML = "yaml";
+ private static final String NORMAL_START_DIR = "aai-schema-gen";
+ private static final String YAML_DIR = (((System.getProperty("user.dir") != null)
+ && (!System.getProperty("user.dir").contains(NORMAL_START_DIR))) ? AUTO_GEN_ROOT : ROOT)
+ "/aai_swagger_yaml";
private StringBuilder inventoryDefSb = null;
private Map<String, String> operationDefinitions = new HashMap<>();
- private String basePath;
+ private final String basePath;
public NodesYAMLfromOXM(String basePath, SchemaVersions schemaVersions, NodeIngestor ni,
- EdgeIngestor ei) {
+ EdgeIngestor ei) {
super(schemaVersions, ni, ei);
this.basePath = basePath;
}
@@ -79,26 +88,39 @@ public class NodesYAMLfromOXM extends OxmFileProcessor {
@Override
public String getDocumentHeader() {
- StringBuffer sb = new StringBuffer();
- sb.append("swagger: \"2.0\"\ninfo:" + LINE_SEPARATOR + " ");
+ StringBuilder sb = new StringBuilder();
+ sb.append("swagger: \"2.0\"\ninfo:").append(LINE_SEPARATOR).append(" ");
sb.append("description: |");
if (versionSupportsSwaggerDiff(v.toString())) {
- sb.append("\n\n [Differences versus the previous schema version]("
- +"apidocs" + basePath + "/aai_swagger_" + v.toString() + ".diff)");
- }
- sb.append(
- DOUBLE_LINE_SEPARATOR + " Copyright &copy; 2017-18 AT&amp;T Intellectual Property. All rights reserved." + OxmFileProcessor.DOUBLE_LINE_SEPARATOR + " Licensed under the Creative Commons License, Attribution 4.0 Intl. (the &quot;License&quot;); you may not use this documentation except in compliance with the License." + DOUBLE_LINE_SEPARATOR + " You may obtain a copy of the License at\n\n (https://creativecommons.org/licenses/by/4.0/)" + DOUBLE_LINE_SEPARATOR + " Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an &quot;AS IS&quot; 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." + OxmFileProcessor.DOUBLE_LINE_SEPARATOR + " This document is best viewed with Firefox or Chrome. ");
- sb.append(
- "Nodes can be found by opening the models link below and finding the node-type. ");
+ sb.append("\n\n [Differences versus the previous schema version](" + "apidocs")
+ .append(basePath).append("/aai_swagger_").append(v.toString()).append(".diff)");
+ }
+ sb.append(DOUBLE_LINE_SEPARATOR).append(
+ " Copyright &copy; 2017-18 AT&amp;T Intellectual Property. All rights reserved.")
+ .append(OxmFileProcessor.DOUBLE_LINE_SEPARATOR).append(
+ " Licensed under the Creative Commons License, Attribution 4.0 Intl. (the &quot;License&quot;); you may not use this documentation except in compliance with the License.")
+ .append(DOUBLE_LINE_SEPARATOR).append(
+ " You may obtain a copy of the License at\n\n (https://creativecommons.org/licenses/by/4.0/)")
+ .append(DOUBLE_LINE_SEPARATOR).append(
+ " Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an &quot;AS IS&quot; 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.")
+ .append(OxmFileProcessor.DOUBLE_LINE_SEPARATOR)
+ .append(" This document is best viewed with Firefox or Chrome. ");
sb.append(
- "Edge definitions can be found with the node definitions." + LINE_SEPARATOR + " version: \""
- + v.toString() + "\"" + LINE_SEPARATOR );
- sb.append(" title: Active and Available Inventory REST API" + LINE_SEPARATOR);
- sb.append(
- " license:" + LINE_SEPARATOR + " name: Apache 2.0" + LINE_SEPARATOR + " url: http://www.apache.org/licenses/LICENSE-2.0.html" + LINE_SEPARATOR);
- sb.append(" contact:" + LINE_SEPARATOR + " name: n/a" + LINE_SEPARATOR + " url: n/a" + LINE_SEPARATOR + " email: n/a" + LINE_SEPARATOR);
- sb.append("host: n/a" + LINE_SEPARATOR + "basePath: " + basePath + "/" + v.toString() + LINE_SEPARATOR);
- sb.append("schemes:" + LINE_SEPARATOR + " - https\npaths:" + LINE_SEPARATOR);
+ "Nodes can be found by opening the models link below and finding the node-type. ");
+ sb.append("Edge definitions can be found with the node definitions.").append(LINE_SEPARATOR)
+ .append(" version: \"").append(v.toString()).append("\"").append(LINE_SEPARATOR);
+ sb.append(" title: Active and Available Inventory REST API").append(LINE_SEPARATOR);
+ sb.append(" license:").append(LINE_SEPARATOR).append(" name: Apache 2.0")
+ .append(LINE_SEPARATOR)
+ .append(" url: http://www.apache.org/licenses/LICENSE-2.0.html")
+ .append(LINE_SEPARATOR);
+ sb.append(" contact:").append(LINE_SEPARATOR).append(" name: n/a")
+ .append(LINE_SEPARATOR).append(" url: n/a").append(LINE_SEPARATOR)
+ .append(" email: n/a").append(LINE_SEPARATOR);
+ sb.append("host: n/a").append(LINE_SEPARATOR).append("basePath: ").append(basePath)
+ .append("/").append(v.toString()).append(LINE_SEPARATOR);
+ sb.append("schemes:").append(LINE_SEPARATOR).append(" - https\npaths:")
+ .append(LINE_SEPARATOR);
return sb.toString();
}
@@ -110,8 +132,8 @@ public class NodesYAMLfromOXM extends OxmFileProcessor {
@Override
public String process() throws ParserConfigurationException, SAXException, IOException,
FileNotFoundException, EdgeRuleNotFoundException {
- StringBuffer sb = new StringBuffer();
- StringBuffer pathSb = new StringBuffer();
+ StringBuilder sb = new StringBuilder();
+ StringBuilder pathSb = new StringBuilder();
NodeGetOperation.resetContainers();
try {
init();
@@ -120,7 +142,7 @@ public class NodesYAMLfromOXM extends OxmFileProcessor {
throw e;
}
pathSb.append(getDocumentHeader());
- StringBuffer definitionsSb = new StringBuffer();
+ StringBuilder definitionsSb = new StringBuilder();
Element elem;
String javaTypeName;
for (int i = 0; i < javaTypeNodes.getLength(); ++i) {
@@ -172,7 +194,7 @@ public class NodesYAMLfromOXM extends OxmFileProcessor {
if (inventoryDefSb != null) {
javaTypeDefinitions.put("inventory", inventoryDefSb.toString());
}
- StringBuffer sb = new StringBuffer("definitions:\n");
+ StringBuilder sb = new StringBuilder("definitions:\n");
Map<String, String> sortedJavaTypeDefinitions = new TreeMap<>(javaTypeDefinitions);
for (Map.Entry<String, String> entry : sortedJavaTypeDefinitions.entrySet()) {
@@ -180,14 +202,15 @@ public class NodesYAMLfromOXM extends OxmFileProcessor {
continue;
}
logger.debug(
- "Key: " + entry.getKey() + "Test: " + (entry.getKey() == "relationship-dict"));
+ "Key: " + entry.getKey() + "Test: " +
+ ("relationship-dict".equals(entry.getKey()) ? "true" : "false"));
if (entry.getKey().matches("relationship-dict")) {
String jb = entry.getValue();
logger.debug("Value: " + jb);
int ndx = jb.indexOf("related-to-property:");
if (ndx > 0) {
jb = jb.substring(0, ndx);
- jb = jb.replaceAll(" +$", "");
+ jb = StringUtils.stripEnd(jb, " ");
}
logger.debug("Value-after: " + jb);
sb.append(jb);
@@ -197,24 +220,25 @@ public class NodesYAMLfromOXM extends OxmFileProcessor {
}
return sb.toString();
}
-
+
private String getDictionary(String resource) {
- StringBuffer dictSb = new StringBuffer();
- dictSb.append(" " + resource + ":\n");
+ StringBuilder dictSb = new StringBuilder();
+ dictSb.append(" ").append(resource).append(":\n");
dictSb.append(" description: |\n");
- dictSb.append(" dictionary of " + resource + "\n");
+ dictSb.append(" dictionary of ").append(resource).append("\n");
dictSb.append(" type: object\n");
dictSb.append(" properties:\n");
- dictSb.append(" " + resource + ":\n");
+ dictSb.append(" ").append(resource).append(":\n");
dictSb.append(" type: array\n");
dictSb.append(" items:\n");
- dictSb.append(" $ref: \"#/definitions/" + resource + "-dict\"\n");
+ dictSb.append(" $ref: \"#/definitions/").append(resource).append("-dict\"\n");
return dictSb.toString();
}
- private String processJavaTypeElementSwagger(String javaTypeName, Element javaTypeElement,
- StringBuffer pathSb, StringBuffer definitionsSb, String path, String tag, String opId,
- String getItemName, StringBuffer pathParams, String validEdges) {
+ private String processJavaTypeElementSwagger(
+ String javaTypeName, Element javaTypeElement,
+ StringBuilder pathSb, StringBuilder definitionsSb, String path, String tag, String opId,
+ String getItemName, StringBuilder pathParams, String validEdges) {
String xmlRootElementName = getXMLRootElementName(javaTypeElement);
StringBuilder definitionsLocalSb = new StringBuilder(256);
@@ -227,8 +251,8 @@ public class NodesYAMLfromOXM extends OxmFileProcessor {
logger.debug("tag=" + tag + "; javaTypeName=" + javaTypeName);
return null;
}
- if (!javaTypeName.equals("Inventory")) {
- if (javaTypeName.equals("AaiInternal")) {
+ if (!"Inventory".equals(javaTypeName)) {
+ if ("AaiInternal".equals(javaTypeName)) {
return null;
}
if (opId == null) {
@@ -241,11 +265,11 @@ public class NodesYAMLfromOXM extends OxmFileProcessor {
}
}
- path = xmlRootElementName.equals("inventory") ? ""
+ path = "inventory".equals(xmlRootElementName) ? ""
: (path == null) ? "/" + xmlRootElementName : path + "/" + xmlRootElementName;
XSDJavaType javaType = new XSDJavaType(javaTypeElement);
if (getItemName != null) {
- if (getItemName.equals("array")) {
+ if ("array".equals(getItemName)) {
return javaType.getArrayType();
} else {
return javaType.getItemName();
@@ -271,18 +295,18 @@ public class NodesYAMLfromOXM extends OxmFileProcessor {
Element parentElement = (Element) parentNodes.item(0);
NodeList xmlElementNodes = parentElement.getElementsByTagName("xml-element");
- StringBuffer sbParameters = new StringBuffer();
- StringBuffer sbRequired = new StringBuffer();
+ StringBuilder sbParameters = new StringBuilder();
+ StringBuilder sbRequired = new StringBuilder();
int requiredCnt = 0;
int propertyCnt = 0;
- StringBuffer sbProperties = new StringBuffer();
+ StringBuilder sbProperties = new StringBuilder();
if (appliedPaths.containsKey(path)) {
return null;
}
StringTokenizer st = new StringTokenizer(path, "/");
- logger.debug("path: " + path + " st? " + st.toString());
+ logger.debug("path: " + path + " st? " + st);
if (st.countTokens() > 1 && getItemName == null) {
logger.debug("appliedPaths: " + appliedPaths + " containsKey? "
+ appliedPaths.containsKey(path));
@@ -305,17 +329,18 @@ public class NodesYAMLfromOXM extends OxmFileProcessor {
logger.debug("xmlElementElement.getAttribute(required):"
+ xmlElementElement.getAttribute("required"));
- if (("true").equals(xmlElementElement.getAttribute("required"))) {
+ if ("true".equals(xmlElementElement.getAttribute("required"))) {
if (requiredCnt == 0) {
sbRequired.append(" required:\n");
}
++requiredCnt;
if (addTypeV == null || addTypeV.isEmpty()) {
- sbRequired.append(" - " + xmlElementElement.getAttribute("name") + "\n");
+ sbRequired.append(" - ").append(xmlElementElement.getAttribute("name"))
+ .append("\n");
} else {
for (int k = 0; k < addTypeV.size(); ++k) {
- sbRequired.append(
- " - " + getXmlRootElementName(addTypeV.elementAt(k)) + ":\n");
+ sbRequired.append(" - ")
+ .append(getXmlRootElementName(addTypeV.elementAt(k))).append(":\n");
}
}
}
@@ -329,7 +354,8 @@ public class NodesYAMLfromOXM extends OxmFileProcessor {
NodeGetOperation.addContainerProps(container, containerProps);
}
if (xmlElementElement.isStandardType()) {
- boolean isDslStartNode = dslStartNodeProps.contains(xmlElementElement.getAttribute("name"));
+ boolean isDslStartNode =
+ dslStartNodeProps.contains(xmlElementElement.getAttribute("name"));
sbProperties.append(xmlElementElement.getTypePropertyYAML(isDslStartNode));
++propertyCnt;
}
@@ -337,7 +363,7 @@ public class NodesYAMLfromOXM extends OxmFileProcessor {
// StringBuffer newPathParams = new StringBuffer((pathParams == null ? "" :
// pathParams.toString())+sbParameters.toString()); //cp8128 don't append the pathParams
// to sbParameters so that child nodes don't contain the parameters from parent
- StringBuffer newPathParams = new StringBuffer(sbParameters.toString());
+ StringBuilder newPathParams = new StringBuilder(sbParameters.toString());
String useName;
for (int k = 0; addTypeV != null && k < addTypeV.size(); ++k) {
String addType = addTypeV.elementAt(k);
@@ -353,24 +379,26 @@ public class NodesYAMLfromOXM extends OxmFileProcessor {
tag == null ? useTag : tag, useOpId, "array", null, null);
if (itemName != null) {
- if (addType.equals("AaiInternal")) {
+ if ("AaiInternal".equals(addType)) {
logger.debug("addType AaiInternal, skip properties");
} else if (getItemName == null) {
++propertyCnt;
- sbProperties.append(" " + getXmlRootElementName(addType) + ":\n");
- if ( "RelationshipList".equals(addType)) {
+ sbProperties.append(" ").append(getXmlRootElementName(addType))
+ .append(":\n");
+ if ("RelationshipList".equals(addType)) {
sbProperties.append(" type: object\n");
- sbProperties.append(" $ref: \"#/definitions/"
- + itemName + "\"\n");
+ sbProperties.append(" $ref: \"#/definitions/").append(itemName)
+ .append("\"\n");
} else {
- sbProperties.append(" type: array\n items:\n");
- sbProperties.append(" $ref: \"#/definitions/"
- + (itemName == "" ? "aai-internal" : itemName) + "\"\n");
+ sbProperties.append(" type: array\n items:\n");
+ sbProperties.append(" $ref: \"#/definitions/")
+ .append("".equals(itemName) ? "aai-internal" : itemName)
+ .append("\"\n");
}
if (StringUtils.isNotEmpty(elementDescription)) {
- sbProperties
- .append(" description: " + elementDescription + "\n");
+ sbProperties.append(" description: ").append(elementDescription)
+ .append("\n");
}
}
} else {
@@ -384,38 +412,38 @@ public class NodesYAMLfromOXM extends OxmFileProcessor {
// newPathParams = new StringBuffer((pathParams == null ? "" :
// pathParams.toString())+sbParameters.toString()); //cp8128 - change this
// to not append pathParameters. Just use sbParameters
- newPathParams = new StringBuffer(sbParameters.toString());
+ newPathParams = new StringBuilder(sbParameters.toString());
processJavaTypeElementSwagger(addType, getJavaTypeElementSwagger(addType),
pathSb, definitionsSb, path, tag == null ? useTag : tag, useOpId, null,
newPathParams, validEdges);
useName = getXmlRootElementName(addType);
- sbProperties.append(" " + useName + ":\n");
- if ( "relationship".equals(useName)) {
+ sbProperties.append(" ").append(useName).append(":\n");
+ if ("relationship".equals(useName)) {
sbProperties.append(" type: object\n");
sbProperties.append(" $ref: \"#/definitions/relationship\"\n");
} else {
- sbProperties.append(" type: array\n items: \n");
- sbProperties.append(" $ref: \"#/definitions/"
- + getXmlRootElementName(addType) + "\"\n");
+ sbProperties.append(" type: array\n items: \n");
+ sbProperties.append(" $ref: \"#/definitions/")
+ .append(getXmlRootElementName(addType)).append("\"\n");
}
if (StringUtils.isNotEmpty(elementDescription)) {
- sbProperties
- .append(" description: " + elementDescription + "\n");
+ sbProperties.append(" description: ").append(elementDescription)
+ .append("\n");
}
} else {
// Make sure certain types added to the filter don't appear
- if (nodeFilter.contains(getXmlRootElementName(addType))) {
- ;
- } else {
- sbProperties.append(" " + getXmlRootElementName(addType) + ":\n");
+ if (!nodeFilter.contains(getXmlRootElementName(addType))) {
+ sbProperties.append(" ").append(getXmlRootElementName(addType))
+ .append(":\n");
sbProperties.append(" type: object\n");
- sbProperties.append(" $ref: \"#/definitions/"
- + getXmlRootElementName(addType) + "\"\n");
+ sbProperties.append(" $ref: \"#/definitions/")
+ .append(getXmlRootElementName(addType)).append("\"\n");
}
}
if (StringUtils.isNotEmpty(elementDescription)) {
- sbProperties.append(" description: " + elementDescription + "\n");
+ sbProperties.append(" description: ").append(elementDescription)
+ .append("\n");
}
++propertyCnt;
}
@@ -424,7 +452,7 @@ public class NodesYAMLfromOXM extends OxmFileProcessor {
if (sbParameters.toString().length() > 0) {
if (pathParams == null) {
- pathParams = new StringBuffer();
+ pathParams = new StringBuilder();
}
pathParams.append(sbParameters);
}
@@ -456,8 +484,8 @@ public class NodesYAMLfromOXM extends OxmFileProcessor {
processingInventoryDef = true;
if (inventoryDefSb == null) {
inventoryDefSb = new StringBuilder();
- definitionsSb.append(" " + xmlRootElementName + ":\n");
- definitionsLocalSb.append(" " + xmlRootElementName + ":\n");
+ definitionsSb.append(" ").append(xmlRootElementName).append(":\n");
+ definitionsLocalSb.append(" ").append(xmlRootElementName).append(":\n");
definitionsLocalSb.append(" properties:\n");
}
} else if (xmlRootElementName.equals("relationship")) {
@@ -465,14 +493,14 @@ public class NodesYAMLfromOXM extends OxmFileProcessor {
definitionsLocalSb.append(" " + "relationship-dict" + ":\n");
dict = getDictionary(xmlRootElementName);
} else {
- definitionsSb.append(" " + xmlRootElementName + ":\n");
- definitionsLocalSb.append(" " + xmlRootElementName + ":\n");
+ definitionsSb.append(" ").append(xmlRootElementName).append(":\n");
+ definitionsLocalSb.append(" ").append(xmlRootElementName).append(":\n");
}
DeleteFootnoteSet footnotes = new DeleteFootnoteSet(xmlRootElementName);
- StringBuffer sbEdge = new StringBuffer();
+ StringBuilder sbEdge = new StringBuilder();
LinkedHashSet<String> preventDelete = new LinkedHashSet<String>();
String prevent = null;
- String nodeCaption = new String(" ###### Related Nodes\n");
+ String nodeCaption = " ###### Related Nodes\n";
try {
EdgeRuleQuery q =
new EdgeRuleQuery.Builder(xmlRootElementName).version(v).fromOnly().build();
@@ -484,17 +512,17 @@ public class NodesYAMLfromOXM extends OxmFileProcessor {
results.get(key).stream()
.filter((i) -> (i.getFrom().equals(xmlRootElementName) && (!i.isPrivateEdge())))
.forEach((i) -> {
- logger.info(new String(new StringBuffer(" - TO ").append(i.getTo())
+ logger.info(new String(new StringBuilder(" - TO ").append(i.getTo())
.append(i.getDirection().toString()).append(i.getContains())));
});
results.get(key).stream()
.filter((i) -> (i.getFrom().equals(xmlRootElementName) && (!i.isPrivateEdge())))
.forEach((i) -> {
- sbEdge.append(" - TO " + i.getTo());
+ sbEdge.append(" - TO ").append(i.getTo());
EdgeDescription ed = new EdgeDescription(i);
String footnote = ed.getAlsoDeleteFootnote(xmlRootElementName);
- sbEdge.append(ed.getRelationshipDescription("TO", xmlRootElementName)
- + footnote + "\n");
+ sbEdge.append(ed.getRelationshipDescription("TO", xmlRootElementName))
+ .append(footnote).append("\n");
if (StringUtils.isNotEmpty(footnote)) {
footnotes.add(footnote);
}
@@ -519,11 +547,11 @@ public class NodesYAMLfromOXM extends OxmFileProcessor {
results.get(key).stream()
.filter((i) -> (i.getTo().equals(xmlRootElementName) && (!i.isPrivateEdge())))
.forEach((i) -> {
- sbEdge.append(" - FROM " + i.getFrom());
+ sbEdge.append(" - FROM ").append(i.getFrom());
EdgeDescription ed = new EdgeDescription(i);
String footnote = ed.getAlsoDeleteFootnote(xmlRootElementName);
- sbEdge.append(ed.getRelationshipDescription("FROM", xmlRootElementName)
- + footnote + "\n");
+ sbEdge.append(ed.getRelationshipDescription("FROM", xmlRootElementName))
+ .append(footnote).append("\n");
if (StringUtils.isNotEmpty(footnote)) {
footnotes.add(footnote);
}
@@ -531,8 +559,9 @@ public class NodesYAMLfromOXM extends OxmFileProcessor {
results.get(key).stream()
.filter((i) -> (i.getTo().equals(xmlRootElementName) && (!i.isPrivateEdge())))
.forEach((i) -> {
- logger.info(new String(new StringBuffer(" - FROM ").append(i.getFrom())
- .append(i.getDirection().toString()).append(i.getContains())));
+ logger
+ .info(new String(new StringBuilder(" - FROM ").append(i.getFrom())
+ .append(i.getDirection().toString()).append(i.getContains())));
});
results.get(key).stream()
.filter((i) -> (i.getTo().equals(xmlRootElementName)
@@ -565,8 +594,8 @@ public class NodesYAMLfromOXM extends OxmFileProcessor {
definitionsLocalSb.append(" description: |\n");
if (pathDescriptionProperty != null) {
- definitionsSb.append(" " + pathDescriptionProperty + "\n");
- definitionsLocalSb.append(" " + pathDescriptionProperty + "\n");
+ definitionsSb.append(" ").append(pathDescriptionProperty).append("\n");
+ definitionsLocalSb.append(" ").append(pathDescriptionProperty).append("\n");
}
definitionsSb.append(validEdges);
definitionsLocalSb.append(validEdges);
@@ -589,16 +618,16 @@ public class NodesYAMLfromOXM extends OxmFileProcessor {
namespaceFilter.add(xmlRootElementName);
if (xmlRootElementName.equals("inventory")) {
// will add to javaTypeDefinitions at end
- inventoryDefSb.append(definitionsLocalSb.toString());
+ inventoryDefSb.append(definitionsLocalSb);
} else if (xmlRootElementName.equals("relationship")) {
javaTypeDefinitions.put(xmlRootElementName, dict);
javaTypeDefinitions.put(xmlRootElementName + "-dict",
- definitionsLocalSb.toString());
+ definitionsLocalSb.toString());
} else {
javaTypeDefinitions.put(xmlRootElementName, definitionsLocalSb.toString());
}
} catch (Exception e) {
- e.printStackTrace();
+ logger.trace("Exception during javaTypeDefinitions :", e);
}
if (xmlRootElementName.equals("inventory")) {
logger.trace("skip xmlRootElementName(2)=" + xmlRootElementName);
@@ -622,7 +651,8 @@ public class NodesYAMLfromOXM extends OxmFileProcessor {
private void writeYAMLfile(String outfileName, String fileContent) {
outfileName = (StringUtils.isEmpty(outfileName)) ? "aai_swagger" : outfileName;
outfileName = (outfileName.lastIndexOf(File.separator) == -1)
- ? yaml_dir + File.separator + outfileName + "_" + v.toString() + "." + generateTypeYAML
+ ? YAML_DIR + File.separator + outfileName + "_" + v.toString() + "." +
+ GENERATE_TYPE_YAML
: outfileName;
File outfile = new File(outfileName);
File parentDir = outfile.getParentFile();
@@ -630,39 +660,34 @@ public class NodesYAMLfromOXM extends OxmFileProcessor {
parentDir.mkdirs();
}
try {
- outfile.createNewFile();
+ if(!outfile.createNewFile()) {
+ logger.error( "File {} already exist", outfileName);
+ }
} catch (IOException e) {
- logger.error("Exception creating output file " + outfileName);
- e.printStackTrace();
+ logger.error("Exception creating output file " + outfileName, e);
}
Path path = Paths.get(outfileName);
- Charset charset = Charset.forName("UTF-8");
- try (BufferedWriter bw = Files.newBufferedWriter(path, charset);) {
+ Charset charset = StandardCharsets.UTF_8;
+ try (BufferedWriter bw = Files.newBufferedWriter(path, charset)) {
bw.write(fileContent);
- if (bw != null) {
- bw.close();
- }
} catch (IOException e) {
- logger.error("Exception writing output file " + outfileName);
- e.printStackTrace();
+ logger.error("Exception writing output file " + outfileName, e);
}
}
public boolean validTag(String tag) {
if (tag != null) {
- // refactored to support top level paths from the schema file, set the ignore
- // parameter to false allows the logic to match all top level paths, including
- // Search and Actions, as hard-coded prior to refactoring
- if (checkTopLevel(tag, false)) {
- return true;
- }
+ // refactored to support top level paths from the schema file, set the ignore
+ // parameter to false allows the logic to match all top level paths, including
+ // Search and Actions, as hard-coded prior to refactoring
+ return checkTopLevel(tag, false);
}
return false;
}
public String appendOperations() {
// append definitions
- StringBuffer sb = new StringBuffer();
+ StringBuilder sb = new StringBuilder();
Map<String, String> sortedOperationDefinitions =
new TreeMap<String, String>(operationDefinitions);
for (Map.Entry<String, String> entry : sortedOperationDefinitions.entrySet()) {
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 d9c544d..224192a 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
@@ -17,14 +17,35 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.schemagen.genxsd;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import javax.xml.XMLConstants;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
import org.onap.aai.edges.EdgeIngestor;
import org.onap.aai.edges.exceptions.EdgeRuleNotFoundException;
import org.onap.aai.nodes.NodeIngestor;
import org.onap.aai.setup.SchemaVersion;
import org.onap.aai.setup.SchemaVersions;
-import org.w3c.dom.*;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
@@ -44,10 +65,10 @@ public abstract class OxmFileProcessor {
public static final String DOUBLE_LINE_SEPARATOR =
System.getProperty("line.separator") + System.getProperty("line.separator");
protected static int annotationsStartVersion = 9; // minimum version to support annotations in
- // xsd
+ // xsd
protected static int annotationsMinVersion = 6; // lower versions support annotations in xsd
protected static int swaggerSupportStartsVersion = 1; // minimum version to support swagger
- // documentation
+ // documentation
protected static int swaggerDiffStartVersion = 1; // minimum version to support difference
protected static int swaggerMinBasepath = 6; // minimum version to support difference
static List<String> nodeFilter = createNodeFilter();
@@ -75,28 +96,28 @@ public abstract class OxmFileProcessor {
}
private static List<String> createNodeFilter() {
- List<String> list = Arrays.asList("search", "actions", "aai-internal", "nodes");
- return list;
+ return Arrays.asList("search", "actions", "aai-internal", "nodes");
}
private Map<String, String> createJavaTypeDefinitions() {
- StringBuffer aaiInternal = new StringBuffer();
- StringBuffer nodes = new StringBuffer();
+ StringBuilder aaiInternal = new StringBuilder();
+ StringBuilder nodes = new StringBuilder();
Map<String, String> javaTypeDefinitions = new HashMap<String, String>();
// update to use platform portable line separator
- aaiInternal.append(" aai-internal:" + LINE_SEPARATOR);
- aaiInternal.append(" properties:" + LINE_SEPARATOR);
- aaiInternal.append(" property-name:" + LINE_SEPARATOR);
- aaiInternal.append(" type: string" + LINE_SEPARATOR);
- aaiInternal.append(" property-value:" + LINE_SEPARATOR);
- aaiInternal.append(" type: string" + LINE_SEPARATOR);
+ aaiInternal.append(" aai-internal:").append(LINE_SEPARATOR);
+ aaiInternal.append(" properties:").append(LINE_SEPARATOR);
+ aaiInternal.append(" property-name:").append(LINE_SEPARATOR);
+ aaiInternal.append(" type: string").append(LINE_SEPARATOR);
+ aaiInternal.append(" property-value:").append(LINE_SEPARATOR);
+ aaiInternal.append(" type: string").append(LINE_SEPARATOR);
// javaTypeDefinitions.put("aai-internal", aaiInternal.toString());
- nodes.append(" nodes:" + LINE_SEPARATOR);
- nodes.append(" properties:" + LINE_SEPARATOR);
- nodes.append(" inventory-item-data:" + LINE_SEPARATOR);
- nodes.append(" type: array" + LINE_SEPARATOR);
- nodes.append(" items:" + LINE_SEPARATOR);
- nodes.append(" $ref: \"#/definitions/inventory-item-data\"" + LINE_SEPARATOR);
+ nodes.append(" nodes:").append(LINE_SEPARATOR);
+ nodes.append(" properties:").append(LINE_SEPARATOR);
+ nodes.append(" inventory-item-data:").append(LINE_SEPARATOR);
+ nodes.append(" type: array").append(LINE_SEPARATOR);
+ nodes.append(" items:").append(LINE_SEPARATOR);
+ nodes.append(" $ref: \"#/definitions/inventory-item-data\"")
+ .append(LINE_SEPARATOR);
javaTypeDefinitions.put("nodes", nodes.toString());
return javaTypeDefinitions;
}
@@ -166,20 +187,17 @@ public abstract class OxmFileProcessor {
}
protected boolean checkTopLevel(String topLevel, boolean ignoreActionsSearch) {
- // when ignoreActionsSearch is set to true, with a topLevel that matches one of the values
- // to ignore, the logic will handle those values, as if they are not at the top level.
- // this was done when refactoring checks that may or may not include these top levels.
- // Using this API allows new top levels to be added to the schema file and
- // included in the generated yaml without changing this generation logic.
+ // when ignoreActionsSearch is set to true, with a topLevel that matches one of the values
+ // to ignore, the logic will handle those values, as if they are not at the top level.
+ // this was done when refactoring checks that may or may not include these top levels.
+ // Using this API allows new top levels to be added to the schema file and
+ // included in the generated yaml without changing this generation logic.
if (ignoreActionsSearch) {
if ("Actions".equals(topLevel) || "Search".equals(topLevel)) {
return false;
}
}
- if (topLevelPaths.contains(topLevel)) {
- return true;
- }
- return false;
+ return topLevelPaths.contains(topLevel);
}
protected void init()
@@ -217,32 +235,21 @@ public abstract class OxmFileProcessor {
}
private void createDocument() throws ParserConfigurationException, SAXException, IOException {
- DocumentBuilder dBuilder = null;
- try {
- DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
- dbFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
- dbFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
- dbFactory.setFeature("http://xml.org/sax/features/external-general-entities", false);
- dbFactory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
- dbFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
- dbFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
- dBuilder = dbFactory.newDocumentBuilder();
- } catch (ParserConfigurationException e) {
- throw e;
+ DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
+ dbFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
+ dbFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
+ dbFactory.setFeature("http://xml.org/sax/features/external-general-entities", false);
+ dbFactory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
+ dbFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
+ dbFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
+ DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
+
+ if (xml == null) {
+ doc = dBuilder.parse(oxmFile);
+ } else {
+ InputSource isInput = new InputSource(new StringReader(xml));
+ doc = dBuilder.parse(isInput);
}
- try {
- if (xml == null) {
- doc = dBuilder.parse(oxmFile);
- } else {
- InputSource isInput = new InputSource(new StringReader(xml));
- doc = dBuilder.parse(isInput);
- }
- } catch (SAXException e) {
- throw e;
- } catch (IOException e) {
- throw e;
- }
- return;
}
public abstract String getDocumentHeader();
@@ -262,7 +269,7 @@ public abstract class OxmFileProcessor {
String attrName = attr.getNodeName();
String attrValue = attr.getNodeValue();
- if (attrName.equals("name")) {
+ if ("name".equals(attrName)) {
xmlRootElementName = attrValue;
}
}
@@ -280,7 +287,7 @@ public abstract class OxmFileProcessor {
attr = (Attr) attributes.item(j);
attrName = attr.getNodeName();
attrValue = attr.getNodeValue();
- if (attrName.equals("name") && attrValue.equals(javaTypeName)) {
+ if ("name".equals(attrName) && attrValue.equals(javaTypeName)) {
NodeList valNodes = javaTypeElement.getElementsByTagName("xml-root-element");
Element valElement = (Element) valNodes.item(0);
attributes = valElement.getAttributes();
@@ -289,7 +296,7 @@ public abstract class OxmFileProcessor {
attrName = attr.getNodeName();
attrValue = attr.getNodeValue();
- if (attrName.equals("name")) {
+ if ("name".equals(attrName)) {
return (attrValue);
}
}
@@ -321,7 +328,7 @@ public abstract class OxmFileProcessor {
attr = (Attr) attributes.item(j);
attrName = attr.getNodeName();
attrValue = attr.getNodeValue();
- if (attrName.equals("name") && attrValue.equals(javaTypeName)) {
+ if ("name".equals(attrName) && attrValue.equals(javaTypeName)) {
combineElementList.add(javaTypeElement);
}
}
@@ -335,19 +342,13 @@ public abstract class OxmFileProcessor {
}
public boolean versionSupportsSwaggerDiff(String version) {
- int ver = new Integer(version.substring(1)).intValue();
- if (ver >= HTMLfromOXM.swaggerDiffStartVersion) {
- return true;
- }
- return false;
+ int ver = Integer.parseInt(version.substring(1));
+ return ver >= HTMLfromOXM.swaggerDiffStartVersion;
}
public boolean versionSupportsBasePathProperty(String version) {
- int ver = new Integer(version.substring(1)).intValue();
- if (ver <= HTMLfromOXM.swaggerMinBasepath) {
- return true;
- }
- return false;
+ int ver = Integer.parseInt(version.substring(1));
+ return ver <= HTMLfromOXM.swaggerMinBasepath;
}
protected void updateParentXmlElements(Element parentElement, NodeList moreXmlElementNodes) {
diff --git a/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/PatchOperation.java b/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/PatchOperation.java
index dc762ee..b52e34b 100644
--- a/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/PatchOperation.java
+++ b/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/PatchOperation.java
@@ -7,9 +7,9 @@
* 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
- *
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
* 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.
@@ -17,108 +17,121 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.schemagen.genxsd;
+import java.util.StringTokenizer;
import org.apache.commons.lang3.StringUtils;
-import org.onap.aai.setup.SchemaVersion;
import org.onap.aai.schemagen.GenerateXsd;
-
-import java.util.StringTokenizer;
+import org.onap.aai.setup.SchemaVersion;
public class PatchOperation {
- private String useOpId;
- private String xmlRootElementName;
- private String tag;
- private String path;
- private String pathParams;
- private String prefixForPatch;
- private SchemaVersion version;
- private String basePath;
+ private String useOpId;
+ private String xmlRootElementName;
+ private String tag;
+ private String path;
+ private String pathParams;
+ private String prefixForPatch;
+ private SchemaVersion version;
+ private String basePath;
+
+ public PatchOperation(String useOpId, String xmlRootElementName, String tag, String path,
+ String pathParams, SchemaVersion v, String basePath) {
+ super();
+ this.useOpId = useOpId;
+ this.xmlRootElementName = xmlRootElementName;
+ this.tag = tag;
+ this.path = path;
+ this.pathParams = pathParams;
+ this.prefixForPatch = "";
+ this.version = v;
+ this.basePath = basePath;
+ }
+
+ public void setPrefixForPatchRef(String prefixForPatchRef) {
+ this.prefixForPatch = prefixForPatchRef;
+ }
- public PatchOperation(String useOpId, String xmlRootElementName, String tag, String path,
- String pathParams, SchemaVersion v, String basePath) {
- super();
- this.useOpId = useOpId;
- this.xmlRootElementName = xmlRootElementName;
- this.tag = tag;
- this.path = path;
- this.pathParams = pathParams;
- this.prefixForPatch = "";
- this.version = v;
- this.basePath = basePath;
- }
- public void setPrefixForPatchRef(String prefixForPatchRef) {
- this.prefixForPatch = prefixForPatchRef;
- }
-
- public String toString() {
- StringTokenizer st;
- st = new StringTokenizer(path, "/");
- //a valid tag is necessary
- if ( StringUtils.isEmpty(tag) ) {
- return "";
- }
- if ( path.contains("/relationship/") ) { // filter paths with relationship-list
- return "";
- }
- if ( path.endsWith("/relationship-list")) {
- return "";
- }
- if ( path.startsWith("/search")) {
- return "";
- }
- //No Patch operation paths end with "relationship"
+ public String toString() {
+ StringTokenizer st;
+ st = new StringTokenizer(path, "/");
+ //a valid tag is necessary
+ if (StringUtils.isEmpty(tag)) {
+ return "";
+ }
+ if (path.contains("/relationship/")) { // filter paths with relationship-list
+ return "";
+ }
+ if (path.endsWith("/relationship-list")) {
+ return "";
+ }
+ if (path.startsWith("/search")) {
+ return "";
+ }
+ //No Patch operation paths end with "relationship"
- if (path.endsWith("/relationship") ) {
- return "";
- }
- if (!path.endsWith("}")) {
- return "";
- }
+ if (path.endsWith("/relationship")) {
+ return "";
+ }
+ if (!path.endsWith("}")) {
+ return "";
+ }
- StringBuffer pathSb = new StringBuffer();
- StringBuffer relationshipExamplesSb = new StringBuffer();
- if ( path.endsWith("/relationship") ) {
- pathSb.append(" " + path + ":\n" );
- }
- pathSb.append(" patch:\n");
- pathSb.append(" tags:\n");
- pathSb.append(" - " + tag + "\n");
+ StringBuilder pathSb = new StringBuilder();
+ StringBuilder relationshipExamplesSb = new StringBuilder();
+ if (path.endsWith("/relationship")) {
+ pathSb.append(" ").append(path).append(":\n");
+ }
+ pathSb.append(" patch:\n");
+ pathSb.append(" tags:\n");
+ pathSb.append(" - ").append(tag).append("\n");
- if ( path.endsWith("/relationship") ) {
- pathSb.append(" summary: see node definition for valid relationships\n");
- } else {
- relationshipExamplesSb.append("[See Examples](apidocs" + basePath + "/relations/"+version.toString()+"/"+useOpId+".json)");
- pathSb.append(" summary: update an existing " + xmlRootElementName + "\n");
- pathSb.append(" description: |\n");
- pathSb.append(" Update an existing " + xmlRootElementName + "\n");
- pathSb.append(" #\n");
- pathSb.append(" Note: Endpoints that are not devoted to object relationships support both PUT and PATCH operations.\n");
- pathSb.append(" The PUT operation will entirely replace an existing object.\n");
- pathSb.append(" The PATCH operation sends a \"description of changes\" for an existing object. The entire set of changes must be applied. An error result means no change occurs.\n");
- pathSb.append(" #\n");
- pathSb.append(" Other differences between PUT and PATCH are:\n");
- pathSb.append(" #\n");
- pathSb.append(" - For PATCH, you can send any of the values shown in sample REQUEST body. There are no required values.\n");
- pathSb.append(" - For PATCH, resource-id which is a required REQUEST body element for PUT, must not be sent.\n");
- pathSb.append(" - PATCH cannot be used to update relationship elements; there are dedicated PUT operations for this.\n");
- }
- pathSb.append(" operationId: Update" + useOpId + "\n");
- pathSb.append(" consumes:\n");
- pathSb.append(" - application/json\n");
- pathSb.append(" produces:\n");
- pathSb.append(" - application/json\n");
- pathSb.append(" responses:\n");
- pathSb.append(" \"default\":\n");
- pathSb.append(" " + GenerateXsd.getResponsesUrl());
- pathSb.append(" parameters:\n");
- pathSb.append(pathParams); // for nesting
- pathSb.append(" - name: body\n");
- pathSb.append(" in: body\n");
- pathSb.append(" description: " + xmlRootElementName + " object that needs to be updated."+relationshipExamplesSb.toString()+"\n");
- pathSb.append(" required: true\n");
- pathSb.append(" schema:\n");
- pathSb.append(" $ref: \"#/definitions/" + prefixForPatch + xmlRootElementName + "\"\n");
- return pathSb.toString();
- }
- }
+ if (path.endsWith("/relationship")) {
+ pathSb.append(" summary: see node definition for valid relationships\n");
+ } else {
+ relationshipExamplesSb.append("[See Examples](apidocs").append(basePath)
+ .append("/relations/").append(version.toString()).append("/").append(useOpId)
+ .append(".json)");
+ pathSb.append(" summary: update an existing ").append(xmlRootElementName)
+ .append("\n");
+ pathSb.append(" description: |\n");
+ pathSb.append(" Update an existing ").append(xmlRootElementName)
+ .append("\n");
+ pathSb.append(" #\n");
+ pathSb.append(
+ " Note: Endpoints that are not devoted to object relationships support both PUT and PATCH operations.\n");
+ pathSb.append(" The PUT operation will entirely replace an existing object.\n");
+ pathSb.append(
+ " The PATCH operation sends a \"description of changes\" for an existing object. The entire set of changes must be applied. An error result means no change occurs.\n");
+ pathSb.append(" #\n");
+ pathSb.append(" Other differences between PUT and PATCH are:\n");
+ pathSb.append(" #\n");
+ pathSb.append(
+ " - For PATCH, you can send any of the values shown in sample REQUEST body. There are no required values.\n");
+ pathSb.append(
+ " - For PATCH, resource-id which is a required REQUEST body element for PUT, must not be sent.\n");
+ pathSb.append(
+ " - PATCH cannot be used to update relationship elements; there are dedicated PUT operations for this.\n");
+ }
+ pathSb.append(" operationId: Update").append(useOpId).append("\n");
+ pathSb.append(" consumes:\n");
+ pathSb.append(" - application/json\n");
+ pathSb.append(" produces:\n");
+ pathSb.append(" - application/json\n");
+ pathSb.append(" responses:\n");
+ pathSb.append(" \"default\":\n");
+ pathSb.append(" ").append(GenerateXsd.getResponsesUrl());
+ pathSb.append(" parameters:\n");
+ pathSb.append(pathParams); // for nesting
+ pathSb.append(" - name: body\n");
+ pathSb.append(" in: body\n");
+ pathSb.append(" description: ").append(xmlRootElementName)
+ .append(" object that needs to be updated.")
+ .append(relationshipExamplesSb.toString()).append("\n");
+ pathSb.append(" required: true\n");
+ pathSb.append(" schema:\n");
+ pathSb.append(" $ref: \"#/definitions/").append(prefixForPatch)
+ .append(xmlRootElementName).append("\"\n");
+ return pathSb.toString();
+ }
+}
diff --git a/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/PutOperation.java b/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/PutOperation.java
index 5895306..d1e7ca5 100644
--- a/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/PutOperation.java
+++ b/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/PutOperation.java
@@ -9,9 +9,9 @@
* 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
- *
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
* 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.
@@ -19,11 +19,12 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.schemagen.genxsd;
import org.apache.commons.lang3.StringUtils;
-import org.onap.aai.setup.SchemaVersion;
import org.onap.aai.schemagen.GenerateXsd;
+import org.onap.aai.setup.SchemaVersion;
public class PutOperation {
public static final String RELATIONSHIP = "relationship";
@@ -35,87 +36,94 @@ public class PutOperation {
private SchemaVersion version;
private String basePath;
- public PutOperation(String useOpId, String xmlRootElementName, String tag, String path,
- String pathParams, SchemaVersion v, String basePath) {
- super();
- this.useOpId = useOpId;
- this.xmlRootElementName = xmlRootElementName;
- this.tag = tag;
- this.path = path;
- this.pathParams = pathParams;
- this.version = v;
- this.basePath = basePath;
- }
-
- @Override
- public String toString() {
- //a valid tag is necessary
- if ( StringUtils.isEmpty(tag) ) {
- return "";
- }
- //All Put operation paths end with "relationship"
- //or there is a parameter at the end of the path
- //and there is a parameter in the path
- if ( path.contains("/"+RELATIONSHIP+"/") ) { // filter paths with relationship-list
- return "";
- }
- if ( path.endsWith("/"+RELATIONSHIP+"-list")) {
- return "";
- }
- if ( !path.endsWith("/"+RELATIONSHIP) && !path.endsWith("}") ) {
- return "";
- }
- if ( path.startsWith("/search")) {
- return "";
- }
- StringBuffer pathSb = new StringBuffer();
- StringBuffer relationshipExamplesSb = new StringBuffer();
- if ( path.endsWith("/"+RELATIONSHIP) ) {
- pathSb.append(" " + path + ":\n" );
- }
- pathSb.append(" put:\n");
- pathSb.append(" tags:\n");
- pathSb.append(" - " + tag + "\n");
+ public PutOperation(String useOpId, String xmlRootElementName, String tag, String path,
+ String pathParams, SchemaVersion v, String basePath) {
+ super();
+ this.useOpId = useOpId;
+ this.xmlRootElementName = xmlRootElementName;
+ this.tag = tag;
+ this.path = path;
+ this.pathParams = pathParams;
+ this.version = v;
+ this.basePath = basePath;
+ }
- if ( path.endsWith("/"+RELATIONSHIP) ) {
- pathSb.append(" summary: see node definition for valid relationships\n");
- } else {
- pathSb.append(" summary: create or update an existing " + xmlRootElementName + "\n");
- pathSb.append(" description: |\n Create or update an existing " + xmlRootElementName + ".\n #\n Note! This PUT method has a corresponding PATCH method that can be used to update just a few of the fields of an existing object, rather than a full object replacement. An example can be found in the [PATCH section] below\n");
- }
- relationshipExamplesSb.append("[Valid relationship examples shown here](apidocs" + basePath + "/relations/"+version.toString()+"/"+useOpId.replace("RelationshipListRelationship", "")+".json)");
- pathSb.append(" operationId: createOrUpdate" + useOpId + "\n");
- pathSb.append(" consumes:\n");
- pathSb.append(" - application/json\n");
- pathSb.append(" - application/xml\n");
- pathSb.append(" produces:\n");
- pathSb.append(" - application/json\n");
- pathSb.append(" - application/xml\n");
- pathSb.append(" responses:\n");
- pathSb.append(" \"default\":\n");
- pathSb.append(" " + GenerateXsd.getResponsesUrl());
+ @Override
+ public String toString() {
+ //a valid tag is necessary
+ if (StringUtils.isEmpty(tag)) {
+ return "";
+ }
+ //All Put operation paths end with "relationship"
+ //or there is a parameter at the end of the path
+ //and there is a parameter in the path
+ if (path.contains("/" + RELATIONSHIP + "/")) { // filter paths with relationship-list
+ return "";
+ }
+ if (path.endsWith("/" + RELATIONSHIP + "-list")) {
+ return "";
+ }
+ if (!path.endsWith("/" + RELATIONSHIP) && !path.endsWith("}")) {
+ return "";
+ }
+ if (path.startsWith("/search")) {
+ return "";
+ }
+ StringBuilder pathSb = new StringBuilder();
+ StringBuilder relationshipExamplesSb = new StringBuilder();
+ if (path.endsWith("/" + RELATIONSHIP)) {
+ pathSb.append(" ").append(path).append(":\n");
+ }
+ pathSb.append(" put:\n");
+ pathSb.append(" tags:\n");
+ pathSb.append(" - ").append(tag).append("\n");
- pathSb.append(" parameters:\n");
- pathSb.append(pathParams); // for nesting
- pathSb.append(" - name: body\n");
- pathSb.append(" in: body\n");
- pathSb.append(" description: " + xmlRootElementName + " object that needs to be created or updated. "+relationshipExamplesSb.toString()+"\n");
- pathSb.append(" required: true\n");
- pathSb.append(" schema:\n");
- String useElement = xmlRootElementName;
- if ( xmlRootElementName.equals("relationship")) {
- useElement += "-dict";
- }
- pathSb.append(" $ref: \"#/definitions/" + useElement + "\"\n");
- this.tagRelationshipPathMapEntry();
- return pathSb.toString();
+ if (path.endsWith("/" + RELATIONSHIP)) {
+ pathSb.append(" summary: see node definition for valid relationships\n");
+ } else {
+ pathSb.append(" summary: create or update an existing ")
+ .append(xmlRootElementName).append("\n");
+ pathSb.append(" description: |\n Create or update an existing ")
+ .append(xmlRootElementName).append(
+ ".\n #\n Note! This PUT method has a corresponding PATCH method that can be used to update just a few of the fields of an existing object, rather than a full object replacement. An example can be found in the [PATCH section] below\n");
}
+ relationshipExamplesSb.append("[Valid relationship examples shown here](apidocs")
+ .append(basePath).append("/relations/").append(version.toString()).append("/")
+ .append(useOpId.replace("RelationshipListRelationship", "")).append(".json)");
+ pathSb.append(" operationId: createOrUpdate").append(useOpId).append("\n");
+ pathSb.append(" consumes:\n");
+ pathSb.append(" - application/json\n");
+ pathSb.append(" - application/xml\n");
+ pathSb.append(" produces:\n");
+ pathSb.append(" - application/json\n");
+ pathSb.append(" - application/xml\n");
+ pathSb.append(" responses:\n");
+ pathSb.append(" \"default\":\n");
+ pathSb.append(" ").append(GenerateXsd.getResponsesUrl());
- public String tagRelationshipPathMapEntry() {
- if ( path.endsWith("/"+RELATIONSHIP) ) {
- PutRelationPathSet.add(useOpId, path);
- }
- return "";
+ pathSb.append(" parameters:\n");
+ pathSb.append(pathParams); // for nesting
+ pathSb.append(" - name: body\n");
+ pathSb.append(" in: body\n");
+ pathSb.append(" description: ").append(xmlRootElementName)
+ .append(" object that needs to be created or updated. ")
+ .append(relationshipExamplesSb.toString()).append("\n");
+ pathSb.append(" required: true\n");
+ pathSb.append(" schema:\n");
+ String useElement = xmlRootElementName;
+ if (xmlRootElementName.equals("relationship")) {
+ useElement += "-dict";
}
+ pathSb.append(" $ref: \"#/definitions/").append(useElement).append("\"\n");
+ this.tagRelationshipPathMapEntry();
+ return pathSb.toString();
+ }
+ public String tagRelationshipPathMapEntry() {
+ if (path.endsWith("/" + RELATIONSHIP)) {
+ PutRelationPathSet.add(useOpId, path);
+ }
+ return "";
}
+
+}
diff --git a/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/PutRelationPathSet.java b/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/PutRelationPathSet.java
index 2b3fcf2..43abb1e 100644
--- a/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/PutRelationPathSet.java
+++ b/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/PutRelationPathSet.java
@@ -7,9 +7,9 @@
* 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
- *
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
* 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.
@@ -17,202 +17,225 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.schemagen.genxsd;
import com.google.common.collect.Multimap;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.SortedSet;
+import java.util.TreeSet;
import org.apache.commons.text.similarity.LevenshteinDistance;
import org.onap.aai.edges.EdgeIngestor;
import org.onap.aai.edges.EdgeRule;
import org.onap.aai.edges.EdgeRuleQuery;
-import org.onap.aai.setup.SchemaVersion;
import org.onap.aai.schemagen.GenerateXsd;
+import org.onap.aai.setup.SchemaVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.*;
-
public class PutRelationPathSet {
- EdgeIngestor ei;
- private static final Logger logger = LoggerFactory.getLogger("PutRelationPathSet.class");
- protected static HashMap<String, String> putRelationPaths = new HashMap<String, String>();
- public static void add(String useOpId, String path) {
- putRelationPaths.put(useOpId, path);
- }
-
- String apiPath;
- String opId;
- SchemaVersion version;
- protected ArrayList<String> relations = new ArrayList<String>();
- String objectName = "";
-
- public PutRelationPathSet(SchemaVersion v) {
- this.version = v;
- }
-
- public PutRelationPathSet(String opId, String path, SchemaVersion v) {
- this.apiPath = path.replace("/relationship-list/relationship", "");
- this.opId = opId;
- this.version = v;
- objectName = DeleteOperation.deletePaths.get(apiPath);
- logger.debug("II-apiPath: "+apiPath+"\nPath: "+path+"\nopId="+opId+"\nobjectName="+objectName);
- }
- private void process(EdgeIngestor edgeIngestor) {
- this.ei = edgeIngestor;
- this.toRelations();
- this.fromRelations();
- this.writeRelationsFile();
-
- }
- private void toRelations() {
- logger.debug("{“comment”: “Valid TO Relations that can be added”},");
- logger.debug("apiPath: "+apiPath+"\nopId="+opId+"\nobjectName="+objectName);
- try {
-
- EdgeRuleQuery q1 = new EdgeRuleQuery.Builder("ToOnly",objectName).version(version).build();
- Multimap<String, EdgeRule> results = ei.getRules(q1);
- relations.add("{\"comment\": \"Valid TO Relations that can be added\"}\n");
- SortedSet<String> ss=new TreeSet<String>(results.keySet());
- for(String key : ss) {
- results.get(key).stream().filter((i) -> ("NONE".equals(i.getContains()) &&! i.isPrivateEdge())).forEach((i) ->{ String rel = selectedRelation(i); relations.add(rel); logger.debug("Relation added: "+rel); } );
- }
- } catch(Exception e) {
- logger.debug("objectName: "+objectName+"\n"+e);
- }
- }
- private String selectedRelation(EdgeRule rule) {
- String selectedRelation = "";
- EdgeDescription ed = new EdgeDescription(rule);
- logger.debug(ed.getRuleKey()+"Type="+ed.getType());
- String obj = ed.getRuleKey().replace(objectName,"").replace("|","");
-
- if(ed.getType() == EdgeDescription.LineageType.UNRELATED) {
- String selectObj = getUnrelatedObjectPaths(obj, apiPath);
- logger.debug("SelectedObj"+selectObj);
- selectedRelation = formatObjectRelationSet(obj,selectObj);
- logger.trace("ObjectRelationSet"+selectedRelation);
- } else {
- String selectObj = getKinObjectPath(obj, apiPath);
- logger.debug("SelectedObj"+selectObj);
- selectedRelation = formatObjectRelation(obj,selectObj);
- logger.trace("ObjectRelationSet"+selectedRelation);
- }
- return selectedRelation;
- }
-
- private void fromRelations() {
- logger.debug("“comment”: “Valid FROM Relations that can be added”");
- try {
-
- EdgeRuleQuery q1 = new EdgeRuleQuery.Builder(objectName,"FromOnly").version(version).build();
- Multimap<String, EdgeRule> results = ei.getRules(q1);
- relations.add("{\"comment\": \"Valid FROM Relations that can be added\"}\n");
- SortedSet<String> ss=new TreeSet<String>(results.keySet());
- for(String key : ss) {
- results.get(key).stream().filter((i) -> (! i.isPrivateEdge())).forEach((i) ->{ String rel = selectedRelation(i); relations.add(rel); logger.debug("Relation added: "+rel); } );
- }
- } catch(Exception e) {
- logger.debug("objectName: "+objectName+"\n"+e);
- }
- }
- private void writeRelationsFile() {
- File examplefilePath = new File(GenerateXsd.getYamlDir() + "/relations/" + version.toString()+"/"+opId.replace("RelationshipListRelationship", "") + ".json");
-
- logger.debug(String.join("exampleFilePath: ", examplefilePath.toString()));
- FileOutputStream fop = null;
- try {
- if (!examplefilePath.exists()) {
- examplefilePath.getParentFile().mkdirs();
- examplefilePath.createNewFile();
- }
- fop = new FileOutputStream(examplefilePath);
- } catch(Exception e) {
- e.printStackTrace();
- return;
- }
- try {
- if(relations.size() > 0) {fop.write("[\n".getBytes());}
- fop.write(String.join(",\n", relations).getBytes());
- if(relations.size() > 0) {fop.write("\n]\n".getBytes());}
- fop.flush();
- fop.close();
- } catch (Exception e) {
- e.printStackTrace();
- return;
- }
- finally{
- try {
- fop.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- logger.debug(String.join(",\n", relations));
- return;
- }
-
- private static String formatObjectRelationSet(String obj, String selectObj) {
- StringBuffer pathSb = new StringBuffer();
- String[] paths = selectObj.split("[|]");
- for (String s: paths) {
- logger.trace("SelectOBJ"+s);
- pathSb.append(formatObjectRelation(obj, s)+",\n");
- }
- pathSb.deleteCharAt(pathSb.length()-2);
- return pathSb.toString();
- }
-
- private static String formatObjectRelation(String obj, String selectObj) {
- StringBuffer pathSb = new StringBuffer();
- pathSb.append("{\n");
- pathSb.append("\"related-to\" : \""+obj+"\",\n");
- pathSb.append("\"related-link\" : \""+selectObj+"\"\n");
- pathSb.append("}");
- return pathSb.toString();
- }
-
- private static String getKinObjectPath(String obj, String apiPath) {
- LevenshteinDistance proximity = new LevenshteinDistance();
- String targetPath = "";
- int targetScore = Integer.MAX_VALUE;
- int targetMaxScore = 0;
- for (Map.Entry<String, String> p : DeleteOperation.deletePaths.entrySet()) {
- if(p.getValue().equals(obj)) {
- targetScore = (targetScore >= proximity.apply(apiPath, p.getKey())) ? proximity.apply(apiPath, p.getKey()) : targetScore;
- targetPath = (targetScore >= proximity.apply(apiPath, p.getKey())) ? p.getKey() : targetPath;
- targetMaxScore = (targetMaxScore <= proximity.apply(apiPath, p.getKey())) ? proximity.apply(apiPath, p.getKey()) : targetScore;
- logger.trace(proximity.apply(apiPath, p.getKey())+":"+p.getKey());
- logger.trace(proximity.apply(apiPath, p.getKey())+":"+apiPath);
- }
- }
- return targetPath;
- }
-
- private static String getUnrelatedObjectPaths(String obj, String apiPath) {
- String targetPath = "";
- logger.trace("Obj:"+obj +"\n" + apiPath);
- for (Map.Entry<String, String> p : DeleteOperation.deletePaths.entrySet()) {
- if(p.getValue().equals(obj)) {
- logger.trace("p.getvalue:"+p.getValue()+"p.getkey:"+p.getKey());
- targetPath += ((targetPath.length() == 0 ? "" : "|") + p.getKey());
- logger.trace("Match:"+apiPath +"\n" + targetPath);
- }
- }
- return targetPath;
- }
-
- public void generateRelations(EdgeIngestor edgeIngestor) {
- putRelationPaths.forEach((k,v)->{
- logger.trace("k="+k+"\n"+"v="+v+v.equals("/business/customers/customer/{global-customer-id}/service-subscriptions/service-subscription/{service-type}/service-instances/service-instance/{service-instance-id}/allotted-resources/allotted-resource/{id}/relationship-list/relationship"));
- logger.debug("apiPath(Operation): "+v);
- logger.debug("Target object: "+v.replace("/relationship-list/relationship", ""));
- logger.debug("Relations: ");
- PutRelationPathSet prp = new PutRelationPathSet(k, v, this.version);
- prp.process(edgeIngestor);
- });
- }
+ EdgeIngestor ei;
+ private static final Logger logger = LoggerFactory.getLogger("PutRelationPathSet.class");
+ protected static HashMap<String, String> putRelationPaths = new HashMap<String, String>();
+
+ public static void add(String useOpId, String path) {
+ putRelationPaths.put(useOpId, path);
+ }
+
+ String apiPath;
+ String opId;
+ SchemaVersion version;
+ protected ArrayList<String> relations = new ArrayList<String>();
+ String objectName = "";
+
+ public PutRelationPathSet(SchemaVersion v) {
+ this.version = v;
+ }
+
+ public PutRelationPathSet(String opId, String path, SchemaVersion v) {
+ this.apiPath = path.replace("/relationship-list/relationship", "");
+ this.opId = opId;
+ this.version = v;
+ objectName = DeleteOperation.deletePaths.get(apiPath);
+ logger.debug(
+ "II-apiPath: " + apiPath + "\nPath: " + path + "\nopId=" + opId + "\nobjectName=" +
+ objectName);
+ }
+
+ private void process(EdgeIngestor edgeIngestor) {
+ this.ei = edgeIngestor;
+ this.toRelations();
+ this.fromRelations();
+ this.writeRelationsFile();
+
+ }
+
+ private void toRelations() {
+ logger.debug("{“comment”: “Valid TO Relations that can be added”},");
+ logger.debug("apiPath: " + apiPath + "\nopId=" + opId + "\nobjectName=" + objectName);
+ try {
+
+ EdgeRuleQuery q1 =
+ new EdgeRuleQuery.Builder("ToOnly", objectName).version(version).build();
+ Multimap<String, EdgeRule> results = ei.getRules(q1);
+ relations.add("{\"comment\": \"Valid TO Relations that can be added\"}\n");
+ SortedSet<String> ss = new TreeSet<String>(results.keySet());
+ for (String key : ss) {
+ results.get(key).stream()
+ .filter((i) -> ("NONE".equals(i.getContains()) && !i.isPrivateEdge()))
+ .forEach((i) -> {
+ String rel = selectedRelation(i);
+ relations.add(rel);
+ logger.debug("Relation added: " + rel);
+ });
+ }
+ } catch (Exception e) {
+ logger.debug("objectName: " + objectName + "\n" + e);
+ }
+ }
+
+ private String selectedRelation(EdgeRule rule) {
+ String selectedRelation = "";
+ EdgeDescription ed = new EdgeDescription(rule);
+ logger.debug(ed.getRuleKey() + "Type=" + ed.getType());
+ String obj = ed.getRuleKey().replace(objectName, "").replace("|", "");
+
+ if (ed.getType() == EdgeDescription.LineageType.UNRELATED) {
+ String selectObj = getUnrelatedObjectPaths(obj, apiPath);
+ logger.debug("SelectedObj" + selectObj);
+ selectedRelation = formatObjectRelationSet(obj, selectObj);
+ logger.trace("ObjectRelationSet" + selectedRelation);
+ } else {
+ String selectObj = getKinObjectPath(obj, apiPath);
+ logger.debug("SelectedObj" + selectObj);
+ selectedRelation = formatObjectRelation(obj, selectObj);
+ logger.trace("ObjectRelationSet" + selectedRelation);
+ }
+ return selectedRelation;
+ }
+
+ private void fromRelations() {
+ logger.debug("“comment”: “Valid FROM Relations that can be added”");
+ try {
+
+ EdgeRuleQuery q1 =
+ new EdgeRuleQuery.Builder(objectName, "FromOnly").version(version).build();
+ Multimap<String, EdgeRule> results = ei.getRules(q1);
+ relations.add("{\"comment\": \"Valid FROM Relations that can be added\"}\n");
+ SortedSet<String> ss = new TreeSet<String>(results.keySet());
+ for (String key : ss) {
+ results.get(key).stream().filter((i) -> (!i.isPrivateEdge())).forEach((i) -> {
+ String rel = selectedRelation(i);
+ relations.add(rel);
+ logger.debug("Relation added: " + rel);
+ });
+ }
+ } catch (Exception e) {
+ logger.debug("objectName: " + objectName + "\n" + e);
+ }
+ }
+
+ private void writeRelationsFile() {
+ File examplefilePath = new File(
+ GenerateXsd.getYamlDir() + "/relations/" + version.toString() + "/" +
+ opId.replace("RelationshipListRelationship", "") + ".json");
+
+ logger.debug(String.join("exampleFilePath: ", examplefilePath.toString()));
+ try {
+ if (!examplefilePath.exists()) {
+ examplefilePath.getParentFile().mkdirs();
+ if(!examplefilePath.createNewFile()) {
+ logger.debug("examplefilePath create file error");
+ }
+ }
+ } catch (Exception e) {
+ logger.debug("examplefilePath create file error", e);
+ return;
+ }
+ try (FileOutputStream fop = new FileOutputStream(examplefilePath)) {
+ if (relations.size() > 0) {
+ fop.write("[\n".getBytes());
+ }
+ fop.write(String.join(",\n", relations).getBytes());
+ if (relations.size() > 0) {
+ fop.write("\n]\n".getBytes());
+ }
+ fop.flush();
+ } catch (Exception e) {
+ logger.debug("examplefilePath write error", e);
+ return;
+ }
+ logger.debug(String.join(",\n", relations));
+ }
+
+ private static String formatObjectRelationSet(String obj, String selectObj) {
+ StringBuilder pathSb = new StringBuilder();
+ String[] paths = selectObj.split("[|]");
+ for (String s : paths) {
+ logger.trace("SelectOBJ" + s);
+ pathSb.append(formatObjectRelation(obj, s)).append(",\n");
+ }
+ pathSb.deleteCharAt(pathSb.length() - 2);
+ return pathSb.toString();
+ }
+
+ private static String formatObjectRelation(String obj, String selectObj) {
+ StringBuilder pathSb = new StringBuilder();
+ pathSb.append("{\n");
+ pathSb.append("\"related-to\" : \"").append(obj).append("\",\n");
+ pathSb.append("\"related-link\" : \"").append(selectObj).append("\"\n");
+ pathSb.append("}");
+ return pathSb.toString();
+ }
+
+ private static String getKinObjectPath(String obj, String apiPath) {
+ LevenshteinDistance proximity = new LevenshteinDistance();
+ String targetPath = "";
+ int targetScore = Integer.MAX_VALUE;
+ int targetMaxScore = 0;
+ for (Map.Entry<String, String> p : DeleteOperation.deletePaths.entrySet()) {
+ if (p.getValue().equals(obj)) {
+ targetScore = (targetScore >= proximity.apply(apiPath, p.getKey())) ?
+ proximity.apply(apiPath, p.getKey()) : targetScore;
+ targetPath =
+ (targetScore >= proximity.apply(apiPath, p.getKey())) ? p.getKey() : targetPath;
+ targetMaxScore = (targetMaxScore <= proximity.apply(apiPath, p.getKey())) ?
+ proximity.apply(apiPath, p.getKey()) : targetScore;
+ logger.trace(proximity.apply(apiPath, p.getKey()) + ":" + p.getKey());
+ logger.trace(proximity.apply(apiPath, p.getKey()) + ":" + apiPath);
+ }
+ }
+ return targetPath;
+ }
+
+ private static String getUnrelatedObjectPaths(String obj, String apiPath) {
+ StringBuilder targetPath = new StringBuilder();
+ logger.trace("Obj:" + obj + "\n" + apiPath);
+ for (Map.Entry<String, String> p : DeleteOperation.deletePaths.entrySet()) {
+ if (p.getValue().equals(obj)) {
+ logger.trace("p.getvalue:" + p.getValue() + "p.getkey:" + p.getKey());
+ targetPath.append(targetPath.length() == 0 ? "" : "|").append(p.getKey());
+ logger.trace("Match:" + apiPath + "\n" + targetPath);
+ }
+ }
+ return targetPath.toString();
+ }
+
+ public void generateRelations(EdgeIngestor edgeIngestor) {
+ putRelationPaths.forEach((k, v) -> {
+ logger.trace("k=" + k + "\n" + "v=" + v + v.equals(
+ "/business/customers/customer/{global-customer-id}/service-subscriptions/service-subscription/{service-type}/service-instances/service-instance/{service-instance-id}/allotted-resources/allotted-resource/{id}/relationship-list/relationship"));
+ logger.debug("apiPath(Operation): " + v);
+ logger.debug("Target object: " + v.replace("/relationship-list/relationship", ""));
+ logger.debug("Relations: ");
+ PutRelationPathSet prp = new PutRelationPathSet(k, v, this.version);
+ prp.process(edgeIngestor);
+ });
+ }
}
diff --git a/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/XSDElement.java b/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/XSDElement.java
index 785ea68..5fe3564 100644
--- a/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/XSDElement.java
+++ b/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/XSDElement.java
@@ -7,9 +7,9 @@
* 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
- *
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
* 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.
@@ -17,747 +17,787 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.schemagen.genxsd;
import com.google.common.base.Joiner;
-import org.apache.commons.lang3.StringUtils;
-import org.onap.aai.setup.SchemaVersion;
-import org.w3c.dom.*;
-
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.util.Vector;
+import org.apache.commons.lang3.StringUtils;
+import org.onap.aai.setup.SchemaVersion;
+import org.w3c.dom.Attr;
+import org.w3c.dom.DOMException;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.TypeInfo;
+import org.w3c.dom.UserDataHandler;
public class XSDElement implements Element {
- Element xmlElementElement;
- String maxOccurs;
- private static final int VALUE_NONE = 0;
- private static final int VALUE_DESCRIPTION = 1;
- private static final int VALUE_INDEXED_PROPS = 2;
- private static final int VALUE_CONTAINER = 3;
- private static final int VALUE_REQUIRES = 4;
- private static final int VALUE_DSLSTARTNODE = 5;
-
- public XSDElement(Element xmlElementElement, String maxOccurs) {
- super();
- this.xmlElementElement = xmlElementElement;
- this.maxOccurs = maxOccurs;
- }
-
- public XSDElement(Element xmlElementElement) {
- super();
- this.xmlElementElement = xmlElementElement;
- this.maxOccurs = null;
- }
-
- public String name() {
- return this.getAttribute("name");
- }
-
- public Vector<String> getAddTypes(String version) {
- String apiVersionFmt = "." + version + ".";
- NamedNodeMap attributes = this.getAttributes();
- Vector<String> addTypeV = new Vector<String>(); // vector of 1
- String addType = null;
-
- for ( int j = 0; j < attributes.getLength(); ++j ) {
+ Element xmlElementElement;
+ String maxOccurs;
+ private static final int VALUE_NONE = 0;
+ private static final int VALUE_DESCRIPTION = 1;
+ private static final int VALUE_INDEXED_PROPS = 2;
+ private static final int VALUE_CONTAINER = 3;
+ private static final int VALUE_REQUIRES = 4;
+ private static final int VALUE_DSLSTARTNODE = 5;
+
+ public XSDElement(Element xmlElementElement, String maxOccurs) {
+ super();
+ this.xmlElementElement = xmlElementElement;
+ this.maxOccurs = maxOccurs;
+ }
+
+ public XSDElement(Element xmlElementElement) {
+ super();
+ this.xmlElementElement = xmlElementElement;
+ this.maxOccurs = null;
+ }
+
+ public String name() {
+ return this.getAttribute("name");
+ }
+
+ public Vector<String> getAddTypes(String version) {
+ String apiVersionFmt = "." + version + ".";
+ NamedNodeMap attributes = this.getAttributes();
+ Vector<String> addTypeV = new Vector<>(); // vector of 1
+ String addType = null;
+
+ for (int j = 0; j < attributes.getLength(); ++j) {
Attr attr = (Attr) attributes.item(j);
String attrName = attr.getNodeName();
String attrValue = attr.getNodeValue();
- if ( attrName.equals("type")) {
- if ( attrValue.contains(apiVersionFmt) ) {
- addType = attrValue.substring(attrValue.lastIndexOf('.')+1);
- if ( addTypeV == null )
- addTypeV = new Vector<String>();
- addTypeV.add(addType);
- }
+ if ("type".equals(attrName)) {
+ if (attrValue.contains(apiVersionFmt)) {
+ addType = attrValue.substring(attrValue.lastIndexOf('.') + 1);
+ addTypeV.add(addType);
+ }
}
- }
- return addTypeV;
- }
-
- public String getRequiresProperty() {
- String elementAlsoRequiresProperty = null;
- NodeList xmlPropNodes = this.getElementsByTagName("xml-properties");
-
- for ( int i = 0; i < xmlPropNodes.getLength(); ++i ) {
- Element xmlPropElement = (Element)xmlPropNodes.item(i);
- if (! xmlPropElement.getParentNode().getAttributes().getNamedItem("name").getNodeValue().equals(this.xmlElementElement.getAttribute("name"))){
- continue;
- }
- NodeList childNodes = xmlPropElement.getElementsByTagName("xml-property");
-
- for ( int j = 0; j < childNodes.getLength(); ++j ) {
- Element childElement = (Element)childNodes.item(j);
- // get name
- int useValue = VALUE_NONE;
- NamedNodeMap attributes = childElement.getAttributes();
- for ( int k = 0; k < attributes.getLength(); ++k ) {
- Attr attr = (Attr) attributes.item(k);
- String attrName = attr.getNodeName();
- String attrValue = attr.getNodeValue();
- if ( attrName == null || attrValue == null )
- continue;
- if ( attrName.equals("name") && attrValue.equals("requires")) {
- useValue = VALUE_REQUIRES;
- }
- if ( useValue == VALUE_REQUIRES && attrName.equals("value")) {
- elementAlsoRequiresProperty = attrValue;
- }
- }
- }
- }
- return elementAlsoRequiresProperty;
- }
-
- public String getPathDescriptionProperty() {
- String pathDescriptionProperty = null;
- NodeList xmlPropNodes = this.getElementsByTagName("xml-properties");
-
- for ( int i = 0; i < xmlPropNodes.getLength(); ++i ) {
- Element xmlPropElement = (Element)xmlPropNodes.item(i);
- if (! xmlPropElement.getParentNode().getAttributes().getNamedItem("name").getNodeValue().equals(this.xmlElementElement.getAttribute("name"))){
- continue;
- }
+ }
+ return addTypeV;
+ }
+
+ public String getRequiresProperty() {
+ String elementAlsoRequiresProperty = null;
+ NodeList xmlPropNodes = this.getElementsByTagName("xml-properties");
+
+ for (int i = 0; i < xmlPropNodes.getLength(); ++i) {
+ Element xmlPropElement = (Element) xmlPropNodes.item(i);
+ if (!xmlPropElement.getParentNode().getAttributes().getNamedItem("name").getNodeValue()
+ .equals(this.xmlElementElement.getAttribute("name"))) {
+ continue;
+ }
+ NodeList childNodes = xmlPropElement.getElementsByTagName("xml-property");
+
+ for (int j = 0; j < childNodes.getLength(); ++j) {
+ Element childElement = (Element) childNodes.item(j);
+ // get name
+ int useValue = VALUE_NONE;
+ NamedNodeMap attributes = childElement.getAttributes();
+ for (int k = 0; k < attributes.getLength(); ++k) {
+ Attr attr = (Attr) attributes.item(k);
+ String attrName = attr.getNodeName();
+ String attrValue = attr.getNodeValue();
+ if (attrName == null || attrValue == null) {
+ continue;
+ }
+ if (attrName.equals("name") && attrValue.equals("requires")) {
+ useValue = VALUE_REQUIRES;
+ }
+ if (useValue == VALUE_REQUIRES && attrName.equals("value")) {
+ elementAlsoRequiresProperty = attrValue;
+ }
+ }
+ }
+ }
+ return elementAlsoRequiresProperty;
+ }
+
+ public String getPathDescriptionProperty() {
+ String pathDescriptionProperty = null;
+ NodeList xmlPropNodes = this.getElementsByTagName("xml-properties");
+
+ for (int i = 0; i < xmlPropNodes.getLength(); ++i) {
+ Element xmlPropElement = (Element) xmlPropNodes.item(i);
+ if (!xmlPropElement.getParentNode().getAttributes().getNamedItem("name").getNodeValue()
+ .equals(this.xmlElementElement.getAttribute("name"))) {
+ continue;
+ }
// This stopped working, replaced with above - should figure out why...
// if ( !xmlPropElement.getParentNode().isSameNode(this.xmlElementElement))
// continue;
- NodeList childNodes = xmlPropElement.getElementsByTagName("xml-property");
-
- for ( int j = 0; j < childNodes.getLength(); ++j ) {
- Element childElement = (Element)childNodes.item(j);
- // get name
- int useValue = VALUE_NONE;
- NamedNodeMap attributes = childElement.getAttributes();
- for ( int k = 0; k < attributes.getLength(); ++k ) {
- Attr attr = (Attr) attributes.item(k);
- String attrName = attr.getNodeName();
- String attrValue = attr.getNodeValue();
- if ( attrName == null || attrValue == null )
- continue;
- if ( attrName.equals("name") && attrValue.equals("description")) {
- useValue = VALUE_DESCRIPTION;
- }
- if ( useValue == VALUE_DESCRIPTION && attrName.equals("value")) {
- pathDescriptionProperty = attrValue;
- }
- }
- }
- }
- if ( pathDescriptionProperty != null ) {
- //suppress non-printable characters in a description
+ NodeList childNodes = xmlPropElement.getElementsByTagName("xml-property");
+
+ for (int j = 0; j < childNodes.getLength(); ++j) {
+ Element childElement = (Element) childNodes.item(j);
+ // get name
+ int useValue = VALUE_NONE;
+ NamedNodeMap attributes = childElement.getAttributes();
+ for (int k = 0; k < attributes.getLength(); ++k) {
+ Attr attr = (Attr) attributes.item(k);
+ String attrName = attr.getNodeName();
+ String attrValue = attr.getNodeValue();
+ if (attrName == null || attrValue == null) {
+ continue;
+ }
+ if (attrName.equals("name") && attrValue.equals("description")) {
+ useValue = VALUE_DESCRIPTION;
+ }
+ if (useValue == VALUE_DESCRIPTION && attrName.equals("value")) {
+ pathDescriptionProperty = attrValue;
+ }
+ }
+ }
+ }
+ if (pathDescriptionProperty != null) {
+ //suppress non-printable characters in a description
String replaceDescription = pathDescriptionProperty.replaceAll("[^\\p{ASCII}]", "");
return replaceDescription;
}
- return pathDescriptionProperty;
- }
-
- public Vector<String> getProps(int needValue) {
- Vector<String> props = new Vector<String>();
- NodeList xmlPropNodes = this.getElementsByTagName("xml-properties");
-
- for ( int i = 0; i < xmlPropNodes.getLength(); ++i ) {
- Element xmlPropElement = (Element)xmlPropNodes.item(i);
- if ( !xmlPropElement.getParentNode().isSameNode(this.xmlElementElement))
- continue;
- NodeList childNodes = xmlPropElement.getElementsByTagName("xml-property");
- for ( int j = 0; j < childNodes.getLength(); ++j ) {
- Element childElement = (Element)childNodes.item(j);
- // get name
- int useValue = VALUE_NONE;
- NamedNodeMap attributes = childElement.getAttributes();
- for ( int k = 0; k < attributes.getLength(); ++k ) {
- Attr attr = (Attr) attributes.item(k);
- String attrName = attr.getNodeName();
- String attrValue = attr.getNodeValue();
- if ( attrName == null || attrValue == null )
- continue;
- if ( needValue == VALUE_INDEXED_PROPS && attrValue.equals("indexedProps")) {
- useValue = VALUE_INDEXED_PROPS;
- } else if ( needValue == VALUE_DSLSTARTNODE && attrValue.equals("dslStartNodeProps")) {
- useValue = VALUE_DSLSTARTNODE;
- }
- if ( useValue != VALUE_NONE && attrName.equals("value")) {
- props = getProps( attrValue );
- }
- }
- }
- }
- return props;
- }
-
- private static Vector<String> getProps( String attrValue )
- {
- if ( attrValue == null )
- return null;
- StringTokenizer st = new StringTokenizer( attrValue, ",");
- if ( st.countTokens() == 0 )
- return null;
- Vector<String> result = new Vector<String>();
- while ( st.hasMoreTokens()) {
- result.add(st.nextToken());
- }
- return result;
- }
-
- public Vector<String> getIndexedProps() {
- return getProps(VALUE_INDEXED_PROPS);
- }
-
- public Vector<String> getDslStartNodeProps() {
- return getProps(VALUE_DSLSTARTNODE);
- }
-
- public String getContainerProperty() {
- NodeList xmlPropNodes = this.getElementsByTagName("xml-properties");
- String container = null;
- for ( int i = 0; i < xmlPropNodes.getLength(); ++i ) {
- Element xmlPropElement = (Element)xmlPropNodes.item(i);
- if ( !xmlPropElement.getParentNode().isSameNode(this.xmlElementElement))
- continue;
- NodeList childNodes = xmlPropElement.getElementsByTagName("xml-property");
- for ( int j = 0; j < childNodes.getLength(); ++j ) {
- Element childElement = (Element)childNodes.item(j);
- // get name
- int useValue = VALUE_NONE;
- NamedNodeMap attributes = childElement.getAttributes();
- for ( int k = 0; k < attributes.getLength(); ++k ) {
- Attr attr = (Attr) attributes.item(k);
- String attrName = attr.getNodeName();
- String attrValue = attr.getNodeValue();
- if ( attrName == null || attrValue == null )
- continue;
- if ( useValue == VALUE_CONTAINER && attrName.equals("value")) {
- container = attrValue;
- }
- if ( attrValue.equals("container")) {
- useValue = VALUE_CONTAINER;
- }
- }
- }
- }
- return container;
- }
-
- public String getQueryParamYAML() {
- StringBuffer sbParameter = new StringBuffer();
- sbParameter.append((" - name: " + this.getAttribute("name") + "\n"));
- sbParameter.append((" in: query\n"));
- if ( this.getAttribute("description") != null && this.getAttribute("description").length() > 0 )
- sbParameter.append((" description: " + this.getAttribute("description") + "\n"));
- else
- sbParameter.append((" description: n/a\n"));
- sbParameter.append((" required: false\n"));
- if ( ("java.lang.String").equals(this.getAttribute("type")))
- sbParameter.append(" type: string\n");
- if ( ("java.lang.Long").equals(this.getAttribute("type"))) {
- sbParameter.append(" type: integer\n");
- sbParameter.append(" format: int64\n");
- }
- if ( ("java.lang.Integer").equals(this.getAttribute("type"))) {
- sbParameter.append(" type: integer\n");
- sbParameter.append(" format: int32\n");
- }
- if ( ("java.lang.Boolean").equals(this.getAttribute("type"))) {
- sbParameter.append(" type: boolean\n");
- }
- return sbParameter.toString();
- }
-
- public String getPathParamYAML(String elementDescription) {
- return getPathParamYAML(elementDescription, null);
- }
-
- public String getPathParamYAML(String elementDescription, String overrideName) {
- // updated to allow caller to provide parameter name to use in API
- StringBuffer sbParameter = new StringBuffer();
- if ( overrideName == null ) {
- overrideName = this.getAttribute("name");
- }
- sbParameter.append((" - name: " + overrideName + "\n"));
- sbParameter.append((" in: path\n"));
- if ( elementDescription != null && elementDescription.length() > 0 )
- sbParameter.append((" description: " + elementDescription + "\n"));
- sbParameter.append((" required: true\n"));
- if ( ("java.lang.String").equals(this.getAttribute("type")))
- sbParameter.append(" type: string\n");
- if ( ("java.lang.Long").equals(this.getAttribute("type"))) {
- sbParameter.append(" type: integer\n");
- sbParameter.append(" format: int64\n");
- }
- if ( ("java.lang.Integer").equals(this.getAttribute("type"))) {
- sbParameter.append(" type: integer\n");
- sbParameter.append(" format: int32\n");
- }
- if ( ("java.lang.Boolean").equals(this.getAttribute("type"))) {
- sbParameter.append(" type: boolean\n");
- }
- if(StringUtils.isNotBlank(this.getAttribute("name"))) {
- sbParameter.append(" example: "+"__"+this.getAttribute("name").toUpperCase()+"__"+"\n");
- }
- return sbParameter.toString();
- }
-
- public String getHTMLElement(SchemaVersion v, boolean useAnnotation, HTMLfromOXM driver) {
- StringBuffer sbElement = new StringBuffer();
- String elementName = this.getAttribute("name");
- String elementType = this.getAttribute("type");
- String elementContainerType = this.getAttribute("container-type");
- String elementIsRequired = this.getAttribute("required");
- String addType = elementType.contains("." + v.toString() + ".") ? elementType.substring(elementType.lastIndexOf('.')+1) : null;
-
- if ( addType != null ) {
- sbElement.append(" <xs:element ref=\"tns:" + driver.getXmlRootElementName(addType)+"\"");
- } else {
- sbElement.append(" <xs:element name=\"" + elementName +"\"");
- }
- if ( elementType.equals("java.lang.String"))
- sbElement.append(" type=\"xs:string\"");
- if ( elementType.equals("java.lang.Long"))
- sbElement.append(" type=\"xs:unsignedInt\"");
- if ( elementType.equals("java.lang.Integer"))
- sbElement.append(" type=\"xs:int\"");
- if ( elementType.equals("java.lang.Boolean"))
- sbElement.append(" type=\"xs:boolean\"");
- if ( addType != null || elementType.startsWith("java.lang.") ) {
- sbElement.append(" minOccurs=\"0\"");
- }
- if ( elementContainerType != null && elementContainerType.equals("java.util.ArrayList")) {
- sbElement.append(" maxOccurs=\"" + maxOccurs + "\"");
- }
- if(useAnnotation) {
- String annotation = new XSDElement(xmlElementElement, maxOccurs).getHTMLAnnotation("field", " ");
- sbElement.append(StringUtils.isNotEmpty(annotation) ? ">" + OxmFileProcessor.LINE_SEPARATOR : "");
- sbElement.append(annotation);
- sbElement.append(StringUtils.isNotEmpty(annotation) ? " </xs:element>" + OxmFileProcessor.LINE_SEPARATOR : "/>" + OxmFileProcessor.LINE_SEPARATOR );
- } else {
- sbElement.append("/>" + OxmFileProcessor.LINE_SEPARATOR);
- }
- return this.getHTMLElementWrapper(sbElement.toString(), v, useAnnotation);
+ return pathDescriptionProperty;
+ }
+
+ public Vector<String> getProps(int needValue) {
+ Vector<String> props = new Vector<String>();
+ NodeList xmlPropNodes = this.getElementsByTagName("xml-properties");
+
+ for (int i = 0; i < xmlPropNodes.getLength(); ++i) {
+ Element xmlPropElement = (Element) xmlPropNodes.item(i);
+ if (!xmlPropElement.getParentNode().isSameNode(this.xmlElementElement)) {
+ continue;
+ }
+ NodeList childNodes = xmlPropElement.getElementsByTagName("xml-property");
+ for (int j = 0; j < childNodes.getLength(); ++j) {
+ Element childElement = (Element) childNodes.item(j);
+ // get name
+ int useValue = VALUE_NONE;
+ NamedNodeMap attributes = childElement.getAttributes();
+ for (int k = 0; k < attributes.getLength(); ++k) {
+ Attr attr = (Attr) attributes.item(k);
+ String attrName = attr.getNodeName();
+ String attrValue = attr.getNodeValue();
+ if (attrName == null || attrValue == null) {
+ continue;
+ }
+ if (needValue == VALUE_INDEXED_PROPS && attrValue.equals("indexedProps")) {
+ useValue = VALUE_INDEXED_PROPS;
+ } else if (needValue == VALUE_DSLSTARTNODE &&
+ attrValue.equals("dslStartNodeProps")) {
+ useValue = VALUE_DSLSTARTNODE;
+ }
+ if (useValue != VALUE_NONE && attrName.equals("value")) {
+ props = getProps(attrValue);
+ }
+ }
+ }
+ }
+ return props;
+ }
+
+ private static Vector<String> getProps(String attrValue) {
+ if (attrValue == null) {
+ return null;
+ }
+ StringTokenizer st = new StringTokenizer(attrValue, ",");
+ if (st.countTokens() == 0) {
+ return null;
+ }
+ Vector<String> result = new Vector<String>();
+ while (st.hasMoreTokens()) {
+ result.add(st.nextToken());
+ }
+ return result;
+ }
+
+ public Vector<String> getIndexedProps() {
+ return getProps(VALUE_INDEXED_PROPS);
+ }
+
+ public Vector<String> getDslStartNodeProps() {
+ return getProps(VALUE_DSLSTARTNODE);
+ }
+
+ public String getContainerProperty() {
+ NodeList xmlPropNodes = this.getElementsByTagName("xml-properties");
+ String container = null;
+ for (int i = 0; i < xmlPropNodes.getLength(); ++i) {
+ Element xmlPropElement = (Element) xmlPropNodes.item(i);
+ if (!xmlPropElement.getParentNode().isSameNode(this.xmlElementElement)) {
+ continue;
+ }
+ NodeList childNodes = xmlPropElement.getElementsByTagName("xml-property");
+ for (int j = 0; j < childNodes.getLength(); ++j) {
+ Element childElement = (Element) childNodes.item(j);
+ // get name
+ int useValue = VALUE_NONE;
+ NamedNodeMap attributes = childElement.getAttributes();
+ for (int k = 0; k < attributes.getLength(); ++k) {
+ Attr attr = (Attr) attributes.item(k);
+ String attrName = attr.getNodeName();
+ String attrValue = attr.getNodeValue();
+ if (attrName == null || attrValue == null) {
+ continue;
+ }
+ if (useValue == VALUE_CONTAINER && attrName.equals("value")) {
+ container = attrValue;
+ }
+ if (attrValue.equals("container")) {
+ useValue = VALUE_CONTAINER;
+ }
+ }
+ }
+ }
+ return container;
+ }
+
+ public String getQueryParamYAML() {
+ StringBuilder sbParameter = new StringBuilder();
+ sbParameter.append(" - name: ").append(this.getAttribute("name")).append("\n");
+ sbParameter.append((" in: query\n"));
+ if (this.getAttribute("description") != null &&
+ this.getAttribute("description").length() > 0) {
+ sbParameter.append(" description: ").append(this.getAttribute("description"))
+ .append("\n");
+ } else {
+ sbParameter.append((" description: n/a\n"));
+ }
+ sbParameter.append((" required: false\n"));
+ if (("java.lang.String").equals(this.getAttribute("type"))) {
+ sbParameter.append(" type: string\n");
+ }
+ if (("java.lang.Long").equals(this.getAttribute("type"))) {
+ sbParameter.append(" type: integer\n");
+ sbParameter.append(" format: int64\n");
+ }
+ if (("java.lang.Integer").equals(this.getAttribute("type"))) {
+ sbParameter.append(" type: integer\n");
+ sbParameter.append(" format: int32\n");
+ }
+ if (("java.lang.Boolean").equals(this.getAttribute("type"))) {
+ sbParameter.append(" type: boolean\n");
+ }
+ return sbParameter.toString();
+ }
+
+ public String getPathParamYAML(String elementDescription) {
+ return getPathParamYAML(elementDescription, null);
+ }
+
+ public String getPathParamYAML(String elementDescription, String overrideName) {
+ // updated to allow caller to provide parameter name to use in API
+ StringBuilder sbParameter = new StringBuilder();
+ if (overrideName == null) {
+ overrideName = this.getAttribute("name");
+ }
+ sbParameter.append(" - name: ").append(overrideName).append("\n");
+ sbParameter.append((" in: path\n"));
+ if (elementDescription != null && elementDescription.length() > 0) {
+ sbParameter.append(" description: ").append(elementDescription).append("\n");
+ }
+ sbParameter.append((" required: true\n"));
+ if (("java.lang.String").equals(this.getAttribute("type"))) {
+ sbParameter.append(" type: string\n");
+ }
+ if (("java.lang.Long").equals(this.getAttribute("type"))) {
+ sbParameter.append(" type: integer\n");
+ sbParameter.append(" format: int64\n");
+ }
+ if (("java.lang.Integer").equals(this.getAttribute("type"))) {
+ sbParameter.append(" type: integer\n");
+ sbParameter.append(" format: int32\n");
+ }
+ if (("java.lang.Boolean").equals(this.getAttribute("type"))) {
+ sbParameter.append(" type: boolean\n");
+ }
+ if (StringUtils.isNotBlank(this.getAttribute("name"))) {
+ sbParameter.append(" example: " + "__")
+ .append(this.getAttribute("name").toUpperCase()).append("__").append("\n");
+ }
+ return sbParameter.toString();
+ }
+
+ public String getHTMLElement(SchemaVersion v, boolean useAnnotation, HTMLfromOXM driver) {
+ StringBuilder sbElement = new StringBuilder();
+ String elementName = this.getAttribute("name");
+ String elementType = this.getAttribute("type");
+ String elementContainerType = this.getAttribute("container-type");
+ String elementIsRequired = this.getAttribute("required");
+ String addType = elementType.contains("." + v.toString() + ".") ?
+ elementType.substring(elementType.lastIndexOf('.') + 1) : null;
+
+ if (addType != null) {
+ sbElement.append(" <xs:element ref=\"tns:")
+ .append(driver.getXmlRootElementName(addType)).append("\"");
+ } else {
+ sbElement.append(" <xs:element name=\"").append(elementName).append("\"");
+ }
+ if (elementType.equals("java.lang.String")) {
+ sbElement.append(" type=\"xs:string\"");
+ }
+ if (elementType.equals("java.lang.Long")) {
+ sbElement.append(" type=\"xs:unsignedInt\"");
+ }
+ if (elementType.equals("java.lang.Integer")) {
+ sbElement.append(" type=\"xs:int\"");
+ }
+ if (elementType.equals("java.lang.Boolean")) {
+ sbElement.append(" type=\"xs:boolean\"");
+ }
+ if (addType != null || elementType.startsWith("java.lang.")) {
+ sbElement.append(" minOccurs=\"0\"");
+ }
+ if (elementContainerType != null && elementContainerType.equals("java.util.ArrayList")) {
+ sbElement.append(" maxOccurs=\"").append(maxOccurs).append("\"");
+ }
+ if (useAnnotation) {
+ String annotation = new XSDElement(xmlElementElement, maxOccurs)
+ .getHTMLAnnotation("field", " ");
+ sbElement.append(
+ StringUtils.isNotEmpty(annotation) ? ">" + OxmFileProcessor.LINE_SEPARATOR : "");
+ sbElement.append(annotation);
+ sbElement.append(StringUtils.isNotEmpty(annotation) ?
+ " </xs:element>" + OxmFileProcessor.LINE_SEPARATOR :
+ "/>" + OxmFileProcessor.LINE_SEPARATOR);
+ } else {
+ sbElement.append("/>").append(OxmFileProcessor.LINE_SEPARATOR);
+ }
+ return this.getHTMLElementWrapper(sbElement.toString(), v, useAnnotation);
// return sbElement.toString();
- }
-
- public String getHTMLElementWrapper(String unwrappedElement, SchemaVersion v, boolean useAnnotation) {
-
- NodeList childNodes = this.getElementsByTagName("xml-element-wrapper");
-
- String xmlElementWrapper = null;
- if ( childNodes.getLength() > 0 ) {
- Element childElement = (Element)childNodes.item(0);
- // get name
- xmlElementWrapper = childElement == null ? null : childElement.getAttribute("name");
- }
- if(xmlElementWrapper == null)
- return unwrappedElement;
-
- StringBuffer sbElement = new StringBuffer();
- sbElement.append(" <xs:element name=\"" + xmlElementWrapper +"\"");
- String elementType = xmlElementElement.getAttribute("type");
- String elementIsRequired = this.getAttribute("required");
- String addType = elementType.contains("." + v.toString() + ".") ? elementType.substring(elementType.lastIndexOf('.')+1) : null;
-
- if ( elementIsRequired == null || !elementIsRequired.equals("true")||addType != null) {
- sbElement.append(" minOccurs=\"0\"");
- }
- sbElement.append(">" + OxmFileProcessor.LINE_SEPARATOR);
- sbElement.append(" <xs:complexType>" + OxmFileProcessor.LINE_SEPARATOR);
- if(useAnnotation) {
- XSDElement javaTypeElement = new XSDElement((Element)this.getParentNode(), maxOccurs);
- sbElement.append(javaTypeElement.getHTMLAnnotation("class", " "));
- }
- sbElement.append(" <xs:sequence>" + OxmFileProcessor.LINE_SEPARATOR);
- sbElement.append(" ");
- sbElement.append(unwrappedElement);
- sbElement.append(" </xs:sequence>" + OxmFileProcessor.LINE_SEPARATOR);
- sbElement.append(" </xs:complexType>" + OxmFileProcessor.LINE_SEPARATOR);
- sbElement.append(" </xs:element>" + OxmFileProcessor.LINE_SEPARATOR);
- return sbElement.toString();
- }
-
- public String getHTMLAnnotation(String target, String indentation) {
- StringBuffer sb = new StringBuffer();
- List<String> metadata = new ArrayList<>();
- if("true".equals(this.getAttribute("xml-key")) ) {
- metadata.add("isKey=true");
- }
-
- NodeList xmlPropTags = this.getElementsByTagName("xml-properties");
- Element xmlPropElement = null;
- for ( int i = 0; i < xmlPropTags.getLength(); ++i ) {
- xmlPropElement = (Element)xmlPropTags.item(i);
- if (! xmlPropElement.getParentNode().getAttributes().getNamedItem("name").getNodeValue().equals(this.xmlElementElement.getAttribute("name")))
- continue;
- else
- break;
- }
- if(xmlPropElement != null) {
- NodeList xmlProperties = xmlPropElement.getElementsByTagName("xml-property");
- for (int i = 0; i < xmlProperties.getLength(); i++) {
- Element item = (Element)xmlProperties.item(i);
- String name = item.getAttribute("name");
- String value = item.getAttribute("value");
- if (name.equals("abstract")) {
- name = "isAbstract";
- } else if (name.equals("extends")) {
- name = "extendsFrom";
- }
- metadata.add(name + "=\"" + value.replaceAll("&", "&amp;") + "\"");
- }
- }
- if(metadata.size() == 0) {
- return "";
- }
- sb.append(indentation +"<xs:annotation>" + OxmFileProcessor.LINE_SEPARATOR);
- sb.append(
- indentation + " <xs:appinfo>" + OxmFileProcessor.LINE_SEPARATOR +
- indentation + " <annox:annotate target=\""+target+"\">@org.onap.aai.annotations.Metadata(" + Joiner.on(",").join(metadata) + ")</annox:annotate>" + OxmFileProcessor.LINE_SEPARATOR +
- indentation + " </xs:appinfo>" + OxmFileProcessor.LINE_SEPARATOR);
- sb.append(indentation +"</xs:annotation>" + OxmFileProcessor.LINE_SEPARATOR);
- return sb.toString();
- }
-
- public String getTypePropertyYAML(boolean isDslStartNode) {
- StringBuffer sbProperties = new StringBuffer();
- sbProperties.append(" " + this.getAttribute("name") + ":\n");
- sbProperties.append(" type: ");
-
- if ( ("java.lang.String").equals(this.getAttribute("type")))
- sbProperties.append("string\n");
- else if ( ("java.lang.Long").equals(this.getAttribute("type"))) {
- sbProperties.append("integer\n");
- sbProperties.append(" format: int64\n");
- }
- else if ( ("java.lang.Integer").equals(this.getAttribute("type"))){
- sbProperties.append("integer\n");
- sbProperties.append(" format: int32\n");
- }
- else if ( ("java.lang.Boolean").equals(this.getAttribute("type")))
- sbProperties.append("boolean\n");
- String attrDescription = this.getPathDescriptionProperty();
- if ( attrDescription != null && attrDescription.length() > 0 ) {
- if ( !isDslStartNode ) {
- sbProperties.append(" description: " + attrDescription + "\n");
- } else {
- sbProperties.append(" description: |\n");
- sbProperties.append(" " + attrDescription + "\n");
- sbProperties.append(" *This property can be used as a filter to find the start node for a dsl query\n");
- }
- } else {
- if ( isDslStartNode ) {
- sbProperties.append(" description: |\n");
- sbProperties.append(" \n");
- sbProperties.append(" *This property can be used as a filter to find the start node for a dsl query\n");
- }
- }
- String elementAlsoRequiresProperty=this.getRequiresProperty();
- if ( StringUtils.isNotEmpty(elementAlsoRequiresProperty) )
- sbProperties.append(" also requires: " + elementAlsoRequiresProperty + "\n");
- return sbProperties.toString();
- }
-
- public boolean isStandardType()
- {
- switch ( this.getAttribute("type") ) {
- case "java.lang.String":
- case "java.lang.Long":
- case "java.lang.Integer":
- case"java.lang.Boolean":
- return true;
- }
- return false;
- }
-
- @Override
- public String getNodeName() {
- return xmlElementElement.getNodeName();
- }
-
- @Override
- public String getNodeValue() throws DOMException {
- return xmlElementElement.getNodeValue();
- }
-
- @Override
- public void setNodeValue(String nodeValue) throws DOMException {
- xmlElementElement.setNodeValue(nodeValue);
- }
-
- @Override
- public short getNodeType() {
- return xmlElementElement.getNodeType();
- }
-
- @Override
- public Node getParentNode() {
- return xmlElementElement.getParentNode();
- }
-
- @Override
- public NodeList getChildNodes() {
- return xmlElementElement.getChildNodes();
- }
-
- @Override
- public Node getFirstChild() {
- return xmlElementElement.getFirstChild();
- }
-
- @Override
- public Node getLastChild() {
- return xmlElementElement.getLastChild();
- }
-
- @Override
- public Node getPreviousSibling() {
- return xmlElementElement.getPreviousSibling();
- }
-
- @Override
- public Node getNextSibling() {
- return xmlElementElement.getNextSibling();
- }
-
- @Override
- public NamedNodeMap getAttributes() {
- return xmlElementElement.getAttributes();
- }
-
- @Override
- public Document getOwnerDocument() {
- return xmlElementElement.getOwnerDocument();
- }
-
- @Override
- public Node insertBefore(Node newChild, Node refChild) throws DOMException {
- return xmlElementElement.insertBefore(newChild, refChild);
- }
-
- @Override
- public Node replaceChild(Node newChild, Node oldChild) throws DOMException {
- return xmlElementElement.replaceChild(newChild, oldChild);
- }
-
- @Override
- public Node removeChild(Node oldChild) throws DOMException {
- return xmlElementElement.removeChild(oldChild);
- }
-
- @Override
- public Node appendChild(Node newChild) throws DOMException {
- return xmlElementElement.appendChild(newChild);
- }
-
- @Override
- public boolean hasChildNodes() {
- return xmlElementElement.hasChildNodes();
- }
-
- @Override
- public Node cloneNode(boolean deep) {
- return xmlElementElement.cloneNode(deep);
- }
-
- @Override
- public void normalize() {
- xmlElementElement.normalize();
- }
-
- @Override
- public boolean isSupported(String feature, String version) {
- return xmlElementElement.isSupported(feature, version);
- }
-
- @Override
- public String getNamespaceURI() {
- return xmlElementElement.getNamespaceURI();
- }
-
- @Override
- public String getPrefix() {
- return xmlElementElement.getPrefix();
- }
-
- @Override
- public void setPrefix(String prefix) throws DOMException {
- xmlElementElement.setPrefix(prefix);
- }
-
- @Override
- public String getLocalName() {
-
- return xmlElementElement.getLocalName();
- }
-
- @Override
- public boolean hasAttributes() {
- return xmlElementElement.hasAttributes();
- }
-
- @Override
- public String getBaseURI() {
- return xmlElementElement.getBaseURI();
- }
-
- @Override
- public short compareDocumentPosition(Node other) throws DOMException {
- return xmlElementElement.compareDocumentPosition(other);
- }
-
- @Override
- public String getTextContent() throws DOMException {
- return xmlElementElement.getTextContent();
- }
-
- @Override
- public void setTextContent(String textContent) throws DOMException {
- xmlElementElement.setTextContent(textContent);
- }
-
- @Override
- public boolean isSameNode(Node other) {
- return xmlElementElement.isSameNode(other);
- }
-
- @Override
- public String lookupPrefix(String namespaceURI) {
- return xmlElementElement.lookupPrefix(namespaceURI);
- }
-
- @Override
- public boolean isDefaultNamespace(String namespaceURI) {
- return xmlElementElement.isDefaultNamespace(namespaceURI);
- }
-
- @Override
- public String lookupNamespaceURI(String prefix) {
- return xmlElementElement.lookupNamespaceURI(prefix);
- }
-
- @Override
- public boolean isEqualNode(Node arg) {
- return xmlElementElement.isEqualNode(arg);
- }
-
- @Override
- public Object getFeature(String feature, String version) {
- return xmlElementElement.getFeature(feature, version);
- }
-
- @Override
- public Object setUserData(String key, Object data, UserDataHandler handler) {
- return xmlElementElement.setUserData(key, data, handler);
- }
-
- @Override
- public Object getUserData(String key) {
- return xmlElementElement.getUserData(key);
- }
-
- @Override
- public String getTagName() {
- return xmlElementElement.getTagName();
- }
-
- @Override
- public String getAttribute(String name) {
- return xmlElementElement.getAttribute(name);
- }
-
- @Override
- public void setAttribute(String name, String value) throws DOMException {
- xmlElementElement.setAttribute(name, value);
- }
-
- @Override
- public void removeAttribute(String name) throws DOMException {
- xmlElementElement.removeAttribute(name);
- }
-
- @Override
- public Attr getAttributeNode(String name) {
- return xmlElementElement.getAttributeNode(name);
- }
-
- @Override
- public Attr setAttributeNode(Attr newAttr) throws DOMException {
- return xmlElementElement.setAttributeNode(newAttr);
- }
-
- @Override
- public Attr removeAttributeNode(Attr oldAttr) throws DOMException {
- return xmlElementElement.removeAttributeNode(oldAttr);
- }
-
- @Override
- public NodeList getElementsByTagName(String name) {
- return xmlElementElement.getElementsByTagName(name);
- }
-
- @Override
- public String getAttributeNS(String namespaceURI, String localName) throws DOMException {
- return xmlElementElement.getAttributeNS(namespaceURI, localName);
- }
-
- @Override
- public void setAttributeNS(String namespaceURI, String qualifiedName, String value) throws DOMException {
- xmlElementElement.setAttributeNS(namespaceURI, qualifiedName, value);
- return;
- }
-
- @Override
- public void removeAttributeNS(String namespaceURI, String localName) throws DOMException {
- xmlElementElement.removeAttributeNS(namespaceURI, localName);
- }
-
- @Override
- public Attr getAttributeNodeNS(String namespaceURI, String localName) throws DOMException {
- return xmlElementElement.getAttributeNodeNS(namespaceURI, localName);
- }
-
- @Override
- public Attr setAttributeNodeNS(Attr newAttr) throws DOMException {
- return xmlElementElement.setAttributeNodeNS(newAttr);
- }
-
- @Override
- public NodeList getElementsByTagNameNS(String namespaceURI, String localName) throws DOMException {
- return xmlElementElement.getElementsByTagNameNS(namespaceURI, localName);
- }
-
- @Override
- public boolean hasAttribute(String name) {
- return xmlElementElement.hasAttribute(name);
- }
-
- @Override
- public boolean hasAttributeNS(String namespaceURI, String localName) throws DOMException {
- return xmlElementElement.hasAttributeNS(namespaceURI, localName);
- }
-
- @Override
- public TypeInfo getSchemaTypeInfo() {
- return xmlElementElement.getSchemaTypeInfo();
- }
-
- @Override
- public void setIdAttribute(String name, boolean isId) throws DOMException {
- xmlElementElement.setIdAttribute(name, isId);
-
- }
-
- @Override
- public void setIdAttributeNS(String namespaceURI, String localName, boolean isId) throws DOMException {
- xmlElementElement.setIdAttributeNS(namespaceURI, localName, isId);
- }
-
- @Override
- public void setIdAttributeNode(Attr idAttr, boolean isId) throws DOMException {
- xmlElementElement.setIdAttributeNode(idAttr, isId);
- return;
- }
-
-
-} \ No newline at end of file
+ }
+
+ public String getHTMLElementWrapper(String unwrappedElement, SchemaVersion v,
+ boolean useAnnotation) {
+
+ NodeList childNodes = this.getElementsByTagName("xml-element-wrapper");
+
+ String xmlElementWrapper = null;
+ if (childNodes.getLength() > 0) {
+ Element childElement = (Element) childNodes.item(0);
+ // get name
+ xmlElementWrapper = childElement == null ? null : childElement.getAttribute("name");
+ }
+ if (xmlElementWrapper == null) {
+ return unwrappedElement;
+ }
+
+ StringBuilder sbElement = new StringBuilder();
+ sbElement.append(" <xs:element name=\"").append(xmlElementWrapper).append("\"");
+ String elementType = xmlElementElement.getAttribute("type");
+ String elementIsRequired = this.getAttribute("required");
+ String addType = elementType.contains("." + v.toString() + ".") ?
+ elementType.substring(elementType.lastIndexOf('.') + 1) : null;
+
+ if (elementIsRequired == null || !elementIsRequired.equals("true") || addType != null) {
+ sbElement.append(" minOccurs=\"0\"");
+ }
+ sbElement.append(">").append(OxmFileProcessor.LINE_SEPARATOR);
+ sbElement.append(" <xs:complexType>").append(OxmFileProcessor.LINE_SEPARATOR);
+ if (useAnnotation) {
+ XSDElement javaTypeElement = new XSDElement((Element) this.getParentNode(), maxOccurs);
+ sbElement.append(javaTypeElement.getHTMLAnnotation("class", " "));
+ }
+ sbElement.append(" <xs:sequence>").append(OxmFileProcessor.LINE_SEPARATOR);
+ sbElement.append(" ");
+ sbElement.append(unwrappedElement);
+ sbElement.append(" </xs:sequence>").append(OxmFileProcessor.LINE_SEPARATOR);
+ sbElement.append(" </xs:complexType>").append(OxmFileProcessor.LINE_SEPARATOR);
+ sbElement.append(" </xs:element>").append(OxmFileProcessor.LINE_SEPARATOR);
+ return sbElement.toString();
+ }
+
+ public String getHTMLAnnotation(String target, String indentation) {
+ StringBuilder sb = new StringBuilder();
+ List<String> metadata = new ArrayList<>();
+ if ("true".equals(this.getAttribute("xml-key"))) {
+ metadata.add("isKey=true");
+ }
+
+ NodeList xmlPropTags = this.getElementsByTagName("xml-properties");
+ Element xmlPropElement = null;
+ for (int i = 0; i < xmlPropTags.getLength(); ++i) {
+ xmlPropElement = (Element) xmlPropTags.item(i);
+ if (xmlPropElement.getParentNode().getAttributes().getNamedItem("name").getNodeValue()
+ .equals(this.xmlElementElement.getAttribute("name"))) {
+ break;
+ }
+ }
+ if (xmlPropElement != null) {
+ NodeList xmlProperties = xmlPropElement.getElementsByTagName("xml-property");
+ for (int i = 0; i < xmlProperties.getLength(); i++) {
+ Element item = (Element) xmlProperties.item(i);
+ String name = item.getAttribute("name");
+ String value = item.getAttribute("value");
+ if (name.equals("abstract")) {
+ name = "isAbstract";
+ } else if (name.equals("extends")) {
+ name = "extendsFrom";
+ }
+ metadata.add(name + "=\"" + value.replaceAll("&", "&amp;") + "\"");
+ }
+ }
+ if (metadata.size() == 0) {
+ return "";
+ }
+ sb.append(indentation).append("<xs:annotation>").append(OxmFileProcessor.LINE_SEPARATOR);
+ sb.append(indentation).append(" <xs:appinfo>").append(OxmFileProcessor.LINE_SEPARATOR)
+ .append(indentation).append(" <annox:annotate target=\"").append(target)
+ .append("\">@org.onap.aai.annotations.Metadata(").append(Joiner.on(",").join(metadata))
+ .append(")</annox:annotate>").append(OxmFileProcessor.LINE_SEPARATOR)
+ .append(indentation).append(" </xs:appinfo>").append(OxmFileProcessor.LINE_SEPARATOR);
+ sb.append(indentation).append("</xs:annotation>").append(OxmFileProcessor.LINE_SEPARATOR);
+ return sb.toString();
+ }
+
+ public String getTypePropertyYAML(boolean isDslStartNode) {
+ StringBuilder sbProperties = new StringBuilder();
+ sbProperties.append(" ").append(this.getAttribute("name")).append(":\n");
+ sbProperties.append(" type: ");
+
+ if (("java.lang.String").equals(this.getAttribute("type"))) {
+ sbProperties.append("string\n");
+ } else if (("java.lang.Long").equals(this.getAttribute("type"))) {
+ sbProperties.append("integer\n");
+ sbProperties.append(" format: int64\n");
+ } else if (("java.lang.Integer").equals(this.getAttribute("type"))) {
+ sbProperties.append("integer\n");
+ sbProperties.append(" format: int32\n");
+ } else if (("java.lang.Boolean").equals(this.getAttribute("type"))) {
+ sbProperties.append("boolean\n");
+ }
+ String attrDescription = this.getPathDescriptionProperty();
+ if (attrDescription != null && attrDescription.length() > 0) {
+ if (!isDslStartNode) {
+ sbProperties.append(" description: ").append(attrDescription).append("\n");
+ } else {
+ sbProperties.append(" description: |\n");
+ sbProperties.append(" ").append(attrDescription).append("\n");
+ sbProperties.append(
+ " *This property can be used as a filter to find the start node for a dsl query\n");
+ }
+ } else {
+ if (isDslStartNode) {
+ sbProperties.append(" description: |\n");
+ sbProperties.append(" \n");
+ sbProperties.append(
+ " *This property can be used as a filter to find the start node for a dsl query\n");
+ }
+ }
+ String elementAlsoRequiresProperty = this.getRequiresProperty();
+ if (StringUtils.isNotEmpty(elementAlsoRequiresProperty)) {
+ sbProperties.append(" also requires: ").append(elementAlsoRequiresProperty)
+ .append("\n");
+ }
+ return sbProperties.toString();
+ }
+
+ public boolean isStandardType() {
+ switch (this.getAttribute("type")) {
+ case "java.lang.String":
+ case "java.lang.Long":
+ case "java.lang.Integer":
+ case "java.lang.Boolean":
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public String getNodeName() {
+ return xmlElementElement.getNodeName();
+ }
+
+ @Override
+ public String getNodeValue() throws DOMException {
+ return xmlElementElement.getNodeValue();
+ }
+
+ @Override
+ public void setNodeValue(String nodeValue) throws DOMException {
+ xmlElementElement.setNodeValue(nodeValue);
+ }
+
+ @Override
+ public short getNodeType() {
+ return xmlElementElement.getNodeType();
+ }
+
+ @Override
+ public Node getParentNode() {
+ return xmlElementElement.getParentNode();
+ }
+
+ @Override
+ public NodeList getChildNodes() {
+ return xmlElementElement.getChildNodes();
+ }
+
+ @Override
+ public Node getFirstChild() {
+ return xmlElementElement.getFirstChild();
+ }
+
+ @Override
+ public Node getLastChild() {
+ return xmlElementElement.getLastChild();
+ }
+
+ @Override
+ public Node getPreviousSibling() {
+ return xmlElementElement.getPreviousSibling();
+ }
+
+ @Override
+ public Node getNextSibling() {
+ return xmlElementElement.getNextSibling();
+ }
+
+ @Override
+ public NamedNodeMap getAttributes() {
+ return xmlElementElement.getAttributes();
+ }
+
+ @Override
+ public Document getOwnerDocument() {
+ return xmlElementElement.getOwnerDocument();
+ }
+
+ @Override
+ public Node insertBefore(Node newChild, Node refChild) throws DOMException {
+ return xmlElementElement.insertBefore(newChild, refChild);
+ }
+
+ @Override
+ public Node replaceChild(Node newChild, Node oldChild) throws DOMException {
+ return xmlElementElement.replaceChild(newChild, oldChild);
+ }
+
+ @Override
+ public Node removeChild(Node oldChild) throws DOMException {
+ return xmlElementElement.removeChild(oldChild);
+ }
+
+ @Override
+ public Node appendChild(Node newChild) throws DOMException {
+ return xmlElementElement.appendChild(newChild);
+ }
+
+ @Override
+ public boolean hasChildNodes() {
+ return xmlElementElement.hasChildNodes();
+ }
+
+ @Override
+ public Node cloneNode(boolean deep) {
+ return xmlElementElement.cloneNode(deep);
+ }
+
+ @Override
+ public void normalize() {
+ xmlElementElement.normalize();
+ }
+
+ @Override
+ public boolean isSupported(String feature, String version) {
+ return xmlElementElement.isSupported(feature, version);
+ }
+
+ @Override
+ public String getNamespaceURI() {
+ return xmlElementElement.getNamespaceURI();
+ }
+
+ @Override
+ public String getPrefix() {
+ return xmlElementElement.getPrefix();
+ }
+
+ @Override
+ public void setPrefix(String prefix) throws DOMException {
+ xmlElementElement.setPrefix(prefix);
+ }
+
+ @Override
+ public String getLocalName() {
+
+ return xmlElementElement.getLocalName();
+ }
+
+ @Override
+ public boolean hasAttributes() {
+ return xmlElementElement.hasAttributes();
+ }
+
+ @Override
+ public String getBaseURI() {
+ return xmlElementElement.getBaseURI();
+ }
+
+ @Override
+ public short compareDocumentPosition(Node other) throws DOMException {
+ return xmlElementElement.compareDocumentPosition(other);
+ }
+
+ @Override
+ public String getTextContent() throws DOMException {
+ return xmlElementElement.getTextContent();
+ }
+
+ @Override
+ public void setTextContent(String textContent) throws DOMException {
+ xmlElementElement.setTextContent(textContent);
+ }
+
+ @Override
+ public boolean isSameNode(Node other) {
+ return xmlElementElement.isSameNode(other);
+ }
+
+ @Override
+ public String lookupPrefix(String namespaceURI) {
+ return xmlElementElement.lookupPrefix(namespaceURI);
+ }
+
+ @Override
+ public boolean isDefaultNamespace(String namespaceURI) {
+ return xmlElementElement.isDefaultNamespace(namespaceURI);
+ }
+
+ @Override
+ public String lookupNamespaceURI(String prefix) {
+ return xmlElementElement.lookupNamespaceURI(prefix);
+ }
+
+ @Override
+ public boolean isEqualNode(Node arg) {
+ return xmlElementElement.isEqualNode(arg);
+ }
+
+ @Override
+ public Object getFeature(String feature, String version) {
+ return xmlElementElement.getFeature(feature, version);
+ }
+
+ @Override
+ public Object setUserData(String key, Object data, UserDataHandler handler) {
+ return xmlElementElement.setUserData(key, data, handler);
+ }
+
+ @Override
+ public Object getUserData(String key) {
+ return xmlElementElement.getUserData(key);
+ }
+
+ @Override
+ public String getTagName() {
+ return xmlElementElement.getTagName();
+ }
+
+ @Override
+ public String getAttribute(String name) {
+ return xmlElementElement.getAttribute(name);
+ }
+
+ @Override
+ public void setAttribute(String name, String value) throws DOMException {
+ xmlElementElement.setAttribute(name, value);
+ }
+
+ @Override
+ public void removeAttribute(String name) throws DOMException {
+ xmlElementElement.removeAttribute(name);
+ }
+
+ @Override
+ public Attr getAttributeNode(String name) {
+ return xmlElementElement.getAttributeNode(name);
+ }
+
+ @Override
+ public Attr setAttributeNode(Attr newAttr) throws DOMException {
+ return xmlElementElement.setAttributeNode(newAttr);
+ }
+
+ @Override
+ public Attr removeAttributeNode(Attr oldAttr) throws DOMException {
+ return xmlElementElement.removeAttributeNode(oldAttr);
+ }
+
+ @Override
+ public NodeList getElementsByTagName(String name) {
+ return xmlElementElement.getElementsByTagName(name);
+ }
+
+ @Override
+ public String getAttributeNS(String namespaceURI, String localName) throws DOMException {
+ return xmlElementElement.getAttributeNS(namespaceURI, localName);
+ }
+
+ @Override
+ public void setAttributeNS(String namespaceURI, String qualifiedName, String value)
+ throws DOMException {
+ xmlElementElement.setAttributeNS(namespaceURI, qualifiedName, value);
+ }
+
+ @Override
+ public void removeAttributeNS(String namespaceURI, String localName) throws DOMException {
+ xmlElementElement.removeAttributeNS(namespaceURI, localName);
+ }
+
+ @Override
+ public Attr getAttributeNodeNS(String namespaceURI, String localName) throws DOMException {
+ return xmlElementElement.getAttributeNodeNS(namespaceURI, localName);
+ }
+
+ @Override
+ public Attr setAttributeNodeNS(Attr newAttr) throws DOMException {
+ return xmlElementElement.setAttributeNodeNS(newAttr);
+ }
+
+ @Override
+ public NodeList getElementsByTagNameNS(String namespaceURI, String localName)
+ throws DOMException {
+ return xmlElementElement.getElementsByTagNameNS(namespaceURI, localName);
+ }
+
+ @Override
+ public boolean hasAttribute(String name) {
+ return xmlElementElement.hasAttribute(name);
+ }
+
+ @Override
+ public boolean hasAttributeNS(String namespaceURI, String localName) throws DOMException {
+ return xmlElementElement.hasAttributeNS(namespaceURI, localName);
+ }
+
+ @Override
+ public TypeInfo getSchemaTypeInfo() {
+ return xmlElementElement.getSchemaTypeInfo();
+ }
+
+ @Override
+ public void setIdAttribute(String name, boolean isId) throws DOMException {
+ xmlElementElement.setIdAttribute(name, isId);
+
+ }
+
+ @Override
+ public void setIdAttributeNS(String namespaceURI, String localName, boolean isId)
+ throws DOMException {
+ xmlElementElement.setIdAttributeNS(namespaceURI, localName, isId);
+ }
+
+ @Override
+ public void setIdAttributeNode(Attr idAttr, boolean isId) throws DOMException {
+ xmlElementElement.setIdAttributeNode(idAttr, isId);
+ }
+
+
+}
diff --git a/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/XSDJavaType.java b/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/XSDJavaType.java
index 80ab79b..ee776b2 100644
--- a/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/XSDJavaType.java
+++ b/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/XSDJavaType.java
@@ -7,9 +7,9 @@
* 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
- *
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
* 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.
@@ -17,48 +17,50 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.schemagen.genxsd;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
public class XSDJavaType extends XSDElement {
- StringBuffer pathSb;
- StringBuffer definitionsSb;
- StringBuffer pathParams;
- public XSDJavaType(Element javaTypeElement) {
- super(javaTypeElement);
- }
-/*
- public XSDJavaType(XSDElement javaTypeElement, StringBuffer pathSb, StringBuffer definitionsSb,
- StringBuffer pathParams) {
- super(javaTypeElement);
- this.pathSb = pathSb;
- this.definitionsSb = definitionsSb;
- this.pathParams = pathParams;
- }
-*/
- public String getItemName() {
- NodeList parentNodes = this.getElementsByTagName("java-attributes");
- if(parentNodes.getLength() == 0)
- return null;
- Element parentElement = (Element)parentNodes.item(0);
- NodeList xmlElementNodes = parentElement.getElementsByTagName("xml-element");
- XSDElement xmlElementElement = new XSDElement((Element)xmlElementNodes.item(0));
- return xmlElementElement.getAttribute("name");
- }
+ public XSDJavaType(Element javaTypeElement) {
+ super(javaTypeElement);
+ }
+
+ /*
+ public XSDJavaType(XSDElement javaTypeElement, StringBuffer pathSb, StringBuffer definitionsSb,
+ StringBuffer pathParams) {
+ super(javaTypeElement);
+ this.pathSb = pathSb;
+ this.definitionsSb = definitionsSb;
+ this.pathParams = pathParams;
+ }
+ */
+ public String getItemName() {
+ NodeList parentNodes = this.getElementsByTagName("java-attributes");
+ if (parentNodes.getLength() == 0) {
+ return null;
+ }
+ Element parentElement = (Element) parentNodes.item(0);
+ NodeList xmlElementNodes = parentElement.getElementsByTagName("xml-element");
+ XSDElement xmlElementElement = new XSDElement((Element) xmlElementNodes.item(0));
+ return xmlElementElement.getAttribute("name");
+ }
- public String getArrayType() {
- NodeList parentNodes = this.getElementsByTagName("java-attributes");
- if(parentNodes.getLength() == 0)
- return null;
- Element parentElement = (Element)parentNodes.item(0);
- NodeList xmlElementNodes = parentElement.getElementsByTagName("xml-element");
- XSDElement xmlElementElement = new XSDElement((Element)xmlElementNodes.item(0));
- if ( xmlElementElement.hasAttribute("container-type") && xmlElementElement.getAttribute("container-type").equals("java.util.ArrayList")) {
- return xmlElementElement.getAttribute("name");
- }
- return null;
- }
+ public String getArrayType() {
+ NodeList parentNodes = this.getElementsByTagName("java-attributes");
+ if (parentNodes.getLength() == 0) {
+ return null;
+ }
+ Element parentElement = (Element) parentNodes.item(0);
+ NodeList xmlElementNodes = parentElement.getElementsByTagName("xml-element");
+ XSDElement xmlElementElement = new XSDElement((Element) xmlElementNodes.item(0));
+ if (xmlElementElement.hasAttribute("container-type") &&
+ xmlElementElement.getAttribute("container-type").equals("java.util.ArrayList")) {
+ return xmlElementElement.getAttribute("name");
+ }
+ return null;
+ }
}
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 0ec95e9..849b40c 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
@@ -7,9 +7,9 @@
* 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
- *
+ * <p>
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ * <p>
* 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.
@@ -17,9 +17,30 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.schemagen.genxsd;
+import com.google.common.base.CharMatcher;
import com.google.common.collect.Multimap;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.HashMap;
+import java.util.LinkedHashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.StringTokenizer;
+import java.util.TreeMap;
+import java.util.TreeSet;
+import java.util.Vector;
+import javax.xml.parsers.ParserConfigurationException;
import org.apache.commons.lang3.StringUtils;
import org.onap.aai.edges.EdgeIngestor;
import org.onap.aai.edges.EdgeRule;
@@ -34,17 +55,6 @@ import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
-import javax.xml.parsers.ParserConfigurationException;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.nio.charset.Charset;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.*;
-
public class YAMLfromOXM extends OxmFileProcessor {
private static final Logger logger = LoggerFactory.getLogger("YAMLfromOXM.class");
// private static StringBuffer totalPathSbAccumulator = new StringBuffer();
@@ -61,7 +71,7 @@ public class YAMLfromOXM extends OxmFileProcessor {
private String basePath;
public YAMLfromOXM(String basePath, SchemaVersions schemaVersions, NodeIngestor ni,
- EdgeIngestor ei) {
+ EdgeIngestor ei) {
super(schemaVersions, ni, ei);
this.basePath = basePath;
}
@@ -80,26 +90,38 @@ public class YAMLfromOXM extends OxmFileProcessor {
@Override
public String getDocumentHeader() {
- StringBuffer sb = new StringBuffer();
- sb.append("swagger: \"2.0\"\ninfo:" + LINE_SEPARATOR + " ");
+ StringBuilder sb = new StringBuilder();
+ sb.append("swagger: \"2.0\"\ninfo:").append(LINE_SEPARATOR).append(" ");
sb.append("description: |");
if (versionSupportsSwaggerDiff(v.toString())) {
sb.append("\n\n [Differences versus the previous schema version]("
- + "apidocs" + basePath + "/aai_swagger_" + v.toString() + ".diff)");
+ + "apidocs" + basePath + "/aai_swagger_" + v.toString() + ".diff)");
}
+ sb.append(DOUBLE_LINE_SEPARATOR).append(
+ " Copyright &copy; 2017-18 AT&amp;T Intellectual Property. All rights reserved.")
+ .append(OxmFileProcessor.DOUBLE_LINE_SEPARATOR).append(
+ " Licensed under the Creative Commons License, Attribution 4.0 Intl. (the &quot;License&quot;); you may not use this documentation except in compliance with the License.")
+ .append(DOUBLE_LINE_SEPARATOR).append(
+ " You may obtain a copy of the License at\n\n (https://creativecommons.org/licenses/by/4.0/)")
+ .append(DOUBLE_LINE_SEPARATOR).append(
+ " Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an &quot;AS IS&quot; 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.")
+ .append(OxmFileProcessor.DOUBLE_LINE_SEPARATOR)
+ .append(" This document is best viewed with Firefox or Chrome. ");
sb.append(
- DOUBLE_LINE_SEPARATOR + " Copyright &copy; 2017-18 AT&amp;T Intellectual Property. All rights reserved." + OxmFileProcessor.DOUBLE_LINE_SEPARATOR + " Licensed under the Creative Commons License, Attribution 4.0 Intl. (the &quot;License&quot;); you may not use this documentation except in compliance with the License." + DOUBLE_LINE_SEPARATOR + " You may obtain a copy of the License at\n\n (https://creativecommons.org/licenses/by/4.0/)" + DOUBLE_LINE_SEPARATOR + " Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an &quot;AS IS&quot; 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." + OxmFileProcessor.DOUBLE_LINE_SEPARATOR + " This document is best viewed with Firefox or Chrome. ");
- sb.append(
- "Nodes can be found by opening the models link below and finding the node-type. ");
- sb.append(
- "Edge definitions can be found with the node definitions." + LINE_SEPARATOR + " version: \""
- + v.toString() + "\"" + LINE_SEPARATOR );
- sb.append(" title: Active and Available Inventory REST API" + LINE_SEPARATOR);
- sb.append(
- " license:" + LINE_SEPARATOR + " name: Apache 2.0\n url: http://www.apache.org/licenses/LICENSE-2.0.html" + LINE_SEPARATOR);
- sb.append(" contact:" + LINE_SEPARATOR + " name: n/a" + LINE_SEPARATOR + " url: n/a" + LINE_SEPARATOR + " email: n/a" + LINE_SEPARATOR);
- sb.append("host: n/a" + LINE_SEPARATOR + "basePath: " + basePath + "/" + v.toString() + LINE_SEPARATOR);
- sb.append("schemes:" + LINE_SEPARATOR + " - https\npaths:" + LINE_SEPARATOR);
+ "Nodes can be found by opening the models link below and finding the node-type. ");
+ sb.append("Edge definitions can be found with the node definitions.").append(LINE_SEPARATOR)
+ .append(" version: \"").append(v.toString()).append("\"").append(LINE_SEPARATOR);
+ sb.append(" title: Active and Available Inventory REST API").append(LINE_SEPARATOR);
+ sb.append(" license:").append(LINE_SEPARATOR).append(
+ " name: Apache 2.0\n url: http://www.apache.org/licenses/LICENSE-2.0.html")
+ .append(LINE_SEPARATOR);
+ sb.append(" contact:").append(LINE_SEPARATOR).append(" name: n/a")
+ .append(LINE_SEPARATOR).append(" url: n/a").append(LINE_SEPARATOR)
+ .append(" email: n/a").append(LINE_SEPARATOR);
+ sb.append("host: n/a").append(LINE_SEPARATOR).append("basePath: ").append(basePath)
+ .append("/").append(v.toString()).append(LINE_SEPARATOR);
+ sb.append("schemes:").append(LINE_SEPARATOR).append(" - https\npaths:")
+ .append(LINE_SEPARATOR);
return sb.toString();
}
@@ -111,8 +133,8 @@ public class YAMLfromOXM extends OxmFileProcessor {
@Override
public String process() throws ParserConfigurationException, SAXException, IOException,
FileNotFoundException, EdgeRuleNotFoundException {
- StringBuffer sb = new StringBuffer();
- StringBuffer pathSb = new StringBuffer();
+ StringBuilder sb = new StringBuilder();
+ StringBuilder pathSb = new StringBuilder();
try {
init();
} catch (Exception e) {
@@ -120,7 +142,7 @@ public class YAMLfromOXM extends OxmFileProcessor {
throw e;
}
pathSb.append(getDocumentHeader());
- StringBuffer definitionsSb = new StringBuffer();
+ StringBuilder definitionsSb = new StringBuilder();
Element elem;
String javaTypeName;
combinedJavaTypes = new HashMap();
@@ -170,7 +192,7 @@ public class YAMLfromOXM extends OxmFileProcessor {
if (inventoryDefSb != null) {
javaTypeDefinitions.put("inventory", inventoryDefSb.toString());
}
- StringBuffer sb = new StringBuffer("definitions:\n");
+ StringBuilder sb = new StringBuilder("definitions:\n");
Map<String, String> sortedJavaTypeDefinitions =
new TreeMap<String, String>(javaTypeDefinitions);
for (Map.Entry<String, String> entry : sortedJavaTypeDefinitions.entrySet()) {
@@ -184,14 +206,14 @@ public class YAMLfromOXM extends OxmFileProcessor {
continue;
}
logger.debug(
- "Key: " + entry.getKey() + "Test: " + (entry.getKey() == "relationship-dict"));
+ "Key: " + entry.getKey() + "Test: " + ("relationship-dict".equals(entry.getKey())));
if (entry.getKey().matches("relationship-dict")) {
String jb = entry.getValue();
logger.debug("Value: " + jb);
int ndx = jb.indexOf("related-to-property:");
if (ndx > 0) {
jb = jb.substring(0, ndx);
- jb = jb.replaceAll(" +$", "");
+ jb = StringUtils.stripEnd(jb, " ");
}
logger.debug("Value-after: " + jb);
sb.append(jb);
@@ -203,22 +225,23 @@ public class YAMLfromOXM extends OxmFileProcessor {
}
private String getDictionary(String resource) {
- StringBuffer dictSb = new StringBuffer();
- dictSb.append(" " + resource + ":\n");
+ StringBuilder dictSb = new StringBuilder();
+ dictSb.append(" ").append(resource).append(":\n");
dictSb.append(" description: |\n");
- dictSb.append(" dictionary of " + resource + "\n");
+ dictSb.append(" dictionary of ").append(resource).append("\n");
dictSb.append(" type: object\n");
dictSb.append(" properties:\n");
- dictSb.append(" " + resource + ":\n");
+ dictSb.append(" ").append(resource).append(":\n");
dictSb.append(" type: array\n");
dictSb.append(" items:\n");
- dictSb.append(" $ref: \"#/definitions/" + resource + "-dict\"\n");
+ dictSb.append(" $ref: \"#/definitions/").append(resource).append("-dict\"\n");
return dictSb.toString();
}
- private String processJavaTypeElementSwagger(String javaTypeName, Element javaTypeElement,
- StringBuffer pathSb, StringBuffer definitionsSb, String path, String tag, String opId,
- String getItemName, StringBuffer pathParams, String validEdges) {
+ private String processJavaTypeElementSwagger(
+ String javaTypeName, Element javaTypeElement, StringBuilder pathSb,
+ StringBuilder definitionsSb, String path, String tag, String opId,
+ String getItemName, StringBuilder pathParams, String validEdges) {
String xmlRootElementName = getXMLRootElementName(javaTypeElement);
StringBuilder definitionsLocalSb = new StringBuilder(256);
@@ -228,15 +251,15 @@ public class YAMLfromOXM extends OxmFileProcessor {
String useOpId = null;
logger.debug("tag=" + tag);
if (tag != null) {
- // set ignore to true to skip Actions and Search
+ // set ignore to true to skip Actions and Search
boolean topCheck = checkTopLevel(tag, true);
if (!topCheck) {
return null;
}
}
- if (!javaTypeName.equals("Inventory")) {
- if (javaTypeName.equals("AaiInternal")) {
+ if (!"Inventory".equals(javaTypeName)) {
+ if ("AaiInternal".equals(javaTypeName)) {
return null;
}
if (opId == null) {
@@ -248,11 +271,11 @@ public class YAMLfromOXM extends OxmFileProcessor {
useTag = javaTypeName;
}
}
- path = xmlRootElementName.equals("inventory") ? ""
+ path = "inventory".equals(xmlRootElementName) ? ""
: (path == null) ? "/" + xmlRootElementName : path + "/" + xmlRootElementName;
XSDJavaType javaType = new XSDJavaType(javaTypeElement);
if (getItemName != null) {
- if (getItemName.equals("array")) {
+ if ("array".equals(getItemName)) {
return javaType.getArrayType();
} else {
return javaType.getItemName();
@@ -278,15 +301,16 @@ public class YAMLfromOXM extends OxmFileProcessor {
Element parentElement = (Element) parentNodes.item(0);
NodeList xmlElementNodes = parentElement.getElementsByTagName("xml-element");
- StringBuffer sbParameters = new StringBuffer();
- StringBuffer sbPathParameters = new StringBuffer(); // separate naming path parameters from name of parameter in the schema
- StringBuffer sbRequired = new StringBuffer();
-
+ StringBuilder sbParameters = new StringBuilder();
+ StringBuilder sbPathParameters =
+ new StringBuilder(); // separate naming path parameters from name of parameter in the schema
+ StringBuilder sbRequired = new StringBuilder();
+
int requiredCnt = 0;
int propertyCnt = 0;
- StringBuffer sbProperties = new StringBuffer();
+ StringBuilder sbProperties = new StringBuilder();
int patchPropertyCnt = 0; // manage payload properties separately for patch
- StringBuffer sbPropertiesPatch = new StringBuffer();
+ StringBuilder sbPropertiesPatch = new StringBuilder();
if (appliedPaths.containsKey(path)) {
return null;
@@ -299,7 +323,7 @@ public class YAMLfromOXM extends OxmFileProcessor {
+ appliedPaths.containsKey(path));
appliedPaths.put(path, xmlRootElementName);
}
-
+
Vector<String> addTypeV = null;
String modifiedName;
String replaceDescription;
@@ -312,12 +336,13 @@ public class YAMLfromOXM extends OxmFileProcessor {
if (getItemName == null) {
addTypeV = xmlElementElement.getAddTypes(v.toString());
}
- // use alternate name for parameter if already in the path string
+ // use alternate name for parameter if already in the path string
modifiedName = "/{" + xmlElementElement.getAttribute("name") + "}";
- if ( path.contains(modifiedName)) {
- modifiedName = path.substring(path.lastIndexOf('/')+1) + "." + xmlElementElement.getAttribute("name");
+ if (path.contains(modifiedName)) {
+ modifiedName = path.substring(path.lastIndexOf('/') + 1) + "." +
+ xmlElementElement.getAttribute("name");
} else {
- modifiedName = xmlElementElement.getAttribute("name");
+ modifiedName = xmlElementElement.getAttribute("name");
}
if ("true".equals(xmlElementElement.getAttribute("xml-key"))) {
path += "/{" + modifiedName + "}";
@@ -328,19 +353,21 @@ public class YAMLfromOXM extends OxmFileProcessor {
if ("true".equals(xmlElementElement.getAttribute("xml-key"))) {
sbParameters.append(xmlElementElement.getPathParamYAML(elementDescription));
- sbPathParameters.append(xmlElementElement.getPathParamYAML(elementDescription, modifiedName));
+ sbPathParameters
+ .append(xmlElementElement.getPathParamYAML(elementDescription, modifiedName));
}
- if (("true").equals(xmlElementElement.getAttribute("required"))) {
+ if ("true".equals(xmlElementElement.getAttribute("required"))) {
if (requiredCnt == 0) {
sbRequired.append(" required:\n");
}
++requiredCnt;
if (addTypeV == null || addTypeV.isEmpty()) {
- sbRequired.append(" - " + xmlElementElement.getAttribute("name") + "\n");
+ sbRequired.append(" - ").append(xmlElementElement.getAttribute("name"))
+ .append("\n");
} else {
for (int k = 0; k < addTypeV.size(); ++k) {
- sbRequired.append(
- " - " + getXmlRootElementName(addTypeV.elementAt(k)) + ":\n");
+ sbRequired.append(" - ")
+ .append(getXmlRootElementName(addTypeV.elementAt(k))).append(":\n");
}
}
}
@@ -350,16 +377,17 @@ public class YAMLfromOXM extends OxmFileProcessor {
GetOperation.addContainerProps(container, containerProps);
}
if (xmlElementElement.isStandardType()) {
- boolean isDslStartNode = dslStartNodeProps.contains(xmlElementElement.getAttribute("name"));
+ boolean isDslStartNode =
+ dslStartNodeProps.contains(xmlElementElement.getAttribute("name"));
sbProperties.append(xmlElementElement.getTypePropertyYAML(isDslStartNode));
- if ( !"resource-version".equals(xmlElementElement.getAttribute("name"))) {
- sbPropertiesPatch.append(xmlElementElement.getTypePropertyYAML(isDslStartNode));
- ++patchPropertyCnt;
+ if (!"resource-version".equals(xmlElementElement.getAttribute("name"))) {
+ sbPropertiesPatch.append(xmlElementElement.getTypePropertyYAML(isDslStartNode));
+ ++patchPropertyCnt;
}
++propertyCnt;
}
- StringBuffer newPathParams = new StringBuffer(
+ StringBuilder newPathParams = new StringBuilder(
(pathParams == null ? "" : pathParams.toString()) + sbPathParameters.toString());
String useName;
for (int k = 0; addTypeV != null && k < addTypeV.size(); ++k) {
@@ -383,27 +411,31 @@ public class YAMLfromOXM extends OxmFileProcessor {
} else if (getItemName == null) {
++propertyCnt;
- sbProperties.append(" " + getXmlRootElementName(addType) + ":\n");
- if ( "RelationshipList".equals(addType)) {
+ sbProperties.append(" ").append(getXmlRootElementName(addType))
+ .append(":\n");
+ if ("RelationshipList".equals(addType)) {
sbProperties.append(" type: object\n");
- sbProperties.append(" $ref: \"#/definitions/"
- + itemName + "\"\n");
- sbPropertiesPatch.append(" " + getXmlRootElementName(addType) + ":\n");
+ sbProperties.append(" $ref: \"#/definitions/").append(itemName)
+ .append("\"\n");
+ sbPropertiesPatch.append(" ")
+ .append(getXmlRootElementName(addType)).append(":\n");
sbPropertiesPatch.append(" type: object\n");
- sbPropertiesPatch.append(" $ref: \"#/definitions/"
- + itemName + "\"\n");
+ sbPropertiesPatch.append(" $ref: \"#/definitions/")
+ .append(itemName).append("\"\n");
++patchPropertyCnt;
} else {
- if ( "relationship".equals(itemName) ) {
- System.out.println(v + "-relationship added as array for getItemName null");
- }
- sbProperties.append(" type: array\n items:\n");
- sbProperties.append(" $ref: \"#/definitions/"
- + (itemName == "" ? "inventory-item-data" : itemName) + "\"\n");
+ if ("relationship".equals(itemName)) {
+ System.out.println(
+ v + "-relationship added as array for getItemName null");
+ }
+ sbProperties.append(" type: array\n items:\n");
+ sbProperties.append(" $ref: \"#/definitions/")
+ .append("".equals(itemName) ? "inventory-item-data" : itemName)
+ .append("\"\n");
}
if (StringUtils.isNotEmpty(elementDescription)) {
- sbProperties
- .append(" description: " + elementDescription + "\n");
+ sbProperties.append(" description: ").append(elementDescription)
+ .append("\n");
}
}
} else {
@@ -412,42 +444,43 @@ public class YAMLfromOXM extends OxmFileProcessor {
// need properties for getXmlRootElementName(addType)
namespaceFilter.add(getXmlRootElementName(addType));
newPathParams =
- new StringBuffer((pathParams == null ? "" : pathParams.toString())
- + sbParameters.toString());
+ new StringBuilder((pathParams == null ? "" : pathParams.toString())
+ + sbParameters);
processJavaTypeElementSwagger(addType, getJavaTypeElementSwagger(addType),
pathSb, definitionsSb, path, tag == null ? useTag : tag, useOpId, null,
newPathParams, validEdges);
useName = getXmlRootElementName(addType);
- sbProperties.append(" " + useName + ":\n");
- if ( "relationship".equals(useName)) {
+ sbProperties.append(" ").append(useName).append(":\n");
+ if ("relationship".equals(useName)) {
sbProperties.append(" type: object\n");
sbProperties.append(" $ref: \"#/definitions/relationship\"\n");
sbPropertiesPatch.append(" type: object\n");
- sbPropertiesPatch.append(" $ref: \"#/definitions/relationship\"\n");
+ sbPropertiesPatch
+ .append(" $ref: \"#/definitions/relationship\"\n");
++patchPropertyCnt;
} else {
- sbProperties.append(" type: array\n items: \n");
- sbProperties.append(" $ref: \"#/definitions/"
- + getXmlRootElementName(addType) + "\"\n");
- if (StringUtils.isNotEmpty(elementDescription)) {
- sbProperties
- .append(" description: " + elementDescription + "\n");
- }
+ sbProperties.append(" type: array\n items: \n");
+ sbProperties.append(" $ref: \"#/definitions/"
+ + getXmlRootElementName(addType) + "\"\n");
+ if (StringUtils.isNotEmpty(elementDescription)) {
+ sbProperties.append(" description: ")
+ .append(elementDescription).append("\n");
+ }
}
} else {
// Make sure certain types added to the filter don't appear
- if (nodeFilter.contains(getXmlRootElementName(addType))) {
- ;
- } else {
- sbProperties.append(" " + getXmlRootElementName(addType) + ":\n");
+ if (!nodeFilter.contains(getXmlRootElementName(addType))) {
+ sbProperties.append(" ").append(getXmlRootElementName(addType))
+ .append(":\n");
sbProperties.append(" type: object\n");
- sbProperties.append(" $ref: \"#/definitions/"
- + getXmlRootElementName(addType) + "\"\n");
+ sbProperties.append(" $ref: \"#/definitions/")
+ .append(getXmlRootElementName(addType)).append("\"\n");
}
}
if (StringUtils.isNotEmpty(elementDescription)) {
- sbProperties.append(" description: " + elementDescription + "\n");
+ sbProperties.append(" description: ").append(elementDescription)
+ .append("\n");
}
++propertyCnt;
}
@@ -456,27 +489,27 @@ public class YAMLfromOXM extends OxmFileProcessor {
if (sbParameters.toString().length() > 0) {
if (pathParams == null) {
- pathParams = new StringBuffer();
+ pathParams = new StringBuilder();
}
pathParams.append(sbPathParameters);
}
GetOperation get = new GetOperation(useOpId, xmlRootElementName, tag, path,
pathParams == null ? "" : pathParams.toString());
- pathSb.append(get.toString());
+ pathSb.append(get);
logger.debug("opId vs useOpId:" + opId + " vs " + useOpId + " PathParams=" + pathParams);
// add PUT
PutOperation put = new PutOperation(useOpId, xmlRootElementName, tag, path,
pathParams == null ? "" : pathParams.toString(), this.v, this.basePath);
- pathSb.append(put.toString());
+ pathSb.append(put);
// add PATCH
PatchOperation patch = new PatchOperation(useOpId, xmlRootElementName, tag, path,
pathParams == null ? "" : pathParams.toString(), this.v, this.basePath);
patch.setPrefixForPatchRef(patchDefinePrefix);
- pathSb.append(patch.toString());
+ pathSb.append(patch);
// add DELETE
DeleteOperation del = new DeleteOperation(useOpId, xmlRootElementName, tag, path,
pathParams == null ? "" : pathParams.toString());
- pathSb.append(del.toString());
+ pathSb.append(del);
if (generatedJavaType.containsKey(xmlRootElementName)) {
logger.debug("xmlRootElementName(1)=" + xmlRootElementName);
return null;
@@ -489,8 +522,8 @@ public class YAMLfromOXM extends OxmFileProcessor {
processingInventoryDef = true;
if (inventoryDefSb == null) {
inventoryDefSb = new StringBuilder();
- definitionsSb.append(" " + xmlRootElementName + ":\n");
- definitionsLocalSb.append(" " + xmlRootElementName + ":\n");
+ definitionsSb.append(" ").append(xmlRootElementName).append(":\n");
+ definitionsLocalSb.append(" ").append(xmlRootElementName).append(":\n");
definitionsLocalSb.append(" properties:\n");
}
} else if (xmlRootElementName.equals("relationship")) {
@@ -498,15 +531,15 @@ public class YAMLfromOXM extends OxmFileProcessor {
definitionsLocalSb.append(" " + "relationship-dict" + ":\n");
dict = getDictionary(xmlRootElementName);
} else {
- definitionsSb.append(" " + xmlRootElementName + ":\n");
- definitionsLocalSb.append(" " + xmlRootElementName + ":\n");
+ definitionsSb.append(" ").append(xmlRootElementName).append(":\n");
+ definitionsLocalSb.append(" ").append(xmlRootElementName).append(":\n");
}
// Collection<EdgeDescription> edges = edgeRuleSet.getEdgeRules(xmlRootElementName );
DeleteFootnoteSet footnotes = new DeleteFootnoteSet(xmlRootElementName);
- StringBuffer sbEdge = new StringBuffer();
+ StringBuilder sbEdge = new StringBuilder();
LinkedHashSet<String> preventDelete = new LinkedHashSet<String>();
String prevent = null;
- String nodeCaption = new String(" ###### Related Nodes\n");
+ String nodeCaption = " ###### Related Nodes\n";
try {
EdgeRuleQuery q =
new EdgeRuleQuery.Builder(xmlRootElementName).version(v).fromOnly().build();
@@ -518,17 +551,17 @@ public class YAMLfromOXM extends OxmFileProcessor {
results.get(key).stream()
.filter((i) -> (i.getFrom().equals(xmlRootElementName) && (!i.isPrivateEdge())))
.forEach((i) -> {
- logger.info(new String(new StringBuffer(" - TO ").append(i.getTo())
+ logger.info(new String(new StringBuilder(" - TO ").append(i.getTo())
.append(i.getDirection().toString()).append(i.getContains())));
});
results.get(key).stream()
.filter((i) -> (i.getFrom().equals(xmlRootElementName) && (!i.isPrivateEdge())))
.forEach((i) -> {
- sbEdge.append(" - TO " + i.getTo());
+ sbEdge.append(" - TO ").append(i.getTo());
EdgeDescription ed = new EdgeDescription(i);
String footnote = ed.getAlsoDeleteFootnote(xmlRootElementName);
- sbEdge.append(ed.getRelationshipDescription("TO", xmlRootElementName)
- + footnote + "\n");
+ sbEdge.append(ed.getRelationshipDescription("TO", xmlRootElementName))
+ .append(footnote).append("\n");
if (StringUtils.isNotEmpty(footnote)) {
footnotes.add(footnote);
}
@@ -553,11 +586,11 @@ public class YAMLfromOXM extends OxmFileProcessor {
results.get(key).stream()
.filter((i) -> (i.getTo().equals(xmlRootElementName) && (!i.isPrivateEdge())))
.forEach((i) -> {
- sbEdge.append(" - FROM " + i.getFrom());
+ sbEdge.append(" - FROM ").append(i.getFrom());
EdgeDescription ed = new EdgeDescription(i);
String footnote = ed.getAlsoDeleteFootnote(xmlRootElementName);
- sbEdge.append(ed.getRelationshipDescription("FROM", xmlRootElementName)
- + footnote + "\n");
+ sbEdge.append(ed.getRelationshipDescription("FROM", xmlRootElementName))
+ .append(footnote).append("\n");
if (StringUtils.isNotEmpty(footnote)) {
footnotes.add(footnote);
}
@@ -565,8 +598,9 @@ public class YAMLfromOXM extends OxmFileProcessor {
results.get(key).stream()
.filter((i) -> (i.getTo().equals(xmlRootElementName) && (!i.isPrivateEdge())))
.forEach((i) -> {
- logger.info(new String(new StringBuffer(" - FROM ").append(i.getFrom())
- .append(i.getDirection().toString()).append(i.getContains())));
+ logger
+ .info(new String(new StringBuilder(" - FROM ").append(i.getFrom())
+ .append(i.getDirection().toString()).append(i.getContains())));
});
results.get(key).stream()
.filter((i) -> (i.getTo().equals(xmlRootElementName)
@@ -599,25 +633,28 @@ public class YAMLfromOXM extends OxmFileProcessor {
definitionsLocalSb.append(" description: |\n");
if (pathDescriptionProperty != null) {
- definitionsSb.append(" " + pathDescriptionProperty + "\n");
- definitionsLocalSb.append(" " + pathDescriptionProperty + "\n");
+ definitionsSb.append(" ").append(pathDescriptionProperty).append("\n");
+ definitionsLocalSb.append(" ").append(pathDescriptionProperty).append("\n");
}
- if (StringUtils.isNotEmpty(validEdges) ) {
- definitionsSb.append(validEdges);
- definitionsLocalSb.append(validEdges);
+ if (StringUtils.isNotEmpty(validEdges)) {
+ definitionsSb.append(validEdges);
+ definitionsLocalSb.append(validEdges);
}
}
- if ( patchPropertyCnt > 0 ) {
- definitionsLocalPatchSb.append(" " + patchDefinePrefix + xmlRootElementName + ":\n");
- if (StringUtils.isNotEmpty(pathDescriptionProperty) || StringUtils.isNotEmpty(validEdges)) {
- definitionsLocalPatchSb.append(" description: |\n");
- }
- if (pathDescriptionProperty != null) {
- definitionsLocalPatchSb.append(" " + pathDescriptionProperty + "\n");
- }
- if (StringUtils.isNotEmpty(validEdges) ) {
- definitionsLocalPatchSb.append(validEdges);
- }
+ if (patchPropertyCnt > 0) {
+ definitionsLocalPatchSb.append(" " + patchDefinePrefix).append(xmlRootElementName)
+ .append(":\n");
+ if (StringUtils.isNotEmpty(pathDescriptionProperty) ||
+ StringUtils.isNotEmpty(validEdges)) {
+ definitionsLocalPatchSb.append(" description: |\n");
+ }
+ if (pathDescriptionProperty != null) {
+ definitionsLocalPatchSb.append(" ").append(pathDescriptionProperty)
+ .append("\n");
+ }
+ if (StringUtils.isNotEmpty(validEdges)) {
+ definitionsLocalPatchSb.append(validEdges);
+ }
definitionsLocalPatchSb.append(" properties:\n");
}
@@ -646,12 +683,12 @@ public class YAMLfromOXM extends OxmFileProcessor {
definitionsLocalSb.toString());
} else {
javaTypeDefinitions.put(xmlRootElementName, definitionsLocalSb.toString());
- if ( !"relationship-list".equals(xmlRootElementName)) {
- javaTypeDefinitions.put(patchDefinePrefix + xmlRootElementName, definitionsLocalPatchSb.toString());
+ if (!"relationship-list".equals(xmlRootElementName)) {
+ javaTypeDefinitions.put(patchDefinePrefix + xmlRootElementName,
+ definitionsLocalPatchSb.toString());
}
}
} catch (Exception e) {
- e.printStackTrace();
logger.error("Exception adding in javaTypeDefinitions", e);
}
if (xmlRootElementName.equals("inventory")) {
@@ -684,30 +721,27 @@ public class YAMLfromOXM extends OxmFileProcessor {
parentDir.mkdirs();
}
try {
- outfile.createNewFile();
+ if(!outfile.createNewFile()) {
+ logger.error( "File {} already exist", outfileName);
+ }
} catch (IOException e) {
- logger.error("Exception creating output file " + outfileName);
- e.printStackTrace();
+ logger.error("Exception creating output file " + outfileName, e);
}
try {
- Charset charset = Charset.forName("UTF-8");
+ Charset charset = StandardCharsets.UTF_8;
Path path = Paths.get(outfileName);
try (BufferedWriter bw = Files.newBufferedWriter(path, charset)) {
bw.write(fileContent);
}
} catch (IOException e) {
- logger.error("Exception writing output file " + outfileName);
- e.printStackTrace();
+ logger.error("Exception writing output file " + outfileName, e);
}
}
public boolean validTag(String tag) {
if (tag != null) {
// set ignore to true to skip Actions and Search
- boolean topCheck = checkTopLevel(tag, true);
- if (topCheck) {
- return true;
- }
+ return checkTopLevel(tag, true);
}
return false;
}
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 41c88ec..ded5f52 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
@@ -96,10 +96,7 @@ public class GenerateSwagger {
try (BufferedReader reader = new BufferedReader(new FileReader(swaggerYamlFile))){
swaggerMap = (Map<String, Object>) yaml.load(reader);
} catch(Exception ex){
- ex.printStackTrace();
- }
-
- if(null == swaggerMap) {
+ System.err.println("Unable load yaml file: " + swaggerYamlFile + " : " + ex.getMessage());
throw new IOException();
}
@@ -144,7 +141,7 @@ public class GenerateSwagger {
line = line.trim();
String hyperLink = "";
if(line.trim().contains("Differences versus")) {
- return String.format("");
+ return "";
}
if(line.trim().contains("https://")){
int startIndex = line.indexOf("https://");
@@ -260,7 +257,7 @@ public class GenerateSwagger {
//Filter out all the relationship links that appear in the YAML
if(key.equals("description")) {
String reqBody=(String)requestBody.get(key);
- if(reqBody.replaceAll("\\[.*.json\\)", "") != reqBody) {
+ if(!reqBody.replaceAll("\\[.*.json\\)", "").equals(reqBody)) {
requestBody.put(key, reqBody.replaceAll("\\[.*.json\\)", ""));
}
}
@@ -372,7 +369,7 @@ public class GenerateSwagger {
List<String> requiredProperties = (valueMap.get("required") == null) ? new ArrayList<>() : (List<String>) valueMap.get("required");
- Set<String> requiredPropsSet = requiredProperties.stream().collect(Collectors.toSet());
+ Set<String> requiredPropsSet = new HashSet<>(requiredProperties);
valueMap
.entrySet()
@@ -381,47 +378,55 @@ public class GenerateSwagger {
.forEach((propertyEntries) -> {
Map<String, Object> propertyRealEntries = (Map<String, Object>) propertyEntries.getValue();
propertyRealEntries
- .entrySet()
- .forEach((propertyEntry) -> {
+ .forEach((propertyKey, value) -> {
Definition.Property definitionProperty = new Definition.Property();
- String propertyKey = propertyEntry.getKey();
- if(requiredPropsSet.contains(propertyKey)){
+ if (requiredPropsSet.contains(propertyKey)) {
definitionProperty.setRequired(true);
}
definitionProperty.setPropertyName(propertyKey);
- Map<String, Object> definitionPropertyMap = (Map<String, Object>) propertyEntry.getValue();
+ Map<String, Object> definitionPropertyMap =
+ (Map<String, Object>) value;
- if(definitionPropertyMap.containsKey("description")){
- definitionProperty.setPropertyDescription(definitionPropertyMap.get("description").toString());
+ if (definitionPropertyMap.containsKey("description")) {
+ definitionProperty.setPropertyDescription(
+ definitionPropertyMap.get("description").toString());
definitionProperty.setHasPropertyDescription(true);
}
- if(definitionPropertyMap.containsKey("type")){
+ if (definitionPropertyMap.containsKey("type")) {
String type = definitionPropertyMap.get("type").toString();
definitionProperty.setPropertyType(type);
definitionProperty.setHasType(true);
if ("array".equals(type)) {
definitionProperty.setPropertyType("object[]");
- if(!definitionPropertyMap.containsKey("items")){
- throw new RuntimeException("Unable to find the property items even though the type is array for " + propertyEntry.getKey());
+ if (!definitionPropertyMap.containsKey("items")) {
+ throw new RuntimeException(
+ "Unable to find the property items even though the type is array for " +
+ propertyKey);
} else {
- Map<String, Object> itemMap = (Map<String, Object>) definitionPropertyMap.get("items");
- if(itemMap.containsKey("$ref")){
+ Map<String, Object> itemMap =
+ (Map<String, Object>) definitionPropertyMap
+ .get("items");
+ if (itemMap.containsKey("$ref")) {
definitionProperty.setHasPropertyReference(true);
String refItem = itemMap.get("$ref").toString();
int retCode = refItem.lastIndexOf('/');
- if(retCode != -1 && retCode != refItem.length()){
- definitionProperty.setPropertyReferenceObjectName(refItem.substring(retCode + 1));
+ if (retCode != -1 && retCode != refItem.length()) {
+ definitionProperty
+ .setPropertyReferenceObjectName(
+ refItem.substring(retCode + 1));
}
definitionProperty.setPropertyReference(refItem);
}
}
} else {
- if(definitionPropertyMap.containsKey("$ref")){
+ if (definitionPropertyMap.containsKey("$ref")) {
definitionProperty.setHasPropertyReference(true);
- String refItem = definitionPropertyMap.get("$ref").toString();
+ String refItem =
+ definitionPropertyMap.get("$ref").toString();
int retCode = refItem.lastIndexOf('/');
- if(retCode != -1 && retCode != refItem.length()){
- definitionProperty.setPropertyReferenceObjectName(refItem.substring(retCode + 1));
+ if (retCode != -1 && retCode != refItem.length()) {
+ definitionProperty.setPropertyReferenceObjectName(
+ refItem.substring(retCode + 1));
}
definitionProperty.setPropertyReference(refItem);
}
@@ -435,7 +440,7 @@ public class GenerateSwagger {
List<Definition.Property> schemaProperties = definitionProperties.
stream()
- .filter((o) -> o.isHasPropertyReference())
+ .filter(Definition.Property::isHasPropertyReference)
.collect(Collectors.toList());
List<Definition.Property> regularProperties = definitionProperties.