Changeset 63:9f8c9611848a 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
r32 r63 4 4 package de.mpiwg.itgroup.annotations.restlet; 5 5 6 import java.util.ArrayList; 6 7 import java.util.List; 7 8 … … 18 19 import de.mpiwg.itgroup.annotations.Person; 19 20 import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore; 21 import de.mpiwg.itgroup.annotations.restlet.utils.JSONObjectComparator; 20 22 21 23 /** … … 34 36 /** 35 37 * result for JSON content-type. optional search parameters: uri, user, limit, 36 * offset .38 * offset, sortBy. 37 39 * 38 40 * @param entity … … 50 52 String uri = form.getFirstValue("uri"); 51 53 String user = form.getFirstValue("user"); 52 String limit = form.getFirstValue("limit"); 53 String offset = form.getFirstValue("offset"); 54 int limit = getInt(form.getFirstValue("limit")); 55 int offset = getInt(form.getFirstValue("offset")); 56 String sortBy = form.getFirstValue("sortBy"); 54 57 55 JSONArray results = new JSONArray();56 58 // do search 59 ArrayList<JSONObject> results = new ArrayList<JSONObject>(); 57 60 logger.debug(String.format("searching for uri=%s user=%s", uri, user)); 58 61 AnnotationStore store = getAnnotationStore(); 59 List<Annotation> annots = store.searchAnnotationByUriUser(uri, user , limit, offset);62 List<Annotation> annots = store.searchAnnotationByUriUser(uri, user); 60 63 for (Annotation annot : annots) { 61 64 // check permission … … 63 66 JSONObject jo = createAnnotatorJson(annot, (authUser == null)); 64 67 if (jo != null) { 65 results. put(jo);68 results.add(jo); 66 69 } else { 67 70 setStatus(Status.SERVER_ERROR_INTERNAL, "JSON Error"); … … 69 72 } 70 73 } 74 75 // sort if necessary 76 if (sortBy != null) { 77 JSONObjectComparator.sortAnnotations(results, sortBy); 78 } 79 80 // put in JSON list 81 JSONArray rows = new JSONArray(); 82 int cnt = 0; 83 for (JSONObject result : results) { 84 cnt += 1; 85 if (offset > 0 && cnt < offset) continue; 86 rows.put(result); 87 if (limit > 0 && cnt >= limit) break; 88 } 89 71 90 // assemble result object 72 91 JSONObject result = new JSONObject(); 73 92 try { 74 result.put("rows", r esults);75 result.put("total", r esults.length());93 result.put("rows", rows); 94 result.put("total", rows.length()); 76 95 } catch (JSONException e) { 77 96 setStatus(Status.SERVER_ERROR_INTERNAL, "JSON Error");
Note: See TracChangeset
for help on using the changeset viewer.