updated 2 notification methods

This commit is contained in:
Massimiliano Assante 2022-05-05 14:10:17 +02:00
parent 67b4e9b81e
commit cf37f90b4d
8 changed files with 132 additions and 117 deletions

14
CHANGELOG.md Normal file
View File

@ -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

26
FUNDING.md Normal file
View File

@ -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);

View File

@ -1,8 +1,8 @@
# gCube System - ASLSocial Library # gCube System - ASL Social
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.
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 ## Structure of the project
@ -15,19 +15,20 @@ The ASL Social Extension is formed by different modules, each of these is delega
## Documentation ## 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 ## Change log
See [Releases](https://code-repo.d4science.org/gCubeSystem/aslsocial/releases). See [Releases](https://code-repo.d4science.org/gCubeSystem/aslsocial/releases).
## Authors ## 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 ## 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 ## 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 Infrastructures enabling the dynamic deployment of Virtual Research Environments
by favouring the realisation of reuse oriented policies. 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 projects leading to this software have received funding from a series of European Union programmes see [FUNDING.md](FUNDING.md)
- 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);

55
pom.xml
View File

@ -11,7 +11,7 @@
<groupId>org.gcube.applicationsupportlayer</groupId> <groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>aslsocial</artifactId> <artifactId>aslsocial</artifactId>
<version>1.7.3</version> <version>1.8.0-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>Social Portal ASL Extension</name> <name>Social Portal ASL Extension</name>
<description> <description>
@ -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. 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.
</description> </description>
<scm> <scm>
<connection>scm:git:https://code-repo.d4science.org/gCubeSystem/aslsocial.git</connection> <connection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</connection>
<developerConnection>scm:git:https://code-repo.d4science.org/gCubeSystem/aslsocial.git</developerConnection> <developerConnection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</developerConnection>
<url>https://code-repo.d4science.org/gCubeSystem/aslsocial</url> <url>https://code-repo.d4science.org/gCubeSystem/${project.artifactId}</url>
</scm> </scm>
<properties> <properties>
<distroDirectory>distro</distroDirectory> <distroDirectory>distro</distroDirectory>
@ -35,7 +35,7 @@
<dependency> <dependency>
<groupId>org.gcube.distribution</groupId> <groupId>org.gcube.distribution</groupId>
<artifactId>maven-portal-bom</artifactId> <artifactId>maven-portal-bom</artifactId>
<version>LATEST</version> <version>3.6.3</version>
<type>pom</type> <type>pom</type>
<scope>import</scope> <scope>import</scope>
</dependency> </dependency>
@ -145,51 +145,6 @@
</resource> </resource>
</resources> </resources>
<plugins> <plugins>
<!-- SA Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>${distroDirectory}/descriptor.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>servicearchive</id>
<phase>install</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>copy-profile</id>
<phase>install</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>target</outputDirectory>
<resources>
<resource>
<directory>${distroDirectory}</directory>
<filtering>true</filtering>
<includes>
<include>profile.xml</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId> <artifactId>maven-javadoc-plugin</artifactId>

View File

