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

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

removing wiring errors

File size: 3.6 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.BackendConstants;
21import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier;
22import eu.dasish.annotation.backend.identifiers.UserIdentifier;
23import eu.dasish.annotation.schema.Annotation;
24import eu.dasish.annotation.schema.ObjectFactory;
25import java.sql.SQLException;
26import javax.servlet.http.HttpServletRequest;
27import javax.ws.rs.Consumes;
28import javax.ws.rs.DELETE;
29import javax.ws.rs.GET;
30import javax.ws.rs.POST;
31import javax.ws.rs.Path;
32import javax.ws.rs.PathParam;
33import javax.ws.rs.Produces;
34import javax.ws.rs.core.Context;
35import javax.ws.rs.core.MediaType;
36import javax.xml.bind.JAXBElement;
37import org.springframework.stereotype.Component;
38
39/**
40 *
41 * @author olhsha
42 */
43@Component
44@Path("/annotations")
45public class AnnotationResource {
46
47    private DaoDispatcher requestor;
48    @Context
49    private HttpServletRequest httpServletRequest;
50
51    public void setHttpRequest(HttpServletRequest request) {
52        this.httpServletRequest = request;
53    }
54
55    public AnnotationResource() {
56    }
57
58    @GET
59    @Produces(MediaType.TEXT_XML)
60    @Path("{annotationid: " + BackendConstants.regExpIdentifier + "}")
61    public JAXBElement<Annotation> getAnnotation(@PathParam("annotationid") String annotationIdentifier) throws SQLException {
62        final Number annotationID = requestor.getAnnotationInternalIdentifier(new AnnotationIdentifier(annotationIdentifier));
63        final Annotation annotation = requestor.getAnnotation(annotationID);
64        return new ObjectFactory().createAnnotation(annotation);
65    }
66
67    ///////////////////////////////////////////////////////
68    // TODO: return envelope: deleted or not deleted
69    @DELETE
70    @Path("{annotationid: " + BackendConstants.regExpIdentifier + "}")
71    public String deleteAnnotation(@PathParam("annotationid") String annotationIdentifier) throws SQLException {
72        final Number annotationID = requestor.getAnnotationInternalIdentifier(new AnnotationIdentifier(annotationIdentifier));
73        int[] resultDelete = requestor.deleteAnnotationWithSourcesAndPermissions(annotationID);
74        String result = Integer.toString(resultDelete[0]);
75        return result;
76    }
77
78    ///////////////////////////////////////////////////////
79    // TODO: should be returning the envelope!!!
80    @POST
81    @Consumes(MediaType.APPLICATION_XML)
82    @Produces(MediaType.APPLICATION_XML)
83    @Path("")
84    public JAXBElement<Annotation> createAnnotation(Annotation annotation) throws SQLException {
85        String remoteUser = httpServletRequest.getRemoteUser();
86        Number userID = null;
87        if (remoteUser != null) {
88            userID = requestor.getUserInternalIdentifier(new UserIdentifier(remoteUser));
89        }
90        Annotation newAnnotation =  requestor.addAnnotationWithTargetSources(annotation, userID);
91        return (new ObjectFactory().createAnnotation(newAnnotation));
92    }
93}
Note: See TracBrowser for help on using the repository browser.