Changeset 31:9f653697437e in AnnotationManagerN4J
- Timestamp:
- Sep 25, 2012, 7:47:58 PM (12 years ago)
- Branch:
- default
- Location:
- src/main
- Files:
-
- 4 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java
r29 r31 85 85 } 86 86 87 88 87 89 public List<Actor> getActors(String key, String query, NodeTypes type) { 88 90 ArrayList<Actor> actors = new ArrayList<Actor>(); … … 123 125 } 124 126 127 128 /** 129 * Returns List of Annotations. 130 * Key has to be indexed. 131 * 132 * @param key 133 * @param query 134 * @return 135 */ 136 public List<Annotation> getAnnotations(String key, String query) { 137 ArrayList<Annotation> annotations = new ArrayList<Annotation>(); 138 Index<Node> idx = getNodeIndex(NodeTypes.ANNOTATION); 139 if (key == null) { 140 key = "id"; 141 query = "*"; 142 } 143 IndexHits<Node> annotNodes = idx.query(key, query); 144 for (Node annotNode : annotNodes) { 145 Annotation annotation = createAnnotationFromNode(annotNode); 146 annotations.add(annotation); 147 } 148 return annotations; 149 } 150 151 125 152 126 153 /** -
src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorAnnotations.java
r22 r31 6 6 7 7 import java.io.IOException; 8 8 import java.util.ArrayList; 9 import java.util.List; 10 11 import org.json.JSONArray; 9 12 import org.json.JSONException; 10 13 import org.json.JSONObject; 14 import org.restlet.data.Form; 15 import org.restlet.data.Parameter; 11 16 import org.restlet.data.Status; 12 17 import org.restlet.ext.json.JsonRepresentation; … … 19 24 import de.mpiwg.itgroup.annotations.Annotation; 20 25 import de.mpiwg.itgroup.annotations.Person; 26 import de.mpiwg.itgroup.annotations.Tag; 21 27 import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore; 28 import de.mpiwg.itgroup.annotations.restlet.utils.JSONObjectComparator; 22 29 23 30 /** … … 50 57 51 58 if (id == null) { 52 // TODO: what to return without id - list all annotations? 53 setStatus(Status.CLIENT_ERROR_BAD_REQUEST); 54 return null; 59 60 return getAllAnnotations(); 55 61 } 56 62 … … 77 83 } 78 84 79 /** 85 private Representation getAllAnnotations() { 86 87 Form form = getRequest().getResourceRef().getQueryAsForm(); 88 String sortBy=null; 89 for (Parameter parameter : form) { 90 if (parameter.getName().equals("sortBy")){ 91 sortBy = parameter.getValue(); 92 } 93 } 94 95 AnnotationStore store = getAnnotationStore(); 96 ArrayList<JSONObject> results = new ArrayList<JSONObject>(); 97 98 List<Annotation> annotations = store.getAnnotations(null, null); 99 for (Annotation annotation : annotations) { 100 101 JSONObject jo = createAnnotatorJson(annotation,false); 102 results.add(jo); 103 104 } 105 106 if (sortBy!=null){ 107 JSONObjectComparator.sortAnnotations(results,sortBy); 108 } 109 110 JSONArray resultsJa = new JSONArray(); 111 for (JSONObject result:results){ 112 resultsJa.put(result); 113 } 114 115 // assemble result object 116 JSONObject result = new JSONObject(); 117 try { 118 result.put("rows", resultsJa); 119 result.put("total", resultsJa.length()); 120 } catch (JSONException e) { 121 setStatus(Status.SERVER_ERROR_INTERNAL, "JSON Error"); 122 return null; 123 } 124 logger.debug("sending:"); 125 logger.debug(result); 126 return new JsonRepresentation(result); 127 } 128 129 130 131 132 133 /** 80 134 * POST with JSON content-type. Creates a new Annotation. 81 135 * -
src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorAnnotationsByTags.java
r28 r31 65 65 66 66 if (sortBy!=null){ 67 sortAnnotations(results,sortBy);67 JSONObjectComparator.sortAnnotations(results,sortBy); 68 68 } 69 69 … … 88 88 89 89 90 /**91 * Sortiere array nach einem Parameter in den Annotationen92 * @param results93 * @return94 */95 private void sortAnnotations(List<JSONObject> results,String attribute) {96 JSONObjectComparator comp = new JSONObjectComparator(attribute);97 98 99 90 100 java.util.Collections.sort( results, comp);101 102 103 104 }105 91 } -
src/main/java/de/mpiwg/itgroup/annotations/restlet/annotations_ui/AnnotationsUiRestlet.java
r23 r31 42 42 router.attach("/groups/{id}/", GroupResource.class); 43 43 router.attach("/groups/{id}/members", GroupMembersResource.class); 44 44 45 45 router.attach("/", InfoResource.class); 46 46 // authenticator.setNext(router); -
src/main/java/de/mpiwg/itgroup/annotations/restlet/utils/JSONObjectComparator.java
r28 r31 2 2 3 3 import java.util.Comparator; 4 import java.util.List; 4 5 5 6 import de.mpiwg.itgroup.annotations.Annotation; … … 34 35 } 35 36 36 37 /** 38 * Sortiere array nach einem Parameter in den Annotationen 39 * @param results 40 * @return 41 */ 42 public static void sortAnnotations(List<JSONObject> results,String attribute) { 43 JSONObjectComparator comp = new JSONObjectComparator(attribute); 44 45 46 47 java.util.Collections.sort( results, comp); 48 49 50 51 } 37 52 38 53 } -
src/main/webapp/index.html
r22 r31 14 14 <ul> 15 15 <li><a href="groups">View and edit groups</a></li> 16 <li><a href="tags">Browse by Tags</a></li> 17 <li><a href="annotationBrowser">All Annotations</a></li> 18 16 19 </ul> 17 20 </body> -
src/main/webapp/tags/css/tag.css
r30 r31 21 21 display:table-cell; 22 22 padding-left:20px; 23 padding-bottom:10px; 23 24 } 24 25 .dcMetaData { 25 26 display:table-row; 26 27 } 28 29 .annotatonMetaData{ 30 padding-bottom:30px; 31 } -
src/main/webapp/tags/index.html
r30 r31 3 3 <head> 4 4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 5 <title>Browse rBy Tags</title>5 <title>Browse By Tags</title> 6 6 <script type="text/javascript" src="./js/jquery-1.8.2.min.js"></script> 7 7 <script type="text/javascript" src="./js/tag.js"></script> -
src/main/webapp/tags/js/tag.js
r30 r31 1 var annotServer="http://localhost:8280/AnnotationManagerN4J/annotator/"; 1 //var annotServer="http://localhost:8280/AnnotationManagerN4J/annotator/"; 2 var annotServer="http://tuxserve03.mpiwg-berlin.mpg.de/AnnotationManager/annotator/"; 2 3 var viewerAddress="http://libcoll.mpiwg-berlin.mpg.de/libviewa?url="; 3 4 var docNamespace="http://echo.mpiwg-berlin.mpg.de/documents/";
Note: See TracChangeset
for help on using the changeset viewer.