1 /*******************************************************************************
2 * Copyright (c) 2012-2014 University of Stuttgart.
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 * Oliver Kopp - initial API and implementation
11 *******************************************************************************/
12 package org.eclipse.winery.repository.resources.servicetemplates.topologytemplates;
14 import java.util.List;
17 import javax.ws.rs.FormParam;
18 import javax.ws.rs.GET;
19 import javax.ws.rs.HEAD;
20 import javax.ws.rs.PUT;
21 import javax.ws.rs.Path;
22 import javax.ws.rs.core.Response;
23 import javax.xml.namespace.QName;
25 import org.eclipse.winery.common.constants.Namespaces;
26 import org.eclipse.winery.common.ids.Namespace;
27 import org.eclipse.winery.model.tosca.TNodeTemplate;
28 import org.eclipse.winery.repository.backend.BackendUtils;
29 import org.eclipse.winery.repository.resources.INodeTemplateResourceOrNodeTypeImplementationResource;
30 import org.eclipse.winery.repository.resources._support.IPersistable;
31 import org.eclipse.winery.repository.resources._support.collections.IIdDetermination;
32 import org.eclipse.winery.repository.resources.artifacts.DeploymentArtifactsResource;
33 import org.eclipse.winery.repository.resources.entitytemplates.TEntityTemplateResource;
34 import org.eclipse.winery.repository.resources.servicetemplates.ServiceTemplateResource;
35 import org.restdoc.annotations.RestDoc;
37 public class NodeTemplateResource extends TEntityTemplateResource<TNodeTemplate> implements INodeTemplateResourceOrNodeTypeImplementationResource {
39 public NodeTemplateResource(IIdDetermination<TNodeTemplate> idDetermination, TNodeTemplate o, int idx, List<TNodeTemplate> list, IPersistable res) {
40 super(idDetermination, o, idx, list, res);
43 @Path("deploymentartifacts/")
44 public DeploymentArtifactsResource getDeploymentArtifacts() {
45 return new DeploymentArtifactsResource(this.o, this);
49 @RestDoc(methodDescription = "* The following methods are currently *not* used by the topology modeler.<br />" + "The modeler is using the repository client to interact with the repository")
51 public String getMinInstances() {
52 return Integer.toString(this.o.getMinInstances());
57 public Response setMinInstances(@FormParam(value = "minInstances") String minInstances) {
58 int min = Integer.parseInt(minInstances);
59 this.o.setMinInstances(min);
60 return BackendUtils.persist(this.res);
65 public String getMaxInstances() {
66 return this.o.getMaxInstances();
71 public Response setMaxInstances(@FormParam(value = "maxInstances") String maxInstances) {
72 // TODO: check for valid integer | "unbound"
73 this.o.setMaxInstances(maxInstances);
74 return BackendUtils.persist(this.res);
79 * The visual appearance
81 * We do not use a subresource "visualappearance" here to avoid generation of more objects
84 private final QName qnameX = new QName(Namespaces.TOSCA_WINERY_EXTENSIONS_NAMESPACE, "x");
85 private final QName qnameY = new QName(Namespaces.TOSCA_WINERY_EXTENSIONS_NAMESPACE, "y");
90 @RestDoc(methodDescription = "@return the x coordinate of the node template")
91 public String getX() {
92 Map<QName, String> otherAttributes = this.o.getOtherAttributes();
93 return otherAttributes.get(this.qnameX);
98 public Response setX(String x) {
99 this.o.getOtherAttributes().put(this.qnameX, x);
100 return BackendUtils.persist(this.res);
105 @RestDoc(methodDescription = "@return the y coordinate of the node template")
106 public String getY() {
107 Map<QName, String> otherAttributes = this.o.getOtherAttributes();
108 return otherAttributes.get(this.qnameY);
113 public Response setY(String y) {
114 this.o.getOtherAttributes().put(this.qnameY, y);
115 return BackendUtils.persist(this.res);
119 public Namespace getNamespace() {
120 // TODO Auto-generated method stub
121 throw new IllegalStateException("Not yet implemented.");
125 * Required for persistence after a change of the deployment artifact.
126 * Required by DeploymentArtifactResource to be able to persist
128 * @return the service template this node template belongs to
130 public ServiceTemplateResource getServiceTemplateResource() {
131 return (ServiceTemplateResource) this.res;
135 * required for topology modeler to check for existence of a node template
138 * @return empty response
141 public Response getHEAD() {
142 return Response.noContent().build();