2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
26 var dgconverter = new Object();
28 dgconverter.getNodeToXml = function (inputNodeSet) {
29 var exportableNodeSet = JSON.parse(inputNodeSet);
30 //uses inputNodeSet if passed otherwise build the latest nodeSet
32 //$("#btn-deploy").removeClass("disabled");
34 function getDgStartNode(nodeList) {
35 for (var i = 0; i < nodeList.length; i++) {
36 if (nodeList[i].type == 'dgstart' && nodeList[i].wires != null && nodeList[i].wires != undefined) {
44 function getNode(id) {
45 for (var i = 0; i < exportableNodeSet.length; i++) {
46 if (exportableNodeSet[i].id == id) {
47 return exportableNodeSet[i];
53 function getStartTag(node) {
56 if (node != null && node.type != 'dgstart') {
58 var regex = /(<)([\w-]+)(.*)?/;
59 var match = regex.exec(xmlStr);
61 if (match[1] != undefined && match[2] != undefined) {
65 console.log("startTag not found.");
71 // if (inputNodeSet == null || inputNodeSet == undefined) {
72 // exportableNodeSet = getCurrentFlowNodeSet();
74 // exportableNodeSet = JSON.parse(inputNodeSet);
76 var dgstartNode = getDgStartNode(exportableNodeSet);
81 printXml(dgstartNode);
84 function printXml(node) {
87 if (node != null && node.type != 'dgstart') {
88 var comments = node.comments;
89 if (comments != null && comments != "") {
90 //if xml comments field already has the <!-- and --> remove them
91 comments = comments.replace("<!--", "");
92 comments = comments.replace("-->", "");
93 xmlStr = "<!--" + comments + "-->";
96 startTag = getStartTag(node);
97 //special handling for break node
98 if(xmlStr != undefined && xmlStr != null && xmlStr.trim() == "<break>"){
99 fullXmlStr += "<break/>";
105 var spacing = Array(level).join(" ");
106 xmlStr=xmlStr.replace(/\n/g,spacing);
117 //console.log("startTag:" + startTag);
120 var wiredNodesArr = [];
121 if (node != null && node.wires != null && node.wires[0] != null && node.wires[0] != undefined && node.wires[0].length > 0) {
122 wiredNodes = node.wires[0];
123 //console.log("Before sort");
124 for (var k = 0; wiredNodes != undefined && wiredNodes != null && k < wiredNodes.length; k++) {
125 wiredNodesArr.push(getNode(wiredNodes[k]));
127 //console.dir(wiredNodesArr);
128 //sort based on y position
129 wiredNodesArr.sort(function (a, b) {
132 //console.log("After sort");
133 //console.dir(wiredNodesArr);
136 for (var k = 0; wiredNodesArr != null && k < wiredNodesArr.length; k++) {
138 var nd = wiredNodesArr[k];
143 if (startTag != "") {
144 if(startTag != "break"){
145 fullXmlStr += "</" + startTag + ">";
149 var spacing = Array(level).join(" ");
150 fullXmlStr += spacing + "</" + startTag + ">";
151 console.log(spacing + "</" + startTag + ">");
153 fullXmlStr += "</" + startTag + ">";
154 console.log("</" + startTag + ">");
163 //console.log("endTag:" + startTag);
164 //console.log("xml:" + fullXmlStr);
166 //console.log("fullXmlStr:" + fullXmlStr);