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

make admin ui view of all annotations scale better.
author casties
date Fri, 13 Feb 2015 18:10:11 +0100
parents 199143c669e4
children
comparison
equal deleted inserted replaced
100:f9ee715ee9e9 101:7268c3ca025b
26 */ 26 */
27 27
28 import java.util.List; 28 import java.util.List;
29 import java.util.logging.Logger; 29 import java.util.logging.Logger;
30 30
31 import org.restlet.data.Form;
31 import org.restlet.data.MediaType; 32 import org.restlet.data.MediaType;
32 import org.restlet.data.Reference; 33 import org.restlet.data.Reference;
33 import org.restlet.representation.Representation; 34 import org.restlet.representation.Representation;
34 import org.restlet.representation.StringRepresentation; 35 import org.restlet.representation.StringRepresentation;
35 import org.restlet.resource.Get; 36 import org.restlet.resource.Get;
36 import org.restlet.resource.ResourceException; 37 import org.restlet.resource.ResourceException;
37 import org.restlet.resource.ServerResource; 38 import org.restlet.resource.ServerResource;
38 39
39 import de.mpiwg.itgroup.annotations.Annotation; 40 import de.mpiwg.itgroup.annotations.Annotation;
40 import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore; 41 import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore;
42 import de.mpiwg.itgroup.annotations.restlet.AnnotatorResourceImpl;
41 import de.mpiwg.itgroup.annotations.restlet.BaseRestlet; 43 import de.mpiwg.itgroup.annotations.restlet.BaseRestlet;
42 44
43 /** 45 /**
44 * Resource class for the list of annotations. 46 * Resource class for the list of annotations.
45 * 47 *
67 * @param entity 69 * @param entity
68 * @return 70 * @return
69 */ 71 */
70 @Get("html") 72 @Get("html")
71 public Representation doGetHTML(Representation entity) { 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 // list all annotations 81 // list all annotations
74 result = "<html><body>\n<h1>Annotations</h1>\n<table>"; 82 result = new StringBuilder("<html><body>\n<h1>Annotations</h1>\n");
75 result += "<tr><th>uri</th><th>text</th><th>target</th><th>fragment</th><th>creator</th></tr>"; 83 result.append("<p>");
76 List<Annotation> annotations = store.getAnnotations("id", "*"); 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 for (Annotation annotation : annotations) { 95 for (Annotation annotation : annotations) {
78 Reference url = this.getReference().clone(); 96 Reference url = this.getReference().clone();
79 url.addSegment(annotation.getUrlId()); 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 annotation.getUri(), annotation.getBodyText(), annotation.getTargetBaseUri(), annotation.getTargetBaseUri(), 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"; 102 result.append("</table>\n");
85 result += "</body>\n</html>"; 103 result.append("</body>\n</html>");
86 return new StringRepresentation(result, MediaType.TEXT_HTML); 104 return new StringRepresentation(result, MediaType.TEXT_HTML);
87 } 105 }
88 106
89 } 107 }