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

Last change on this file since 3722 was 3722, checked in by olhsha, 11 years ago

adding schemaLocation property via customising marshaller. Works, however the value of the schema location is not picked up from context.xml

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