@ -1,5 +1,5 @@
/ * *
*
*
* /
package org.gcube.portlets.user.workspace.server.notifications ;
@ -27,9 +27,9 @@ import org.gcube.portlets.user.workspace.server.util.WsUtil;
public class NotificationsProducer {
protected ScopeBean scope ;
protected static Logger logger = Logger . getLogger ( NotificationsProducer . class ) ;
protected NotificationsManager notificationsMng ;
protected ASLSession aslSession ;
protected String userId ;
@ -72,7 +72,7 @@ public class NotificationsProducer {
public ASLSession getAslSession ( ) {
return aslSession ;
}
/ * *
* Runs a new thread to notify the contacts passed in input .
@ -85,22 +85,22 @@ public class NotificationsProducer {
new Thread ( ) {
@Override
public void run ( ) {
logger . trace ( "Send notifies folder sharing is running..." ) ;
for ( InfoContactModel infoContactModel : listContacts ) {
try {
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
if ( infoContactModel . getLogin ( ) . compareTo ( userId ) ! = 0 ) {
if ( infoContactModel . getLogin ( ) . compareTo ( userId ) ! = 0 ) {
logger . debug ( "Sending notification new share folder " + sharedFolder . getName ( ) + " for user " + infoContactModel . getLogin ( ) ) ;
//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 ( ) ) ;
}
@ -109,16 +109,16 @@ public class NotificationsProducer {
// e.printStackTrace();
}
}
logger . trace ( "notifies share folder is completed" ) ;
}
} . start ( ) ;
}
/ * *
* Runs a new thread to notify the contacts passed in input .
*
@ -133,34 +133,34 @@ public class NotificationsProducer {
new Thread ( ) {
@Override
public void run ( ) {
logger . trace ( "Send notifies shared folder was renamed is running..." ) ;
try {
if ( NotificationsUtil . checkIsRootFolderShared ( folderItem . getId ( ) , idsharedFolder ) ) {
logger . trace ( "Notification isn't sent because the event is on root shared folder" ) ;
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 ) {
if ( infoContactModel . getLogin ( ) . compareTo ( userId ) ! = 0 ) {
logger . trace ( "Sending notification share folder " + itemOldName + " was renamed as " + itemNewName + "for user " + infoContactModel . getLogin ( ) ) ;
//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 ( ) ) ;
}
@ -169,15 +169,15 @@ public class NotificationsProducer {
// e.printStackTrace();
}
}
logger . trace ( "notifies share folder was renamed is completed" ) ;
}
} . start ( ) ;
}
/ * *
* Runs a new thread to notify the contacts passed in input .
*
@ -191,21 +191,21 @@ public class NotificationsProducer {
new Thread ( ) {
@Override
public void run ( ) {
logger . trace ( "Send notifies shared item was updated is running..." ) ;
for ( InfoContactModel infoContactModel : listSharedContact ) {
try {
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
if ( infoContactModel . getLogin ( ) . compareTo ( userId ) ! = 0 ) {
if ( infoContactModel . getLogin ( ) . compareTo ( userId ) ! = 0 ) {
logger . trace ( "Sending notification to user " + infoContactModel . getLogin ( ) + " updated item " + item . getName ( ) ) ;
//DEBUG
System . out . println ( "Sending notification to user " + infoContactModel . getLogin ( ) + " updated item " + item . getName ( ) ) ;
// notificationsMng.notifyItemRenaming(infoContactModel.getLogin(), previousName, item, sharedFolder);
boolean notify = notificationsMng . notifyItemRenaming ( infoContactModel . getLogin ( ) , previousName , item , sharedFolder ) ;
if ( ! notify )
@ -216,14 +216,14 @@ public class NotificationsProducer {
// e.printStackTrace();
}
}
logger . trace ( "notifies shared item was updated is completed" ) ;
}
} . start ( ) ;
}
/ * *
* Runs a new thread to notify the updated ( add / remove ) contacts to sharing
@ -237,88 +237,88 @@ public class NotificationsProducer {
new Thread ( ) {
@Override
public void run ( ) {
try {
//NEW USER SHARED
DifferenceBetweenInfoContactModel diff = new DifferenceBetweenInfoContactModel ( listSharingContact , listSharedContact ) ;
List < InfoContactModel > listNewContactsShared = diff . getDifferentsContacts ( ) ;
logger . info ( "list new contacts shared: " + listNewContactsShared . size ( ) ) ;
if ( listNewContactsShared . size ( ) > 0 ) {
if ( listNewContactsShared . size ( ) = = 1 ) { //CASE ONLY ONE CONTACS WAS ADDED
InfoContactModel infoContactModel = listNewContactsShared . get ( 0 ) ;
for ( InfoContactModel contact : listSharedContact ) { //NOTIFIES ALREADY SHARED CONTACTS THAT A NEW USER WAS ADDED
try {
logger . trace ( "Sending notification to user " + contact . getLogin ( ) + ", added user " + infoContactModel . getLogin ( ) + " to share folder " + sharedFolder . getName ( ) ) ;
//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 ) ;
// e.printStackTrace();
}
}
List < InfoContactModel > listCts = new ArrayList < InfoContactModel > ( ) ;
listCts . add ( infoContactModel ) ;
notifyFolderSharing ( listCts , sharedFolder ) ; //NOTIFIER NEW USER OF SHARING FOLDER
} else { //CASE MORE THEN ONE CONTACT WAS ADDED
List < String > listLogins = UserUtil . getListLoginByInfoContactModel ( listNewContactsShared ) ;
for ( InfoContactModel contact : listSharedContact ) { //NOTIFIES ALREADY SHARED CONTACTS THATH A NEW USER WAS ADDED
try {
logger . trace ( "Sending notification to user " + contact . getLogin ( ) + ", added " + listLogins . size ( ) + " users to share folder " + sharedFolder . getName ( ) ) ;
//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 ) ;
// e.printStackTrace();
}
}
notifyFolderSharing ( listNewContactsShared , sharedFolder ) ; //NOTIFIER NEW USER OF SHARING FOLDER
}
}
//USER REMOVED FROM SHARE
DifferenceBetweenInfoContactModel diff2 = new DifferenceBetweenInfoContactModel ( listSharedContact , listSharingContact ) ;
List < InfoContactModel > listRemovedUsersFromShare = diff2 . getDifferentsContacts ( ) ;
logger . info ( "list removed contacts from share: " + listRemovedUsersFromShare . size ( ) ) ;
if ( listRemovedUsersFromShare . size ( ) > 0 ) {
for ( InfoContactModel contact : listRemovedUsersFromShare )
notifyFolderRemovedUser ( contact , sharedFolder ) ;
}
} catch ( Exception e ) {
logger . error ( "An error occured in notifyAddedUserToSharing " , e ) ;
// e.printStackTrace();
@ -326,9 +326,9 @@ public class NotificationsProducer {
}
} . start ( ) ;
}
/ * *
* Runs a new thread to notify the contacts passed in input .
@ -339,26 +339,26 @@ public class NotificationsProducer {
* /
public void notifyFolderUnSharing ( final List < InfoContactModel > listContacts , final String unShareFolderId , final String unSharedFolderName ) {
new Thread ( ) {
@Override
public void run ( ) {
// printContacts(listContacts);
logger . trace ( "Send notifies folder un share 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 ( ) + " unshare folder " + unSharedFolderName ) ;
//DEBUG
// System.out.println("Sending notification to user "+infoContactModel.getLogin() +" un shared folder "+unSharedFolder.getName());
// boolean notify = notificationsMng.notifyFolderRemovedUser(infoContactModel.getLogin(), (WorkspaceSharedFolder) unSharedFolder);
boolean notify = notificationsMng . notifyFolderUnsharing ( infoContactModel . getLogin ( ) , unShareFolderId , unSharedFolderName ) ;
if ( ! notify )
logger . error ( "An error occured when notifies user: " + infoContactModel . getLogin ( ) ) ;
@ -368,12 +368,12 @@ public class NotificationsProducer {
// e.printStackTrace();
}
}
logger . trace ( "notifies of un share notifications is completed" ) ;
}
} . start ( ) ;
}
/ * *
@ -387,31 +387,31 @@ public class NotificationsProducer {
new Thread ( ) {
@Override
public void run ( ) {
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 ) {
logger . debug ( "Sending notification to user " + userUnShared . getLogin ( ) + " unshared from folder " + shareFolder . getName ( ) ) ;
boolean notify = notificationsMng . notifyFolderRemovedUser ( userUnShared . getLogin ( ) , ( WorkspaceSharedFolder ) shareFolder ) ;
boolean notify = notificationsMng . notifyFolderRemovedUser ( userUnShared . getLogin ( ) , shareFolder ) ;
if ( ! notify )
logger . error ( "An error occured when notifies user: " + userUnShared . getLogin ( ) ) ;
}
} catch ( Exception e ) {
logger . error ( "An error occured in notifyFolderRemovedUser " , e ) ;
}
logger . trace ( "notifies of un unshare user is completed" ) ;
}
} . start ( ) ;
}
/ * *
* Runs a new thread to notify the contacts passed in input .
*
@ -424,27 +424,24 @@ public class NotificationsProducer {
new Thread ( ) {
@Override
public void run ( ) {
// printContacts(listContacts);
logger . trace ( "Send notifies added item in sharedfolder is running..." ) ;
//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 ) {
logger . trace ( "Sending notification to user " + infoContactModel . getLogin ( ) + " added item " + workspaceItem . getName ( ) + " in shared folder " + sharedFolder . getName ( ) ) ;
//DEBUG
System . out . println ( "Sending notification to user " + infoContactModel . getLogin ( ) + " added item " + workspaceItem . getName ( ) + " in shared folder " + sharedFolder . getName ( ) ) ;
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 ( ) ) ;
//DEBUG
// System.out.println("Send notify folder un share user "+infoContactModel.getLogin());
boolean notify = notificationsMng . notifyAddedItem ( infoContactModel . getLogin ( ) , workspaceItem , sharedFolder ) ;
if ( ! notify ) {
@ -458,17 +455,17 @@ public class NotificationsProducer {
// e.printStackTrace();
}
}
logger . trace ( "notifies of added item in shared folder is completed" ) ;
//DEBUG
// System.out.println("notifies of added item in shared folder is completed");
}
} . start ( ) ;
}
/ * *
* Runs a new thread to notify the contacts passed in input .
*
@ -481,27 +478,27 @@ public class NotificationsProducer {
new Thread ( ) {
@Override
public void run ( ) {
// printContacts(listContacts);
logger . trace ( "Send notifies updated item in shared folder is running..." ) ;
//DEBUG
// System.out.println("Send notifies updated item in shared folder is running...");
for ( InfoContactModel infoContactModel : listContacts ) {
try {
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
if ( infoContactModel . getLogin ( ) . compareTo ( userId ) ! = 0 ) {
if ( infoContactModel . getLogin ( ) . compareTo ( userId ) ! = 0 ) {
logger . trace ( "Sending notification to user " + infoContactModel . getLogin ( ) + " updated item " + workspaceItem . getName ( ) + " in shared folder " + sharedFolder . getName ( ) ) ;
//DEBUG
// System.out.println("Sending notification to user "+infoContactModel.getLogin() +" updated item "+workspaceItem.getName()+" in shared folder "+sharedFolder.getName());
//DEBUG
// System.out.println("Send notify folder un share user "+infoContactModel.getLogin());
boolean notify = notificationsMng . notifyUpdatedItem ( infoContactModel . getLogin ( ) , workspaceItem , sharedFolder ) ;
if ( ! notify ) {
@ -515,20 +512,20 @@ public class NotificationsProducer {
e . printStackTrace ( ) ;
}
}
logger . trace ( "notifies of updated item in shared folder is completed" ) ;
//DEBUG
// System.out.println("notifies of updated item in shared folder is completed");
}
} . start ( ) ;
}
/ * *
* Runs a new thread to notify the contacts passed in input .
*
@ -538,38 +535,38 @@ public class NotificationsProducer {
* /
public void notifyMovedItemToSharing ( final List < InfoContactModel > listContacts , final WorkspaceItem workspaceItem , final WorkspaceSharedFolder sharedFolder ) {
new Thread ( ) {
@Override
public void run ( ) {
logger . trace ( "Sending notification remove item in shared folder is running..." ) ;
// printContacts(listContacts);
try {
if ( NotificationsUtil . checkIsRootFolderShared ( workspaceItem . getId ( ) , sharedFolder . getId ( ) ) ) {
logger . trace ( "Notification isn't sent because the event is on root shared folder" ) ;
return ;
}
} catch ( InternalErrorException e1 ) {
logger . error ( "An error occurred in checkIsRootFolderShared " , e1 ) ;
return ;
}
logger . trace ( "Sending notification moved item in shared folder is running..." ) ;
// System.out.println("Sending notification moved item in shared folder 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 ( ) + " moved item " + workspaceItem . getName ( ) + " in shared folder " + sharedFolder . getName ( ) ) ;
//DEBUG
// System.out.println("Sending notification to user "+infoContactModel.getLogin() +" moved item "+workspaceItem.getName()+" in shared folder "+sharedFolder.getName());
@ -577,7 +574,7 @@ public class NotificationsProducer {
if ( ! notify ) {
logger . error ( "An error occured when notify user: " + infoContactModel . getLogin ( ) ) ;
//DEBUG
// System.out.println("An error occured when notify user: "+infoContactModel.getLogin());
}
@ -587,20 +584,20 @@ public class NotificationsProducer {
e . printStackTrace ( ) ;
}
}
logger . trace ( "notifies of moved item in shared folder is completed" ) ;
//DEBUG
// System.out.println("notifies of moved item in shared folder is completed");
}
} . start ( ) ;
}
/ * *
* Runs a new thread to notify the contacts passed in input .
*
@ -610,35 +607,35 @@ public class NotificationsProducer {
* /
public void notifyRemovedItemToSharing ( final List < InfoContactModel > listContacts , final String itemName , final WorkspaceSharedFolder sharedFolder ) {
new Thread ( ) {
@Override
public void run ( ) {
logger . trace ( "Sending notification remove item in shared folder is running..." ) ;
// printContacts(listContacts);
if ( itemName = = null | | itemName . isEmpty ( ) ) {
logger . trace ( "Notification isn't sent - itemName is null or empty" ) ;
return ;
}
if ( sharedFolder = = null ) {
logger . trace ( "Notification isn't sent - sharedFolder is null" ) ;
}
logger . trace ( "Sending notification removed item in shared folder is running..." ) ;
// System.out.println("Sending notification removed item in shared folder 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 ( ) + " removed item " + itemName + " in shared folder " + sharedFolder . getName ( ) ) ;
//DEBUG
// System.out.println("Sending notification to user "+infoContactModel.getLogin() +" removed item "+itemName+" in shared folder "+sharedFolder.getName());
@ -646,7 +643,7 @@ public class NotificationsProducer {
if ( ! notify ) {
logger . error ( "An error occured when notify user: " + infoContactModel . getLogin ( ) ) ;
//DEBUG
// System.out.println("An error occured when notify user: "+infoContactModel.getLogin());
}
@ -656,16 +653,16 @@ public class NotificationsProducer {
// e.printStackTrace();
}
}
logger . trace ( "notifies of moved item in shared folder is completed" ) ;
//DEBUG
// System.out.println("notifies of moved item in shared folder is completed");
}
} . start ( ) ;
}
/ * *
* Runs a new thread to notify the contacts passed in input .
*
@ -674,28 +671,28 @@ public class NotificationsProducer {
* /
public void notifySharedFolderDeleted ( final List < InfoContactModel > listContacts , final String folderNameDeleted ) {
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());
}
@ -704,14 +701,14 @@ public class NotificationsProducer {
// e.printStackTrace();
}
}
logger . trace ( "notifies of deleted shared foder is completed" ) ;
}
} . start ( ) ;
}
/ * *
* Runs a new thread to notify the contacts passed in input .
@ -724,14 +721,14 @@ public class NotificationsProducer {
new Thread ( ) {
@Override
public void run ( ) {
// 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 ;
}
if ( sharedFolder = = null ) {
logger . warn ( "Notification abort sharedFolder to notify is null..." ) ;
return ;
@ -739,21 +736,21 @@ public class NotificationsProducer {
try {
String login = userToNotify . getLogin ( ) ;
logger . trace ( "Send notifies administrator upgrade for login: " + login ) ;
boolean notify = notificationsMng . notifyAdministratorUpgrade ( login , sharedFolder ) ;
logger . trace ( "Notification sent correctly? " + notify ) ;
} catch ( Exception e ) {
logger . error ( "An error occured in notifyAdministratorUpgrade " , e ) ;
}
logger . trace ( "notifies of administrator upgrade completed" ) ;
}
} . start ( ) ;
}
/ * *
* Runs a new thread to notify the contacts passed in input .
*
@ -765,14 +762,14 @@ public class NotificationsProducer {
new Thread ( ) {
@Override
public void run ( ) {
// 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 ;
}
if ( sharedFolder = = null ) {
logger . warn ( "Notification abort sharedFolder to notify is null..." ) ;
return ;
@ -780,19 +777,19 @@ public class NotificationsProducer {
try {
String login = userToNotify . getLogin ( ) ;
logger . trace ( "Send notifies administrator Downgrade for login: " + login ) ;
boolean notify = notificationsMng . notifyAdministratorDowngrade ( login , sharedFolder ) ;
logger . trace ( "Notification sent correctly? " + notify ) ;
} catch ( Exception e ) {
logger . error ( "An error occured in notifyAdministratorDowngrade " , e ) ;
}
logger . trace ( "notifies of administrator Downgrade completed" ) ;
}
} . start ( ) ;
}
//DEBUG
@ -802,7 +799,7 @@ public class NotificationsProducer {
* @param listContacts the list contacts
* /
private void printContacts ( List < InfoContactModel > listContacts ) {
System . out . println ( "Print contacts" ) ;
for ( InfoContactModel infoContactModel : listContacts ) {
System . out . println ( infoContactModel ) ;
@ -822,20 +819,20 @@ public class NotificationsProducer {
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 ) ;
}
}