Changeset 14:629e15b345aa in AnnotationManagerN4J for src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorSearch.java
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorSearch.java
r4 r14 16 16 17 17 import de.mpiwg.itgroup.annotations.Annotation; 18 import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore;19 18 20 19 /** … … 32 31 33 32 /** 34 * result for JSON content-type. optional search parameters: uri user limit35 * offset 33 * result for JSON content-type. optional search parameters: uri, user, limit, 34 * offset. 36 35 * 37 36 * @param entity … … 42 41 logger.debug("AnnotatorSearch doGetJSON!"); 43 42 setCorsHeaders(); 44 // TODO: what to do with authentication?45 boolean authenticated = isAuthenticated(entity);46 logger.debug("request authenticated=" + auth enticated);43 // do authentication 44 String authUser = this.checkAuthToken(entity); 45 logger.debug("request authenticated=" + authUser); 47 46 48 47 Form form = getRequest().getResourceRef().getQueryAsForm(); 49 48 String uri = form.getFirstValue("uri"); 50 49 String user = form.getFirstValue("user"); 51 52 50 String limit = form.getFirstValue("limit"); 53 51 String offset = form.getFirstValue("offset"); 54 52 55 AnnotationStore searcher = getAnnotationStore(); 56 57 JSONArray ja; 58 59 List<Annotation> annots = searcher.searchByUriUser(uri, user, limit, offset); 60 61 ja = new JSONArray(); 53 JSONArray results = new JSONArray(); 54 // do search 55 logger.debug(String.format("searching for uri=%s user=%s", uri, user)); 56 List<Annotation> annots = getAnnotationStore().searchByUriUser(uri, user, limit, offset); 62 57 for (Annotation annot : annots) { 63 JSONObject jo = createAnnotatorJson(annot); 58 // check permission 59 if (!annot.isActionAllowed("read", authUser)) continue; 60 JSONObject jo = createAnnotatorJson(annot, (authUser == null)); 64 61 if (jo != null) { 65 ja.put(createAnnotatorJson(annot));62 results.put(jo); 66 63 } else { 67 64 setStatus(Status.SERVER_ERROR_INTERNAL, "JSON Error"); … … 69 66 } 70 67 } 71 68 // assemble result object 72 69 JSONObject result = new JSONObject(); 73 70 try { 74 result.put("rows", ja);75 result.put("total", ja.length());71 result.put("rows", results); 72 result.put("total", results.length()); 76 73 } catch (JSONException e) { 77 e.printStackTrace();78 74 setStatus(Status.SERVER_ERROR_INTERNAL, "JSON Error"); 79 75 return null;
Note: See TracChangeset
for help on using the changeset viewer.