Ignore:
Timestamp:
Nov 22, 2012, 4:38:53 PM (11 years ago)
Author:
casties
Branch:
default
Message:

implemented new shape format for image annotations.
minor cleanups.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorResources.java

    r50 r61  
    1818import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore;
    1919
    20 
    2120/**
    22  * API for accessing tags in the Annotation store.
     21 * API for accessing resource objects in the Annotation store.
    2322 *
    2423 * @author dwinter
    25  *
     24 * 
    2625 */
    2726public class AnnotatorResources extends AnnotatorResourceImpl {
     
    3130
    3231    /**
    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     *
    3835     * @param entity
    3936     * @return
     
    4138    @Get("json")
    4239    public Representation doGetJSON(Representation entity) {
    43         logger.debug("AnnotatorGroups doGetJSON!");
     40        logger.debug("AnnotatorResources doGetJSON!");
    4441        setCorsHeaders();
    45        
     42
    4643        String jsonId = (String) getRequest().getAttributes().get("id");
    4744        String uri = decodeJsonId(jsonId);
    48        
     45
    4946        logger.debug("resources-id=" + uri);
    5047
    51         if (uri==null){
    52         return getAllResources();
     48        if (uri == null) {
     49            return getAllResources();
    5350        } else {
    54 
    55                 return getResource(uri);
     51            return getResource(uri);
    5652        }
    5753    }
    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);
    7267    }
    73         protected Representation getAllResources() {
    74                 JSONArray results = new JSONArray();
     68
     69    protected Representation getAllResources() {
     70        JSONArray results = new JSONArray();
    7571        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) {
    8780            }
    88        
     81            results.put(jo);
     82        }
     83
    8984        // assemble result object
    9085        JSONObject result = new JSONObject();
     
    9994        logger.debug(result);
    10095        return new JsonRepresentation(result);
    101         }               
    102        
     96    }
    10397
    104    
    10598}
Note: See TracChangeset for help on using the changeset viewer.