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.entitytypes.nodetypes.reqandcapdefs;
14 import java.util.List;
16 import javax.ws.rs.FormParam;
17 import javax.ws.rs.PUT;
18 import javax.ws.rs.Path;
19 import javax.ws.rs.core.Response;
20 import javax.xml.namespace.QName;
22 import org.eclipse.winery.model.tosca.TConstraint;
23 import org.eclipse.winery.model.tosca.TRequirementDefinition;
24 import org.eclipse.winery.model.tosca.TRequirementDefinition.Constraints;
25 import org.eclipse.winery.repository.backend.BackendUtils;
26 import org.eclipse.winery.repository.resources.AbstractComponentInstanceResource;
27 import org.eclipse.winery.repository.resources._support.IPersistable;
28 import org.eclipse.winery.repository.resources._support.collections.IIdDetermination;
29 import org.eclipse.winery.repository.resources.entitytypes.nodetypes.NodeTypeResource;
31 public final class RequirementDefinitionResource extends AbstractReqOrCapDefResource<TRequirementDefinition> {
33 private TRequirementDefinition reqDef;
37 * Constructor has to follow the pattern of EnetityTResource as the
38 * constructor is invoked by reflection in EntityWithIdcollectionResource
40 * @param res the resource this req def is nested in. Has to be of Type
41 * "NodeTypeResource". Due to the implementation of
42 * org.eclipse.winery .repository.resources._support.collections.
43 * withid.EntityWithIdCollectionResource
44 * .getEntityResourceInstance(EntityT, int), we have to use
45 * "AbstractComponentInstanceResource" as type
47 public RequirementDefinitionResource(IIdDetermination<TRequirementDefinition> idDetermination, TRequirementDefinition reqDef, int idx, List<TRequirementDefinition> list, AbstractComponentInstanceResource res) {
48 super(idDetermination, reqDef, idx, list, (NodeTypeResource) res, RequirementDefinitionResource.getConstraints(reqDef));
53 * Quick fix to avoid internal server error when opening
54 * RequirementDefinitions Tab
56 public RequirementDefinitionResource(IIdDetermination<TRequirementDefinition> idDetermination, TRequirementDefinition reqDef, int idx, List<TRequirementDefinition> list, IPersistable res) {
57 this(idDetermination, reqDef, idx, list, (AbstractComponentInstanceResource) res);
61 * Fetch the list of constraints from the given definition. If the list does
62 * not exist, the list is created an stored in the given def
64 public static List<TConstraint> getConstraints(TRequirementDefinition def) {
65 Constraints constraints = def.getConstraints();
66 if (constraints == null) {
67 constraints = new Constraints();
68 def.setConstraints(constraints);
70 return constraints.getConstraint();
73 public QName getType() {
74 return this.reqDef.getRequirementType();
79 public Response setType(@FormParam(value = "type") String value) {
80 QName qname = QName.valueOf(value);
81 this.reqDef.setRequirementType(qname);
82 return BackendUtils.persist(this.parent);
86 public String getId(TRequirementDefinition e) {