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/AnnotatorAnnotations.java

    r41 r61  
    5555        logger.debug("annotation-id=" + id);
    5656
    57        
    5857        // do authentication
    5958        Person authUser = Person.createPersonWithId(this.checkAuthToken(entity));
     
    6160
    6261        if (id == null) {
    63            
    6462            return getAllAnnotations(authUser);
    6563        }
    6664
    67      
    6865        AnnotationStore store = getAnnotationStore();
    6966        Annotation annot = store.getAnnotationById(id);
    7067        if (annot != null) {
    71             if (! annot.isActionAllowed("read", authUser, store)) {
     68            if (!annot.isActionAllowed("read", authUser, store)) {
    7269                setStatus(Status.CLIENT_ERROR_FORBIDDEN, "Not Authorized!");
    7370                return null;
     
    8582
    8683    private Representation getAllAnnotations(Person authUser) {
    87        
    88         Form form = getRequest().getResourceRef().getQueryAsForm();
    89            String sortBy=null;
    90            for (Parameter parameter : form) {
    91              if (parameter.getName().equals("sortBy")){
    92              sortBy = parameter.getValue();
    93              }
    94            }
    95        
     84
     85        Form form = getRequest().getResourceRef().getQueryAsForm();
     86        String sortBy = null;
     87        for (Parameter parameter : form) {
     88            if (parameter.getName().equals("sortBy")) {
     89                sortBy = parameter.getValue();
     90            }
     91        }
     92
    9693        AnnotationStore store = getAnnotationStore();
    9794        ArrayList<JSONObject> results = new ArrayList<JSONObject>();
    98        
    99         List<Annotation> annotations = store.getAnnotations(null, null);
     95
     96        List<Annotation> annotations = store.getAnnotations(null, null);
    10097        for (Annotation annotation : annotations) {
    101                  //check permission
    102                          if (!annotation.isActionAllowed("read", authUser, store)) continue;
    103      
    104                  JSONObject jo = createAnnotatorJson(annotation,false);
    105              results.add(jo);
    106            
    107             }
    108        
    109         if (sortBy!=null){
    110                 JSONObjectComparator.sortAnnotations(results,sortBy);
    111         }
    112        
    113         JSONArray resultsJa = new JSONArray();
    114         for (JSONObject result:results){
    115                 resultsJa.put(result);
    116         }
    117        
     98            // check permission
     99            if (!annotation.isActionAllowed("read", authUser, store)) continue;
     100
     101            JSONObject jo = createAnnotatorJson(annotation, false);
     102            results.add(jo);
     103        }
     104
     105        if (sortBy != null) {
     106            JSONObjectComparator.sortAnnotations(results, sortBy);
     107        }
     108
     109        JSONArray resultsJa = new JSONArray();
     110        for (JSONObject result : results) {
     111            resultsJa.put(result);
     112        }
     113
    118114        // assemble result object
    119115        JSONObject result = new JSONObject();
     
    130126    }
    131127
    132        
    133        
    134        
    135 
    136         /**
     128    /**
    137129     * POST with JSON content-type. Creates a new Annotation.
    138130     *
     
    144136        // set headers
    145137        setCorsHeaders();
    146        
    147         // do authentication TODO: who's allowed to create? 
     138
     139        // do authentication TODO: who's allowed to create?
    148140        Person authUser = Person.createPersonWithId(this.checkAuthToken(entity));
    149141        logger.debug("request authenticated=" + authUser);
     
    222214                return null;
    223215            }
    224             if (! storedAnnot.isActionAllowed("update", authUser, store)) {
     216            if (!storedAnnot.isActionAllowed("update", authUser, store)) {
    225217                setStatus(Status.CLIENT_ERROR_FORBIDDEN);
    226218                return null;
     
    272264        Annotation annot = store.getAnnotationById(id);
    273265        if (annot != null) {
    274             if (! annot.isActionAllowed("delete", authUser, store)) {
     266            if (!annot.isActionAllowed("delete", authUser, store)) {
    275267                setStatus(Status.CLIENT_ERROR_FORBIDDEN, "Not Authorized!");
    276268                return null;
    277269            }
    278270        }
    279        
     271
    280272        // delete annotation
    281273        store.deleteAnnotationById(id);
Note: See TracChangeset for help on using the changeset viewer.