<commit_before><%--
/*******************************************************************************
 * Copyright (c) 2012-2013 University of Stuttgart.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * and the Apache License 2.0 which both accompany this distribution,
 * and are available at http://www.eclipse.org/legal/epl-v10.html
 * and http://www.apache.org/licenses/LICENSE-2.0
 *
 * Contributors:
 *    <NAME> - initial API and implementation and/or initial documentation
 *    <NAME> - integration with the repository, adapted to TOSCA v1.0
 *    <NAME> - switch to bootstrap 3
 *******************************************************************************/
--%>

<%@page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@page buffer="none" %>
<%@page import="java.util.Collection"%>
<%@page import="java.util.List"%>
<%@page import="java.util.LinkedList"%>
<%@page import="java.util.Map"%>
<%@page import="java.util.SortedSet"%>
<%@page import="javax.xml.namespace.QName"%>
<%@page import="org.apache.commons.lang3.StringUtils"%>
<%@page import="org.eclipse.winery.model.tosca.TArtifactTemplate"%>
<%@page import="org.eclipse.winery.model.tosca.TArtifactType"%>
<%@page import="org.eclipse.winery.model.tosca.TCapability"%>
<%@page import="org.eclipse.winery.model.tosca.TCapabilityType"%>
<%@page import="org.eclipse.winery.model.tosca.TEntityTemplate"%>
<%@page import="org.eclipse.winery.model.tosca.TTopologyTemplate"%>
<%@page import="org.eclipse.winery.model.tosca.TNodeTemplate"%>
<%@page import="org.eclipse.winery.model.tosca.TNodeType"%>
<%@page import="org.eclipse.winery.model.tosca.TPolicyType"%>
<%@page import="org.eclipse.winery.model.tosca.TRelationshipType"%>
<%@page import="org.eclipse.winery.model.tosca.TRelationshipTemplate"%>
<%@page import="org.eclipse.winery.model.tosca.TRelationshipTemplate.SourceElement"%>
<%@page import="org.eclipse.winery.model.tosca.TRelationshipTemplate.TargetElement"%>
<%@page import="org.eclipse.winery.model.tosca.TRequirement"%>
<%@page import="org.eclipse.winery.model.tosca.TRequirementType"%>
<%@page import="org.eclipse.winery.common.constants.Namespaces" %>
<%@page import="org.eclipse.winery.common.ids.definitions.ArtifactTemplateId"%>
<%@page import="org.eclipse.winery.common.ids.definitions.ServiceTemplateId" %>
<%@page import="org.eclipse.winery.common.interfaces.QNameWithName"%>
<%@page import="org.eclipse.winery.common.constants.QNames" %>
<%@page import="org.eclipse.winery.common.ModelUtilities"%>
<%@page import="org.eclipse.winery.common.Util"%>
<%@page import="org.eclipse.winery.repository.client.WineryRepositoryClientFactory"%>
<%@page import="org.eclipse.winery.repository.client.IWineryRepositoryClient"%>
<%@page import="org.eclipse.winery.repository.client.WineryRepositoryClient"%>
<%@page import="org.eclipse.winery.topologymodeler.WineryUtil"%>
<%@page import="com.sun.jersey.api.client.WebResource"%>
<%@page import="com.sun.jersey.api.client.Client"%>
<%@page import="com.sun.jersey.api.client.ClientResponse"%>
<%@page import="com.sun.jersey.api.client.config.ClientConfig"%>
<%@page import="com.sun.jersey.api.client.config.DefaultClientConfig"%>

<%-- nc.. = non-common .. --%>
<%@taglib prefix="ncnt"  tagdir="/WEB-INF/tags/templates/nodetemplates" %>
<%@taglib prefix="ncrt"  tagdir="/WEB-INF/tags/templates/relationshiptemplates" %>
<%@taglib prefix="tntrq" tagdir="/WEB-INF/tags/templates/nodetemplates/reqscaps" %>

<%@taglib prefix="ct"    tagdir="/WEB-INF/tags/common" %>
<%@taglib prefix="tmpl"  tagdir="/WEB-INF/tags/common/templates" %>
<%@taglib prefix="nt"    tagdir="/WEB-INF/tags/common/templates/nodetemplates" %>
<%@taglib prefix="ntrq"  tagdir="/WEB-INF/tags/common/templates/nodetemplates/reqscaps" %>
<%@taglib prefix="pol"   tagdir="/WEB-INF/tags/common/policies" %>

