Merge "Fix build errors in autorelease full clean build"
[vfc/nfvo/wfengine.git] / winery / org.eclipse.winery.repository / src / main / java / org / eclipse / winery / repository / resources / documentation / DocumentationsResource.java
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.documentation;
13
14 import java.util.List;
15
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;
21
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;
28
29 import com.sun.jersey.api.view.Viewable;
30
31 public class DocumentationsResource extends EntityWithoutIdCollectionResource<DocumentationResource, TDocumentation> {
32         
33         private static final Logger logger = LoggerFactory.getLogger(DocumentationResource.class);
34         
35         
36         public DocumentationsResource(IPersistable res, List<TDocumentation> documentations) {
37                 super(DocumentationResource.class, TDocumentation.class, documentations, res);
38         }
39         
40         @Override
41         public Viewable getHTML() {
42                 return new Viewable("/jsp/documentation.jsp", this.list);
43         }
44         
45         /**
46          * Adds a new documentation
47          */
48         @POST
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();
53                 }
54                 TDocumentation doc = new TDocumentation();
55                 doc.getContent().add(documentation);
56                 // TODO: check for duplicates as in instance states
57                 this.list.add(doc);
58                 return CollectionsHelper.persist(this.res, this, doc);
59         }
60 }