@ -322,6 +322,13 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
return saveNotification(not); 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} * {@inheritDoc}
* @throws UserManagementPortalException * @throws UserManagementPortalException
@ -329,8 +336,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
* @throws UserManagementSystemException * @throws UserManagementSystemException
*/ */
@Override @Override
public boolean notifyFolderAddedUser(String userIdToNotify, SocialSharedFolder sharedFolder, String newAddedUserId) throws UserManagementSystemException, UserRetrievalFault, UserManagementPortalException { public boolean notifyFolderAddedUser(String userIdToNotify, SocialSharedFolder sharedFolder, String newAddedUserId, UserManager um) throws UserManagementSystemException, UserRetrievalFault, UserManagementPortalException {
UserManager um = new LiferayUserManager();
GCubeUser user = um.getUserByUsername(newAddedUserId); GCubeUser user = um.getUserByUsername(newAddedUserId);
Notification not = new Notification( Notification not = new Notification(
UUID.randomUUID().toString(), UUID.randomUUID().toString(),
@ -347,6 +353,14 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
return saveNotification(not); return saveNotification(not);
} }
/**
* @Deprecated
*/
@Deprecated
public boolean notifyFolderAddedUsers(String userIdToNotify, SocialSharedFolder sharedFolder, List<String> newAddedUserIds) throws UserManagementSystemException, UserRetrievalFault, UserManagementPortalException {
return notifyFolderAddedUsers(userIdToNotify, sharedFolder, newAddedUserIds, new LiferayUserManager());
}
/** /**
* {@inheritDoc} * {@inheritDoc}
* @throws UserManagementPortalException * @throws UserManagementPortalException
@ -354,12 +368,11 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
* @throws UserManagementSystemException * @throws UserManagementSystemException
*/ */
@Override @Override
public boolean notifyFolderAddedUsers(String userIdToNotify, SocialSharedFolder sharedFolder, List<String> newAddedUserIds) throws UserManagementSystemException, UserRetrievalFault, UserManagementPortalException { public boolean notifyFolderAddedUsers(String userIdToNotify, SocialSharedFolder sharedFolder, List<String> newAddedUserIds, UserManager um) throws UserManagementSystemException, UserRetrievalFault, UserManagementPortalException {
if (newAddedUserIds != null && newAddedUserIds.size() > 0) { if (newAddedUserIds != null && newAddedUserIds.size() > 0) {
if (newAddedUserIds.size() == 1) if (newAddedUserIds.size() == 1)
return notifyFolderAddedUser(userIdToNotify, sharedFolder, newAddedUserIds.get(0)); return notifyFolderAddedUser(userIdToNotify, sharedFolder, newAddedUserIds.get(0), um);
StringBuilder addedUsersFullNames = new StringBuilder(); StringBuilder addedUsersFullNames = new StringBuilder();
UserManager um = new LiferayUserManager();
for (String userId : newAddedUserIds) for (String userId : newAddedUserIds)
addedUsersFullNames.append(um.getUserByUsername(userId).getFullname()).append(" "); addedUsersFullNames.append(um.getUserByUsername(userId).getFullname()).append(" ");

View File

@ -8,6 +8,7 @@ import org.gcube.applicationsupportlayer.social.shared.SocialFileItem;
import org.gcube.applicationsupportlayer.social.shared.SocialSharedFolder; import org.gcube.applicationsupportlayer.social.shared.SocialSharedFolder;
import org.gcube.portal.databook.shared.NotificationType; import org.gcube.portal.databook.shared.NotificationType;
import org.gcube.portal.databook.shared.RunningJob; import org.gcube.portal.databook.shared.RunningJob;
import org.gcube.vomanagement.usermanagement.UserManager;
/** /**
* *
* @author Massimiliano Assante, ISTI-CNR * @author Massimiliano Assante, ISTI-CNR
@ -59,12 +60,7 @@ public interface NotificationsManager {
*/ */
boolean notifyFolderRenaming(String userIdToNotify, String previousName, String newName, String renamedFolderId) throws Exception; 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 * @deprecated user notifyFolderAddedUser passing UserManager class
*
* @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
*/ */
boolean notifyFolderAddedUser(String userIdToNotify, SocialSharedFolder sharedFolder, String newAddedUserId) throws Exception; boolean notifyFolderAddedUser(String userIdToNotify, SocialSharedFolder sharedFolder, String newAddedUserId) throws Exception;
/** /**
@ -72,10 +68,25 @@ public interface NotificationsManager {
* *
* @param userIdToNotify the user you want to notify * @param userIdToNotify the user you want to notify
* @param sharedFolder the shared {@link SocialSharedFolder} instance * @param sharedFolder the shared {@link SocialSharedFolder} instance
* @param newAddedUserIds List of new users that were added * @param newAddedUserId the new user that was added
* @param UserManager UserManager class instance
* @return true if the notification is correctly delivered, false otherwise * @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<String> newAddedUserIds) throws Exception; boolean notifyFolderAddedUsers(String userIdToNotify, SocialSharedFolder sharedFolder, List<String> 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<String> newAddedUserIds, UserManager um) throws Exception;
/** /**
* use to notify a user that an existing user was removed from one of his workspace shared folder * use to notify a user that an existing user was removed from one of his workspace shared folder
* *

View File

@ -102,7 +102,7 @@ public class NotificationMail {
msg2Return.addRecipient(Message.RecipientType.TO, new InternetAddress(email)); msg2Return.addRecipient(Message.RecipientType.TO, new InternetAddress(email));
// retrieve post/comments from its id (if possible) // retrieve post/comments from its id (if possible)
Feed feed = null; Feed post = null;
List<Comment> comments = null; List<Comment> comments = null;
String commentKey = null; String commentKey = null;
String vreNameFromFeed = null; String vreNameFromFeed = null;
@ -113,13 +113,13 @@ public class NotificationMail {
notification2Send.getType() == NotificationType.MENTION) { notification2Send.getType() == NotificationType.MENTION) {
try{ try{
String feedId = notification2Send.getSubjectid(); String feedId = notification2Send.getSubjectid();
feed = store.readFeed(feedId); post = store.readFeed(feedId);
comments = store.getAllCommentByFeed(feedId); comments = store.getAllCommentByFeed(feedId);
Collections.sort(comments); // sort them Collections.sort(comments); // sort them
commentKey = notification2Send.getCommentKey(); commentKey = notification2Send.getCommentKey();
// try to set vreName when notification is created in infrastructure scope // try to set vreName when notification is created in infrastructure scope
String[] splittedVREName = feed.getVreid().split("/"); String[] splittedVREName = post.getVreid().split("/");
if(vreName == null) if(vreName == null)
vreName = splittedVREName[splittedVREName.length - 1]; 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 " _log.debug("VRE Name for the email's subject is going to be "
+ vreNameToUse + "[vreNameFromFeed is " + vreNameFromFeed + ", vreName is " + vreName + "]"); + vreNameToUse + "[vreNameFromFeed is " + vreNameFromFeed + ", vreName is " + vreName + "]");
try{
// set subject // set subject
msg2Return.setSubject(SocialMailingUtil.getSubjectByNotificationType(notification2Send, vreNameToUse, user.getFirstName(), mentionedVReGroups, hashtags)); msg2Return.setSubject(SocialMailingUtil.getSubjectByNotificationType(notification2Send, vreNameToUse, user.getFirstName(), mentionedVReGroups, hashtags));
_log.debug("message subject set");
final MimeBodyPart textPart = new MimeBodyPart(); final MimeBodyPart textPart = new MimeBodyPart();
textPart.setContent(SocialMailingUtil.getTextEmail(notification2Send, user.getFirstName(), portalURL, siteLandingPagePath, email, feed, comments, commentKey, hashtags), "text/plain; charset=UTF-8"); textPart.setContent(SocialMailingUtil.getTextEmail(notification2Send, user.getFirstName(), portalURL, siteLandingPagePath, email, post, comments, commentKey, hashtags), "text/plain; charset=UTF-8");
final MimeBodyPart htmlPart = new MimeBodyPart();
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");
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);
final Multipart mp = new MimeMultipart("alternative"); mp.addBodyPart(htmlPart);
mp.addBodyPart(textPart); _log.debug("message added body parts");
mp.addBodyPart(htmlPart); // Set Multipart as the message's content
// Set Multipart as the message's content msg2Return.setContent(mp);
msg2Return.setContent(mp); _log.debug("message setContent DONE");
msg2Return.setSentDate(new Date());
msg2Return.setSentDate(new Date()); } catch(Exception e){
e.printStackTrace();
}
return msg2Return; return msg2Return;
} }

View File

@ -58,8 +58,10 @@ 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 //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 + "?"; String pathToVRE = siteLandingPagePath + "?";
if (notification2Save.getUri().split("\\?").length > 0) { if (notification2Save.getUri() != null) {
pathToVRE = notification2Save.getUri().split("\\?")[0]; if (notification2Save.getUri().split("\\?").length > 0) {
pathToVRE = notification2Save.getUri().split("\\?")[0];
}
} }
_log.debug("editing hyperlinks for mail client"); _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.replaceAll("href=\"/group/", "href=\""+portalURL + "/group/"); //because there is no indication of the portal (for mentions)
@ -207,7 +209,7 @@ public class SocialMailingUtil {
case MESSAGE: case MESSAGE:
String messageSubject = (optionalParams != null && optionalParams.length > 0) ? String messageSubject = (optionalParams != null && optionalParams.length > 0) ?
optionalParams[0] : notification2Save.getSenderFullName()+" sent you a message"; optionalParams[0] : notification2Save.getSenderFullName()+" sent you a message";
return messageSubject; return messageSubject;
case WP_FOLDER_ADDEDUSER: case WP_FOLDER_ADDEDUSER:
return "New user in a shared folder"; return "New user in a shared folder";
case WP_FOLDER_REMOVEDUSER: case WP_FOLDER_REMOVEDUSER:
@ -408,8 +410,8 @@ public class SocialMailingUtil {
if (notification2Save.getType() == NotificationType.COMMENT || if (notification2Save.getType() == NotificationType.COMMENT ||
notification2Save.getType() == NotificationType.OWN_COMMENT || notification2Save.getType() == NotificationType.OWN_COMMENT ||
notification2Save.getType() == NotificationType.LIKE || notification2Save.getType() == NotificationType.LIKE ||
notification2Save.getType() == NotificationType.MENTION){ notification2Save.getType() == NotificationType.MENTION){
String htmlPost = "<br />" + "<br />----<p>Original post:</p>"; String htmlPost = "<br />" + "<br />----<p>Original post:</p>";
// data formatter // data formatter
@ -497,8 +499,8 @@ public class SocialMailingUtil {
if (notification2Save.getType() == NotificationType.COMMENT || if (notification2Save.getType() == NotificationType.COMMENT ||
notification2Save.getType() == NotificationType.OWN_COMMENT || notification2Save.getType() == NotificationType.OWN_COMMENT ||
notification2Save.getType() == NotificationType.LIKE || notification2Save.getType() == NotificationType.LIKE ||
notification2Save.getType() == NotificationType.MENTION){ notification2Save.getType() == NotificationType.MENTION){
// build discussion // build discussion
String discussion = "\n\n----\n\nOriginal post:"; String discussion = "\n\n----\n\nOriginal post:";
@ -564,7 +566,7 @@ public class SocialMailingUtil {
return "profile?"+ new String( return "profile?"+ new String(
Base64.getEncoder().encodeToString(GCubePortalConstants.USER_PROFILE_OID.getBytes())+ Base64.getEncoder().encodeToString(GCubePortalConstants.USER_PROFILE_OID.getBytes())+
"="+ "="+
new String( Base64.getEncoder().encodeToString(username.getBytes()) ) new String( Base64.getEncoder().encodeToString(username.getBytes()) )
); );
} }
} }