<%@taglib prefix="t"     tagdir="/WEB-INF/tags" %>

<%@taglib prefix="c"     uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="wc"    uri="http://www.eclipse.org/winery/functions" %>

<%@taglib prefix="tc"   tagdir="/WEB-INF/tags/common/topologycompletion"%>

<%
	String repositoryURL = request.getParameter("repositoryURL");
	if (StringUtils.isEmpty(repositoryURL)) {
		repositoryURL = "http://localhost:8080/winery";
	} else if (repositoryURL.endsWith("/")) {
		repositoryURL = repositoryURL.substring(0, repositoryURL.length()-1);
	}

	String ns = request.getParameter("ns");
	if (StringUtils.isEmpty(ns)) {
%>
		A namespace has to be provided by using the query parameter &ldquo;ns.&rdquo; Please start the modeler using the <a href="<%=repositoryURL%>">repository</a>.
<%
		return;
	}

	String id = request.getParameter("id");
	if (StringUtils.isEmpty(id)) {
%>
		An id has to be provided by using the query parameter &ldquo;id.&rdquo; Please start the modeler using the <a href="<%=repositoryURL%>">repository</a>.
<%
		return;
	}

	// initialize client dependend on useproxy URL parameter
	IWineryRepositoryClient client;
	if (request.getParameterMap().containsKey("useproxy")) {
		// debugging - using fiddler:
		client = new WineryRepositoryClient(true);
		System.out.println("Using a proxy...");
	} else {
		// production:
		client = WineryRepositoryClientFactory.getWineryRepositoryClient();
	}

	client.addRepository(repositoryURL);

	if (!client.primaryRepositoryAvailable()) {
%>
		The repository is not available.
<%
		return;
	}

	QName serviceTemplateQName = new QName(ns, id);
	TTopologyTemplate topologyTemplate = client.getTopologyTemplate(serviceTemplateQName);
	if (topologyTemplate == null) {
%>
		Something went wrong in the repository: topology template not found.
<%
		return;
	}

	String topologyTemplateURL = repositoryURL + "/servicetemplates/" + Util.DoubleURLencode(serviceTemplateQName) + "/topologytemplate/";

	String serviceTemplateName = client.getName(new ServiceTemplateId(serviceTemplateQName));

	Collection<TRelationshipType> relationshipTypes = client.getAllTypes(TRelationshipType.class);
%>
<!DOCTYPE html>
<html>
<head>
	<title>Winery Topologymodeler &ndash; <%= serviceTemplateName %></title>
	<meta http-equiv="content-type" content="text/html;charset=utf-8" />

	<link rel="icon" href="favicon.png" type="image/png">

	<link rel="stylesheet" href="components/bootstrap/dist/css/bootstrap.css" />
	<link rel="stylesheet" href="components/bootstrap/dist/css/bootstrap-theme.css" />
	<link rel="stylesheet" href="components/bootstrap-spinedit/css/bootstrap-spinedit.css" />

	<link rel="stylesheet" href="components/blueimp-file-upload/css/jquery.fileupload.css" />
	<link rel="stylesheet" href="components/blueimp-file-upload/css/jquery.fileupload-ui.css" />

	<link type="text/css" href="components/pnotify/jquery.pnotify.default.css" media="all" rel="stylesheet" />
	<link type="text/css" href="components/pnotify/jquery.pnotify.default.icons.css" media="all" rel="stylesheet" />

	<!-- select2 -->
	<link type="text/css" href="components/select2/select2.css" media="all" rel="stylesheet" />
	<link type="text/css" href="components/select2/select2-bootstrap.css" media="all" rel="stylesheet" />

	<!-- x-editable -->
	<link type="text/css" href="components/x-editable/dist/bootstrap3-editable/css/bootstrap-editable.css" media="all" rel="stylesheet" />

	<link rel="stylesheet" type="text/css" href="http://eclipse.org/orion/editor/releases/6.0/built-editor.css"/>

	<!--  Winery as last: Winrey also overwrites some definitions from above -->
	<link rel="stylesheet" href="css/winery-common.css" />
	<link rel="stylesheet" href="css/topologytemplatecontent.css" />
	<link rel="stylesheet" href="css/topologymodeler.css" />
</head>

<body data-demo-id="drawingarea" data-library="jquery">

<div id="loading">loading...</div>

