Mercurial > hg > AnnotationManagerN4J
comparison src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorAnnotations.java @ 75:25eb2e1df106
change logging to java.util.logging.
author | casties |
---|---|
date | Fri, 21 Mar 2014 13:32:41 +0100 |
parents | 2b1e6df5e21a |
children | b406507a953d |
comparison
equal
deleted
inserted
replaced
74:e5ff09208c28 | 75:25eb2e1df106 |
---|---|
68 * @param entity | 68 * @param entity |
69 * @return | 69 * @return |
70 */ | 70 */ |
71 @Get("json") | 71 @Get("json") |
72 public Representation doGetJSON(Representation entity) { | 72 public Representation doGetJSON(Representation entity) { |
73 logger.debug("AnnotatorAnnotations doGetJSON!"); | 73 logger.fine("AnnotatorAnnotations doGetJSON!"); |
74 setCorsHeaders(); | 74 setCorsHeaders(); |
75 // id from URI /annotations/{id} | 75 // id from URI /annotations/{id} |
76 String id = null; | 76 String id = null; |
77 String jsonId = (String) getRequest().getAttributes().get("id"); | 77 String jsonId = (String) getRequest().getAttributes().get("id"); |
78 if (jsonId != null) { | 78 if (jsonId != null) { |
81 jsonId = URLDecoder.decode(jsonId, "UTF-8"); | 81 jsonId = URLDecoder.decode(jsonId, "UTF-8"); |
82 } catch (UnsupportedEncodingException e) { | 82 } catch (UnsupportedEncodingException e) { |
83 // this shouldn't happen | 83 // this shouldn't happen |
84 } | 84 } |
85 id = decodeJsonId(jsonId); | 85 id = decodeJsonId(jsonId); |
86 logger.debug("annotation-id=" + id); | 86 logger.fine("annotation-id=" + id); |
87 } | 87 } |
88 | 88 |
89 // do authentication | 89 // do authentication |
90 Person authUser = Person.createPersonWithId(this.checkAuthToken(entity)); | 90 Person authUser = Person.createPersonWithId(this.checkAuthToken(entity)); |
91 logger.debug("request authenticated=" + authUser); | 91 logger.fine("request authenticated=" + authUser); |
92 | 92 |
93 if (id == null) { | 93 if (id == null) { |
94 // no id -- send all annotations | 94 // no id -- send all annotations |
95 Form form = getRequest().getResourceRef().getQueryAsForm(); | 95 Form form = getRequest().getResourceRef().getQueryAsForm(); |
96 int limit = getInt(form.getFirstValue("limit")); | 96 int limit = getInt(form.getFirstValue("limit")); |
165 * | 165 * |
166 * @return | 166 * @return |
167 */ | 167 */ |
168 @Post("json") | 168 @Post("json") |
169 public Representation doPostJson(Representation entity) { | 169 public Representation doPostJson(Representation entity) { |
170 logger.debug("AnnotatorAnnotations doPostJSON!"); | 170 logger.fine("AnnotatorAnnotations doPostJSON!"); |
171 // set headers | 171 // set headers |
172 setCorsHeaders(); | 172 setCorsHeaders(); |
173 | 173 |
174 // do authentication TODO: who's allowed to create? | 174 // do authentication TODO: who's allowed to create? |
175 Person authUser = Person.createPersonWithId(this.checkAuthToken(entity)); | 175 Person authUser = Person.createPersonWithId(this.checkAuthToken(entity)); |
176 logger.debug("request authenticated=" + authUser); | 176 logger.fine("request authenticated=" + authUser); |
177 if (authUser == null) { | 177 if (authUser == null) { |
178 setStatus(Status.CLIENT_ERROR_FORBIDDEN, "Not Authorized!"); | 178 setStatus(Status.CLIENT_ERROR_FORBIDDEN, "Not Authorized!"); |
179 return null; | 179 return null; |
180 } | 180 } |
181 | 181 |
220 * @param entity | 220 * @param entity |
221 * @return | 221 * @return |
222 */ | 222 */ |
223 @Put("json") | 223 @Put("json") |
224 public Representation doPutJSON(Representation entity) { | 224 public Representation doPutJSON(Representation entity) { |
225 logger.debug("AnnotatorAnnotations doPutJSON!"); | 225 logger.fine("AnnotatorAnnotations doPutJSON!"); |
226 setCorsHeaders(); | 226 setCorsHeaders(); |
227 // id from URI /annotations/{id} | 227 // id from URI /annotations/{id} |
228 String jsonId = (String) getRequest().getAttributes().get("id"); | 228 String jsonId = (String) getRequest().getAttributes().get("id"); |
229 String id = decodeJsonId(jsonId); | 229 String id = decodeJsonId(jsonId); |
230 logger.debug("annotation-id=" + id); | 230 logger.fine("annotation-id=" + id); |
231 | 231 |
232 // do authentication | 232 // do authentication |
233 Person authUser = Person.createPersonWithId(this.checkAuthToken(entity)); | 233 Person authUser = Person.createPersonWithId(this.checkAuthToken(entity)); |
234 logger.debug("request authenticated=" + authUser); | 234 logger.fine("request authenticated=" + authUser); |
235 | 235 |
236 Annotation annot = null; | 236 Annotation annot = null; |
237 AnnotationStore store = getAnnotationStore(); | 237 AnnotationStore store = getAnnotationStore(); |
238 try { | 238 try { |
239 JsonRepresentation jrep = new JsonRepresentation(entity); | 239 JsonRepresentation jrep = new JsonRepresentation(entity); |
266 // return new annotation | 266 // return new annotation |
267 jo = createAnnotatorJson(storedAnnot, (authUser == null)); | 267 jo = createAnnotatorJson(storedAnnot, (authUser == null)); |
268 JsonRepresentation retRep = new JsonRepresentation(jo); | 268 JsonRepresentation retRep = new JsonRepresentation(jo); |
269 return retRep; | 269 return retRep; |
270 } catch (JSONException e) { | 270 } catch (JSONException e) { |
271 logger.error("Error in doPutJSON", e); | 271 logger.severe("Error in doPutJSON: "+e); |
272 setStatus(Status.CLIENT_ERROR_BAD_REQUEST); | 272 setStatus(Status.CLIENT_ERROR_BAD_REQUEST); |
273 } catch (IOException e) { | 273 } catch (IOException e) { |
274 logger.error("Error in doPutJSON", e); | 274 logger.severe("Error in doPutJSON: "+e); |
275 setStatus(Status.SERVER_ERROR_INTERNAL, "Other Error"); | 275 setStatus(Status.SERVER_ERROR_INTERNAL, "Other Error"); |
276 } | 276 } |
277 return null; | 277 return null; |
278 } | 278 } |
279 | 279 |
283 * @param entity | 283 * @param entity |
284 * @return | 284 * @return |
285 */ | 285 */ |
286 @Delete("json") | 286 @Delete("json") |
287 public Representation doDeleteJSON(Representation entity) { | 287 public Representation doDeleteJSON(Representation entity) { |
288 logger.debug("AnnotatorAnnotations doDeleteJSON!"); | 288 logger.fine("AnnotatorAnnotations doDeleteJSON!"); |
289 setCorsHeaders(); | 289 setCorsHeaders(); |
290 // id from URI /annotations/{id} | 290 // id from URI /annotations/{id} |
291 String jsonId = (String) getRequest().getAttributes().get("id"); | 291 String jsonId = (String) getRequest().getAttributes().get("id"); |
292 String id = decodeJsonId(jsonId); | 292 String id = decodeJsonId(jsonId); |
293 logger.debug("annotation-id=" + id); | 293 logger.fine("annotation-id=" + id); |
294 | 294 |
295 // do authentication | 295 // do authentication |
296 Person authUser = Person.createPersonWithId(this.checkAuthToken(entity)); | 296 Person authUser = Person.createPersonWithId(this.checkAuthToken(entity)); |
297 logger.debug("request authenticated=" + authUser); | 297 logger.fine("request authenticated=" + authUser); |
298 AnnotationStore store = getAnnotationStore(); | 298 AnnotationStore store = getAnnotationStore(); |
299 Annotation annot = store.getAnnotationById(id); | 299 Annotation annot = store.getAnnotationById(id); |
300 if (annot != null) { | 300 if (annot != null) { |
301 if (!annot.isActionAllowed("delete", authUser, store)) { | 301 if (!annot.isActionAllowed("delete", authUser, store)) { |
302 setStatus(Status.CLIENT_ERROR_FORBIDDEN, "Not Authorized!"); | 302 setStatus(Status.CLIENT_ERROR_FORBIDDEN, "Not Authorized!"); |