v20 support in schema-service without javafx
[aai/schema-service.git] / aai-schema-gen / src / main / java / org / onap / aai / schemagen / genxsd / NodesYAMLfromOXM.java
index e28c127..1de4466 100644 (file)
@@ -84,16 +84,20 @@ public class NodesYAMLfromOXM extends OxmFileProcessor {
         sb.append("description: |");
         if (versionSupportsSwaggerDiff(v.toString())) {
             sb.append("\n\n    [Differences versus the previous schema version]("
-                + "apidocs/aai_swagger_" + v.toString() + ".diff)");
+                    +"apidocs" + basePath + "/aai_swagger_" + v.toString() + ".diff)");
         }
         sb.append(
-            DOUBLE_LINE_SEPARATOR + "    Copyright © 2017-18 AT&T Intellectual Property. All rights reserved.\n\n    Licensed under the Creative Commons License, Attribution 4.0 Intl. (the "License"); 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 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\n\n    This document is best viewed with Firefox or Chrome. Nodes can be found by appending /#/definitions/node-type-to-find to the path to this document. Edge definitions can be found with the node definitions." + LINE_SEPARATOR + "  version: \""
-                + v.toString() + "\"" + LINE_SEPARATOR );
+            DOUBLE_LINE_SEPARATOR + "    Copyright © 2017-18 AT&T Intellectual Property. All rights reserved." + OxmFileProcessor.DOUBLE_LINE_SEPARATOR + "    Licensed under the Creative Commons License, Attribution 4.0 Intl. (the "License"); 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 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License." + 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" + LINE_SEPARATOR + "    url: http://www.apache.org/licenses/LICENSE-2.0.html" + LINE_SEPARATOR);
-        sb.append("  contact:" + LINE_SEPARATOR + "    name:" + LINE_SEPARATOR + "    url:" + LINE_SEPARATOR + "    email:" + LINE_SEPARATOR);
-        sb.append("host:" + LINE_SEPARATOR + "basePath: " + basePath + "/" + v.toString() + 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);
         return sb.toString();
     }
@@ -175,10 +179,38 @@ public class NodesYAMLfromOXM extends OxmFileProcessor {
             if (namespaceFilter != null && (!namespaceFilter.contains(entry.getKey()))) {
                 continue;
             }
+            logger.debug(
+                "Key: " + entry.getKey() + "Test: " + (entry.getKey() == "relationship-dict"));
+            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(" +$", "");
+                }
+                logger.debug("Value-after: " + jb);
+                sb.append(jb);
+                continue;
+            }
             sb.append(entry.getValue());
         }
         return sb.toString();
     }