<script type='text/javascript' src='${pageContext.request.contextPath}/components/requirejs/require.js'></script>
<script>
	require.config({
		baseUrl: "${pageContext.request.contextPath}/js",
		paths: {
			"datatables": "../components/datatables/media/js/jquery.dataTables",
			"jquery": "../components/jquery/jquery",

			"jquery.fileupload": "../components/blueimp-file-upload/js/jquery.fileupload",
			"jquery.fileupload-ui": "../components/blueimp-file-upload/js/jquery.fileupload-ui",
			"jquery.fileupload-process": "../components/blueimp-file-upload/js/jquery.fileupload-process",
			"jquery.ui.widget": "../components/blueimp-file-upload/js/vendor/jquery.ui.widget",

			// required for jsplumb
			"jquery.ui": "../3rdparty/jquery-ui/js/jquery-ui",

			"jsplumb": "../components/jsPlumb/dist/js/jquery.jsPlumb-1.5.4",

			"keyboardjs": "../components/KeyboardJS/keyboard",
			"orioneditor": "http://eclipse.org/orion/editor/releases/6.0/built-editor-amd",
			"pnotify": "../components/pnotify/jquery.pnotify",
			"select2": "../components/select2/select2",
			"tmpl": "../components/blueimp-tmpl/js/tmpl",
			"XMLWriter": "../components/XMLWriter/XMLWriter"
		}
	});
</script>

<script type='text/javascript' src='components/jquery/jquery.js'></script>

<script type='text/javascript' src='3rdparty/jquery-ui/js/jquery-ui.js'></script>

<script type='text/javascript' src='components/bootstrap/dist/js/bootstrap.js'></script>

<script type='text/javascript' src='components/bootstrap-spinedit/js/bootstrap-spinedit.js'></script>

<!--  udpate of jquery widget by jQuery-File-Upload, which requires jQuery UI 1.9 at least -->
<!-- <script type="text/javascript" src="components/jQuery-File-Upload/js/vendor/jquery.ui.widget.js"></script> -->

<script type='text/javascript' src='components/jsPlumb/dist/js/jquery.jsPlumb-1.5.4.js'></script>

<script type="text/javascript" src="components/jquery-typing/plugin/jquery.typing-0.3.2.js"></script>

<script type="text/javascript" src="components/select2/select2.js"></script>

<script type="text/javascript" src="components/x-editable/dist/bootstrap3-editable/js/bootstrap-editable.js"></script>

<script type="text/javascript" src="js/winery-common.js"></script>
<script type="text/javascript" src="js/winery-topologymodeler.js"></script>

<jsp:include page="/jsp/shared/dialogs.jsp" />

<%
  // only required for generating the CSS for each node type
  Collection<TNodeType> allNodeTypes = client.getAllTypes(TNodeType.class);
%>

<tmpl:CSSForTypes nodeTypes="<%=allNodeTypes%>" relationshipTypes="<%=relationshipTypes%>"/>

<tmpl:propertiesBasic />

<t:about />

<script>
// global variable hodling data for relationship templates
if (!winery) winery = {};

// winery.connections is a hashmap from jsPlumb id to a data structure with
// .id = winery id; // The two ids DO NOT match. Explanation is at winery-common-topologyrendering.js
// ...
winery.connections = {};

// all x-editable popups should be placed in a way to fit "perfectly" on the screen
$.fn.editable.defaults.placement = "auto";

//configuration for pnotify
require(["jquery", "pnotify"], function() {
	$.pnotify.defaults.styling = "bootstrap3";
});
</script>

<%-- Begin: Add&Edit Req/Cap --%>

<%List<QName> allTypes = client.getQNameListOfAllTypes(TRequirementType.class);%>
<tntrq:addorupdatereqorcap requirementOrCapability="requirement" shortName="Req" cssClassPrefix="requirements" headerLabel="Requirement" allTypes="<%=allTypes%>" clazz="<%=TRequirement.class%>" repositoryURL="<%=repositoryURL%>" />

<%allTypes = client.getQNameListOfAllTypes(TCapabilityType.class);%>
<tntrq:addorupdatereqorcap requirementOrCapability="capability" shortName="Cap" cssClassPrefix="capabilities" headerLabel="Capability" allTypes="<%=allTypes%>" clazz="<%=TCapability.class%>" repositoryURL="<%=repositoryURL%>" />

<%-- End: Add&Edit Req/Cap --%>

