Mercurial > hg > AnnotationManagerN4J
diff src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorResources.java @ 61:b8ef15c8c4a5
implemented new shape format for image annotations.
minor cleanups.
author | casties |
---|---|
date | Thu, 22 Nov 2012 17:38:53 +0100 |
parents | 64aa756c60cc |
children | c0dd5314bada |
line wrap: on
line diff
--- a/src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorResources.java Tue Nov 20 19:43:12 2012 +0100 +++ b/src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorResources.java Thu Nov 22 17:38:53 2012 +0100 @@ -17,12 +17,11 @@ import de.mpiwg.itgroup.annotations.Resource; import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore; - /** - * API for accessing tags in the Annotation store. + * API for accessing resource objects in the Annotation store. * * @author dwinter - * + * */ public class AnnotatorResources extends AnnotatorResourceImpl { protected String getAllowedMethodsForHeader() { @@ -30,62 +29,58 @@ } /** - * GET with JSON content-type. - * Parameters: - * user: short user name - * uri: user uri - * + * GET with JSON content-type. + * Parameters: user: short user name uri: user uri + * * @param entity * @return */ @Get("json") public Representation doGetJSON(Representation entity) { - logger.debug("AnnotatorGroups doGetJSON!"); + logger.debug("AnnotatorResources doGetJSON!"); setCorsHeaders(); - + String jsonId = (String) getRequest().getAttributes().get("id"); String uri = decodeJsonId(jsonId); - + logger.debug("resources-id=" + uri); - if (uri==null){ - return getAllResources(); + if (uri == null) { + return getAllResources(); } else { - - return getResource(uri); + return getResource(uri); } } - - protected Representation getResource(String uri){ - AnnotationStore store = getAnnotationStore(); - //String tagUri=NS.MPIWG_TAGS_URL+id; - Node tagNode = store.getResourceNodeByUri(uri); - Resource resource = store.createResourceFromNode(tagNode); - JSONObject jo = new JSONObject(); - try { - jo.put("id", encodeJsonId(resource.getUri())); - jo.put("uri", resource.getUri()); - } catch (JSONException e) { - } - - return new JsonRepresentation(jo); + + protected Representation getResource(String uri) { + AnnotationStore store = getAnnotationStore(); + Node resNode = store.getResourceNodeByUri(uri); + Resource resource = store.createResourceFromNode(resNode); + JSONObject jo = new JSONObject(); + try { + jo.put("id", encodeJsonId(resource.getUri())); + jo.put("uri", resource.getUri()); + } catch (JSONException e) { + } + + return new JsonRepresentation(jo); } - protected Representation getAllResources() { - JSONArray results = new JSONArray(); + + protected Representation getAllResources() { + JSONArray results = new JSONArray(); AnnotationStore store = getAnnotationStore(); - - - List<Resource> resources = store.getResources(null, null); - for (Resource resource : resources) { - JSONObject jo = new JSONObject(); - try { - jo.put("id", encodeJsonId(resource.getUri())); - jo.put("uri", resource.getUri()); - } catch (JSONException e) { - } - results.put(jo); + + List<Resource> resources = store.getResources(null, null); + for (Resource resource : resources) { + JSONObject jo = new JSONObject(); + try { + jo.put("id", encodeJsonId(resource.getUri())); + jo.put("uri", resource.getUri()); + } catch (JSONException e) { } - + results.put(jo); + } + // assemble result object JSONObject result = new JSONObject(); try { @@ -98,8 +93,6 @@ logger.debug("sending:"); logger.debug(result); return new JsonRepresentation(result); - } - + } - }