Changeset 65:c0dd5314bada in AnnotationManagerN4J for src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorTags.java
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note: See TracChangeset
for help on using the changeset viewer.