From cf37f90b4d31df6d2f86b9d964ce3145dd004b38 Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Thu, 5 May 2022 14:10:17 +0200 Subject: [PATCH] updated 2 notification methods --- CHANGELOG.md | 14 +++++ FUNDING.md | 26 +++++++++ README.md | 25 +++------ pom.xml | 55 ++----------------- .../ApplicationNotificationsManager.java | 23 ++++++-- .../social/NotificationsManager.java | 27 ++++++--- .../social/mailing/NotificationMail.java | 45 +++++++-------- .../social/mailing/SocialMailingUtil.java | 34 ++++++------ 8 files changed, 132 insertions(+), 117 deletions(-) create mode 100644 CHANGELOG.md create mode 100644 FUNDING.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..f74e094 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,14 @@ + +# Changelog for ASL Social + +All notable changes to this project will be documented in this file. +This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + + +## [v1.8.0-SNAPSHOT] - 2022-05-05 + + - fixed some notification methods + +## [v1.0.0] - 2016-06-01 + + - First release diff --git a/FUNDING.md b/FUNDING.md new file mode 100644 index 0000000..6fa9eac --- /dev/null +++ b/FUNDING.md @@ -0,0 +1,26 @@ +# Acknowledgments + +The projects leading to this software have received funding from a series of European Union programmes including: + +- the Sixth Framework Programme for Research and Technological Development + - [DILIGENT](https://cordis.europa.eu/project/id/004260) (grant no. 004260). +- the Seventh Framework Programme for research, technological development and demonstration + - [D4Science](https://cordis.europa.eu/project/id/212488) (grant no. 212488); + - [D4Science-II](https://cordis.europa.eu/project/id/239019) (grant no.239019); + - [ENVRI](https://cordis.europa.eu/project/id/283465) (grant no. 283465); + - [iMarine](https://cordis.europa.eu/project/id/283644) (grant no. 283644); + - [EUBrazilOpenBio](https://cordis.europa.eu/project/id/288754) (grant no. 288754). +- the H2020 research and innovation programme + - [SoBigData](https://cordis.europa.eu/project/id/654024) (grant no. 654024); + - [PARTHENOS](https://cordis.europa.eu/project/id/654119) (grant no. 654119); + - [EGI-Engage](https://cordis.europa.eu/project/id/654142) (grant no. 654142); + - [ENVRI PLUS](https://cordis.europa.eu/project/id/654182) (grant no. 654182); + - [BlueBRIDGE](https://cordis.europa.eu/project/id/675680) (grant no. 675680); + - [PerformFISH](https://cordis.europa.eu/project/id/727610) (grant no. 727610); + - [AGINFRA PLUS](https://cordis.europa.eu/project/id/731001) (grant no. 731001); + - [DESIRA](https://cordis.europa.eu/project/id/818194) (grant no. 818194); + - [ARIADNEplus](https://cordis.europa.eu/project/id/823914) (grant no. 823914); + - [RISIS 2](https://cordis.europa.eu/project/id/824091) (grant no. 824091); + - [EOSC-Pillar](https://cordis.europa.eu/project/id/857650) (grant no. 857650); + - [Blue Cloud](https://cordis.europa.eu/project/id/862409) (grant no. 862409); + - [SoBigData-PlusPlus](https://cordis.europa.eu/project/id/871042) (grant no. 871042); \ No newline at end of file diff --git a/README.md b/README.md index 15b16cd..48b0a00 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -# gCube System - ASLSocial Library - -Social Portal ASL Extension is an abstraction over the Social Networking Library to be used from within you gCube Portlets. -The ASL Social Extension is formed by different modules, each of these is delegated to one specific task. Every module inherits from a super class called SocialPortalBridge. +# gCube System - ASL Social +The ASL Social Extension is formed by different modules, each of these is delegated to one specific task. Every module inherits from a super class called SocialPortalBridge. Currently there are two modules available: +Application News Manager: to be used by gCube Applications when they need to post news on their user news feeds; +User Notifications Manager: to be used by gCube Applications when they need to notify their users about some events. ## Structure of the project @@ -15,19 +15,20 @@ The ASL Social Extension is formed by different modules, each of these is delega ## Documentation -* Use of this service is described in the [Wiki](https://gcube.wiki.gcube-system.org/gcube/Social_Networking_Library#ASL_Social_Extension). +* Use of this service is described in the [Wiki](https://wiki.gcube-system.org/gcube/Social_Networking_Library#ASL_Social_Extension). ## Change log See [Releases](https://code-repo.d4science.org/gCubeSystem/aslsocial/releases). + ## Authors -* **Massimiliano Assante** - [ISTI-CNR Infrascience Group](http://nemis.isti.cnr.it/groups/infrascience) +* **Massimiliano Assante** ([ORCID](https://orcid.org/0000-0002-3761-1492)) - [ISTI-CNR Infrascience Group](https://www.isti.cnr.it/People/M.Assante) ## Maintainers -* **Massimiliano Assante** - [ISTI-CNR Infrascience Group](http://nemis.isti.cnr.it/groups/infrascience) +* **Massimiliano Assante** ([ORCID](https://orcid.org/0000-0002-3761-1492)) - [ISTI-CNR Infrascience Group](https://www.isti.cnr.it/People/M.Assante) ## License @@ -40,12 +41,4 @@ open-source software toolkit used for building and operating Hybrid Data Infrastructures enabling the dynamic deployment of Virtual Research Environments by favouring the realisation of reuse oriented policies. -The projects leading to this software have received funding from a series of European Union programmes including: - -- the Sixth Framework Programme for Research and Technological Development - - DILIGENT (grant no. 004260); -- the Seventh Framework Programme for research, technological development and demonstration - - D4Science (grant no. 212488), D4Science-II (grant no.239019), ENVRI (grant no. 283465), EUBrazilOpenBio (grant no. 288754), iMarine(grant no. 283644); -- the H2020 research and innovation programme - - BlueBRIDGE (grant no. 675680), EGIEngage (grant no. 654142), ENVRIplus (grant no. 654182), Parthenos (grant no. 654119), SoBigData (grant no. 654024),DESIRA (grant no. 818194), ARIADNEplus (grant no. 823914), RISIS2 (grant no. 824091), PerformFish (grant no. 727610), AGINFRAplus (grant no. 731001); - \ No newline at end of file +The projects leading to this software have received funding from a series of European Union programmes see [FUNDING.md](FUNDING.md) \ No newline at end of file diff --git a/pom.xml b/pom.xml index 48f0262..3fb8065 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ org.gcube.applicationsupportlayer aslsocial - 1.7.3 + 1.8.0-SNAPSHOT jar Social Portal ASL Extension @@ -19,9 +19,9 @@ The ASL Social Extension is formed by different modules, each of these is delegated to one specific task. Every module inherits from a super class called SocialPortalBridge. - scm:git:https://code-repo.d4science.org/gCubeSystem/aslsocial.git - scm:git:https://code-repo.d4science.org/gCubeSystem/aslsocial.git - https://code-repo.d4science.org/gCubeSystem/aslsocial + scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git + scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git + https://code-repo.d4science.org/gCubeSystem/${project.artifactId} distro @@ -35,7 +35,7 @@ org.gcube.distribution maven-portal-bom - LATEST + 3.6.3 pom import @@ -145,51 +145,6 @@ - - - org.apache.maven.plugins - maven-assembly-plugin - - - ${distroDirectory}/descriptor.xml - - - - - servicearchive - install - - single - - - - - - org.apache.maven.plugins - maven-resources-plugin - 2.5 - - - copy-profile - install - - copy-resources - - - target - - - ${distroDirectory} - true - - profile.xml - - - - - - - org.apache.maven.plugins maven-javadoc-plugin diff --git a/src/main/java/org/gcube/applicationsupportlayer/social/ApplicationNotificationsManager.java b/src/main/java/org/gcube/applicationsupportlayer/social/ApplicationNotificationsManager.java index 50acb7c..db11bd2 100644 --- a/src/main/java/org/gcube/applicationsupportlayer/social/ApplicationNotificationsManager.java +++ b/src/main/java/org/gcube/applicationsupportlayer/social/ApplicationNotificationsManager.java @@ -322,6 +322,13 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen return saveNotification(not); } + /** + * @Deprecated + */ + @Deprecated + public boolean notifyFolderAddedUser(String userIdToNotify, SocialSharedFolder sharedFolder, String newAddedUserId) throws UserManagementSystemException, UserRetrievalFault, UserManagementPortalException { + return notifyFolderAddedUser(userIdToNotify, sharedFolder, newAddedUserId, new LiferayUserManager()); + } /** * {@inheritDoc} * @throws UserManagementPortalException @@ -329,8 +336,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen * @throws UserManagementSystemException */ @Override - public boolean notifyFolderAddedUser(String userIdToNotify, SocialSharedFolder sharedFolder, String newAddedUserId) throws UserManagementSystemException, UserRetrievalFault, UserManagementPortalException { - UserManager um = new LiferayUserManager(); + public boolean notifyFolderAddedUser(String userIdToNotify, SocialSharedFolder sharedFolder, String newAddedUserId, UserManager um) throws UserManagementSystemException, UserRetrievalFault, UserManagementPortalException { GCubeUser user = um.getUserByUsername(newAddedUserId); Notification not = new Notification( UUID.randomUUID().toString(), @@ -347,6 +353,14 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen return saveNotification(not); } + /** + * @Deprecated + */ + @Deprecated + public boolean notifyFolderAddedUsers(String userIdToNotify, SocialSharedFolder sharedFolder, List newAddedUserIds) throws UserManagementSystemException, UserRetrievalFault, UserManagementPortalException { + return notifyFolderAddedUsers(userIdToNotify, sharedFolder, newAddedUserIds, new LiferayUserManager()); + } + /** * {@inheritDoc} * @throws UserManagementPortalException @@ -354,12 +368,11 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen * @throws UserManagementSystemException */ @Override - public boolean notifyFolderAddedUsers(String userIdToNotify, SocialSharedFolder sharedFolder, List newAddedUserIds) throws UserManagementSystemException, UserRetrievalFault, UserManagementPortalException { + public boolean notifyFolderAddedUsers(String userIdToNotify, SocialSharedFolder sharedFolder, List newAddedUserIds, UserManager um) throws UserManagementSystemException, UserRetrievalFault, UserManagementPortalException { if (newAddedUserIds != null && newAddedUserIds.size() > 0) { if (newAddedUserIds.size() == 1) - return notifyFolderAddedUser(userIdToNotify, sharedFolder, newAddedUserIds.get(0)); + return notifyFolderAddedUser(userIdToNotify, sharedFolder, newAddedUserIds.get(0), um); StringBuilder addedUsersFullNames = new StringBuilder(); - UserManager um = new LiferayUserManager(); for (String userId : newAddedUserIds) addedUsersFullNames.append(um.getUserByUsername(userId).getFullname()).append(" "); diff --git a/src/main/java/org/gcube/applicationsupportlayer/social/NotificationsManager.java b/src/main/java/org/gcube/applicationsupportlayer/social/NotificationsManager.java index 489061e..026c553 100644 --- a/src/main/java/org/gcube/applicationsupportlayer/social/NotificationsManager.java +++ b/src/main/java/org/gcube/applicationsupportlayer/social/NotificationsManager.java @@ -8,6 +8,7 @@ import org.gcube.applicationsupportlayer.social.shared.SocialFileItem; import org.gcube.applicationsupportlayer.social.shared.SocialSharedFolder; import org.gcube.portal.databook.shared.NotificationType; import org.gcube.portal.databook.shared.RunningJob; +import org.gcube.vomanagement.usermanagement.UserManager; /** * * @author Massimiliano Assante, ISTI-CNR @@ -59,23 +60,33 @@ public interface NotificationsManager { */ boolean notifyFolderRenaming(String userIdToNotify, String previousName, String newName, String renamedFolderId) 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 SocialSharedFolder} instance - * @param newAddedUserId the new user that was added - * @return true if the notification is correctly delivered, false otherwise + * @deprecated user notifyFolderAddedUser passing UserManager class */ boolean notifyFolderAddedUser(String userIdToNotify, SocialSharedFolder 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 SocialSharedFolder} instance - * @param newAddedUserIds List of new users that were added + * @param sharedFolder the shared {@link SocialSharedFolder} instance + * @param newAddedUserId the new user that was added + * @param UserManager UserManager class instance * @return true if the notification is correctly delivered, false otherwise */ + boolean notifyFolderAddedUser(String userIdToNotify, SocialSharedFolder sharedFolder, String newAddedUserId, UserManager um) throws Exception; + /** + * @deprecated user notifyFolderAddedUser passing UserManager class + */ boolean notifyFolderAddedUsers(String userIdToNotify, SocialSharedFolder sharedFolder, List newAddedUserIds) 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 SocialSharedFolder} instance + * @param newAddedUserIds List of new users that were added + * @param UserManager UserManager class instance + * @return true if the notification is correctly delivered, false otherwise + */ + boolean notifyFolderAddedUsers(String userIdToNotify, SocialSharedFolder sharedFolder, List newAddedUserIds, UserManager um) throws Exception; /** * use to notify a user that an existing user was removed from one of his workspace shared folder * diff --git a/src/main/java/org/gcube/applicationsupportlayer/social/mailing/NotificationMail.java b/src/main/java/org/gcube/applicationsupportlayer/social/mailing/NotificationMail.java index 7dfae58..7d18183 100644 --- a/src/main/java/org/gcube/applicationsupportlayer/social/mailing/NotificationMail.java +++ b/src/main/java/org/gcube/applicationsupportlayer/social/mailing/NotificationMail.java @@ -68,7 +68,7 @@ public class NotificationMail { String email = user.getEmail(); Message msg2Return = new MimeMessage(session); - + if (notification2Send.getType() == NotificationType.POST_ALERT || notification2Send.getType() == NotificationType.COMMENT || notification2Send.getType() == NotificationType.MENTION || @@ -102,7 +102,7 @@ public class NotificationMail { msg2Return.addRecipient(Message.RecipientType.TO, new InternetAddress(email)); // retrieve post/comments from its id (if possible) - Feed feed = null; + Feed post = null; List comments = null; String commentKey = null; String vreNameFromFeed = null; @@ -113,13 +113,13 @@ public class NotificationMail { notification2Send.getType() == NotificationType.MENTION) { try{ String feedId = notification2Send.getSubjectid(); - feed = store.readFeed(feedId); + post = store.readFeed(feedId); comments = store.getAllCommentByFeed(feedId); Collections.sort(comments); // sort them commentKey = notification2Send.getCommentKey(); // try to set vreName when notification is created in infrastructure scope - String[] splittedVREName = feed.getVreid().split("/"); + String[] splittedVREName = post.getVreid().split("/"); if(vreName == null) vreName = splittedVREName[splittedVREName.length - 1]; @@ -140,24 +140,25 @@ public class NotificationMail { _log.debug("VRE Name for the email's subject is going to be " + vreNameToUse + "[vreNameFromFeed is " + vreNameFromFeed + ", vreName is " + vreName + "]"); - - // set subject - msg2Return.setSubject(SocialMailingUtil.getSubjectByNotificationType(notification2Send, vreNameToUse, user.getFirstName(), mentionedVReGroups, hashtags)); - - final MimeBodyPart textPart = new MimeBodyPart(); - textPart.setContent(SocialMailingUtil.getTextEmail(notification2Send, user.getFirstName(), portalURL, siteLandingPagePath, email, feed, comments, commentKey, hashtags), "text/plain; charset=UTF-8"); - - final MimeBodyPart htmlPart = new MimeBodyPart(); - htmlPart.setContent(SocialMailingUtil.getHTMLEmail(vreNameToUse, notification2Send, user.getFirstName(), portalURL, siteLandingPagePath, email, feed, comments, commentKey, hashtags), "text/html; charset=UTF-8"); - - final Multipart mp = new MimeMultipart("alternative"); - mp.addBodyPart(textPart); - mp.addBodyPart(htmlPart); - // Set Multipart as the message's content - msg2Return.setContent(mp); - - msg2Return.setSentDate(new Date()); - + try{ + // set subject + msg2Return.setSubject(SocialMailingUtil.getSubjectByNotificationType(notification2Send, vreNameToUse, user.getFirstName(), mentionedVReGroups, hashtags)); + _log.debug("message subject set"); + final MimeBodyPart textPart = new MimeBodyPart(); + textPart.setContent(SocialMailingUtil.getTextEmail(notification2Send, user.getFirstName(), portalURL, siteLandingPagePath, email, post, comments, commentKey, hashtags), "text/plain; charset=UTF-8"); + final MimeBodyPart htmlPart = new MimeBodyPart(); + htmlPart.setContent(SocialMailingUtil.getHTMLEmail(vreNameToUse, notification2Send, user.getFirstName(), portalURL, siteLandingPagePath, email, post, comments, commentKey, hashtags), "text/html; charset=UTF-8"); + final Multipart mp = new MimeMultipart("alternative"); + mp.addBodyPart(textPart); + mp.addBodyPart(htmlPart); + _log.debug("message added body parts"); + // Set Multipart as the message's content + msg2Return.setContent(mp); + _log.debug("message setContent DONE"); + msg2Return.setSentDate(new Date()); + } catch(Exception e){ + e.printStackTrace(); + } return msg2Return; } diff --git a/src/main/java/org/gcube/applicationsupportlayer/social/mailing/SocialMailingUtil.java b/src/main/java/org/gcube/applicationsupportlayer/social/mailing/SocialMailingUtil.java index e1e7878..8c902dd 100644 --- a/src/main/java/org/gcube/applicationsupportlayer/social/mailing/SocialMailingUtil.java +++ b/src/main/java/org/gcube/applicationsupportlayer/social/mailing/SocialMailingUtil.java @@ -58,13 +58,15 @@ public class SocialMailingUtil { //notification2Save uri contains the absoulte path to the feed in the correct channel, e.g. /group/ustore_vre?oid=f1637958-34d0-48fc-b5ad-13b1116e389d String pathToVRE = siteLandingPagePath + "?"; - if (notification2Save.getUri().split("\\?").length > 0) { - pathToVRE = notification2Save.getUri().split("\\?")[0]; - } + if (notification2Save.getUri() != null) { + if (notification2Save.getUri().split("\\?").length > 0) { + pathToVRE = notification2Save.getUri().split("\\?")[0]; + } + } _log.debug("editing hyperlinks for mail client"); removedMarkup = removedMarkup.replaceAll("href=\"/group/", "href=\""+portalURL + "/group/"); //because there is no indication of the portal (for mentions) removedMarkup = removedMarkup.replace("href=\"?", "href=\""+portalURL + pathToVRE + "?"); //because there is no indication of the portal (for hashtags) - + String sender = notification2Save.getSenderFullName(); String portalHost = portalURL.replaceAll("https://", ""); portalHost = portalHost.replaceAll("http://", ""); @@ -86,7 +88,7 @@ public class SocialMailingUtil { body.append("
").append(WRITE_ABOVE_MESSAGE_REPLY).append("

