- logger.info( "GeneratedXSD successful, saved in " + outfileName);
- }
-
- }
-
-
- public static String processJavaTypeElement( String javaTypeName, Element javaTypeElement) {
-
- String xmlRootElementName = null;
-
- NodeList parentNodes = javaTypeElement.getElementsByTagName("java-attributes");
- StringBuffer sb = new StringBuffer();
- if ( parentNodes.getLength() == 0 ) {
- logger.trace( "no java-attributes for java-type " + javaTypeName);
- return "";
-
- }
-
- 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();
- logger.trace("Found xml-root-element attribute: " + attrName + " with value: " + attrValue);
- if ( attrName.equals("name"))
- xmlRootElementName = attrValue;
- }
-
- Element parentElement = (Element)parentNodes.item(0);
- NodeList xmlElementNodes = parentElement.getElementsByTagName("xml-element");
- NodeList childNodes;
- Element childElement;
- String xmlElementWrapper;
-
- Element xmlElementElement;
- String addType;
- String elementName, elementType, elementIsKey, elementIsRequired, elementContainerType;
- StringBuffer sb1 = new StringBuffer();
- if ( xmlElementNodes.getLength() > 0 ) {
- sb1.append(" <xs:element name=\"" + xmlRootElementName + "\">\n");
- sb1.append(" <xs:complexType>\n");
- NodeList properties = GenerateXsd.locateXmlProperties(javaTypeElement);
- if (properties != null && useAnnotationsInXsd) {
- logger.trace("properties found for: " + xmlRootElementName);
- sb1.append(" <xs:annotation>\r\n");
- insertAnnotation(properties, false, "class", sb1, " ");
-
- sb1.append(" </xs:annotation>\r\n");
- } else {
- logger.trace("no properties found for: " + xmlRootElementName);
- }
- sb1.append(" <xs:sequence>\n");
- for ( int i = 0; i < xmlElementNodes.getLength(); ++i ) {
-
- xmlElementElement = (Element)xmlElementNodes.item(i);
- childNodes = xmlElementElement.getElementsByTagName("xml-element-wrapper");
-
- xmlElementWrapper = null;
- if ( childNodes.getLength() > 0 ) {
- childElement = (Element)childNodes.item(0);
- // get name
- attributes = childElement.getAttributes();
- for ( int k = 0; k < attributes.getLength(); ++k ) {
- Attr attr = (Attr) attributes.item(k);
- String attrName = attr.getNodeName();
- String attrValue = attr.getNodeValue();
- if ( attrName.equals("name")) {
- xmlElementWrapper = attrValue;
- logger.trace("found xml-element-wrapper " + xmlElementWrapper);
- }
- }
-
- }
- attributes = xmlElementElement.getAttributes();
- addType = null;
-
-
- elementName = elementType = elementIsKey = elementIsRequired = elementContainerType = null;
- for ( int j = 0; j < attributes.getLength(); ++j ) {
- Attr attr = (Attr) attributes.item(j);
- String attrName = attr.getNodeName();
-
- String attrValue = attr.getNodeValue();
- logger.trace("For " + xmlRootElementName + " Found xml-element attribute: " + attrName + " with value: " + attrValue);
- if ( attrName.equals("name")) {
- elementName = attrValue;
- }
- if ( attrName.equals("type")) {
- elementType = attrValue;
- if ( attrValue.contains(apiVersionFmt) ) {
- addType = attrValue.substring(attrValue.lastIndexOf('.')+1);
- if ( !generatedJavaType.containsKey(addType) ) {
- generatedJavaType.put(addType, attrValue);
- sb.append(processJavaTypeElement( addType, getJavaTypeElement(addType) ));
- }
- }
-
- }
-
- if ( attrName.equals("xml-key")) {
- elementIsKey = attrValue;
- }
- if ( attrName.equals("required")) {
- elementIsRequired = attrValue;
- }
- if ( attrName.equals("container-type")) {
- elementContainerType = attrValue;
- }
- }
-
- if ( xmlElementWrapper != null ) {
- sb1.append(" <xs:element name=\"" + xmlElementWrapper +"\"");
- if ( elementIsRequired == null || !elementIsRequired.equals("true")||addType != null) {
- sb1.append(" minOccurs=\"0\"");
- }
- sb1.append(">\n");
- sb1.append(" <xs:complexType>\n");
- properties = GenerateXsd.locateXmlProperties(javaTypeElement);
- if (properties != null && useAnnotationsInXsd) {
- sb1.append(" <xs:annotation>\r\n");
- insertAnnotation(properties, false, "class", sb1, " ");
- sb1.append(" </xs:annotation>\r\n");
- } else {
- logger.trace("no properties found for: " + xmlElementWrapper);
- }
- sb1.append(" <xs:sequence>\n");
- sb1.append(" ");
- }
- if ("Nodes".equals(addType)) {
- logger.trace("Skipping nodes, temporary testing");
- continue;
- }
- if ( addType != null ) {
- sb1.append(" <xs:element ref=\"tns:" + getXmlRootElementName(addType) +"\"");
- } else {
- sb1.append(" <xs:element name=\"" + elementName +"\"");
- }
- if ( elementType.equals("java.lang.String"))
- sb1.append(" type=\"xs:string\"");
- if ( elementType.equals("java.lang.Long"))
- sb1.append(" type=\"xs:unsignedInt\"");
- if ( elementType.equals("java.lang.Integer"))
- sb1.append(" type=\"xs:int\"");
- if ( elementType.equals("java.lang.Boolean"))
- sb1.append(" type=\"xs:boolean\"");
- if ( elementIsRequired == null || !elementIsRequired.equals("true")||addType != null) {
- sb1.append(" minOccurs=\"0\"");
- }
- if ( elementContainerType != null && elementContainerType.equals("java.util.ArrayList")) {
- sb1.append(" maxOccurs=\"unbounded\"");
- }
- properties = GenerateXsd.locateXmlProperties(xmlElementElement);
- if (properties != null || elementIsKey != null) {
- sb1.append(">\n");
- if ( useAnnotationsInXsd ) {
- sb1.append(" <xs:annotation>\r\n");
- insertAnnotation(properties, elementIsKey != null, "field", sb1, " ");
- sb1.append(" </xs:annotation>\r\n");
- }
- if (xmlElementWrapper== null) {
- sb1.append(" </xs:element>\n");
- }
- } else {
- sb1.append("/>\n");
- }
- if ( xmlElementWrapper != null ) {
- sb1.append(" </xs:sequence>\n");
- sb1.append(" </xs:complexType>\n");
- sb1.append(" </xs:element>\n");
- }
- }
- sb1.append(" </xs:sequence>\n");
- sb1.append(" </xs:complexType>\n");
- sb1.append(" </xs:element>\n");
- }
-
- if ( xmlElementNodes.getLength() < 1 ) {
- sb.append(" <xs:element name=\"" + xmlRootElementName + "\">\n");
- sb.append(" <xs:complexType>\n");
- sb.append(" <xs:sequence/>\n");
- sb.append(" </xs:complexType>\n");
- sb.append(" </xs:element>\n");
- generatedJavaType.put(javaTypeName, null);
- return sb.toString();
- }
- sb.append( sb1 );
- return sb.toString();
- }
-
- private static void insertAnnotation(NodeList items, boolean isKey, String target, StringBuffer sb1, String indentation) {
- if (items != null || isKey) {
- List<String> metadata = new ArrayList<>();
-
- String name = "";
- String value = "";
- Element item = null;
- if (isKey) {
- metadata.add("isKey=true");
- }
- if (items != null) {
- for (int i = 0; i < items.getLength(); i++) {
- item = (Element)items.item(i);
- name = item.getAttribute("name");
- value = item.getAttribute("value");
- if (name.equals("abstract")) {
- name = "isAbstract";
- } else if (name.equals("extends")) {
- name = "extendsFrom";
- }
- metadata.add(name + "=\"" + value.replaceAll("&", "&") + "\"");
- }
- }
- sb1.append(
- indentation + " <xs:appinfo>\r\n" +
- indentation + " <annox:annotate target=\""+target+"\">@org.onap.aai.annotations.Metadata(" + Joiner.on(",").join(metadata) + ")</annox:annotate>\r\n" +
- indentation + " </xs:appinfo>\r\n");
- }
-
- }
-
- private static Element getJavaTypeElement( 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))
- return javaTypeElement;
- }
- }
- logger.error( "oxm file format error, missing java-type " + javaTypeName);
- return (Element) null;
- }
-
- private static Element getJavaTypeElementSwagger( 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))
- return javaTypeElement;
- }
- }
- logger.error( "oxm file format error, missing java-type " + javaTypeName);
- return (Element) null;
- }
- private static 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);
- }
- }
- }
- }
- logger.error( "oxm file format error, missing java-type " + javaTypeName);
- return null;
- }
-
-
- public static String processOxmFile( File oxmFile, Version v, String xml )
- {
- if ( xml != null ){
- apiVersion = v.toString();
- useAnnotationsInXsd = true;
- apiVersionFmt = "." + apiVersion + ".";
- generatedJavaType = new HashMap<>();
- appliedPaths = new HashMap<>();
- }
- StringBuilder sb = new StringBuilder();
- logger.trace("processing starts");
- sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n");
- String namespace = "org.onap";
- if (v.compareTo(Version.v11) < 0) {
- namespace = "org.openecomp";
- }
- if ( useAnnotationsInXsd ) {
- sb.append("<xs:schema elementFormDefault=\"qualified\" version=\"1.0\" targetNamespace=\"http://" + namespace + ".aai.inventory/"
- + apiVersion + "\" xmlns:tns=\"http://" + namespace + ".aai.inventory/" + apiVersion + "\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\""
- + "\n"
- + "xmlns:jaxb=\"http://java.sun.com/xml/ns/jaxb\"\r\n" +
- " jaxb:version=\"2.1\" \r\n" +
- " xmlns:annox=\"http://annox.dev.java.net\" \r\n" +
- " jaxb:extensionBindingPrefixes=\"annox\">\n\n");
- } else {
-
- sb.append("<xs:schema elementFormDefault=\"qualified\" version=\"1.0\" targetNamespace=\"http://" + namespace + ".aai.inventory/"
- + apiVersion + "\" xmlns:tns=\"http://" + namespace + ".aai.inventory/" + apiVersion + "\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n\n");
- }
-
- try {
-
- DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
- dbFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
- DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
- Document doc;
-
- if ( xml == null ){
- doc = dBuilder.parse(oxmFile);
- } else {
- InputSource is = new InputSource(new StringReader(xml));
- doc = dBuilder.parse(is);
- }
- NodeList bindingsNodes = doc.getElementsByTagName("xml-bindings");
- Element bindingElement;
- NodeList javaTypesNodes;
- Element javaTypesElement;
-
- Element javaTypeElement;
-
-
- if ( bindingsNodes == null || bindingsNodes.getLength() == 0 ) {
- logger.error( "missing <binding-nodes> in " + oxmFile );
- return null;
- }
-
- bindingElement = (Element) bindingsNodes.item(0);
- javaTypesNodes = bindingElement.getElementsByTagName("java-types");
- if ( javaTypesNodes.getLength() < 1 ) {
- logger.error( "missing <binding-nodes><java-types> in " + oxmFile );
- return null;
- }
- javaTypesElement = (Element) javaTypesNodes.item(0);
- javaTypeNodes = javaTypesElement.getElementsByTagName("java-type");
- if ( javaTypeNodes.getLength() < 1 ) {
- logger.error( "missing <binding-nodes><java-types><java-type> in " + oxmFile );
- return null;
- }
-
- String javaTypeName;
- String attrName, attrValue;
- Attr attr;
- for ( int i = 0; i < javaTypeNodes.getLength(); ++ i ) {
- javaTypeElement = (Element) javaTypeNodes.item(i);
- NamedNodeMap attributes = javaTypeElement.getAttributes();
- javaTypeName = null;
- for ( int j = 0; j < attributes.getLength(); ++j ) {
- attr = (Attr) attributes.item(j);
- attrName = attr.getNodeName();
- attrValue = attr.getNodeValue();
- if ( attrName.equals("name"))
- javaTypeName = attrValue;
- }
- if ( javaTypeName == null ) {
- logger.error( "<java-type> has no name attribute in " + oxmFile );
- return null;
- }
- if ("Nodes".equals(javaTypeName)) {
- logger.debug("skipping Nodes entry (temporary feature)");
- continue;
- }
- if ( !generatedJavaType.containsKey(javaTypeName) ) {
- generatedJavaType.put(javaTypeName, null);
- sb.append(processJavaTypeElement( javaTypeName, javaTypeElement ));
- }
- }
-
- } catch (Exception e) {
- e.printStackTrace();
- return null;
- }
- sb.append("</xs:schema>\n");
- return sb.toString();
- }
-
- public static String toDeleteRules(String objectName) {
- Collection<EdgeDescription> toEdges = GenerateXsd.getEdgeRulesTO(objectName);
- logger.debug("TO Edges count: "+toEdges.size()+" Object: "+objectName);
- String prevent=null;
- String also=null;
- LinkedHashSet<String> preventDelete = new LinkedHashSet<String>();
- LinkedHashSet<String> alsoDelete = new LinkedHashSet<String>();
- for (EdgeDescription ed : toEdges) {
- logger.debug("{“comment”: From = "+ed.getFrom()+" To: "+ed.getTo()+" Object: "+objectName);
- logger.debug("{“comment”: Direction = "+ed.getDirection()+" PreventDelete: "+ed.getPreventDelete()+" DeleteOtherV: "+ed.getDeleteOtherV()+" Object: "+objectName);
- if(ed.getPreventDelete().equals("IN") && ed.getTo().equals(objectName)) {
- preventDelete.add(ed.getFrom().toUpperCase());
- }
- if(ed.getDeleteOtherV().equals("IN") && ed.getTo().equals(objectName) ) {
- alsoDelete.add(ed.getFrom().toUpperCase());
- }
- }
- if(preventDelete.size() > 0) {
- prevent = " - "+objectName.toUpperCase()+" cannot be deleted if linked to "+String.join(",",preventDelete);
- logger.info(prevent);
- }
- if(alsoDelete.size() > 0) {
- also = " - "+objectName.toUpperCase()+" is DELETED when these are DELETED "+String.join(",",alsoDelete);
- // This commented out line is better (gets who deletes what correct) but still not accurate.
- //also = " - Deletion of an instance of "+objectName.toUpperCase()+" causes instances of these directly related types to be DELETED ["+String.join(",",alsoDelete)+"]";
- logger.info(also);
- }
- return String.join((prevent == null || also == null) ? "" : "\n", prevent == null ? "" : prevent, also == null ? "" : also)+((prevent == null && also == null) ? "" : "\n");
- }
-
- public static String fromDeleteRules(String objectName) {
- Collection<EdgeDescription> fromEdges = GenerateXsd.getEdgeRulesFROM(objectName);
- LinkedHashSet<String> preventDelete = new LinkedHashSet <String>();
- LinkedHashSet<String> alsoDelete = new LinkedHashSet <String>();
- String prevent=null;
- String also=null;
- for (EdgeDescription ed : fromEdges) {
- logger.debug("{“comment”: From = "+ed.getFrom()+" To: "+ed.getTo()+" Object: "+objectName);
- logger.debug("{“comment”: Direction = "+ed.getDirection()+" PreventDelete: "+ed.getPreventDelete()+" DeleteOtherV: "+ed.getDeleteOtherV()+" Object: "+objectName);
- if(ed.getPreventDelete().equals("OUT") && ed.getFrom().equals(objectName)) {
- preventDelete.add(ed.getTo().toUpperCase());
- }
- if(ed.getDeleteOtherV().equals("OUT") && ed.getFrom().equals(objectName) ) {
- alsoDelete.add(ed.getTo().toUpperCase());
- }
- }
- if(preventDelete.size() > 0) {
- prevent = " - "+objectName.toUpperCase()+" cannot be deleted if linked to "+String.join(",",preventDelete);
- logger.info(prevent);
- }
- if(alsoDelete.size() > 0) {
- also = " - "+objectName.toUpperCase()+" deletion means associated objects of these types are also DELETED:"+String.join(",",alsoDelete);
- // This commented out line is better (gets who deletes what correct) but still not accurate.
- //also = " - Deletion of an instance of "+objectName.toUpperCase()+" causes instances of these directly related types to be DELETED ["+String.join(",",alsoDelete)+"]";
- logger.info(also);
- }
- return String.join((prevent == null || also == null) ? "" : "\n", prevent == null ? "" : prevent, also == null ? "" : also)+((prevent == null && also == null) ? "" : "\n");
- }
-
-
- private static boolean isStandardType( String elementType )
- {
- switch ( elementType ) {
- case "java.lang.String":
- case "java.lang.Long":
- case "java.lang.Integer":
- case"java.lang.Boolean":
- return true;
- }
- return false;
- }
-
- private static Vector<String> getIndexedProps( String attrValue )
- {
- if ( attrValue == null )
- return null;
- StringTokenizer st = new StringTokenizer( attrValue, ",");
- if ( st.countTokens() == 0 )
- return null;
- Vector<String> result = new Vector<String>();
- while ( st.hasMoreTokens()) {
- result.add(st.nextToken());
- }
- return result;
- }
-
- /**
- * Guaranteed to at least return non null but empty collection of edge descriptions
- * @param nodeName name of the vertex whose edge relationships to return
- * @return collection of node neighbors based on DbEdgeRules
- **/
- private static Collection<EdgeDescription> getEdgeRulesFromJson( String path, boolean skipMatch )
- {
-
- ArrayList<EdgeDescription> result = new ArrayList<>();
- Iterator<Map<String, Object>> edgeRulesIterator;
- try {
-
- GenerateXsd x = new GenerateXsd();
-
- List<Map<String, Object>> inEdges = JsonPath.parse(jsonEdges).read(path);
-
- edgeRulesIterator = inEdges.iterator();
- Map<String, Object> edgeMap;
- String fromNode;
- String toNode;
- String direction;
- String multiplicity;
- String isParent;
- String hasDelTarget;
- String deleteOtherV;
- String preventDelete;
- String description;
- EdgeDescription edgeDes;
-
- while( edgeRulesIterator.hasNext() ){
- edgeMap = edgeRulesIterator.next();
- fromNode = (String)edgeMap.get("from");
- toNode = (String)edgeMap.get("to");
- if ( skipMatch ) {
- if ( fromNode.equals(toNode)) {
- continue;
- }
- }
- edgeDes = x.new EdgeDescription();
- edgeDes.setRuleKey(fromNode + "|" + toNode);
- edgeDes.setLabel((String)edgeMap.get("label"));
- edgeDes.setTo((String)edgeMap.get("to"));
- edgeDes.setFrom((String)edgeMap.get("from"));
- direction = (String)edgeMap.get("direction");
- edgeDes.setDirection(direction);
- multiplicity = (String)edgeMap.get("multiplicity");
- edgeDes.setMultiplicity(multiplicity);
- isParent = (String)edgeMap.get(EdgeProperty.CONTAINS.toString());
- if ( "${direction}".equals(isParent)) {
- edgeDes.setType(LineageType.PARENT);
- } else {
- edgeDes.setType(LineageType.UNRELATED);
- }
- hasDelTarget = (String)edgeMap.get(EdgeProperty.DELETE_OTHER_V.toString());
- deleteOtherV = (String)edgeMap.get(EdgeProperty.DELETE_OTHER_V.toString());
- edgeDes.setDeleteOtherV(deleteOtherV);
- edgeDes.setHasDelTarget(hasDelTarget);
- preventDelete = (String)edgeMap.get(EdgeProperty.PREVENT_DELETE.toString());
- edgeDes.setPreventDelete(preventDelete);
- description = (String)edgeMap.get(EdgeProperty.DESCRIPTION.toString());
- edgeDes.setDescription(description);
-
- result.add(edgeDes);
- logger.debug("Edge: "+edgeDes.getRuleKey());
- }
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- return result;
-
- }
-
- /**
- * Guaranteed to at least return non null but empty collection of edge descriptions
- * @param nodeName name of the vertex whose edge relationships to return
- * @return collection of node neighbors based on DbEdgeRules
- **/
- private static Collection<EdgeDescription> getEdgeRules( String nodeName )
- {
- String fromRulesPath = "$['rules'][?(@['from']=='" + nodeName + "')]";
- String toRulesPath = "$['rules'][?(@['to']=='" + nodeName + "')]";
- Collection<EdgeDescription> fromEdges = getEdgeRulesFromJson( fromRulesPath, false );
- Collection<EdgeDescription> edges = getEdgeRulesFromJson( toRulesPath, true );
- edges.addAll(fromEdges);
- return edges;
- }
-
- private static Collection<EdgeDescription> getEdgeRulesTO( String nodeName )
- {
- String toRulesPath = "$['rules'][?(@['to']=='" + nodeName + "')]";
- Collection<EdgeDescription> edges = getEdgeRulesFromJson( toRulesPath, true );
- return edges;
- }
-
- private static Collection<EdgeDescription> getEdgeRulesFROM( String nodeName )
- {
- String fromRulesPath = "$['rules'][?(@['from']=='" + nodeName + "')]";
- Collection<EdgeDescription> edges = getEdgeRulesFromJson( fromRulesPath, true );
- return edges;
- }
- public static String processJavaTypeElementSwagger( String javaTypeName, Element javaTypeElement,
- StringBuffer pathSb, StringBuffer definitionsSb, String path, String tag, String opId,
- String getItemName, StringBuffer pathParams, String queryParams, String validEdges) {
-
- String xmlRootElementName = null;
- StringBuilder definitionsLocalSb = new StringBuilder(256);
-
- String useTag = null;
- String useOpId = null;
-
- if ( tag != null ) {
- switch ( tag ) {
- case "Network":
- case "ServiceDesignAndCreation":
- case "Business":
- case "LicenseManagement":
- case "CloudInfrastructure":
- break;
- default:
- 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;
- }
-
- NodeList parentNodes = javaTypeElement.getElementsByTagName("java-attributes");
-
- if ( parentNodes.getLength() == 0 ) {
- logger.trace( "no java-attributes for java-type " + javaTypeName);
- return "";
- }
-
- 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();
- logger.trace("Found xml-root-element attribute: " + attrName + " with value: " + attrValue);
- if ( attrName.equals("name"))
- xmlRootElementName = attrValue;
- }
-
- NodeList childNodes;
- Element childElement;
- NodeList xmlPropNodes = javaTypeElement.getElementsByTagName("xml-properties");
- Element xmlPropElement;
- String pathDescriptionProperty = null;
-
-
- Vector<String> indexedProps = null;
-
- if ( xmlPropNodes.getLength() > 0 ) {
-
- for ( int i = 0; i < xmlPropNodes.getLength(); ++i ) {
- xmlPropElement = (Element)xmlPropNodes.item(i);
- if ( !xmlPropElement.getParentNode().isSameNode(javaTypeElement))
- continue;
- childNodes = xmlPropElement.getElementsByTagName("xml-property");
-
- if ( childNodes.getLength() > 0 ) {
- for ( int j = 0; j < childNodes.getLength(); ++j ) {
- childElement = (Element)childNodes.item(j);
- // get name
- int useValue = VALUE_NONE;
- attributes = childElement.getAttributes();
- for ( int k = 0; k < attributes.getLength(); ++k ) {
- Attr attr = (Attr) attributes.item(k);
- String attrName = attr.getNodeName();
- String attrValue = attr.getNodeValue();
- if ( attrName == null || attrValue == null )
- continue;
- if ( attrName.equals("name") && attrValue.equals("description")) {
- useValue = VALUE_DESCRIPTION;
- }
- if ( useValue == VALUE_DESCRIPTION && attrName.equals("value")) {
- pathDescriptionProperty = attrValue;
- }
- if ( attrValue.equals("indexedProps")) {
- useValue = VALUE_INDEXED_PROPS;
- }
- if ( useValue == VALUE_INDEXED_PROPS && attrName.equals("value")) {
- indexedProps = getIndexedProps( attrValue );
- }
- }
- }
- }
- }
- }
- logger.trace("javaTypeName " + javaTypeName + " description " + pathDescriptionProperty);
-
- Element parentElement = (Element)parentNodes.item(0);
- NodeList xmlElementNodes = parentElement.getElementsByTagName("xml-element");
-
-
- String attrDescription = null;
-
- Element xmlElementElement;
- String addType = null;
- String elementType = null, elementIsKey = null, elementIsRequired, elementContainerType = null;
- String elementName = null;
- StringBuffer sbParameters = new StringBuffer();
-
- StringBuffer sbRequired = new StringBuffer();
- int requiredCnt = 0;
- int propertyCnt = 0;
- StringBuffer sbProperties = new StringBuffer();
- StringBuffer sbIndexedParams = new StringBuffer();
-
-
- StringTokenizer st;
- if ( xmlRootElementName.equals("inventory"))
- path = "";
- else if ( path == null )
- path = "/" + xmlRootElementName;
- else
- path += "/" + xmlRootElementName;
- st = new StringTokenizer(path, "/");
- boolean genPath = false;
-
- if ( st.countTokens() > 1 && getItemName == null ) {
- if ( appliedPaths.containsKey(path))
- return null;
- appliedPaths.put(path, xmlRootElementName);
- genPath = true;
- if ( path.contains("/relationship/") ) { // filter paths with relationship-list
- genPath = false;
- }
- if ( path.endsWith("/relationship-list")) {
- genPath = false;
- }
-
- }
-
- Vector<String> addTypeV = null;
- if ( xmlElementNodes.getLength() > 0 ) {
-
- for ( int i = 0; i < xmlElementNodes.getLength(); ++i ) {
- xmlElementElement = (Element)xmlElementNodes.item(i);
- if ( !xmlElementElement.getParentNode().isSameNode(parentElement))
- continue;
-
- valNodes = xmlElementElement.getElementsByTagName("xml-properties");
- attrDescription = null;
- if ( valNodes.getLength() > 0 ) {
- for ( int j = 0; j < valNodes.getLength(); ++j ) {
- valElement = (Element)valNodes.item(j);
- if ( !valElement.getParentNode().isSameNode(xmlElementElement))
- continue;
- childNodes = valElement.getElementsByTagName("xml-property");
- if ( childNodes.getLength() > 0 ) {
- childElement = (Element)childNodes.item(0);
- // get name
- attributes = childElement.getAttributes();
- attrDescription = null;
- boolean useValue = false;
- for ( int k = 0; k < attributes.getLength(); ++k ) {
- Attr attr = (Attr) attributes.item(k);
- String attrName = attr.getNodeName();
- String attrValue = attr.getNodeValue();
- if ( attrName.equals("name") && attrValue.equals("description")) {
- useValue = true;
- }
- if ( useValue && attrName.equals("value")) {
- attrDescription = attrValue;
- }
- }
-
- }
- }
- }
-
- attributes = xmlElementElement.getAttributes();
- addTypeV = null; // vector of 1
- addType = null;
-
- elementName = elementType = elementIsKey = elementIsRequired = elementContainerType = null;
- for ( int j = 0; j < attributes.getLength(); ++j ) {
- Attr attr = (Attr) attributes.item(j);
- String attrName = attr.getNodeName();
-
- String attrValue = attr.getNodeValue();
- logger.trace("For " + xmlRootElementName + " Found xml-element attribute: " + attrName + " with value: " + attrValue);
- if ( attrName.equals("name")) {
- elementName = attrValue;
-
- }
- if ( attrName.equals("type") && getItemName == null ) {
- elementType = attrValue;
- if ( attrValue.contains(apiVersionFmt) ) {
- addType = attrValue.substring(attrValue.lastIndexOf('.')+1);
- if ( addTypeV == null )
- addTypeV = new Vector<String>();
- addTypeV.add(addType);
- }
-
- }
- if ( attrName.equals("xml-key")) {
- elementIsKey = attrValue;
- path += "/{" + elementName + "}";
- }
- if ( attrName.equals("required")) {
- elementIsRequired = attrValue;
- }
- if ( attrName.equals("container-type")) {
- elementContainerType = attrValue;
- }
- }
- if ( getItemName != null ) {
- if ( getItemName.equals("array") ) {
- if ( elementContainerType != null && elementContainerType.equals("java.util.ArrayList")) {
- logger.trace( " returning array " + elementName );
- return elementName;
- }
-
- } else { // not an array check
- if ( elementContainerType == null || !elementContainerType.equals("java.util.ArrayList")) {
- logger.trace( " returning object " + elementName );
- return elementName;
- }
-
- }
- logger.trace( " returning null" );
- return null;
- }
- if ( elementIsRequired != null ) {
- if ( requiredCnt == 0 )
- sbRequired.append(" required:\n");
- ++requiredCnt;
- if ( addTypeV != null ) {
- for ( int k = 0; k < addTypeV.size(); ++i ) {
- sbRequired.append(" - " + getXmlRootElementName(addTypeV.elementAt(k)) + ":\n");
- }
- } else
- sbRequired.append(" - " + elementName + "\n");
-
- }
-
- if ( elementIsKey != null ) {
- sbParameters.append((" - name: " + elementName + "\n"));
- sbParameters.append((" in: path\n"));
- if ( attrDescription != null && attrDescription.length() > 0 )
- sbParameters.append((" description: " + attrDescription + "\n"));
- sbParameters.append((" required: true\n"));
- if ( elementType.equals("java.lang.String"))
- sbParameters.append(" type: string\n");
- if ( elementType.equals("java.lang.Long")) {
- sbParameters.append(" type: integer\n");
- sbParameters.append(" format: int64\n");
- }
- if ( elementType.equals("java.lang.Integer")) {
- sbParameters.append(" type: integer\n");
- sbParameters.append(" format: int32\n");
- }
- if ( elementType.equals("java.lang.Boolean")) {
- sbParameters.append(" type: boolean\n");
- }
- if(StringUtils.isNotBlank(elementName)) {
- sbParameters.append(" example: "+"__"+elementName.toUpperCase()+"__"+"\n");
- }
- } else if ( indexedProps != null
- && indexedProps.contains(elementName ) ) {
- sbIndexedParams.append((" - name: " + elementName + "\n"));
- sbIndexedParams.append((" in: query\n"));
- if ( attrDescription != null && attrDescription.length() > 0 )
- sbIndexedParams.append((" description: " + attrDescription + "\n"));
- sbIndexedParams.append((" required: false\n"));
- if ( elementType.equals("java.lang.String"))
- sbIndexedParams.append(" type: string\n");
- if ( elementType.equals("java.lang.Long")) {
- sbIndexedParams.append(" type: integer\n");
- sbIndexedParams.append(" format: int64\n");
- }
- if ( elementType.equals("java.lang.Integer")) {
- sbIndexedParams.append(" type: integer\n");
- sbIndexedParams.append(" format: int32\n");
- }
- if ( elementType.equals("java.lang.Boolean"))
- sbIndexedParams.append(" type: boolean\n");
- }
- if ( isStandardType(elementType)) {
- sbProperties.append(" " + elementName + ":\n");
- ++propertyCnt;
- sbProperties.append(" type: ");
-
- if ( elementType.equals("java.lang.String"))
- sbProperties.append("string\n");
- else if ( elementType.equals("java.lang.Long")) {
- sbProperties.append("integer\n");
- sbProperties.append(" format: int64\n");
- }
- else if ( elementType.equals("java.lang.Integer")){
- sbProperties.append("integer\n");
- sbProperties.append(" format: int32\n");
- }
- else if ( elementType.equals("java.lang.Boolean"))
- sbProperties.append("boolean\n");
- if ( attrDescription != null && attrDescription.length() > 0 )
- sbProperties.append(" description: " + attrDescription + "\n");
- }
-
- if ( addTypeV != null ) {
- StringBuffer newPathParams = null;
- if ( pathParams != null ) {
- newPathParams = new StringBuffer();
- newPathParams.append(pathParams);
- }
- if ( sbParameters.toString().length() > 0 ) {
- if ( newPathParams == null )
- newPathParams = new StringBuffer();
- newPathParams.append(sbParameters);
- }
- String newQueryParams = null;
- if ( sbIndexedParams.toString().length() > 0 ) {
- if ( queryParams == null )
- newQueryParams = sbIndexedParams.toString();
- else
- newQueryParams = queryParams + sbIndexedParams.toString();
- } else {
- newQueryParams = queryParams;
- }
- for ( int k = 0; k < addTypeV.size(); ++k ) {
- addType = addTypeV.elementAt(k);
-
- if ( opId == null || !opId.contains(addType)) {
- processJavaTypeElementSwagger( addType, getJavaTypeElementSwagger(addType),
- pathSb, definitionsSb, path, tag == null ? useTag : tag, useOpId, null,
- newPathParams, newQueryParams, validEdges);
- }
- // need item name of array
- String itemName = processJavaTypeElementSwagger( addType, getJavaTypeElementSwagger(addType),
- pathSb, definitionsSb, path, tag == null ? useTag : tag, useOpId,
- "array", null, 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 ( attrDescription != null && attrDescription.length() > 0 )
- sbProperties.append(" description: " + attrDescription + "\n");
- }
- } else {
- if ( elementContainerType != null && elementContainerType.equals("java.util.ArrayList")) {
- // need properties for getXmlRootElementName(addType)
- newPathParams = null;
- if ( pathParams != null ) {
- newPathParams = new StringBuffer();
- newPathParams.append(pathParams);
- }
- if ( sbParameters.toString().length() > 0 ) {
- if ( newPathParams == null )
- newPathParams = new StringBuffer();
- newPathParams.append(sbParameters);
- }
- newQueryParams = null;
- if ( sbIndexedParams.toString().length() > 0 ) {
- if ( queryParams == null )
- newQueryParams = sbIndexedParams.toString();
- else
- newQueryParams = queryParams + sbIndexedParams.toString();
- } else {
- newQueryParams = queryParams;
- }
- processJavaTypeElementSwagger( addType, getJavaTypeElementSwagger(addType),
- pathSb, definitionsSb, path, tag == null ? useTag : tag, useOpId,
- null, newPathParams, newQueryParams, validEdges );
- sbProperties.append(" " + getXmlRootElementName(addType) + ":\n");
- sbProperties.append(" type: array\n items: \n");
- sbProperties.append(" $ref: \"#/definitions/" + getXmlRootElementName(addType) + "\"\n");
- } else {
- sbProperties.append(" " + getXmlRootElementName(addType) + ":\n");
- sbProperties.append(" type: object\n");
- sbProperties.append(" $ref: \"#/definitions/" + getXmlRootElementName(addType) + "\"\n");
- }
- if ( attrDescription != null && attrDescription.length() > 0 )
- sbProperties.append(" description: " + attrDescription + "\n");
- ++propertyCnt;
- }
- }
- }
- }
- }
- if ( genPath ) {
- if ( !path.endsWith("/relationship") ) {
- GetOperation get = new GetOperation(useOpId, xmlRootElementName, tag, path, pathParams == null ? "" : pathParams.toString());
- pathSb.append(get.toString());
-// if ( path.indexOf('{') > 0 ) {
-
- if ( sbParameters.toString().length() > 0 ) {
- if ( pathParams == null )
- pathParams = new StringBuffer();
- pathParams.append(sbParameters);
- }
- if ( pathParams != null) {
- pathSb.append(" parameters:\n");
- pathSb.append(pathParams);
- } else
- logger.trace( "null pathParams for " + useOpId);
- if ( sbIndexedParams.toString().length() > 0 ) {
- if ( queryParams == null )
- queryParams = sbIndexedParams.toString();
- else
- queryParams = queryParams + sbIndexedParams.toString();
- }
- if ( queryParams != null ) {
- if ( pathParams == null ) {
- pathSb.append(" parameters:\n");
- }
- pathSb.append(queryParams);
- }
-// }
- }
- boolean skipPutDelete = false; // no put or delete for "all"
- if ( !path.endsWith("/relationship") ) {
- if ( !path.endsWith("}") ){
- skipPutDelete = true;
- }
-
- }
- if ( path.indexOf('{') > 0 && !opId.startsWith("Search") &&!skipPutDelete) {
- // add PUT
- PutOperation put = new PutOperation(useOpId, xmlRootElementName, tag, path, pathParams == null ? "" : pathParams.toString());
- pathSb.append(put.toString());
- if ( !path.endsWith("/relationship") ) {
- PatchOperation patch = new PatchOperation(useOpId, xmlRootElementName, tag, path, pathParams == null ? "" : pathParams.toString());
- pathSb.append(patch.toString1());
- }
- logger.debug(put.tagRelationshipPathMapEntry());
-
- // add DELETE
- DeleteOperation del = new DeleteOperation(useOpId, xmlRootElementName, tag, path, pathParams == null ? "" : pathParams.toString());
- pathSb.append(del.toString());
- logger.debug(del.objectPathMapEntry());
- }
-
- }
- if ( generatedJavaType.containsKey(xmlRootElementName) ) {
- return null;
- }
-
- definitionsSb.append(" " + xmlRootElementName + ":\n");
- definitionsLocalSb.append(" " + xmlRootElementName + ":\n");
- Collection<EdgeDescription> edges = getEdgeRules(xmlRootElementName );
-
- if ( edges.size() > 0 ) {
- StringBuffer sbEdge = new StringBuffer();
- sbEdge.append(" ###### Related Nodes\n");
- for (EdgeDescription ed : edges) {
- if ( ed.getRuleKey().startsWith(xmlRootElementName)) {
- sbEdge.append(" - TO ").append(ed.getRuleKey().substring(ed.getRuleKey().indexOf("|")+1));
- sbEdge.append(ed.getRelationshipDescription("TO", xmlRootElementName));
- sbEdge.append("\n");
- }
- }
- for (EdgeDescription ed : edges) {
- if ( ed.getRuleKey().endsWith(xmlRootElementName)) {
- sbEdge.append(" - FROM ").append(ed.getRuleKey().substring(0, ed.getRuleKey().indexOf("|")));
- sbEdge.append(ed.getRelationshipDescription("FROM", xmlRootElementName));
- sbEdge.append("\n");
- }
- }
- // Delete rule processing is incorrect. One cannot express the delete rules in isolation from the
- // specific edge. Take the case of allotted-resource and service-instance. When the service-instance owns the
- // allotted-resource, yes, it deletes it. But when the service-instance only uses the allotted-resource, the deletion
- // of the service instance does not cause the deletion of the allotted-resource.
- // I put some lines into the toDeleteRules and fromDeleteRules to correct things to an extent, but it's still
- // not right.
- sbEdge.append(toDeleteRules(xmlRootElementName));
- sbEdge.append(fromDeleteRules(xmlRootElementName));
- 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 (pathDescriptionProperty != null || validEdges != null) {
- definitionsSb.append(" description: |\n");
- definitionsLocalSb.append(" description: |\n");
-
- if ( pathDescriptionProperty != null ) {
- definitionsSb.append(" " + pathDescriptionProperty + "\n" );
- definitionsLocalSb.append(" " + pathDescriptionProperty + "\n" );
- }
- if (validEdges != null) {
- 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);
- definitionsLocalSb.append(" properties:\n");
- definitionsLocalSb.append(sbProperties);
- }
- try {
- javaTypeDefinitions.put(xmlRootElementName, definitionsLocalSb.toString());
- } catch (Exception e) {
- e.printStackTrace();
- }
- generatedJavaType.put(xmlRootElementName, null);
- return null;
- }
-
- public static void generateRelations() {
- if(putRelationPaths == null)
- return;
- putRelationPaths.forEach((k,v)->{
- logger.trace("k="+k+"\n"+"v="+v+v.equals("/business/customers/customer/{global-customer-id}/service-subscriptions/service-subscription/{service-type}/service-instances/service-instance/{service-instance-id}/allotted-resources/allotted-resource/{id}/relationship-list/relationship"));
- logger.debug("apiPath(Operation): "+v);
- logger.debug("Target object: "+v.replace("/relationship-list/relationship", ""));
- logger.debug("Relations: ");
- PutRelationPathSet prp = new PutRelationPathSet(k, v);
- prp.process();
- });
- }
-
- public static String generateSwaggerFromOxmFile( File oxmFile, String xml )
- {
- if ( xml != null ){
- apiVersion = Version.getLatest().toString();
- apiVersionFmt = "." + apiVersion + ".";
- generatedJavaType = new HashMap<>();
- appliedPaths = new HashMap<>();
- responsesUrl = "Description: response-label\n";
- }
- StringBuffer sb = new StringBuffer();
- sb.append("swagger: \"2.0\"\ninfo:\n ");
- sb.append("description: |");
- sb.append("\n\n [Differences versus the previous schema version]("+"apidocs/aai_swagger_" + apiVersion + ".diff)");
- sb.append("\n\n Copyright © 2017 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 ECOMP and OpenECOMP are trademarks and service marks of AT&T Intellectual Property.\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: \"" + apiVersion +"\"\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: /aai/" + apiVersion + "\n");
- sb.append("schemes:\n - https\npaths:\n");
-
- try {
- File initialFile;
- if(System.getProperty("user.dir") != null && !System.getProperty("user.dir").contains(normalStartDir)) {
- initialFile = new File(normalStartDir + "/src/main/resources/dbedgerules/DbEdgeRules_" + apiVersion + ".json");
- }
- else {
- initialFile = new File("src/main/resources/dbedgerules/DbEdgeRules_" + apiVersion + ".json");
- }
- InputStream is = new FileInputStream(initialFile);
-
- Scanner scanner = new Scanner(is);
- jsonEdges = scanner.useDelimiter("\\Z").next();
- scanner.close();
- is.close();
-
- DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
- dbFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
- DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
- Document doc;
-
- if ( xml == null ) {
- doc = dBuilder.parse(oxmFile);
- } else {
- InputSource isInput = new InputSource(new StringReader(xml));
- doc = dBuilder.parse(isInput);
- }
-
- NodeList bindingsNodes = doc.getElementsByTagName("xml-bindings");
- Element bindingElement;
- NodeList javaTypesNodes;
- Element javaTypesElement;
-
- Element javaTypeElement;
-
-
- if ( bindingsNodes == null || bindingsNodes.getLength() == 0 ) {
- logger.error( "missing <binding-nodes> in " + oxmFile );
- return null;
- }
-
- bindingElement = (Element) bindingsNodes.item(0);
- javaTypesNodes = bindingElement.getElementsByTagName("java-types");
- if ( javaTypesNodes.getLength() < 1 ) {
- logger.error( "missing <binding-nodes><java-types> in " + oxmFile );
- return null;
- }
- javaTypesElement = (Element) javaTypesNodes.item(0);
-
- javaTypeNodes = javaTypesElement.getElementsByTagName("java-type");
- if ( javaTypeNodes.getLength() < 1 ) {
- logger.error( "missing <binding-nodes><java-types><java-type> in " + oxmFile );
- return null;
- }
-
- String javaTypeName;
- String attrName, attrValue;
- Attr attr;
- StringBuffer pathSb = new StringBuffer();
-
- StringBuffer definitionsSb = new StringBuffer();
- for ( int i = 0; i < javaTypeNodes.getLength(); ++ i ) {
- javaTypeElement = (Element) javaTypeNodes.item(i);
- NamedNodeMap attributes = javaTypeElement.getAttributes();
- javaTypeName = null;
- for ( int j = 0; j < attributes.getLength(); ++j ) {
- attr = (Attr) attributes.item(j);
- attrName = attr.getNodeName();
- attrValue = attr.getNodeValue();
- if ( attrName.equals("name"))
- javaTypeName = attrValue;
- }
- if ( javaTypeName == null ) {
- logger.error( "<java-type> has no name attribute in " + oxmFile );
- return null;
- }
- if ( !generatedJavaType.containsKey(getXmlRootElementName(javaTypeName)) ) {
-
- processJavaTypeElementSwagger( javaTypeName, javaTypeElement, pathSb,
- definitionsSb, null, null, null, null, null, null, null);
- }
- }
- sb.append(pathSb);
- } catch (Exception e) {
- e.printStackTrace();
- return null;
- }
- //append definitions
- sb.append("definitions:\n");
- Map<String, String> sortedJavaTypeDefinitions = new TreeMap<String, String>(javaTypeDefinitions);
- for (Map.Entry<String, String> entry : sortedJavaTypeDefinitions.entrySet()) {
- logger.debug("Key: "+entry.getKey()+"Test: "+ (entry.getKey() == "relationship"));
- if(entry.getKey().matches("relationship")) {
- 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()) {
- 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()) {
- String jb=entry.getValue().replaceAll("/definitions/", "/getDefinitions/");
- sb.append(jb);
- }
-
- logger.debug("generated " + sb.toString());
- generateRelations();
- return sb.toString();
- }
-
- private static NodeList locateXmlProperties(Element element) {
- XPathExpression expr;
- NodeList result = null;
- try {
- expr = xpath.compile("xml-properties");
- if (expr != null) {
- Object nodeset = expr.evaluate(element, XPathConstants.NODESET);
- if (nodeset != null) {
- NodeList nodes = (NodeList) nodeset;
- if (nodes != null && nodes.getLength() > 0) {
- Element xmlProperty = (Element)nodes.item(0);
- result = xmlProperty.getElementsByTagName("xml-property");
- }
- }
- }
- } catch (XPathExpressionException e) {
- e.printStackTrace();