Changeset 65:c0dd5314bada in AnnotationManagerN4J for src
- Timestamp:
- Dec 5, 2012, 2:36:43 PM (12 years ago)
- Branch:
- default
- Location:
- src/main/java/de/mpiwg/itgroup/annotations/restlet
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorAnnotations.java
r63 r65 6 6 7 7 import java.io.IOException; 8 import java.io.UnsupportedEncodingException; 9 import java.net.URLDecoder; 8 10 import java.util.ArrayList; 9 11 import java.util.List; … … 50 52 setCorsHeaders(); 51 53 // id from URI /annotations/{id} 54 String id = null; 52 55 String jsonId = (String) getRequest().getAttributes().get("id"); 53 String id = decodeJsonId(jsonId); 54 logger.debug("annotation-id=" + id); 56 if (jsonId != null) { 57 // URL decode 58 try { 59 jsonId = URLDecoder.decode(jsonId, "UTF-8"); 60 } catch (UnsupportedEncodingException e) { 61 // this shouldn't happen 62 } 63 id = decodeJsonId(jsonId); 64 logger.debug("annotation-id=" + id); 65 } 55 66 56 67 // do authentication … … 87 98 AnnotationStore store = getAnnotationStore(); 88 99 ArrayList<JSONObject> results = new ArrayList<JSONObject>(); 89 100 90 101 // read all annotations 91 102 List<Annotation> annotations = store.getAnnotations(null, null); 92 103 for (Annotation annotation : annotations) { 93 104 // check permission 94 if (!annotation.isActionAllowed("read", authUser, store)) continue; 105 if (!annotation.isActionAllowed("read", authUser, store)) 106 continue; 95 107 // add annotation to list 96 108 JSONObject jo = createAnnotatorJson(annotation, false); … … 102 114 JSONObjectComparator.sortAnnotations(results, sortBy); 103 115 } 104 116 105 117 // put in JSON list 106 118 JSONArray rows = new JSONArray(); … … 108 120 for (JSONObject result : results) { 109 121 cnt += 1; 110 if (offset > 0 && cnt < offset) continue; 122 if (offset > 0 && cnt < offset) 123 continue; 111 124 rows.put(result); 112 if (limit > 0 && cnt >= limit) break; 125 if (limit > 0 && cnt >= limit) 126 break; 113 127 } 114 128 -
src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorAnnotationsByResources.java
r50 r65 1 1 package de.mpiwg.itgroup.annotations.restlet; 2 2 3 import java.io.UnsupportedEncodingException; 4 import java.net.URLDecoder; 3 5 import java.util.ArrayList; 4 6 import java.util.List; … … 23 25 * 24 26 * @author dwinter 25 * 27 * 26 28 */ 27 29 public class AnnotatorAnnotationsByResources extends AnnotatorResourceImpl { … … 29 31 return "OPTIONS,GET"; 30 32 } 31 33 32 34 @Get("json") 33 35 public Representation doGetJSON(Representation entity) { 34 36 logger.debug("AnnotatorAnnotatonsByResource doGetJSON!"); 35 37 setCorsHeaders(); 36 38 37 39 // do authentication 38 40 Person authUser = Person.createPersonWithId(this.checkAuthToken(entity)); 39 41 logger.debug("request authenticated=" + authUser); 40 42 41 43 String id = null; 42 44 String jsonId = (String) getRequest().getAttributes().get("id"); 43 45 if (jsonId != null) { 46 // URL decode 47 try { 48 jsonId = URLDecoder.decode(jsonId, "UTF-8"); 49 } catch (UnsupportedEncodingException e) { 50 // this shouldn't happen 51 } 52 id = decodeJsonId(jsonId); 53 // String id = jsonId; 54 logger.debug("ressource-id=" + id); 55 } 56 44 57 Form form = getRequest().getResourceRef().getQueryAsForm(); 45 String sortBy =null;58 String sortBy = null; 46 59 for (Parameter parameter : form) { 47 if (parameter.getName().equals("sortBy")){48 sortBy =parameter.getValue();49 }60 if (parameter.getName().equals("sortBy")) { 61 sortBy = parameter.getValue(); 62 } 50 63 } 51 52 String id = decodeJsonId(jsonId); 53 //String id = jsonId; 54 logger.debug("ressource-id=" + id); 55 64 56 65 AnnotationStore store = getAnnotationStore(); 57 //String tagUri=NS.MPIWG_TAGS_URL+id;66 // String tagUri=NS.MPIWG_TAGS_URL+id; 58 67 List<Annotation> annotations = store.getAnnotationsByResource(id); 59 60 //JSONArray results = new JSONArray();68 69 // JSONArray results = new JSONArray(); 61 70 ArrayList<JSONObject> results = new ArrayList<JSONObject>(); 62 63 for (Annotation annot : annotations) { 64 //check permission 65 if (!annot.isActionAllowed("read", authUser, store)) continue; 66 67 JSONObject jo = createAnnotatorJson(annot,false); 71 72 for (Annotation annot : annotations) { 73 // check permission 74 if (!annot.isActionAllowed("read", authUser, store)) 75 continue; 76 77 JSONObject jo = createAnnotatorJson(annot, false); 68 78 results.add(jo); 69 79 } 70 71 if (sortBy!=null){ 72 JSONObjectComparator.sortAnnotations(results,sortBy); 73 } 74 75 JSONArray resultsJa = new JSONArray(); 76 for (JSONObject result:results){ 77 resultsJa.put(result); 78 } 79 80 // assemble result object 81 JSONObject result = new JSONObject(); 82 try { 83 result.put("rows", resultsJa); 84 result.put("total", resultsJa.length()); 85 } catch (JSONException e) { 86 setStatus(Status.SERVER_ERROR_INTERNAL, "JSON Error"); 87 return null; 80 81 if (sortBy != null) { 82 JSONObjectComparator.sortAnnotations(results, sortBy); 83 } 84 85 JSONArray resultsJa = new JSONArray(); 86 for (JSONObject result : results) { 87 resultsJa.put(result); 88 } 89 90 // assemble result object 91 JSONObject result = new JSONObject(); 92 try { 93 result.put("rows", resultsJa); 94 result.put("total", resultsJa.length()); 95 } catch (JSONException e) { 96 setStatus(Status.SERVER_ERROR_INTERNAL, "JSON Error"); 97 return null; 98 } 99 return new JsonRepresentation(result); 88 100 } 89 logger.debug("sending:"); 90 logger.debug(result); 91 return new JsonRepresentation(result); 101 92 102 } 93 94 95 96 } -
src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorAnnotationsByTags.java
r58 r65 1 1 package de.mpiwg.itgroup.annotations.restlet; 2 2 3 import java.io.UnsupportedEncodingException; 4 import java.net.URLDecoder; 3 5 import java.util.ArrayList; 4 6 import java.util.List; … … 8 10 import org.json.JSONObject; 9 11 import org.restlet.data.Form; 10 import org.restlet.data.Parameter;11 12 import org.restlet.data.Status; 12 13 import org.restlet.ext.json.JsonRepresentation; … … 23 24 * 24 25 * @author dwinter 25 * 26 * 26 27 */ 27 28 public class AnnotatorAnnotationsByTags extends AnnotatorResourceImpl { … … 29 30 return "OPTIONS,GET"; 30 31 } 31 32 32 33 @Get("json") 33 34 public Representation doGetJSON(Representation entity) { 34 35 logger.debug("AnnotatorAnnotatonsBytag doGetJSON!"); 35 36 setCorsHeaders(); 36 37 37 38 // do authentication 38 39 Person authUser = Person.createPersonWithId(this.checkAuthToken(entity)); 39 40 logger.debug("request authenticated=" + authUser); 40 41 41 42 String jsonId = (String) getRequest().getAttributes().get("id"); 43 42 String id = (String) getRequest().getAttributes().get("id"); 43 // URL decode 44 try { 45 id = URLDecoder.decode(id, "UTF-8"); 46 } catch (UnsupportedEncodingException e) { 47 // this shouldn't happen 48 } 49 logger.debug("annotation-id=" + id); 50 44 51 Form form = getRequest().getResourceRef().getQueryAsForm(); 45 String sortBy=null; 46 for (Parameter parameter : form) { 47 if (parameter.getName().equals("sortBy")){ 48 sortBy = parameter.getValue(); 49 } 50 } 51 52 //String id = decodeJsonId(jsonId); 53 String id = jsonId; 54 logger.debug("annotation-id=" + id); 55 52 String sortBy = form.getFirstValue("sortBy"); 53 56 54 AnnotationStore store = getAnnotationStore(); 57 55 String tagUri = BaseRestlet.TAGS_URI_PREFIX + id; 58 56 List<Annotation> annotations = store.getAnnotationsByTag(tagUri); 59 60 //JSONArray results = new JSONArray();57 58 // JSONArray results = new JSONArray(); 61 59 ArrayList<JSONObject> results = new ArrayList<JSONObject>(); 62 63 for (Annotation annot : annotations) { 64 //check permission 65 if (!annot.isActionAllowed("read", authUser, store)) continue; 66 67 JSONObject jo = createAnnotatorJson(annot,false); 60 61 for (Annotation annot : annotations) { 62 // check permission 63 if (!annot.isActionAllowed("read", authUser, store)) 64 continue; 65 66 JSONObject jo = createAnnotatorJson(annot, false); 68 67 results.add(jo); 69 68 } 70 71 if (sortBy!=null){ 72 JSONObjectComparator.sortAnnotations(results,sortBy); 73 } 74 75 JSONArray resultsJa = new JSONArray(); 76 for (JSONObject result:results){ 77 resultsJa.put(result); 78 } 79 80 // assemble result object 81 JSONObject result = new JSONObject(); 82 try { 83 result.put("rows", resultsJa); 84 result.put("total", resultsJa.length()); 85 } catch (JSONException e) { 86 setStatus(Status.SERVER_ERROR_INTERNAL, "JSON Error"); 87 return null; 69 70 if (sortBy != null) { 71 JSONObjectComparator.sortAnnotations(results, sortBy); 72 } 73 74 JSONArray resultsJa = new JSONArray(); 75 for (JSONObject result : results) { 76 resultsJa.put(result); 77 } 78 79 // assemble result object 80 JSONObject result = new JSONObject(); 81 try { 82 result.put("rows", resultsJa); 83 result.put("total", resultsJa.length()); 84 } catch (JSONException e) { 85 setStatus(Status.SERVER_ERROR_INTERNAL, "JSON Error"); 86 return null; 87 } 88 return new JsonRepresentation(result); 88 89 } 89 logger.debug("sending:"); 90 logger.debug(result); 91 return new JsonRepresentation(result); 90 92 91 } 93 94 95 96 } -
src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorResources.java
r61 r65 4 4 package de.mpiwg.itgroup.annotations.restlet; 5 5 6 import java.io.UnsupportedEncodingException; 7 import java.net.URLDecoder; 6 8 import java.util.List; 7 9 … … 42 44 43 45 String jsonId = (String) getRequest().getAttributes().get("id"); 46 if (jsonId != null) { 47 // URL decode 48 try { 49 jsonId = URLDecoder.decode(jsonId, "UTF-8"); 50 } catch (UnsupportedEncodingException e) { 51 // this shouldn't happen 52 } 53 } 44 54 String uri = decodeJsonId(jsonId); 45 55 -
src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorTags.java
r58 r65 4 4 package de.mpiwg.itgroup.annotations.restlet; 5 5 6 import java.io.UnsupportedEncodingException; 7 import java.net.URLDecoder; 6 8 import java.util.List; 7 9 … … 18 20 import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore; 19 21 20 21 22 /** 22 23 * API for accessing tags in the Annotation store. 23 24 * 24 25 * @author dwinter 25 * 26 * 26 27 */ 27 28 public class AnnotatorTags extends AnnotatorResourceImpl { … … 31 32 32 33 /** 33 * GET with JSON content-type. 34 * GET with JSON content-type. 34 35 * Parameters: 35 * user: short user name 36 * user: short user name 36 37 * uri: user uri 37 * 38 * 38 39 * @param entity 39 40 * @return … … 43 44 logger.debug("AnnotatorGroups doGetJSON!"); 44 45 setCorsHeaders(); 45 46 46 47 String jsonId = (String) getRequest().getAttributes().get("id"); 47 // String id = decodeJsonId(jsonId);48 // String id = decodeJsonId(jsonId); 48 49 String id = jsonId; 49 50 logger.debug("annotation-id=" + id); 50 51 51 if (id ==null){52 return getAllTags();52 if (id == null) { 53 return getAllTags(); 53 54 } else { 54 55 return getTag(id); 55 // URL decode 56 try { 57 id = URLDecoder.decode(id, "UTF-8"); 58 } catch (UnsupportedEncodingException e) { 59 // this shouldn't happen 60 } 61 return getTag(id); 56 62 } 57 63 } 58 59 protected Representation getTag(String id) {60 61 62 63 64 65 66 67 68 69 70 71 72 64 65 protected Representation getTag(String id) { 66 AnnotationStore store = getAnnotationStore(); 67 String tagUri = BaseRestlet.TAGS_URI_PREFIX + id; 68 Node tagNode = store.getTagNodeByUri(tagUri); 69 Tag tag = store.createTagFromNode(tagNode); 70 JSONObject jo = new JSONObject(); 71 try { 72 jo.put("id", tag.getId()); 73 jo.put("name", tag.getName()); 74 jo.put("uri", tag.getUri()); 75 } catch (JSONException e) { 76 } 77 78 return new JsonRepresentation(jo); 73 79 } 74 protected Representation getAllTags() { 75 JSONArray results = new JSONArray(); 80 81 protected Representation getAllTags() { 82 JSONArray results = new JSONArray(); 76 83 AnnotationStore store = getAnnotationStore(); 77 78 79 List<Tag> tags = store.getTags(null, null); 80 for (Tag tag : tags) { 81 JSONObject jo = new JSONObject(); 82 try { 83 jo.put("id", tag.getId()); 84 jo.put("name", tag.getName()); 85 jo.put("uri", tag.getUri()); 86 } catch (JSONException e) { 87 } 88 results.put(jo); 84 85 List<Tag> tags = store.getTags(null, null); 86 for (Tag tag : tags) { 87 JSONObject jo = new JSONObject(); 88 try { 89 jo.put("id", tag.getId()); 90 jo.put("name", tag.getName()); 91 jo.put("uri", tag.getUri()); 92 } catch (JSONException e) { 89 93 } 90 94 results.put(jo); 95 } 96 91 97 // assemble result object 92 98 JSONObject result = new JSONObject(); … … 101 107 logger.debug(result); 102 108 return new JsonRepresentation(result); 103 } 104 109 } 105 110 106 107 111 } -
src/main/java/de/mpiwg/itgroup/annotations/restlet/annotations_ui/AnnotationResource.java
r50 r65 3 3 */ 4 4 package de.mpiwg.itgroup.annotations.restlet.annotations_ui; 5 6 import java.io.UnsupportedEncodingException; 7 import java.net.URLDecoder; 5 8 6 9 import org.apache.log4j.Logger; … … 49 52 // get annotation from store 50 53 if (requestId != null) { 54 // URL decode 55 try { 56 requestId = URLDecoder.decode(requestId, "UTF-8"); 57 } catch (UnsupportedEncodingException e) { 58 // this shouldn't happen 59 } 51 60 // the ID in the path is encoded 52 61 String id = Annotation.decodeId(requestId); -
src/main/java/de/mpiwg/itgroup/annotations/restlet/annotations_ui/GroupResource.java
r32 r65 3 3 */ 4 4 package de.mpiwg.itgroup.annotations.restlet.annotations_ui; 5 6 import java.io.UnsupportedEncodingException; 7 import java.net.URLDecoder; 5 8 6 9 import org.apache.log4j.Logger; … … 49 52 // get group from store 50 53 if (requestId != null) { 54 // URL decode 55 try { 56 requestId = URLDecoder.decode(requestId, "UTF-8"); 57 } catch (UnsupportedEncodingException e) { 58 // this shouldn't happen 59 } 51 60 group = (Group) store.getActor(new Group(requestId)); 52 61 } -
src/main/java/de/mpiwg/itgroup/annotations/restlet/annotations_ui/PersonResource.java
r32 r65 3 3 */ 4 4 package de.mpiwg.itgroup.annotations.restlet.annotations_ui; 5 6 import java.io.UnsupportedEncodingException; 7 import java.net.URLDecoder; 5 8 6 9 import org.apache.log4j.Logger; … … 42 45 // id from URI /annotations/persons/{id} 43 46 requestId = (String) getRequest().getAttributes().get("id"); 44 logger.debug(" group-id=" + requestId);47 logger.debug("person-id=" + requestId); 45 48 // get store instance 46 49 if (store == null) { 47 50 store = ((BaseRestlet) getApplication()).getAnnotationStore(); 48 51 } 49 // get groupfrom store52 // get person from store 50 53 if (requestId != null) { 54 // URL decode 55 try { 56 requestId = URLDecoder.decode(requestId, "UTF-8"); 57 } catch (UnsupportedEncodingException e) { 58 // this shouldn't happen 59 } 51 60 person = (Person) store.getActor(new Person(requestId)); 52 61 } -
src/main/java/de/mpiwg/itgroup/annotations/restlet/annotations_ui/PersonsResource.java
r50 r65 57 57 String form = f.getFirstValue("form"); 58 58 if (form != null && form.equals("new_person")) { 59 // output new groupform59 // output new person form 60 60 result = "<html><body>\n"; 61 61 result += "<h1>New person</h1>\n"; … … 69 69 result += "</form>\n</body>\n</html>"; 70 70 } else { 71 // list all groups71 // list all persons 72 72 result = "<html><body>\n<h1>Persons</h1>\n<table>"; 73 73 result += "<tr><th>id</th><th>name</th><th>uri</th></tr>"; … … 75 75 for (Person person : persons) { 76 76 Reference url = this.getReference().clone(); 77 url.addSegment(person.getId ());77 url.addSegment(person.getIdString()); 78 78 result += String.format("<tr><td><a href=\"%s\">%s</a></td><td>%s</td><td>%s</td></tr>\n", url, 79 79 person.getIdString(), person.getName(), person.getUri()); … … 87 87 88 88 /** 89 * POST creates a new Group.89 * POST creates a new person. 90 90 * 91 91 * @return
Note: See TracChangeset
for help on using the changeset viewer.