2013-02-13 18:39:33 +01:00
/ * *
2016-05-05 11:49:36 +02:00
*
2013-02-13 18:39:33 +01:00
* /
package org.gcube.portlets.user.workspace.server.notifications ;
2013-03-28 12:41:19 +01:00
import java.util.ArrayList ;
2013-02-13 18:39:33 +01:00
import java.util.List ;
2016-05-31 17:11:53 +02:00
import javax.servlet.http.HttpServletRequest ;
2016-11-25 12:03:25 +01:00
import javax.servlet.http.HttpSession ;
2016-05-31 17:11:53 +02:00
2013-10-04 13:58:07 +02:00
import org.apache.log4j.Logger ;
2013-02-13 18:39:33 +01:00
import org.gcube.applicationsupportlayer.social.NotificationsManager ;
2013-09-27 17:39:28 +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-10-04 13:58:07 +02:00
import org.gcube.common.scope.impl.ScopeBean ;
2013-02-13 18:39:33 +01:00
import org.gcube.portlets.user.workspace.client.model.InfoContactModel ;
2015-11-19 17:17:13 +01:00
import org.gcube.portlets.user.workspace.server.util.DifferenceBetweenInfoContactModel ;
2016-11-25 12:03:25 +01:00
import org.gcube.portlets.user.workspace.server.util.PortalContextInfo ;
2013-03-25 17:35:27 +01:00
import org.gcube.portlets.user.workspace.server.util.UserUtil ;
2013-06-13 18:44:46 +02:00
import org.gcube.portlets.user.workspace.server.util.WsUtil ;
2013-02-13 18:39:33 +01:00
/ * *
2015-11-05 11:23:01 +01:00
* The Class NotificationsProducer .
2013-02-13 18:39:33 +01:00
*
2015-11-05 11:23:01 +01:00
* @author Francesco Mangiacrapa francesco . mangiacrapa @isti.cnr.it
2013-02-13 18:39:33 +01:00
* /
public class NotificationsProducer {
2013-10-04 13:58:07 +02:00
protected ScopeBean scope ;
2016-05-05 11:49:36 +02:00
2013-10-04 13:58:07 +02:00
protected static Logger logger = Logger . getLogger ( NotificationsProducer . class ) ;
2016-05-05 11:49:36 +02:00
2013-02-13 18:39:33 +01:00
protected NotificationsManager notificationsMng ;
2016-11-25 12:03:25 +01:00
protected HttpSession httpSession ;
2013-02-13 18:39:33 +01:00
protected String userId ;
/ * *
2015-11-05 11:23:01 +01:00
* Instantiates a new notifications producer .
*
2016-11-25 12:03:25 +01:00
* @param httpServletRequest the http servlet request
2013-02-13 18:39:33 +01:00
* /
2016-11-25 12:03:25 +01:00
public NotificationsProducer ( HttpServletRequest httpServletRequest ) {
PortalContextInfo info = WsUtil . getPortalContext ( httpServletRequest ) ;
this . notificationsMng = WsUtil . getNotificationManager ( httpServletRequest ) ;
this . userId = info . getUsername ( ) ;
2013-02-13 18:39:33 +01:00
}
2015-11-05 11:23:01 +01:00
/ * *
* Gets the notifications mng .
*
* @return the notifications mng
* /
2013-02-13 18:39:33 +01:00
public NotificationsManager getNotificationsMng ( ) {
return notificationsMng ;
}
2015-11-05 11:23:01 +01:00
/ * *
* Sets the notification mng .
*
* @param notificationMng the new notification mng
* /
2013-02-13 18:39:33 +01:00
public void setNotificationMng ( NotificationsManager notificationMng ) {
this . notificationsMng = notificationMng ;
}
/ * *
2015-11-05 11:23:01 +01:00
* Runs a new thread to notify the contacts passed in input .
*
* @param listContacts the list contacts
* @param sharedFolder the shared folder
2013-02-13 18:39:33 +01:00
* /
2014-05-14 15:47:17 +02:00
public void notifyFolderSharing ( final List < InfoContactModel > listContacts , final WorkspaceSharedFolder sharedFolder ) {
2013-02-13 18:39:33 +01:00
new Thread ( ) {
@Override
public void run ( ) {
2016-05-05 11:49:36 +02:00
2013-10-04 13:58:07 +02:00
logger . trace ( " Send notifies folder sharing is running... " ) ;
2016-05-05 11:49:36 +02:00
2013-02-13 18:39:33 +01:00
for ( InfoContactModel infoContactModel : listContacts ) {
try {
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
2016-05-05 11:49:36 +02:00
if ( infoContactModel . getLogin ( ) . compareTo ( userId ) ! = 0 ) {
2015-11-19 15:53:55 +01:00
logger . debug ( " Sending notification new share folder " + sharedFolder . getName ( ) + " for user " + infoContactModel . getLogin ( ) ) ;
2016-05-05 11:49:36 +02:00
2013-02-25 19:03:53 +01:00
//DEBUG
2015-11-19 15:53:55 +01:00
// System.out.println("Sending notification new share folder "+sharedFolder.getName()+" for user "+infoContactModel.getLogin());
2013-02-27 19:17:22 +01:00
2013-03-25 11:14:26 +01:00
boolean notify = notificationsMng . notifyFolderSharing ( infoContactModel . getLogin ( ) , sharedFolder ) ;
2016-05-05 11:49:36 +02:00
2013-02-13 18:39:33 +01:00
if ( ! notify )
2013-10-04 13:58:07 +02:00
logger . error ( " An error occured when notify user: " + infoContactModel . getLogin ( ) ) ;
2013-02-26 11:37:55 +01:00
}
2013-02-13 18:39:33 +01:00
} catch ( Exception e ) {
2013-10-04 13:58:07 +02:00
logger . error ( " An error occured in notifyFolderSharing " , e ) ;
2014-05-09 17:48:30 +02:00
// e.printStackTrace();
2013-02-13 18:39:33 +01:00
}
}
2016-05-05 11:49:36 +02:00
2013-10-04 13:58:07 +02:00
logger . trace ( " notifies share folder is completed " ) ;
2013-02-13 18:39:33 +01:00
}
} . start ( ) ;
2016-05-05 11:49:36 +02:00
2013-02-13 18:39:33 +01:00
}
2016-05-05 11:49:36 +02:00
2013-02-27 19:17:22 +01:00
/ * *
2016-05-31 17:11:53 +02:00
* Runs a new thread to notify the updated ( add / remove ) contacts to sharing .
2015-11-05 11:23:01 +01:00
*
2013-02-27 19:17:22 +01:00
* @param listSharedContact - list of contacts already shared
2015-11-05 11:23:01 +01:00
* @param listSharingContact - list of " new " contacts to share
2013-02-27 19:17:22 +01:00
* @param sharedFolder - the shared folder
* /
2015-11-05 11:23:01 +01:00
public void notifyUpdatedUsersToSharing ( final List < InfoContactModel > listSharedContact , final List < InfoContactModel > listSharingContact , final WorkspaceSharedFolder sharedFolder ) {
2013-02-27 19:17:22 +01:00
new Thread ( ) {
@Override
public void run ( ) {
2016-05-05 11:49:36 +02:00
2013-03-25 17:35:27 +01:00
try {
2016-05-05 11:49:36 +02:00
2015-11-05 11:23:01 +01:00
//NEW USER SHARED
2015-11-19 17:17:13 +01:00
DifferenceBetweenInfoContactModel diff = new DifferenceBetweenInfoContactModel ( listSharingContact , listSharedContact ) ;
2016-05-05 11:49:36 +02:00
2015-11-05 11:23:01 +01:00
List < InfoContactModel > listNewContactsShared = diff . getDifferentsContacts ( ) ;
2016-05-05 11:49:36 +02:00
2015-11-19 15:53:55 +01:00
logger . info ( " list new contacts shared: " + listNewContactsShared . size ( ) ) ;
2016-05-05 11:49:36 +02:00
2015-11-05 11:23:01 +01:00
if ( listNewContactsShared . size ( ) > 0 ) {
2016-05-05 11:49:36 +02:00
2015-11-05 11:23:01 +01:00
if ( listNewContactsShared . size ( ) = = 1 ) { //CASE ONLY ONE CONTACS WAS ADDED
2016-05-05 11:49:36 +02:00
2015-11-05 11:23:01 +01:00
InfoContactModel infoContactModel = listNewContactsShared . get ( 0 ) ;
2016-05-05 11:49:36 +02:00
2015-11-05 11:23:01 +01:00
for ( InfoContactModel contact : listSharedContact ) { //NOTIFIES ALREADY SHARED CONTACTS THAT A NEW USER WAS ADDED
2016-05-05 11:49:36 +02:00
2013-03-25 17:35:27 +01:00
try {
2016-05-05 11:49:36 +02:00
2013-10-04 13:58:07 +02:00
logger . trace ( " Sending notification to user " + contact . getLogin ( ) + " , added user " + infoContactModel . getLogin ( ) + " to share folder " + sharedFolder . getName ( ) ) ;
2016-05-05 11:49:36 +02:00
2013-03-25 17:35:27 +01:00
//DEBUG
// System.out.println("Sending notification added user "+ infoContactModel.getLogin() +" to share folder "+sharedFolder.getName() + " for user "+contact.getLogin());
2016-05-05 11:49:36 +02:00
2013-03-25 17:35:27 +01:00
boolean notify = notificationsMng . notifyFolderAddedUser ( contact . getLogin ( ) , sharedFolder , infoContactModel . getLogin ( ) ) ;
2016-05-05 11:49:36 +02:00
2013-03-25 17:35:27 +01:00
if ( ! notify )
2013-10-04 13:58:07 +02:00
logger . error ( " An error occured when notifies user: " + contact . getLogin ( ) ) ;
2016-05-05 11:49:36 +02:00
2013-03-25 17:35:27 +01:00
} catch ( Exception e ) {
2013-10-04 13:58:07 +02:00
logger . error ( " An error occured in notifyFolderAddedUser " , e ) ;
2014-05-09 17:48:30 +02:00
// e.printStackTrace();
2013-03-25 17:35:27 +01:00
}
}
2016-05-05 11:49:36 +02:00
2013-03-28 12:41:19 +01:00
List < InfoContactModel > listCts = new ArrayList < InfoContactModel > ( ) ;
listCts . add ( infoContactModel ) ;
notifyFolderSharing ( listCts , sharedFolder ) ; //NOTIFIER NEW USER OF SHARING FOLDER
2016-05-05 11:49:36 +02:00
2015-11-05 11:23:01 +01:00
} else { //CASE MORE THEN ONE CONTACT WAS ADDED
2016-05-05 11:49:36 +02:00
2015-11-05 11:23:01 +01:00
List < String > listLogins = UserUtil . getListLoginByInfoContactModel ( listNewContactsShared ) ;
2016-05-05 11:49:36 +02:00
2013-03-25 17:35:27 +01:00
for ( InfoContactModel contact : listSharedContact ) { //NOTIFIES ALREADY SHARED CONTACTS THATH A NEW USER WAS ADDED
2016-05-05 11:49:36 +02:00
2013-03-25 17:35:27 +01:00
try {
2016-05-05 11:49:36 +02:00
2013-10-04 13:58:07 +02:00
logger . trace ( " Sending notification to user " + contact . getLogin ( ) + " , added " + listLogins . size ( ) + " users to share folder " + sharedFolder . getName ( ) ) ;
2016-05-05 11:49:36 +02:00
2013-03-25 17:35:27 +01:00
//DEBUG
// System.out.println("Sending notification added user "+ infoContactModel.getLogin() +" to share folder "+sharedFolder.getName() + " for user "+contact.getLogin());
2016-05-05 11:49:36 +02:00
2013-03-25 17:35:27 +01:00
boolean notify = notificationsMng . notifyFolderAddedUsers ( contact . getLogin ( ) , sharedFolder , listLogins ) ;
2016-05-05 11:49:36 +02:00
2013-03-25 17:35:27 +01:00
if ( ! notify )
2013-10-04 13:58:07 +02:00
logger . error ( " An error occured when notifies user: " + contact . getLogin ( ) ) ;
2016-05-05 11:49:36 +02:00
2013-03-25 17:35:27 +01:00
} catch ( Exception e ) {
2013-10-04 13:58:07 +02:00
logger . error ( " An error occured in notifyFolderAddedUser " , e ) ;
2014-05-09 17:48:30 +02:00
// e.printStackTrace();
2013-02-27 19:17:22 +01:00
}
}
2016-05-05 11:49:36 +02:00
2015-11-05 11:23:01 +01:00
notifyFolderSharing ( listNewContactsShared , sharedFolder ) ; //NOTIFIER NEW USER OF SHARING FOLDER
2016-05-05 11:49:36 +02:00
2013-03-25 17:35:27 +01:00
}
}
2016-05-05 11:49:36 +02:00
2015-11-05 11:23:01 +01:00
//USER REMOVED FROM SHARE
2015-11-19 17:17:13 +01:00
DifferenceBetweenInfoContactModel diff2 = new DifferenceBetweenInfoContactModel ( listSharedContact , listSharingContact ) ;
2016-05-05 11:49:36 +02:00
2015-11-05 11:23:01 +01:00
List < InfoContactModel > listRemovedUsersFromShare = diff2 . getDifferentsContacts ( ) ;
2016-05-05 11:49:36 +02:00
2015-11-19 15:53:55 +01:00
logger . info ( " list removed contacts from share: " + listRemovedUsersFromShare . size ( ) ) ;
2016-05-05 11:49:36 +02:00
2015-11-05 11:23:01 +01:00
if ( listRemovedUsersFromShare . size ( ) > 0 ) {
2016-05-05 11:49:36 +02:00
2015-11-05 11:23:01 +01:00
for ( InfoContactModel contact : listRemovedUsersFromShare )
notifyFolderRemovedUser ( contact , sharedFolder ) ;
}
2016-05-05 11:49:36 +02:00
2013-02-27 19:17:22 +01:00
} catch ( Exception e ) {
2013-10-04 13:58:07 +02:00
logger . error ( " An error occured in notifyAddedUserToSharing " , e ) ;
2014-05-09 17:48:30 +02:00
// e.printStackTrace();
2013-02-27 19:17:22 +01:00
}
}
} . start ( ) ;
2016-05-05 11:49:36 +02:00
2013-02-27 19:17:22 +01:00
}
2016-05-05 11:49:36 +02:00
2013-03-25 17:35:27 +01:00
2013-02-13 18:39:33 +01:00
/ * *
2015-11-05 11:23:01 +01:00
* Runs a new thread to notify the contacts passed in input .
*
* @param listContacts the list contacts
* @param unShareFolderId the un share folder id
* @param unSharedFolderName the un shared folder name
2013-02-13 18:39:33 +01:00
* /
2014-09-29 18:11:33 +02:00
public void notifyFolderUnSharing ( final List < InfoContactModel > listContacts , final String unShareFolderId , final String unSharedFolderName ) {
2013-02-13 18:39:33 +01:00
2016-05-05 11:49:36 +02:00
2013-02-13 18:39:33 +01:00
new Thread ( ) {
@Override
public void run ( ) {
2016-05-05 11:49:36 +02:00
2013-02-26 11:37:55 +01:00
// printContacts(listContacts);
2013-10-04 13:58:07 +02:00
logger . trace ( " Send notifies folder un share is running... " ) ;
2016-05-05 11:49:36 +02:00
2013-02-13 18:39:33 +01:00
for ( InfoContactModel infoContactModel : listContacts ) {
try {
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
2013-03-25 11:14:26 +01:00
if ( infoContactModel . getLogin ( ) . compareTo ( userId ) ! = 0 ) {
2016-05-05 11:49:36 +02:00
2014-09-29 18:11:33 +02:00
logger . trace ( " Sending notification to user " + infoContactModel . getLogin ( ) + " unshare folder " + unSharedFolderName ) ;
2016-05-05 11:49:36 +02:00
2013-02-25 19:03:53 +01:00
//DEBUG
2014-05-09 17:48:30 +02:00
// System.out.println("Sending notification to user "+infoContactModel.getLogin() +" un shared folder "+unSharedFolder.getName());
2014-09-29 18:11:33 +02:00
// boolean notify = notificationsMng.notifyFolderRemovedUser(infoContactModel.getLogin(), (WorkspaceSharedFolder) unSharedFolder);
2016-05-05 11:49:36 +02:00
2014-09-29 18:11:33 +02:00
boolean notify = notificationsMng . notifyFolderUnsharing ( infoContactModel . getLogin ( ) , unShareFolderId , unSharedFolderName ) ;
2013-02-13 18:39:33 +01:00
if ( ! notify )
2013-10-04 13:58:07 +02:00
logger . error ( " An error occured when notifies user: " + infoContactModel . getLogin ( ) ) ;
2013-02-26 11:37:55 +01:00
}
2013-02-13 18:39:33 +01:00
} catch ( Exception e ) {
2013-10-04 13:58:07 +02:00
logger . error ( " An error occured in notifyFolderUnSharing " , e ) ;
2014-05-09 17:48:30 +02:00
// e.printStackTrace();
2013-02-13 18:39:33 +01:00
}
}
2016-05-05 11:49:36 +02:00
2013-10-04 13:58:07 +02:00
logger . trace ( " notifies of un share notifications is completed " ) ;
2013-02-13 18:39:33 +01:00
}
} . start ( ) ;
2016-05-05 11:49:36 +02:00
2013-02-13 18:39:33 +01:00
}
2015-11-05 11:23:01 +01:00
/ * *
* Notify folder removed user .
*
* @param userUnShared the user un shared
2016-05-31 17:11:53 +02:00
* @param shareFolder the share folder
2015-11-05 11:23:01 +01:00
* /
public void notifyFolderRemovedUser ( final InfoContactModel userUnShared , final WorkspaceSharedFolder shareFolder ) {
new Thread ( ) {
@Override
public void run ( ) {
2016-05-05 11:49:36 +02:00
2015-11-05 11:23:01 +01:00
logger . trace ( " Send notifies removed user from shared folder is running... " ) ;
try {
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
if ( userUnShared . getLogin ( ) . compareTo ( userId ) ! = 0 ) {
2016-05-05 11:49:36 +02:00
2015-11-19 15:53:55 +01:00
logger . debug ( " Sending notification to user " + userUnShared . getLogin ( ) + " unshared from folder " + shareFolder . getName ( ) ) ;
2016-05-05 11:49:36 +02:00
boolean notify = notificationsMng . notifyFolderRemovedUser ( userUnShared . getLogin ( ) , shareFolder ) ;
2015-11-05 11:23:01 +01:00
if ( ! notify )
logger . error ( " An error occured when notifies user: " + userUnShared . getLogin ( ) ) ;
}
2016-05-05 11:49:36 +02:00
2015-11-05 11:23:01 +01:00
} catch ( Exception e ) {
logger . error ( " An error occured in notifyFolderRemovedUser " , e ) ;
}
2016-05-05 11:49:36 +02:00
2015-11-05 11:23:01 +01:00
logger . trace ( " notifies of un unshare user is completed " ) ;
}
} . start ( ) ;
2016-05-05 11:49:36 +02:00
2015-11-05 11:23:01 +01:00
}
2016-05-05 11:49:36 +02:00
2013-02-26 11:37:55 +01:00
/ * *
2015-11-05 11:23:01 +01:00
* Runs a new thread to notify the contacts passed in input .
*
* @param listContacts the list contacts
* @param workspaceItem the workspace item
* @param sharedFolder the shared folder
2013-02-26 11:37:55 +01:00
* /
2014-05-14 15:47:17 +02:00
public void notifyAddedItemToSharing ( final List < InfoContactModel > listContacts , final WorkspaceItem workspaceItem , final WorkspaceSharedFolder sharedFolder ) {
2013-02-26 11:37:55 +01:00
new Thread ( ) {
@Override
public void run ( ) {
2016-05-05 11:49:36 +02:00
2013-02-26 11:37:55 +01:00
// printContacts(listContacts);
2013-10-04 13:58:07 +02:00
logger . trace ( " Send notifies added item in sharedfolder is running... " ) ;
2016-05-05 11:49:36 +02:00
2013-02-27 19:17:22 +01:00
//DEBUG
System . out . println ( " Send notifies added item in sharedfolder is running... " ) ;
2016-05-05 11:49:36 +02:00
2013-02-26 11:37:55 +01:00
for ( InfoContactModel infoContactModel : listContacts ) {
try {
2013-02-13 18:39:33 +01:00
2013-02-26 11:37:55 +01:00
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
2016-05-05 11:49:36 +02:00
if ( infoContactModel . getLogin ( ) . compareTo ( userId ) ! = 0 ) {
logger . info ( " Sending notification to user " + infoContactModel . getLogin ( ) + " added item [id: " + workspaceItem . getId ( ) + " ] name: " + workspaceItem . getName ( ) + " in shared folder " + sharedFolder . getName ( ) ) ;
2013-02-26 11:37:55 +01:00
//DEBUG
2013-03-25 11:14:26 +01:00
// System.out.println("Send notify folder un share user "+infoContactModel.getLogin());
2016-05-05 11:49:36 +02:00
2013-03-25 11:14:26 +01:00
boolean notify = notificationsMng . notifyAddedItem ( infoContactModel . getLogin ( ) , workspaceItem , sharedFolder ) ;
2013-02-27 19:17:22 +01:00
if ( ! notify ) {
2013-10-04 13:58:07 +02:00
logger . error ( " An error occured when notify user: " + infoContactModel . getLogin ( ) ) ;
2013-02-27 19:17:22 +01:00
//DEBUG
2014-05-09 17:48:30 +02:00
// System.out.println("An error occured when notify user: "+infoContactModel.getLogin());
2013-02-27 19:17:22 +01:00
}
2013-02-26 11:37:55 +01:00
}
} catch ( Exception e ) {
2013-10-04 13:58:07 +02:00
logger . error ( " An error occured in notifyAddedItemToSharing " , e ) ;
2014-05-09 17:48:30 +02:00
// e.printStackTrace();
2013-02-26 11:37:55 +01:00
}
}
2016-05-05 11:49:36 +02:00
2013-10-04 13:58:07 +02:00
logger . trace ( " notifies of added item in shared folder is completed " ) ;
2016-05-05 11:49:36 +02:00
2013-02-27 19:17:22 +01:00
//DEBUG
2014-05-09 17:48:30 +02:00
// System.out.println("notifies of added item in shared folder is completed");
2013-02-26 11:37:55 +01:00
}
} . start ( ) ;
}
2016-05-05 11:49:36 +02:00
2013-07-01 12:19:53 +02:00
/ * *
2015-11-05 11:23:01 +01:00
* Runs a new thread to notify the contacts passed in input .
*
* @param listContacts the list contacts
* @param workspaceItem the workspace item
* @param sharedFolder the shared folder
2013-07-01 12:19:53 +02:00
* /
2014-05-14 15:47:17 +02:00
public void notifyUpdatedItemToSharing ( final List < InfoContactModel > listContacts , final WorkspaceItem workspaceItem , final WorkspaceSharedFolder sharedFolder ) {
2013-07-01 12:19:53 +02:00
new Thread ( ) {
@Override
public void run ( ) {
2016-05-05 11:49:36 +02:00
2013-07-01 12:19:53 +02:00
// printContacts(listContacts);
2013-10-04 13:58:07 +02:00
logger . trace ( " Send notifies updated item in shared folder is running... " ) ;
2016-05-05 11:49:36 +02:00
2013-07-01 12:19:53 +02:00
//DEBUG
2014-05-09 17:48:30 +02:00
// System.out.println("Send notifies updated item in shared folder is running...");
2016-05-05 11:49:36 +02:00
2013-07-01 12:19:53 +02:00
for ( InfoContactModel infoContactModel : listContacts ) {
try {
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
2016-05-05 11:49:36 +02:00
if ( infoContactModel . getLogin ( ) . compareTo ( userId ) ! = 0 ) {
2013-10-04 13:58:07 +02:00
logger . trace ( " Sending notification to user " + infoContactModel . getLogin ( ) + " updated item " + workspaceItem . getName ( ) + " in shared folder " + sharedFolder . getName ( ) ) ;
2016-05-05 11:49:36 +02:00
2013-07-01 12:19:53 +02:00
//DEBUG
2014-05-09 17:48:30 +02:00
// System.out.println("Sending notification to user "+infoContactModel.getLogin() +" updated item "+workspaceItem.getName()+" in shared folder "+sharedFolder.getName());
2016-05-05 11:49:36 +02:00
2013-07-01 12:19:53 +02:00
//DEBUG
// System.out.println("Send notify folder un share user "+infoContactModel.getLogin());
2016-05-05 11:49:36 +02:00
2013-07-01 12:19:53 +02:00
boolean notify = notificationsMng . notifyUpdatedItem ( infoContactModel . getLogin ( ) , workspaceItem , sharedFolder ) ;
if ( ! notify ) {
2013-10-04 13:58:07 +02:00
logger . error ( " An error updated when notify user: " + infoContactModel . getLogin ( ) ) ;
2013-07-01 12:19:53 +02:00
//DEBUG
2014-05-09 17:48:30 +02:00
// System.out.println("An error updated when notify user: "+infoContactModel.getLogin());
2013-07-01 12:19:53 +02:00
}
}
} catch ( Exception e ) {
2013-10-04 13:58:07 +02:00
logger . error ( " An error updated in notifyAddedItemToSharing " , e ) ;
2013-07-01 12:19:53 +02:00
e . printStackTrace ( ) ;
}
}
2016-05-05 11:49:36 +02:00
2013-10-04 13:58:07 +02:00
logger . trace ( " notifies of updated item in shared folder is completed " ) ;
2016-05-05 11:49:36 +02:00
2013-07-01 12:19:53 +02:00
//DEBUG
2014-05-09 17:48:30 +02:00
// System.out.println("notifies of updated item in shared folder is completed");
2013-07-01 12:19:53 +02:00
}
} . start ( ) ;
}
2016-05-05 11:49:36 +02:00
2013-02-26 11:37:55 +01:00
/ * *
2015-11-05 11:23:01 +01:00
* Runs a new thread to notify the contacts passed in input .
*
* @param listContacts the list contacts
* @param workspaceItem the workspace item
* @param sharedFolder the shared folder
2013-02-26 11:37:55 +01:00
* /
2014-05-14 15:47:17 +02:00
public void notifyMovedItemToSharing ( final List < InfoContactModel > listContacts , final WorkspaceItem workspaceItem , final WorkspaceSharedFolder sharedFolder ) {
2013-02-26 11:37:55 +01:00
2016-05-05 11:49:36 +02:00
2013-02-26 11:37:55 +01:00
new Thread ( ) {
@Override
public void run ( ) {
2016-05-05 11:49:36 +02:00
2013-10-04 13:58:07 +02:00
logger . trace ( " Sending notification remove item in shared folder is running... " ) ;
2013-02-26 11:37:55 +01:00
// printContacts(listContacts);
2016-05-05 11:49:36 +02:00
2013-06-13 18:44:46 +02:00
try {
2016-05-05 11:49:36 +02:00
2013-06-13 18:44:46 +02:00
if ( NotificationsUtil . checkIsRootFolderShared ( workspaceItem . getId ( ) , sharedFolder . getId ( ) ) ) {
2013-10-04 13:58:07 +02:00
logger . trace ( " Notification isn't sent because the event is on root shared folder " ) ;
2013-06-13 18:44:46 +02:00
return ;
}
2016-05-05 11:49:36 +02:00
2013-06-13 18:44:46 +02:00
} catch ( InternalErrorException e1 ) {
2013-10-04 13:58:07 +02:00
logger . error ( " An error occurred in checkIsRootFolderShared " , e1 ) ;
2013-06-13 18:44:46 +02:00
return ;
}
2016-05-05 11:49:36 +02:00
2013-10-04 13:58:07 +02:00
logger . trace ( " Sending notification moved item in shared folder is running... " ) ;
2016-05-05 11:49:36 +02:00
2014-05-09 17:48:30 +02:00
// System.out.println("Sending notification moved item in shared folder is running...");
2016-05-05 11:49:36 +02:00
2013-02-26 11:37:55 +01:00
for ( InfoContactModel infoContactModel : listContacts ) {
try {
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
2013-03-25 11:14:26 +01:00
if ( infoContactModel . getLogin ( ) . compareTo ( userId ) ! = 0 ) {
2016-05-05 11:49:36 +02:00
2013-10-04 13:58:07 +02:00
logger . trace ( " Sending notification to user " + infoContactModel . getLogin ( ) + " moved item " + workspaceItem . getName ( ) + " in shared folder " + sharedFolder . getName ( ) ) ;
2016-05-05 11:49:36 +02:00
2013-02-27 19:17:22 +01:00
//DEBUG
2014-05-09 17:48:30 +02:00
// System.out.println("Sending notification to user "+infoContactModel.getLogin() +" moved item "+workspaceItem.getName()+" in shared folder "+sharedFolder.getName());
2013-02-27 19:17:22 +01:00
2013-06-14 15:30:40 +02:00
boolean notify = notificationsMng . notifyMovedItem ( infoContactModel . getLogin ( ) , workspaceItem , sharedFolder ) ;
2013-06-13 18:44:46 +02:00
2013-02-27 19:17:22 +01:00
if ( ! notify ) {
2013-10-04 13:58:07 +02:00
logger . error ( " An error occured when notify user: " + infoContactModel . getLogin ( ) ) ;
2016-05-05 11:49:36 +02:00
2013-02-27 19:17:22 +01:00
//DEBUG
2014-05-09 17:48:30 +02:00
// System.out.println("An error occured when notify user: "+infoContactModel.getLogin());
2013-02-27 19:17:22 +01:00
}
2013-02-26 11:37:55 +01:00
}
} catch ( Exception e ) {
2013-10-04 13:58:07 +02:00
logger . error ( " An error occurred in notifyMovedItemToSharing " , e ) ;
2013-02-26 11:37:55 +01:00
e . printStackTrace ( ) ;
}
}
2016-05-05 11:49:36 +02:00
2013-10-04 13:58:07 +02:00
logger . trace ( " notifies of moved item in shared folder is completed " ) ;
2016-05-05 11:49:36 +02:00
2013-02-27 19:17:22 +01:00
//DEBUG
2014-05-09 17:48:30 +02:00
// System.out.println("notifies of moved item in shared folder is completed");
2013-02-26 11:37:55 +01:00
}
2016-05-05 11:49:36 +02:00
2013-06-13 18:44:46 +02:00
2013-02-26 11:37:55 +01:00
} . start ( ) ;
2013-02-27 19:17:22 +01:00
2013-02-26 11:37:55 +01:00
}
2016-05-05 11:49:36 +02:00
2013-06-13 18:44:46 +02:00
/ * *
2015-11-05 11:23:01 +01:00
* Runs a new thread to notify the contacts passed in input .
*
* @param listContacts the list contacts
* @param itemName the item name
* @param sharedFolder the shared folder
2013-06-13 18:44:46 +02:00
* /
2014-05-14 15:47:17 +02:00
public void notifyRemovedItemToSharing ( final List < InfoContactModel > listContacts , final String itemName , final WorkspaceSharedFolder sharedFolder ) {
2013-06-13 18:44:46 +02:00
2016-05-05 11:49:36 +02:00
2013-06-13 18:44:46 +02:00
new Thread ( ) {
@Override
public void run ( ) {
2016-05-05 11:49:36 +02:00
2013-10-04 13:58:07 +02:00
logger . trace ( " Sending notification remove item in shared folder is running... " ) ;
2013-06-13 18:44:46 +02:00
// printContacts(listContacts);
2016-05-05 11:49:36 +02:00
2013-06-13 18:44:46 +02:00
if ( itemName = = null | | itemName . isEmpty ( ) ) {
2013-10-04 13:58:07 +02:00
logger . trace ( " Notification isn't sent - itemName is null or empty " ) ;
2013-06-13 18:44:46 +02:00
return ;
}
2016-05-05 11:49:36 +02:00
2013-06-13 18:44:46 +02:00
if ( sharedFolder = = null ) {
2013-10-04 13:58:07 +02:00
logger . trace ( " Notification isn't sent - sharedFolder is null " ) ;
2013-06-13 18:44:46 +02:00
}
2016-05-05 11:49:36 +02:00
2013-10-04 13:58:07 +02:00
logger . trace ( " Sending notification removed item in shared folder is running... " ) ;
2016-05-05 11:49:36 +02:00
2014-05-09 17:48:30 +02:00
// System.out.println("Sending notification removed item in shared folder is running...");
2016-05-05 11:49:36 +02:00
2013-06-13 18:44:46 +02:00
for ( InfoContactModel infoContactModel : listContacts ) {
try {
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
if ( infoContactModel . getLogin ( ) . compareTo ( userId ) ! = 0 ) {
2016-05-05 11:49:36 +02:00
2013-10-04 13:58:07 +02:00
logger . trace ( " Sending notification to user " + infoContactModel . getLogin ( ) + " removed item " + itemName + " in shared folder " + sharedFolder . getName ( ) ) ;
2016-05-05 11:49:36 +02:00
2013-06-13 18:44:46 +02:00
//DEBUG
2014-05-09 17:48:30 +02:00
// System.out.println("Sending notification to user "+infoContactModel.getLogin() +" removed item "+itemName+" in shared folder "+sharedFolder.getName());
2013-06-13 18:44:46 +02:00
2013-06-14 15:30:40 +02:00
boolean notify = notificationsMng . notifyRemovedItem ( infoContactModel . getLogin ( ) , itemName , sharedFolder ) ;
2013-06-13 18:44:46 +02:00
2013-06-14 15:30:40 +02:00
if ( ! notify ) {
2013-10-04 13:58:07 +02:00
logger . error ( " An error occured when notify user: " + infoContactModel . getLogin ( ) ) ;
2016-05-05 11:49:36 +02:00
2013-06-13 18:44:46 +02:00
//DEBUG
2014-05-09 17:48:30 +02:00
// System.out.println("An error occured when notify user: "+infoContactModel.getLogin());
2013-06-14 15:30:40 +02:00
}
2013-06-13 18:44:46 +02:00
}
} catch ( Exception e ) {
2013-10-04 13:58:07 +02:00
logger . error ( " An error occurred in notifyRemovedItemToSharing " , e ) ;
2014-05-09 17:48:30 +02:00
// e.printStackTrace();
2013-06-13 18:44:46 +02:00
}
}
2016-05-05 11:49:36 +02:00
2013-10-04 13:58:07 +02:00
logger . trace ( " notifies of moved item in shared folder is completed " ) ;
2016-05-05 11:49:36 +02:00
2013-06-13 18:44:46 +02:00
//DEBUG
2014-05-09 17:48:30 +02:00
// System.out.println("notifies of moved item in shared folder is completed");
2013-06-13 18:44:46 +02:00
}
2014-05-09 17:48:30 +02:00
} . start ( ) ;
}
2016-05-05 11:49:36 +02:00
2014-05-09 17:48:30 +02:00
/ * *
2015-11-05 11:23:01 +01:00
* Runs a new thread to notify the contacts passed in input .
*
* @param listContacts the list contacts
* @param folderNameDeleted the folder name deleted
2014-05-09 17:48:30 +02:00
* /
public void notifySharedFolderDeleted ( final List < InfoContactModel > listContacts , final String folderNameDeleted ) {
2013-06-13 18:44:46 +02:00
2016-05-05 11:49:36 +02:00
2014-05-09 17:48:30 +02:00
new Thread ( ) {
@Override
public void run ( ) {
2016-05-05 11:49:36 +02:00
2014-05-09 17:48:30 +02:00
// printContacts(listContacts);
logger . trace ( " Send notifies shared folder deleted is running... " ) ;
2016-05-05 11:49:36 +02:00
2014-05-09 17:48:30 +02:00
for ( InfoContactModel infoContactModel : listContacts ) {
try {
2013-06-13 18:44:46 +02:00
2014-05-09 17:48:30 +02:00
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
if ( infoContactModel . getLogin ( ) . compareTo ( userId ) ! = 0 ) {
2016-05-05 11:49:36 +02:00
2014-05-09 17:48:30 +02:00
logger . trace ( " Sending notification to user " + infoContactModel . getLogin ( ) + " deleted shared folder " + folderNameDeleted ) ;
2016-05-05 11:49:36 +02:00
2014-05-09 17:48:30 +02:00
//DEBUG
System . out . println ( " Sending notification to user " + infoContactModel . getLogin ( ) + " deleted shared folder " + folderNameDeleted ) ;
2016-05-05 11:49:36 +02:00
2014-05-09 17:48:30 +02:00
//TODO
// boolean notify = notificationsMng.
2016-05-05 11:49:36 +02:00
2014-05-09 17:48:30 +02:00
// if(!notify)
// logger.error("An error occured when notifies user: "+infoContactModel.getLogin());
}
} catch ( Exception e ) {
logger . error ( " An error occured in notifySharedFolderDeleted " , e ) ;
// e.printStackTrace();
}
}
2016-05-05 11:49:36 +02:00
2014-05-09 17:48:30 +02:00
logger . trace ( " notifies of deleted shared foder is completed " ) ;
}
2013-06-13 18:44:46 +02:00
2014-05-09 17:48:30 +02:00
} . start ( ) ;
2016-05-05 11:49:36 +02:00
2013-06-13 18:44:46 +02:00
}
2016-05-05 11:49:36 +02:00
2014-09-30 12:13:26 +02:00
/ * *
2015-11-05 11:23:01 +01:00
* Runs a new thread to notify the contacts passed in input .
*
* @param userToNotify the user to notify
* @param sharedFolder the shared folder
2014-09-30 12:13:26 +02:00
* /
public void notifyAdministratorUpgrade ( final InfoContactModel userToNotify , final WorkspaceSharedFolder sharedFolder ) {
new Thread ( ) {
@Override
public void run ( ) {
2016-05-05 11:49:36 +02:00
2014-09-30 12:13:26 +02:00
// printContacts(listContacts);
logger . trace ( " Send notifies administrator upgrade is running... " ) ;
if ( userToNotify = = null | | userToNotify . getLogin ( ) = = null ) {
logger . warn ( " Notification abort user to notify is null... " ) ;
return ;
}
2016-05-05 11:49:36 +02:00
2014-09-30 12:13:26 +02:00
if ( sharedFolder = = null ) {
logger . warn ( " Notification abort sharedFolder to notify is null... " ) ;
return ;
}
try {
String login = userToNotify . getLogin ( ) ;
logger . trace ( " Send notifies administrator upgrade for login: " + login ) ;
2016-05-05 11:49:36 +02:00
2014-09-30 12:13:26 +02:00
boolean notify = notificationsMng . notifyAdministratorUpgrade ( login , sharedFolder ) ;
logger . trace ( " Notification sent correctly? " + notify ) ;
} catch ( Exception e ) {
logger . error ( " An error occured in notifyAdministratorUpgrade " , e ) ;
}
2016-05-05 11:49:36 +02:00
2014-09-30 12:13:26 +02:00
logger . trace ( " notifies of administrator upgrade completed " ) ;
}
} . start ( ) ;
2016-05-05 11:49:36 +02:00
2014-09-30 12:13:26 +02:00
}
2016-05-05 11:49:36 +02:00
2014-09-30 12:13:26 +02:00
/ * *
2015-11-05 11:23:01 +01:00
* Runs a new thread to notify the contacts passed in input .
*
* @param userToNotify the user to notify
* @param sharedFolder the shared folder
2014-09-30 12:13:26 +02:00
* /
public void notifyAdministratorDowngrade ( final InfoContactModel userToNotify , final WorkspaceSharedFolder sharedFolder ) {
new Thread ( ) {
@Override
public void run ( ) {
2016-05-05 11:49:36 +02:00
2014-09-30 12:13:26 +02:00
// printContacts(listContacts);
logger . trace ( " Send notifies administrator Downgrade is running... " ) ;
if ( userToNotify = = null | | userToNotify . getLogin ( ) = = null ) {
logger . warn ( " Notification abort user to notify is null... " ) ;
return ;
}
2016-05-05 11:49:36 +02:00
2014-09-30 12:13:26 +02:00
if ( sharedFolder = = null ) {
logger . warn ( " Notification abort sharedFolder to notify is null... " ) ;
return ;
}
try {
String login = userToNotify . getLogin ( ) ;
logger . trace ( " Send notifies administrator Downgrade for login: " + login ) ;
2016-05-05 11:49:36 +02:00
2014-09-30 12:13:26 +02:00
boolean notify = notificationsMng . notifyAdministratorDowngrade ( login , sharedFolder ) ;
logger . trace ( " Notification sent correctly? " + notify ) ;
} catch ( Exception e ) {
logger . error ( " An error occured in notifyAdministratorDowngrade " , e ) ;
}
2016-05-05 11:49:36 +02:00
2014-09-30 12:13:26 +02:00
logger . trace ( " notifies of administrator Downgrade completed " ) ;
}
} . start ( ) ;
2016-05-05 11:49:36 +02:00
2014-09-30 12:13:26 +02:00
}
2013-02-26 11:37:55 +01:00
//DEBUG
2015-11-05 11:23:01 +01:00
/ * *
* Prints the contacts .
*
* @param listContacts the list contacts
* /
2013-02-13 18:39:33 +01:00
private void printContacts ( List < InfoContactModel > listContacts ) {
2016-05-05 11:49:36 +02:00
2013-02-13 18:39:33 +01:00
System . out . println ( " Print contacts " ) ;
for ( InfoContactModel infoContactModel : listContacts ) {
System . out . println ( infoContactModel ) ;
}
System . out . println ( " End print contacts " ) ;
}
}