<%allTypes = client.getQNameListOfAllTypes(TPolicyType.class);%>
<pol:policydiag allPolicyTypes="<%=allTypes%>" repositoryURL="<%=repositoryURL%>" />

<script>
"use strict";

// for debugging
//$.pnotify.defaults.remove = false;

// global data structure
// .repositoryURL - the URL of the repository
// DOES NOT end with /
winery.repositoryURL = "<%=repositoryURL%>";

</script>

<script>
/**
 * Uses global variables currentlySelectedNodeTemplate and currentlySelectedDeploymentArtifactDiv
 *
 * @param atDelete (optional). Function to be called if the DA has been successfully deleted
 */
function askForDeploymentArtifactDeletion(atDelete) {
	// we have to remove it on both the node template locally and on the server
	// reason: if the user does NOT save after deletion, the repository would present him
	// the DA again. Possibly with a dangeling reference to the artifact template,
	// which might have been deleted if this DA was the last reference to it

	var daName = currentlySelectedDeploymentArtifactDiv.children("div.name").text();
	var url = "<%=topologyTemplateURL%>nodetemplates/" + encodeID(currentlySelectedNodeTemplate) + "/deploymentartifacts/" + daName;
	deleteResource("this deployment artifact", url, function() {
		currentlySelectedDeploymentArtifactDiv.remove();
		$("#DeploymentArtifactInfo").modal("hide");
		if (atDelete) {
			atDelete();
		}
	});
}

/**
 * Queries the user for deletion of the currently selected DA.
 * If the associated artifact template points to the current DA only, he is also ask if he wants to delete that template, too.
 */
function deleteDeploymentArtifact() {
	var templateURL = $("#DAArtifactTemplate").attr("href");
	// an artifact template exists
	// we have to ask the user if the wants to delete is as well
	// IF this deployment artifact is the only reference to it
	// The user has to be first asked for DA deletion and then for artifact template deletion
	// Therefore, we pass a function to be executed AFTER deletion of the deployment artifact.
	if (templateURL) {
		// check for count
		$.ajax({
			type: "GET",
			async: false,
			url: templateURL + "?referenceCount",
			dataType: "text",
			error: function(jqXHR, textStatus, errorThrown) {
				vShowAJAXError("Could not get count of artifact template usage", jqXHR, errorThrown);
			},
			success: function(resData, textStatus, jqXHR) {
				if (resData == "1") {
					var atDelete = function() {
						deleteResource("the associated artifact template", templateURL, function() {});
					};
					askForDeploymentArtifactDeletion(atDelete);
				} else {
					// more than one reference to the artifact template
					// just ask for deletion of the DA and not of the AT
					askForDeploymentArtifactDeletion();
				}
			}
		});
	} else {
		askForDeploymentArtifactDeletion();
	}
}

/**
 * The user might have updated the XML information
 * This has to be copied into the "storage" of the currently selected node template
 *
 * Uses global variable currentlySelectedDeploymentArtifactDiv
 */
function updateDeploymentArtifact() {
	require(["winery-support-common"], function(wsc) {
		var newVal = $("#DAXML").val();
		if (wsc.checkXMLValidityAndShowErrorIfInvalid(newVal)) {
			currentlySelectedDeploymentArtifactDiv.children("textarea").val(newVal);
			$("#DeploymentArtifactInfo").modal("hide");
		}
	});
}
</script>
<div class="modal fade" id="DeploymentArtifactInfo">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h4 class="modal-title">Artifact Information</h4>
			</div>
			<div class="modal-body">
				<form><fieldset>
					<div class="form-group">
						<label for="DADname" class="control-label">Name</label>
						<div id="DAname" class="form-control"></div>
					</div>

					<div class="form-group">
						<label for="DAArtifactType" class="control-label">Artifact Type</label>
						<a id="DAArtifactType" class="form-control"></a>
					</div>
					<div class="form-group">
						<label for="DAArtifactTemplate" class="control-label">Artifact Template</label>
						<a id="DAArtifactTemplate" class="form-control"></a>
					</div>
					<div class="form-group">
						<label for=DAXML" class="control-label">XML</label>
						<textarea id="DAXML" cols=50 rows=7 class="form-control"></textarea>
					</div><commit_msg>Artifact Type and Artifact Template now opened in separate tab<commit_after><%--