+    
+    private String getDictionary(String resource) {
+        StringBuffer dictSb = new StringBuffer();
+        dictSb.append("  " + resource + ":\n");
+        dictSb.append("    description: |\n");
+        dictSb.append("      dictionary of " + resource + "\n");
+        dictSb.append("    type: object\n");
+        dictSb.append("    properties:\n");
+        dictSb.append("      " + resource + ":\n");
+        dictSb.append("        type: array\n");
+        dictSb.append("        items:\n");
+        dictSb.append("          $ref: \"#/definitions/" + resource + "-dict\"\n");
+        return dictSb.toString();
+    }
 
     private String processJavaTypeElementSwagger(String javaTypeName, Element javaTypeElement,
         StringBuffer pathSb, StringBuffer definitionsSb, String path, String tag, String opId,
@@ -229,6 +261,7 @@ public class NodesYAMLfromOXM extends OxmFileProcessor {
         String pathDescriptionProperty = javaType.getPathDescriptionProperty();
         String container = javaType.getContainerProperty();
         Vector<String> indexedProps = javaType.getIndexedProps();
+        Vector<String> dslStartNodeProps = javaType.getDslStartNodeProps();
         Vector<String> containerProps = new Vector<String>();
         if (container != null) {
             logger.debug("javaTypeName " + javaTypeName + " container:" + container
@@ -296,7 +329,8 @@ public class NodesYAMLfromOXM extends OxmFileProcessor {
                 NodeGetOperation.addContainerProps(container, containerProps);
             }
             if (xmlElementElement.isStandardType()) {
-                sbProperties.append(xmlElementElement.getTypePropertyYAML());
+               boolean isDslStartNode = dslStartNodeProps.contains(xmlElementElement.getAttribute("name"));
+                sbProperties.append(xmlElementElement.getTypePropertyYAML(isDslStartNode));
                 ++propertyCnt;
             }
 
@@ -304,6 +338,7 @@ public class NodesYAMLfromOXM extends OxmFileProcessor {
             // 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());
+            String useName;
             for (int k = 0; addTypeV != null && k < addTypeV.size(); ++k) {
                 String addType = addTypeV.elementAt(k);
                 namespaceFilter.add(getXmlRootElementName(addType));
@@ -324,9 +359,15 @@ public class NodesYAMLfromOXM extends OxmFileProcessor {
                     } else if (getItemName == null) {
                         ++propertyCnt;
                         sbProperties.append("      " + getXmlRootElementName(addType) + ":\n");
-                        sbProperties.append("        type: array\n        items:\n");
-                        sbProperties.append("          $ref: \"#/definitions/"
+                        if ( "RelationshipList".equals(addType)) {
+                            sbProperties.append("        type: object\n");
+                            sbProperties.append("        $ref: \"#/definitions/"
+                                + itemName + "\"\n");
+                        } else {
+                               sbProperties.append("        type: array\n        items:\n");
+                               sbProperties.append("          $ref: \"#/definitions/"
                             + (itemName == "" ? "aai-internal" : itemName) + "\"\n");
+                        }
                         if (StringUtils.isNotEmpty(elementDescription)) {
                             sbProperties
                                 .append("        description: " + elementDescription + "\n");
@@ -347,10 +388,16 @@ public class NodesYAMLfromOXM extends OxmFileProcessor {
                         processJavaTypeElementSwagger(addType, getJavaTypeElementSwagger(addType),
                             pathSb, definitionsSb, path, tag == null ? useTag : tag, useOpId, null,
                             newPathParams, validEdges);
-                        sbProperties.append("      " + getXmlRootElementName(addType) + ":\n");
-                        sbProperties.append("        type: array\n        items:          \n");
-                        sbProperties.append("          $ref: \"#/definitions/"
-                            + getXmlRootElementName(addType) + "\"\n");
+                        useName = getXmlRootElementName(addType);
+                        sbProperties.append("      " + useName + ":\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");
+                        }
                         if (StringUtils.isNotEmpty(elementDescription)) {
                             sbProperties
                                 .append("        description: " + elementDescription + "\n");
@@ -403,6 +450,7 @@ public class NodesYAMLfromOXM extends OxmFileProcessor {
             return null;
         }
         boolean processingInventoryDef = false;
+        String dict = null;
         if (xmlRootElementName.equals("inventory")) {
             // inventory properties for each oxm to be concatenated
             processingInventoryDef = true;
@@ -412,7 +460,10 @@ public class NodesYAMLfromOXM extends OxmFileProcessor {
                 definitionsLocalSb.append("  " + xmlRootElementName + ":\n");
                 definitionsLocalSb.append("    properties:\n");
             }
-
+        } else if (xmlRootElementName.equals("relationship")) {
+            definitionsSb.append("  " + "relationship-dict" + ":\n");
+            definitionsLocalSb.append("  " + "relationship-dict" + ":\n");
+            dict = getDictionary(xmlRootElementName);
         } else {
             definitionsSb.append("  " + xmlRootElementName + ":\n");
             definitionsLocalSb.append("  " + xmlRootElementName + ":\n");
@@ -539,6 +590,10 @@ public class NodesYAMLfromOXM extends OxmFileProcessor {
             if (xmlRootElementName.equals("inventory")) {
                 // will add to javaTypeDefinitions at end
                 inventoryDefSb.append(definitionsLocalSb.toString());
+            } else if (xmlRootElementName.equals("relationship")) {
+                javaTypeDefinitions.put(xmlRootElementName, dict);
+                javaTypeDefinitions.put(xmlRootElementName + "-dict",
+                    definitionsLocalSb.toString());                
             } else {
                 javaTypeDefinitions.put(xmlRootElementName, definitionsLocalSb.toString());
             }