Merge "Reorder modifiers"
[so.git] / bpmn / MSOCommonBPMN / src / main / groovy / org / openecomp / mso / bpmn / common / scripts / MsoUtils.groovy
index cd5ae79..719aeb8 100644 (file)
@@ -59,6 +59,21 @@ class MsoUtils {
                }\r
                return nodes\r
        }\r
+       /**\r
+        * Note: this uses XmlParser instead of XmlSlurper, thus it is not as\r
+        * efficient because it instantiates the whole DOM tree.\r
+        * @param xmlInput\r
+        * @param element\r
+        * @return a list of Nodes, or {@code null} if <i>xmlInput</i> is {@code null}\r
+        */\r
+       def getMultNodeObjects(xmlInput, element){\r
+               def nodes=null\r
+               if(xmlInput!=null){\r
+                       def xml= new XmlParser().parseText(xmlInput)\r
+                       nodes = xml.'**'.findAll{ node-> node.name() == element }\r
+               }\r
+               return nodes\r
+       }\r
        def getNodeText1(xmlInput,element){\r
                def rtn=null\r
                if(xmlInput!=null){\r
@@ -283,7 +298,7 @@ class MsoUtils {
        def log(logmode,logtxt,isDebugLogEnabled="false"){\r
                MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL);\r
                if ("INFO"==logmode) {\r
-                       msoLogger.info(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, logtxt);\r
+                       msoLogger.info(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, logtxt, "BPMN", MsoLogger.getServiceName());\r
                } else if ("WARN"==logmode) {\r
                        // to see the warning text displayed in the log entry, the text must also be passed as arg0 (2nd argument) to invoke the correct MsoLogger warn() method\r
                        msoLogger.warn (MessageEnum.BPMN_GENERAL_WARNING, logtxt, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, logtxt);\r
@@ -971,4 +986,31 @@ class MsoUtils {
 \r
                return requestId\r
        }\r
+\r
+       /**\r
+        * Remove all the empty nodes and attributes from the within the given node\r
+        * @param node\r
+        * @return true if all empty nodes and attributes were removed.\r
+        */\r
+       public boolean cleanNode( Node node ) {\r
+               node.attributes().with { a ->\r
+                       a.findAll { !it.value }.each { a.remove( it.key ) }\r
+               }\r
+               node.children().with { kids ->\r
+                       kids.findAll { it instanceof Node ? !cleanNode( it ) : false }\r
+                                       .each { kids.remove( it ) }\r
+               }\r
+               node.attributes() || node.children() || node.text()\r
+       }\r
+\r
+       /**\r
+        *\r
+        * @param xml\r
+        * @return String representation of xml after removing the empty nodes and attributes\r
+        */\r
+       public String cleanNode(String xmlString) {\r
+               def xml = new XmlParser(false, false).parseText(xmlString)\r
+               cleanNode(xml)\r
+               return XmlUtil.serialize(xml)\r
+       }\r
 }\r