source: DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/NotebookResource.java @ 4207

Last change on this file since 4207 was 4207, checked in by olhsha, 10 years ago

adding trasnactional, refactoring and fixing bugs in updated annotations, removing try-catch from resource methods (The Greek's advice)

File size: 9.4 KB
Line 
1/*
2 * Copyright (C) 2013 DASISH
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17 */
18package eu.dasish.annotation.backend.rest;
19
20import eu.dasish.annotation.backend.dao.DBIntegrityService;
21import java.io.IOException;
22import java.sql.SQLException;
23import javax.servlet.http.HttpServletRequest;
24import javax.ws.rs.Path;
25import javax.ws.rs.core.Context;
26import javax.ws.rs.core.UriInfo;
27import javax.ws.rs.ext.Providers;
28import javax.xml.parsers.ParserConfigurationException;
29import org.springframework.beans.factory.annotation.Autowired;
30import org.springframework.stereotype.Component;
31import org.springframework.transaction.annotation.Transactional;
32
33/**
34 * Created on : Jun 11, 2013, 5:10:55 PM
35 *
36 * @author Peter Withers <peter.withers@mpi.nl>
37 */
38@Component
39@Path("/notebooks")
40@Transactional(rollbackFor={Exception.class, SQLException.class, IOException.class, ParserConfigurationException.class})
41public class NotebookResource {
42
43    @Autowired
44    private DBIntegrityService dbIntegrityService;
45    @Context
46    private HttpServletRequest httpServletRequest;
47   
48    @Context
49    private UriInfo uriInfo;
50   
51    @Context
52    protected Providers providers;
53
54//    @GET
55//    @Produces(MediaType.TEXT_XML)
56//    @Path("")
57//    // Returns notebook-infos for the notebooks accessible to the current user.
58//    public JAXBElement<NotebookInfoList> getNotebookInfo(@Context HttpServletRequest httpServletRequest) {
59//        final NotebookInfoList notebookInfoList = new NotebookInfoList();
60//        String remoteUser = httpServletRequest.getRemoteUser();
61//        UUID remoteUserUUID = (remoteUser != null) ? UUID.fromString(remoteUser) : null;
62//        notebookInfoList.getNotebook().addAll(notebookDao.getNotebookInfos(remoteUserUUID));
63//        return new ObjectFactory().createNotebookInfoList(notebookInfoList);
64//    }
65//
66//    @GET
67//    @Produces(MediaType.TEXT_XML)
68//    @Path("test")
69//    // This is not in the standards definition and is only used for testing
70//    public JAXBElement<NotebookInfoList> getNotebookInfo(@QueryParam("userid") String userId) {
71//        final NotebookInfoList notebookInfos = new NotebookInfoList();
72//        notebookInfos.getNotebook().addAll(notebookDao.getNotebookInfos(UUID.fromString(userId)));
73//        return new ObjectFactory().createNotebookInfoList(notebookInfos);
74//    }
75//
76//    @GET
77//    @Produces(MediaType.TEXT_XML)
78//    @Path("owned")
79//    // Returns the list of all notebooks owned by the current logged user.
80//    public List<Notebook> getUsersNotebooks(@Context HttpServletRequest httpServletRequest) {
81//        // todo: sort out how the user id is obtained and how it is stored it the db
82//        String remoteUser = httpServletRequest.getRemoteUser();
83//        UUID remoteUserUUID = (remoteUser != null) ? UUID.fromString(remoteUser) : null;
84//        return notebookDao.getUsersNotebooks(remoteUserUUID);
85//    }
86//
87//    @GET
88//    @Produces("text/html")
89//    @Path("{notebookid: [a-zA-Z0-9_]*}/readers")
90//    // Returns the list of _uid_ who allowed to read the annotations from notebook.
91//    public String getReaders(@PathParam("notebookid") String notebookId) {
92//        return "readers for " + notebookId;
93//    }
94//
95//    @GET
96//    @Produces("text/html")
97//    @Path("{notebookid: [a-zA-Z0-9_]*}/writers")
98//    // Returns the list of _uid_ that can add annotations to the notebook.
99//    public String getWriters(@PathParam("notebookid") String notebookId) {
100//        return "writers for " + notebookId;
101//    }
102//
103//    @GET
104//    @Produces(MediaType.TEXT_XML)
105//    @Path("{notebookid: " + BackendConstants.regExpIdentifier + "}/metadata")
106//    // Get all metadata about a specified notebook _nid_, including the information if it is private or not.
107//    public JAXBElement<NotebookInfo> getMetadata(@PathParam("notebookid") String notebookId) {
108//        NotebookInfo result = notebookDao.getNotebookInfo(notebookDao.getInternalID(UUID.fromString(notebookId)));
109//        // TODO change the name of the create method to createNotebookInfo!
110//        return new ObjectFactory().createNotebookInfo(result);
111//
112//    }
113//
114//    @GET
115//    @Path("{notebookid: " + BackendConstants.regExpIdentifier + "}")
116//    /*
117//     * Get the list of all annotations _aid_-s contained within a Notebook with related metadata.
118//     * Parameters: _nid_,
119//     * optional maximumAnnotations specifies the maximum number of annotations to retrieve (default -1, all annotations),
120//     * optional startAnnotation specifies the starting point from which the annotations will be retrieved (default: -1, start from the first annotation),
121//     * optional orderby, specifies the RDF property used to order the annotations (default: dc:created ),
122//     * optional orderingMode specifies if the results should be sorted using a descending order desc=1 or an ascending order desc=0 (default: 0 ).
123//     * */
124//    @Produces(MediaType.TEXT_XML)
125//    public List<JAXBElement<UUID>> getAllAnnotations(@PathParam("notebookid") String notebookId, @DefaultValue("-1") @QueryParam(value = "maximumAnnotations") final int maximumAnnotations,
126//            @DefaultValue("-1") @QueryParam(value = "startAnnotation") final int startAnnotation,
127//            @DefaultValue("dc:created") @QueryParam(value = "orderby") final String orderby,
128//            @DefaultValue("0") @QueryParam(value = "orderingMode") final int orderingMode) {
129//        UUID notebookUUID = UUID.fromString(notebookId);
130//        List<UUID> annotationIDs = notebookDao.getAnnotationExternalIDs(notebookUUID);
131//        List<JAXBElement<UUID>> result = new ArrayList<JAXBElement<UUID>>();
132//        for (UUID annotationID : annotationIDs) {
133//            final JAXBElement<UUID> jaxbElement = new JAXBElement<UUID>(new QName("http://www.dasish.eu/ns/addit", "uuid"), UUID.class, null, annotationID);
134//            result.add(jaxbElement);
135//        }
136//        return result;
137//        // TODO implement optional parameters!!
138//    }
139//
140//    @PUT
141//    @Path("{notebookid: [a-zA-Z0-9_]*}")
142//    @Consumes(MediaType.APPLICATION_XML)
143//    /*
144//     Modify metadata of _nid_. The new notebook?s name must be sent in request?s body.
145//     */
146//    public String modifyNotebook(@PathParam("notebookid") String notebookId, Notebook notebook) {
147//        return "modifyNotebook " + notebookId + notebook.getTitle();
148//    }
149//
150//    @PUT
151//    @Path("{notebookid: [a-zA-Z0-9_]*}/{annotationid: [a-zA-Z0-9_]*}")
152//    /*
153//     Adds an annotation _aid_ to the list of annotations of _nid_.
154//     */
155//    public String addAnnotation(@PathParam("notebookid") String notebookId, @PathParam("annotationid") String annotationId) {
156//        return "addAnnotation " + notebookId + " : " + annotationId;
157//    }
158//
159////    @PUT
160////    @Path("{notebookid: [a-zA-Z0-9_]*}/setPrivate={isPrivate: true|false}")
161////    /*
162////     Sets the specified Notebook as private or not private.
163////     */
164////    public String setPrivate(@PathParam("notebookid") String notebookId, @PathParam("isPrivate") String isPrivate) {
165////        return "modifyNotebook " + notebookId + " : " + isPrivate;
166////    }
167//    @POST
168//    @Path("")
169//    /*
170//     * Creates a new notebook.
171//     * This API returns the _nid_ of the created Notebook in response?s payload and the full URL of the notebook adding a Location header into the HTTP response.
172//     * The name of the new notebook can be specified sending a specific payload.
173//     */
174//    public String createNotebook(@Context HttpServletRequest httpServletRequest) throws URISyntaxException {
175//        String remoteUser = httpServletRequest.getRemoteUser();
176//        UUID remoteUserUUID = (remoteUser != null) ? UUID.fromString(remoteUser) : null;
177//        UUID notebookId = notebookDao.addNotebook(remoteUserUUID, null);
178//        final URI serverUri = new URI(httpServletRequest.getRequestURL().toString());
179//        String fullUrlString = "/api/notebooks/" + notebookId.toString();
180//        return serverUri.resolve(fullUrlString).toString();
181//    }
182//
183//    @POST
184//    @Path("{notebookid: [a-zA-Z0-9_]*}")
185//    /*
186//     * Creates a new annotation in _nid_.
187//     * The content of an annotation is given in the request body. In fact this is a short cut of two actions:
188//     */
189//    public String createAnnotation() {
190//        String notebookId = "_nid_";
191//        String fullUrlString = "api/notebooks/_nid_";
192//        return "annotation " + notebookId + " : " + fullUrlString;
193//    }
194//
195//    @DELETE
196//    @Path("{notebookid: [a-zA-Z0-9_-]*}")
197//    /*
198//     Delete _nid_. Annotations stay, they just lose connection to _nid_.<br>
199//     */
200//    public String deleteNotebook(@PathParam("notebookid") UUID notebookId) {
201//        // todo: sort out how the id string passsed in here is mapped eg db column for _nid_
202//        return Integer.toString(notebookDao.deleteNotebook(notebookId));
203//    }
204}
Note: See TracBrowser for help on using the repository browser.