1
2
3
4 package eu.scape_project.watch.rest.resource;
5
6 import java.util.List;
7
8 import javax.ws.rs.GET;
9 import javax.ws.rs.Path;
10 import javax.ws.rs.PathParam;
11 import javax.ws.rs.QueryParam;
12 import javax.ws.rs.core.GenericEntity;
13 import javax.ws.rs.core.Response;
14
15 import com.wordnik.swagger.core.ApiOperation;
16 import com.wordnik.swagger.core.ApiParam;
17 import com.wordnik.swagger.core.JavaHelp;
18
19 import eu.scape_project.watch.dao.RequestDAO;
20 import eu.scape_project.watch.domain.Entity;
21 import eu.scape_project.watch.domain.EntityType;
22 import eu.scape_project.watch.domain.Property;
23 import eu.scape_project.watch.domain.PropertyValue;
24 import eu.scape_project.watch.domain.RequestTarget;
25
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28
29 import thewebsemantic.binding.RdfBean;
30
31
32
33
34
35
36
37
38 public class RequestResource extends JavaHelp {
39
40
41
42
43 private static final Logger LOG = LoggerFactory.getLogger(RequestResource.class);
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59 @SuppressWarnings("unchecked")
60 @GET
61 @Path("/{target}")
62 @ApiOperation(value = "Make a request", notes = "")
63 public Response getRequest(
64 @ApiParam(value = "Request target", required = true, allowableValues = "entity, entity_type, property, property_value") @PathParam("target") final String target,
65 @ApiParam(value = "Request query", required = true) @QueryParam("query") final String query,
66 @ApiParam(value = "Start index", required = true) @QueryParam("start") final int start,
67 @ApiParam(value = "Max number of items", required = true) @QueryParam("max") final int max) {
68
69 LOG.debug("Making request '{}', target={}, start={}, max={}", new Object[] {query, target, start, max});
70
71 final RequestTarget requestTarget = RequestTarget.valueOf(target.toUpperCase());
72
73 final List<? extends RdfBean<?>> list = RequestDAO.getInstance().query(requestTarget, query, start, max);
74
75 Response ret;
76 switch (requestTarget) {
77 case ENTITY_TYPE:
78 ret = Response.ok().entity(new GenericEntity<List<EntityType>>((List<EntityType>) list) {
79 }).build();
80 break;
81 case PROPERTY:
82 ret = Response.ok().entity(new GenericEntity<List<Property>>((List<Property>) list) {
83 }).build();
84 break;
85 case ENTITY:
86 ret = Response.ok().entity(new GenericEntity<List<Entity>>((List<Entity>) list) {
87 }).build();
88 break;
89 case PROPERTY_VALUE:
90 ret = Response.ok().entity(new GenericEntity<List<PropertyValue>>((List<PropertyValue>) list) {
91 }).build();
92 break;
93 default:
94 LOG.error("Request target not supported {}", requestTarget);
95 ret = null;
96 break;
97 }
98
99 return ret;
100 }
101 }