Mercurial > hg > AnnotationManagerN4J
changeset 64:c48435e7f312
fix npe when an annotation has no creator.
author | casties |
---|---|
date | Mon, 03 Dec 2012 18:42:20 +0100 |
parents | 9f8c9611848a |
children | c0dd5314bada |
files | src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorResourceImpl.java |
diffstat | 1 files changed, 28 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorResourceImpl.java Fri Nov 23 17:55:04 2012 +0100 +++ b/src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorResourceImpl.java Mon Dec 03 18:42:20 2012 +0100 @@ -66,7 +66,8 @@ } public String encodeJsonId(String id) { - if (id == null) return null; + if (id == null) + return null; try { return Base64.encodeBase64URLSafeString(id.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { @@ -75,7 +76,8 @@ } public String decodeJsonId(String id) { - if (id == null) return null; + if (id == null) + return null; try { return new String(Base64.decodeBase64(id), "UTF-8"); } catch (UnsupportedEncodingException e) { @@ -202,28 +204,30 @@ /* * user */ - if (makeUserObject) { - // create user object - JSONObject userObject = new JSONObject(); - Actor creator = annot.getCreator(); - // save creator as uri - userObject.put("uri", creator.getUri()); - // make short user id - String userId = creator.getIdString(); - // set as id - userObject.put("id", userId); - // get full name - String userName = creator.getName(); - if (userName == null) { - BaseRestlet restServer = (BaseRestlet) getApplication(); - userName = restServer.getFullNameFromLdap(userId); + Actor creator = annot.getCreator(); + if (creator != null) { + if (makeUserObject) { + // create user object + JSONObject userObject = new JSONObject(); + // save creator as uri + userObject.put("uri", creator.getUri()); + // make short user id + String userId = creator.getIdString(); + // set as id + userObject.put("id", userId); + // get full name + String userName = creator.getName(); + if (userName == null) { + BaseRestlet restServer = (BaseRestlet) getApplication(); + userName = restServer.getFullNameFromLdap(userId); + } + userObject.put("name", userName); + // save user object + jo.put("user", userObject); + } else { + // save user as string + jo.put("user", annot.getCreatorUri()); } - userObject.put("name", userName); - // save user object - jo.put("user", userObject); - } else { - // save user as string - jo.put("user", annot.getCreatorUri()); } /* @@ -600,7 +604,7 @@ if (annot.getFragmentType() == null || annot.getTargetFragment() == null) { throw new JSONException("Annotation has no valid target fragment!"); } - + /* * permissions */