/*******************************************************************************
 * Copyright (c) 2012-2013 University of Stuttgart.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * and the Apache License 2.0 which both accompany this distribution,
 * and are available at http://www.eclipse.org/legal/epl-v10.html
 * and http://www.apache.org/licenses/LICENSE-2.0
 *
 * Contributors:
 *    <NAME> - initial API and implementation and/or initial documentation
 *    <NAME> - integration with the repository, adapted to TOSCA v1.0
 *    <NAME> - switch to bootstrap 3
 *******************************************************************************/
--%>

<%@page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@page buffer="none" %>
<%@page import="java.util.Collection"%>
<%@page import="java.util.List"%>
<%@page import="java.util.LinkedList"%>
<%@page import="java.util.Map"%>
<%@page import="java.util.SortedSet"%>
<%@page import="javax.xml.namespace.QName"%>
<%@page import="org.apache.commons.lang3.StringUtils"%>
<%@page import="org.eclipse.winery.model.tosca.TArtifactTemplate"%>
<%@page import="org.eclipse.winery.model.tosca.TArtifactType"%>
<%@page import="org.eclipse.winery.model.tosca.TCapability"%>
<%@page import="org.eclipse.winery.model.tosca.TCapabilityType"%>
<%@page import="org.eclipse.winery.model.tosca.TEntityTemplate"%>
<%@page import="org.eclipse.winery.model.tosca.TTopologyTemplate"%>
<%@page import="org.eclipse.winery.model.tosca.TNodeTemplate"%>
<%@page import="org.eclipse.winery.model.tosca.TNodeType"%>
<%@page import="org.eclipse.winery.model.tosca.TPolicyType"%>
<%@page import="org.eclipse.winery.model.tosca.TRelationshipType"%>
<%@page import="org.eclipse.winery.model.tosca.TRelationshipTemplate"%>
<%@page import="org.eclipse.winery.model.tosca.TRelationshipTemplate.SourceElement"%>
<%@page import="org.eclipse.winery.model.tosca.TRelationshipTemplate.TargetElement"%>
<%@page import="org.eclipse.winery.model.tosca.TRequirement"%>
<%@page import="org.eclipse.winery.model.tosca.TRequirementType"%>
<%@page import="org.eclipse.winery.common.constants.Namespaces" %>
<%@page import="org.eclipse.winery.common.ids.definitions.ArtifactTemplateId"%>
<%@page import="org.eclipse.winery.common.ids.definitions.ServiceTemplateId" %>
<%@page import="org.eclipse.winery.common.interfaces.QNameWithName"%>
<%@page import="org.eclipse.winery.common.constants.QNames" %>
<%@page import="org.eclipse.winery.common.ModelUtilities"%>
<%@page import="org.eclipse.winery.common.Util"%>
<%@page import="org.eclipse.winery.repository.client.WineryRepositoryClientFactory"%>
<%@page import="org.eclipse.winery.repository.client.IWineryRepositoryClient"%>
<%@page import="org.eclipse.winery.repository.client.WineryRepositoryClient"%>
<%@page import="org.eclipse.winery.topologymodeler.WineryUtil"%>
<%@page import="com.sun.jersey.api.client.WebResource"%>
<%@page import="com.sun.jersey.api.client.Client"%>
<%@page import="com.sun.jersey.api.client.ClientResponse"%>
<%@page import="com.sun.jersey.api.client.config.ClientConfig"%>
<%@page import="com.sun.jersey.api.client.config.DefaultClientConfig"%>

<%-- nc.. = non-common .. --%>
<%@taglib prefix="ncnt"  tagdir="/WEB-INF/tags/templates/nodetemplates" %>
<%@taglib prefix="ncrt"  tagdir="/WEB-INF/tags/templates/relationshiptemplates" %>
<%@taglib prefix="tntrq" tagdir="/WEB-INF/tags/templates/nodetemplates/reqscaps" %>

<%@taglib prefix="ct"    tagdir="/WEB-INF/tags/common" %>
<%@taglib prefix="tmpl"  tagdir="/WEB-INF/tags/common/templates" %>
<%@taglib prefix="nt"    tagdir="/WEB-INF/tags/common/templates/nodetemplates" %>
<%@taglib prefix="ntrq"  tagdir="/WEB-INF/tags/common/templates/nodetemplates/reqscaps" %>
<%@taglib prefix="pol"   tagdir="/WEB-INF/tags/common/policies" %>

<%@taglib prefix="t"     tagdir="/WEB-INF/tags" %>

