comparison src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorAnnotations.java @ 101:7268c3ca025b

make admin ui view of all annotations scale better.
author casties
date Fri, 13 Feb 2015 18:10:11 +0100
parents cf44d9e1a4a7
children 9140017e8962
comparison
equal deleted inserted replaced
100:f9ee715ee9e9 101:7268c3ca025b
82 logger.fine("request authenticated=" + authUser); 82 logger.fine("request authenticated=" + authUser);
83 83
84 if (id == null) { 84 if (id == null) {
85 // no id -- send all annotations 85 // no id -- send all annotations
86 Form form = getRequest().getResourceRef().getQueryAsForm(); 86 Form form = getRequest().getResourceRef().getQueryAsForm();
87 int limit = getInt(form.getFirstValue("limit")); 87 int limit = getInt(form.getFirstValue("limit", "1000"));
88 int offset = getInt(form.getFirstValue("offset")); 88 int offset = getInt(form.getFirstValue("offset", "0"));
89 String sortBy = form.getFirstValue("sortBy"); 89 String sortBy = form.getFirstValue("sortBy");
90 return getAllAnnotations(authUser, limit, offset, sortBy); 90 return getAllAnnotations(authUser, limit, offset, sortBy);
91 } 91 }
92 92
93 // send annotation with id 93 // send annotation with id
110 private Representation getAllAnnotations(Person authUser, int limit, int offset, String sortBy) { 110 private Representation getAllAnnotations(Person authUser, int limit, int offset, String sortBy) {
111 AnnotationStore store = getAnnotationStore(); 111 AnnotationStore store = getAnnotationStore();
112 ArrayList<JSONObject> results = new ArrayList<JSONObject>(); 112 ArrayList<JSONObject> results = new ArrayList<JSONObject>();
113 113
114 // read all annotations 114 // read all annotations
115 List<Annotation> annotations = store.getAnnotations(null, null); 115 List<Annotation> annotations = store.getAnnotations(null, null, 0, 0);
116 for (Annotation annotation : annotations) { 116 for (Annotation annotation : annotations) {
117 // check permission 117 // check permission
118 if (!annotation.isActionAllowed("read", authUser, store)) 118 if (!annotation.isActionAllowed("read", authUser, store))
119 continue; 119 continue;
120 // add annotation to list 120 // add annotation to list
128 } 128 }
129 129
130 // put in JSON list 130 // put in JSON list
131 JSONArray rows = new JSONArray(); 131 JSONArray rows = new JSONArray();
132 int cnt = 0; 132 int cnt = 0;
133 int max = limit + offset;
133 for (JSONObject result : results) { 134 for (JSONObject result : results) {
134 cnt += 1; 135 cnt += 1;
135 if (offset > 0 && cnt < offset) 136 if (cnt < offset) continue;
136 continue;
137 rows.put(result); 137 rows.put(result);
138 if (limit > 0 && cnt >= limit) 138 if (limit > 0 && cnt >= max) break;
139 break;
140 } 139 }
141 140
142 // assemble result object 141 // assemble result object
143 JSONObject result = new JSONObject(); 142 JSONObject result = new JSONObject();
144 try { 143 try {