1
2
3
4 package eu.scape_project.watch.rest.resource;
5
6 import java.util.Collection;
7
8 import javax.ws.rs.GET;
9 import javax.ws.rs.POST;
10 import javax.ws.rs.Path;
11 import javax.ws.rs.PathParam;
12 import javax.ws.rs.QueryParam;
13 import javax.ws.rs.core.GenericEntity;
14 import javax.ws.rs.core.Response;
15
16 import com.wordnik.swagger.core.ApiError;
17 import com.wordnik.swagger.core.ApiErrors;
18 import com.wordnik.swagger.core.ApiOperation;
19 import com.wordnik.swagger.core.ApiParam;
20 import com.wordnik.swagger.core.JavaHelp;
21
22 import eu.scape_project.watch.dao.AsyncRequestDAO;
23 import eu.scape_project.watch.domain.AsyncRequest;
24 import eu.scape_project.watch.utils.exception.NotFoundException;
25
26
27
28
29
30
31
32
33 public class AsyncRequestResource extends JavaHelp {
34
35
36
37
38
39
40
41
42
43 @GET
44 @Path("/{id}")
45 @ApiOperation(value = "Find Request by Id", notes = "")
46 @ApiErrors(value = {@ApiError(code = NotFoundException.CODE, reason = "Request not found")})
47 public Response getAsyncRequestById(
48 @ApiParam(value = "Request Id", required = true) @PathParam("id") final String requestId) {
49
50 final AsyncRequest request = AsyncRequestDAO.getInstance().findById(requestId);
51
52 if (request != null) {
53 return Response.ok().entity(request).build();
54 } else {
55 throw new NotFoundException("Request not found: " + requestId);
56 }
57 }
58
59
60
61
62
63
64
65
66 @POST
67 @Path("/")
68 @ApiOperation(value = "Create Async Request", notes = "This can only be done by a logged user (TODO)")
69 public Response createAsyncRequest(@ApiParam(value = "Async Request", required = true) final AsyncRequest request) {
70 AsyncRequestDAO.getInstance().save(request);
71 return Response.ok().entity(request).build();
72 }
73
74
75
76
77
78
79
80
81
82
83
84
85 @GET
86 @Path("/list")
87 @ApiOperation(value = "List all async requests", notes = "")
88 public Response listAsyncRequest(
89 @ApiParam(value = "Index of first item to retrieve", required = true) @QueryParam("start") final int start,
90 @ApiParam(value = "Maximum number of items to retrieve", required = true) @QueryParam("max") final int max) {
91 final Collection<AsyncRequest> list = AsyncRequestDAO.getInstance().list(start, max);
92 return Response.ok().entity(new GenericEntity<Collection<AsyncRequest>>(list) {
93 }).build();
94 }
95
96 }