<%@taglib prefix="c"     uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="wc"    uri="http://www.eclipse.org/winery/functions" %>

<%@taglib prefix="tc"   tagdir="/WEB-INF/tags/common/topologycompletion"%>

<%
	String repositoryURL = request.getParameter("repositoryURL");
	if (StringUtils.isEmpty(repositoryURL)) {
		repositoryURL = "http://localhost:8080/winery";
	} else if (repositoryURL.endsWith("/")) {
		repositoryURL = repositoryURL.substring(0, repositoryURL.length()-1);
	}

	String ns = request.getParameter("ns");
	if (StringUtils.isEmpty(ns)) {
%>
		A namespace has to be provided by using the query parameter &ldquo;ns.&rdquo; Please start the modeler using the <a href="<%=repositoryURL%>">repository</a>.
<%
		return;
	}

	String id = request.getParameter("id");
	if (StringUtils.isEmpty(id)) {
%>
		An id has to be provided by using the query parameter &ldquo;id.&rdquo; Please start the modeler using the <a href="<%=repositoryURL%>">repository</a>.
<%
		return;
	}

	// initialize client dependend on useproxy URL parameter
	IWineryRepositoryClient client;
	if (request.getParameterMap().containsKey("useproxy")) {
		// debugging - using fiddler:
		client = new WineryRepositoryClient(true);
		System.out.println("Using a proxy...");
	} else {
		// production:
		client = WineryRepositoryClientFactory.getWineryRepositoryClient();
	}

	client.addRepository(repositoryURL);

	if (!client.primaryRepositoryAvailable()) {
%>
		The repository is not available.
<%
		return;
	}

	QName serviceTemplateQName = new QName(ns, id);
	TTopologyTemplate topologyTemplate = client.getTopologyTemplate(serviceTemplateQName);
	if (topologyTemplate == null) {
%>
		Something went wrong in the repository: topology template not found.
<%
		return;
	}

	String topologyTemplateURL = repositoryURL + "/servicetemplates/" + Util.DoubleURLencode(serviceTemplateQName) + "/topologytemplate/";

	String serviceTemplateName = client.getName(new ServiceTemplateId(serviceTemplateQName));

	Collection<TRelationshipType> relationshipTypes = client.getAllTypes(TRelationshipType.class);
%>
<!DOCTYPE html>
<html>
<head>
	<title>Winery Topologymodeler &ndash; <%= serviceTemplateName %></title>
	<meta http-equiv="content-type" content="text/html;charset=utf-8" />

	<link rel="icon" href="favicon.png" type="image/png">

	<link rel="stylesheet" href="components/bootstrap/dist/css/bootstrap.css" />
	<link rel="stylesheet" href="components/bootstrap/dist/css/bootstrap-theme.css" />
	<link rel="stylesheet" href="components/bootstrap-spinedit/css/bootstrap-spinedit.css" />

	<link rel="stylesheet" href="components/blueimp-file-upload/css/jquery.fileupload.css" />
	<link rel="stylesheet" href="components/blueimp-file-upload/css/jquery.fileupload-ui.css" />

	<link type="text/css" href="components/pnotify/jquery.pnotify.default.css" media="all" rel="stylesheet" />
	<link type="text/css" href="components/pnotify/jquery.pnotify.default.icons.css" media="all" rel="stylesheet" />

	<!-- select2 -->
	<link type="text/css" href="components/select2/select2.css" media="all" rel="stylesheet" />
	<link type="text/css" href="components/select2/select2-bootstrap.css" media="all" rel="stylesheet" />

	<!-- x-editable -->
	<link type="text/css" href="components/x-editable/dist/bootstrap3-editable/css/bootstrap-editable.css" media="all" rel="stylesheet" />

	<link rel="stylesheet" type="text/css" href="http://eclipse.org/orion/editor/releases/6.0/built-editor.css"/>

	<!--  Winery as last: Winrey also overwrites some definitions from above -->
	<link rel="stylesheet" href="css/winery-common.css" />
	<link rel="stylesheet" href="css/topologytemplatecontent.css" />
	<link rel="stylesheet" href="css/topologymodeler.css" />
</head>

<body data-demo-id="drawingarea" data-library="jquery">

<div id="loading">loading...</div>

