diff options
20 files changed, 2711 insertions, 1492 deletions
diff --git a/INFO.yaml b/INFO.yaml new file mode 100644 index 0000000..a3d0e4b --- /dev/null +++ b/INFO.yaml @@ -0,0 +1,90 @@ +--- +project: 'aai-schema-service' +project_creation_date: '2018-10-30' +project_category: '' +lifecycle_state: 'Incubation' +project_lead: &onap_aai_ptl + name: 'James Forsyth' + email: 'jf2512@att.com' + id: 'jimmydot' + company: 'ATT' + timezone: 'America/Detroit' +primary_contact: *onap_aai_ptl +issue_tracking: + type: 'jira' + url: 'https://jira.onap.org/projects/AAI' + key: 'AAI' +mailing_list: + type: 'groups.io' + url: 'lists.onap.org' + tag: '<[sub-project_name]>' +realtime_discussion: '' +meetings: + - type: 'zoom' + agenda: 'https://wiki.onap.org/display/DW/AAI+Meeting+Notes' + url: 'https://wiki.onap.org/pages/viewpage.action?pageId=8227676' + server: 'n/a' + channel: 'n/a' + repeats: 'weekly' + time: '14:00 UTC' +repositories: + - 'aai-aai-common' + - 'aai-aai-config' + - 'aai-aai-data' + - 'aai-aai-service' + - 'aai-babel' + - 'aai-cacher' + - 'aai-chameleon' + - 'aai-champ' + - 'aai-data-router' + - 'aai-eis' + - 'aai-enricher' + - 'aai-event-client' + - 'aai-gallifrey' + - 'aai-gap' + - 'aai-gizmo' + - 'aai-graphadmin' + - 'aai-graphgraph' + - 'aai-logging-service' + - 'aai-model-loader' + - 'aai-oom' + - 'aai-resources' + - 'aai-rest-client' + - 'aai-router-core' + - 'aai-schema-service' + - 'aai-search-data-service' + - 'aai-sparky-be' + - 'aai-sparky-fe' + - 'aai-spike' + - 'aai-tabular-data-service' + - 'aai-test-config' + - 'aai-traversal' + - 'aai-validation' +committers: + - <<: *onap_aai_ptl + - name: 'Manisha Aggarwal' + email: 'ma9181@att.com' + company: 'ATT' + id: 'ma9181' + timezone: 'America/New_York' + - name: 'Steven Blimkie' + email: 'Steven.Blimkie@amdocs.com' + company: 'Amdocs' + id: 'sblimkie' + timezone: 'America/Toronto' + - name: 'Tian Lee' + email: 'TianL@amdocs.com' + company: 'Amdocs' + id: 'TianL' + timezone: 'Europe/London' + - name: 'Venkata Harish Kajur' + email: 'vk250x@att.com' + company: 'ATT' + id: 'vk250x' + timezone: 'America/New_York' +tsc: + approval: 'https://lists.onap.org/pipermail/onap-tsc' + changes: + - type: 'removal' + name: 'Steve Smokowski' + link: 'https://lists.onap.org/pipermail/onap-tsc/2018-February/004361.html' diff --git a/aai-annotations/.gitignore b/aai-annotations/.gitignore index 2f30844..43a5448 100644 --- a/aai-annotations/.gitignore +++ b/aai-annotations/.gitignore @@ -1,2 +1,3 @@ /bin/ /.checkstyle +/target/ diff --git a/aai-queries/.gitignore b/aai-queries/.gitignore index a6e94f8..1e030b7 100644 --- a/aai-queries/.gitignore +++ b/aai-queries/.gitignore @@ -1,2 +1,3 @@ **/dbedgerules/** **/oxm/** +/target/ 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 b9efa2f..e28c127 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 @@ -8,7 +8,7 @@ * 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 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -46,482 +46,573 @@ 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) + "/aai_swagger_yaml"; - private StringBuilder inventoryDefSb = null; - private Map<String,String> operationDefinitions = new HashMap<>(); - - private String basePath; - - public NodesYAMLfromOXM(String basePath, SchemaVersions schemaVersions, NodeIngestor ni, EdgeIngestor ei){ - super(schemaVersions, ni,ei); - this.basePath = basePath; - } - public void setOxmVersion(File oxmFile, SchemaVersion v) { - super.setOxmVersion(oxmFile, v); - } - public void setXmlVersion(String xml, SchemaVersion v){ - super.setXmlVersion(xml, v); - } - - public void setVersion(SchemaVersion v) { - super.setVersion(v); - } - - @Override - public String getDocumentHeader() { - StringBuffer sb = new StringBuffer(); - sb.append("swagger: \"2.0\"\ninfo:\n "); - sb.append("description: |"); - if ( versionSupportsSwaggerDiff(v.toString())) { - sb.append("\n\n [Differences versus the previous schema version]("+"apidocs/aai_swagger_" + v.toString() + ".diff)"); - } - sb.append("\n\n 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.\n\n You may obtain a copy of the License at\n\n (https://creativecommons.org/licenses/by/4.0/)\n\n 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.\n version: \"" + v.toString() +"\"\n"); - sb.append(" title: Active and Available Inventory REST API\n"); - sb.append(" license:\n name: Apache 2.0\n url: http://www.apache.org/licenses/LICENSE-2.0.html\n"); - sb.append(" contact:\n name:\n url:\n email:\n"); - sb.append("host:\nbasePath: " + basePath + "/" + v.toString() + "\n"); - sb.append("schemes:\n - https\npaths:\n"); - return sb.toString(); - } - - protected void init() throws ParserConfigurationException, SAXException, IOException, FileNotFoundException, EdgeRuleNotFoundException { - super.init(); - } - - @Override - public String process() throws ParserConfigurationException, SAXException, IOException, FileNotFoundException, EdgeRuleNotFoundException { - StringBuffer sb = new StringBuffer(); - StringBuffer pathSb = new StringBuffer(); - NodeGetOperation.resetContainers(); - try { - init(); - } catch(Exception e) { - logger.error( "Error initializing " + this.getClass()); - throw e; - } - pathSb.append(getDocumentHeader()); - StringBuffer definitionsSb = new StringBuffer(); - Element elem; - String javaTypeName; - 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 = getJavaTypeElementSwagger(javaTypeName ); - } - - XSDElement javaTypeElement = new XSDElement(elem); - - logger.debug("External: "+javaTypeElement.getAttribute("name")+"/"+getXmlRootElementName(javaTypeName)); - if ( javaTypeName == null ) { - String msg = "Invalid OXM file: <java-type> has no name attribute in " + oxmFile; - logger.error(msg); - throw new SAXException(msg); - } - namespaceFilter.add(getXmlRootElementName(javaTypeName)); - processJavaTypeElementSwagger( javaTypeName, javaTypeElement, pathSb, - definitionsSb, null, null, null, null, null, null); - } - sb.append(pathSb); -// sb.append(getDocumentHeader()); -// sb.append(totalPathSbAccumulator); - sb.append(appendOperations()); - sb.append(appendDefinitions()); - PutRelationPathSet prp = new PutRelationPathSet(v); - prp.generateRelations(ei); - return sb.toString(); - } - - public String appendDefinitions() { - return appendDefinitions(null); - } - - public String appendDefinitions(Set<String> namespaceFilter) { - if ( inventoryDefSb != null ) { - javaTypeDefinitions.put("inventory", inventoryDefSb.toString()); - } - StringBuffer sb = new StringBuffer("definitions:\n"); - Map<String, String> sortedJavaTypeDefinitions = new TreeMap<>(javaTypeDefinitions); - - for (Map.Entry<String, String> entry : sortedJavaTypeDefinitions.entrySet()) { - if(namespaceFilter != null && (! namespaceFilter.contains(entry.getKey()))) { - continue; - } - sb.append(entry.getValue()); - } - return sb.toString(); - } - - private String processJavaTypeElementSwagger( String javaTypeName, Element javaTypeElement, - StringBuffer pathSb, StringBuffer definitionsSb, String path, String tag, String opId, - String getItemName, StringBuffer pathParams, String validEdges) { - - String xmlRootElementName = getXMLRootElementName(javaTypeElement); - StringBuilder definitionsLocalSb = new StringBuilder(256); - - String useTag = null; - String useOpId = null; - logger.debug("tag="+tag); - - if(tag != null && (! validTag(tag))) { - logger.debug("tag="+tag+"; javaTypeName="+javaTypeName); - return null; - } - if ( !javaTypeName.equals("Inventory") ) { - if ( javaTypeName.equals("AaiInternal")) - return null; - if ( opId == null ) - useOpId = javaTypeName; - else - useOpId = opId + javaTypeName; - if ( tag == null ) - useTag = javaTypeName; - } - - path = xmlRootElementName.equals("inventory") ? "" : (path == null) ? "/" + xmlRootElementName : path + "/" + xmlRootElementName; - XSDJavaType javaType = new XSDJavaType(javaTypeElement); - if ( getItemName != null) { - if ( getItemName.equals("array") ) - return javaType.getArrayType(); - else - return javaType.getItemName(); - } - - NodeList parentNodes = javaTypeElement.getElementsByTagName("java-attributes"); - if ( parentNodes.getLength() == 0 ) { - logger.debug( "no java-attributes for java-type " + javaTypeName); - return ""; - } - - String pathDescriptionProperty = javaType.getPathDescriptionProperty(); - String container = javaType.getContainerProperty(); - Vector<String> indexedProps = javaType.getIndexedProps(); - Vector<String> containerProps = new Vector<String>(); - if(container != null) { - logger.debug("javaTypeName " + javaTypeName + " container:" + container +" indexedProps:"+indexedProps); - } - - Element parentElement = (Element)parentNodes.item(0); - NodeList xmlElementNodes = parentElement.getElementsByTagName("xml-element"); - - StringBuffer sbParameters = new StringBuffer(); - StringBuffer sbRequired = new StringBuffer(); - int requiredCnt = 0; - int propertyCnt = 0; - StringBuffer sbProperties = new StringBuffer(); - - if ( appliedPaths.containsKey(path)) - return null; - - StringTokenizer st = new StringTokenizer(path, "/"); - logger.debug("path: " + path + " st? " + st.toString()); - if ( st.countTokens() > 1 && getItemName == null ) { - logger.debug("appliedPaths: " + appliedPaths + " containsKey? " + appliedPaths.containsKey(path)); - appliedPaths.put(path, xmlRootElementName); - } - Vector<String> addTypeV = null; - for ( int i = 0; i < xmlElementNodes.getLength(); ++i ) { - XSDElement xmlElementElement = new XSDElement((Element)xmlElementNodes.item(i)); - if ( !xmlElementElement.getParentNode().isSameNode(parentElement)) - continue; - String elementDescription=xmlElementElement.getPathDescriptionProperty(); - if(getItemName == null) { - addTypeV = xmlElementElement.getAddTypes(v.toString()); - } - if ( "true".equals(xmlElementElement.getAttribute("xml-key"))) { - path += "/{" + xmlElementElement.getAttribute("name") + "}"; - } - logger.debug("path: " + path); - logger.debug( "xmlElementElement.getAttribute(required):"+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"); - } else { - for ( int k = 0; k < addTypeV.size(); ++k ) { - sbRequired.append(" - " + getXmlRootElementName(addTypeV.elementAt(k)) + ":\n"); - } - } - } - - if ( "true".equals(xmlElementElement.getAttribute("xml-key")) ) { - sbParameters.append(xmlElementElement.getPathParamYAML(elementDescription)); - } - if ( indexedProps != null - && indexedProps.contains(xmlElementElement.getAttribute("name") ) ) { - containerProps.add(xmlElementElement.getQueryParamYAML()); - NodeGetOperation.addContainerProps(container, containerProps); - } - if ( xmlElementElement.isStandardType()) { - sbProperties.append(xmlElementElement.getTypePropertyYAML()); - ++propertyCnt; - } - -// 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()); - for ( int k = 0; addTypeV != null && k < addTypeV.size(); ++k ) { - String addType = addTypeV.elementAt(k); - namespaceFilter.add(getXmlRootElementName(addType)); - if ( opId == null || !opId.contains(addType)) { - processJavaTypeElementSwagger( addType, getJavaTypeElementSwagger(addType), - pathSb, definitionsSb, path, tag == null ? useTag : tag, useOpId, null, - newPathParams, validEdges); - } - // need item name of array - String itemName = processJavaTypeElementSwagger( addType, getJavaTypeElementSwagger(addType), - pathSb, definitionsSb, path, tag == null ? useTag : tag, useOpId, - "array", null, null); - - if ( itemName != null ) { - if ( addType.equals("AaiInternal") ) { - logger.debug( "addType AaiInternal, skip properties"); - - } else if ( getItemName == null) { - ++propertyCnt; - sbProperties.append(" " + getXmlRootElementName(addType) + ":\n"); - 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"); - } - } else { - if ( ("java.util.ArrayList").equals(xmlElementElement.getAttribute("container-type"))) { - // need properties for getXmlRootElementName(addType) - namespaceFilter.add(getXmlRootElementName(addType)); - if(getXmlRootElementName(addType).equals("service-capabilities")) - { - logger.info("arrays: "+ getXmlRootElementName(addType)); - } -// newPathParams = new StringBuffer((pathParams == null ? "" : pathParams.toString())+sbParameters.toString()); //cp8128 - change this to not append pathParameters. Just use sbParameters - newPathParams = new StringBuffer(sbParameters.toString()); - 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"); - if ( StringUtils.isNotEmpty(elementDescription) ) - sbProperties.append(" description: " + elementDescription + "\n"); - - } else { - //Make sure certain types added to the filter don't appear - if (nodeFilter.contains(getXmlRootElementName(addType))) { - ; - } else { - sbProperties.append(" " + getXmlRootElementName(addType) + ":\n"); - sbProperties.append(" type: object\n"); - sbProperties.append(" $ref: \"#/definitions/" + getXmlRootElementName(addType) + "\"\n"); - } - } - if ( StringUtils.isNotEmpty(elementDescription) ) - sbProperties.append(" description: " + elementDescription + "\n"); - ++propertyCnt; - } - } - } - - if ( sbParameters.toString().length() > 0 ) { - if ( pathParams == null ) - pathParams = new StringBuffer(); - pathParams.append(sbParameters); - } - if (indexedProps.isEmpty() && containerProps.isEmpty()){ - NodeGetOperation get = new NodeGetOperation(useOpId, xmlRootElementName, tag, path, null); - String operation = get.toString(); - if(StringUtils.isNotEmpty(operation)) { - operationDefinitions.put(xmlRootElementName, operation); - } - } else { - NodeGetOperation get = new NodeGetOperation(useOpId, xmlRootElementName, tag, path, pathParams == null ? "" : pathParams.toString()); - String operation = get.toString(); - if(StringUtils.isNotEmpty(operation)) { - operationDefinitions.put(xmlRootElementName, operation); - } - } - logger.debug("opId vs useOpId:"+opId+" vs "+useOpId+" PathParams="+pathParams); - // add PUT - if ( generatedJavaType.containsKey(xmlRootElementName) ) { - logger.debug("xmlRootElementName(1)="+xmlRootElementName); - return null; - } - boolean processingInventoryDef = false; - if ( xmlRootElementName.equals("inventory")) { - // inventory properties for each oxm to be concatenated - processingInventoryDef = true; - if ( inventoryDefSb == null ) { - inventoryDefSb = new StringBuilder(); - definitionsSb.append(" " + xmlRootElementName + ":\n"); - definitionsLocalSb.append(" " + xmlRootElementName + ":\n"); - definitionsLocalSb.append(" properties:\n"); - } - - } else { - definitionsSb.append(" " + xmlRootElementName + ":\n"); - definitionsLocalSb.append(" " + xmlRootElementName + ":\n"); - } - DeleteFootnoteSet footnotes = new DeleteFootnoteSet(xmlRootElementName); - StringBuffer sbEdge = new StringBuffer(); - LinkedHashSet<String> preventDelete = new LinkedHashSet<String>(); - String prevent=null; - String nodeCaption = new String(" ###### Related Nodes\n"); - try { - EdgeRuleQuery q = new EdgeRuleQuery.Builder(xmlRootElementName).version(v).fromOnly().build(); - Multimap<String, EdgeRule> results = ei.getRules(q); - SortedSet<String> ss=new TreeSet<>(results.keySet()); - sbEdge.append(nodeCaption); - nodeCaption=""; - for(String key : ss) { - results.get(key).stream().filter((i) -> (i.getFrom().equals(xmlRootElementName) && (! i.isPrivateEdge()))).forEach((i) ->{ logger.info(new String(new StringBuffer(" - 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()); EdgeDescription ed = new EdgeDescription(i); String footnote = ed.getAlsoDeleteFootnote(xmlRootElementName); sbEdge.append(ed.getRelationshipDescription("TO", xmlRootElementName)+footnote+"\n"); if(StringUtils.isNotEmpty(footnote)) footnotes.add(footnote);} ); - results.get(key).stream().filter((i) -> (i.getFrom().equals(xmlRootElementName) && (! i.isPrivateEdge() && i.getPreventDelete().equals("OUT")))).forEach((i) ->{ preventDelete.add(i.getTo().toUpperCase());} ); - } - } catch(Exception e) { - logger.debug("xmlRootElementName: "+xmlRootElementName+"\n"+e); - } - try { - EdgeRuleQuery q1 = new EdgeRuleQuery.Builder(xmlRootElementName).version(v).toOnly().build(); - Multimap<String, EdgeRule> results = ei.getRules(q1); - SortedSet<String> ss=new TreeSet<String>(results.keySet()); - sbEdge.append(nodeCaption); - for(String key : ss) { - results.get(key).stream().filter((i) -> (i.getTo().equals(xmlRootElementName) && (! i.isPrivateEdge()))).forEach((i) ->{ sbEdge.append(" - FROM "+i.getFrom()); EdgeDescription ed = new EdgeDescription(i); String footnote = ed.getAlsoDeleteFootnote(xmlRootElementName); sbEdge.append(ed.getRelationshipDescription("FROM", xmlRootElementName)+footnote+"\n"); if(StringUtils.isNotEmpty(footnote)) footnotes.add(footnote);} ); - 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())));} ); - results.get(key).stream().filter((i) -> (i.getTo().equals(xmlRootElementName) && (! i.isPrivateEdge() && i.getPreventDelete().equals("IN")))).forEach((i) ->{ preventDelete.add(i.getFrom().toUpperCase());} ); - } - } catch(Exception e) { - logger.debug("xmlRootElementName: "+xmlRootElementName+"\n"+e); - } - if(preventDelete.size() > 0) { - prevent = xmlRootElementName.toUpperCase()+" cannot be deleted if related to "+String.join(",",preventDelete); - logger.debug(prevent); - } - - if(StringUtils.isNotEmpty(prevent)) { - footnotes.add(prevent); - } - if(footnotes.footnotes.size() > 0) { - sbEdge.append(footnotes.toString()); - } - validEdges = sbEdge.toString(); - - // Handle description property. Might have a description OR valid edges OR both OR neither. - // Only put a description: tag if there is at least one. - if (StringUtils.isNotEmpty(pathDescriptionProperty) || StringUtils.isNotEmpty(validEdges) ) { - definitionsSb.append(" description: |\n"); - definitionsLocalSb.append(" description: |\n"); - - if ( pathDescriptionProperty != null ) { - definitionsSb.append(" " + pathDescriptionProperty + "\n" ); - definitionsLocalSb.append(" " + pathDescriptionProperty + "\n" ); - } - definitionsSb.append(validEdges); - definitionsLocalSb.append(validEdges); - } - - if ( requiredCnt > 0 ) { - definitionsSb.append(sbRequired); - definitionsLocalSb.append(sbRequired); - } - - if ( propertyCnt > 0 ) { - definitionsSb.append(" properties:\n"); - definitionsSb.append(sbProperties); - if ( !processingInventoryDef) { - definitionsLocalSb.append(" properties:\n"); - } - definitionsLocalSb.append(sbProperties); - } - try { - namespaceFilter.add(xmlRootElementName); - if ( xmlRootElementName.equals("inventory") ) { - //will add to javaTypeDefinitions at end - inventoryDefSb.append(definitionsLocalSb.toString()); - } else { - javaTypeDefinitions.put(xmlRootElementName, definitionsLocalSb.toString()); - } - } catch (Exception e) { - e.printStackTrace(); - } - if ( xmlRootElementName.equals("inventory") ) { - logger.trace("skip xmlRootElementName(2)="+xmlRootElementName); - return null; - } - generatedJavaType.put(xmlRootElementName, null); - //Write operations by Namespace(tagName) -/* - if( validTag(javaTypeName) && javaTypeName == useTag && tag == null) { - writeYAMLfile("nodes_"+javaTypeName, getDocumentHeader()+pathSb.toString()+appendDefinitions(namespaceFilter)); - totalPathSbAccumulator.append(pathSb); - pathSb.delete(0, pathSb.length()); - namespaceFilter.clear(); - } -*/ - logger.debug("xmlRootElementName(2)="+xmlRootElementName); - return null; - } - - 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 : outfileName; - File outfile = new File(outfileName); - File parentDir = outfile.getParentFile(); - if(parentDir != null && ! parentDir.exists()) - parentDir.mkdirs(); - try { - outfile.createNewFile(); - } catch (IOException e) { - logger.error( "Exception creating output file " + outfileName); - e.printStackTrace(); - } - Path path = Paths.get(outfileName); - Charset charset = Charset.forName("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(); - } - } - - public boolean validTag(String tag) { - if(tag != null) { - switch ( tag ) { - case "Network": - case "Search": - case "Actions": - case "ServiceDesignAndCreation": - case "Business": - case "LicenseManagement": - case "CloudInfrastructure": - return true; - } - } - return false; - } - - public String appendOperations() { - //append definitions - StringBuffer sb = new StringBuffer(); - Map<String, String> sortedOperationDefinitions = new TreeMap<String, String>(operationDefinitions); - for (Map.Entry<String, String> entry : sortedOperationDefinitions.entrySet()) { - sb.append(entry.getValue()); - } - return sb.toString(); - } -} + 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) + + "/aai_swagger_yaml"; + private StringBuilder inventoryDefSb = null; + private Map<String, String> operationDefinitions = new HashMap<>(); + + private String basePath; + + public NodesYAMLfromOXM(String basePath, SchemaVersions schemaVersions, NodeIngestor ni, + EdgeIngestor ei) { + super(schemaVersions, ni, ei); + this.basePath = basePath; + } + + public void setOxmVersion(File oxmFile, SchemaVersion v) { + super.setOxmVersion(oxmFile, v); + } + + public void setXmlVersion(String xml, SchemaVersion v) { + super.setXmlVersion(xml, v); + } + + public void setVersion(SchemaVersion v) { + super.setVersion(v); + } + + @Override + public String getDocumentHeader() { + StringBuffer sb = new StringBuffer(); + sb.append("swagger: \"2.0\"\ninfo:" + LINE_SEPARATOR + " "); + sb.append("description: |"); + if (versionSupportsSwaggerDiff(v.toString())) { + sb.append("\n\n [Differences versus the previous schema version](" + + "apidocs/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 ); + 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("schemes:" + LINE_SEPARATOR + " - https\npaths:" + LINE_SEPARATOR); + return sb.toString(); + } + + protected void init() throws ParserConfigurationException, SAXException, IOException, + FileNotFoundException, EdgeRuleNotFoundException { + super.init(); + } + + @Override + public String process() throws ParserConfigurationException, SAXException, IOException, + FileNotFoundException, EdgeRuleNotFoundException { + StringBuffer sb = new StringBuffer(); + StringBuffer pathSb = new StringBuffer(); + NodeGetOperation.resetContainers(); + try { + init(); + } catch (Exception e) { + logger.error("Error initializing " + this.getClass()); + throw e; + } + pathSb.append(getDocumentHeader()); + StringBuffer definitionsSb = new StringBuffer(); + Element elem; + String javaTypeName; + for (int i = 0; i < javaTypeNodes.getLength(); ++i) { + elem = (Element) javaTypeNodes.item(i); + javaTypeName = elem.getAttribute("name"); + boolean processInventory = false; + if (!"Inventory".equals(javaTypeName)) { + if (generatedJavaType.containsKey(javaTypeName)) { + continue; + } + // will combine all matching java-types + elem = getJavaTypeElementSwagger(javaTypeName); + } else { + processInventory = true; + } + + XSDElement javaTypeElement = new XSDElement(elem); + + if (processInventory) { + getTopLevelPaths(javaTypeElement); + } + + logger.debug("External: " + javaTypeElement.getAttribute("name") + "/" + + getXmlRootElementName(javaTypeName)); + if (javaTypeName == null) { + String msg = "Invalid OXM file: <java-type> has no name attribute in " + oxmFile; + logger.error(msg); + throw new SAXException(msg); + } + namespaceFilter.add(getXmlRootElementName(javaTypeName)); + processJavaTypeElementSwagger(javaTypeName, javaTypeElement, pathSb, definitionsSb, + null, null, null, null, null, null); + } + sb.append(pathSb); + // sb.append(getDocumentHeader()); + // sb.append(totalPathSbAccumulator); + sb.append(appendOperations()); + sb.append(appendDefinitions()); + PutRelationPathSet prp = new PutRelationPathSet(v); + prp.generateRelations(ei); + return sb.toString(); + } + + public String appendDefinitions() { + return appendDefinitions(null); + } + + public String appendDefinitions(Set<String> namespaceFilter) { + if (inventoryDefSb != null) { + javaTypeDefinitions.put("inventory", inventoryDefSb.toString()); + } + StringBuffer sb = new StringBuffer("definitions:\n"); + Map<String, String> sortedJavaTypeDefinitions = new TreeMap<>(javaTypeDefinitions); + + for (Map.Entry<String, String> entry : sortedJavaTypeDefinitions.entrySet()) { + if (namespaceFilter != null && (!namespaceFilter.contains(entry.getKey()))) { + continue; + } + sb.append(entry.getValue()); + } + return sb.toString(); + } + + private String processJavaTypeElementSwagger(String javaTypeName, Element javaTypeElement, + StringBuffer pathSb, StringBuffer definitionsSb, String path, String tag, String opId, + String getItemName, StringBuffer pathParams, String validEdges) { + + String xmlRootElementName = getXMLRootElementName(javaTypeElement); + StringBuilder definitionsLocalSb = new StringBuilder(256); + + String useTag = null; + String useOpId = null; + logger.debug("tag=" + tag); + + if (tag != null && (!validTag(tag))) { + logger.debug("tag=" + tag + "; javaTypeName=" + javaTypeName); + return null; + } + if (!javaTypeName.equals("Inventory")) { + if (javaTypeName.equals("AaiInternal")) { + return null; + } + if (opId == null) { + useOpId = javaTypeName; + } else { + useOpId = opId + javaTypeName; + } + if (tag == null) { + useTag = javaTypeName; + } + } + + path = xmlRootElementName.equals("inventory") ? "" + : (path == null) ? "/" + xmlRootElementName : path + "/" + xmlRootElementName; + XSDJavaType javaType = new XSDJavaType(javaTypeElement); + if (getItemName != null) { + if (getItemName.equals("array")) { + return javaType.getArrayType(); + } else { + return javaType.getItemName(); + } + } + + NodeList parentNodes = javaTypeElement.getElementsByTagName("java-attributes"); + if (parentNodes.getLength() == 0) { + logger.debug("no java-attributes for java-type " + javaTypeName); + return ""; + } + + String pathDescriptionProperty = javaType.getPathDescriptionProperty(); + String container = javaType.getContainerProperty(); + Vector<String> indexedProps = javaType.getIndexedProps(); + Vector<String> containerProps = new Vector<String>(); + if (container != null) { + logger.debug("javaTypeName " + javaTypeName + " container:" + container + + " indexedProps:" + indexedProps); + } + + Element parentElement = (Element) parentNodes.item(0); + NodeList xmlElementNodes = parentElement.getElementsByTagName("xml-element"); + + StringBuffer sbParameters = new StringBuffer(); + StringBuffer sbRequired = new StringBuffer(); + int requiredCnt = 0; + int propertyCnt = 0; + StringBuffer sbProperties = new StringBuffer(); + + if (appliedPaths.containsKey(path)) { + return null; + } + + StringTokenizer st = new StringTokenizer(path, "/"); + logger.debug("path: " + path + " st? " + st.toString()); + if (st.countTokens() > 1 && getItemName == null) { + logger.debug("appliedPaths: " + appliedPaths + " containsKey? " + + appliedPaths.containsKey(path)); + appliedPaths.put(path, xmlRootElementName); + } + Vector<String> addTypeV = null; + for (int i = 0; i < xmlElementNodes.getLength(); ++i) { + XSDElement xmlElementElement = new XSDElement((Element) xmlElementNodes.item(i)); + if (!xmlElementElement.getParentNode().isSameNode(parentElement)) { + continue; + } + String elementDescription = xmlElementElement.getPathDescriptionProperty(); + if (getItemName == null) { + addTypeV = xmlElementElement.getAddTypes(v.toString()); + } + if ("true".equals(xmlElementElement.getAttribute("xml-key"))) { + path += "/{" + xmlElementElement.getAttribute("name") + "}"; + } + logger.debug("path: " + path); + logger.debug("xmlElementElement.getAttribute(required):" + + 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"); + } else { + for (int k = 0; k < addTypeV.size(); ++k) { + sbRequired.append( + " - " + getXmlRootElementName(addTypeV.elementAt(k)) + ":\n"); + } + } + } + + if ("true".equals(xmlElementElement.getAttribute("xml-key"))) { + sbParameters.append(xmlElementElement.getPathParamYAML(elementDescription)); + } + if (indexedProps != null + && indexedProps.contains(xmlElementElement.getAttribute("name"))) { + containerProps.add(xmlElementElement.getQueryParamYAML()); + NodeGetOperation.addContainerProps(container, containerProps); + } + if (xmlElementElement.isStandardType()) { + sbProperties.append(xmlElementElement.getTypePropertyYAML()); + ++propertyCnt; + } + + // 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()); + for (int k = 0; addTypeV != null && k < addTypeV.size(); ++k) { + String addType = addTypeV.elementAt(k); + namespaceFilter.add(getXmlRootElementName(addType)); + if (opId == null || !opId.contains(addType)) { + processJavaTypeElementSwagger(addType, getJavaTypeElementSwagger(addType), + pathSb, definitionsSb, path, tag == null ? useTag : tag, useOpId, null, + newPathParams, validEdges); + } + // need item name of array + String itemName = processJavaTypeElementSwagger(addType, + getJavaTypeElementSwagger(addType), pathSb, definitionsSb, path, + tag == null ? useTag : tag, useOpId, "array", null, null); + + if (itemName != null) { + if (addType.equals("AaiInternal")) { + logger.debug("addType AaiInternal, skip properties"); + + } else if (getItemName == null) { + ++propertyCnt; + sbProperties.append(" " + getXmlRootElementName(addType) + ":\n"); + 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"); + } + } + } else { + if (("java.util.ArrayList") + .equals(xmlElementElement.getAttribute("container-type"))) { + // need properties for getXmlRootElementName(addType) + namespaceFilter.add(getXmlRootElementName(addType)); + if (getXmlRootElementName(addType).equals("service-capabilities")) { + logger.info("arrays: " + getXmlRootElementName(addType)); + } + // newPathParams = new StringBuffer((pathParams == null ? "" : + // pathParams.toString())+sbParameters.toString()); //cp8128 - change this + // to not append pathParameters. Just use sbParameters + newPathParams = new StringBuffer(sbParameters.toString()); + 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"); + if (StringUtils.isNotEmpty(elementDescription)) { + sbProperties + .append(" description: " + elementDescription + "\n"); + } + + } else { + // Make sure certain types added to the filter don't appear + if (nodeFilter.contains(getXmlRootElementName(addType))) { + ; + } else { + sbProperties.append(" " + getXmlRootElementName(addType) + ":\n"); + sbProperties.append(" type: object\n"); + sbProperties.append(" $ref: \"#/definitions/" + + getXmlRootElementName(addType) + "\"\n"); + } + } + if (StringUtils.isNotEmpty(elementDescription)) { + sbProperties.append(" description: " + elementDescription + "\n"); + } + ++propertyCnt; + } + } + } + + if (sbParameters.toString().length() > 0) { + if (pathParams == null) { + pathParams = new StringBuffer(); + } + pathParams.append(sbParameters); + } + if (indexedProps.isEmpty() && containerProps.isEmpty()) { + NodeGetOperation get = + new NodeGetOperation(useOpId, xmlRootElementName, tag, path, null); + String operation = get.toString(); + if (StringUtils.isNotEmpty(operation)) { + operationDefinitions.put(xmlRootElementName, operation); + } + } else { + NodeGetOperation get = new NodeGetOperation(useOpId, xmlRootElementName, tag, path, + pathParams == null ? "" : pathParams.toString()); + String operation = get.toString(); + if (StringUtils.isNotEmpty(operation)) { + operationDefinitions.put(xmlRootElementName, operation); + } + } + logger.debug("opId vs useOpId:" + opId + " vs " + useOpId + " PathParams=" + pathParams); + // add PUT + if (generatedJavaType.containsKey(xmlRootElementName)) { + logger.debug("xmlRootElementName(1)=" + xmlRootElementName); + return null; + } + boolean processingInventoryDef = false; + if (xmlRootElementName.equals("inventory")) { + // inventory properties for each oxm to be concatenated + processingInventoryDef = true; + if (inventoryDefSb == null) { + inventoryDefSb = new StringBuilder(); + definitionsSb.append(" " + xmlRootElementName + ":\n"); + definitionsLocalSb.append(" " + xmlRootElementName + ":\n"); + definitionsLocalSb.append(" properties:\n"); + } + + } else { + definitionsSb.append(" " + xmlRootElementName + ":\n"); + definitionsLocalSb.append(" " + xmlRootElementName + ":\n"); + } + DeleteFootnoteSet footnotes = new DeleteFootnoteSet(xmlRootElementName); + StringBuffer sbEdge = new StringBuffer(); + LinkedHashSet<String> preventDelete = new LinkedHashSet<String>(); + String prevent = null; + String nodeCaption = new String(" ###### Related Nodes\n"); + try { + EdgeRuleQuery q = + new EdgeRuleQuery.Builder(xmlRootElementName).version(v).fromOnly().build(); + Multimap<String, EdgeRule> results = ei.getRules(q); + SortedSet<String> ss = new TreeSet<>(results.keySet()); + sbEdge.append(nodeCaption); + nodeCaption = ""; + for (String key : ss) { + results.get(key).stream() + .filter((i) -> (i.getFrom().equals(xmlRootElementName) && (!i.isPrivateEdge()))) + .forEach((i) -> { + logger.info(new String(new StringBuffer(" - 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()); + EdgeDescription ed = new EdgeDescription(i); + String footnote = ed.getAlsoDeleteFootnote(xmlRootElementName); + sbEdge.append(ed.getRelationshipDescription("TO", xmlRootElementName) + + footnote + "\n"); + if (StringUtils.isNotEmpty(footnote)) { + footnotes.add(footnote); + } + }); + results.get(key).stream() + .filter((i) -> (i.getFrom().equals(xmlRootElementName) + && (!i.isPrivateEdge() && i.getPreventDelete().equals("OUT")))) + .forEach((i) -> { + preventDelete.add(i.getTo().toUpperCase()); + }); + } + } catch (Exception e) { + logger.debug("xmlRootElementName: " + xmlRootElementName + "\n" + e); + } + try { + EdgeRuleQuery q1 = + new EdgeRuleQuery.Builder(xmlRootElementName).version(v).toOnly().build(); + Multimap<String, EdgeRule> results = ei.getRules(q1); + SortedSet<String> ss = new TreeSet<String>(results.keySet()); + sbEdge.append(nodeCaption); + for (String key : ss) { + results.get(key).stream() + .filter((i) -> (i.getTo().equals(xmlRootElementName) && (!i.isPrivateEdge()))) + .forEach((i) -> { + sbEdge.append(" - FROM " + i.getFrom()); + EdgeDescription ed = new EdgeDescription(i); + String footnote = ed.getAlsoDeleteFootnote(xmlRootElementName); + sbEdge.append(ed.getRelationshipDescription("FROM", xmlRootElementName) + + footnote + "\n"); + if (StringUtils.isNotEmpty(footnote)) { + footnotes.add(footnote); + } + }); + 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()))); + }); + results.get(key).stream() + .filter((i) -> (i.getTo().equals(xmlRootElementName) + && (!i.isPrivateEdge() && i.getPreventDelete().equals("IN")))) + .forEach((i) -> { + preventDelete.add(i.getFrom().toUpperCase()); + }); + } + } catch (Exception e) { + logger.debug("xmlRootElementName: " + xmlRootElementName + "\n" + e); + } + if (preventDelete.size() > 0) { + prevent = xmlRootElementName.toUpperCase() + " cannot be deleted if related to " + + String.join(",", preventDelete); + logger.debug(prevent); + } + + if (StringUtils.isNotEmpty(prevent)) { + footnotes.add(prevent); + } + if (footnotes.footnotes.size() > 0) { + sbEdge.append(footnotes.toString()); + } + validEdges = sbEdge.toString(); + + // Handle description property. Might have a description OR valid edges OR both OR neither. + // Only put a description: tag if there is at least one. + if (StringUtils.isNotEmpty(pathDescriptionProperty) || StringUtils.isNotEmpty(validEdges)) { + definitionsSb.append(" description: |\n"); + definitionsLocalSb.append(" description: |\n"); + + if (pathDescriptionProperty != null) { + definitionsSb.append(" " + pathDescriptionProperty + "\n"); + definitionsLocalSb.append(" " + pathDescriptionProperty + "\n"); + } + definitionsSb.append(validEdges); + definitionsLocalSb.append(validEdges); + } + + if (requiredCnt > 0) { + definitionsSb.append(sbRequired); + definitionsLocalSb.append(sbRequired); + } + if (propertyCnt > 0) { + definitionsSb.append(" properties:\n"); + definitionsSb.append(sbProperties); + if (!processingInventoryDef) { + definitionsLocalSb.append(" properties:\n"); + } + definitionsLocalSb.append(sbProperties); + } + try { + namespaceFilter.add(xmlRootElementName); + if (xmlRootElementName.equals("inventory")) { + // will add to javaTypeDefinitions at end + inventoryDefSb.append(definitionsLocalSb.toString()); + } else { + javaTypeDefinitions.put(xmlRootElementName, definitionsLocalSb.toString()); + } + } catch (Exception e) { + e.printStackTrace(); + } + if (xmlRootElementName.equals("inventory")) { + logger.trace("skip xmlRootElementName(2)=" + xmlRootElementName); + return null; + } + generatedJavaType.put(xmlRootElementName, null); + // Write operations by Namespace(tagName) + /* + * if( validTag(javaTypeName) && javaTypeName == useTag && tag == null) { + * writeYAMLfile("nodes_"+javaTypeName, + * getDocumentHeader()+pathSb.toString()+appendDefinitions(namespaceFilter)); + * totalPathSbAccumulator.append(pathSb); + * pathSb.delete(0, pathSb.length()); + * namespaceFilter.clear(); + * } + */ + logger.debug("xmlRootElementName(2)=" + xmlRootElementName); + return null; + } + + 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 + : outfileName; + File outfile = new File(outfileName); + File parentDir = outfile.getParentFile(); + if (parentDir != null && !parentDir.exists()) { + parentDir.mkdirs(); + } + try { + outfile.createNewFile(); + } catch (IOException e) { + logger.error("Exception creating output file " + outfileName); + e.printStackTrace(); + } + Path path = Paths.get(outfileName); + Charset charset = Charset.forName("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(); + } + } + + 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; + } + } + return false; + } + + public String appendOperations() { + // append definitions + StringBuffer sb = new StringBuffer(); + Map<String, String> sortedOperationDefinitions = + new TreeMap<String, String>(operationDefinitions); + for (Map.Entry<String, String> entry : sortedOperationDefinitions.entrySet()) { + sb.append(entry.getValue()); + } + return sb.toString(); + } +} diff --git a/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/OxmFileProcessor.java b/aai-schema-gen/src/main/java/org/onap/aai/schemagen/genxsd/OxmFileProcessor.java index dfa702b..39eb9d9 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 @@ -8,7 +8,7 @@ * 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 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -40,442 +40,494 @@ import java.util.*; public abstract class OxmFileProcessor { - public static final String LINE_SEPARATOR = System.getProperty("line.separator"); - public static final String DOUBLE_LINE_SEPARATOR = System.getProperty("line.separator") + System.getProperty("line.separator"); - - EdgeIngestor ei; - NodeIngestor ni; - protected Set<String> namespaceFilter; - protected File oxmFile; - protected String xml; - protected SchemaVersion v; - protected Document doc = null; - protected String apiVersion = null; - protected SchemaVersions schemaVersions; - - - protected static int annotationsStartVersion = 9; // minimum version to support annotations in xsd - protected static int annotationsMinVersion = 6; // lower versions support annotations in xsd - protected static int swaggerSupportStartsVersion = 1; // minimum version to support swagger documentation - protected static int swaggerDiffStartVersion = 1; // minimum version to support difference - protected static int swaggerMinBasepath = 6; // minimum version to support difference - - protected Map combinedJavaTypes; - - - protected String apiVersionFmt = null; - protected HashMap<String, String> generatedJavaType = new HashMap<String, String>(); - protected HashMap<String, String> appliedPaths = new HashMap<String, String>(); - protected NodeList javaTypeNodes = null; - - protected Map<String,String> javaTypeDefinitions = createJavaTypeDefinitions(); - private Map<String, String> createJavaTypeDefinitions() - { - StringBuffer aaiInternal = new StringBuffer(); - StringBuffer nodes = new StringBuffer(); - Map<String,String> javaTypeDefinitions = new HashMap<String, String>(); - aaiInternal.append(" aai-internal:\n"); - aaiInternal.append(" properties:\n"); - aaiInternal.append(" property-name:\n"); - aaiInternal.append(" type: string\n"); - aaiInternal.append(" property-value:\n"); - aaiInternal.append(" type: string\n"); -// javaTypeDefinitions.put("aai-internal", aaiInternal.toString()); - nodes.append(" nodes:\n"); - nodes.append(" properties:\n"); - nodes.append(" inventory-item-data:\n"); - nodes.append(" type: array\n"); - nodes.append(" items:\n"); - nodes.append(" $ref: \"#/definitions/inventory-item-data\"\n"); - javaTypeDefinitions.put("nodes", nodes.toString()); - return javaTypeDefinitions; + public static final String LINE_SEPARATOR = System.getProperty("line.separator"); + 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 + protected static int annotationsMinVersion = 6; // lower versions support annotations in xsd + protected static int swaggerSupportStartsVersion = 1; // minimum version to support swagger + // 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(); + protected Set<String> namespaceFilter; + protected File oxmFile; + protected String xml; + protected SchemaVersion v; + protected Document doc = null; + protected String apiVersion = null; + protected SchemaVersions schemaVersions; + protected Map combinedJavaTypes; + protected String apiVersionFmt = null; + protected List<String> topLevelPaths = new ArrayList<String>(); + protected HashMap<String, String> generatedJavaType = new HashMap<String, String>(); + protected HashMap<String, String> appliedPaths = new HashMap<String, String>(); + protected NodeList javaTypeNodes = null; + protected Map<String, String> javaTypeDefinitions = createJavaTypeDefinitions(); + EdgeIngestor ei; + NodeIngestor ni; + + public OxmFileProcessor(SchemaVersions schemaVersions, NodeIngestor ni, EdgeIngestor ei) { + this.schemaVersions = schemaVersions; + this.ni = ni; + this.ei = ei; } - static List<String> nodeFilter = createNodeFilter(); - private static List<String> createNodeFilter() - { - List<String> list = Arrays.asList("search", "actions", "aai-internal", "nodes"); - return list; - } - - public OxmFileProcessor(SchemaVersions schemaVersions, NodeIngestor ni, EdgeIngestor ei){ - this.schemaVersions = schemaVersions; - this.ni = ni; - this.ei = ei; - } + private static List<String> createNodeFilter() { + List<String> list = Arrays.asList("search", "actions", "aai-internal", "nodes"); + return list; + } + private Map<String, String> createJavaTypeDefinitions() { + StringBuffer aaiInternal = new StringBuffer(); + StringBuffer nodes = new StringBuffer(); + 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); + // 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); + javaTypeDefinitions.put("nodes", nodes.toString()); + return javaTypeDefinitions; + } - public void setOxmVersion(File oxmFile, SchemaVersion v) { - this.oxmFile = oxmFile; - this.v = v; - } + public void setOxmVersion(File oxmFile, SchemaVersion v) { + this.oxmFile = oxmFile; + this.v = v; + } - public void setXmlVersion(String xml, SchemaVersion v) { - this.xml = xml; - this.v = v; - } + public void setXmlVersion(String xml, SchemaVersion v) { + this.xml = xml; + this.v = v; + } - public void setVersion(SchemaVersion v) { - this.oxmFile = null; - this.v = v; - } + public void setVersion(SchemaVersion v) { + this.oxmFile = null; + this.v = v; + } - public void setNodeIngestor(NodeIngestor ni) { - this.ni = ni; - } + public void setNodeIngestor(NodeIngestor ni) { + this.ni = ni; + } public void setEdgeIngestor(EdgeIngestor ei) { - this.ei = ei; - } + this.ei = ei; + } public SchemaVersions getSchemaVersions() { - return schemaVersions; - } - - public void setSchemaVersions(SchemaVersions schemaVersions) { - this.schemaVersions = schemaVersions; - } - - protected void init() throws ParserConfigurationException, SAXException, IOException, EdgeRuleNotFoundException { - if(this.xml != null || this.oxmFile != null ) { - createDocument(); - } - if(this.doc == null) { - this.doc = ni.getSchema(v); - } - namespaceFilter = new HashSet<>(); - - NodeList bindingsNodes = doc.getElementsByTagName("xml-bindings"); - Element bindingElement; - NodeList javaTypesNodes; - Element javaTypesElement; - - if ( bindingsNodes == null || bindingsNodes.getLength() == 0 ) { - throw new SAXException("OXM file error: missing <binding-nodes> in " + oxmFile); - } - - bindingElement = (Element) bindingsNodes.item(0); - javaTypesNodes = bindingElement.getElementsByTagName("java-types"); - if ( javaTypesNodes.getLength() < 1 ) { - throw new SAXException("OXM file error: missing <binding-nodes><java-types> in " + oxmFile); - } - javaTypesElement = (Element) javaTypesNodes.item(0); - - javaTypeNodes = javaTypesElement.getElementsByTagName("java-type"); - if ( javaTypeNodes.getLength() < 1 ) { - throw new SAXException("OXM file error: missing <binding-nodes><java-types><java-type> in " + oxmFile ); - } - } - - private void createDocument() throws ParserConfigurationException, SAXException, IOException { - DocumentBuilder dBuilder = null; - try { - DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); - dbFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); - dBuilder = dbFactory.newDocumentBuilder(); - } catch (ParserConfigurationException e) { - throw e; - } - 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(); - public abstract String process() throws ParserConfigurationException, SAXException, IOException, FileNotFoundException, EdgeRuleNotFoundException ; - - public String getXMLRootElementName(Element javaTypeElement) { - String xmlRootElementName=null; - NamedNodeMap attributes; - - NodeList valNodes = javaTypeElement.getElementsByTagName("xml-root-element"); - Element valElement = (Element) valNodes.item(0); - attributes = valElement.getAttributes(); - for ( int i = 0; i < attributes.getLength(); ++i ) { + return schemaVersions; + } + + public void setSchemaVersions(SchemaVersions schemaVersions) { + this.schemaVersions = schemaVersions; + } + + protected void getTopLevelPaths(XSDElement elem) { + NodeList parentNodes; + Element parentElement; + NodeList xmlElementNodes; + + parentNodes = elem.getElementsByTagName("java-attributes"); + if (parentNodes.getLength() == 0) { + return; + } + parentElement = (Element) parentNodes.item(0); + xmlElementNodes = parentElement.getElementsByTagName("xml-element"); + if (xmlElementNodes.getLength() <= 0) { + return; + } + + XSDElement xmlElementElement; + + for (int i = 0; i < xmlElementNodes.getLength(); ++i) { + xmlElementElement = new XSDElement((Element) xmlElementNodes.item(i)); + if (!xmlElementElement.getParentNode().isSameNode(parentElement)) { + continue; + } + String topLevel = xmlElementElement.getAttribute("type"); + topLevel = topLevel.substring(topLevel.lastIndexOf('.') + 1); + if (!topLevelPaths.contains(topLevel)) { + if ("Nodes".equals(topLevel) || "AaiInternal".equals(topLevel)) { + continue; + } + topLevelPaths.add(topLevel); + } + } + } + + 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. + if (ignoreActionsSearch) { + if ("Actions".equals(topLevel) || "Search".equals(topLevel)) { + return false; + } + } + if (topLevelPaths.contains(topLevel)) { + return true; + } + return false; + } + + protected void init() + throws ParserConfigurationException, SAXException, IOException, EdgeRuleNotFoundException { + if (this.xml != null || this.oxmFile != null) { + createDocument(); + } + if (this.doc == null) { + this.doc = ni.getSchema(v); + } + namespaceFilter = new HashSet<>(); + + NodeList bindingsNodes = doc.getElementsByTagName("xml-bindings"); + Element bindingElement; + NodeList javaTypesNodes; + Element javaTypesElement; + + if (bindingsNodes == null || bindingsNodes.getLength() == 0) { + throw new SAXException("OXM file error: missing <binding-nodes> in " + oxmFile); + } + + bindingElement = (Element) bindingsNodes.item(0); + javaTypesNodes = bindingElement.getElementsByTagName("java-types"); + if (javaTypesNodes.getLength() < 1) { + throw new SAXException( + "OXM file error: missing <binding-nodes><java-types> in " + oxmFile); + } + javaTypesElement = (Element) javaTypesNodes.item(0); + + javaTypeNodes = javaTypesElement.getElementsByTagName("java-type"); + if (javaTypeNodes.getLength() < 1) { + throw new SAXException( + "OXM file error: missing <binding-nodes><java-types><java-type> in " + oxmFile); + } + } + + private void createDocument() throws ParserConfigurationException, SAXException, IOException { + DocumentBuilder dBuilder = null; + try { + DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); + dbFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); + dBuilder = dbFactory.newDocumentBuilder(); + } catch (ParserConfigurationException e) { + throw e; + } + 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(); + + public abstract String process() throws ParserConfigurationException, SAXException, IOException, + FileNotFoundException, EdgeRuleNotFoundException; + + public String getXMLRootElementName(Element javaTypeElement) { + String xmlRootElementName = null; + NamedNodeMap attributes; + + NodeList valNodes = javaTypeElement.getElementsByTagName("xml-root-element"); + Element valElement = (Element) valNodes.item(0); + attributes = valElement.getAttributes(); + for (int i = 0; i < attributes.getLength(); ++i) { Attr attr = (Attr) attributes.item(i); String attrName = attr.getNodeName(); String attrValue = attr.getNodeValue(); - if ( attrName.equals("name")) - xmlRootElementName = attrValue; - } - return xmlRootElementName; - } - - public String getXmlRootElementName( String javaTypeName ) - { - String attrName, attrValue; - Attr attr; - Element javaTypeElement; - 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)) { - NodeList valNodes = javaTypeElement.getElementsByTagName("xml-root-element"); - Element valElement = (Element) valNodes.item(0); - attributes = valElement.getAttributes(); - for ( int k = 0; k < attributes.getLength(); ++k ) { - attr = (Attr) attributes.item(k); - attrName = attr.getNodeName(); - - attrValue = attr.getNodeValue(); - if ( attrName.equals("name")) - return (attrValue); - } - } - } - } - return null; - } - - public Map getCombinedJavaTypes() { - return combinedJavaTypes; - } - - public void setCombinedJavaTypes(Map combinedJavaTypes) { - this.combinedJavaTypes = combinedJavaTypes; - } - - public Element getJavaTypeElementSwagger( String javaTypeName ) - { - - 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)) { - combineElementList.add(javaTypeElement); - } - } - } - if ( combineElementList.size() == 0 ) { - return (Element) null; - } else if ( combineElementList.size() > 1 ) { - return combineElements( javaTypeName, combineElementList); - } - return combineElementList.get(0); - } - - public boolean versionSupportsSwaggerDiff( String version) { - int ver = new Integer(version.substring(1)).intValue(); - if ( ver >= HTMLfromOXM.swaggerDiffStartVersion ) { - return true; - } - return false; - } - - public boolean versionSupportsBasePathProperty( String version) { - int ver = new Integer(version.substring(1)).intValue(); - if ( ver <= HTMLfromOXM.swaggerMinBasepath ) { - return true; - } - return false; - } - - protected void updateParentXmlElements(Element parentElement, NodeList moreXmlElementNodes) { - Element xmlElement; - NodeList childNodes; - Node childNode; - - Node refChild = null; - // find childNode with attributes and no children, insert children before that node - childNodes = parentElement.getChildNodes(); - if ( childNodes == null || childNodes.getLength() == 0 ) { - // should not happen since the base parent was chosen if it had children - return; - } - - for ( int i = 0; i < childNodes.getLength(); ++i ) { - refChild = childNodes.item(i); - if ( refChild.hasAttributes() && !refChild.hasChildNodes()) { - break; - } - - } - - for ( int i = 0; i < moreXmlElementNodes.getLength(); ++i ) { - xmlElement = (Element)moreXmlElementNodes.item(i); - childNode = xmlElement.cloneNode(true); - parentElement.insertBefore(childNode, refChild); - } - } - - protected Node getXmlPropertiesNode(Element javaTypeElement ) { - NodeList nl = javaTypeElement.getChildNodes(); - Node child; - for ( int i = 0; i < nl.getLength(); ++i ) { - child = nl.item(i); - if ( "xml-properties".equals(child.getNodeName())) { - return child; - } - } - return null; - } - - protected Node merge( NodeList nl, Node mergeNode ) { - NamedNodeMap nnm = mergeNode.getAttributes(); - Node childNode; - NamedNodeMap childNnm; - - String mergeName = nnm.getNamedItem("name").getNodeValue(); - String mergeValue = nnm.getNamedItem("value").getNodeValue(); - String childName; - String childValue; - for ( int j = 0; j < nl.getLength(); ++j ) { - childNode = nl.item(j); - if ( "xml-property".equals(childNode.getNodeName())) { - childNnm = childNode.getAttributes(); - childName = childNnm.getNamedItem("name").getNodeValue(); - childValue = childNnm.getNamedItem("value").getNodeValue(); - if ( childName.equals(mergeName)) { - // attribute exists - // keep, replace or update - if ( childValue.contains(mergeValue) ) { - return null; - } - if ( mergeValue.contains(childValue) ) { - childNnm.getNamedItem("value").setTextContent(mergeValue); - return null; - } - childNnm.getNamedItem("value").setTextContent(mergeValue + "," + childValue); - return null; - } - } - } - childNode = mergeNode.cloneNode(true); - return childNode; - } - - protected void mergeXmlProperties(Node useChildProperties, NodeList propertiesToMerge ) { - NodeList nl = useChildProperties.getChildNodes(); - Node childNode; - Node newNode; - for ( int i = 0; i < propertiesToMerge.getLength(); ++i ) { - childNode = propertiesToMerge.item(i); - if ( "xml-property".equals(childNode.getNodeName()) ) { - newNode = merge(nl, childNode); - if ( newNode != null ) { - useChildProperties.appendChild(newNode); - } - } - - } - } - - protected void combineXmlProperties(int useElement, List<Element> combineElementList) { - // add or update xml-properties to the referenced element from the combined list - Element javaTypeElement = combineElementList.get(useElement); - NodeList nl = javaTypeElement.getChildNodes(); - Node useChildProperties = getXmlPropertiesNode( javaTypeElement); - int cloneChild = -1; - Node childProperties; - if ( useChildProperties == null ) { - // find xml-properties to clone - for ( int i = 0; i < combineElementList.size(); ++i ) { - if ( i == useElement ) { - continue; - } - childProperties = getXmlPropertiesNode(combineElementList.get(i)); - if ( childProperties != null ) { - useChildProperties = childProperties.cloneNode(true); - javaTypeElement.appendChild(useChildProperties); - cloneChild = i; - } - } - } - NodeList cnl; - // find other xml-properties - for ( int i = 0; i < combineElementList.size(); ++i ) { - if ( i == useElement|| ( cloneChild >= 0 && i <= cloneChild )) { - continue; - } - childProperties = getXmlPropertiesNode(combineElementList.get(i)); - if ( childProperties == null ) { - continue; - } - cnl = childProperties.getChildNodes(); - mergeXmlProperties( useChildProperties, cnl); - } - - } - - protected Element combineElements( String javaTypeName, List<Element> combineElementList ) { - Element javaTypeElement; - NodeList parentNodes; - Element parentElement = null; - NodeList xmlElementNodes; - - int useElement = -1; - if ( combinedJavaTypes.containsKey( javaTypeName) ) { - return combineElementList.get((int)combinedJavaTypes.get(javaTypeName)); - } - for ( int i = 0; i < combineElementList.size(); ++i ) { - javaTypeElement = combineElementList.get(i); - parentNodes = javaTypeElement.getElementsByTagName("java-attributes"); - if ( parentNodes.getLength() == 0 ) { - continue; - } - parentElement = (Element)parentNodes.item(0); - xmlElementNodes = parentElement.getElementsByTagName("xml-element"); - if ( xmlElementNodes.getLength() <= 0 ) { - continue; - } - useElement = i; - break; - } - boolean doCombineElements = true; - if ( useElement < 0 ) { - useElement = 0; - doCombineElements = false; - } else if ( useElement == combineElementList.size() - 1) { - doCombineElements = false; - } - if ( doCombineElements ) { - // get xml-element from other javaTypeElements - Element otherParentElement = null; - for ( int i = 0; i < combineElementList.size(); ++i ) { - if ( i == useElement ) { - continue; - } - javaTypeElement = combineElementList.get(i); - parentNodes = javaTypeElement.getElementsByTagName("java-attributes"); - if ( parentNodes.getLength() == 0 ) { - continue; - } - otherParentElement = (Element)parentNodes.item(0); - xmlElementNodes = otherParentElement.getElementsByTagName("xml-element"); - if ( xmlElementNodes.getLength() <= 0 ) { - continue; - } - // xml-element that are not present - updateParentXmlElements( parentElement, xmlElementNodes); - - } - } - // need to combine xml-properties - combineXmlProperties(useElement, combineElementList ); - combinedJavaTypes.put( javaTypeName, useElement); - return combineElementList.get(useElement); - } + if (attrName.equals("name")) { + xmlRootElementName = attrValue; + } + } + return xmlRootElementName; + } + + public String getXmlRootElementName(String javaTypeName) { + String attrName, attrValue; + Attr attr; + Element javaTypeElement; + 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)) { + NodeList valNodes = javaTypeElement.getElementsByTagName("xml-root-element"); + Element valElement = (Element) valNodes.item(0); + attributes = valElement.getAttributes(); + for (int k = 0; k < attributes.getLength(); ++k) { + attr = (Attr) attributes.item(k); + attrName = attr.getNodeName(); + + attrValue = attr.getNodeValue(); + if (attrName.equals("name")) { + return (attrValue); + } + } + } + } + } + return null; + } + + public Map getCombinedJavaTypes() { + return combinedJavaTypes; + } + + public void setCombinedJavaTypes(Map combinedJavaTypes) { + this.combinedJavaTypes = combinedJavaTypes; + } + + public Element getJavaTypeElementSwagger(String javaTypeName) { + + 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)) { + combineElementList.add(javaTypeElement); + } + } + } + if (combineElementList.size() == 0) { + return (Element) null; + } else if (combineElementList.size() > 1) { + return combineElements(javaTypeName, combineElementList); + } + return combineElementList.get(0); + } + + public boolean versionSupportsSwaggerDiff(String version) { + int ver = new Integer(version.substring(1)).intValue(); + if (ver >= HTMLfromOXM.swaggerDiffStartVersion) { + return true; + } + return false; + } + + public boolean versionSupportsBasePathProperty(String version) { + int ver = new Integer(version.substring(1)).intValue(); + if (ver <= HTMLfromOXM.swaggerMinBasepath) { + return true; + } + return false; + } + + protected void updateParentXmlElements(Element parentElement, NodeList moreXmlElementNodes) { + Element xmlElement; + NodeList childNodes; + Node childNode; + + Node refChild = null; + // find childNode with attributes and no children, insert children before that node + childNodes = parentElement.getChildNodes(); + if (childNodes == null || childNodes.getLength() == 0) { + // should not happen since the base parent was chosen if it had children + return; + } + + for (int i = 0; i < childNodes.getLength(); ++i) { + refChild = childNodes.item(i); + if (refChild.hasAttributes() && !refChild.hasChildNodes()) { + break; + } + + } + + for (int i = 0; i < moreXmlElementNodes.getLength(); ++i) { + xmlElement = (Element) moreXmlElementNodes.item(i); + childNode = xmlElement.cloneNode(true); + parentElement.insertBefore(childNode, refChild); + } + } + + protected Node getXmlPropertiesNode(Element javaTypeElement) { + NodeList nl = javaTypeElement.getChildNodes(); + Node child; + for (int i = 0; i < nl.getLength(); ++i) { + child = nl.item(i); + if ("xml-properties".equals(child.getNodeName())) { + return child; + } + } + return null; + } + + protected Node merge(NodeList nl, Node mergeNode) { + NamedNodeMap nnm = mergeNode.getAttributes(); + Node childNode; + NamedNodeMap childNnm; + + String mergeName = nnm.getNamedItem("name").getNodeValue(); + String mergeValue = nnm.getNamedItem("value").getNodeValue(); + String childName; + String childValue; + for (int j = 0; j < nl.getLength(); ++j) { + childNode = nl.item(j); + if ("xml-property".equals(childNode.getNodeName())) { + childNnm = childNode.getAttributes(); + childName = childNnm.getNamedItem("name").getNodeValue(); + childValue = childNnm.getNamedItem("value").getNodeValue(); + if (childName.equals(mergeName)) { + // attribute exists + // keep, replace or update + if (childValue.contains(mergeValue)) { + return null; + } + if (mergeValue.contains(childValue)) { + childNnm.getNamedItem("value").setTextContent(mergeValue); + return null; + } + childNnm.getNamedItem("value").setTextContent(mergeValue + "," + childValue); + return null; + } + } + } + childNode = mergeNode.cloneNode(true); + return childNode; + } + + protected void mergeXmlProperties(Node useChildProperties, NodeList propertiesToMerge) { + NodeList nl = useChildProperties.getChildNodes(); + Node childNode; + Node newNode; + for (int i = 0; i < propertiesToMerge.getLength(); ++i) { + childNode = propertiesToMerge.item(i); + if ("xml-property".equals(childNode.getNodeName())) { + newNode = merge(nl, childNode); + if (newNode != null) { + useChildProperties.appendChild(newNode); + } + } + + } + } + + protected void combineXmlProperties(int useElement, List<Element> combineElementList) { + // add or update xml-properties to the referenced element from the combined list + Element javaTypeElement = combineElementList.get(useElement); + NodeList nl = javaTypeElement.getChildNodes(); + Node useChildProperties = getXmlPropertiesNode(javaTypeElement); + int cloneChild = -1; + Node childProperties; + if (useChildProperties == null) { + // find xml-properties to clone + for (int i = 0; i < combineElementList.size(); ++i) { + if (i == useElement) { + continue; + } + childProperties = getXmlPropertiesNode(combineElementList.get(i)); + if (childProperties != null) { + useChildProperties = childProperties.cloneNode(true); + javaTypeElement.appendChild(useChildProperties); + cloneChild = i; + } + } + } + NodeList cnl; + // find other xml-properties + for (int i = 0; i < combineElementList.size(); ++i) { + if (i == useElement || (cloneChild >= 0 && i <= cloneChild)) { + continue; + } + childProperties = getXmlPropertiesNode(combineElementList.get(i)); + if (childProperties == null) { + continue; + } + cnl = childProperties.getChildNodes(); + mergeXmlProperties(useChildProperties, cnl); + } + + } + + protected Element combineElements(String javaTypeName, List<Element> combineElementList) { + Element javaTypeElement; + NodeList parentNodes; + Element parentElement = null; + NodeList xmlElementNodes; + + int useElement = -1; + if (combinedJavaTypes.containsKey(javaTypeName)) { + return combineElementList.get((int) combinedJavaTypes.get(javaTypeName)); + } + for (int i = 0; i < combineElementList.size(); ++i) { + javaTypeElement = combineElementList.get(i); + parentNodes = javaTypeElement.getElementsByTagName("java-attributes"); + if (parentNodes.getLength() == 0) { + continue; + } + parentElement = (Element) parentNodes.item(0); + xmlElementNodes = parentElement.getElementsByTagName("xml-element"); + if (xmlElementNodes.getLength() <= 0) { + continue; + } + useElement = i; + break; + } + boolean doCombineElements = true; + if (useElement < 0) { + useElement = 0; + doCombineElements = false; + } else if (useElement == combineElementList.size() - 1) { + doCombineElements = false; + } + if (doCombineElements) { + // get xml-element from other javaTypeElements + Element otherParentElement = null; + for (int i = 0; i < combineElementList.size(); ++i) { + if (i == useElement) { + continue; + } + javaTypeElement = combineElementList.get(i); + parentNodes = javaTypeElement.getElementsByTagName("java-attributes"); + if (parentNodes.getLength() == 0) { + continue; + } + otherParentElement = (Element) parentNodes.item(0); + xmlElementNodes = otherParentElement.getElementsByTagName("xml-element"); + if (xmlElementNodes.getLength() <= 0) { + continue; + } + // xml-element that are not present + updateParentXmlElements(parentElement, xmlElementNodes); + + } + } + // need to combine xml-properties + combineXmlProperties(useElement, combineElementList); + combinedJavaTypes.put(javaTypeName, useElement); + return combineElementList.get(useElement); + } } 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 6e2af57..45e2ea3 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 @@ -8,7 +8,7 @@ * 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 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -45,546 +45,633 @@ 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(); - 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) + "/aai_swagger_yaml"; - private StringBuilder inventoryDefSb = null; - - - private String basePath; - - public YAMLfromOXM(String basePath, SchemaVersions schemaVersions, NodeIngestor ni, EdgeIngestor ei){ - super(schemaVersions, ni,ei); - this.basePath = basePath; - } - public void setOxmVersion(File oxmFile, SchemaVersion v) { - super.setOxmVersion(oxmFile, v); - } - public void setXmlVersion(String xml, SchemaVersion v){ - super.setXmlVersion(xml, v); - } - - public void setVersion(SchemaVersion v) { - super.setVersion(v); - } - - @Override - public String getDocumentHeader() { - StringBuffer sb = new StringBuffer(); - sb.append("swagger: \"2.0\"\ninfo:\n "); - sb.append("description: |"); - if ( versionSupportsSwaggerDiff(v.toString())) { - sb.append("\n\n [Differences versus the previous schema version](" + "apidocs/aai_swagger_" + v.toString() + ".diff)"); - } - sb.append("\n\n 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.\n\n You may obtain a copy of the License at\n\n (https://creativecommons.org/licenses/by/4.0/)\n\n 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.\n version: \"" + v.toString() +"\"\n"); - sb.append(" title: Active and Available Inventory REST API\n"); - sb.append(" license:\n name: Apache 2.0\n url: http://www.apache.org/licenses/LICENSE-2.0.html\n"); - sb.append(" contact:\n name:\n url:\n email:\n"); - sb.append("host:\nbasePath: " + basePath + "/" + v.toString() + "\n"); - sb.append("schemes:\n - https\npaths:\n"); - return sb.toString(); - } - - protected void init() throws ParserConfigurationException, SAXException, IOException, FileNotFoundException, EdgeRuleNotFoundException { - super.init(); - } - - @Override - public String process() throws ParserConfigurationException, SAXException, IOException, FileNotFoundException, EdgeRuleNotFoundException { - StringBuffer sb = new StringBuffer(); - StringBuffer pathSb = new StringBuffer(); - try { - init(); - } catch(Exception e) { - logger.error( "Error initializing " + this.getClass(),e); - throw e; - } - pathSb.append(getDocumentHeader()); - StringBuffer definitionsSb = new StringBuffer(); - 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(getXmlRootElementName(javaTypeName) ) ) { - continue; - } - // will combine all matching java-types - elem = getJavaTypeElementSwagger(javaTypeName ); - } - - XSDElement javaTypeElement = new XSDElement(elem); - if ( javaTypeName == null ) { - String msg = "Invalid OXM file: <java-type> has no name attribute in " + oxmFile; - logger.error(msg); - throw new SAXException(msg); - } - namespaceFilter.add(getXmlRootElementName(javaTypeName)); - processJavaTypeElementSwagger( javaTypeName, javaTypeElement, pathSb, - definitionsSb, null, null, null, null, null, null); - } - sb.append(pathSb); - - sb.append(appendDefinitions()); - PutRelationPathSet prp = new PutRelationPathSet(v); - prp.generateRelations(ei); - return sb.toString(); - } - - public String appendDefinitions() { - return appendDefinitions(null); - } - - public String appendDefinitions(Set<String> namespaceFilter) { - //append definitions - if ( inventoryDefSb != null ) { - javaTypeDefinitions.put("inventory", inventoryDefSb.toString()); - } - StringBuffer sb = new StringBuffer("definitions:\n"); - Map<String, String> sortedJavaTypeDefinitions = new TreeMap<String, String>(javaTypeDefinitions); - for (Map.Entry<String, String> entry : sortedJavaTypeDefinitions.entrySet()) { -// logger.info("Key: "+entry.getKey()+"Value: "+ entry.getValue()); - if(namespaceFilter != null && entry.getKey().matches("service-capabilities")) { - for(String tally : namespaceFilter) { logger.debug("Marker: "+tally);} - } - 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()); - } - - sb.append("patchDefinitions:\n"); - for (Map.Entry<String, String> entry : sortedJavaTypeDefinitions.entrySet()) { - if(namespaceFilter != null && (! namespaceFilter.contains(entry.getKey()))) { - continue; - } - String jb=entry.getValue().replaceAll("/definitions/", "/patchDefinitions/"); - int ndx=jb.indexOf("relationship-list:"); - if(ndx > 0) { - jb=jb.substring(0, ndx); - jb=jb.replaceAll(" +$", ""); - } - int ndx1=jb.indexOf("resource-version:"); - logger.debug("Key: "+entry.getKey()+" index: " + ndx1); - logger.debug("Value: "+jb); - if(ndx1 > 0) { - jb=jb.substring(0, ndx1); - jb=jb.replaceAll(" +$", ""); - } - logger.debug("Value-after: "+jb); - sb.append(jb); - } - - sb.append("getDefinitions:\n"); - for (Map.Entry<String, String> entry : sortedJavaTypeDefinitions.entrySet()) { - if(namespaceFilter != null && (! namespaceFilter.contains(entry.getKey()))) { - continue; - } - String jb=entry.getValue().replaceAll("/definitions/", "/getDefinitions/"); - sb.append(jb); - } - 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, - String getItemName, StringBuffer pathParams, String validEdges) { - - String xmlRootElementName = getXMLRootElementName(javaTypeElement); - StringBuilder definitionsLocalSb = new StringBuilder(256); - - String useTag = null; - String useOpId = null; - logger.debug("tag="+tag); - if ( tag != null ) { - switch ( tag ) { - case "Network": - case "ServiceDesignAndCreation": - case "Business": - case "LicenseManagement": - case "CloudInfrastructure": - case "Common": - break; - default: - logger.debug("javaTypeName="+javaTypeName); - return null; - } - } - - if ( !javaTypeName.equals("Inventory") ) { - if ( javaTypeName.equals("AaiInternal")) - return null; - if ( opId == null ) - useOpId = javaTypeName; - else - useOpId = opId + javaTypeName; - if ( tag == null ) - useTag = javaTypeName; - } - path = xmlRootElementName.equals("inventory") ? "" : (path == null) ? "/" + xmlRootElementName : path + "/" + xmlRootElementName; - XSDJavaType javaType = new XSDJavaType(javaTypeElement); - if ( getItemName != null) { - if ( getItemName.equals("array") ) - return javaType.getArrayType(); - else - return javaType.getItemName(); - } - - NodeList parentNodes = javaTypeElement.getElementsByTagName("java-attributes"); - if ( parentNodes.getLength() == 0 ) { - logger.debug( "no java-attributes for java-type " + javaTypeName); - return ""; - } - - String pathDescriptionProperty = javaType.getPathDescriptionProperty(); - String container = javaType.getContainerProperty(); - Vector<String> indexedProps = javaType.getIndexedProps(); - Vector<String> containerProps = new Vector<String>(); - if(container != null) { - logger.debug("javaTypeName " + javaTypeName + " container:" + container +" indexedProps:"+indexedProps); - } - - Element parentElement = (Element)parentNodes.item(0); - NodeList xmlElementNodes = parentElement.getElementsByTagName("xml-element"); - - StringBuffer sbParameters = new StringBuffer(); - StringBuffer sbRequired = new StringBuffer(); - int requiredCnt = 0; - int propertyCnt = 0; - StringBuffer sbProperties = new StringBuffer(); - - if ( appliedPaths.containsKey(path)) - return null; - - StringTokenizer st = new StringTokenizer(path, "/"); - logger.debug("path: " + path + " st? " + st.toString()); - if ( st.countTokens() > 1 && getItemName == null ) { - logger.debug("appliedPaths: " + appliedPaths + " containsKey? " + appliedPaths.containsKey(path)); - appliedPaths.put(path, xmlRootElementName); - } - - Vector<String> addTypeV = null; - for ( int i = 0; i < xmlElementNodes.getLength(); ++i ) { - XSDElement xmlElementElement = new XSDElement((Element)xmlElementNodes.item(i)); - if ( !xmlElementElement.getParentNode().isSameNode(parentElement)) - continue; - String elementDescription=xmlElementElement.getPathDescriptionProperty(); - if(getItemName == null) { - addTypeV = xmlElementElement.getAddTypes(v.toString()); - } - if ( "true".equals(xmlElementElement.getAttribute("xml-key"))) { - path += "/{" + xmlElementElement.getAttribute("name") + "}"; - } - logger.debug("path: " + path); - logger.debug( "xmlElementElement.getAttribute(required):"+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"); - } else { - for ( int k = 0; k < addTypeV.size(); ++k ) { - sbRequired.append(" - " + getXmlRootElementName(addTypeV.elementAt(k)) + ":\n"); - } - } - } - - if ( "true".equals(xmlElementElement.getAttribute("xml-key")) ) { - sbParameters.append(xmlElementElement.getPathParamYAML(elementDescription)); - } - if ( indexedProps != null - && indexedProps.contains(xmlElementElement.getAttribute("name") ) ) { - containerProps.add(xmlElementElement.getQueryParamYAML()); - GetOperation.addContainerProps(container, containerProps); - } - if ( xmlElementElement.isStandardType()) { - sbProperties.append(xmlElementElement.getTypePropertyYAML()); - ++propertyCnt; - } - - StringBuffer newPathParams = new StringBuffer((pathParams == null ? "" : pathParams.toString())+sbParameters.toString()); - for ( int k = 0; addTypeV != null && k < addTypeV.size(); ++k ) { - String addType = addTypeV.elementAt(k); - namespaceFilter.add(getXmlRootElementName(addType)); - logger.debug("addType: "+ addType); - - if ( opId == null || !opId.contains(addType)) { - processJavaTypeElementSwagger( addType, getJavaTypeElementSwagger(addType), - pathSb, definitionsSb, path, tag == null ? useTag : tag, useOpId, null, - newPathParams, validEdges); - } - // need item name of array - String itemName = processJavaTypeElementSwagger( addType, getJavaTypeElementSwagger(addType), - pathSb, definitionsSb, path, tag == null ? useTag : tag, useOpId, - "array", null, null ); - - if ( itemName != null ) { - if ( addType.equals("AaiInternal") ) { - logger.debug( "addType AaiInternal, skip properties"); - - } else if ( getItemName == null) { - ++propertyCnt; - sbProperties.append(" " + getXmlRootElementName(addType) + ":\n"); - sbProperties.append(" type: array\n items:\n"); - sbProperties.append(" $ref: \"#/definitions/" + (itemName == "" ? "inventory-item-data" : itemName) + "\"\n"); - if ( StringUtils.isNotEmpty(elementDescription) ) - sbProperties.append(" description: " + elementDescription + "\n"); - } - } else { - if ( ("java.util.ArrayList").equals(xmlElementElement.getAttribute("container-type"))) { - // need properties for getXmlRootElementName(addType) - namespaceFilter.add(getXmlRootElementName(addType)); - newPathParams = new StringBuffer((pathParams == null ? "" : pathParams.toString())+sbParameters.toString()); - 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"); - if ( StringUtils.isNotEmpty(elementDescription) ) - sbProperties.append(" description: " + elementDescription + "\n"); - - } else { - //Make sure certain types added to the filter don't appear - if(nodeFilter.contains(getXmlRootElementName(addType))) { - ; - } else { - sbProperties.append(" " + getXmlRootElementName(addType) + ":\n"); - sbProperties.append(" type: object\n"); - sbProperties.append(" $ref: \"#/definitions/" + getXmlRootElementName(addType) + "\"\n"); - } - } - if ( StringUtils.isNotEmpty(elementDescription) ) - sbProperties.append(" description: " + elementDescription + "\n"); - ++propertyCnt; - } - } - } - - if ( sbParameters.toString().length() > 0 ) { - if ( pathParams == null ) - pathParams = new StringBuffer(); - pathParams.append(sbParameters); - } - GetOperation get = new GetOperation(useOpId, xmlRootElementName, tag, path, pathParams == null ? "" : pathParams.toString()); - pathSb.append(get.toString()); - 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); - pathSb.append(put.toString()); - // add PATCH - PatchOperation patch = new PatchOperation(useOpId, xmlRootElementName, tag, path, pathParams == null ? "" : pathParams.toString()); - pathSb.append(patch.toString()); - // add DELETE - DeleteOperation del = new DeleteOperation(useOpId, xmlRootElementName, tag, path, pathParams == null ? "" : pathParams.toString()); - pathSb.append(del.toString()); - if ( generatedJavaType.containsKey(xmlRootElementName) ) { - logger.debug("xmlRootElementName(1)="+xmlRootElementName); - return null; - } - - boolean processingInventoryDef = false; - String dict = null; - if ( xmlRootElementName.equals("inventory")) { - // inventory properties for each oxm to be concatenated - processingInventoryDef = true; - if ( inventoryDefSb == null ) { - inventoryDefSb = new StringBuilder(); - definitionsSb.append(" " + xmlRootElementName + ":\n"); - 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"); - } -// Collection<EdgeDescription> edges = edgeRuleSet.getEdgeRules(xmlRootElementName ); - DeleteFootnoteSet footnotes = new DeleteFootnoteSet(xmlRootElementName); - StringBuffer sbEdge = new StringBuffer(); - LinkedHashSet<String> preventDelete = new LinkedHashSet<String>(); - String prevent=null; - String nodeCaption = new String(" ###### Related Nodes\n"); - try { - EdgeRuleQuery q = new EdgeRuleQuery.Builder(xmlRootElementName).version(v).fromOnly().build(); - Multimap<String, EdgeRule> results = ei.getRules(q); - SortedSet<String> ss=new TreeSet<String>(results.keySet()); - sbEdge.append(nodeCaption); - nodeCaption=""; - for(String key : ss) { - results.get(key).stream().filter((i) -> (i.getFrom().equals(xmlRootElementName) && (! i.isPrivateEdge()))).forEach((i) ->{ logger.info(new String(new StringBuffer(" - 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()); EdgeDescription ed = new EdgeDescription(i); String footnote = ed.getAlsoDeleteFootnote(xmlRootElementName); sbEdge.append(ed.getRelationshipDescription("TO", xmlRootElementName)+footnote+"\n"); if(StringUtils.isNotEmpty(footnote)) footnotes.add(footnote);} ); - results.get(key).stream().filter((i) -> (i.getFrom().equals(xmlRootElementName) && (! i.isPrivateEdge() && i.getPreventDelete().equals("OUT")))).forEach((i) ->{ preventDelete.add(i.getTo().toUpperCase());} ); - } - } catch(Exception e) { - logger.debug("xmlRootElementName: "+xmlRootElementName+" from edge exception\n", e); - } - try { - EdgeRuleQuery q1 = new EdgeRuleQuery.Builder(xmlRootElementName).version(v).toOnly().build(); - Multimap<String, EdgeRule> results = ei.getRules(q1); - SortedSet<String> ss=new TreeSet<String>(results.keySet()); - sbEdge.append(nodeCaption); - for(String key : ss) { - results.get(key).stream().filter((i) -> (i.getTo().equals(xmlRootElementName) && (! i.isPrivateEdge()))).forEach((i) ->{ sbEdge.append(" - FROM "+i.getFrom()); EdgeDescription ed = new EdgeDescription(i); String footnote = ed.getAlsoDeleteFootnote(xmlRootElementName); sbEdge.append(ed.getRelationshipDescription("FROM", xmlRootElementName)+footnote+"\n"); if(StringUtils.isNotEmpty(footnote)) footnotes.add(footnote);} ); - 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())));} ); - results.get(key).stream().filter((i) -> (i.getTo().equals(xmlRootElementName) && (! i.isPrivateEdge() && i.getPreventDelete().equals("IN")))).forEach((i) ->{ preventDelete.add(i.getFrom().toUpperCase());} ); - } - } catch(Exception e) { - logger.debug("xmlRootElementName: "+xmlRootElementName+" to edge exception\n", e); - } - if(preventDelete.size() > 0) { - prevent = xmlRootElementName.toUpperCase()+" cannot be deleted if related to "+String.join(",",preventDelete); - logger.debug(prevent); - } - - if(StringUtils.isNotEmpty(prevent)) { - footnotes.add(prevent); - } - if(footnotes.footnotes.size() > 0) { - sbEdge.append(footnotes.toString()); - } - validEdges = sbEdge.toString(); - - // Handle description property. Might have a description OR valid edges OR both OR neither. - // Only put a description: tag if there is at least one. - if (StringUtils.isNotEmpty(pathDescriptionProperty) || StringUtils.isNotEmpty(validEdges) ) { - definitionsSb.append(" description: |\n"); - definitionsLocalSb.append(" description: |\n"); - - if ( pathDescriptionProperty != null ) { - definitionsSb.append(" " + pathDescriptionProperty + "\n" ); - definitionsLocalSb.append(" " + pathDescriptionProperty + "\n" ); - } - definitionsSb.append(validEdges); - definitionsLocalSb.append(validEdges); - } - - if ( requiredCnt > 0 ) { - definitionsSb.append(sbRequired); - definitionsLocalSb.append(sbRequired); - } - - if ( propertyCnt > 0 ) { - definitionsSb.append(" properties:\n"); - definitionsSb.append(sbProperties); - if ( !processingInventoryDef) { - definitionsLocalSb.append(" properties:\n"); - } - definitionsLocalSb.append(sbProperties); - } - try { - namespaceFilter.add(xmlRootElementName); - 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()); - } - } catch (Exception e) { - e.printStackTrace(); - logger.error("Exception adding in javaTypeDefinitions",e); - } - if ( xmlRootElementName.equals("inventory") ) { - logger.trace("skip xmlRootElementName(2)="+xmlRootElementName); - return null; - } - generatedJavaType.put(xmlRootElementName, null); -/* - if( validTag(javaTypeName) && javaTypeName == useTag && tag == null) { - String nameSpaceResult = getDocumentHeader()+pathSb.toString()+appendDefinitions(namespaceFilter); - writeYAMLfile(javaTypeName, nameSpaceResult); - totalPathSbAccumulator.append(pathSb); - pathSb.delete(0, pathSb.length()); - namespaceFilter.clear(); - } -*/ - logger.trace("xmlRootElementName(2)="+xmlRootElementName); - return null; - } - - 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 : outfileName; - File outfile = new File(outfileName); - File parentDir = outfile.getParentFile(); - if(parentDir != null && ! parentDir.exists()) - parentDir.mkdirs(); - try { - outfile.createNewFile(); - } catch (IOException e) { - logger.error( "Exception creating output file " + outfileName); - e.printStackTrace(); - } - try { - Charset charset = Charset.forName("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(); - } - } - - public boolean validTag(String tag) { - if(tag != null) { - switch ( tag ) { - case "Network": -// case "Search": -// case "Actions": - case "ServiceDesignAndCreation": - case "Business": - case "LicenseManagement": - case "CloudInfrastructure": - case "Common": - return true; - } - } - return false; - } + private static final Logger logger = LoggerFactory.getLogger("YAMLfromOXM.class"); + // private static StringBuffer totalPathSbAccumulator = new StringBuffer(); + 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) + + "/aai_swagger_yaml"; + private StringBuilder inventoryDefSb = null; + + private String basePath; + + public YAMLfromOXM(String basePath, SchemaVersions schemaVersions, NodeIngestor ni, + EdgeIngestor ei) { + super(schemaVersions, ni, ei); + this.basePath = basePath; + } + + public void setOxmVersion(File oxmFile, SchemaVersion v) { + super.setOxmVersion(oxmFile, v); + } + + public void setXmlVersion(String xml, SchemaVersion v) { + super.setXmlVersion(xml, v); + } + + public void setVersion(SchemaVersion v) { + super.setVersion(v); + } + + @Override + public String getDocumentHeader() { + StringBuffer sb = new StringBuffer(); + sb.append("swagger: \"2.0\"\ninfo:" + LINE_SEPARATOR + " "); + sb.append("description: |"); + if (versionSupportsSwaggerDiff(v.toString())) { + sb.append("\n\n [Differences versus the previous schema version](" + + "apidocs/aai_swagger_" + v.toString() + ".diff)"); + } + sb.append( + DOUBLE_LINE_SEPARATOR + " Copyright © 2017-18 AT&T Intellectual Property. All rights reserved." + 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.\n\n You may obtain a copy of the License at\n\n (https://creativecommons.org/licenses/by/4.0/)\n\n 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." + DOUBLE_LINE_SEPARATOR + " 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 ); + 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:" + LINE_SEPARATOR + " url:" + LINE_SEPARATOR + " email:" + LINE_SEPARATOR); + sb.append("host:" + LINE_SEPARATOR + "basePath: " + basePath + "/" + v.toString() + LINE_SEPARATOR); + sb.append("schemes:" + LINE_SEPARATOR + " - https\npaths:" + LINE_SEPARATOR); + return sb.toString(); + } + + protected void init() throws ParserConfigurationException, SAXException, IOException, + FileNotFoundException, EdgeRuleNotFoundException { + super.init(); + } + + @Override + public String process() throws ParserConfigurationException, SAXException, IOException, + FileNotFoundException, EdgeRuleNotFoundException { + StringBuffer sb = new StringBuffer(); + StringBuffer pathSb = new StringBuffer(); + try { + init(); + } catch (Exception e) { + logger.error("Error initializing " + this.getClass(), e); + throw e; + } + pathSb.append(getDocumentHeader()); + StringBuffer definitionsSb = new StringBuffer(); + Element elem; + String javaTypeName; + combinedJavaTypes = new HashMap(); + for (int i = 0; i < javaTypeNodes.getLength(); ++i) { + elem = (Element) javaTypeNodes.item(i); + javaTypeName = elem.getAttribute("name"); + boolean processInventory = false; + if (!"Inventory".equals(javaTypeName)) { + if (generatedJavaType.containsKey(getXmlRootElementName(javaTypeName))) { + continue; + } + // will combine all matching java-types + elem = getJavaTypeElementSwagger(javaTypeName); + } else { + processInventory = true; + } + + XSDElement javaTypeElement = new XSDElement(elem); + + if (processInventory) { + getTopLevelPaths(javaTypeElement); + } + + if (javaTypeName == null) { + String msg = "Invalid OXM file: <java-type> has no name attribute in " + oxmFile; + logger.error(msg); + throw new SAXException(msg); + } + namespaceFilter.add(getXmlRootElementName(javaTypeName)); + processJavaTypeElementSwagger(javaTypeName, javaTypeElement, pathSb, definitionsSb, + null, null, null, null, null, null); + } + sb.append(pathSb); + + sb.append(appendDefinitions()); + PutRelationPathSet prp = new PutRelationPathSet(v); + prp.generateRelations(ei); + return sb.toString(); + } + + public String appendDefinitions() { + return appendDefinitions(null); + } + + public String appendDefinitions(Set<String> namespaceFilter) { + // append definitions + if (inventoryDefSb != null) { + javaTypeDefinitions.put("inventory", inventoryDefSb.toString()); + } + StringBuffer sb = new StringBuffer("definitions:\n"); + Map<String, String> sortedJavaTypeDefinitions = + new TreeMap<String, String>(javaTypeDefinitions); + for (Map.Entry<String, String> entry : sortedJavaTypeDefinitions.entrySet()) { + // logger.info("Key: "+entry.getKey()+"Value: "+ entry.getValue()); + if (namespaceFilter != null && entry.getKey().matches("service-capabilities")) { + for (String tally : namespaceFilter) { + logger.debug("Marker: " + tally); + } + } + 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()); + } + + sb.append("patchDefinitions:\n"); + for (Map.Entry<String, String> entry : sortedJavaTypeDefinitions.entrySet()) { + if (namespaceFilter != null && (!namespaceFilter.contains(entry.getKey()))) { + continue; + } + String jb = entry.getValue().replaceAll("/definitions/", "/patchDefinitions/"); + int ndx = jb.indexOf("relationship-list:"); + if (ndx > 0) { + jb = jb.substring(0, ndx); + jb = jb.replaceAll(" +$", ""); + } + int ndx1 = jb.indexOf("resource-version:"); + logger.debug("Key: " + entry.getKey() + " index: " + ndx1); + logger.debug("Value: " + jb); + if (ndx1 > 0) { + jb = jb.substring(0, ndx1); + jb = jb.replaceAll(" +$", ""); + } + logger.debug("Value-after: " + jb); + sb.append(jb); + } + + sb.append("getDefinitions:\n"); + for (Map.Entry<String, String> entry : sortedJavaTypeDefinitions.entrySet()) { + if (namespaceFilter != null && (!namespaceFilter.contains(entry.getKey()))) { + continue; + } + String jb = entry.getValue().replaceAll("/definitions/", "/getDefinitions/"); + sb.append(jb); + } + 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, + String getItemName, StringBuffer pathParams, String validEdges) { + + String xmlRootElementName = getXMLRootElementName(javaTypeElement); + StringBuilder definitionsLocalSb = new StringBuilder(256); + + String useTag = null; + String useOpId = null; + logger.debug("tag=" + tag); + if (tag != null) { + // 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")) { + return null; + } + if (opId == null) { + useOpId = javaTypeName; + } else { + useOpId = opId + javaTypeName; + } + if (tag == null) { + useTag = javaTypeName; + } + } + path = xmlRootElementName.equals("inventory") ? "" + : (path == null) ? "/" + xmlRootElementName : path + "/" + xmlRootElementName; + XSDJavaType javaType = new XSDJavaType(javaTypeElement); + if (getItemName != null) { + if (getItemName.equals("array")) { + return javaType.getArrayType(); + } else { + return javaType.getItemName(); + } + } + + NodeList parentNodes = javaTypeElement.getElementsByTagName("java-attributes"); + if (parentNodes.getLength() == 0) { + logger.debug("no java-attributes for java-type " + javaTypeName); + return ""; + } + + String pathDescriptionProperty = javaType.getPathDescriptionProperty(); + String container = javaType.getContainerProperty(); + Vector<String> indexedProps = javaType.getIndexedProps(); + Vector<String> containerProps = new Vector<String>(); + if (container != null) { + logger.debug("javaTypeName " + javaTypeName + " container:" + container + + " indexedProps:" + indexedProps); + } + + Element parentElement = (Element) parentNodes.item(0); + NodeList xmlElementNodes = parentElement.getElementsByTagName("xml-element"); + + StringBuffer sbParameters = new StringBuffer(); + StringBuffer sbRequired = new StringBuffer(); + int requiredCnt = 0; + int propertyCnt = 0; + StringBuffer sbProperties = new StringBuffer(); + + if (appliedPaths.containsKey(path)) { + return null; + } + + StringTokenizer st = new StringTokenizer(path, "/"); + logger.debug("path: " + path + " st? " + st.toString()); + if (st.countTokens() > 1 && getItemName == null) { + logger.debug("appliedPaths: " + appliedPaths + " containsKey? " + + appliedPaths.containsKey(path)); + appliedPaths.put(path, xmlRootElementName); + } + + Vector<String> addTypeV = null; + for (int i = 0; i < xmlElementNodes.getLength(); ++i) { + XSDElement xmlElementElement = new XSDElement((Element) xmlElementNodes.item(i)); + if (!xmlElementElement.getParentNode().isSameNode(parentElement)) { + continue; + } + String elementDescription = xmlElementElement.getPathDescriptionProperty(); + if (getItemName == null) { + addTypeV = xmlElementElement.getAddTypes(v.toString()); + } + if ("true".equals(xmlElementElement.getAttribute("xml-key"))) { + path += "/{" + xmlElementElement.getAttribute("name") + "}"; + } + logger.debug("path: " + path); + logger.debug("xmlElementElement.getAttribute(required):" + + 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"); + } else { + for (int k = 0; k < addTypeV.size(); ++k) { + sbRequired.append( + " - " + getXmlRootElementName(addTypeV.elementAt(k)) + ":\n"); + } + } + } + + if ("true".equals(xmlElementElement.getAttribute("xml-key"))) { + sbParameters.append(xmlElementElement.getPathParamYAML(elementDescription)); + } + if (indexedProps != null + && indexedProps.contains(xmlElementElement.getAttribute("name"))) { + containerProps.add(xmlElementElement.getQueryParamYAML()); + GetOperation.addContainerProps(container, containerProps); + } + if (xmlElementElement.isStandardType()) { + sbProperties.append(xmlElementElement.getTypePropertyYAML()); + ++propertyCnt; + } + + StringBuffer newPathParams = new StringBuffer( + (pathParams == null ? "" : pathParams.toString()) + sbParameters.toString()); + for (int k = 0; addTypeV != null && k < addTypeV.size(); ++k) { + String addType = addTypeV.elementAt(k); + namespaceFilter.add(getXmlRootElementName(addType)); + logger.debug("addType: " + addType); + + if (opId == null || !opId.contains(addType)) { + processJavaTypeElementSwagger(addType, getJavaTypeElementSwagger(addType), + pathSb, definitionsSb, path, tag == null ? useTag : tag, useOpId, null, + newPathParams, validEdges); + } + // need item name of array + String itemName = processJavaTypeElementSwagger(addType, + getJavaTypeElementSwagger(addType), pathSb, definitionsSb, path, + tag == null ? useTag : tag, useOpId, "array", null, null); + + if (itemName != null) { + if (addType.equals("AaiInternal")) { + logger.debug("addType AaiInternal, skip properties"); + + } else if (getItemName == null) { + ++propertyCnt; + sbProperties.append(" " + getXmlRootElementName(addType) + ":\n"); + sbProperties.append(" type: array\n items:\n"); + sbProperties.append(" $ref: \"#/definitions/" + + (itemName == "" ? "inventory-item-data" : itemName) + "\"\n"); + if (StringUtils.isNotEmpty(elementDescription)) { + sbProperties + .append(" description: " + elementDescription + "\n"); + } + } + } else { + if (("java.util.ArrayList") + .equals(xmlElementElement.getAttribute("container-type"))) { + // need properties for getXmlRootElementName(addType) + namespaceFilter.add(getXmlRootElementName(addType)); + newPathParams = + new StringBuffer((pathParams == null ? "" : pathParams.toString()) + + sbParameters.toString()); + 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"); + if (StringUtils.isNotEmpty(elementDescription)) { + sbProperties + .append(" description: " + elementDescription + "\n"); + } + + } else { + // Make sure certain types added to the filter don't appear + if (nodeFilter.contains(getXmlRootElementName(addType))) { + ; + } else { + sbProperties.append(" " + getXmlRootElementName(addType) + ":\n"); + sbProperties.append(" type: object\n"); + sbProperties.append(" $ref: \"#/definitions/" + + getXmlRootElementName(addType) + "\"\n"); + } + } + if (StringUtils.isNotEmpty(elementDescription)) { + sbProperties.append(" description: " + elementDescription + "\n"); + } + ++propertyCnt; + } + } + } + + if (sbParameters.toString().length() > 0) { + if (pathParams == null) { + pathParams = new StringBuffer(); + } + pathParams.append(sbParameters); + } + GetOperation get = new GetOperation(useOpId, xmlRootElementName, tag, path, + pathParams == null ? "" : pathParams.toString()); + pathSb.append(get.toString()); + 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); + pathSb.append(put.toString()); + // add PATCH + PatchOperation patch = new PatchOperation(useOpId, xmlRootElementName, tag, path, + pathParams == null ? "" : pathParams.toString()); + pathSb.append(patch.toString()); + // add DELETE + DeleteOperation del = new DeleteOperation(useOpId, xmlRootElementName, tag, path, + pathParams == null ? "" : pathParams.toString()); + pathSb.append(del.toString()); + if (generatedJavaType.containsKey(xmlRootElementName)) { + logger.debug("xmlRootElementName(1)=" + xmlRootElementName); + return null; + } + + boolean processingInventoryDef = false; + String dict = null; + if (xmlRootElementName.equals("inventory")) { + // inventory properties for each oxm to be concatenated + processingInventoryDef = true; + if (inventoryDefSb == null) { + inventoryDefSb = new StringBuilder(); + definitionsSb.append(" " + xmlRootElementName + ":\n"); + 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"); + } + // Collection<EdgeDescription> edges = edgeRuleSet.getEdgeRules(xmlRootElementName ); + DeleteFootnoteSet footnotes = new DeleteFootnoteSet(xmlRootElementName); + StringBuffer sbEdge = new StringBuffer(); + LinkedHashSet<String> preventDelete = new LinkedHashSet<String>(); + String prevent = null; + String nodeCaption = new String(" ###### Related Nodes\n"); + try { + EdgeRuleQuery q = + new EdgeRuleQuery.Builder(xmlRootElementName).version(v).fromOnly().build(); + Multimap<String, EdgeRule> results = ei.getRules(q); + SortedSet<String> ss = new TreeSet<String>(results.keySet()); + sbEdge.append(nodeCaption); + nodeCaption = ""; + for (String key : ss) { + results.get(key).stream() + .filter((i) -> (i.getFrom().equals(xmlRootElementName) && (!i.isPrivateEdge()))) + .forEach((i) -> { + logger.info(new String(new StringBuffer(" - 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()); + EdgeDescription ed = new EdgeDescription(i); + String footnote = ed.getAlsoDeleteFootnote(xmlRootElementName); + sbEdge.append(ed.getRelationshipDescription("TO", xmlRootElementName) + + footnote + "\n"); + if (StringUtils.isNotEmpty(footnote)) { + footnotes.add(footnote); + } + }); + results.get(key).stream() + .filter((i) -> (i.getFrom().equals(xmlRootElementName) + && (!i.isPrivateEdge() && i.getPreventDelete().equals("OUT")))) + .forEach((i) -> { + preventDelete.add(i.getTo().toUpperCase()); + }); + } + } catch (Exception e) { + logger.debug("xmlRootElementName: " + xmlRootElementName + " from edge exception\n", e); + } + try { + EdgeRuleQuery q1 = + new EdgeRuleQuery.Builder(xmlRootElementName).version(v).toOnly().build(); + Multimap<String, EdgeRule> results = ei.getRules(q1); + SortedSet<String> ss = new TreeSet<String>(results.keySet()); + sbEdge.append(nodeCaption); + for (String key : ss) { + results.get(key).stream() + .filter((i) -> (i.getTo().equals(xmlRootElementName) && (!i.isPrivateEdge()))) + .forEach((i) -> { + sbEdge.append(" - FROM " + i.getFrom()); + EdgeDescription ed = new EdgeDescription(i); + String footnote = ed.getAlsoDeleteFootnote(xmlRootElementName); + sbEdge.append(ed.getRelationshipDescription("FROM", xmlRootElementName) + + footnote + "\n"); + if (StringUtils.isNotEmpty(footnote)) { + footnotes.add(footnote); + } + }); + 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()))); + }); + results.get(key).stream() + .filter((i) -> (i.getTo().equals(xmlRootElementName) + && (!i.isPrivateEdge() && i.getPreventDelete().equals("IN")))) + .forEach((i) -> { + preventDelete.add(i.getFrom().toUpperCase()); + }); + } + } catch (Exception e) { + logger.debug("xmlRootElementName: " + xmlRootElementName + " to edge exception\n", e); + } + if (preventDelete.size() > 0) { + prevent = xmlRootElementName.toUpperCase() + " cannot be deleted if related to " + + String.join(",", preventDelete); + logger.debug(prevent); + } + + if (StringUtils.isNotEmpty(prevent)) { + footnotes.add(prevent); + } + if (footnotes.footnotes.size() > 0) { + sbEdge.append(footnotes.toString()); + } + validEdges = sbEdge.toString(); + + // Handle description property. Might have a description OR valid edges OR both OR neither. + // Only put a description: tag if there is at least one. + if (StringUtils.isNotEmpty(pathDescriptionProperty) || StringUtils.isNotEmpty(validEdges)) { + definitionsSb.append(" description: |\n"); + definitionsLocalSb.append(" description: |\n"); + + if (pathDescriptionProperty != null) { + definitionsSb.append(" " + pathDescriptionProperty + "\n"); + definitionsLocalSb.append(" " + pathDescriptionProperty + "\n"); + } + definitionsSb.append(validEdges); + definitionsLocalSb.append(validEdges); + } + + if (requiredCnt > 0) { + definitionsSb.append(sbRequired); + definitionsLocalSb.append(sbRequired); + } + + if (propertyCnt > 0) { + definitionsSb.append(" properties:\n"); + definitionsSb.append(sbProperties); + if (!processingInventoryDef) { + definitionsLocalSb.append(" properties:\n"); + } + definitionsLocalSb.append(sbProperties); + } + try { + namespaceFilter.add(xmlRootElementName); + 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()); + } + } catch (Exception e) { + e.printStackTrace(); + logger.error("Exception adding in javaTypeDefinitions", e); + } + if (xmlRootElementName.equals("inventory")) { + logger.trace("skip xmlRootElementName(2)=" + xmlRootElementName); + return null; + } + generatedJavaType.put(xmlRootElementName, null); + /* + * if( validTag(javaTypeName) && javaTypeName == useTag && tag == null) { + * String nameSpaceResult = + * getDocumentHeader()+pathSb.toString()+appendDefinitions(namespaceFilter); + * writeYAMLfile(javaTypeName, nameSpaceResult); + * totalPathSbAccumulator.append(pathSb); + * pathSb.delete(0, pathSb.length()); + * namespaceFilter.clear(); + * } + */ + logger.trace("xmlRootElementName(2)=" + xmlRootElementName); + return null; + } + + 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 + : outfileName; + File outfile = new File(outfileName); + File parentDir = outfile.getParentFile(); + if (parentDir != null && !parentDir.exists()) { + parentDir.mkdirs(); + } + try { + outfile.createNewFile(); + } catch (IOException e) { + logger.error("Exception creating output file " + outfileName); + e.printStackTrace(); + } + try { + Charset charset = Charset.forName("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(); + } + } + + 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 false; + } } diff --git a/aai-schema-gen/src/main/java/org/onap/aai/schemagen/swagger/Api.java b/aai-schema-gen/src/main/java/org/onap/aai/schemagen/swagger/Api.java index 717b710..a3adcd8 100644 --- a/aai-schema-gen/src/main/java/org/onap/aai/schemagen/swagger/Api.java +++ b/aai-schema-gen/src/main/java/org/onap/aai/schemagen/swagger/Api.java @@ -8,7 +8,7 @@ * 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 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -38,23 +38,23 @@ public class Api { this.httpMethods = httpMethods; } - public String getTag(){ + public String getTag() { - if(this.tag != null){ + if (this.tag != null) { return this.tag; } - if(this.httpMethods != null){ - if(this.httpMethods.size() != 0){ - if(this.httpMethods.get(0).getTags() != null){ - if(this.httpMethods.get(0).getTags().size() != 0){ + if (this.httpMethods != null) { + if (this.httpMethods.size() != 0) { + if (this.httpMethods.get(0).getTags() != null) { + if (this.httpMethods.get(0).getTags().size() != 0) { this.tag = this.httpMethods.get(0).getTags().get(0); } } } } - if(this.tag == null){ + if (this.tag == null) { this.tag = ""; } @@ -63,10 +63,7 @@ public class Api { @Override public String toString() { - return "Api{" + - "path='" + path + '\'' + - ", httpMethods=" + httpMethods + - '}'; + return "Api{" + "path='" + path + '\'' + ", httpMethods=" + httpMethods + '}'; } public void setPath(String path) { @@ -77,9 +74,9 @@ public class Api { return this.path; } - public String getOperation(){ + public String getOperation() { - if(this.path != null){ + if (this.path != null) { return this.path.replaceAll("[^a-zA-Z0-9\\-]", "-") + "-"; } @@ -122,7 +119,7 @@ public class Api { private String returnSchemaObject; - public void setConsumerEnabled(boolean consumerEnabled){ + public void setConsumerEnabled(boolean consumerEnabled) { this.consumerEnabled = consumerEnabled; } @@ -130,7 +127,6 @@ public class Api { return consumerEnabled; } - public List<String> getTags() { return tags; } @@ -197,16 +193,10 @@ public class Api { @Override public String toString() { - return "HttpVerb{" + - "tags=" + tags + - ", type='" + type + '\'' + - ", summary='" + summary + '\'' + - ", operationId='" + operationId + '\'' + - ", consumes=" + consumes + - ", produces=" + produces + - ", responses=" + responses + - ", parameters=" + parameters + - '}'; + return "HttpVerb{" + "tags=" + getTags() + ", type='" + getType() + '\'' + ", summary='" + + getSummary() + '\'' + ", operationId='" + getOperationId() + '\'' + ", consumes=" + + getConsumes() + ", produces=" + getProduces() + ", responses=" + getResponses() + + ", parameters=" + getParameters() + '}'; } public void setParametersEnabled(boolean b) { @@ -220,8 +210,9 @@ public class Api { public boolean isBodyParametersEnabled() { return bodyParametersEnabled; } + public boolean isOpNotPatch() { - return type.equalsIgnoreCase("patch") ? false : true; + return type.equalsIgnoreCase("patch") ? false : true; } public void setBodyParametersEnabled(boolean bodyParametersEnabled) { @@ -282,7 +273,7 @@ public class Api { private String description; - private String version; + private String version; public String getResponseCode() { return responseCode; @@ -302,15 +293,13 @@ public class Api { @Override public String toString() { - return "Response{" + - "responseCode='" + responseCode + '\'' + - ", description='" + description + '\'' + - '}'; + return "Response{" + "responseCode='" + getResponseCode() + '\'' + ", description='" + + getDescription() + '\'' + '}'; } - public void setVersion(String version) { - this.version = version; - } + public void setVersion(String version) { + this.version = version; + } } } diff --git a/aai-schema-gen/src/main/java/org/onap/aai/schemagen/swagger/Definition.java b/aai-schema-gen/src/main/java/org/onap/aai/schemagen/swagger/Definition.java index 4a52020..9df9842 100644 --- a/aai-schema-gen/src/main/java/org/onap/aai/schemagen/swagger/Definition.java +++ b/aai-schema-gen/src/main/java/org/onap/aai/schemagen/swagger/Definition.java @@ -8,7 +8,7 @@ * 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 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemagen.swagger; import java.util.List; @@ -61,11 +62,9 @@ public class Definition { @Override public String toString() { - return "Definition{" + - "definitionName='" + definitionName + '\'' + - ", definitionDescription='" + definitionDescription + '\'' + - ", propertyList=" + propertyList + - '}'; + return "Definition{" + "definitionName='" + getDefinitionName() + '\'' + + ", definitionDescription='" + getDefinitionDescription() + '\'' + ", propertyList=" + + getPropertyList() + '}'; } public boolean isHasDescription() { @@ -112,7 +111,8 @@ public class Definition { private boolean hasPropertyReference; - public Property(){} + public Property() { + } public String getPropertyName() { return propertyName; @@ -140,11 +140,9 @@ public class Definition { @Override public String toString() { - return "Property{" + - "propertyName='" + propertyName + '\'' + - ", propertyType='" + propertyType + '\'' + - ", propertyReference='" + propertyReference + '\'' + - '}'; + return "Property{" + "propertyName='" + getPropertyName() + '\'' + ", propertyType='" + + getPropertyType() + '\'' + ", propertyReference='" + getPropertyReference() + '\'' + + '}'; } public boolean isHasType() { diff --git a/aai-schema-gen/src/test/java/org/onap/aai/schemagen/swagger/ApiHttpVerbResponseTest.java b/aai-schema-gen/src/test/java/org/onap/aai/schemagen/swagger/ApiHttpVerbResponseTest.java new file mode 100644 index 0000000..2a39149 --- /dev/null +++ b/aai-schema-gen/src/test/java/org/onap/aai/schemagen/swagger/ApiHttpVerbResponseTest.java @@ -0,0 +1,84 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2019 Huawei Technologies (Australia) Pty Ltd. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.aai.schemagen.swagger; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +import java.util.Arrays; +import java.util.Collection; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +@RunWith(Parameterized.class) +public class ApiHttpVerbResponseTest { + Api.HttpVerb.Response theResponse = null; + String responseCode; + String description; + String result; + + /** + * Parameters for the test cases all following same pattern. + */ + @Parameters + public static Collection<String[]> testConditions() { + String inputs[][] = {{"200", "OK", "Response{responseCode='200', description='OK'}"}, + {"400", "Bad Request", "Response{responseCode='400', description='Bad Request'}"}, + {"500", "Internal Server Error", + "Response{responseCode='500', description='Internal Server Error'}"}, + {"fake", "random message", + "Response{responseCode='fake', description='random message'}"}}; + return (Arrays.asList(inputs)); + } + + /** + * Constructor for the test cases all following same pattern. + */ + public ApiHttpVerbResponseTest(String responseCode, String description, String result) { + super(); + this.responseCode = responseCode; + this.description = description; + this.result = result; + } + + /** + * Initialise the test object. + */ + @Before + public void setUp() throws Exception { + theResponse = new Api.HttpVerb.Response(); + } + + /** + * Perform the test on the test object. + */ + @Test + public void testApiHttpVerbResponse() { + theResponse.setResponseCode(this.responseCode); + theResponse.setDescription(this.description); + assertThat(theResponse.toString(), is(this.result)); + } + +} diff --git a/aai-schema-gen/src/test/java/org/onap/aai/schemagen/swagger/ApiHttpVerbTest.java b/aai-schema-gen/src/test/java/org/onap/aai/schemagen/swagger/ApiHttpVerbTest.java new file mode 100644 index 0000000..c714d82 --- /dev/null +++ b/aai-schema-gen/src/test/java/org/onap/aai/schemagen/swagger/ApiHttpVerbTest.java @@ -0,0 +1,123 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2019 Huawei Technologies (Australia) Pty Ltd. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.aai.schemagen.swagger; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +@RunWith(Parameterized.class) +public class ApiHttpVerbTest { + Api.HttpVerb theVerb = null; + List<String> tags; + String type; + String summary; + String operationId; + List<String> consumes; + List<String> produces; + String result; + + /** + * Parameters for the test cases all following same pattern. + */ + @Parameters + public static Collection<String[]> testConditions() { + String inputs[][] = {{"tag1,tag2", "typeA", "summaryB", "operationC", "consumesD,consumesE", + "producesF,producesG", + "HttpVerb{tags=[tag1, tag2], type='typeA', summary='summaryB', operationId='operationC', consumes=[consumesD, consumesE], produces=[producesF, producesG], responses=[], parameters=[]}"}, + {"tag11,tag22", "typeAA", "summaryBB", "operationCC", "consumesDD,consumesEE", + "producesFF,producesGG", + "HttpVerb{tags=[tag11, tag22], type='typeAA', summary='summaryBB', operationId='operationCC', consumes=[consumesDD, consumesEE], produces=[producesFF, producesGG], responses=[], parameters=[]}"}}; + return (Arrays.asList(inputs)); + } + + /** + * Constructor for the test cases all following same pattern. + */ + public ApiHttpVerbTest(String tags, String type, String summary, String operationId, + String consumes, String produces, String result) { + super(); + this.tags = Arrays.asList(tags.split(",")); + this.type = type; + this.summary = summary; + this.operationId = operationId; + this.consumes = Arrays.asList(consumes.split(",")); + this.produces = Arrays.asList(produces.split(",")); + this.result = result; + + } + + /** + * Initialise the test object. + */ + @Before + public void setUp() throws Exception { + theVerb = new Api.HttpVerb(); + } + + /** + * Perform the test on the test object. + */ + @Test + public void testApiHttpVerb() { + theVerb.setTags(this.tags); + theVerb.setType(this.type); + theVerb.setSummary(this.summary); + theVerb.setOperationId(this.operationId); + theVerb.setConsumes(this.consumes); + theVerb.setProduces(this.produces); + + // other stuff that can be set but not necessarily + // included in the toString() output + theVerb.setConsumerEnabled(true); + + List<Api.HttpVerb.Response> tmpList1 = new ArrayList<Api.HttpVerb.Response>(); + theVerb.setResponses(tmpList1); + + List<Map<String, Object>> tmpList2 = new ArrayList<Map<String, Object>>(); + theVerb.setParameters(tmpList2); + + Map<String, Object> tmpMap1 = new HashMap<String, Object>(); + theVerb.setBodyParameters(tmpMap1); + theVerb.setBodyParametersEnabled(true); + theVerb.setParametersEnabled(true); + theVerb.setSchemaLink(""); + theVerb.setSchemaType(""); + theVerb.setHasReturnSchema(true); + theVerb.setReturnSchemaLink(""); + theVerb.setReturnSchemaObject(""); + + assertThat(theVerb.toString(), is(this.result)); + } + +} diff --git a/aai-schema-gen/src/test/java/org/onap/aai/schemagen/swagger/DefinitionPropertyTest.java b/aai-schema-gen/src/test/java/org/onap/aai/schemagen/swagger/DefinitionPropertyTest.java new file mode 100644 index 0000000..fef3344 --- /dev/null +++ b/aai-schema-gen/src/test/java/org/onap/aai/schemagen/swagger/DefinitionPropertyTest.java @@ -0,0 +1,108 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2019 Huawei Technologies (Australia) Pty Ltd. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.aai.schemagen.swagger; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +import java.util.Arrays; +import java.util.Collection; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +@RunWith(Parameterized.class) +public class DefinitionPropertyTest { + Definition.Property theProperty = null; + String propertyName; + String propertyType; + String propertyReference; + String result; + + /** + * Parameters for the test cases all following same pattern. + */ + @Parameters + public static Collection<String[]> testConditions() { + String inputs[][] = { + {"name1", "type1", "ref1", + "Property{propertyName='name1', propertyType='type1', propertyReference='ref1'}"}, + {"name2", "type2", "ref2", + "Property{propertyName='name2', propertyType='type2', propertyReference='ref2'}"}, + {"fake", "random", "bluff", + "Property{propertyName='fake', propertyType='random', propertyReference='bluff'}"}}; + return (Arrays.asList(inputs)); + } + + /** + * Constructor for the test cases all following same pattern. + */ + public DefinitionPropertyTest(String propertyName, String propertyType, + String propertyReference, String result) { + super(); + this.propertyName = propertyName; + this.propertyType = propertyType; + this.propertyReference = propertyReference; + this.result = result; + } + + /** + * Initialise the test object. + */ + @Before + public void setUp() throws Exception { + theProperty = new Definition.Property(); + } + + /** + * Perform the test on the test object. + */ + @Test + public void testDefinitionProperty() { + theProperty.setPropertyName(this.propertyName); + theProperty.setPropertyType(this.propertyType); + theProperty.setPropertyReference(this.propertyReference); + assertThat(theProperty.toString(), is(this.result)); + + // other stuff that can be set but not necessarily + // included in the toString() output + theProperty.setHasType(true); + assertThat(theProperty.isHasType(), is(true)); + + theProperty.setRequired(true); + assertThat(theProperty.isRequired(), is(true)); + + theProperty.setHasPropertyReference(true); + assertThat(theProperty.isHasPropertyReference(), is(true)); + + theProperty.setPropertyReferenceObjectName("someName"); + assertThat(theProperty.getPropertyReferenceObjectName(), is("someName")); + + theProperty.setPropertyDescription("some description"); + assertThat(theProperty.getPropertyDescription(), is("some description")); + + theProperty.setHasPropertyDescription(true); + assertThat(theProperty.isHasPropertyDescription(), is(true)); + } +} diff --git a/aai-schema-gen/src/test/java/org/onap/aai/schemagen/swagger/DefinitionTest.java b/aai-schema-gen/src/test/java/org/onap/aai/schemagen/swagger/DefinitionTest.java new file mode 100644 index 0000000..3a53019 --- /dev/null +++ b/aai-schema-gen/src/test/java/org/onap/aai/schemagen/swagger/DefinitionTest.java @@ -0,0 +1,100 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2019 Huawei Technologies (Australia) Pty Ltd. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.aai.schemagen.swagger; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +@RunWith(Parameterized.class) +public class DefinitionTest { + Definition theDefinition = null; + String definitionName; + String definitionDescription; + String result; + + /** + * Parameters for the test cases all following same pattern. + */ + @Parameters + public static Collection<String[]> testConditions() { + String inputs[][] = { + {"name1", "desc1", + "Definition{definitionName='name1', definitionDescription='desc1', propertyList=[]}"}, + {"name2", "desc2", + "Definition{definitionName='name2', definitionDescription='desc2', propertyList=[]}"}, + {"fake", "random", + "Definition{definitionName='fake', definitionDescription='random', propertyList=[]}"}}; + return (Arrays.asList(inputs)); + } + + /** + * Constructor for the test cases all following same pattern. + */ + public DefinitionTest(String definitionName, String definitionDescription, String result) { + super(); + this.definitionName = definitionName; + this.definitionDescription = definitionDescription; + this.result = result; + } + + /** + * Initialise the test object. + */ + @Before + public void setUp() throws Exception { + theDefinition = new Definition(); + } + + /** + * Perform the test on the test object. + */ + @Test + public void testDefinitionProperty() { + theDefinition.setDefinitionName(this.definitionName); + theDefinition.setDefinitionDescription(this.definitionDescription); + + List<Definition.Property> tmpList1 = new ArrayList<Definition.Property>(); + theDefinition.setPropertyList(tmpList1); + assertThat(theDefinition.toString(), is(this.result)); + + // other stuff that can be set but not necessarily + // included in the toString() output + theDefinition.setHasDescription(true); + assertThat(theDefinition.isHasDescription(), is(true)); + + theDefinition.setSchemaPropertyList(tmpList1); + assertThat(theDefinition.getSchemaPropertyList(), is(tmpList1)); + + theDefinition.setRegularPropertyList(tmpList1); + assertThat(theDefinition.getRegularPropertyList(), is(tmpList1)); + } +} diff --git a/aai-schema-gen/src/test/resources/dbedgerules/EdgeDescriptionRules_test.json b/aai-schema-gen/src/test/resources/dbedgerules/EdgeDescriptionRules_test.json new file mode 100644 index 0000000..c25f1fb --- /dev/null +++ b/aai-schema-gen/src/test/resources/dbedgerules/EdgeDescriptionRules_test.json @@ -0,0 +1,39 @@ +{ + "rules": [ + { + "from": "service-subscription", + "to": "customer", + "label": "org.onap.relationships.inventory.BelongsTo", + "direction": "OUT", + "multiplicity": "MANY2ONE", + "contains-other-v": "!${direction}", + "delete-other-v": "!${direction}", + "prevent-delete": "NONE", + "default": "true", + "description":"" + }, + { + "from": "service-instance", + "to": "service-subscription", + "label": "org.onap.relationships.inventory.BelongsTo", + "direction": "OUT", + "multiplicity": "MANY2ONE", + "contains-other-v": "!${direction}", + "delete-other-v": "!${direction}", + "prevent-delete": "NONE", + "default": "true", + "description":"" + }, + { + "from": "service-subscription", + "to": "tenant", + "label": "org.onap.relationships.inventory.Uses", + "direction": "OUT", + "multiplicity": "MANY2MANY", + "contains-other-v": "NONE", + "delete-other-v": "NONE", + "prevent-delete": "NONE", + "default": "true", + "description":"" + } ] +} diff --git a/aai-schema/.gitignore b/aai-schema/.gitignore index 2f30844..43a5448 100644 --- a/aai-schema/.gitignore +++ b/aai-schema/.gitignore @@ -1,2 +1,3 @@ /bin/ /.checkstyle +/target/ diff --git a/aai-schema/src/main/resources/onap/aai_schema/aai_schema_v16.xsd b/aai-schema/src/main/resources/onap/aai_schema/aai_schema_v16.xsd index 7fe4223..2cbd179 100644 --- a/aai-schema/src/main/resources/onap/aai_schema/aai_schema_v16.xsd +++ b/aai-schema/src/main/resources/onap/aai_schema/aai_schema_v16.xsd @@ -3220,6 +3220,52 @@ xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" </xs:sequence> </xs:complexType> </xs:element> + <xs:element name="esr-nfvo"> + <xs:complexType> + <xs:annotation> + <xs:appinfo> + <annox:annotate target="class">@org.onap.aai.annotations.Metadata(description="Persist NFVO address information used by VF-C.",indexedProps="nfvo-id",searchable="nfvo-id",container="esr-nfvo-list",namespace="external-system",requiredProps="nfvo-id",uriTemplate="/external-system/esr-nfvo-list/esr-nfvo/{nfvo-id}")</annox:annotate> + </xs:appinfo> + </xs:annotation> + <xs:sequence> + <xs:element name="nfvo-id" type="xs:string" minOccurs="0"> + <xs:annotation> + <xs:appinfo> + <annox:annotate target="field">@org.onap.aai.annotations.Metadata(isKey=true,description="Unique ID of nfvo.")</annox:annotate> + </xs:appinfo> + </xs:annotation> + </xs:element> + <xs:element name="api-root" type="xs:string" minOccurs="0"> + <xs:annotation> + <xs:appinfo> + <annox:annotate target="field">@org.onap.aai.annotations.Metadata(description="indecate the api-root.")</annox:annotate> + </xs:appinfo> + </xs:annotation> + </xs:element> + <xs:element name="resource-version" type="xs:string" minOccurs="0"> + <xs:annotation> + <xs:appinfo> + <annox:annotate target="field">@org.onap.aai.annotations.Metadata(description="Used for optimistic concurrency. Must be empty on create, valid on update and delete.")</annox:annotate> + </xs:appinfo> + </xs:annotation> + </xs:element> + <xs:element ref="tns:esr-system-info-list" minOccurs="0"/> + <xs:element ref="tns:relationship-list" minOccurs="0"/> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="esr-nfvo-list"> + <xs:complexType> + <xs:annotation> + <xs:appinfo> + <annox:annotate target="class">@org.onap.aai.annotations.Metadata(maximumDepth="0")</annox:annotate> + </xs:appinfo> + </xs:annotation> + <xs:sequence> + <xs:element ref="tns:esr-nfvo" minOccurs="0" maxOccurs="5000"/> + </xs:sequence> + </xs:complexType> + </xs:element> <xs:element name="esr-thirdparty-sdnc"> <xs:complexType> <xs:annotation> @@ -3283,6 +3329,7 @@ xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" <xs:sequence> <xs:element ref="tns:esr-ems-list" minOccurs="0"/> <xs:element ref="tns:esr-vnfm-list" minOccurs="0"/> + <xs:element ref="tns:esr-nfvo-list" minOccurs="0"/> <xs:element ref="tns:esr-thirdparty-sdnc-list" minOccurs="0"/> </xs:sequence> </xs:complexType> diff --git a/aai-schema/src/main/resources/onap/dbedgerules/v15/DbEdgeRules_esr_v15.json b/aai-schema/src/main/resources/onap/dbedgerules/v15/DbEdgeRules_esr_v15.json index e5ba23b..fb20986 100644 --- a/aai-schema/src/main/resources/onap/dbedgerules/v15/DbEdgeRules_esr_v15.json +++ b/aai-schema/src/main/resources/onap/dbedgerules/v15/DbEdgeRules_esr_v15.json @@ -59,6 +59,18 @@ "SVC-INFRA": "NONE", "prevent-delete": "NONE", "default": "true" + }, + { + "from": "generic-vnf", + "to": "esr-vnfm", + "label": "tosca.relationships.DependsOn", + "direction": "OUT", + "multiplicity": "MANY2ONE", + "contains-other-v": "NONE", + "delete-other-v": "NONE", + "prevent-delete": "NONE", + "default": "true", + "description":"" } ] } diff --git a/aai-schema/src/main/resources/onap/dbedgerules/v16/DbEdgeRules_esr_v16.json b/aai-schema/src/main/resources/onap/dbedgerules/v16/DbEdgeRules_esr_v16.json index e5ba23b..baa6ab8 100644 --- a/aai-schema/src/main/resources/onap/dbedgerules/v16/DbEdgeRules_esr_v16.json +++ b/aai-schema/src/main/resources/onap/dbedgerules/v16/DbEdgeRules_esr_v16.json @@ -26,6 +26,18 @@ }, { "from": "esr-system-info", + "to": "esr-nfvo", + "label": "org.onap.relationships.inventory.BelongsTo", + "direction": "OUT", + "multiplicity": "ONE2ONE", + "contains-other-v": "!${direction}", + "delete-other-v": "!${direction}", + "SVC-INFRA": "NONE", + "prevent-delete": "NONE", + "default": "true" + }, + { + "from": "esr-system-info", "to": "esr-thirdparty-sdnc", "label": "org.onap.relationships.inventory.BelongsTo", "direction": "OUT", @@ -59,6 +71,18 @@ "SVC-INFRA": "NONE", "prevent-delete": "NONE", "default": "true" + }, + { + "from": "generic-vnf", + "to": "esr-vnfm", + "label": "tosca.relationships.DependsOn", + "direction": "OUT", + "multiplicity": "MANY2ONE", + "contains-other-v": "NONE", + "delete-other-v": "NONE", + "prevent-delete": "NONE", + "default": "true", + "description":"" } ] } diff --git a/aai-schema/src/main/resources/onap/oxm/v16/aai_oxm_v16.xml b/aai-schema/src/main/resources/onap/oxm/v16/aai_oxm_v16.xml index 5354618..736a5f6 100644 --- a/aai-schema/src/main/resources/onap/oxm/v16/aai_oxm_v16.xml +++ b/aai-schema/src/main/resources/onap/oxm/v16/aai_oxm_v16.xml @@ -234,6 +234,7 @@ <java-attributes> <xml-element java-attribute="esrEmsList" name="esr-ems-list" type="inventory.aai.onap.org.v16.EsrEmsList"/> <xml-element java-attribute="esrVnfmList" name="esr-vnfm-list" type="inventory.aai.onap.org.v16.EsrVnfmList"/> + <xml-element java-attribute="esrNfvoList" name="esr-nfvo-list" type="inventory.aai.onap.org.v16.EsrNfvoList"/> <xml-element java-attribute="esrThirdpartySdncList" name="esr-thirdparty-sdnc-list" type="inventory.aai.onap.org.v16.EsrThirdpartySdncList"/> </java-attributes> </java-type> @@ -322,6 +323,49 @@ </xml-properties> </java-type> + <java-type name="EsrNfvoList"> + <xml-root-element name="esr-nfvo-list"/> + <java-attributes> + <xml-element container-type="java.util.ArrayList" java-attribute="esrNfvo" name="esr-nfvo" type="inventory.aai.onap.org.v16.EsrNfvo"/> + </java-attributes> + <xml-properties> + <xml-property name="maximumDepth" value="0"/> + </xml-properties> + </java-type> + + <java-type name="EsrNfvo"> + <xml-root-element name="esr-nfvo"/> + <java-attributes> + <xml-element java-attribute="nfvoId" name="nfvo-id" required="true" type="java.lang.String" xml-key="true"> + <xml-properties> + <xml-property name="description" value="Unique ID of nfvo."/> + </xml-properties> + </xml-element> + <xml-element java-attribute="apiRoot" name="api-root" type="java.lang.String"> + <xml-properties> + <xml-property name="description" value="indecate the api-root."/> + </xml-properties> + </xml-element> + <xml-element java-attribute="resourceVersion" name="resource-version" type="java.lang.String"> + <xml-properties> + <xml-property name="description" value="Used for optimistic concurrency. Must be empty on create, valid on update and delete."/> + </xml-properties> + </xml-element> + <xml-element java-attribute="esrSystemInfoList" name="esr-system-info-list" type="inventory.aai.onap.org.v16.EsrSystemInfoList"/> + <xml-element java-attribute="relationshipList" name="relationship-list" type="inventory.aai.onap.org.v16.RelationshipList"/> + </java-attributes> + <xml-properties> + <xml-property name="description" value="Persist NFVO address information used by VF-C."/> + <xml-property name="indexedProps" value="nfvo-id"/> + <xml-property name="searchable" value="nfvo-id"/> + <xml-property name="container" value="esr-nfvo-list"/> + <xml-property name="namespace" value="external-system"/> + <xml-property name="requiredProps" value="nfvo-id"/> + <xml-property name="uriTemplate" value="/external-system/esr-nfvo-list/esr-nfvo/{nfvo-id}"/> + </xml-properties> + </java-type> + + <java-type name="EsrThirdpartySdncList"> <xml-root-element name="esr-thirdparty-sdnc-list"/> <java-attributes> @@ -497,7 +541,7 @@ <xml-property name="indexedProps" value="esr-system-info-id,system-name,system-type"/> <xml-property name="searchable" value="esr-system-info-id,system-name,system-type"/> <xml-property name="container" value="esr-system-info-list"/> - <xml-property name="dependentOn" value="cloud-region,esr-ems,esr-vnfm,esr-thirdparty-sdnc,ext-aai-network"/> + <xml-property name="dependentOn" value="cloud-region,esr-ems,esr-vnfm,esr-thirdparty-sdnc,ext-aai-network,esr-nfvo"/> <xml-property name="requiredProps" value="esr-system-info-id,user-name,password,system-type"/> <xml-property name="uriTemplate" value="/esr-system-info-list/esr-system-info/{esr-system-info-id}"/> </xml-properties> diff --git a/onap-java-formatter.xml b/onap-java-formatter.xml new file mode 100644 index 0000000..2e34b9c --- /dev/null +++ b/onap-java-formatter.xml @@ -0,0 +1,295 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<profiles version="12"> +<profile kind="CodeFormatterProfile" name="onap-java-formatter" version="12"> +<setting id="org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode" value="enabled"/> +<setting id="org.eclipse.jdt.core.compiler.codegen.targetPlatform" value="1.8"/> +<setting id="org.eclipse.jdt.core.compiler.compliance" value="1.8"/> +<setting id="org.eclipse.jdt.core.compiler.problem.assertIdentifier" value="error"/> +<setting id="org.eclipse.jdt.core.compiler.problem.enumIdentifier" value="error"/> +<setting id="org.eclipse.jdt.core.compiler.source" value="1.8"/> +<setting id="org.eclipse.jdt.core.formatter.align_type_members_on_columns" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation" value="48"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_assignment" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_binary_expression" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_compact_if" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_conditional_expression" value="80"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_enum_constants" value="0"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_method_declaration" value="0"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_multiple_fields" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_resources_in_try" value="80"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_imports" value="1"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_package" value="1"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_field" value="0"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration" value="0"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_imports" value="0"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_member_type" value="0"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_method" value="1"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk" value="1"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_package" value="1"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_import_groups" value="1"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations" value="2"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration" value="end_of_line"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration" value="end_of_line"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_array_initializer" value="end_of_line"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block" value="end_of_line"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block_in_case" value="end_of_line"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration" value="end_of_line"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_constant" value="end_of_line"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration" value="end_of_line"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_lambda_body" value="end_of_line"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_method_declaration" value="end_of_line"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_switch" value="end_of_line"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_type_declaration" value="end_of_line"/> +<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.comment.format_block_comments" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.comment.format_header" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.comment.format_html" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.comment.format_javadoc_comments" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.comment.format_line_comments" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.comment.format_source_code" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.comment.indent_parameter_description" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.comment.indent_root_tags" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.comment.line_length" value="100"/> +<setting id="org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.compact_else_if" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.continuation_indentation" value="1"/> +<setting id="org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer" value="1"/> +<setting id="org.eclipse.jdt.core.formatter.disabling_tag" value="@formatter:off"/> +<setting id="org.eclipse.jdt.core.formatter.enabling_tag" value="@formatter:on"/> +<setting id="org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.indent_empty_lines" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_block" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_body" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.indentation.size" value="4"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_label" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_type_annotation" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_binary_operator" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_ellipsis" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_lambda_arrow" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_try" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_unary_operator" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_binary_operator" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_try" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_ellipsis" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_lambda_arrow" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_unary_operator" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.join_lines_in_comments" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.join_wrapped_lines" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.lineSplit" value="100"/> +<setting id="org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body" value="0"/> +<setting id="org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve" value="1"/> +<setting id="org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.tabulation.char" value="space"/> +<setting id="org.eclipse.jdt.core.formatter.tabulation.size" value="4"/> +<setting id="org.eclipse.jdt.core.formatter.use_on_off_tags" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.wrap_before_binary_operator" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested" value="true"/> +</profile> +</profiles> @@ -56,6 +56,39 @@ <build> <pluginManagement> <plugins> + <!-- + Using https://code.revelc.net/formatter-maven-plugin/ for Eclipse formatter + Using https://github.com/diffplug/spotless/tree/master/plugin-maven for import order + Use in combination to rewrite code and imports, then checkstyle + + mvn formatter:format spotless:apply process-sources + --> + <plugin> + <groupId>net.revelc.code.formatter</groupId> + <artifactId>formatter-maven-plugin</artifactId> + <version>2.8.1</version> + <configuration> + <configFile>${project.parent.basedir}/onap-java-formatter.xml</configFile> + </configuration> + <!-- https://code.revelc.net/formatter-maven-plugin/ + use mvn formatter:format to rewrite source files + use mvn formatter:validate to validate source files --> + </plugin> + <plugin> + <groupId>com.diffplug.spotless</groupId> + <artifactId>spotless-maven-plugin</artifactId> + <version>1.18.0</version> + <configuration> + <java> + <importOrder> + <order>com,java,javax,org</order> + </importOrder> + </java> + </configuration> + <!-- https://github.com/diffplug/spotless/tree/master/plugin-maven + use mvn spotless:apply to rewrite source files + use mvn spotless:check to validate source files --> + </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>sonar-maven-plugin</artifactId> |