diff --git a/src/main/java/org/gcube/portal/social/networking/ws/methods/v2/Notifications.java b/src/main/java/org/gcube/portal/social/networking/ws/methods/v2/Notifications.java index d81ebd2..5e192b8 100644 --- a/src/main/java/org/gcube/portal/social/networking/ws/methods/v2/Notifications.java +++ b/src/main/java/org/gcube/portal/social/networking/ws/methods/v2/Notifications.java @@ -185,7 +185,7 @@ public class Notifications { return Response.status(status).entity(responseBean).build(); } - + /** * Send a Catalogue notification to a given user * @param event @@ -225,8 +225,9 @@ public class Notifications { if (! event.idsAsGroup()) { for (int i = 0; i < idsToNotify.length; i++) { String userIdToNotify = idsToNotify[i]; + String username2Notify = null; try { - um.getUserByUsername(userIdToNotify); + username2Notify = um.getUserByUsername(userIdToNotify).getUsername(); } catch (Exception e) { status = Status.NOT_ACCEPTABLE; @@ -235,13 +236,20 @@ public class Notifications { responseBean.setMessage("Username not found " + userIdToNotify); return Response.status(status).entity(responseBean).build(); } - deliveryResult = - nm.notifyCatalogueEvent( - CatalogueEventTypeMapper.getType(event.getType()), - userIdToNotify, - event.getItemId(), - event.getNotifyText(), - event.getItemURL()); + if (username2Notify != null) { + deliveryResult = + nm.notifyCatalogueEvent( + CatalogueEventTypeMapper.getType(event.getType()), + username, + event.getItemId(), + event.getNotifyText(), + event.getItemURL()); + } else { + status = Status.NOT_ACCEPTABLE; + responseBean.setSuccess(false); + responseBean.setMessage("Username not found " + userIdToNotify); + return Response.status(status).entity(responseBean).build(); + } } } else { //the ids are contexts for (int i = 0; i < idsToNotify.length; i++) { @@ -335,8 +343,9 @@ public class Notifications { if (! event.idsAsGroup()) { for (int i = 0; i < idsToNotify.length; i++) { String userIdToNotify = idsToNotify[i]; + String username2Notify = ""; try { - um.getUserByUsername(userIdToNotify); + username2Notify = um.getUserByUsername(userIdToNotify).getUsername(); } catch (Exception e) { status = Status.NOT_ACCEPTABLE; @@ -345,7 +354,7 @@ public class Notifications { responseBean.setMessage("Username not found " + userIdToNotify); return Response.status(status).entity(responseBean).build(); } - deliveryResult = notifyWorkspaceEvent(event, nm, userIdToNotify); + deliveryResult = notifyWorkspaceEvent(event, nm, username2Notify); } } else { //the ids are contexts for (int i = 0; i < idsToNotify.length; i++) {