Mercurial > hg > AnnotationManagerN4J
comparison src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorSearch.java @ 15:58357a4b86de
ASSIGNED - # 249: Annotations shared in groups
https://it-dev.mpiwg-berlin.mpg.de/tracs/mpdl-project-software/ticket/249
author | casties |
---|---|
date | Tue, 28 Aug 2012 20:23:12 +0200 |
parents | 629e15b345aa |
children | 0731c4549065 |
comparison
equal
deleted
inserted
replaced
14:629e15b345aa | 15:58357a4b86de |
---|---|
13 import org.restlet.ext.json.JsonRepresentation; | 13 import org.restlet.ext.json.JsonRepresentation; |
14 import org.restlet.representation.Representation; | 14 import org.restlet.representation.Representation; |
15 import org.restlet.resource.Get; | 15 import org.restlet.resource.Get; |
16 | 16 |
17 import de.mpiwg.itgroup.annotations.Annotation; | 17 import de.mpiwg.itgroup.annotations.Annotation; |
18 import de.mpiwg.itgroup.annotations.Person; | |
19 import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore; | |
18 | 20 |
19 /** | 21 /** |
20 * Implements the "search" uri of the Annotator API. see | 22 * Implements the "search" uri of the Annotator API. see |
21 * <https://github.com/okfn/annotator/wiki/Storage> | 23 * <https://github.com/okfn/annotator/wiki/Storage> |
22 * | 24 * |
39 @Get("json") | 41 @Get("json") |
40 public Representation doGetJSON(Representation entity) { | 42 public Representation doGetJSON(Representation entity) { |
41 logger.debug("AnnotatorSearch doGetJSON!"); | 43 logger.debug("AnnotatorSearch doGetJSON!"); |
42 setCorsHeaders(); | 44 setCorsHeaders(); |
43 // do authentication | 45 // do authentication |
44 String authUser = this.checkAuthToken(entity); | 46 Person authUser = Person.createPersonWithId(this.checkAuthToken(entity)); |
45 logger.debug("request authenticated=" + authUser); | 47 logger.debug("request authenticated=" + authUser); |
46 | 48 |
47 Form form = getRequest().getResourceRef().getQueryAsForm(); | 49 Form form = getRequest().getResourceRef().getQueryAsForm(); |
48 String uri = form.getFirstValue("uri"); | 50 String uri = form.getFirstValue("uri"); |
49 String user = form.getFirstValue("user"); | 51 String user = form.getFirstValue("user"); |
51 String offset = form.getFirstValue("offset"); | 53 String offset = form.getFirstValue("offset"); |
52 | 54 |
53 JSONArray results = new JSONArray(); | 55 JSONArray results = new JSONArray(); |
54 // do search | 56 // do search |
55 logger.debug(String.format("searching for uri=%s user=%s", uri, user)); | 57 logger.debug(String.format("searching for uri=%s user=%s", uri, user)); |
56 List<Annotation> annots = getAnnotationStore().searchByUriUser(uri, user, limit, offset); | 58 AnnotationStore store = getAnnotationStore(); |
59 List<Annotation> annots = store.searchByUriUser(uri, user, limit, offset); | |
57 for (Annotation annot : annots) { | 60 for (Annotation annot : annots) { |
58 // check permission | 61 // check permission |
59 if (!annot.isActionAllowed("read", authUser)) continue; | 62 if (!annot.isActionAllowed("read", authUser, store)) continue; |
60 JSONObject jo = createAnnotatorJson(annot, (authUser == null)); | 63 JSONObject jo = createAnnotatorJson(annot, (authUser == null)); |
61 if (jo != null) { | 64 if (jo != null) { |
62 results.put(jo); | 65 results.put(jo); |
63 } else { | 66 } else { |
64 setStatus(Status.SERVER_ERROR_INTERNAL, "JSON Error"); | 67 setStatus(Status.SERVER_ERROR_INTERNAL, "JSON Error"); |