<script type='text/javascript' src='${pageContext.request.contextPath}/components/requirejs/require.js'></script>
<script>
	require.config({
		baseUrl: "${pageContext.request.contextPath}/js",
		paths: {
			"datatables": "../components/datatables/media/js/jquery.dataTables",
			"jquery": "../components/jquery/jquery",

			"jquery.fileupload": "../components/blueimp-file-upload/js/jquery.fileupload",
			"jquery.fileupload-ui": "../components/blueimp-file-upload/js/jquery.fileupload-ui",
			"jquery.fileupload-process": "../components/blueimp-file-upload/js/jquery.fileupload-process",
			"jquery.ui.widget": "../components/blueimp-file-upload/js/vendor/jquery.ui.widget",

			// required for jsplumb
			"jquery.ui": "../3rdparty/jquery-ui/js/jquery-ui",

			"jsplumb": "../components/jsPlumb/dist/js/jquery.jsPlumb-1.5.4",

			"keyboardjs": "../components/KeyboardJS/keyboard",
			"orioneditor": "http://eclipse.org/orion/editor/releases/6.0/built-editor-amd",
			"pnotify": "../components/pnotify/jquery.pnotify",
			"select2": "../components/select2/select2",
			"tmpl": "../components/blueimp-tmpl/js/tmpl",
			"XMLWriter": "../components/XMLWriter/XMLWriter"
		}
	});
</script>

<script type='text/javascript' src='components/jquery/jquery.js'></script>

<script type='text/javascript' src='3rdparty/jquery-ui/js/jquery-ui.js'></script>

<script type='text/javascript' src='components/bootstrap/dist/js/bootstrap.js'></script>

<script type='text/javascript' src='components/bootstrap-spinedit/js/bootstrap-spinedit.js'></script>

<!--  udpate of jquery widget by jQuery-File-Upload, which requires jQuery UI 1.9 at least -->
<!-- <script type="text/javascript" src="components/jQuery-File-Upload/js/vendor/jquery.ui.widget.js"></script> -->

<script type='text/javascript' src='components/jsPlumb/dist/js/jquery.jsPlumb-1.5.4.js'></script>

<script type="text/javascript" src="components/jquery-typing/plugin/jquery.typing-0.3.2.js"></script>

<script type="text/javascript" src="components/select2/select2.js"></script>

<script type="text/javascript" src="components/x-editable/dist/bootstrap3-editable/js/bootstrap-editable.js"></script>

<script type="text/javascript" src="js/winery-common.js"></script>
<script type="text/javascript" src="js/winery-topologymodeler.js"></script>

<jsp:include page="/jsp/shared/dialogs.jsp" />

<%
  // only required for generating the CSS for each node type
  Collection<TNodeType> allNodeTypes = client.getAllTypes(TNodeType.class);
%>

<tmpl:CSSForTypes nodeTypes="<%=allNodeTypes%>" relationshipTypes="<%=relationshipTypes%>"/>

<tmpl:propertiesBasic />

<t:about />

<script>
// global variable hodling data for relationship templates
if (!winery) winery = {};

// winery.connections is a hashmap from jsPlumb id to a data structure with
// .id = winery id; // The two ids DO NOT match. Explanation is at winery-common-topologyrendering.js
// ...
winery.connections = {};

// all x-editable popups should be placed in a way to fit "perfectly" on the screen
$.fn.editable.defaults.placement = "auto";

//configuration for pnotify
require(["jquery", "pnotify"], function() {
	$.pnotify.defaults.styling = "bootstrap3";
});
</script>

<%-- Begin: Add&Edit Req/Cap --%>

<%List<QName> allTypes = client.getQNameListOfAllTypes(TRequirementType.class);%>
<tntrq:addorupdatereqorcap requirementOrCapability="requirement" shortName="Req" cssClassPrefix="requirements" headerLabel="Requirement" allTypes="<%=allTypes%>" clazz="<%=TRequirement.class%>" repositoryURL="<%=repositoryURL%>" />

<%allTypes = client.getQNameListOfAllTypes(TCapabilityType.class);%>
<tntrq:addorupdatereqorcap requirementOrCapability="capability" shortName="Cap" cssClassPrefix="capabilities" headerLabel="Capability" allTypes="<%=allTypes%>" clazz="<%=TCapability.class%>" repositoryURL="<%=repositoryURL%>" />

<%-- End: Add&Edit Req/Cap --%>

<%allTypes = client.getQNameListOfAllTypes(TPolicyType.class);%>
<pol:policydiag allPolicyTypes="<%=allTypes%>" repositoryURL="<%=repositoryURL%>" />

