1 /*******************************************************************************
2 * Copyright (c) 2013 Pascal Hirmer.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * and the Apache License 2.0 which both accompany this distribution,
6 * and are available at http://www.eclipse.org/legal/epl-v10.html
7 * and http://www.apache.org/licenses/LICENSE-2.0
10 * Pascal Hirmer - initial API and implementation
11 *******************************************************************************/
16 * This module handles a click on "Complete Topology" in the enterTopologyCompletionInformation dialog.
20 restartCompletion: restartCompletion
25 * This function start the topology completion. With information from the
26 * PolicyInformationDialog the topologyCompletion.jsp is called which will invoke the
27 * Topology Completion java component. The parameters determine if the current topology
28 * will be overwritten or if a new topology is created.
30 * @param (String) overwriteTopology
31 * determines how to save the topology. If true, the current topology is overwritten.
32 * @param (Boolean) openInNewWindow
33 * determines if the result is opened in a new window
34 * @param (String) topologyName
35 * the name of the new topology
36 * @param (String) topologyNamespace
37 * the namespace of the new topology
38 * @param (Boolean) stepByStep
39 * if true, the completion will be processed step by step
40 * @param (String) repositoryURL
41 * the URL to the repository the topology is saved to
42 * @param (String) toscaNamespace
43 * the namespace URL of TOSCA
44 * @param (String) wineryNamespace
45 * the namespace URL of winery
46 * @param (String) serviceTemplateName
47 * the name of the service template containing the displayed topology template
48 * @param (String) topologyTemplateURL
49 * the URL to the displayed topology template
51 function complete(overwriteTopology, openInNewWindow, topologyName, topologyNamespace, stepByStep, repositoryURL, serviceTemplateName, topologyTemplateURL) {
53 // if the user wants to create a new topology, a post call is sent to the repository adding
54 // the new ServiceTemplate
55 if (!overwriteTopology) {
56 var dataToSend = "name=" + topologyName + "&namespace=" + topologyNamespace;
57 var url = repositoryURL + "/servicetemplates/";
65 error: function(jqXHR, textStatus, errorThrown) {
66 vShowAJAXError("Could not add Service Template.");
73 require(["winery-topologymodeler-AMD"], function(wt) {
74 topology = wt.getTopologyTemplateAsXML(true);
76 // call to the completion JSP which will call the java component
77 $.post("jsp/topologyCompletion/topologyCompletion.jsp", {topology: topology, stName: serviceTemplateName, templateURL: topologyTemplateURL, overwriteTopology: overwriteTopology, topologyName: topologyName, topologyNamespace: topologyNamespace, repositoryURL: repositoryURL, stepByStep: stepByStep, openInNewWindow: openInNewWindow, restarted: "false"},
79 * Callback function which will either open a new window if a new topology was created or
80 * refresh the current browser window
82 * @param (String) data
83 * the answer of the post call
86 // checks the message returned by the CompletionInterface
87 if (data.indexOf("topologyComplete") != -1) {
88 vShowSuccess('The topology is already complete.');
89 } else if (data.indexOf("failure") != -1) {
91 } else if (data.indexOf("userTopologySelection") != -1) {
92 $(chooseTopologyDiag[0].children[0].children[0].children[1]).html(data);
93 window.setTimeout(jsPlumb.repaintEverything, JQUERY_ANIMATION_DURATION);
94 chooseTopologyDiag.modal("show");
95 } else if (data.indexOf("topologyComplete") == -1 && data.indexOf("userTopologySelection") == -1 && data.indexOf("userInteraction") != -1) {
96 $(chooseRelationshipTemplateDiag[0].children[0].children[0].children[1]).html(data);
97 window.setTimeout(jsPlumb.repaintEverything, JQUERY_ANIMATION_DURATION);
98 chooseRelationshipTemplateDiag.modal("show");
99 } else if (data.indexOf("topologyComplete") == -1 && data.indexOf("stepByStep") != -1) {
100 $(chooseNodeTemplateDiag[0].children[0].children[0].children[1]).html(data);
101 window.setTimeout(jsPlumb.repaintEverything, JQUERY_ANIMATION_DURATION);
102 chooseNodeTemplateDiag.modal("show");
104 if (openInNewWindow) {
105 // a new topology has been created, open it in a new window
106 var win=window.open('?repositoryURL=' + repositoryURL + '&ns='+ topologyNamespace + '&id=' + topologyName, '_blank');
108 } else if (overwriteTopology) {
110 document.location.reload(true);
119 * This function restarts the topology completion when it has been stopped to get a
122 * @param (String) topology
123 * the topology as XML string
124 * @param (String) overwriteTopology
125 * determines how to save the topology. Can contain the values "createNew" or "overwrite"
126 * @param (Boolean) openInNewWindow
127 * determines if the result is opened in a new window
128 * @param (String) topologyName
129 * the name of the new topology
130 * @param (String) topologyNamespace
131 * the namespace of the new topology
132 * @param (Boolean) stepByStep
133 * if true, the completion will be processed step by step
134 * @param (String) serviceTemplateName
135 * the name of the service template containing the displayed topology template
136 * @param (String) topologyTemplateURL
137 * the URL to the displayed topology template
138 * @param (String) repositoryURL
139 * the URL to the repository the topology is saved to
141 function restartCompletion(topology, overwriteTopology, openInNewWindow, topologyName, topologyNamespace, stepByStep, serviceTemplateName, topologyTemplateURL, repositoryURL) {
143 // remove whitespaces in the topology XML string
144 topology = topology.replace(/\s+/g, ' ');
145 topology = topology.substr(1);
147 // call to the completion JSP which will call the java component
148 $.post("jsp/topologyCompletion/topologyCompletion.jsp", { topology: topology, stName: serviceTemplateName, templateURL: topologyTemplateURL, overwriteTopology: overwriteTopology, topologyName: topologyName, topologyNamespace: topologyNamespace, repositoryURL: repositoryURL, stepByStep: stepByStep, restarted: "true"},
150 * Callback function which will either open a new window if a new topology was created or
151 * refresh the current browser window
153 * @param (String) data
154 * the answer of the post call
157 if (data.indexOf("Successful") == -1 && data.indexOf("stepByStep") == -1) {
158 $(chooseRelationshipTemplateDiag[0].children[0].children[0].children[1]).html(data);
159 window.setTimeout(jsPlumb.repaintEverything, JQUERY_ANIMATION_DURATION);
160 chooseRelationshipTemplateDiag.modal("show");
161 } else if (data.indexOf("Successful") == -1 && data.indexOf("stepByStep") != -1) {
162 $(chooseNodeTemplateDiag[0].children[0].children[0].children[1]).html(data);
163 window.setTimeout(jsPlumb.repaintEverything, JQUERY_ANIMATION_DURATION);
164 chooseNodeTemplateDiag.modal("show");
166 if (openInNewWindow) {
167 // a new topology has been created, open it in a new window
168 var win = window.open('?repositoryURL=' + "<%=repositoryURL%>" + '&ns='+ topologyNamespace + '&id=' + topologyName, '_blank');
170 } else if (overwriteTopology) {
172 document.location.reload(true);