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.documentation;
14 import java.util.List;
16 import javax.ws.rs.Consumes;
17 import javax.ws.rs.POST;
18 import javax.ws.rs.core.MediaType;
19 import javax.ws.rs.core.Response;
20 import javax.ws.rs.core.Response.Status;
22 import org.eclipse.winery.model.tosca.TDocumentation;
23 import org.eclipse.winery.repository.resources._support.IPersistable;
24 import org.eclipse.winery.repository.resources._support.collections.CollectionsHelper;
25 import org.eclipse.winery.repository.resources._support.collections.withoutid.EntityWithoutIdCollectionResource;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
29 import com.sun.jersey.api.view.Viewable;
31 public class DocumentationsResource extends EntityWithoutIdCollectionResource<DocumentationResource, TDocumentation> {
33 private static final Logger logger = LoggerFactory.getLogger(DocumentationResource.class);
36 public DocumentationsResource(IPersistable res, List<TDocumentation> documentations) {
37 super(DocumentationResource.class, TDocumentation.class, documentations, res);
41 public Viewable getHTML() {
42 return new Viewable("/jsp/documentation.jsp", this.list);
46 * Adds a new documentation
49 @Consumes(MediaType.TEXT_HTML)
50 public Response addNewElement(String documentation) {
51 if (documentation == null) {
52 return Response.status(Status.BAD_REQUEST).entity("No content provided").build();
54 TDocumentation doc = new TDocumentation();
55 doc.getContent().add(documentation);
56 // TODO: check for duplicates as in instance states
58 return CollectionsHelper.persist(this.res, this, doc);