diff --git a/src/main/java/org/gcube/applicationsupportlayer/social/ApplicationNotificationsManager.java b/src/main/java/org/gcube/applicationsupportlayer/social/ApplicationNotificationsManager.java index 74a7b48..bc16eb9 100644 --- a/src/main/java/org/gcube/applicationsupportlayer/social/ApplicationNotificationsManager.java +++ b/src/main/java/org/gcube/applicationsupportlayer/social/ApplicationNotificationsManager.java @@ -11,16 +11,15 @@ import java.util.UUID; import org.gcube.application.framework.core.session.ASLSession; import org.gcube.applicationsupportlayer.social.mailing.EmailPlugin; +import org.gcube.common.homelibrary.home.exceptions.InternalErrorException; +import org.gcube.common.homelibrary.home.workspace.WorkspaceItem; +import org.gcube.common.homelibrary.home.workspace.WorkspaceSharedFolder; import org.gcube.portal.custom.communitymanager.OrganizationsUtil; import org.gcube.portal.databook.shared.ApplicationProfile; import org.gcube.portal.databook.shared.Notification; import org.gcube.portal.databook.shared.NotificationChannelType; import org.gcube.portal.databook.shared.NotificationType; import org.gcube.portal.databook.shared.RunningJob; -import org.gcube.common.homelibrary.home.exceptions.InternalErrorException; -import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder; -import org.gcube.common.homelibrary.home.workspace.WorkspaceItem; -import org.gcube.common.homelibrary.home.workspace.WorkspaceSharedFolder; import org.gcube.vomanagement.usermanagement.UserManager; import org.gcube.vomanagement.usermanagement.exception.UserManagementPortalException; import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException; @@ -38,10 +37,10 @@ import org.slf4j.LoggerFactory; */ public class ApplicationNotificationsManager extends SocialPortalBridge implements NotificationsManager { private static final Logger _log = LoggerFactory.getLogger(ApplicationNotificationsManager.class); - + private static final String SENDER_EMAIL = "notificationSenderEmail"; private static final String GATEWAY_NAME = "portalinstancename"; - + private String portalName; private String senderEmail; /** @@ -122,7 +121,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen * @throws InternalErrorException */ @Override - public boolean notifyFolderSharing(String userIdToNotify, WorkspaceFolder sharedFolder) throws InternalErrorException { + public boolean notifyFolderSharing(String userIdToNotify, WorkspaceSharedFolder sharedFolder) throws InternalErrorException { String sharedFolderName = sharedFolder.getName(); if (sharedFolder.isShared()) { WorkspaceSharedFolder sharedWSFolder = (WorkspaceSharedFolder) sharedFolder; @@ -172,7 +171,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen * @throws UserManagementSystemException */ @Override - public boolean notifyFolderAddedUser(String userIdToNotify, WorkspaceFolder sharedFolder, String newAddedUserId) throws InternalErrorException, UserManagementSystemException, UserRetrievalFault, UserManagementPortalException { + public boolean notifyFolderAddedUser(String userIdToNotify, WorkspaceSharedFolder sharedFolder, String newAddedUserId) throws InternalErrorException, UserManagementSystemException, UserRetrievalFault, UserManagementPortalException { UserManager um = new LiferayUserManager(); UserModel user = um.getUserByScreenName(newAddedUserId); Notification not = new Notification( @@ -197,7 +196,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen * @throws UserManagementSystemException */ @Override - public boolean notifyFolderAddedUsers(String userIdToNotify, WorkspaceFolder sharedFolder, List newAddedUserIds) throws InternalErrorException, UserManagementSystemException, UserRetrievalFault, UserManagementPortalException { + public boolean notifyFolderAddedUsers(String userIdToNotify, WorkspaceSharedFolder sharedFolder, List newAddedUserIds) throws InternalErrorException, UserManagementSystemException, UserRetrievalFault, UserManagementPortalException { if (newAddedUserIds != null && newAddedUserIds.size() > 0) { if (newAddedUserIds.size() == 1) return notifyFolderAddedUser(userIdToNotify, sharedFolder, newAddedUserIds.get(0)); @@ -228,7 +227,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen * {@inheritDoc} */ @Override - public boolean notifyFolderRemovedUser(String userIdToNotify, WorkspaceFolder sharedFolder) throws InternalErrorException, UserManagementSystemException, UserRetrievalFault, UserManagementPortalException { + public boolean notifyFolderRemovedUser(String userIdToNotify, WorkspaceSharedFolder sharedFolder) throws InternalErrorException, UserManagementSystemException, UserRetrievalFault, UserManagementPortalException { Notification not = new Notification( UUID.randomUUID().toString(), NotificationType.WP_FOLDER_REMOVEDUSER, @@ -249,15 +248,11 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen * @throws InternalErrorException */ @Override - public boolean notifyAddedItem(String userIdToNotify, WorkspaceItem item, WorkspaceFolder sharedFolder) throws InternalErrorException { - String notifyText = "added "+ item.getName() +" to your workspace shared folder "+ item.getPath().substring(0,item.getPath().lastIndexOf('/')); - if (sharedFolder.isShared()) { - WorkspaceSharedFolder sharedWSFolder = (WorkspaceSharedFolder) sharedFolder; - if (sharedWSFolder.isVreFolder()) { - notifyText = "added "+ item.getName() +" to the workspace group folder " + sharedWSFolder.getDisplayName(); - } - - } + public boolean notifyAddedItem(String userIdToNotify, WorkspaceItem item, WorkspaceSharedFolder sharedFolder) throws InternalErrorException { + String notifyText = sharedFolder.isVreFolder() ? + "added "+ item.getName() +" to the workspace group folder " + sharedFolder.getDisplayName() : + "added "+ item.getName() +" to your workspace shared folder "+ item.getPath().substring(0,item.getPath().lastIndexOf('/')); + Notification not = new Notification( UUID.randomUUID().toString(), NotificationType.WP_ITEM_NEW, @@ -278,14 +273,10 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen * @throws InternalErrorException */ @Override - public boolean notifyMovedItem(String userIdToNotify, WorkspaceItem item, WorkspaceFolder sharedFolder) throws InternalErrorException { - String notifyText = "removed item "+ item.getName() +" from your workspace shared folder "+ sharedFolder.getName(); - if (sharedFolder.isShared()) { - WorkspaceSharedFolder sharedWSFolder = (WorkspaceSharedFolder) sharedFolder; - if (sharedWSFolder.isVreFolder()) { - notifyText = "removed item "+ item.getName() +" from the workspace group folder " + sharedWSFolder.getDisplayName(); - } - } + public boolean notifyMovedItem(String userIdToNotify, WorkspaceItem item, WorkspaceSharedFolder sharedFolder) throws InternalErrorException { + String notifyText = sharedFolder.isVreFolder() ? "removed item "+ item.getName() +" from the workspace group folder " + sharedFolder.getDisplayName(): + "removed item "+ item.getName() +" from your workspace shared folder "+ sharedFolder.getName(); + Notification not = new Notification( UUID.randomUUID().toString(), NotificationType.WP_ITEM_DELETE, @@ -306,14 +297,10 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen * @throws InternalErrorException */ @Override - public boolean notifyRemovedItem(String userIdToNotify, String itemName, WorkspaceFolder sharedFolder) throws InternalErrorException { - String notifyText = "deleted item "+ itemName +" from your workspace shared folder "+ sharedFolder.getName(); - if (sharedFolder.isShared()) { - WorkspaceSharedFolder sharedWSFolder = (WorkspaceSharedFolder) sharedFolder; - if (sharedWSFolder.isVreFolder()) { - notifyText = "deleted item "+ itemName +" from the workspace group folder " + sharedWSFolder.getDisplayName(); - } - } + public boolean notifyRemovedItem(String userIdToNotify, String itemName, WorkspaceSharedFolder sharedFolder) throws InternalErrorException { + String notifyText = sharedFolder.isVreFolder() ? "deleted item "+ itemName +" from the workspace group folder " + sharedFolder.getDisplayName(): + " deleted item "+ itemName +" from your workspace shared folder "+ sharedFolder.getName(); + Notification not = new Notification( UUID.randomUUID().toString(), NotificationType.WP_ITEM_DELETE, @@ -334,14 +321,10 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen * @throws InternalErrorException */ @Override - public boolean notifyUpdatedItem(String userIdToNotify, WorkspaceItem item, WorkspaceFolder sharedFolder) throws InternalErrorException { - String notifyText = " updated "+ item.getName() +" to your workspace shared folder "+ item.getPath().substring(0,item.getPath().lastIndexOf('/')); - if (sharedFolder.isShared()) { - WorkspaceSharedFolder sharedWSFolder = (WorkspaceSharedFolder) sharedFolder; - if (sharedWSFolder.isVreFolder()) { - notifyText = " updated "+ item.getName() +" from the workspace group folder " + sharedWSFolder.getDisplayName(); - } - } + public boolean notifyUpdatedItem(String userIdToNotify, WorkspaceItem item, WorkspaceSharedFolder sharedFolder) throws InternalErrorException { + String notifyText = sharedFolder.isVreFolder() ? " updated "+ item.getName() +" from the workspace group folder " + sharedFolder.getDisplayName(): + " updated "+ item.getName() +" to your workspace shared folder "+ item.getPath().substring(0,item.getPath().lastIndexOf('/')); + Notification not = new Notification( UUID.randomUUID().toString(), NotificationType.WP_ITEM_UPDATED, @@ -362,15 +345,10 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen * @throws InternalErrorException */ @Override - public boolean notifyItemRenaming(String userIdToNotify, String previousName, WorkspaceItem renamedItem, WorkspaceFolder rootSharedFolder) throws InternalErrorException { - String notifyText = "renamed " + previousName +" as " + renamedItem.getName() +" in your shared folder " + renamedItem.getPath().substring(0, renamedItem.getPath().lastIndexOf('/')); - - if (rootSharedFolder.isShared()) { - WorkspaceSharedFolder sharedWSFolder = (WorkspaceSharedFolder) renamedItem.getParent(); - if (sharedWSFolder.isVreFolder()) { - notifyText = "renamed "+ previousName +" as " + renamedItem.getName() +" in the workspace group folder " + sharedWSFolder.getDisplayName(); - } - } + public boolean notifyItemRenaming(String userIdToNotify, String previousName, WorkspaceItem renamedItem, WorkspaceSharedFolder rootSharedFolder) throws InternalErrorException { + String notifyText = rootSharedFolder.isVreFolder() ? "renamed "+ previousName +" as " + renamedItem.getName() +" in the workspace group folder " + rootSharedFolder.getDisplayName(): + "renamed " + previousName +" as " + renamedItem.getName() +" in your shared folder " + renamedItem.getPath().substring(0, renamedItem.getPath().lastIndexOf('/')); + Notification not = new Notification( UUID.randomUUID().toString(), NotificationType.WP_ITEM_RENAMED, @@ -411,12 +389,12 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen */ @Override public boolean notifyPost(String userIdToNotify, String feedid, String feedText) { - + StringBuilder notificationText = new StringBuilder(); notificationText.append("posted a news on ").append(aslSession.getGroupName()).append(":") // has done something .append("

").append(escapeHtml(feedText)).append(". ") .append("

Follow the discussion and comment it. "); - + Notification not = new Notification( UUID.randomUUID().toString(), NotificationType.POST_ALERT, @@ -673,18 +651,18 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen @Override public boolean notifyNewCalendarEvent(String userIdToNotify, String eventTitle, String eventType, Date startDate, Date endingDate) { SimpleDateFormat spf = new SimpleDateFormat("EEE dd MMMMM, yyyy"); - + String endDateToDisplay=""; if (endingDate != null) { endDateToDisplay = " to " + spf.format(endingDate); } - + StringBuilder notificationText = new StringBuilder(); notificationText.append("added the following event in the ").append(aslSession.getGroupName()).append(" shared calendar: ") // has done something .append("").append(eventTitle).append("
") .append("
Time: ").append(spf.format(startDate)).append(endDateToDisplay).append("
") .append("
Category: ").append(eventType); - + Notification not = new Notification( UUID.randomUUID().toString(), NotificationType.CALENDAR_ADDED_EVENT, @@ -700,25 +678,25 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen return saveNotification(not); } - + /** * {@inheritDoc} */ @Override public boolean notifyEditedCalendarEvent(String userIdToNotify, String eventTitle, String eventType, Date startDate, Date endingDate) { SimpleDateFormat spf = new SimpleDateFormat("EEE dd MMMMM, yyyy"); - + String endDateToDisplay=""; if (endingDate != null) { endDateToDisplay = " to " + spf.format(endingDate); } - + StringBuilder notificationText = new StringBuilder(); notificationText.append("edited the following event in the ").append(aslSession.getGroupName()).append(" shared calendar: ") // has done something .append("").append(eventTitle).append("
") .append("
Time: ").append(spf.format(startDate)).append(endDateToDisplay).append("
") .append("
Category: ").append(eventType); - + Notification not = new Notification( UUID.randomUUID().toString(), NotificationType.CALENDAR_UPDATED_EVENT, @@ -734,25 +712,25 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen return saveNotification(not); } - + /** * {@inheritDoc} */ @Override public boolean notifyDeletedCalendarEvent(String userIdToNotify, String eventTitle, String eventType, Date startDate, Date endingDate) { SimpleDateFormat spf = new SimpleDateFormat("EEE dd MMMMM, yyyy"); - + String endDateToDisplay=""; if (endingDate != null) { endDateToDisplay = " to " + spf.format(endingDate); } - + StringBuilder notificationText = new StringBuilder(); notificationText.append("deleted the following event in the ").append(aslSession.getGroupName()).append(" shared calendar: ") // has done something .append("").append(eventTitle).append("
") .append("
Was planned: ").append(spf.format(startDate)).append(endDateToDisplay).append("
") .append("
Category: ").append(eventType); - + Notification not = new Notification( UUID.randomUUID().toString(), NotificationType.CALENDAR_DELETED_EVENT, @@ -768,7 +746,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen return saveNotification(not); } - + /** * read the portal instance name from a property file and returns it */ @@ -793,7 +771,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen _log.debug("Returning Gateway Name: " + toReturn ); return toReturn; } - + /** * read the sender email for notifications name from a property file and returns it */ diff --git a/src/main/java/org/gcube/applicationsupportlayer/social/NotificationsManager.java b/src/main/java/org/gcube/applicationsupportlayer/social/NotificationsManager.java index 16464f5..a046b9d 100644 --- a/src/main/java/org/gcube/applicationsupportlayer/social/NotificationsManager.java +++ b/src/main/java/org/gcube/applicationsupportlayer/social/NotificationsManager.java @@ -7,6 +7,7 @@ import org.gcube.portal.databook.shared.ApplicationProfile; import org.gcube.portal.databook.shared.RunningJob; import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder; import org.gcube.common.homelibrary.home.workspace.WorkspaceItem; +import org.gcube.common.homelibrary.home.workspace.WorkspaceSharedFolder; /** * * @author Massimiliano Assante, ISTI-CNR @@ -17,10 +18,10 @@ public interface NotificationsManager { * use to notify a user he got a workspace folder shared * * @param userIdToNotify the user you want to notify - * @param sharedFolder the shared {@link WorkspaceFolder} + * @param sharedFolder the shared {@link WorkspaceSharedFolder} * @return true if the notification is correctly delivered, false otherwise */ - boolean notifyFolderSharing(String userIdToNotify, WorkspaceFolder sharedFolder) throws Exception; + boolean notifyFolderSharing(String userIdToNotify, WorkspaceSharedFolder sharedFolder) throws Exception; /** * use to notify a user he got a workspace folder renamed * @@ -35,52 +36,52 @@ public interface NotificationsManager { * use to notify a user that a new user was added in on of his workspace shared folder * * @param userIdToNotify the user you want to notify - * @param sharedFolder the shared {@link WorkspaceFolder} + * @param sharedFolder the shared {@link WorkspaceSharedFolder} * @param newAddedUserId the new user that was added * @return true if the notification is correctly delivered, false otherwise */ - boolean notifyFolderAddedUser(String userIdToNotify, WorkspaceFolder sharedFolder, String newAddedUserId) throws Exception; + boolean notifyFolderAddedUser(String userIdToNotify, WorkspaceSharedFolder sharedFolder, String newAddedUserId) throws Exception; /** * use to notify a user that a new user was added in on of his workspace shared folder * * @param userIdToNotify the user you want to notify - * @param sharedFolder the shared {@link WorkspaceFolder} + * @param sharedFolder the shared {@link WorkspaceSharedFolder} * @param newAddedUserIds List of new users that were added * @return true if the notification is correctly delivered, false otherwise */ - boolean notifyFolderAddedUsers(String userIdToNotify, WorkspaceFolder sharedFolder, List newAddedUserIds) throws Exception; + boolean notifyFolderAddedUsers(String userIdToNotify, WorkspaceSharedFolder sharedFolder, List newAddedUserIds) throws Exception; /** * use to notify a user that an existing user was removed from one of his workspace shared folder * * @param userIdToNotify the user you want to notify - * @param sharedFolder the shared {@link WorkspaceFolder} + * @param sharedFolder the shared {@link WorkspaceSharedFolder} * @return true if the notification is correctly delivered, false otherwise */ - boolean notifyFolderRemovedUser(String userIdToNotify, WorkspaceFolder sharedFolder) throws Exception; + boolean notifyFolderRemovedUser(String userIdToNotify, WorkspaceSharedFolder sharedFolder) throws Exception; /** * use to notify a user he got a workspace item new in some of his workspace shared folder * @param userIdToNotify the user you want to notify * @param newItem the new shared {@link WorkspaceItem} - * @param sharedFolder the shared folder {@link WorkspaceFolder} + * @param sharedFolder the shared folder {@link WorkspaceSharedFolder} * @return true if the notification is correctly delivered, false otherwise */ - boolean notifyAddedItem(String userIdToNotify, WorkspaceItem item, WorkspaceFolder sharedFolder) throws Exception; + boolean notifyAddedItem(String userIdToNotify, WorkspaceItem item, WorkspaceSharedFolder sharedFolder) throws Exception; /** * use to notify a user he got a workspace item deleted from one of his workspace shared folder * @param userIdToNotify the user you want to notify * @param removedItem the removed {@link WorkspaceItem} - * @param sharedFolder the shared folder {@link WorkspaceFolder} + * @param sharedFolder the shared folder {@link WorkspaceSharedFolder} * @return true if the notification is correctly delivered, false otherwise */ - boolean notifyMovedItem(String userIdToNotify, WorkspaceItem item, WorkspaceFolder sharedFolder) throws Exception; + boolean notifyMovedItem(String userIdToNotify, WorkspaceItem item, WorkspaceSharedFolder sharedFolder) throws Exception; /** * use to notify a user he got a workspace item deleted from one of his workspace shared folder * @param userIdToNotify the user you want to notify * @param removedItem the removed {@link WorkspaceItem} - * @param sharedFolder the shared folder {@link WorkspaceFolder} + * @param sharedFolder the shared folder {@link WorkspaceSharedFolder} * @return true if the notification is correctly delivered, false otherwise */ - boolean notifyRemovedItem(String userIdToNotify, String item, WorkspaceFolder sharedFolder) throws Exception; + boolean notifyRemovedItem(String userIdToNotify, String item, WorkspaceSharedFolder sharedFolder) throws Exception; /** * use to notify a user he got a workspace item updated from one of his workspace shared folder @@ -89,17 +90,17 @@ public interface NotificationsManager { * @param sharedFolder the shared folder {@link WorkspaceFolder} * @return true if the notification is correctly delivered, false otherwise */ - boolean notifyUpdatedItem(String userIdToNotify, WorkspaceItem item, WorkspaceFolder sharedFolder) throws Exception; + boolean notifyUpdatedItem(String userIdToNotify, WorkspaceItem item, WorkspaceSharedFolder sharedFolder) throws Exception; /** * use to notify a user he got a workspace item renamed * * @param userIdToNotify the user you want to notify * @param previousName the previous name of the folder * @param renamedItem the renamed {@link WorkspaceItem} - * @param rootSharedFolder the root shared {@link WorkspaceFolder} of the {@link WorkspaceItem} + * @param rootSharedFolder the root shared {@link WorkspaceSharedFolder} of the {@link WorkspaceItem} * @return true if the notification is correctly delivered, false otherwise */ - boolean notifyItemRenaming(String userIdToNotify, String previousName, WorkspaceItem renamedItem, WorkspaceFolder rootSharedFolder) throws Exception; + boolean notifyItemRenaming(String userIdToNotify, String previousName, WorkspaceItem renamedItem, WorkspaceSharedFolder rootSharedFolder) throws Exception; /** * * @param userIdToNotify the user you want to notify diff --git a/src/main/java/org/gcube/applicationsupportlayer/social/mailing/EmailPlugin.java b/src/main/java/org/gcube/applicationsupportlayer/social/mailing/EmailPlugin.java index 655372a..7a3d93c 100644 --- a/src/main/java/org/gcube/applicationsupportlayer/social/mailing/EmailPlugin.java +++ b/src/main/java/org/gcube/applicationsupportlayer/social/mailing/EmailPlugin.java @@ -8,10 +8,13 @@ import java.util.Properties; import javax.mail.Address; import javax.mail.Message; +import javax.mail.Multipart; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.InternetAddress; +import javax.mail.internet.MimeBodyPart; import javax.mail.internet.MimeMessage; +import javax.mail.internet.MimeMultipart; import org.gcube.portal.custom.communitymanager.OrganizationsUtil; import org.gcube.portal.databook.shared.Notification; @@ -72,6 +75,36 @@ public class EmailPlugin { return body.toString(); } + + private static String getTextEmail(Notification notification2Save, String userFirstName, String portalURL, String email) { + + String removedMarkup = notification2Save.getDescription().replaceAll("&", "&"); + removedMarkup = removedMarkup.replaceAll(">", ">"); + removedMarkup = removedMarkup.replaceAll("<", "<"); + + String sender = notification2Save.getSenderFullName(); + if (notification2Save.getType() == NotificationType.DOCUMENT_WORKFLOW_STEP_REQUEST_TASK) + sender = ""; + + String portalHost = portalURL.replaceAll("https://", ""); + portalHost = portalHost.replaceAll("http://", ""); + + StringBuilder body = new StringBuilder(); + + body.append("Dear ").append(userFirstName).append(",") //dear + .append("\n").append(sender).append(" ").append(removedMarkup) // has done something + .append("\nsee: ").append(portalURL).append(notification2Save.getUri()) + .append("\n\n\n----\n") + .append("This message was sent to ") + .append(email) + .append(" by ") + .append(portalHost) + .append(" If you don't want to receive these emails in the future, please unsubscribe here: ") + .append(portalURL).append("/group/data-e-infrastructure-gateway/notifications ."); + + return body.toString(); + + } private static String getActionLink(Notification notification2Save, String portalURL) { StringBuilder actionLink = new StringBuilder("