2013-02-13 18:39:33 +01:00
/ * *
*
* /
package org.gcube.portlets.user.workspace.server.notifications ;
import java.util.List ;
import org.gcube.application.framework.core.session.ASLSession ;
import org.gcube.application.framework.core.session.SessionManager ;
import org.gcube.applicationsupportlayer.social.NotificationsManager ;
import org.gcube.common.core.scope.GCUBEScope ;
2013-02-27 19:17:22 +01:00
import org.gcube.common.core.utils.logging.GCUBELog ;
2013-02-13 18:39:33 +01:00
import org.gcube.portlets.user.homelibrary.home.workspace.WorkspaceFolder ;
2013-02-27 19:17:22 +01:00
import org.gcube.portlets.user.homelibrary.home.workspace.WorkspaceItem ;
import org.gcube.portlets.user.homelibrary.home.workspace.WorkspaceSharedFolder ;
2013-02-13 18:39:33 +01:00
import org.gcube.portlets.user.workspace.client.model.InfoContactModel ;
import org.gcube.portlets.user.workspace.server.util.Util ;
/ * *
*
* @author Francesco Mangiacrapa francesco . mangiacrapa @isti.cnr.it
*
* /
public class NotificationsProducer {
2013-02-27 19:17:22 +01:00
protected GCUBELog gcubeLogger = new GCUBELog ( NotificationsProducer . class ) ;
2013-02-13 18:39:33 +01:00
protected GCUBEScope scope ;
protected NotificationsManager notificationsMng ;
protected ASLSession aslSession ;
protected String userId ;
/ * *
*
* @param aslSession
* /
public NotificationsProducer ( ASLSession aslSession ) {
this . notificationsMng = Util . 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 ;
}
/ * *
* Runs a new thread to notify the contacts passed in input
* @param listContacts
* @param sharedFolder
* /
public void notifyFolderSharing ( final List < InfoContactModel > listContacts , final WorkspaceFolder sharedFolder ) {
new Thread ( ) {
@Override
public void run ( ) {
2013-02-27 19:17:22 +01:00
gcubeLogger . trace ( " Send notifies folder sharing is running... " ) ;
2013-02-26 11:37:55 +01: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-02-27 19:17:22 +01:00
if ( infoContactModel . getId ( ) . compareTo ( userId ) ! = 0 ) {
2013-02-25 19:03:53 +01:00
2013-02-27 19:17:22 +01:00
gcubeLogger . trace ( " Send notifies new share folder " + sharedFolder . getName ( ) + " for user " + infoContactModel . getId ( ) ) ;
2013-02-25 19:03:53 +01:00
//DEBUG
2013-02-27 19:17:22 +01:00
System . out . println ( " Send notifies new share folder " + sharedFolder . getName ( ) + " for user " + infoContactModel . getId ( ) ) ;
2013-02-13 18:39:33 +01:00
boolean notify = notificationsMng . notifyFolderSharing ( infoContactModel . getId ( ) , sharedFolder ) ;
if ( ! notify )
2013-02-18 16:47:37 +01:00
gcubeLogger . error ( " An error occured when notify user: " + infoContactModel . getId ( ) ) ;
2013-02-26 11:37:55 +01:00
}
2013-02-13 18:39:33 +01:00
} catch ( Exception e ) {
2013-02-18 16:47:37 +01:00
gcubeLogger . error ( " An error occured in notifyFolderSharing " , e ) ;
2013-02-13 18:39:33 +01:00
e . printStackTrace ( ) ;
}
}
2013-02-27 19:17:22 +01:00
gcubeLogger . trace ( " notifies share folder is completed " ) ;
2013-02-13 18:39:33 +01:00
}
} . start ( ) ;
}
2013-02-27 19:17:22 +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 notifyAddedUserToSharing ( final List < InfoContactModel > listSharedContact , final List < InfoContactModel > listSharingContact , final WorkspaceSharedFolder sharedFolder ) {
new Thread ( ) {
@Override
public void run ( ) {
try {
if ( listSharedContact = = null )
return ;
for ( InfoContactModel infoContactModel : listSharingContact ) {
if ( ! listSharedContact . contains ( infoContactModel ) ) { //if is new contact.. notifies share
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
if ( infoContactModel . getId ( ) . compareTo ( userId ) ! = 0 ) {
for ( InfoContactModel contact : listSharedContact ) { //NOTIFIES ALREADY SHARED CONTACTS
try {
gcubeLogger . trace ( " Send notifies added user " + infoContactModel . getId ( ) + " to share folder " + sharedFolder . getName ( ) + " for user " + contact . getId ( ) ) ;
//DEBUG
System . out . println ( " Send notifies added user " + infoContactModel . getId ( ) + " to share folder " + sharedFolder . getName ( ) + " for user " + contact . getId ( ) ) ;
boolean notify = notificationsMng . notifyFolderAddedUser ( contact . getId ( ) , sharedFolder , infoContactModel . getId ( ) ) ;
if ( ! notify )
gcubeLogger . error ( " An error occured when notifies user: " + infoContactModel . getId ( ) ) ;
} catch ( Exception e ) {
gcubeLogger . error ( " An error occured in notifyFolderAddedUser " , e ) ;
e . printStackTrace ( ) ;
}
}
}
}
}
} catch ( Exception e ) {
gcubeLogger . error ( " An error occured in notifyAddedUserToSharing " , e ) ;
e . printStackTrace ( ) ;
}
}
} . start ( ) ;
}
2013-02-13 18:39:33 +01:00
/ * *
* Runs a new thread to notify the contacts passed in input
* @param listContacts
2013-02-27 19:17:22 +01:00
* @param unSharedFolder
2013-02-13 18:39:33 +01:00
* /
2013-02-27 19:17:22 +01:00
public void notifyFolderUnSharing ( final List < InfoContactModel > listContacts , final WorkspaceFolder unSharedFolder ) {
2013-02-13 18:39:33 +01:00
2013-02-14 15:06:34 +01:00
2013-02-13 18:39:33 +01:00
new Thread ( ) {
@Override
public void run ( ) {
2013-02-26 11:37:55 +01:00
// printContacts(listContacts);
2013-02-27 19:17:22 +01:00
gcubeLogger . trace ( " Send notifies folder un share is running... " ) ;
2013-02-13 18:39:33 +01:00
for ( InfoContactModel infoContactModel : listContacts ) {
try {
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
2013-02-27 19:17:22 +01:00
if ( infoContactModel . getId ( ) . compareTo ( userId ) ! = 0 ) {
2013-02-13 18:39:33 +01:00
2013-02-27 19:17:22 +01:00
gcubeLogger . trace ( " User id: " + userId + " send notifies un shared folder " + unSharedFolder . getName ( ) + " for user " + infoContactModel . getId ( ) ) ;
2013-02-25 19:03:53 +01:00
//DEBUG
2013-02-27 19:17:22 +01:00
System . out . println ( " User id: " + userId + " send notifies un shared folder " + unSharedFolder . getName ( ) + " for user " + infoContactModel . getId ( ) ) ;
2013-02-13 18:39:33 +01:00
2013-02-27 19:17:22 +01:00
boolean notify = notificationsMng . notifyFolderRemovedUser ( infoContactModel . getId ( ) , unSharedFolder ) ;
2013-02-13 18:39:33 +01:00
if ( ! notify )
2013-02-27 19:17:22 +01:00
gcubeLogger . error ( " An error occured when notifies user: " + infoContactModel . getId ( ) ) ;
2013-02-26 11:37:55 +01:00
}
2013-02-13 18:39:33 +01:00
} catch ( Exception e ) {
2013-02-27 19:17:22 +01:00
gcubeLogger . error ( " An error occured in notifyFolderUnSharing " , e ) ;
2013-02-13 18:39:33 +01:00
e . printStackTrace ( ) ;
}
}
2013-02-27 19:17:22 +01:00
gcubeLogger . trace ( " notifies of un share notifications is completed " ) ;
2013-02-13 18:39:33 +01:00
}
} . start ( ) ;
2013-02-27 19:17:22 +01:00
2013-02-13 18:39:33 +01:00
}
2013-02-26 11:37:55 +01:00
/ * *
* Runs a new thread to notify the contacts passed in input
* @param listContacts
2013-02-27 19:17:22 +01:00
* @param workspaceItem
2013-02-26 11:37:55 +01:00
* /
2013-02-27 19:17:22 +01:00
public void notifyAddedItemToSharing ( final List < InfoContactModel > listContacts , final WorkspaceItem workspaceItem , final WorkspaceFolder sharedFolder ) {
2013-02-26 11:37:55 +01:00
new Thread ( ) {
@Override
public void run ( ) {
// printContacts(listContacts);
2013-02-27 19:17:22 +01:00
gcubeLogger . trace ( " Send notifies added item in sharedfolder is running... " ) ;
//DEBUG
System . out . println ( " Send notifies added item in sharedfolder is running... " ) ;
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
2013-02-27 19:17:22 +01:00
if ( infoContactModel . getId ( ) . compareTo ( userId ) ! = 0 ) {
2013-02-26 11:37:55 +01:00
2013-02-27 19:17:22 +01:00
gcubeLogger . trace ( " Send notifies added item " + workspaceItem . getName ( ) + " in shared folder " + sharedFolder . getName ( ) + " for user " + infoContactModel . getId ( ) ) ;
2013-02-26 11:37:55 +01:00
2013-02-27 19:17:22 +01:00
//DEBUG
System . out . println ( " Send notifies added item " + workspaceItem . getName ( ) + " in shared folder " + sharedFolder . getName ( ) + " for user " + infoContactModel . getId ( ) ) ;
2013-02-26 11:37:55 +01:00
//DEBUG
// System.out.println("Send notify folder un share user "+infoContactModel.getId());
2013-02-27 19:17:22 +01:00
boolean notify = notificationsMng . notifyAddedItem ( infoContactModel . getId ( ) , workspaceItem , sharedFolder ) ;
2013-02-26 11:37:55 +01:00
2013-02-27 19:17:22 +01:00
if ( ! notify ) {
2013-02-26 11:37:55 +01:00
gcubeLogger . error ( " An error occured when notify user: " + infoContactModel . getId ( ) ) ;
2013-02-27 19:17:22 +01:00
//DEBUG
System . out . println ( " An error occured when notify user: " + infoContactModel . getId ( ) ) ;
}
2013-02-26 11:37:55 +01:00
}
} catch ( Exception e ) {
gcubeLogger . error ( " An error occured in notifyAddedItemToSharing " , e ) ;
e . printStackTrace ( ) ;
}
}
2013-02-27 19:17:22 +01:00
gcubeLogger . trace ( " notifies of added item in shared folder is completed " ) ;
//DEBUG
System . out . println ( " notifies of added item in shared folder is completed " ) ;
2013-02-26 11:37:55 +01:00
}
} . start ( ) ;
}
2013-02-13 18:39:33 +01:00
2013-02-26 11:37:55 +01:00
2013-02-27 19:17:22 +01:00
2013-02-26 11:37:55 +01:00
/ * *
* Runs a new thread to notify the contacts passed in input
* @param listContacts
* @param sharedFolder
* /
2013-02-27 19:17:22 +01:00
public void notifyRemovedItemToSharing ( final List < InfoContactModel > listContacts , final WorkspaceItem workspaceItem , final WorkspaceFolder sharedFolder ) {
2013-02-26 11:37:55 +01:00
new Thread ( ) {
@Override
public void run ( ) {
// printContacts(listContacts);
2013-02-27 19:17:22 +01:00
gcubeLogger . trace ( " Send notifies remove item in shared folder is running... " ) ;
System . out . println ( " Send notifies remove item in shared folder is running... " ) ;
2013-02-26 11:37:55 +01:00
for ( InfoContactModel infoContactModel : listContacts ) {
try {
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
2013-02-27 19:17:22 +01:00
if ( infoContactModel . getId ( ) . compareTo ( userId ) ! = 0 ) {
2013-02-26 11:37:55 +01:00
2013-02-27 19:17:22 +01:00
gcubeLogger . trace ( " Send notifies remove item " + workspaceItem . getName ( ) + " in shared folder " + sharedFolder . getName ( ) + " for user " + infoContactModel . getId ( ) ) ;
2013-02-26 11:37:55 +01:00
2013-02-27 19:17:22 +01:00
//DEBUG
System . out . println ( " Send notifies remove item " + workspaceItem . getName ( ) + " in shared folder " + sharedFolder . getName ( ) + " for user " + infoContactModel . getId ( ) ) ;
boolean notify = notificationsMng . notifyRemovedItem ( infoContactModel . getId ( ) , workspaceItem , sharedFolder ) ;
2013-02-26 11:37:55 +01:00
2013-02-27 19:17:22 +01:00
if ( ! notify ) {
2013-02-26 11:37:55 +01:00
gcubeLogger . error ( " An error occured when notify user: " + infoContactModel . getId ( ) ) ;
2013-02-27 19:17:22 +01:00
//DEBUG
System . out . println ( " An error occured when notify user: " + infoContactModel . getId ( ) ) ;
}
2013-02-26 11:37:55 +01:00
}
} catch ( Exception e ) {
gcubeLogger . error ( " An error occured in notifyRemovedItemToSharing " , e ) ;
e . printStackTrace ( ) ;
}
}
2013-02-27 19:17:22 +01:00
gcubeLogger . trace ( " notifies of removed item in shared folder is completed " ) ;
//DEBUG
System . out . println ( " notifies of removed item in shared folder is completed " ) ;
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
}
//DEBUG
2013-02-13 18:39:33 +01:00
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 " ;
GCUBEScope scope ;
ASLSession session ;
session = SessionManager . getInstance ( ) . getASLSession ( sessionID , user ) ;
scope = GCUBEScope . getScope ( scopeString ) ;
session . setScope ( scope . toString ( ) ) ;
session . setUserAvatarId ( user + " Avatar " ) ;
session . setUserFullName ( fullName ) ;
NotificationsProducer feeder = new NotificationsProducer ( session ) ;
2013-02-26 11:37:55 +01:00
2013-02-13 18:39:33 +01:00
}
}