<script>
"use strict";

// for debugging
//$.pnotify.defaults.remove = false;

// global data structure
// .repositoryURL - the URL of the repository
// DOES NOT end with /
winery.repositoryURL = "<%=repositoryURL%>";

</script>

<script>
/**
 * Uses global variables currentlySelectedNodeTemplate and currentlySelectedDeploymentArtifactDiv
 *
 * @param atDelete (optional). Function to be called if the DA has been successfully deleted
 */
function askForDeploymentArtifactDeletion(atDelete) {
	// we have to remove it on both the node template locally and on the server
	// reason: if the user does NOT save after deletion, the repository would present him
	// the DA again. Possibly with a dangeling reference to the artifact template,
	// which might have been deleted if this DA was the last reference to it

	var daName = currentlySelectedDeploymentArtifactDiv.children("div.name").text();
	var url = "<%=topologyTemplateURL%>nodetemplates/" + encodeID(currentlySelectedNodeTemplate) + "/deploymentartifacts/" + daName;
	deleteResource("this deployment artifact", url, function() {
		currentlySelectedDeploymentArtifactDiv.remove();
		$("#DeploymentArtifactInfo").modal("hide");
		if (atDelete) {
			atDelete();
		}
	});
}

/**
 * Queries the user for deletion of the currently selected DA.
 * If the associated artifact template points to the current DA only, he is also ask if he wants to delete that template, too.
 */
function deleteDeploymentArtifact() {
	var templateURL = $("#DAArtifactTemplate").attr("href");
	// an artifact template exists
	// we have to ask the user if the wants to delete is as well
	// IF this deployment artifact is the only reference to it
	// The user has to be first asked for DA deletion and then for artifact template deletion
	// Therefore, we pass a function to be executed AFTER deletion of the deployment artifact.
	if (templateURL) {
		// check for count
		$.ajax({
			type: "GET",
			async: false,
			url: templateURL + "?referenceCount",
			dataType: "text",
			error: function(jqXHR, textStatus, errorThrown) {
				vShowAJAXError("Could not get count of artifact template usage", jqXHR, errorThrown);
			},
			success: function(resData, textStatus, jqXHR) {
				if (resData == "1") {
					var atDelete = function() {
						deleteResource("the associated artifact template", templateURL, function() {});
					};
					askForDeploymentArtifactDeletion(atDelete);
				} else {
					// more than one reference to the artifact template
					// just ask for deletion of the DA and not of the AT
					askForDeploymentArtifactDeletion();
				}
			}
		});
	} else {
		askForDeploymentArtifactDeletion();
	}
}

/**
 * The user might have updated the XML information
 * This has to be copied into the "storage" of the currently selected node template
 *
 * Uses global variable currentlySelectedDeploymentArtifactDiv
 */
function updateDeploymentArtifact() {
	require(["winery-support-common"], function(wsc) {
		var newVal = $("#DAXML").val();
		if (wsc.checkXMLValidityAndShowErrorIfInvalid(newVal)) {
			currentlySelectedDeploymentArtifactDiv.children("textarea").val(newVal);
			$("#DeploymentArtifactInfo").modal("hide");
		}
	});
}
</script>
<div class="modal fade" id="DeploymentArtifactInfo">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h4 class="modal-title">Artifact Information</h4>
			</div>
			<div class="modal-body">
				<form><fieldset>
					<div class="form-group">
						<label for="DADname" class="control-label">Name</label>
						<div id="DAname" class="form-control"></div>
					</div>

					<div class="form-group">
						<label for="DAArtifactType" class="control-label">Artifact Type</label>
						<a id="DAArtifactType" class="form-control" target="_blank"></a>
					</div>
					<div class="form-group">
						<label for="DAArtifactTemplate" class="control-label">Artifact Template</label>
						<a id="DAArtifactTemplate" class="form-control" target="_blank"></a>
					</div>
					<div class="form-group">
						<label for=DAXML" class="control-label">XML</label>
						<textarea id="DAXML" cols=50 rows=7 class="form-control"></textarea>
					</div>
{'fraction_non_alphanumeric': 0.1742694779989442, 'fraction_numerical': 0.004036890972890724, 'mean_word_length': 5.2556332556332555, 'pattern_counts': {'":': 28, '<': 393, '<?xml version=': 0, '>': 393, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1370465', 'n_tokens_mistral': 10909, 'n_tokens_neox': 10224, 'n_words': 2002}