b9eb3459ed3a65a6ccc495ead98ceebc697f0799
[vfc/nfvo/wfengine.git] /
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;
13
14 import java.util.List;
15
16 import javax.ws.rs.Consumes;
17 import javax.ws.rs.GET;
18 import javax.ws.rs.PUT;
19 import javax.ws.rs.Path;
20 import javax.ws.rs.Produces;
21 import javax.ws.rs.core.MediaType;
22 import javax.ws.rs.core.Response;
23
24 import org.eclipse.winery.model.tosca.TConstraint;
25 import org.eclipse.winery.repository.backend.BackendUtils;
26 import org.eclipse.winery.repository.resources._support.collections.withoutid.EntityWithoutIdResource;
27 import org.eclipse.winery.repository.resources.entitytypes.nodetypes.NodeTypeResource;
28
29 public class ConstraintResource extends EntityWithoutIdResource<TConstraint> {
30         
31         /**
32          * 
33          * @param constraint the current constraint value
34          * @param list the list this constraint belongs to
35          * @param res the node type resource this constraint belongs to. Required
36          *            for saving
37          */
38         public ConstraintResource(TConstraint constraint, int idx, List<TConstraint> list, NodeTypeResource res) {
39                 super(constraint, idx, list, res);
40         }
41         
42         /**
43          * Required for collectionResource
44          * 
45          * @throws ClassCastException of !(res instanceof NodeTypeResource)
46          */
47         public ConstraintResource(TConstraint constraint, int idx, List<TConstraint> list, AbstractComponentInstanceResource res) {
48                 this(constraint, idx, list, (NodeTypeResource) res);
49         }
50         
51         private TConstraint getConstraint() {
52                 return this.o;
53         }
54         
55         @GET
56         @Path("type")
57         @Produces(MediaType.TEXT_PLAIN)
58         public String getConstraintType() {
59                 return this.getConstraint().getConstraintType();
60         }
61         
62         @PUT
63         @Path("type")
64         @Consumes(MediaType.TEXT_PLAIN)
65         public Response putConstraintType(String constraintType) {
66                 this.getConstraint().setConstraintType(constraintType);
67                 return BackendUtils.persist(this.res);
68         }
69 }