Compare commits

...

5 Commits

10 changed files with 221 additions and 157 deletions

17
CHANGELOG.md Normal file
View File

@ -0,0 +1,17 @@
# 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.1] - 2023-05-14
- Bug 27457: get application profile multiple times before settling on sitelandingpath
## [v1.8.0] - 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
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);
The projects leading to this software have received funding from a series of European Union programmes see [FUNDING.md](FUNDING.md)

55
pom.xml
View File

@ -11,7 +11,7 @@
<groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>aslsocial</artifactId>
<version>1.7.3</version>
<version>1.8.1</version>
<packaging>jar</packaging>
<name>Social Portal ASL Extension</name>
<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.
</description>
<scm>
<connection>scm:git:https://code-repo.d4science.org/gCubeSystem/aslsocial.git</connection>
<developerConnection>scm:git:https://code-repo.d4science.org/gCubeSystem/aslsocial.git</developerConnection>
<url>https://code-repo.d4science.org/gCubeSystem/aslsocial</url>
<connection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</connection>
<developerConnection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</developerConnection>
<url>https://code-repo.d4science.org/gCubeSystem/${project.artifactId}</url>
</scm>
<properties>
<distroDirectory>distro</distroDirectory>
@ -35,7 +35,7 @@
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>maven-portal-bom</artifactId>
<version>LATEST</version>
<version>3.6.3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
@ -145,51 +145,6 @@
</resource>
</resources>
<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>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>

View File

@ -1,11 +1,13 @@
package org.gcube.applicationsupportlayer.social;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import org.gcube.applicationsupportlayer.social.ex.UnsupportedNotificationException;
import org.gcube.applicationsupportlayer.social.mailing.EmailPlugin;
import org.gcube.applicationsupportlayer.social.shared.SocialFileItem;
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingSite;
@ -40,6 +42,8 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
public static final String USER_MESSAGES_FRIENDLY_URL = "/messages";
public static final String USER_NOTIFICATION_FRIENDLY_URL = "/notifications";
private final int MAX_TRIAL = 10;
private String portalName;
private String senderEmail;
private String portalURL;
@ -202,14 +206,18 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
* @return .
*/
private String getApplicationUrl() {
if (applicationProfile != null && applicationProfile.getUrl() != null) {
_log.trace("getApplicationUrl="+applicationProfile.getUrl());
return applicationProfile.getUrl();
}
else {
_log.warn("applicationProfile NULL or url is empty returning " + siteLandingPagePath);
return siteLandingPagePath;
int count = 0;
while (count < MAX_TRIAL){
if (applicationProfile != null && applicationProfile.getUrl() != null) {
_log.trace("getApplicationUrl="+applicationProfile.getUrl());
return applicationProfile.getUrl();
}
if (applicationProfile != null && applicationProfile.getKey() != null)
applicationProfile = getProfileFromInfrastrucure(applicationProfile.getKey());
count++;
}
_log.warn("applicationProfile NULL or url is empty returning " + siteLandingPagePath);
return siteLandingPagePath;
}
/**
* {@inheritDoc}
@ -322,6 +330,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 +344,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 +361,14 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
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}
* @throws UserManagementPortalException
@ -354,12 +376,11 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
* @throws UserManagementSystemException
*/
@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.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(" ");
@ -816,7 +837,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
/**
* {@inheritDoc}
*/
@Override
@Deprecated
public boolean notifyNewCalendarEvent(String userIdToNotify, String eventTitle, String eventType, Date startDate, Date endingDate) {
SimpleDateFormat spf = new SimpleDateFormat("EEE dd MMMMM, yyyy");
@ -850,7 +871,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
/**
* {@inheritDoc}
*/
@Override
@Deprecated
public boolean notifyEditedCalendarEvent(String userIdToNotify, String eventTitle, String eventType, Date startDate, Date endingDate) {
SimpleDateFormat spf = new SimpleDateFormat("EEE dd MMMMM, yyyy");
@ -883,7 +904,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
/**
* {@inheritDoc}
*/
@Override
@Deprecated
public boolean notifyDeletedCalendarEvent(String userIdToNotify, String eventTitle, String eventType, Date startDate, Date endingDate) {
SimpleDateFormat spf = new SimpleDateFormat("EEE dd MMMMM, yyyy");
@ -916,7 +937,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
/**
* {@inheritDoc}
*/
@Override
@Deprecated
public boolean notifyTDMTabularResourceSharing(String userIdToNotify, String tabularResourceName, String encodedTabularResourceParams) throws Exception {
Notification not = new Notification(
UUID.randomUUID().toString(),
@ -936,7 +957,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
/**
* {@inheritDoc}
*/
@Override
@Deprecated
public boolean notifyTDMObjectSharing(String userIdToNotify, NotificationType type, String tdmObjectName, String encodedTabularResourceParams) throws Exception {
if (! (type == NotificationType.TDM_RULE_SHARE || type == NotificationType.TDM_TEMPLATE_SHARE))
throw new IllegalArgumentException("Type must be either TDM_RULE_SHARE or TDM_TEMPLATE_SHARE");
@ -964,4 +985,27 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
return saveNotification(not);
}
@Override
public boolean notifyCatalogueEvent(NotificationType type, String userIdToNotify, String itemId, String notifyText, URL url) throws Exception {
final String prefix = "CAT_";
if (! type.toString().startsWith(prefix)) {
throw new UnsupportedNotificationException("The type of notification is not belonging to the catalogue ones, must start with " + prefix);
}
Notification not = new Notification(
UUID.randomUUID().toString(),
type,
userIdToNotify, //user no notify
itemId, //the
new Date(),
url.toString(),
notifyText,
false,
currUser.getUsername(),
currUser.getFullname(),
currUser.getUserAvatarId());
return saveNotification(not);
}
}

View File

@ -1,5 +1,6 @@
package org.gcube.applicationsupportlayer.social;
import java.net.URL;
import java.util.Date;
import java.util.List;
import java.util.Set;
@ -8,6 +9,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 +61,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<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
*
@ -137,33 +149,26 @@ public interface NotificationsManager {
*/
boolean notifyMessageReceived(String userIdToNotify, String messageUniqueIdentifier, String subject, String messageText, String ... otherRecipientsFullNames);
/**
*
* use to notify a catalogue moderators someone submitted an item for consideration
* @param type the notification type
* @param userIdToNotify the user you want to notify
* @param eventTitle the title of the event
* @param eventType the type of the event
* @param startDate staring date
* @param endingDate ending date
* @param itemId the item unique identifier
* @param notifyText the text of the notification
* @param the resolver URL pointing to the item
* @return true if the notification is correctly delivered, false otherwise
*/
boolean notifyCatalogueEvent(NotificationType type, String userIdToNotify, String itemId, String notifyText, URL url) throws Exception;
/**
* @deprecated no longer supported
*/
boolean notifyNewCalendarEvent(String userIdToNotify, String eventTitle, String eventType, Date startDate, Date endingDate);
/**
*
* @param userIdToNotify the user you want to notify
* @param eventTitle the title of the event
* @param eventType the type of the event
* @param startDate staring date
* @param endingDate ending date
* @return true if the notification is correctly delivered, false otherwise
* @deprecated no longer supported
*/
boolean notifyEditedCalendarEvent(String userIdToNotify, String eventTitle, String eventType, Date startDate, Date endingDate);
/**
*
* @param userIdToNotify the user you want to notify
* @param eventTitle the title of the event
* @param eventType the type of the event
* @param startDate staring date
* @param endingDate ending date
* @return true if the notification is correctly delivered, false otherwise
* @deprecated no longer supported
*/
boolean notifyDeletedCalendarEvent(String userIdToNotify, String eventTitle, String eventType, Date startDate, Date endingDate);
@ -269,16 +274,12 @@ public interface NotificationsManager {
* @return true if the notification is correctly delivered, false otherwise
*/
boolean notifyJobStatus(String userIdToNotify, RunningJob job);
/**
* @deprecated no longer supported
*/
boolean notifyTDMTabularResourceSharing(String userIdToNotify, String tabularResourceName, String encodedTabularResourceParams) throws Exception;
/**
* use to notify a user he got a Tabular Data Resource shared
*
* @param userIdToNotify the user you want to notify
* @param type type of the shared tdm object (TDM Rule or TDM Template at the moment)
* @param tdmObjectName the name
* @param encodedTabularResourceParams the parameters to be placed in the HTTP GET Request (must be encoded)
* @return true if the notification is correctly delivered, false otherwise
* @deprecated no longer supported
*/
boolean notifyTDMObjectSharing(String userIdToNotify, NotificationType type, String tdmObjectName, String encodedTabularResourceParams) throws Exception;

View File

@ -39,6 +39,8 @@ public class SocialPortalBridge {
protected ApplicationProfile applicationProfile;
//unique instance
private static DatabookStore store;
private String portletClassName;
/**
*
* @param scope the current scope
@ -60,6 +62,7 @@ public class SocialPortalBridge {
public SocialPortalBridge(String scope, SocialNetworkingUser currUser, String portletClassName) {
this(scope, currUser);
this.applicationProfile = getProfileFromInfrastrucure(portletClassName);
this.portletClassName = portletClassName;
_log.debug("ASLSocial called on " + portletClassName);
}
@ -98,7 +101,7 @@ public class SocialPortalBridge {
* @param portletClassName your servlet class name will be used ad unique identifier for your applicationProfile
* @return the applicationProfile profile
*/
private ApplicationProfile getProfileFromInfrastrucure(String portletClassName) {
protected ApplicationProfile getProfileFromInfrastrucure(String portletClassName) {
ScopeBean scope = new ScopeBean(currScope);
_log.debug("Trying to fetch applicationProfile profile from the infrastructure for " + portletClassName + " scope: " + scope);
try {

View File

@ -0,0 +1,8 @@
package org.gcube.applicationsupportlayer.social.ex;
@SuppressWarnings("serial")
public class UnsupportedNotificationException extends Exception {
public UnsupportedNotificationException(String message) {
super(message);
}
}

View File

@ -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<Comment> 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;
}

View File

@ -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("<div>").append(WRITE_ABOVE_MESSAGE_REPLY).append("</div><br />");
attachmentsNotice = "<br/><p>Please note that email replies do not support attachments.</p>";
}
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:
@ -247,6 +249,12 @@ public class SocialMailingUtil {
toReturn += " " + hashtag;
}
return toReturn;
case CAT_ITEM_DELETE:
case CAT_ITEM_PUBLISHED:
case CAT_ITEM_REJECTED:
case CAT_ITEM_SUBMITTED:
case CAT_ITEM_UPDATED:
return "[D4Science Catalogue] " + notification2Save.getSubjectid();
case REQUEST_CONNECTION:
return "Connection request";
case JOB_COMPLETED_NOK:
@ -304,6 +312,14 @@ public class SocialMailingUtil {
case POST_ALERT:
actionLink.append("\">").append("See this Post").append("</a>");
break;
case CAT_ITEM_DELETE:
case CAT_ITEM_PUBLISHED:
case CAT_ITEM_REJECTED:
case CAT_ITEM_SUBMITTED:
case CAT_ITEM_UPDATED:
StringBuilder myLink = new StringBuilder("<br/><br/><a style=\"color:#3B5998; text-decoration:none\" target=\"_blank\" href=\"");
myLink.append(notification2Save.getUri()).append("\">").append(" See this on Catalogue").append("</a>");
return myLink.toString();
case REQUEST_CONNECTION:
actionLink.append("\">").append(" Go to Contacts Center").append("</a>");
break;
@ -371,7 +387,7 @@ public class SocialMailingUtil {
buffer.append(" ");
}
}
if (node instanceof TextNode) {
TextNode textNode = (TextNode) node;
buffer.append(textNode.text().trim());
@ -408,8 +424,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 = "<br />" + "<br />----<p>Original post:</p>";
// data formatter
@ -419,8 +435,8 @@ public class SocialMailingUtil {
String postTextNoHtml = post.getDescription().replaceAll("&amp;", "&");
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 += "<div style=\"margin-top: 10px; margin-bottom: 10px;padding-left: 15px; "
@ -445,7 +461,7 @@ public class SocialMailingUtil {
if(comments != null)
for (int i = 0; i < comments.size(); i++) {
String commentTextNoHtml = comments.get(i).getText().replaceAll("&amp;", "&");
commentTextNoHtml = commentTextNoHtml.replaceAll("href=\"/group/", "href=\""+portalURL + "/group/"); //because there is no indication of the portal (for mentions)
commentTextNoHtml = commentTextNoHtml.replace("href=\"?", "href=\""+portalURL + pathToVRE + "?"); //because there is no indication of the portal (for hashtags)
@ -497,8 +513,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){
// build discussion
String discussion = "\n\n----\n\nOriginal post:";
@ -564,7 +580,7 @@ public class SocialMailingUtil {
return "profile?"+ new String(
Base64.getEncoder().encodeToString(GCubePortalConstants.USER_PROFILE_OID.getBytes())+
"="+
new String( Base64.getEncoder().encodeToString(username.getBytes()) )
);
new String( Base64.getEncoder().encodeToString(username.getBytes()) )
);
}
}