diff src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorAnnotations.java @ 61:b8ef15c8c4a5

implemented new shape format for image annotations. minor cleanups.
author casties
date Thu, 22 Nov 2012 17:38:53 +0100
parents 5d4260344db5
children 9f8c9611848a
line wrap: on
line diff
--- a/src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorAnnotations.java	Tue Nov 20 19:43:12 2012 +0100
+++ b/src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorAnnotations.java	Thu Nov 22 17:38:53 2012 +0100
@@ -54,21 +54,18 @@
         String id = decodeJsonId(jsonId);
         logger.debug("annotation-id=" + id);
 
-        
         // do authentication
         Person authUser = Person.createPersonWithId(this.checkAuthToken(entity));
         logger.debug("request authenticated=" + authUser);
 
         if (id == null) {
-            
             return getAllAnnotations(authUser);
         }
 
-     
         AnnotationStore store = getAnnotationStore();
         Annotation annot = store.getAnnotationById(id);
         if (annot != null) {
-            if (! annot.isActionAllowed("read", authUser, store)) {
+            if (!annot.isActionAllowed("read", authUser, store)) {
                 setStatus(Status.CLIENT_ERROR_FORBIDDEN, "Not Authorized!");
                 return null;
             }
@@ -84,37 +81,36 @@
     }
 
     private Representation getAllAnnotations(Person authUser) {
-    	
-    	 Form form = getRequest().getResourceRef().getQueryAsForm();
-           String sortBy=null;
-           for (Parameter parameter : form) {
-             if (parameter.getName().equals("sortBy")){
-             sortBy =  parameter.getValue();
-             }
-           }
-        
+
+        Form form = getRequest().getResourceRef().getQueryAsForm();
+        String sortBy = null;
+        for (Parameter parameter : form) {
+            if (parameter.getName().equals("sortBy")) {
+                sortBy = parameter.getValue();
+            }
+        }
+
         AnnotationStore store = getAnnotationStore();
         ArrayList<JSONObject> results = new ArrayList<JSONObject>();
-       
-       	List<Annotation> annotations = store.getAnnotations(null, null);
+
+        List<Annotation> annotations = store.getAnnotations(null, null);
         for (Annotation annotation : annotations) {
-          	 //check permission
-			 if (!annotation.isActionAllowed("read", authUser, store)) continue;
-     
-        	 JSONObject jo = createAnnotatorJson(annotation,false);
-             results.add(jo);
-           
-            }
-        
-        if (sortBy!=null){
-    		JSONObjectComparator.sortAnnotations(results,sortBy);
-    	}
-        
-    	JSONArray resultsJa = new JSONArray();
-    	for (JSONObject result:results){
-    		resultsJa.put(result);
-    	}
-    	
+            // check permission
+            if (!annotation.isActionAllowed("read", authUser, store)) continue;
+
+            JSONObject jo = createAnnotatorJson(annotation, false);
+            results.add(jo);
+        }
+
+        if (sortBy != null) {
+            JSONObjectComparator.sortAnnotations(results, sortBy);
+        }
+
+        JSONArray resultsJa = new JSONArray();
+        for (JSONObject result : results) {
+            resultsJa.put(result);
+        }
+
         // assemble result object
         JSONObject result = new JSONObject();
         try {
@@ -129,11 +125,7 @@
         return new JsonRepresentation(result);
     }
 
-       	
-        
-	
-
-	/**
+    /**
      * POST with JSON content-type. Creates a new Annotation.
      * 
      * @return
@@ -143,8 +135,8 @@
         logger.debug("AnnotatorAnnotations doPostJSON!");
         // set headers
         setCorsHeaders();
-        
-        // do authentication TODO: who's allowed to create? 
+
+        // do authentication TODO: who's allowed to create?
         Person authUser = Person.createPersonWithId(this.checkAuthToken(entity));
         logger.debug("request authenticated=" + authUser);
         if (authUser == null) {
@@ -221,7 +213,7 @@
                 setStatus(Status.CLIENT_ERROR_NOT_FOUND);
                 return null;
             }
-            if (! storedAnnot.isActionAllowed("update", authUser, store)) {
+            if (!storedAnnot.isActionAllowed("update", authUser, store)) {
                 setStatus(Status.CLIENT_ERROR_FORBIDDEN);
                 return null;
             }
@@ -271,12 +263,12 @@
         AnnotationStore store = getAnnotationStore();
         Annotation annot = store.getAnnotationById(id);
         if (annot != null) {
-            if (! annot.isActionAllowed("delete", authUser, store)) {
+            if (!annot.isActionAllowed("delete", authUser, store)) {
                 setStatus(Status.CLIENT_ERROR_FORBIDDEN, "Not Authorized!");
                 return null;
             }
         }
-        
+
         // delete annotation
         store.deleteAnnotationById(id);
         setStatus(Status.SUCCESS_NO_CONTENT);