Changeset 61:b8ef15c8c4a5 in AnnotationManagerN4J for src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorResources.java
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorResources.java
r50 r61 18 18 import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore; 19 19 20 21 20 /** 22 * API for accessing tags in the Annotation store.21 * API for accessing resource objects in the Annotation store. 23 22 * 24 23 * @author dwinter 25 * 24 * 26 25 */ 27 26 public class AnnotatorResources extends AnnotatorResourceImpl { … … 31 30 32 31 /** 33 * GET with JSON content-type. 34 * Parameters: 35 * user: short user name 36 * uri: user uri 37 * 32 * GET with JSON content-type. 33 * Parameters: user: short user name uri: user uri 34 * 38 35 * @param entity 39 36 * @return … … 41 38 @Get("json") 42 39 public Representation doGetJSON(Representation entity) { 43 logger.debug("Annotator Groups doGetJSON!");40 logger.debug("AnnotatorResources doGetJSON!"); 44 41 setCorsHeaders(); 45 42 46 43 String jsonId = (String) getRequest().getAttributes().get("id"); 47 44 String uri = decodeJsonId(jsonId); 48 45 49 46 logger.debug("resources-id=" + uri); 50 47 51 if (uri ==null){52 return getAllResources();48 if (uri == null) { 49 return getAllResources(); 53 50 } else { 54 55 return getResource(uri); 51 return getResource(uri); 56 52 } 57 53 } 58 59 protected Representation getResource(String uri){ 60 AnnotationStore store = getAnnotationStore(); 61 //String tagUri=NS.MPIWG_TAGS_URL+id; 62 Node tagNode = store.getResourceNodeByUri(uri); 63 Resource resource = store.createResourceFromNode(tagNode); 64 JSONObject jo = new JSONObject(); 65 try { 66 jo.put("id", encodeJsonId(resource.getUri())); 67 jo.put("uri", resource.getUri()); 68 } catch (JSONException e) { 69 } 70 71 return new JsonRepresentation(jo); 54 55 protected Representation getResource(String uri) { 56 AnnotationStore store = getAnnotationStore(); 57 Node resNode = store.getResourceNodeByUri(uri); 58 Resource resource = store.createResourceFromNode(resNode); 59 JSONObject jo = new JSONObject(); 60 try { 61 jo.put("id", encodeJsonId(resource.getUri())); 62 jo.put("uri", resource.getUri()); 63 } catch (JSONException e) { 64 } 65 66 return new JsonRepresentation(jo); 72 67 } 73 protected Representation getAllResources() { 74 JSONArray results = new JSONArray(); 68 69 protected Representation getAllResources() { 70 JSONArray results = new JSONArray(); 75 71 AnnotationStore store = getAnnotationStore(); 76 77 78 List<Resource> resources = store.getResources(null, null); 79 for (Resource resource : resources) { 80 JSONObject jo = new JSONObject(); 81 try { 82 jo.put("id", encodeJsonId(resource.getUri())); 83 jo.put("uri", resource.getUri()); 84 } catch (JSONException e) { 85 } 86 results.put(jo); 72 73 List<Resource> resources = store.getResources(null, null); 74 for (Resource resource : resources) { 75 JSONObject jo = new JSONObject(); 76 try { 77 jo.put("id", encodeJsonId(resource.getUri())); 78 jo.put("uri", resource.getUri()); 79 } catch (JSONException e) { 87 80 } 88 81 results.put(jo); 82 } 83 89 84 // assemble result object 90 85 JSONObject result = new JSONObject(); … … 99 94 logger.debug(result); 100 95 return new JsonRepresentation(result); 101 } 102 96 } 103 97 104 105 98 }
Note: See TracChangeset
for help on using the changeset viewer.