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
10 * Oliver Kopp - initial API and implementation
11 *******************************************************************************/
12 package org.eclipse.winery.repository.resources;
14 import java.util.List;
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;
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;
29 public class ConstraintResource extends EntityWithoutIdResource<TConstraint> {
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
38 public ConstraintResource(TConstraint constraint, int idx, List<TConstraint> list, NodeTypeResource res) {
39 super(constraint, idx, list, res);
43 * Required for collectionResource
45 * @throws ClassCastException of !(res instanceof NodeTypeResource)
47 public ConstraintResource(TConstraint constraint, int idx, List<TConstraint> list, AbstractComponentInstanceResource res) {
48 this(constraint, idx, list, (NodeTypeResource) res);
51 private TConstraint getConstraint() {
57 @Produces(MediaType.TEXT_PLAIN)
58 public String getConstraintType() {
59 return this.getConstraint().getConstraintType();
64 @Consumes(MediaType.TEXT_PLAIN)
65 public Response putConstraintType(String constraintType) {
66 this.getConstraint().setConstraintType(constraintType);
67 return BackendUtils.persist(this.res);