Changeset 101:7268c3ca025b in AnnotationManagerN4J for src/main/java/de/mpiwg/itgroup/annotations/restlet
- Timestamp:
- Feb 13, 2015, 5:10:11 PM (10 years ago)
- Branch:
- default
- Location:
- src/main/java/de/mpiwg/itgroup/annotations/restlet
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorAnnotations.java
r91 r101 85 85 // no id -- send all annotations 86 86 Form form = getRequest().getResourceRef().getQueryAsForm(); 87 int limit = getInt(form.getFirstValue("limit" ));88 int offset = getInt(form.getFirstValue("offset" ));87 int limit = getInt(form.getFirstValue("limit", "1000")); 88 int offset = getInt(form.getFirstValue("offset", "0")); 89 89 String sortBy = form.getFirstValue("sortBy"); 90 90 return getAllAnnotations(authUser, limit, offset, sortBy); … … 113 113 114 114 // read all annotations 115 List<Annotation> annotations = store.getAnnotations(null, null );115 List<Annotation> annotations = store.getAnnotations(null, null, 0, 0); 116 116 for (Annotation annotation : annotations) { 117 117 // check permission … … 131 131 JSONArray rows = new JSONArray(); 132 132 int cnt = 0; 133 int max = limit + offset; 133 134 for (JSONObject result : results) { 134 135 cnt += 1; 135 if (offset > 0 && cnt < offset) 136 continue; 136 if (cnt < offset) continue; 137 137 rows.put(result); 138 if (limit > 0 && cnt >= limit) 139 break; 138 if (limit > 0 && cnt >= max) break; 140 139 } 141 140 -
src/main/java/de/mpiwg/itgroup/annotations/restlet/annotations_ui/AnnotationsResource.java
r99 r101 29 29 import java.util.logging.Logger; 30 30 31 import org.restlet.data.Form; 31 32 import org.restlet.data.MediaType; 32 33 import org.restlet.data.Reference; … … 39 40 import de.mpiwg.itgroup.annotations.Annotation; 40 41 import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore; 42 import de.mpiwg.itgroup.annotations.restlet.AnnotatorResourceImpl; 41 43 import de.mpiwg.itgroup.annotations.restlet.BaseRestlet; 42 44 … … 70 72 @Get("html") 71 73 public Representation doGetHTML(Representation entity) { 72 String result = null; 74 Form form = getRequest().getResourceRef().getQueryAsForm(); 75 int limit = AnnotatorResourceImpl.getInt(form.getFirstValue("limit", "100")); 76 int offset = AnnotatorResourceImpl.getInt(form.getFirstValue("offset", "0")); 77 int max = offset + limit; 78 int numannots = store.getAnnotationCount(); 79 String baseUrl = this.getReference().getHierarchicalPart(); 80 StringBuilder result = null; 73 81 // list all annotations 74 result = "<html><body>\n<h1>Annotations</h1>\n<table>"; 75 result += "<tr><th>uri</th><th>text</th><th>target</th><th>fragment</th><th>creator</th></tr>"; 76 List<Annotation> annotations = store.getAnnotations("id", "*"); 82 result = new StringBuilder("<html><body>\n<h1>Annotations</h1>\n"); 83 result.append("<p>"); 84 if (offset > 0) { 85 result.append(String.format(" <a href=\"%s?offset=%s&limit=%s\">prev</a> ", baseUrl, Math.max(offset - limit, 0), limit)); 86 } 87 result.append(String.format("| %s - %s of %s annotations |", offset, (offset + limit), numannots)); 88 if (max < numannots) { 89 result.append(String.format(" <a href=\"%s?offset=%s&limit=%s\">next</a>", baseUrl, Math.min(max, numannots), limit)); 90 } 91 result.append("</p>\n"); 92 result.append("<table>"); 93 result.append("<tr><th>uri</th><th>text</th><th>target</th><th>fragment</th><th>creator</th></tr>"); 94 List<Annotation> annotations = store.getAnnotations("id", "*", limit, offset); 77 95 for (Annotation annotation : annotations) { 78 96 Reference url = this.getReference().clone(); 79 97 url.addSegment(annotation.getUrlId()); 80 result +=String.format("<tr><td><a href=\"%s\">%s</a></td><td>%s</td><td><a href=\"%s\">%s</a></td><td>%s</td><td>%s</td></tr>\n", url,98 result.append(String.format("<tr><td><a href=\"%s\">%s</a></td><td>%s</td><td><a href=\"%s\">%s</a></td><td>%s</td><td>%s</td></tr>\n", url, 81 99 annotation.getUri(), annotation.getBodyText(), annotation.getTargetBaseUri(), annotation.getTargetBaseUri(), 82 annotation.getTargetFragment(), annotation.getCreatorName()) ;100 annotation.getTargetFragment(), annotation.getCreatorName())); 83 101 } 84 result += "</table>\n";85 result += "</body>\n</html>";102 result.append("</table>\n"); 103 result.append("</body>\n</html>"); 86 104 return new StringRepresentation(result, MediaType.TEXT_HTML); 87 105 }
Note: See TracChangeset
for help on using the changeset viewer.