2014-02-25 15:58:42 +01:00
package org.gcube.portlets.widgets.workspacesharingwidget.server.notifications ;
2014-06-23 17:02:57 +02:00
import java.util.ArrayList ;
2014-02-25 15:58:42 +01:00
import java.util.List ;
2014-06-23 17:02:57 +02:00
import org.apache.log4j.Logger ;
2014-02-25 15:58:42 +01:00
import org.gcube.application.framework.core.session.ASLSession ;
import org.gcube.application.framework.core.session.SessionManager ;
import org.gcube.applicationsupportlayer.social.NotificationsManager ;
2014-06-23 17:02:57 +02:00
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException ;
2014-02-25 15:58:42 +01:00
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem ;
import org.gcube.common.homelibrary.home.workspace.WorkspaceSharedFolder ;
import org.gcube.common.scope.impl.ScopeBean ;
2014-06-23 17:02:57 +02:00
import org.gcube.portlets.widgets.workspacesharingwidget.server.util.DiffereceBeetweenInfoContactModel ;
import org.gcube.portlets.widgets.workspacesharingwidget.server.util.UserUtil ;
2014-02-25 15:58:42 +01:00
import org.gcube.portlets.widgets.workspacesharingwidget.server.util.WsUtil ;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel ;
/ * *
*
* @author Francesco Mangiacrapa francesco . mangiacrapa @isti.cnr.it
*
* /
public class NotificationsProducer {
protected ScopeBean scope ;
2014-06-23 17:02:57 +02:00
protected static Logger logger = Logger . getLogger ( NotificationsProducer . class ) ;
2014-02-25 15:58:42 +01:00
protected NotificationsManager notificationsMng ;
protected ASLSession aslSession ;
protected String userId ;
/ * *
*
* @param aslSession
* /
public NotificationsProducer ( ASLSession aslSession ) {
this . notificationsMng = WsUtil . getNotificationManager ( aslSession ) ;
this . aslSession = aslSession ;
this . userId = aslSession . getUsername ( ) ;
}
public NotificationsManager getNotificationsMng ( ) {
return notificationsMng ;
}
public void setNotificationMng ( NotificationsManager notificationMng ) {
this . notificationsMng = notificationMng ;
}
public ASLSession getAslSession ( ) {
return aslSession ;
}
2014-06-23 17:02:57 +02:00
2014-02-25 15:58:42 +01:00
/ * *
* Runs a new thread to notify the contacts passed in input
* @param listContacts
* @param sharedFolder
* /
2014-06-23 17:02:57 +02:00
public void notifyFolderSharing ( final List < InfoContactModel > listContacts , final WorkspaceSharedFolder sharedFolder ) {
2014-02-25 15:58:42 +01:00
new Thread ( ) {
@Override
public void run ( ) {
2014-06-23 17:02:57 +02:00
logger . trace ( " Send notifies folder sharing is running... " ) ;
2014-02-25 15:58:42 +01:00
for ( InfoContactModel infoContactModel : listContacts ) {
try {
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
if ( infoContactModel . getLogin ( ) . compareTo ( userId ) ! = 0 ) {
2014-06-23 17:02:57 +02:00
logger . trace ( " Sending notification new share folder " + sharedFolder . getName ( ) + " for user " + infoContactModel . getLogin ( ) ) ;
2014-02-25 15:58:42 +01:00
//DEBUG
System . out . println ( " Sending notification new share folder " + sharedFolder . getName ( ) + " for user " + infoContactModel . getLogin ( ) ) ;
boolean notify = notificationsMng . notifyFolderSharing ( infoContactModel . getLogin ( ) , sharedFolder ) ;
if ( ! notify )
logger . error ( " An error occured when notify user: " + infoContactModel . getLogin ( ) ) ;
}
} catch ( Exception e ) {
logger . error ( " An error occured in notifyFolderSharing " , e ) ;
2014-06-23 17:02:57 +02:00
// e.printStackTrace();
2014-02-25 15:58:42 +01:00
}
}
2014-06-23 17:02:57 +02:00
logger . trace ( " notifies share folder is completed " ) ;
2014-02-25 15:58:42 +01:00
}
} . start ( ) ;
2014-06-23 17:02:57 +02:00
2014-02-25 15:58:42 +01:00
}
/ * *
* Runs a new thread to notify the contacts passed in input
* @param folderItem
* @param listContacts
* @param sharedFolder
* /
public void notifyFolderRenamed ( final List < InfoContactModel > listSharedContact , final WorkspaceItem folderItem , final String itemOldName , final String itemNewName , final String idsharedFolder ) {
2014-06-23 17:02:57 +02:00
2014-02-25 15:58:42 +01:00
new Thread ( ) {
@Override
public void run ( ) {
2014-06-23 17:02:57 +02:00
logger . trace ( " Send notifies shared folder was renamed is running... " ) ;
2014-02-25 15:58:42 +01:00
try {
if ( NotificationsUtil . checkIsRootFolderShared ( folderItem . getId ( ) , idsharedFolder ) ) {
2014-06-23 17:02:57 +02:00
logger . trace ( " Notification isn't sent because the event is on root shared folder " ) ;
2014-02-25 15:58:42 +01:00
return ;
}
} catch ( InternalErrorException e1 ) {
logger . error ( " An error occurred in checkIsRootFolderShared " , e1 ) ;
return ;
}
for ( InfoContactModel infoContactModel : listSharedContact ) {
try {
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
if ( infoContactModel . getLogin ( ) . compareTo ( userId ) ! = 0 ) {
2014-06-23 17:02:57 +02:00
logger . trace ( " Sending notification share folder " + itemOldName + " was renamed as " + itemNewName + " for user " + infoContactModel . getLogin ( ) ) ;
2014-02-25 15:58:42 +01:00
//DEBUG
System . out . println ( " Sending notification share folder " + itemOldName + " was renamed as " + itemNewName + " for user " + infoContactModel . getLogin ( ) ) ;
boolean notify = notificationsMng . notifyFolderRenaming ( infoContactModel . getLogin ( ) , itemOldName , itemNewName , idsharedFolder ) ;
if ( ! notify )
logger . error ( " An error occured when notify user: " + infoContactModel . getLogin ( ) ) ;
}
} catch ( Exception e ) {
logger . error ( " An error occured in notifyFolderRenamed " , e ) ;
2014-06-23 17:02:57 +02:00
// e.printStackTrace();
2014-02-25 15:58:42 +01:00
}
}
2014-06-23 17:02:57 +02:00
logger . trace ( " notifies share folder was renamed is completed " ) ;
2014-02-25 15:58:42 +01:00
}
} . start ( ) ;
2014-06-23 17:02:57 +02:00
2014-02-25 15:58:42 +01:00
}
/ * *
* Runs a new thread to notify the contacts passed in input
* @param listContacts
* @param sharedFolder
* /
2014-06-23 17:02:57 +02:00
public void notifyItemRenamed ( final List < InfoContactModel > listSharedContact , final String previousName , final WorkspaceItem item , final WorkspaceSharedFolder sharedFolder ) {
2014-02-25 15:58:42 +01:00
new Thread ( ) {
@Override
public void run ( ) {
2014-06-23 17:02:57 +02:00
logger . trace ( " Send notifies shared item was updated is running... " ) ;
2014-02-25 15:58:42 +01:00
for ( InfoContactModel infoContactModel : listSharedContact ) {
try {
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
if ( infoContactModel . getLogin ( ) . compareTo ( userId ) ! = 0 ) {
2014-06-23 17:02:57 +02:00
logger . trace ( " Sending notification to user " + infoContactModel . getLogin ( ) + " updated item " + item . getName ( ) ) ;
2014-02-25 15:58:42 +01:00
//DEBUG
System . out . println ( " Sending notification to user " + infoContactModel . getLogin ( ) + " updated item " + item . getName ( ) ) ;
// notificationsMng.notifyItemRenaming(infoContactModel.getLogin(), previousName, item, sharedFolder);
2014-06-23 17:02:57 +02:00
boolean notify = notificationsMng . notifyItemRenaming ( infoContactModel . getLogin ( ) , previousName , item , sharedFolder ) ;
2014-02-25 15:58:42 +01:00
if ( ! notify )
logger . error ( " An error occured when notify user: " + infoContactModel . getLogin ( ) ) ;
}
} catch ( Exception e ) {
logger . error ( " An error occured in notifyItemUpdated " , e ) ;
2014-06-23 17:02:57 +02:00
// e.printStackTrace();
2014-02-25 15:58:42 +01:00
}
}
2014-06-23 17:02:57 +02:00
logger . trace ( " notifies shared item was updated is completed " ) ;
2014-02-25 15:58:42 +01:00
}
} . start ( ) ;
2014-06-23 17:02:57 +02:00
2014-02-25 15:58:42 +01:00
}
/ * *
* Runs a new thread to notify the new contacts passed in input
* @param listSharedContact - list of contacts already shared
* @param listSharingContact - list of " new " contacts witch share
* @param sharedFolder - the shared folder
* /
public void notifyAddedUsersToSharing ( final List < InfoContactModel > listSharedContact , final List < InfoContactModel > listSharingContact , final WorkspaceSharedFolder sharedFolder ) {
2014-06-23 17:02:57 +02:00
2014-02-25 15:58:42 +01:00
new Thread ( ) {
@Override
public void run ( ) {
try {
DiffereceBeetweenInfoContactModel diff = new DiffereceBeetweenInfoContactModel ( listSharingContact , listSharedContact ) ;
List < InfoContactModel > listExclusiveContacts = diff . getDifferentsContacts ( ) ;
System . out . println ( " list exclusive contacts: " + listExclusiveContacts ) ;
if ( listExclusiveContacts . size ( ) > 0 ) {
if ( listExclusiveContacts . size ( ) = = 1 ) { //CASE ONLY ONE CONTACS WAS ADDED
InfoContactModel infoContactModel = listExclusiveContacts . get ( 0 ) ;
for ( InfoContactModel contact : listSharedContact ) { //NOTIFIES ALREADY SHARED CONTACTS THATH A NEW USER WAS ADDED
try {
2014-06-23 17:02:57 +02:00
logger . trace ( " Sending notification to user " + contact . getLogin ( ) + " , added user " + infoContactModel . getLogin ( ) + " to share folder " + sharedFolder . getName ( ) ) ;
2014-02-25 15:58:42 +01:00
//DEBUG
// System.out.println("Sending notification added user "+ infoContactModel.getLogin() +" to share folder "+sharedFolder.getName() + " for user "+contact.getLogin());
boolean notify = notificationsMng . notifyFolderAddedUser ( contact . getLogin ( ) , sharedFolder , infoContactModel . getLogin ( ) ) ;
if ( ! notify )
logger . error ( " An error occured when notifies user: " + contact . getLogin ( ) ) ;
} catch ( Exception e ) {
logger . error ( " An error occured in notifyFolderAddedUser " , e ) ;
2014-06-23 17:02:57 +02:00
// e.printStackTrace();
2014-02-25 15:58:42 +01:00
}
}
List < InfoContactModel > listCts = new ArrayList < InfoContactModel > ( ) ;
listCts . add ( infoContactModel ) ;
notifyFolderSharing ( listCts , sharedFolder ) ; //NOTIFIER NEW USER OF SHARING FOLDER
} else { //CASE MORE THEN ONE CONTACS WAS ADDED
List < String > listLogins = UserUtil . getListLoginByInfoContactModel ( listExclusiveContacts ) ;
for ( InfoContactModel contact : listSharedContact ) { //NOTIFIES ALREADY SHARED CONTACTS THATH A NEW USER WAS ADDED
try {
2014-06-23 17:02:57 +02:00
logger . trace ( " Sending notification to user " + contact . getLogin ( ) + " , added " + listLogins . size ( ) + " users to share folder " + sharedFolder . getName ( ) ) ;
2014-02-25 15:58:42 +01:00
//DEBUG
// System.out.println("Sending notification added user "+ infoContactModel.getLogin() +" to share folder "+sharedFolder.getName() + " for user "+contact.getLogin());
boolean notify = notificationsMng . notifyFolderAddedUsers ( contact . getLogin ( ) , sharedFolder , listLogins ) ;
if ( ! notify )
logger . error ( " An error occured when notifies user: " + contact . getLogin ( ) ) ;
} catch ( Exception e ) {
logger . error ( " An error occured in notifyFolderAddedUser " , e ) ;
2014-06-23 17:02:57 +02:00
// e.printStackTrace();
2014-02-25 15:58:42 +01:00
}
}
notifyFolderSharing ( listExclusiveContacts , sharedFolder ) ; //NOTIFIER NEW USER OF SHARING FOLDER
}
}
} catch ( Exception e ) {
logger . error ( " An error occured in notifyAddedUserToSharing " , e ) ;
2014-06-23 17:02:57 +02:00
// e.printStackTrace();
2014-02-25 15:58:42 +01:00
}
}
} . start ( ) ;
2014-06-23 17:02:57 +02:00
2014-02-25 15:58:42 +01:00
}
/ * *
* Runs a new thread to notify the contacts passed in input
* @param listContacts
* @param unSharedFolder
* /
2014-06-23 17:02:57 +02:00
public void notifyFolderUnSharing ( final List < InfoContactModel > listContacts , final WorkspaceSharedFolder unSharedFolder ) {
2014-02-25 15:58:42 +01:00
new Thread ( ) {
@Override
public void run ( ) {
// printContacts(listContacts);
2014-06-23 17:02:57 +02:00
logger . trace ( " Send notifies folder un share is running... " ) ;
2014-02-25 15:58:42 +01:00
for ( InfoContactModel infoContactModel : listContacts ) {
try {
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
if ( infoContactModel . getLogin ( ) . compareTo ( userId ) ! = 0 ) {
2014-06-23 17:02:57 +02:00
logger . trace ( " Sending notification to user " + infoContactModel . getLogin ( ) + " un shared folder " + unSharedFolder . getName ( ) ) ;
2014-02-25 15:58:42 +01:00
//DEBUG
2014-06-23 17:02:57 +02:00
// System.out.println("Sending notification to user "+infoContactModel.getLogin() +" un shared folder "+unSharedFolder.getName());
boolean notify = notificationsMng . notifyFolderRemovedUser ( infoContactModel . getLogin ( ) , ( WorkspaceSharedFolder ) unSharedFolder ) ;
2014-02-25 15:58:42 +01:00
if ( ! notify )
logger . error ( " An error occured when notifies user: " + infoContactModel . getLogin ( ) ) ;
}
} catch ( Exception e ) {
logger . error ( " An error occured in notifyFolderUnSharing " , e ) ;
2014-06-23 17:02:57 +02:00
// e.printStackTrace();
2014-02-25 15:58:42 +01:00
}
}
2014-06-23 17:02:57 +02:00
logger . trace ( " notifies of un share notifications is completed " ) ;
2014-02-25 15:58:42 +01:00
}
} . start ( ) ;
2014-06-23 17:02:57 +02:00
2014-02-25 15:58:42 +01:00
}
/ * *
* Runs a new thread to notify the contacts passed in input
* @param listContacts
* @param workspaceItem
* /
2014-06-23 17:02:57 +02:00
public void notifyAddedItemToSharing ( final List < InfoContactModel > listContacts , final WorkspaceItem workspaceItem , final WorkspaceSharedFolder sharedFolder ) {
2014-02-25 15:58:42 +01:00
new Thread ( ) {
@Override
public void run ( ) {
// printContacts(listContacts);
2014-06-23 17:02:57 +02:00
logger . trace ( " Send notifies added item in sharedfolder is running... " ) ;
2014-02-25 15:58:42 +01:00
//DEBUG
System . out . println ( " Send notifies added item in sharedfolder is running... " ) ;
for ( InfoContactModel infoContactModel : listContacts ) {
try {
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
if ( infoContactModel . getLogin ( ) . compareTo ( userId ) ! = 0 ) {
2014-06-23 17:02:57 +02:00
logger . trace ( " Sending notification to user " + infoContactModel . getLogin ( ) + " added item " + workspaceItem . getName ( ) + " in shared folder " + sharedFolder . getName ( ) ) ;
2014-02-25 15:58:42 +01:00
//DEBUG
System . out . println ( " Sending notification to user " + infoContactModel . getLogin ( ) + " added item " + workspaceItem . getName ( ) + " in shared folder " + sharedFolder . getName ( ) ) ;
//DEBUG
// System.out.println("Send notify folder un share user "+infoContactModel.getLogin());
boolean notify = notificationsMng . notifyAddedItem ( infoContactModel . getLogin ( ) , workspaceItem , sharedFolder ) ;
if ( ! notify ) {
logger . error ( " An error occured when notify user: " + infoContactModel . getLogin ( ) ) ;
//DEBUG
2014-06-23 17:02:57 +02:00
// System.out.println("An error occured when notify user: "+infoContactModel.getLogin());
2014-02-25 15:58:42 +01:00
}
}
} catch ( Exception e ) {
logger . error ( " An error occured in notifyAddedItemToSharing " , e ) ;
2014-06-23 17:02:57 +02:00
// e.printStackTrace();
2014-02-25 15:58:42 +01:00
}
}
2014-06-23 17:02:57 +02:00
logger . trace ( " notifies of added item in shared folder is completed " ) ;
2014-02-25 15:58:42 +01:00
//DEBUG
2014-06-23 17:02:57 +02:00
// System.out.println("notifies of added item in shared folder is completed");
2014-02-25 15:58:42 +01:00
}
} . start ( ) ;
}
/ * *
* Runs a new thread to notify the contacts passed in input
* @param listContacts
* @param workspaceItem
* /
2014-06-23 17:02:57 +02:00
public void notifyUpdatedItemToSharing ( final List < InfoContactModel > listContacts , final WorkspaceItem workspaceItem , final WorkspaceSharedFolder sharedFolder ) {
2014-02-25 15:58:42 +01:00
new Thread ( ) {
@Override
public void run ( ) {
// printContacts(listContacts);
2014-06-23 17:02:57 +02:00
logger . trace ( " Send notifies updated item in shared folder is running... " ) ;
2014-02-25 15:58:42 +01:00
//DEBUG
2014-06-23 17:02:57 +02:00
// System.out.println("Send notifies updated item in shared folder is running...");
2014-02-25 15:58:42 +01:00
for ( InfoContactModel infoContactModel : listContacts ) {
try {
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
if ( infoContactModel . getLogin ( ) . compareTo ( userId ) ! = 0 ) {
2014-06-23 17:02:57 +02:00
logger . trace ( " Sending notification to user " + infoContactModel . getLogin ( ) + " updated item " + workspaceItem . getName ( ) + " in shared folder " + sharedFolder . getName ( ) ) ;
2014-02-25 15:58:42 +01:00
//DEBUG
2014-06-23 17:02:57 +02:00
// System.out.println("Sending notification to user "+infoContactModel.getLogin() +" updated item "+workspaceItem.getName()+" in shared folder "+sharedFolder.getName());
2014-02-25 15:58:42 +01:00
//DEBUG
// System.out.println("Send notify folder un share user "+infoContactModel.getLogin());
boolean notify = notificationsMng . notifyUpdatedItem ( infoContactModel . getLogin ( ) , workspaceItem , sharedFolder ) ;
if ( ! notify ) {
logger . error ( " An error updated when notify user: " + infoContactModel . getLogin ( ) ) ;
//DEBUG
2014-06-23 17:02:57 +02:00
// System.out.println("An error updated when notify user: "+infoContactModel.getLogin());
2014-02-25 15:58:42 +01:00
}
}
} catch ( Exception e ) {
logger . error ( " An error updated in notifyAddedItemToSharing " , e ) ;
e . printStackTrace ( ) ;
}
}
2014-06-23 17:02:57 +02:00
logger . trace ( " notifies of updated item in shared folder is completed " ) ;
2014-02-25 15:58:42 +01:00
//DEBUG
2014-06-23 17:02:57 +02:00
// System.out.println("notifies of updated item in shared folder is completed");
2014-02-25 15:58:42 +01:00
}
} . start ( ) ;
}
/ * *
* Runs a new thread to notify the contacts passed in input
* @param listContacts
* @param sharedFolder
* /
2014-06-23 17:02:57 +02:00
public void notifyMovedItemToSharing ( final List < InfoContactModel > listContacts , final WorkspaceItem workspaceItem , final WorkspaceSharedFolder sharedFolder ) {
2014-02-25 15:58:42 +01:00
2014-06-23 17:02:57 +02:00
2014-02-25 15:58:42 +01:00
new Thread ( ) {
@Override
public void run ( ) {
2014-06-23 17:02:57 +02:00
logger . trace ( " Sending notification remove item in shared folder is running... " ) ;
2014-02-25 15:58:42 +01:00
// printContacts(listContacts);
try {
if ( NotificationsUtil . checkIsRootFolderShared ( workspaceItem . getId ( ) , sharedFolder . getId ( ) ) ) {
2014-06-23 17:02:57 +02:00
logger . trace ( " Notification isn't sent because the event is on root shared folder " ) ;
2014-02-25 15:58:42 +01:00
return ;
}
} catch ( InternalErrorException e1 ) {
logger . error ( " An error occurred in checkIsRootFolderShared " , e1 ) ;
return ;
}
2014-06-23 17:02:57 +02:00
logger . trace ( " Sending notification moved item in shared folder is running... " ) ;
2014-02-25 15:58:42 +01:00
2014-06-23 17:02:57 +02:00
// System.out.println("Sending notification moved item in shared folder is running...");
2014-02-25 15:58:42 +01:00
for ( InfoContactModel infoContactModel : listContacts ) {
try {
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
if ( infoContactModel . getLogin ( ) . compareTo ( userId ) ! = 0 ) {
2014-06-23 17:02:57 +02:00
logger . trace ( " Sending notification to user " + infoContactModel . getLogin ( ) + " moved item " + workspaceItem . getName ( ) + " in shared folder " + sharedFolder . getName ( ) ) ;
2014-02-25 15:58:42 +01:00
//DEBUG
2014-06-23 17:02:57 +02:00
// System.out.println("Sending notification to user "+infoContactModel.getLogin() +" moved item "+workspaceItem.getName()+" in shared folder "+sharedFolder.getName());
2014-02-25 15:58:42 +01:00
boolean notify = notificationsMng . notifyMovedItem ( infoContactModel . getLogin ( ) , workspaceItem , sharedFolder ) ;
if ( ! notify ) {
logger . error ( " An error occured when notify user: " + infoContactModel . getLogin ( ) ) ;
//DEBUG
2014-06-23 17:02:57 +02:00
// System.out.println("An error occured when notify user: "+infoContactModel.getLogin());
2014-02-25 15:58:42 +01:00
}
}
} catch ( Exception e ) {
logger . error ( " An error occurred in notifyMovedItemToSharing " , e ) ;
e . printStackTrace ( ) ;
}
}
2014-06-23 17:02:57 +02:00
logger . trace ( " notifies of moved item in shared folder is completed " ) ;
2014-02-25 15:58:42 +01:00
//DEBUG
2014-06-23 17:02:57 +02:00
// System.out.println("notifies of moved item in shared folder is completed");
2014-02-25 15:58:42 +01:00
}
} . start ( ) ;
2014-06-23 17:02:57 +02:00
2014-02-25 15:58:42 +01:00
}
/ * *
* Runs a new thread to notify the contacts passed in input
* @param listContacts
* @param sharedFolder
* /
2014-06-23 17:02:57 +02:00
public void notifyRemovedItemToSharing ( final List < InfoContactModel > listContacts , final String itemName , final WorkspaceSharedFolder sharedFolder ) {
2014-02-25 15:58:42 +01:00
new Thread ( ) {
@Override
public void run ( ) {
2014-06-23 17:02:57 +02:00
logger . trace ( " Sending notification remove item in shared folder is running... " ) ;
2014-02-25 15:58:42 +01:00
// printContacts(listContacts);
if ( itemName = = null | | itemName . isEmpty ( ) ) {
2014-06-23 17:02:57 +02:00
logger . trace ( " Notification isn't sent - itemName is null or empty " ) ;
2014-02-25 15:58:42 +01:00
return ;
}
if ( sharedFolder = = null ) {
2014-06-23 17:02:57 +02:00
logger . trace ( " Notification isn't sent - sharedFolder is null " ) ;
2014-02-25 15:58:42 +01:00
}
2014-06-23 17:02:57 +02:00
logger . trace ( " Sending notification removed item in shared folder is running... " ) ;
2014-02-25 15:58:42 +01:00
2014-06-23 17:02:57 +02:00
// System.out.println("Sending notification removed item in shared folder is running...");
2014-02-25 15:58:42 +01:00
for ( InfoContactModel infoContactModel : listContacts ) {
try {
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
if ( infoContactModel . getLogin ( ) . compareTo ( userId ) ! = 0 ) {
2014-06-23 17:02:57 +02:00
logger . trace ( " Sending notification to user " + infoContactModel . getLogin ( ) + " removed item " + itemName + " in shared folder " + sharedFolder . getName ( ) ) ;
2014-02-25 15:58:42 +01:00
//DEBUG
2014-06-23 17:02:57 +02:00
// System.out.println("Sending notification to user "+infoContactModel.getLogin() +" removed item "+itemName+" in shared folder "+sharedFolder.getName());
2014-02-25 15:58:42 +01:00
boolean notify = notificationsMng . notifyRemovedItem ( infoContactModel . getLogin ( ) , itemName , sharedFolder ) ;
if ( ! notify ) {
logger . error ( " An error occured when notify user: " + infoContactModel . getLogin ( ) ) ;
//DEBUG
2014-06-23 17:02:57 +02:00
// System.out.println("An error occured when notify user: "+infoContactModel.getLogin());
2014-02-25 15:58:42 +01:00
}
}
} catch ( Exception e ) {
logger . error ( " An error occurred in notifyRemovedItemToSharing " , e ) ;
2014-06-23 17:02:57 +02:00
// e.printStackTrace();
2014-02-25 15:58:42 +01:00
}
}
2014-06-23 17:02:57 +02:00
logger . trace ( " notifies of moved item in shared folder is completed " ) ;
2014-02-25 15:58:42 +01:00
//DEBUG
2014-06-23 17:02:57 +02:00
// System.out.println("notifies of moved item in shared folder is completed");
2014-02-25 15:58:42 +01:00
}
2014-06-23 17:02:57 +02:00
} . start ( ) ;
}
/ * *
* Runs a new thread to notify the contacts passed in input
* @param listContacts
* @param unSharedFolder
* /
public void notifySharedFolderDeleted ( final List < InfoContactModel > listContacts , final String folderNameDeleted ) {
2014-02-25 15:58:42 +01:00
2014-06-23 17:02:57 +02:00
new Thread ( ) {
@Override
public void run ( ) {
// printContacts(listContacts);
logger . trace ( " Send notifies shared folder deleted is running... " ) ;
for ( InfoContactModel infoContactModel : listContacts ) {
try {
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
if ( infoContactModel . getLogin ( ) . compareTo ( userId ) ! = 0 ) {
logger . trace ( " Sending notification to user " + infoContactModel . getLogin ( ) + " deleted shared folder " + folderNameDeleted ) ;
//DEBUG
System . out . println ( " Sending notification to user " + infoContactModel . getLogin ( ) + " deleted shared folder " + folderNameDeleted ) ;
//TODO
// boolean notify = notificationsMng.
// 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();
}
}
logger . trace ( " notifies of deleted shared foder is completed " ) ;
}
2014-02-25 15:58:42 +01:00
} . start ( ) ;
2014-06-23 17:02:57 +02:00
2014-02-25 15:58:42 +01:00
}
2014-06-23 17:02:57 +02:00
2014-02-25 15:58:42 +01:00
//DEBUG
private void printContacts ( List < InfoContactModel > listContacts ) {
System . out . println ( " Print contacts " ) ;
for ( InfoContactModel infoContactModel : listContacts ) {
System . out . println ( infoContactModel ) ;
}
System . out . println ( " End print contacts " ) ;
}
public static void main ( String [ ] args ) throws Exception
{
String sessionID = " 1 " ;
String user = " francesco.mangiacrapa " ;
String scopeString = " /gcube/devsec/devVRE " ;
String fullName = " Francesco Mangiacrapa " ;
ScopeBean scope ;
ASLSession session ;
session = SessionManager . getInstance ( ) . getASLSession ( sessionID , user ) ;
scope = new ScopeBean ( scopeString ) ;
session . setScope ( scope . toString ( ) ) ;
session . setUserAvatarId ( user + " Avatar " ) ;
session . setUserFullName ( fullName ) ;
NotificationsProducer feeder = new NotificationsProducer ( session ) ;
}
2014-06-23 17:02:57 +02:00
}