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.interfaces;
14 import java.util.List;
16 import javax.ws.rs.Consumes;
17 import javax.ws.rs.FormParam;
18 import javax.ws.rs.POST;
19 import javax.ws.rs.Produces;
20 import javax.ws.rs.core.MediaType;
21 import javax.ws.rs.core.Response;
22 import javax.ws.rs.core.Response.Status;
24 import org.apache.commons.lang3.StringUtils;
25 import org.eclipse.winery.model.tosca.TOperation;
26 import org.eclipse.winery.common.Util;
27 import org.eclipse.winery.repository.backend.BackendUtils;
28 import org.eclipse.winery.repository.resources._support.IPersistable;
29 import org.eclipse.winery.repository.resources._support.collections.withid.EntityWithIdCollectionResource;
30 import org.restdoc.annotations.RestDocParam;
32 import com.sun.jersey.api.view.Viewable;
34 public class OperationsResource extends EntityWithIdCollectionResource<OperationResource, TOperation> {
36 public OperationsResource(List<TOperation> list, IPersistable res) {
37 super(OperationResource.class, TOperation.class, list, res);
41 public String getId(TOperation entity) {
42 return entity.getName();
46 public Viewable getHTML() {
47 throw new IllegalStateException("Not yet implemented.");
51 @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
52 @Produces(MediaType.TEXT_PLAIN)
53 public Response createOperation(@FormParam("name") @RestDocParam(description = "used as name and id") String operationName) {
54 if (StringUtils.isEmpty(operationName)) {
55 return Response.status(Status.BAD_REQUEST).entity("operationName not provided").build();
58 operationName = Util.URLdecode(operationName);
60 // TODO: check for duplicates as in instance states
62 TOperation operation = new TOperation();
63 operation.setName(operationName);
64 this.list.add(operation);
66 return BackendUtils.persist(this.res);