Merge "Fix build errors in autorelease full clean build"
[vfc/nfvo/wfengine.git] / winery / org.eclipse.winery.repository / src / main / java / org / eclipse / winery / repository / resources / entitytemplates / PropertiesResource.java
1 /*******************************************************************************
2  * Copyright (c) 2012-2013 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
8  *
9  * Contributors:
10  *     Oliver Kopp - initial API and implementation
11  *******************************************************************************/
12 package org.eclipse.winery.repository.resources.entitytemplates;
13
14 import javax.ws.rs.Consumes;
15 import javax.ws.rs.GET;
16 import javax.ws.rs.PUT;
17 import javax.ws.rs.Produces;
18 import javax.ws.rs.core.MediaType;
19 import javax.ws.rs.core.Response;
20
21 import org.eclipse.winery.model.tosca.TEntityTemplate;
22 import org.eclipse.winery.repository.backend.BackendUtils;
23 import org.eclipse.winery.repository.resources.AbstractComponentInstanceResource;
24
25 import com.sun.jersey.api.view.Viewable;
26
27 public class PropertiesResource {
28         
29         private AbstractComponentInstanceResource res;
30         private TEntityTemplate template;
31         
32         
33         /**
34          * @param template the template to store the definitions at
35          * @param res the resource to save after modifications
36          */
37         public PropertiesResource(TEntityTemplate template, AbstractComponentInstanceResource res) {
38                 this.template = template;
39                 this.res = res;
40         }
41         
42         /**
43          * Currently, properties can only be updated as a whole XML fragment
44          * 
45          * Getting/setting a fragment of properties is not possible yet
46          */
47         @PUT
48         @Consumes({MediaType.APPLICATION_XML, MediaType.TEXT_XML, MediaType.APPLICATION_JSON})
49         public Response setProperties(TEntityTemplate.Properties properties) {
50                 this.getTemplate().setProperties(properties);
51                 return BackendUtils.persist(this.res);
52         }
53         
54         @GET
55         @Produces(MediaType.TEXT_HTML)
56         public Viewable getHTML() {
57                 return new Viewable("/jsp/entitytemplates/properties.jsp", this);
58         }
59         
60         /** data for the JSP **/
61         
62         public TEntityTemplate getTemplate() {
63                 return this.template;
64         }
65         
66 }