Ignore:
Timestamp:
Sep 25, 2012, 8:20:17 PM (12 years ago)
Author:
casties
Branch:
default
Parents:
33:86bb29132ba6 (diff), 31:9f653697437e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge with 8ad8596a570af38aacfaecdb68b7e06145624181

Files:
2 edited

Legend:

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

    r31 r34  
    276276       
    277277        // delete annotation
    278         store.deleteById(id);
     278        store.deleteAnnotationById(id);
    279279        setStatus(Status.SUCCESS_NO_CONTENT);
    280280        return null;
  • src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorAnnotations.java

    r32 r34  
    66
    77import java.io.IOException;
    8 
     8import java.util.ArrayList;
     9import java.util.List;
     10
     11import org.json.JSONArray;
    912import org.json.JSONException;
    1013import org.json.JSONObject;
     14import org.restlet.data.Form;
     15import org.restlet.data.Parameter;
    1116import org.restlet.data.Status;
    1217import org.restlet.ext.json.JsonRepresentation;
     
    1924import de.mpiwg.itgroup.annotations.Annotation;
    2025import de.mpiwg.itgroup.annotations.Person;
     26import de.mpiwg.itgroup.annotations.Tag;
    2127import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore;
     28import de.mpiwg.itgroup.annotations.restlet.utils.JSONObjectComparator;
    2229
    2330/**
     
    5057
    5158        if (id == null) {
    52             // TODO: what to return without id - list all annotations?
    53             setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
    54             return null;
     59           
     60            return getAllAnnotations();
    5561        }
    5662
     
    7783    }
    7884
    79     /**
     85    private Representation getAllAnnotations() {
     86       
     87         Form form = getRequest().getResourceRef().getQueryAsForm();
     88           String sortBy=null;
     89           for (Parameter parameter : form) {
     90             if (parameter.getName().equals("sortBy")){
     91             sortBy =  parameter.getValue();
     92             }
     93           }
     94       
     95        AnnotationStore store = getAnnotationStore();
     96        ArrayList<JSONObject> results = new ArrayList<JSONObject>();
     97       
     98        List<Annotation> annotations = store.getAnnotations(null, null);
     99        for (Annotation annotation : annotations) {
     100               
     101                 JSONObject jo = createAnnotatorJson(annotation,false);
     102             results.add(jo);
     103           
     104            }
     105       
     106        if (sortBy!=null){
     107                JSONObjectComparator.sortAnnotations(results,sortBy);
     108        }
     109       
     110        JSONArray resultsJa = new JSONArray();
     111        for (JSONObject result:results){
     112                resultsJa.put(result);
     113        }
     114       
     115        // assemble result object
     116        JSONObject result = new JSONObject();
     117        try {
     118            result.put("rows", resultsJa);
     119            result.put("total", resultsJa.length());
     120        } catch (JSONException e) {
     121            setStatus(Status.SERVER_ERROR_INTERNAL, "JSON Error");
     122            return null;
     123        }
     124        logger.debug("sending:");
     125        logger.debug(result);
     126        return new JsonRepresentation(result);
     127    }
     128
     129       
     130       
     131       
     132
     133        /**
    80134     * POST with JSON content-type. Creates a new Annotation.
    81135     *
Note: See TracChangeset for help on using the changeset viewer.