Mercurial > hg > AnnotationManagerN4J
comparison src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorResourceImpl.java @ 64:c48435e7f312
fix npe when an annotation has no creator.
author | casties |
---|---|
date | Mon, 03 Dec 2012 18:42:20 +0100 |
parents | 9f8c9611848a |
children | 2b1e6df5e21a |
comparison
equal
deleted
inserted
replaced
63:9f8c9611848a | 64:c48435e7f312 |
---|---|
64 } | 64 } |
65 return store; | 65 return store; |
66 } | 66 } |
67 | 67 |
68 public String encodeJsonId(String id) { | 68 public String encodeJsonId(String id) { |
69 if (id == null) return null; | 69 if (id == null) |
70 return null; | |
70 try { | 71 try { |
71 return Base64.encodeBase64URLSafeString(id.getBytes("UTF-8")); | 72 return Base64.encodeBase64URLSafeString(id.getBytes("UTF-8")); |
72 } catch (UnsupportedEncodingException e) { | 73 } catch (UnsupportedEncodingException e) { |
73 return null; | 74 return null; |
74 } | 75 } |
75 } | 76 } |
76 | 77 |
77 public String decodeJsonId(String id) { | 78 public String decodeJsonId(String id) { |
78 if (id == null) return null; | 79 if (id == null) |
80 return null; | |
79 try { | 81 try { |
80 return new String(Base64.decodeBase64(id), "UTF-8"); | 82 return new String(Base64.decodeBase64(id), "UTF-8"); |
81 } catch (UnsupportedEncodingException e) { | 83 } catch (UnsupportedEncodingException e) { |
82 return null; | 84 return null; |
83 } | 85 } |
200 } | 202 } |
201 | 203 |
202 /* | 204 /* |
203 * user | 205 * user |
204 */ | 206 */ |
205 if (makeUserObject) { | 207 Actor creator = annot.getCreator(); |
206 // create user object | 208 if (creator != null) { |
207 JSONObject userObject = new JSONObject(); | 209 if (makeUserObject) { |
208 Actor creator = annot.getCreator(); | 210 // create user object |
209 // save creator as uri | 211 JSONObject userObject = new JSONObject(); |
210 userObject.put("uri", creator.getUri()); | 212 // save creator as uri |
211 // make short user id | 213 userObject.put("uri", creator.getUri()); |
212 String userId = creator.getIdString(); | 214 // make short user id |
213 // set as id | 215 String userId = creator.getIdString(); |
214 userObject.put("id", userId); | 216 // set as id |
215 // get full name | 217 userObject.put("id", userId); |
216 String userName = creator.getName(); | 218 // get full name |
217 if (userName == null) { | 219 String userName = creator.getName(); |
218 BaseRestlet restServer = (BaseRestlet) getApplication(); | 220 if (userName == null) { |
219 userName = restServer.getFullNameFromLdap(userId); | 221 BaseRestlet restServer = (BaseRestlet) getApplication(); |
220 } | 222 userName = restServer.getFullNameFromLdap(userId); |
221 userObject.put("name", userName); | 223 } |
222 // save user object | 224 userObject.put("name", userName); |
223 jo.put("user", userObject); | 225 // save user object |
224 } else { | 226 jo.put("user", userObject); |
225 // save user as string | 227 } else { |
226 jo.put("user", annot.getCreatorUri()); | 228 // save user as string |
229 jo.put("user", annot.getCreatorUri()); | |
230 } | |
227 } | 231 } |
228 | 232 |
229 /* | 233 /* |
230 * ranges | 234 * ranges |
231 */ | 235 */ |
598 } | 602 } |
599 // no fragment is an error | 603 // no fragment is an error |
600 if (annot.getFragmentType() == null || annot.getTargetFragment() == null) { | 604 if (annot.getFragmentType() == null || annot.getTargetFragment() == null) { |
601 throw new JSONException("Annotation has no valid target fragment!"); | 605 throw new JSONException("Annotation has no valid target fragment!"); |
602 } | 606 } |
603 | 607 |
604 /* | 608 /* |
605 * permissions | 609 * permissions |
606 */ | 610 */ |
607 if (jo.has("permissions")) { | 611 if (jo.has("permissions")) { |
608 JSONObject permissions = jo.getJSONObject("permissions"); | 612 JSONObject permissions = jo.getJSONObject("permissions"); |