2013-02-13 18:39:33 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
package org.gcube.portlets.user.workspace.server.notifications;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import org.apache.log4j.Logger;
|
|
|
|
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;
|
|
|
|
import org.gcube.portlets.user.homelibrary.home.workspace.WorkspaceFolder;
|
|
|
|
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 {
|
|
|
|
|
|
|
|
protected Logger logger = Logger.getLogger(NotificationsProducer.class);
|
|
|
|
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() {
|
|
|
|
|
|
|
|
for (InfoContactModel infoContactModel : listContacts) {
|
|
|
|
try{
|
|
|
|
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
|
2013-02-14 15:06:34 +01:00
|
|
|
// if(infoContactModel.getId().compareTo(userId)!=0){
|
2013-02-13 18:39:33 +01:00
|
|
|
logger.trace("Send notify folder sharing for user "+infoContactModel.getId());
|
|
|
|
boolean notify = notificationsMng.notifyFolderSharing(infoContactModel.getId(), sharedFolder);
|
|
|
|
|
|
|
|
if(!notify)
|
|
|
|
logger.error("An error occured when notify user: "+infoContactModel.getId());
|
2013-02-14 15:06:34 +01:00
|
|
|
// }
|
2013-02-13 18:39:33 +01:00
|
|
|
}catch (Exception e) {
|
|
|
|
logger.error("An error occured in notifyFolderSharing ", e);
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.trace("share notifications is completed");
|
|
|
|
}
|
|
|
|
}.start();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Runs a new thread to notify the contacts passed in input
|
|
|
|
* @param listContacts
|
|
|
|
* @param sharedFolder
|
|
|
|
*/
|
|
|
|
public void notifyFolderUnSharing(final List<InfoContactModel> listContacts, final WorkspaceFolder sharedFolder) {
|
|
|
|
|
2013-02-14 15:06:34 +01:00
|
|
|
|
2013-02-13 18:39:33 +01:00
|
|
|
new Thread() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
|
|
|
|
printContacts(listContacts);
|
|
|
|
|
|
|
|
for (InfoContactModel infoContactModel : listContacts) {
|
|
|
|
try{
|
|
|
|
|
|
|
|
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
|
2013-02-14 15:06:34 +01:00
|
|
|
// if(infoContactModel.getId().compareTo(userId)!=0){
|
2013-02-13 18:39:33 +01:00
|
|
|
|
|
|
|
logger.trace("Send notify folder un share user "+infoContactModel.getId());
|
|
|
|
System.out.println("Send notify folder un share user "+infoContactModel.getId());
|
|
|
|
|
|
|
|
boolean notify = notificationsMng.notifyFolderRemovedUser(infoContactModel.getId(), sharedFolder, userId);
|
|
|
|
|
|
|
|
if(!notify)
|
|
|
|
logger.error("An error occured when notify user: "+infoContactModel.getId());
|
2013-02-14 15:06:34 +01:00
|
|
|
// }
|
2013-02-13 18:39:33 +01:00
|
|
|
}catch (Exception e) {
|
|
|
|
logger.error("An error occured in notifyFolderSharing ", e);
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.trace("un share notifications is completed");
|
|
|
|
System.out.println("un share folder completed");
|
|
|
|
}
|
|
|
|
|
|
|
|
}.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|