refactored
This commit is contained in:
parent
306ecf935b
commit
cd0f65cf35
|
@ -200,55 +200,13 @@ public class Notifications {
|
|||
SocialNetworkingUser user = new SocialNetworkingUser(senderUser.getUsername(), senderUser.getEmail(), senderUser.getFullname(), senderUser.getUserAvatarURL());
|
||||
NotificationsManager nm = new ApplicationNotificationsManager(UserManagerWSBuilder.getInstance().getUserManager(), site, context, user);
|
||||
|
||||
String[] idsToNotify = event.getIdsToNotify();
|
||||
if (! event.idsAsGroup()) {
|
||||
for (int i = 0; i < idsToNotify.length; i++) {
|
||||
String userIdToNotify = idsToNotify[i];
|
||||
deliveryResult = notifyWorkspaceEvent(event, nm, userIdToNotify);
|
||||
|
||||
switch (event.getType()) {
|
||||
case ITEM_NEW: {
|
||||
AddedItemEvent itemBean = (AddedItemEvent) event;
|
||||
String[] userIdsToNotify = itemBean.getIdsToNotify();
|
||||
if (! itemBean.idsAsGroup()) {
|
||||
for (int i = 0; i < userIdsToNotify.length; i++) {
|
||||
String userIdToNotify = userIdsToNotify[i];
|
||||
deliveryResult = nm.notifyAddedItem(userIdToNotify, WorkspaceItemMapper.getFileItem(itemBean.getItem()), WorkspaceItemMapper.getSharedFolder(itemBean.getItem().getParent()));
|
||||
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case FOLDER_SHARE: {
|
||||
SharedFolderEvent itemBean = (SharedFolderEvent) event;
|
||||
String[] userIdsToNotify = itemBean.getIdsToNotify();
|
||||
if (! itemBean.idsAsGroup()) {
|
||||
for (int i = 0; i < userIdsToNotify.length; i++) {
|
||||
String userIdToNotify = userIdsToNotify[i];
|
||||
deliveryResult = nm.notifyFolderSharing(userIdToNotify, WorkspaceItemMapper.getSharedFolder(itemBean.getFolder()));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case FOLDER_UNSHARE: {
|
||||
UnsharedFolderEvent itemBean = (UnsharedFolderEvent) event;
|
||||
String[] userIdsToNotify = itemBean.getIdsToNotify();
|
||||
if (! itemBean.idsAsGroup()) {
|
||||
for (int i = 0; i < userIdsToNotify.length; i++) {
|
||||
String userIdToNotify = userIdsToNotify[i];
|
||||
deliveryResult = nm.notifyFolderUnsharing(userIdToNotify, itemBean.getUnsharedFolderId(), itemBean.getUnsharedFolderName());
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case FOLDER_RENAME: {
|
||||
RenamedFolderEvent itemBean = (RenamedFolderEvent) event;
|
||||
String[] userIdsToNotify = itemBean.getIdsToNotify();
|
||||
if (! itemBean.idsAsGroup()) {
|
||||
for (int i = 0; i < userIdsToNotify.length; i++) {
|
||||
String userIdToNotify = userIdsToNotify[i];
|
||||
deliveryResult = nm.notifyFolderRenaming(userIdToNotify, itemBean.getPreviousName(), itemBean.getNewName(), itemBean.getRenamedFolderId());
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} catch(Exception e){
|
||||
logger.error("Unable to send job notification", e);
|
||||
|
@ -268,5 +226,40 @@ public class Notifications {
|
|||
}
|
||||
return Response.status(status).entity(responseBean).build();
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param event
|
||||
* @param nm
|
||||
* @param idToNotify
|
||||
* @return
|
||||
*/
|
||||
private boolean notifyWorkspaceEvent(WorkspaceEvent event, NotificationsManager nm, String idToNotify) {
|
||||
try {
|
||||
switch (event.getType()) {
|
||||
case ITEM_NEW: {
|
||||
AddedItemEvent itemBean = (AddedItemEvent) event;
|
||||
return nm.notifyAddedItem(idToNotify, WorkspaceItemMapper.getFileItem(itemBean.getItem()), WorkspaceItemMapper.getSharedFolder(itemBean.getItem().getParent()));
|
||||
}
|
||||
case FOLDER_SHARE: {
|
||||
SharedFolderEvent itemBean = (SharedFolderEvent) event;
|
||||
return nm.notifyFolderSharing(idToNotify, WorkspaceItemMapper.getSharedFolder(itemBean.getFolder()));
|
||||
}
|
||||
case FOLDER_UNSHARE: {
|
||||
UnsharedFolderEvent itemBean = (UnsharedFolderEvent) event;
|
||||
return nm.notifyFolderUnsharing(idToNotify, itemBean.getUnsharedFolderId(), itemBean.getUnsharedFolderName());
|
||||
}
|
||||
case FOLDER_RENAME: {
|
||||
RenamedFolderEvent itemBean = (RenamedFolderEvent) event;
|
||||
return nm.notifyFolderRenaming(idToNotify, itemBean.getPreviousName(), itemBean.getNewName(), itemBean.getRenamedFolderId());
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} catch(Exception e){
|
||||
logger.error("Unable to send job notification", e);
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue