2012-12-07 15:06:26 +01:00
package org.gcube.applicationsupportlayer.social ;
2013-07-11 17:25:21 +02:00
import java.text.SimpleDateFormat ;
2013-01-09 17:47:22 +01:00
import java.util.Date ;
2013-01-30 18:41:39 +01:00
import java.util.List ;
2017-01-20 14:45:53 +01:00
import java.util.Set ;
2013-01-09 17:47:22 +01:00
import java.util.UUID ;
2013-01-31 01:31:07 +01:00
import org.gcube.applicationsupportlayer.social.mailing.EmailPlugin ;
2016-05-19 00:13:50 +02:00
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingSite ;
2016-02-25 18:57:25 +01:00
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingUser ;
2014-05-15 19:28:05 +02:00
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException ;
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem ;
import org.gcube.common.homelibrary.home.workspace.WorkspaceSharedFolder ;
2013-01-09 17:47:22 +01:00
import org.gcube.portal.databook.shared.Notification ;
2013-01-30 18:41:39 +01:00
import org.gcube.portal.databook.shared.NotificationChannelType ;
2013-01-09 17:47:22 +01:00
import org.gcube.portal.databook.shared.NotificationType ;
2013-01-03 16:28:36 +01:00
import org.gcube.portal.databook.shared.RunningJob ;
2013-01-11 12:36:44 +01:00
import org.gcube.vomanagement.usermanagement.UserManager ;
import org.gcube.vomanagement.usermanagement.exception.UserManagementPortalException ;
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException ;
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault ;
2016-04-13 18:10:22 +02:00
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager ;
2017-01-18 12:37:27 +01:00
import org.gcube.vomanagement.usermanagement.impl.ws.LiferayWSUserManager ;
2016-04-13 18:10:22 +02:00
import org.gcube.vomanagement.usermanagement.model.GCubeUser ;
2013-09-30 15:43:29 +02:00
import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;
2013-01-11 12:36:44 +01:00
2016-04-21 14:12:10 +02:00
import com.liferay.portal.kernel.exception.PortalException ;
import com.liferay.portal.kernel.exception.SystemException ;
2012-12-07 15:06:26 +01:00
/ * *
*
* @author Massimiliano Assante , ISTI - CNR
*
2012-12-07 18:06:40 +01:00
* use to notify users from within your application
2012-12-07 15:06:26 +01:00
* /
2013-01-03 16:28:36 +01:00
public class ApplicationNotificationsManager extends SocialPortalBridge implements NotificationsManager {
2013-09-30 15:43:29 +02:00
private static final Logger _log = LoggerFactory . getLogger ( ApplicationNotificationsManager . class ) ;
2017-01-16 18:10:09 +01:00
public static final String USER_WORKSPACE_FRIENDLY_URL = " /workspace " ;
public static final String USER_MESSAGES_FRIENDLY_URL = " /messages " ;
public static final String USER_NOTIFICATION_FRIENDLY_URL = " /notifications " ;
2017-01-20 14:45:53 +01:00
2014-03-05 18:50:24 +01:00
private String portalName ;
private String senderEmail ;
2016-04-13 18:10:22 +02:00
private String portalURL ;
2016-04-21 14:12:10 +02:00
private String siteLandingPagePath ;
2017-01-18 12:37:27 +01:00
private UserManager userManager ;
2016-02-25 18:57:25 +01:00
/ * *
2017-01-18 12:37:27 +01:00
* < p >
2016-02-25 18:57:25 +01:00
* Use this constructor if you do not need notifications to point back to your applications
2017-01-18 12:37:27 +01:00
* < / p >
2016-02-25 18:57:25 +01:00
* @param scope the current scope
* @param currUser an instance of { @link SocialNetworkingUser } filled with the required user data
2016-05-19 00:13:50 +02:00
* @param site an instance of { @link SocialNetworkingSite } filled with the required data
2016-02-25 18:57:25 +01:00
* /
2016-05-19 00:13:50 +02:00
public ApplicationNotificationsManager ( SocialNetworkingSite site , String scope , SocialNetworkingUser currUser ) {
2016-02-25 18:57:25 +01:00
super ( scope , currUser ) ;
2016-05-19 00:13:50 +02:00
setContext ( site ) ;
2017-01-18 12:37:27 +01:00
userManager = new LiferayUserManager ( ) ;
2016-02-25 18:57:25 +01:00
_log . warn ( " Asked for Simple Notification (without redirect to creator) " ) ;
}
2017-01-20 14:45:53 +01:00
2016-02-25 18:57:25 +01:00
/ * *
2017-01-18 12:37:27 +01:00
* < p >
* Use this constructor if your artifact is not deployed on the portal and do not need notifications to point back to your applications
* < / p >
* @param userManager a remote implementation of { @link UserManager } , see { @link LiferayWSUserManager }
* @param site an instance of { @link SocialNetworkingSite } filled with the required data
* @param scope the current scope
* @param currUser an instance of { @link SocialNetworkingUser } filled with the required user data
* /
public ApplicationNotificationsManager ( UserManager userManager , SocialNetworkingSite site , String scope , SocialNetworkingUser currUser ) {
super ( scope , currUser ) ;
setContext ( site ) ;
this . userManager = userManager ;
_log . warn ( " Asked for Simple Notification (without redirect to creator) " ) ;
}
/ * *
* < p >
2016-02-25 18:57:25 +01:00
* Use this constructor if you do need notifications to point back to your applications ,
* make sure you create your application profile on the infrastructure .
2017-01-18 12:37:27 +01:00
* < / p >
2016-02-25 18:57:25 +01:00
* @see http : //wiki.gcube-system.org/gcube/index.php/Social_Networking_Library#Create_Your_Application_Profile
*
* @param scope the current scope
* @param currUser an instance of { @link SocialNetworkingUser } filled with the required user data
2016-05-19 00:13:50 +02:00
* @param site an instance of { @link SocialNetworkingSite } filled with the required data
2016-02-25 18:57:25 +01:00
* @param portletClassName your portlet class name will be used ad unique identifier for your applicationProfile
* /
2016-05-19 00:13:50 +02:00
public ApplicationNotificationsManager ( SocialNetworkingSite site , String scope , SocialNetworkingUser currUser , String portletClassName ) {
2016-02-25 18:57:25 +01:00
super ( scope , currUser , portletClassName ) ;
2016-05-19 00:13:50 +02:00
setContext ( site ) ;
2017-01-18 12:37:27 +01:00
userManager = new LiferayUserManager ( ) ;
}
/ * *
* < p >
* Use this constructor if your artifact is not deployed on the portal and you do need notifications to point back to your applications ,
* make sure you create your application profile on the infrastructure .
* < / p >
* @see http : //wiki.gcube-system.org/gcube/index.php/Social_Networking_Library#Create_Your_Application_Profile
*
* @param userManager a remote implementation of { @link UserManager } , see { @link LiferayWSUserManager }
* @param scope the current scope
* @param currUser an instance of { @link SocialNetworkingUser } filled with the required user data
* @param site an instance of { @link SocialNetworkingSite } filled with the required data
* @param portletClassName your portlet class name will be used ad unique identifier for your applicationProfile
* /
public ApplicationNotificationsManager ( UserManager userManager , SocialNetworkingSite site , String scope , SocialNetworkingUser currUser , String portletClassName ) {
super ( scope , currUser , portletClassName ) ;
setContext ( site ) ;
this . userManager = userManager ;
2016-04-13 18:10:22 +02:00
}
/ * *
* set the current portal context ( name , emal , url )
* @param request
2016-04-21 14:12:10 +02:00
* @throws SystemException
* @throws PortalException
2016-04-13 18:10:22 +02:00
* /
2016-05-19 00:13:50 +02:00
private void setContext ( SocialNetworkingSite site ) {
siteLandingPagePath = site . getSiteLandingPagePath ( ) ;
portalName = site . getName ( ) ;
senderEmail = site . getSenderEmail ( ) ;
portalURL = site . getSiteURL ( ) ;
2016-09-26 12:14:27 +02:00
_log . info ( " ApplicationNotificationsManager setContext for Site: " + portalURL ) ;
_log . info ( " siteLandingPagePath: " + siteLandingPagePath ) ;
_log . info ( " senderEmail: " + senderEmail ) ;
_log . info ( " portalName: " + senderEmail ) ;
2013-01-11 12:36:44 +01:00
}
2017-01-20 14:45:53 +01:00
2013-01-28 23:30:54 +01:00
/ * *
* actually save the notification to the store
* @param notification2Save the notification instance to save
* @return true if the notification was sent ok
* /
2014-11-03 19:31:09 +01:00
private boolean saveNotification ( Notification notification2Save , String . . . hashtags ) {
2013-01-28 23:30:54 +01:00
_log . trace ( " Trying to send notification to: " + notification2Save . getUserid ( ) + " Type: " + notification2Save . getType ( ) ) ;
2013-04-26 13:08:59 +02:00
if ( notification2Save . getSenderid ( ) . compareTo ( notification2Save . getUserid ( ) ) = = 0 ) {
_log . trace ( " Sender and Receiver are the same " + notification2Save . getUserid ( ) + " Notification Stopped " ) ;
return true ; //I'm not sending notifications to the person who triggered it, pretend I sent it though
}
2013-01-30 18:41:39 +01:00
List < NotificationChannelType > channels = null ;
try {
2013-06-03 18:13:46 +02:00
channels = getStoreInstance ( ) . getUserNotificationChannels ( notification2Save . getUserid ( ) , notification2Save . getType ( ) ) ;
2013-06-06 18:52:03 +02:00
} catch ( Exception e ) {
2013-01-30 18:41:39 +01:00
e . printStackTrace ( ) ;
}
boolean result = false ;
2013-01-31 01:31:07 +01:00
if ( channels . contains ( NotificationChannelType . PORTAL ) ) {
2013-01-30 18:41:39 +01:00
result = getStoreInstance ( ) . saveNotification ( notification2Save ) ;
2013-01-31 01:31:07 +01:00
if ( result )
_log . trace ( " Notification Saved Successfully! " ) ;
else
_log . error ( " Error While trying to save Notification " ) ;
}
2016-04-13 18:10:22 +02:00
if ( channels . contains ( NotificationChannelType . EMAIL ) ) {
2017-01-20 14:45:53 +01:00
EmailPlugin . getInstance ( userManager , currScope ) . sendNotification ( portalURL , siteLandingPagePath , notification2Save , currGroupName , portalName , senderEmail , null , hashtags ) ;
}
if ( channels . isEmpty ( ) ) {
_log . info ( " Notification was not needed as " + notification2Save . getUserid ( ) + " decided not to be notified for " + notification2Save . getType ( ) ) ;
result = true ;
}
return result ;
}
/ * *
* actually save the notification to the store
* @param notification2Save the notification instance to save
* @return true if the notification was sent ok
* /
private boolean saveNotification ( Notification notification2Save , Set < String > mentionedVREGroups , String . . . hashtags ) {
_log . trace ( " Trying to send notification to: " + notification2Save . getUserid ( ) + " Type: " + notification2Save . getType ( ) ) ;
if ( notification2Save . getSenderid ( ) . compareTo ( notification2Save . getUserid ( ) ) = = 0 ) {
_log . trace ( " Sender and Receiver are the same " + notification2Save . getUserid ( ) + " Notification Stopped " ) ;
return true ; //I'm not sending notifications to the person who triggered it, pretend I sent it though
}
List < NotificationChannelType > channels = null ;
try {
channels = getStoreInstance ( ) . getUserNotificationChannels ( notification2Save . getUserid ( ) , notification2Save . getType ( ) ) ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
}
boolean result = false ;
if ( channels . contains ( NotificationChannelType . PORTAL ) ) {
result = getStoreInstance ( ) . saveNotification ( notification2Save ) ;
if ( result )
_log . trace ( " Notification Saved Successfully! " ) ;
else
_log . error ( " Error While trying to save Notification " ) ;
}
if ( channels . contains ( NotificationChannelType . EMAIL ) ) {
EmailPlugin . getInstance ( userManager , currScope ) . sendNotification ( portalURL , siteLandingPagePath , notification2Save , currGroupName , portalName , senderEmail , mentionedVREGroups , hashtags ) ;
2016-04-13 18:10:22 +02:00
}
2013-01-31 01:31:07 +01:00
if ( channels . isEmpty ( ) ) {
2013-07-12 15:37:32 +02:00
_log . info ( " Notification was not needed as " + notification2Save . getUserid ( ) + " decided not to be notified for " + notification2Save . getType ( ) ) ;
2013-01-31 01:31:07 +01:00
result = true ;
}
2013-01-28 23:30:54 +01:00
return result ;
}
2015-07-13 19:37:32 +02:00
2013-01-29 02:09:00 +01:00
/ * *
* return the url of the application if exists in the profile
* @return .
* /
private String getApplicationUrl ( ) {
2014-03-02 23:51:28 +01:00
if ( applicationProfile ! = null & & applicationProfile . getUrl ( ) ! = null ) {
_log . trace ( " getApplicationUrl= " + applicationProfile . getUrl ( ) ) ;
return applicationProfile . getUrl ( ) ;
}
else {
2016-04-21 14:12:10 +02:00
_log . warn ( " applicationProfile NULL or url is empty returning " + siteLandingPagePath ) ;
return siteLandingPagePath ;
2014-03-02 23:51:28 +01:00
}
2013-01-29 02:09:00 +01:00
}
2012-12-07 18:02:20 +01:00
/ * *
* { @inheritDoc }
2013-01-11 12:36:44 +01:00
* @throws InternalErrorException
2012-12-07 18:02:20 +01:00
* /
2012-12-07 15:06:26 +01:00
@Override
2014-05-15 19:28:05 +02:00
public boolean notifyFolderSharing ( String userIdToNotify , WorkspaceSharedFolder sharedFolder ) throws InternalErrorException {
2014-02-13 17:46:34 +01:00
String sharedFolderName = sharedFolder . getName ( ) ;
if ( sharedFolder . isShared ( ) ) {
WorkspaceSharedFolder sharedWSFolder = ( WorkspaceSharedFolder ) sharedFolder ;
if ( sharedWSFolder . isVreFolder ( ) )
sharedFolderName = sharedWSFolder . getDisplayName ( ) ;
}
2013-01-11 12:36:44 +01:00
Notification not = new Notification (
UUID . randomUUID ( ) . toString ( ) ,
NotificationType . WP_FOLDER_SHARE ,
userIdToNotify , //user no notify
2014-09-29 18:47:23 +02:00
sharedFolder . getId ( ) ,
2013-01-11 12:36:44 +01:00
new Date ( ) ,
2017-01-16 18:10:09 +01:00
siteLandingPagePath + USER_WORKSPACE_FRIENDLY_URL + " ?itemid= " + sharedFolder . getId ( ) ,
2014-09-29 18:47:23 +02:00
" shared the workspace folder \" " + sharedFolderName + " \" with you " ,
false ,
2016-02-25 18:57:25 +01:00
currUser . getUsername ( ) ,
currUser . getFullname ( ) ,
currUser . getUserAvatarId ( ) ) ;
2014-09-29 18:47:23 +02:00
return saveNotification ( not ) ;
}
/ * *
* { @inheritDoc }
* @throws Exception
* /
@Override
public boolean notifyFolderUnsharing ( String userIdToNotify , String unsharedFolderId , String unsharedFolderName ) throws Exception {
Notification not = new Notification (
UUID . randomUUID ( ) . toString ( ) ,
NotificationType . WP_FOLDER_UNSHARE ,
userIdToNotify , //user no notify
unsharedFolderId ,
new Date ( ) ,
2017-01-16 18:10:09 +01:00
siteLandingPagePath + USER_WORKSPACE_FRIENDLY_URL + " ?itemid= " + unsharedFolderId ,
2014-09-29 18:47:23 +02:00
" unshared the workspace folder \" " + unsharedFolderName + " \" " ,
2013-01-11 12:36:44 +01:00
false ,
2016-02-25 18:57:25 +01:00
currUser . getUsername ( ) ,
currUser . getFullname ( ) ,
currUser . getUserAvatarId ( ) ) ;
2013-01-11 12:36:44 +01:00
2013-01-28 23:30:54 +01:00
return saveNotification ( not ) ;
2012-12-07 15:06:26 +01:00
}
2014-09-30 12:36:37 +02:00
/ * *
* { @inheritDoc }
* @throws Exception
* /
@Override
public boolean notifyAdministratorUpgrade ( String userIdToNotify , WorkspaceSharedFolder sharedFolder ) throws Exception {
String sharedFolderName = sharedFolder . getName ( ) ;
Notification not = new Notification (
UUID . randomUUID ( ) . toString ( ) ,
NotificationType . WP_ADMIN_UPGRADE ,
userIdToNotify , //user no notify
sharedFolder . getId ( ) ,
new Date ( ) ,
2017-01-16 18:10:09 +01:00
siteLandingPagePath + USER_WORKSPACE_FRIENDLY_URL + " ?itemid= " + sharedFolder . getId ( ) ,
2014-09-30 12:36:37 +02:00
" upgraded you to Administrator of the workspace folder \" " + sharedFolderName + " \" " ,
false ,
2016-02-25 18:57:25 +01:00
currUser . getUsername ( ) ,
currUser . getFullname ( ) ,
currUser . getUserAvatarId ( ) ) ;
2014-09-30 12:36:37 +02:00
return saveNotification ( not ) ;
}
/ * *
* { @inheritDoc }
* @throws Exception
* /
@Override
public boolean notifyAdministratorDowngrade ( String userIdToNotify , WorkspaceSharedFolder sharedFolder ) throws Exception {
String sharedFolderName = sharedFolder . getName ( ) ;
Notification not = new Notification (
UUID . randomUUID ( ) . toString ( ) ,
NotificationType . WP_ADMIN_DOWNGRADE ,
userIdToNotify , //user no notify
sharedFolder . getId ( ) ,
new Date ( ) ,
2017-01-16 18:10:09 +01:00
siteLandingPagePath + USER_WORKSPACE_FRIENDLY_URL + " ?itemid= " + sharedFolder . getId ( ) ,
2014-09-30 12:36:37 +02:00
" downgraded you from Administrator of the workspace folder \" " + sharedFolderName + " \" " ,
false ,
2016-02-25 18:57:25 +01:00
currUser . getUsername ( ) ,
currUser . getFullname ( ) ,
currUser . getUserAvatarId ( ) ) ;
2014-09-30 12:36:37 +02:00
return saveNotification ( not ) ;
}
2015-07-13 19:37:32 +02:00
2013-03-20 15:45:06 +01:00
/ * *
* { @inheritDoc }
* @throws InternalErrorException
* /
@Override
public boolean notifyFolderRenaming ( String userIdToNotify , String previousName , String newName , String renamedFolderId ) throws InternalErrorException {
Notification not = new Notification (
UUID . randomUUID ( ) . toString ( ) ,
2013-03-25 14:38:14 +01:00
NotificationType . WP_FOLDER_RENAMED ,
2013-03-20 15:45:06 +01:00
userIdToNotify , //user no notify
renamedFolderId , //the
new Date ( ) ,
2017-01-16 18:10:09 +01:00
siteLandingPagePath + USER_WORKSPACE_FRIENDLY_URL + " ?itemid= " + renamedFolderId ,
2014-09-29 18:47:23 +02:00
" renamed your shared folder \" " + previousName + " \" as \" " + newName + " \" " ,
2013-03-20 15:45:06 +01:00
false ,
2016-02-25 18:57:25 +01:00
currUser . getUsername ( ) ,
currUser . getFullname ( ) ,
currUser . getUserAvatarId ( ) ) ;
2013-03-20 15:45:06 +01:00
return saveNotification ( not ) ;
}
2012-12-07 18:02:20 +01:00
/ * *
* { @inheritDoc }
2013-01-11 12:36:44 +01:00
* @throws UserManagementPortalException
* @throws UserRetrievalFault
* @throws UserManagementSystemException
2012-12-07 18:02:20 +01:00
* /
2012-12-07 15:06:26 +01:00
@Override
2014-05-15 19:28:05 +02:00
public boolean notifyFolderAddedUser ( String userIdToNotify , WorkspaceSharedFolder sharedFolder , String newAddedUserId ) throws InternalErrorException , UserManagementSystemException , UserRetrievalFault , UserManagementPortalException {
2013-01-11 12:36:44 +01:00
UserManager um = new LiferayUserManager ( ) ;
2016-04-13 18:10:22 +02:00
GCubeUser user = um . getUserByUsername ( newAddedUserId ) ;
2013-01-11 12:36:44 +01:00
Notification not = new Notification (
UUID . randomUUID ( ) . toString ( ) ,
NotificationType . WP_FOLDER_ADDEDUSER ,
userIdToNotify , //user no notify
sharedFolder . getId ( ) , //the
new Date ( ) ,
2017-01-16 18:10:09 +01:00
siteLandingPagePath + USER_WORKSPACE_FRIENDLY_URL + " ?itemid= " + sharedFolder . getId ( ) ,
2014-09-29 18:47:23 +02:00
" added " + user . getFullname ( ) + " to your workspace shared folder \" " + sharedFolder . getName ( ) + " \" " ,
2013-01-11 12:36:44 +01:00
false ,
2016-02-25 18:57:25 +01:00
currUser . getUsername ( ) ,
currUser . getFullname ( ) ,
currUser . getUserAvatarId ( ) ) ;
2013-01-29 02:09:00 +01:00
2013-01-28 23:30:54 +01:00
return saveNotification ( not ) ;
2012-12-07 15:06:26 +01:00
}
2013-03-25 12:08:25 +01:00
/ * *
* { @inheritDoc }
* @throws UserManagementPortalException
* @throws UserRetrievalFault
* @throws UserManagementSystemException
* /
@Override
2014-05-15 19:28:05 +02:00
public boolean notifyFolderAddedUsers ( String userIdToNotify , WorkspaceSharedFolder sharedFolder , List < String > newAddedUserIds ) throws InternalErrorException , UserManagementSystemException , UserRetrievalFault , UserManagementPortalException {
2013-03-25 12:08:25 +01:00
if ( newAddedUserIds ! = null & & newAddedUserIds . size ( ) > 0 ) {
if ( newAddedUserIds . size ( ) = = 1 )
return notifyFolderAddedUser ( userIdToNotify , sharedFolder , newAddedUserIds . get ( 0 ) ) ;
StringBuilder addedUsersFullNames = new StringBuilder ( ) ;
UserManager um = new LiferayUserManager ( ) ;
for ( String userId : newAddedUserIds )
2016-05-16 19:18:23 +02:00
addedUsersFullNames . append ( um . getUserByUsername ( userId ) . getFullname ( ) ) . append ( " " ) ;
2013-04-26 13:08:59 +02:00
2013-03-25 12:08:25 +01:00
Notification not = new Notification (
UUID . randomUUID ( ) . toString ( ) ,
NotificationType . WP_FOLDER_ADDEDUSER ,
userIdToNotify , //user no notify
sharedFolder . getId ( ) , //the
new Date ( ) ,
2017-01-16 18:10:09 +01:00
siteLandingPagePath + USER_WORKSPACE_FRIENDLY_URL + " ?itemid= " + sharedFolder . getId ( ) ,
2014-09-29 18:47:23 +02:00
" added " + addedUsersFullNames + " to your workspace shared folder \" " + sharedFolder . getName ( ) + " \" " ,
2013-03-25 12:08:25 +01:00
false ,
2016-02-25 18:57:25 +01:00
currUser . getUsername ( ) ,
currUser . getFullname ( ) ,
currUser . getUserAvatarId ( ) ) ;
2013-03-25 12:08:25 +01:00
return saveNotification ( not ) ;
}
2013-04-26 13:08:59 +02:00
2013-03-25 12:08:25 +01:00
return false ;
}
2012-12-07 18:02:20 +01:00
/ * *
* { @inheritDoc }
* /
2012-12-07 15:06:26 +01:00
@Override
2014-05-15 19:28:05 +02:00
public boolean notifyFolderRemovedUser ( String userIdToNotify , WorkspaceSharedFolder sharedFolder ) throws InternalErrorException , UserManagementSystemException , UserRetrievalFault , UserManagementPortalException {
2013-01-11 12:36:44 +01:00
Notification not = new Notification (
UUID . randomUUID ( ) . toString ( ) ,
NotificationType . WP_FOLDER_REMOVEDUSER ,
userIdToNotify , //user no notify
sharedFolder . getId ( ) , //the
new Date ( ) ,
2017-01-16 18:10:09 +01:00
siteLandingPagePath + USER_WORKSPACE_FRIENDLY_URL + " ?itemid= " + sharedFolder . getId ( ) ,
2014-09-29 18:47:23 +02:00
" unshared his shared folder \" " + sharedFolder . getName ( ) + " \" from your workspace " ,
2013-01-11 12:36:44 +01:00
false ,
2016-02-25 18:57:25 +01:00
currUser . getUsername ( ) ,
currUser . getFullname ( ) ,
currUser . getUserAvatarId ( ) ) ;
2013-01-29 02:09:00 +01:00
2013-01-28 23:30:54 +01:00
return saveNotification ( not ) ;
2012-12-07 15:06:26 +01:00
}
2012-12-07 18:02:20 +01:00
/ * *
* { @inheritDoc }
2013-01-11 12:36:44 +01:00
* @throws InternalErrorException
2012-12-07 18:02:20 +01:00
* /
2012-12-07 15:06:26 +01:00
@Override
2014-05-15 19:28:05 +02:00
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 ( ) :
2015-07-13 19:37:32 +02:00
" added " + item . getName ( ) + " to your workspace shared folder " + item . getPath ( ) . substring ( 0 , item . getPath ( ) . lastIndexOf ( '/' ) ) ;
2013-01-29 02:09:00 +01:00
2015-07-13 19:37:32 +02:00
Notification not = new Notification (
UUID . randomUUID ( ) . toString ( ) ,
NotificationType . WP_ITEM_NEW ,
userIdToNotify , //user no notify
item . getId ( ) , //the
new Date ( ) ,
2017-01-16 18:10:09 +01:00
siteLandingPagePath + USER_WORKSPACE_FRIENDLY_URL + " ?itemid= " + item . getParent ( ) . getId ( ) ,
2015-07-13 19:37:32 +02:00
notifyText ,
false ,
2016-02-25 18:57:25 +01:00
currUser . getUsername ( ) ,
currUser . getFullname ( ) ,
currUser . getUserAvatarId ( ) ) ;
2015-07-13 19:37:32 +02:00
return saveNotification ( not ) ;
2012-12-07 15:06:26 +01:00
}
2012-12-07 18:02:20 +01:00
/ * *
* { @inheritDoc }
2013-01-11 12:36:44 +01:00
* @throws InternalErrorException
2012-12-07 18:02:20 +01:00
* /
2012-12-07 15:06:26 +01:00
@Override
2014-05-15 19:28:05 +02:00
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 ( ) :
2014-09-29 18:47:23 +02:00
" removed item " + item . getName ( ) + " from your workspace shared folder \" " + sharedFolder . getName ( ) + " \" " ;
2015-07-13 19:37:32 +02:00
2013-01-11 12:36:44 +01:00
Notification not = new Notification (
UUID . randomUUID ( ) . toString ( ) ,
NotificationType . WP_ITEM_DELETE ,
userIdToNotify , //user no notify
item . getId ( ) , //the
new Date ( ) ,
2017-01-16 18:10:09 +01:00
siteLandingPagePath + USER_WORKSPACE_FRIENDLY_URL + " ?itemid= " + sharedFolder . getId ( ) ,
2014-02-13 17:46:34 +01:00
notifyText ,
2013-01-11 12:36:44 +01:00
false ,
2016-02-25 18:57:25 +01:00
currUser . getUsername ( ) ,
currUser . getFullname ( ) ,
currUser . getUserAvatarId ( ) ) ;
2013-06-14 15:24:42 +02:00
return saveNotification ( not ) ;
}
/ * *
* { @inheritDoc }
* @throws InternalErrorException
* /
@Override
2014-05-15 19:28:05 +02:00
public boolean notifyRemovedItem ( String userIdToNotify , String itemName , WorkspaceSharedFolder sharedFolder ) throws InternalErrorException {
2014-09-29 18:47:23 +02:00
String notifyText = sharedFolder . isVreFolder ( ) ? " deleted item \" " + itemName + " \" from the workspace group folder " + sharedFolder . getDisplayName ( ) :
" deleted item \" " + itemName + " \" from your workspace shared folder \" " + sharedFolder . getName ( ) + " \" " ;
2014-05-15 19:28:05 +02:00
2013-06-14 15:24:42 +02:00
Notification not = new Notification (
UUID . randomUUID ( ) . toString ( ) ,
NotificationType . WP_ITEM_DELETE ,
userIdToNotify , //user no notify
sharedFolder . getId ( ) , //the
new Date ( ) ,
2017-01-16 18:10:09 +01:00
siteLandingPagePath + USER_WORKSPACE_FRIENDLY_URL + " ?itemid= " + sharedFolder . getId ( ) ,
2014-02-13 17:46:34 +01:00
notifyText ,
2013-06-14 15:24:42 +02:00
false ,
2016-02-25 18:57:25 +01:00
currUser . getUsername ( ) ,
currUser . getFullname ( ) ,
currUser . getUserAvatarId ( ) ) ;
2013-01-29 02:09:00 +01:00
2013-01-28 23:30:54 +01:00
return saveNotification ( not ) ;
2012-12-07 15:06:26 +01:00
}
2012-12-07 18:02:20 +01:00
/ * *
* { @inheritDoc }
2013-01-11 12:36:44 +01:00
* @throws InternalErrorException
2012-12-07 18:02:20 +01:00
* /
2012-12-07 15:06:26 +01:00
@Override
2014-05-15 19:28:05 +02:00
public boolean notifyUpdatedItem ( String userIdToNotify , WorkspaceItem item , WorkspaceSharedFolder sharedFolder ) throws InternalErrorException {
2014-09-29 18:47:23 +02:00
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 ( '/' ) ) + " \" " ;
2014-05-15 19:28:05 +02:00
2013-01-11 12:36:44 +01:00
Notification not = new Notification (
UUID . randomUUID ( ) . toString ( ) ,
NotificationType . WP_ITEM_UPDATED ,
userIdToNotify , //user no notify
2013-03-16 02:40:56 +01:00
item . getId ( ) , //the
2013-01-11 12:36:44 +01:00
new Date ( ) ,
2017-01-16 18:10:09 +01:00
siteLandingPagePath + USER_WORKSPACE_FRIENDLY_URL + " ?itemid= " + item . getParent ( ) . getId ( ) ,
2014-02-13 17:46:34 +01:00
notifyText ,
2013-01-11 12:36:44 +01:00
false ,
2016-02-25 18:57:25 +01:00
currUser . getUsername ( ) ,
currUser . getFullname ( ) ,
currUser . getUserAvatarId ( ) ) ;
2013-01-29 02:09:00 +01:00
2013-01-28 23:30:54 +01:00
return saveNotification ( not ) ;
2012-12-07 15:06:26 +01:00
}
2013-03-25 14:38:14 +01:00
/ * *
* { @inheritDoc }
* @throws InternalErrorException
* /
@Override
2014-05-15 19:28:05 +02:00
public boolean notifyItemRenaming ( String userIdToNotify , String previousName , WorkspaceItem renamedItem , WorkspaceSharedFolder rootSharedFolder ) throws InternalErrorException {
2014-09-29 18:47:23 +02:00
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 ( '/' ) ) + " \" " ;
2014-05-15 19:28:05 +02:00
2013-03-25 14:38:14 +01:00
Notification not = new Notification (
UUID . randomUUID ( ) . toString ( ) ,
NotificationType . WP_ITEM_RENAMED ,
userIdToNotify , //user no notify
renamedItem . getId ( ) , //the
new Date ( ) ,
2017-01-16 18:10:09 +01:00
siteLandingPagePath + USER_WORKSPACE_FRIENDLY_URL + " ?itemid= " + renamedItem . getParent ( ) . getId ( ) ,
2014-02-13 17:46:34 +01:00
notifyText ,
2013-03-25 14:38:14 +01:00
false ,
2016-02-25 18:57:25 +01:00
currUser . getUsername ( ) ,
currUser . getFullname ( ) ,
currUser . getUserAvatarId ( ) ) ;
2013-03-25 14:38:14 +01:00
return saveNotification ( not ) ;
}
2012-12-07 18:02:20 +01:00
/ * *
* { @inheritDoc }
* /
2012-12-07 16:29:09 +01:00
@Override
2015-10-14 17:27:13 +02:00
public boolean notifyMessageReceived ( String userIdToNotify , String messageId , String subject , String messageText , String . . . otherRecipientsFullNames ) {
2015-10-09 10:02:47 +02:00
String [ ] optionalParams = { subject } ;
2015-10-14 17:27:13 +02:00
String otherRecipientNames = " " ;
if ( otherRecipientsFullNames ! = null & & otherRecipientsFullNames . length > 0 ) {
otherRecipientNames = " <br/><div> - This message was also sent to: <ul> " ;
for ( int i = 0 ; i < otherRecipientsFullNames . length ; i + + ) {
2015-10-15 12:09:30 +02:00
otherRecipientNames + = " <li> " + otherRecipientsFullNames [ i ] + " </li> " ;
2015-10-14 17:27:13 +02:00
}
2016-05-17 10:20:18 +02:00
otherRecipientNames + = " </ul></div><div>If you reply, your message will be also delivered to them.</div><br/> " ;
2015-10-14 17:27:13 +02:00
}
2017-01-20 14:45:53 +01:00
2013-01-09 17:47:22 +01:00
Notification not = new Notification (
UUID . randomUUID ( ) . toString ( ) ,
NotificationType . MESSAGE ,
userIdToNotify , //user no notify
2015-10-09 10:02:47 +02:00
messageId , //the unique identifier of the message
2013-01-09 17:47:22 +01:00
new Date ( ) ,
2017-01-16 18:10:09 +01:00
siteLandingPagePath + USER_MESSAGES_FRIENDLY_URL ,
2015-10-09 10:02:47 +02:00
" sent you a message: "
2015-10-14 17:27:13 +02:00
+ " <br/><div style= \" margin-top: 10px; margin-bottom: 10px; margin-left: 50px; padding-left: 15px; border-left: 3px solid #ccc; font-style: italic; \" > "
+ messageText + " </div> "
2017-01-20 14:45:53 +01:00
+ otherRecipientNames ,
false ,
currUser . getUsername ( ) ,
currUser . getFullname ( ) ,
currUser . getUserAvatarId ( ) ) ;
2013-01-11 12:36:44 +01:00
2015-10-09 10:02:47 +02:00
return saveNotification ( not , optionalParams ) ;
2012-12-07 16:29:09 +01:00
}
2012-12-07 18:02:20 +01:00
/ * *
* { @inheritDoc }
* /
2012-12-07 16:29:09 +01:00
@Override
2014-11-03 19:31:09 +01:00
public boolean notifyPost ( String userIdToNotify , String feedid , String feedText , String . . . hashtags ) {
2014-03-05 00:40:14 +01:00
StringBuilder notificationText = new StringBuilder ( ) ;
2016-09-26 12:14:27 +02:00
notificationText . append ( " posted on <b> " ) . append ( currGroupName ) . append ( " :</b> " ) // has done something
2015-10-16 00:16:38 +02:00
. append ( " <br /><br /> " ) . append ( feedText ) . append ( " " )
. append ( " <br /><br /> " ) ;
2017-01-20 14:45:53 +01:00
2014-03-05 00:40:14 +01:00
Notification not = new Notification (
UUID . randomUUID ( ) . toString ( ) ,
NotificationType . POST_ALERT ,
userIdToNotify , //user no notify
feedid , //the post
new Date ( ) ,
getApplicationUrl ( ) + " ?oid= " + feedid ,
notificationText . toString ( ) ,
false ,
2016-02-25 18:57:25 +01:00
currUser . getUsername ( ) ,
currUser . getFullname ( ) ,
currUser . getUserAvatarId ( ) ) ;
2014-11-03 19:31:09 +01:00
return saveNotification ( not , hashtags ) ;
2014-03-05 00:40:14 +01:00
}
2017-01-20 14:45:53 +01:00
@Override
public boolean notifyPost ( String userIdToNotify , String feedid ,
String feedText , Set < String > mentionedVREGroups ,
Set < String > hashtags ) {
StringBuilder notificationText = new StringBuilder ( ) ;
notificationText . append ( " posted on <b> " ) . append ( currGroupName ) . append ( " :</b> " ) // has done something
. append ( " <br /><br /> " ) . append ( feedText ) . append ( " " )
. append ( " <br /><br /> " ) ;
Notification not = new Notification (
UUID . randomUUID ( ) . toString ( ) ,
NotificationType . POST_ALERT ,
userIdToNotify , //user no notify
feedid , //the post
new Date ( ) ,
getApplicationUrl ( ) + " ?oid= " + feedid ,
notificationText . toString ( ) ,
false ,
currUser . getUsername ( ) ,
currUser . getFullname ( ) ,
currUser . getUserAvatarId ( ) ) ;
return saveNotification ( not , mentionedVREGroups , hashtags . toArray ( new String [ hashtags . size ( ) ] ) ) ;
}
2014-03-05 00:40:14 +01:00
/ * *
* { @inheritDoc }
* /
@Override
2016-02-17 18:27:46 +01:00
public boolean notifyOwnCommentReply ( String userIdToNotify , String feedid , String feedText , String commentKey ) {
2013-01-11 12:36:44 +01:00
Notification not = new Notification (
UUID . randomUUID ( ) . toString ( ) ,
NotificationType . OWN_COMMENT ,
userIdToNotify , //user no notify
feedid , //the post
new Date ( ) ,
2015-07-15 18:39:58 +02:00
getApplicationUrl ( ) + " ?oid= " + feedid ,
2015-07-13 19:37:32 +02:00
" commented on your post: "
2015-10-16 00:16:38 +02:00
+ " <div style= \" margin-top: 10px; margin-bottom: 10px; margin-left: 50px; padding-left: 15px; "
+ " border-left: 3px solid #ccc; font-style: italic; \" > \" "
+ feedText + " \" </div> " ,
2015-07-13 19:37:32 +02:00
false ,
2016-02-25 18:57:25 +01:00
currUser . getUsername ( ) ,
currUser . getFullname ( ) ,
currUser . getUserAvatarId ( ) ,
2017-01-20 14:45:53 +01:00
commentKey ) ;
2013-01-28 23:30:54 +01:00
return saveNotification ( not ) ;
2012-12-07 16:29:09 +01:00
}
2012-12-07 18:02:20 +01:00
/ * *
* { @inheritDoc }
* /
2012-12-07 16:29:09 +01:00
@Override
2016-02-17 18:27:46 +01:00
public boolean notifyCommentReply ( String userIdToNotify , String feedid , String commentText , String feedOwnerFullName , String feedOwnerId , String commentKey ) {
2016-02-25 18:57:25 +01:00
String notificationText = ( currUser . getUsername ( ) . compareTo ( feedOwnerId ) = = 0 ) ?
2015-07-13 19:37:32 +02:00
" also commented on his post: "
+ " <div style= \" margin-top: 10px; margin-bottom: 10px; margin-left: 50px; padding-left: 15px; border-left: 3px solid #ccc; font-style: italic; \" > \" "
2015-10-16 00:16:38 +02:00
+ commentText + " \" </div> "
2013-04-26 13:08:59 +02:00
:
2015-07-13 19:37:32 +02:00
" also commented on " + feedOwnerFullName + " 's post: "
+ " <div style= \" margin-top: 10px; margin-bottom: 10px; margin-left: 50px; padding-left: 15px; border-left: 3px solid #ccc; font-style: italic; \" > \" "
2015-10-16 00:16:38 +02:00
+ commentText + " \" </div> " ;
2015-07-13 19:37:32 +02:00
Notification not = new Notification (
UUID . randomUUID ( ) . toString ( ) ,
NotificationType . COMMENT ,
userIdToNotify , //user no notify
feedid , //the post
new Date ( ) ,
2015-07-15 18:39:58 +02:00
getApplicationUrl ( ) + " ?oid= " + feedid ,
2015-07-13 19:37:32 +02:00
notificationText ,
false ,
2016-02-25 18:57:25 +01:00
currUser . getUsername ( ) ,
currUser . getFullname ( ) ,
currUser . getUserAvatarId ( ) ,
2016-02-17 18:27:46 +01:00
commentKey ) ;
2015-07-13 19:37:32 +02:00
return saveNotification ( not ) ;
2013-04-18 16:34:07 +02:00
}
/ * *
* { @inheritDoc }
* /
@Override
2016-02-17 18:27:46 +01:00
public boolean notifyCommentOnFavorite ( String userIdToNotify , String feedid , String commentText , String commentKey ) {
2016-09-26 12:14:27 +02:00
return notifyCommentOnLike ( userIdToNotify , feedid , commentText , commentKey ) ;
}
/ * *
* { @inheritDoc }
* /
@Override
public boolean notifyCommentOnLike ( String userIdToNotify , String feedid , String commentText , String commentKey ) {
2013-03-11 12:35:23 +01:00
Notification not = new Notification (
UUID . randomUUID ( ) . toString ( ) ,
NotificationType . COMMENT ,
userIdToNotify , //user no notify
feedid , //the post
new Date ( ) ,
2015-07-15 18:39:58 +02:00
getApplicationUrl ( ) + " ?oid= " + feedid ,
2016-09-26 12:14:27 +02:00
" commented on one of your liked posts: "
2015-07-13 19:37:32 +02:00
+ " <div style= \" margin-top: 10px; margin-bottom: 10px; margin-left: 50px; padding-left: 15px; border-left: 3px solid #ccc; font-style: italic; \" > \" "
2015-10-16 00:16:38 +02:00
+ commentText + " \" </div> " ,
2015-07-13 19:37:32 +02:00
false ,
2016-02-25 18:57:25 +01:00
currUser . getUsername ( ) ,
currUser . getFullname ( ) ,
currUser . getUserAvatarId ( ) ,
2016-02-17 18:27:46 +01:00
commentKey ) ;
2013-03-11 12:35:23 +01:00
return saveNotification ( not ) ;
2012-12-07 16:29:09 +01:00
}
2012-12-07 18:02:20 +01:00
/ * *
* { @inheritDoc }
* /
2012-12-07 16:29:09 +01:00
@Override
2016-02-17 18:27:46 +01:00
public boolean notifyUserTag ( String userIdToNotify , String feedid , String feedText , String commentKey ) {
2013-04-18 11:21:31 +02:00
Notification not = new Notification (
UUID . randomUUID ( ) . toString ( ) ,
NotificationType . MENTION ,
userIdToNotify , //user no notify
feedid , //the post
new Date ( ) ,
2015-07-15 18:39:58 +02:00
getApplicationUrl ( ) + " ?oid= " + feedid ,
" mentioned you: " + " <div style= \" margin-top: 10px; margin-bottom: 10px; margin-left: 50px; padding-left: 15px; border-left: 3px solid #ccc; font-style: italic; \" > \" "
2015-10-16 00:16:38 +02:00
+ feedText + " \" </div> " ,
2017-01-20 14:45:53 +01:00
false ,
currUser . getUsername ( ) ,
currUser . getFullname ( ) ,
currUser . getUserAvatarId ( ) ,
commentKey ) ;
2013-04-18 11:21:31 +02:00
return saveNotification ( not ) ;
}
/ * *
* { @inheritDoc }
* /
@Override
2013-01-11 12:36:44 +01:00
public boolean notifyLikedFeed ( String userIdToNotify , String feedid , String feedText ) {
2017-01-20 14:45:53 +01:00
Notification not = new Notification (
2013-01-11 12:36:44 +01:00
UUID . randomUUID ( ) . toString ( ) ,
NotificationType . LIKE ,
userIdToNotify , //user no notify
feedid , //the post
new Date ( ) ,
2015-07-15 18:39:58 +02:00
getApplicationUrl ( ) + " ?oid= " + feedid ,
2016-09-26 12:14:27 +02:00
" liked/subscribed to one of your post " ,
2013-01-11 12:36:44 +01:00
false ,
2016-02-25 18:57:25 +01:00
currUser . getUsername ( ) ,
currUser . getFullname ( ) ,
currUser . getUserAvatarId ( ) ) ;
2013-01-28 23:30:54 +01:00
return saveNotification ( not ) ;
2012-12-07 16:29:09 +01:00
}
2013-01-28 01:12:51 +01:00
/ * *
* { @inheritDoc }
* /
2013-01-03 16:28:36 +01:00
@Override
2017-01-20 14:45:53 +01:00
public boolean notifyJobStatus ( String userIdToNotify , RunningJob job ) {
//get job status
NotificationType statusToUse = null ;
// notification final part
String notificationFinalPart = null ;
switch ( job . getStatus ( ) ) {
case CANCELLED :
notificationFinalPart = " has been cancelled. " ;
statusToUse = NotificationType . JOB_COMPLETED_NOK ;
break ;
case CANCELLING :
notificationFinalPart = " is going to be cancelled. " ;
statusToUse = NotificationType . JOB_COMPLETED_NOK ;
break ;
case DELETED :
notificationFinalPart = " has been deleted. " ;
statusToUse = NotificationType . JOB_COMPLETED_NOK ;
break ;
case DELETING :
notificationFinalPart = " is going to be deleted. " ;
statusToUse = NotificationType . JOB_COMPLETED_NOK ;
break ;
case EXECUTING :
notificationFinalPart = " is executing. " ;
statusToUse = NotificationType . JOB_COMPLETED_OK ;
break ;
case FAILED :
notificationFinalPart = " is failed. " ;
statusToUse = NotificationType . JOB_COMPLETED_NOK ;
break ;
case NEW :
notificationFinalPart = " has been instanciated. " ;
statusToUse = NotificationType . JOB_COMPLETED_OK ;
break ;
case SUBMITTED :
notificationFinalPart = " has been submitted. " ;
statusToUse = NotificationType . JOB_COMPLETED_OK ;
break ;
case SUCCEEDED :
notificationFinalPart = " terminated correctly. " ;
statusToUse = NotificationType . JOB_COMPLETED_OK ;
break ;
case TIMED_OUT :
notificationFinalPart = " went in time out. " ;
statusToUse = NotificationType . JOB_COMPLETED_NOK ;
break ;
case WAITING :
notificationFinalPart = " is waiting. " ;
statusToUse = NotificationType . JOB_COMPLETED_NOK ;
break ;
default :
_log . error ( " job status is missing, returning without sending notification " ) ;
return false ;
}
Notification not = new Notification (
UUID . randomUUID ( ) . toString ( ) ,
statusToUse ,
userIdToNotify , //user to notify
job . getServiceName ( ) ,
new Date ( ) ,
null ,
" 's job with id " + job . getJobId ( ) + " , named <b> " + job . getJobName ( ) + " </b> " + notificationFinalPart +
( job . getMessage ( ) ! = null & & ! job . getMessage ( ) . isEmpty ( ) ?
" Additional information: " + job . getMessage ( ) : " " ) ,
false ,
currUser . getUsername ( ) ,
job . getServiceName ( ) ,
currUser . getUserAvatarId ( ) ) ;
return saveNotification ( not ) ;
2013-01-03 16:28:36 +01:00
}
2017-01-20 14:45:53 +01:00
2013-07-11 17:25:21 +02:00
/ * *
* { @inheritDoc }
* /
@Override
public boolean notifyNewCalendarEvent ( String userIdToNotify , String eventTitle , String eventType , Date startDate , Date endingDate ) {
SimpleDateFormat spf = new SimpleDateFormat ( " EEE dd MMMMM, yyyy " ) ;
2014-05-15 19:28:05 +02:00
2013-07-11 17:25:21 +02:00
String endDateToDisplay = " " ;
if ( endingDate ! = null ) {
endDateToDisplay = " to " + spf . format ( endingDate ) ;
}
2014-05-15 19:28:05 +02:00
2013-07-11 17:25:21 +02:00
StringBuilder notificationText = new StringBuilder ( ) ;
2016-02-25 18:57:25 +01:00
notificationText . append ( " added the following event in the <b> " ) . append ( currGroupName ) . append ( " </b> shared calendar: " ) // has done something
2013-07-12 15:37:32 +02:00
. append ( " <strong> " ) . append ( eventTitle ) . append ( " </strong><br /> " )
. append ( " <br /><strong> Time:</strong> " ) . append ( spf . format ( startDate ) ) . append ( endDateToDisplay ) . append ( " <br /> " )
. append ( " <br /><strong> Category: </strong> " ) . append ( eventType ) ;
2014-05-15 19:28:05 +02:00
2013-07-11 17:25:21 +02:00
Notification not = new Notification (
UUID . randomUUID ( ) . toString ( ) ,
NotificationType . CALENDAR_ADDED_EVENT ,
userIdToNotify , //user no notify
" " , //
new Date ( ) ,
getApplicationUrl ( ) ,
notificationText . toString ( ) ,
false ,
2016-02-25 18:57:25 +01:00
currUser . getUsername ( ) ,
currUser . getFullname ( ) ,
currUser . getUserAvatarId ( ) ) ;
2013-07-11 17:25:21 +02:00
return saveNotification ( not ) ;
}
2014-05-15 19:28:05 +02:00
2013-07-12 16:59:26 +02:00
/ * *
* { @inheritDoc }
* /
@Override
public boolean notifyEditedCalendarEvent ( String userIdToNotify , String eventTitle , String eventType , Date startDate , Date endingDate ) {
SimpleDateFormat spf = new SimpleDateFormat ( " EEE dd MMMMM, yyyy " ) ;
2014-05-15 19:28:05 +02:00
2013-07-12 16:59:26 +02:00
String endDateToDisplay = " " ;
if ( endingDate ! = null ) {
endDateToDisplay = " to " + spf . format ( endingDate ) ;
}
2014-05-15 19:28:05 +02:00
2013-07-12 16:59:26 +02:00
StringBuilder notificationText = new StringBuilder ( ) ;
2016-02-25 18:57:25 +01:00
notificationText . append ( " edited the following event in the <b> " ) . append ( currGroupName ) . append ( " </b> shared calendar: " ) // has done something
2013-07-12 16:59:26 +02:00
. append ( " <strong> " ) . append ( eventTitle ) . append ( " </strong><br /> " )
. append ( " <br /><strong> Time:</strong> " ) . append ( spf . format ( startDate ) ) . append ( endDateToDisplay ) . append ( " <br /> " )
. append ( " <br /><strong> Category: </strong> " ) . append ( eventType ) ;
2014-05-15 19:28:05 +02:00
2013-07-12 16:59:26 +02:00
Notification not = new Notification (
UUID . randomUUID ( ) . toString ( ) ,
NotificationType . CALENDAR_UPDATED_EVENT ,
userIdToNotify , //user no notify
" " , //
new Date ( ) ,
getApplicationUrl ( ) ,
notificationText . toString ( ) ,
false ,
2016-02-25 18:57:25 +01:00
currUser . getUsername ( ) ,
currUser . getFullname ( ) ,
currUser . getUserAvatarId ( ) ) ;
2013-07-12 16:59:26 +02:00
return saveNotification ( not ) ;
}
2013-07-12 17:06:34 +02:00
/ * *
* { @inheritDoc }
* /
@Override
public boolean notifyDeletedCalendarEvent ( String userIdToNotify , String eventTitle , String eventType , Date startDate , Date endingDate ) {
SimpleDateFormat spf = new SimpleDateFormat ( " EEE dd MMMMM, yyyy " ) ;
2014-05-15 19:28:05 +02:00
2013-07-12 17:06:34 +02:00
String endDateToDisplay = " " ;
if ( endingDate ! = null ) {
endDateToDisplay = " to " + spf . format ( endingDate ) ;
}
2014-05-15 19:28:05 +02:00
2013-07-12 17:06:34 +02:00
StringBuilder notificationText = new StringBuilder ( ) ;
2016-02-25 18:57:25 +01:00
notificationText . append ( " deleted the following event in the <b> " ) . append ( currGroupName ) . append ( " </b> shared calendar: " ) // has done something
2013-07-12 17:06:34 +02:00
. append ( " <strong> " ) . append ( eventTitle ) . append ( " </strong><br /> " )
. append ( " <br /><strong> Was planned:</strong> " ) . append ( spf . format ( startDate ) ) . append ( endDateToDisplay ) . append ( " <br /> " )
. append ( " <br /><strong> Category: </strong> " ) . append ( eventType ) ;
2014-05-15 19:28:05 +02:00
2013-07-12 17:06:34 +02:00
Notification not = new Notification (
UUID . randomUUID ( ) . toString ( ) ,
NotificationType . CALENDAR_DELETED_EVENT ,
userIdToNotify , //user no notify
" " , //
new Date ( ) ,
getApplicationUrl ( ) ,
notificationText . toString ( ) ,
false ,
2016-02-25 18:57:25 +01:00
currUser . getUsername ( ) ,
currUser . getFullname ( ) ,
currUser . getUserAvatarId ( ) ) ;
2013-07-12 17:06:34 +02:00
return saveNotification ( not ) ;
2015-06-11 14:08:50 +02:00
}
/ * *
* { @inheritDoc }
* /
@Override
2015-06-15 11:10:43 +02:00
public boolean notifyTDMTabularResourceSharing ( String userIdToNotify , String tabularResourceName , String encodedTabularResourceParams ) throws Exception {
Notification not = new Notification (
UUID . randomUUID ( ) . toString ( ) ,
NotificationType . TDM_TAB_RESOURCE_SHARE ,
userIdToNotify , //user no notify
tabularResourceName ,
new Date ( ) ,
getApplicationUrl ( ) + " ? " + encodedTabularResourceParams ,
" shared the Tabular Resource \" " + tabularResourceName + " \" with you " ,
false ,
2016-02-25 18:57:25 +01:00
currUser . getUsername ( ) ,
currUser . getFullname ( ) ,
currUser . getUserAvatarId ( ) ) ;
2015-06-15 11:10:43 +02:00
return saveNotification ( not ) ;
2015-06-11 14:08:50 +02:00
}
/ * *
* { @inheritDoc }
* /
@Override
2015-06-15 11:10:43 +02:00
public boolean notifyTDMObjectSharing ( String userIdToNotify , NotificationType type , String tdmObjectName , String encodedTabularResourceParams ) throws Exception {
2015-06-15 17:00:03 +02:00
if ( ! ( type = = NotificationType . TDM_RULE_SHARE | | type = = NotificationType . TDM_TEMPLATE_SHARE ) )
2015-06-15 11:10:43 +02:00
throw new IllegalArgumentException ( " Type must be either TDM_RULE_SHARE or TDM_TEMPLATE_SHARE " ) ;
2015-07-13 19:37:32 +02:00
2015-06-15 11:10:43 +02:00
String notificationText = " shared the Tabular Data Manager " ;
notificationText + = ( type = = NotificationType . TDM_RULE_SHARE ) ? " Rule " : " Template " ;
2015-06-18 11:27:49 +02:00
notificationText + = " \" " + tdmObjectName + " \" with you " ;
2015-07-13 19:37:32 +02:00
2015-06-15 11:10:43 +02:00
String url = getApplicationUrl ( ) ;
if ( encodedTabularResourceParams ! = null & & encodedTabularResourceParams . compareTo ( " " ) ! = 0 )
url + = " ? " + encodedTabularResourceParams ;
2015-07-13 19:37:32 +02:00
2015-06-15 11:10:43 +02:00
Notification not = new Notification (
UUID . randomUUID ( ) . toString ( ) ,
type ,
userIdToNotify , //user no notify
tdmObjectName ,
new Date ( ) ,
url ,
notificationText ,
false ,
2016-02-25 18:57:25 +01:00
currUser . getUsername ( ) ,
currUser . getFullname ( ) ,
currUser . getUserAvatarId ( ) ) ;
2015-07-13 19:37:32 +02:00
2015-06-15 11:10:43 +02:00
return saveNotification ( not ) ;
2015-06-11 14:08:50 +02:00
}
2012-12-07 15:06:26 +01:00
}