"); attachmentsNotice = "

Please note that email replies do not support attachments.

"; } - + String userProfileLink = new StringBuffer(getVREUrl(portalURL, vreName)) .append("/").append(getUserProfileLink(notification2Save.getSenderid())).toString(); @@ -207,7 +209,7 @@ public class SocialMailingUtil { case MESSAGE: String messageSubject = (optionalParams != null && optionalParams.length > 0) ? optionalParams[0] : notification2Save.getSenderFullName()+" sent you a message"; - return messageSubject; + return messageSubject; case WP_FOLDER_ADDEDUSER: return "New user in a shared folder"; case WP_FOLDER_REMOVEDUSER: @@ -371,7 +373,7 @@ public class SocialMailingUtil { buffer.append(" "); } } - + if (node instanceof TextNode) { TextNode textNode = (TextNode) node; buffer.append(textNode.text().trim()); @@ -408,8 +410,8 @@ public class SocialMailingUtil { if (notification2Save.getType() == NotificationType.COMMENT || notification2Save.getType() == NotificationType.OWN_COMMENT || - notification2Save.getType() == NotificationType.LIKE || - notification2Save.getType() == NotificationType.MENTION){ + notification2Save.getType() == NotificationType.LIKE || + notification2Save.getType() == NotificationType.MENTION){ String htmlPost = "
" + "
----

Original post:

"; // data formatter @@ -419,8 +421,8 @@ public class SocialMailingUtil { String postTextNoHtml = post.getDescription().replaceAll("&", "&"); postTextNoHtml = postTextNoHtml.replaceAll("href=\"/group/", "href=\""+portalURL + "/group/"); //because there is no indication of the portal (for mentions) postTextNoHtml = postTextNoHtml.replace("href=\"?", "href=\""+portalURL + pathToVRE + "?"); //because there is no indication of the portal (for hashtags) - - + + // build up html post + comments if(notification2Save.getType() == NotificationType.POST_ALERT || (comments.size() == 0 && notification2Save.getType() == NotificationType.MENTION)) htmlPost += "