Migrated to Liferay 6.2

Updated pom version at 1.7.0

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/workspace-sharing-widget@128923 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2016-05-31 14:35:57 +00:00
parent e06cccb40f
commit 2604f4daae
8 changed files with 321 additions and 372 deletions

View File

@ -14,7 +14,7 @@
<groupId>org.gcube.portlets.widgets</groupId> <groupId>org.gcube.portlets.widgets</groupId>
<artifactId>workspace-sharing-widget</artifactId> <artifactId>workspace-sharing-widget</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<version>1.6.0-SNAPSHOT</version> <version>1.7.0-SNAPSHOT</version>
<name>gCube Workspace Sharing Widget</name> <name>gCube Workspace Sharing Widget</name>
<description> <description>
gCube Workspace Sharing Widget allows users to share gCube Workspace items gCube Workspace Sharing Widget allows users to share gCube Workspace items

View File

@ -30,7 +30,7 @@ import org.gcube.portlets.widgets.workspacesharingwidget.shared.WorkspaceACL;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.WorkspaceACL.USER_TYPE; import org.gcube.portlets.widgets.workspacesharingwidget.shared.WorkspaceACL.USER_TYPE;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.system.VO; import org.gcube.portlets.widgets.workspacesharingwidget.shared.system.VO;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.system.VRE; import org.gcube.portlets.widgets.workspacesharingwidget.shared.system.VRE;
import org.gcube.vomanagement.usermanagement.model.UserModel; import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -230,7 +230,7 @@ public class GWTWorkspaceSharingBuilder {
* @throws InternalErrorException the internal error exception * @throws InternalErrorException the internal error exception
*/ */
public List<InfoContactModel> buildGXTListContactsModelFromUserModel( public List<InfoContactModel> buildGXTListContactsModelFromUserModel(
List<UserModel> listUsers) throws InternalErrorException { List<GCubeUser> listUsers) throws InternalErrorException {
List<InfoContactModel> listContactsModel = new ArrayList<InfoContactModel>(); List<InfoContactModel> listContactsModel = new ArrayList<InfoContactModel>();
@ -241,7 +241,7 @@ public class GWTWorkspaceSharingBuilder {
+ listUsers.size()); + listUsers.size());
logger.trace("Building list contact model list user model"); logger.trace("Building list contact model list user model");
for (UserModel userModel : listUsers) { for (GCubeUser userModel : listUsers) {
String fullName = userModel.getFullname(); String fullName = userModel.getFullname();
if (fullName != null && !fullName.isEmpty()) if (fullName != null && !fullName.isEmpty())

View File

@ -4,6 +4,8 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.gcube.application.framework.core.session.ASLSession; import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.common.homelibary.model.items.type.WorkspaceItemType; import org.gcube.common.homelibary.model.items.type.WorkspaceItemType;
import org.gcube.common.homelibrary.home.HomeLibrary; import org.gcube.common.homelibrary.home.HomeLibrary;
@ -34,7 +36,7 @@ import org.gcube.portlets.widgets.workspacesharingwidget.shared.SessionExpiredEx
import org.gcube.portlets.widgets.workspacesharingwidget.shared.WorkspaceACL; import org.gcube.portlets.widgets.workspacesharingwidget.shared.WorkspaceACL;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.system.VO; import org.gcube.portlets.widgets.workspacesharingwidget.shared.system.VO;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.system.VRE; import org.gcube.portlets.widgets.workspacesharingwidget.shared.system.VRE;
import org.gcube.vomanagement.usermanagement.model.UserModel; import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -79,11 +81,12 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
/** /**
* Gets the notification producer. * Gets the notification producer.
* *
* @param request the request
* @return the notification producer * @return the notification producer
*/ */
protected NotificationsProducer getNotificationProducer(){ protected NotificationsProducer getNotificationProducer(HttpServletRequest request){
return WsUtil.getNotificationProducer(WsUtil.getAslSession(this.getThreadLocalRequest().getSession())); return WsUtil.getNotificationProducer(WsUtil.getAslSession(this.getThreadLocalRequest().getSession()), request);
} }
/** /**
@ -137,7 +140,7 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
logger.info("Liferay User Manager getting list users by group: "+groupId); logger.info("Liferay User Manager getting list users by group: "+groupId);
List<InfoContactModel> listContactsModel = builder.buildGXTListContactsModelFromUserModel(userManag.listUsersByGroup(groupId)); List<InfoContactModel> listContactsModel = builder.buildGXTListContactsModelFromUserModel(userManag.listUsersByGroup(groupId));
*/ */
List<UserModel> users = UserUtil.getOrganizationUsers(aslSession.getScope()); List<GCubeUser> users = UserUtil.getOrganizationUsers(aslSession.getScope());
if(users==null) if(users==null)
throw new Exception("An error occurred on recovering users from Portal, try again later"); throw new Exception("An error occurred on recovering users from Portal, try again later");
@ -427,7 +430,7 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
setACLs(sharedFolder.getId(), listLogin, acl.getId().toString()); setACLs(sharedFolder.getId(), listLogin, acl.getId().toString());
if(created){ if(created){
NotificationsProducer np = getNotificationProducer(); NotificationsProducer np = getNotificationProducer(this.getThreadLocalRequest());
if(!sourceFolderIsShared) {//if source folder is not already shared if(!sourceFolderIsShared) {//if source folder is not already shared
//TODO ADD NOTIFICATION //TODO ADD NOTIFICATION

View File

@ -3,9 +3,10 @@ package org.gcube.portlets.widgets.workspacesharingwidget.server.notifications;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.gcube.application.framework.core.session.ASLSession; 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.applicationsupportlayer.social.NotificationsManager;
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException; import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem; import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
@ -17,27 +18,29 @@ import org.gcube.portlets.widgets.workspacesharingwidget.server.util.WsUtil;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel; import org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel;
/** /**
* *
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* *
*/ */
public class NotificationsProducer { public class NotificationsProducer {
protected ScopeBean scope; protected ScopeBean scope;
protected static Logger logger = Logger.getLogger(NotificationsProducer.class); protected static Logger logger = Logger.getLogger(NotificationsProducer.class);
protected NotificationsManager notificationsMng; protected NotificationsManager notificationsMng;
protected ASLSession aslSession; protected ASLSession aslSession;
protected String userId; protected String userId;
/** /**
* * Instantiates a new notifications producer.
* @param aslSession *
* @param aslSession the asl session
* @param request the request
*/ */
public NotificationsProducer(ASLSession aslSession) { public NotificationsProducer(ASLSession aslSession, HttpServletRequest request) {
this.notificationsMng = WsUtil.getNotificationManager(aslSession); this.notificationsMng = WsUtil.getNotificationManager(aslSession, request);
this.aslSession = aslSession; this.aslSession = aslSession;
this.userId = aslSession.getUsername(); this.userId = aslSession.getUsername();
} }
@ -53,7 +56,7 @@ public class NotificationsProducer {
public ASLSession getAslSession() { public ASLSession getAslSession() {
return aslSession; return aslSession;
} }
/** /**
* Runs a new thread to notify the contacts passed in input * Runs a new thread to notify the contacts passed in input
@ -65,22 +68,22 @@ public class NotificationsProducer {
new Thread(){ new Thread(){
@Override @Override
public void run() { public void run() {
logger.trace("Send notifies folder sharing is running..."); logger.trace("Send notifies folder sharing is running...");
for (InfoContactModel infoContactModel : listContacts) { for (InfoContactModel infoContactModel : listContacts) {
try{ try{
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER //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 new share folder "+sharedFolder.getName()+" for user "+infoContactModel.getLogin()); logger.trace("Sending notification new share folder "+sharedFolder.getName()+" for user "+infoContactModel.getLogin());
//DEBUG //DEBUG
System.out.println("Sending notification new share folder "+sharedFolder.getName()+" for user "+infoContactModel.getLogin()); System.out.println("Sending notification new share folder "+sharedFolder.getName()+" for user "+infoContactModel.getLogin());
boolean notify = notificationsMng.notifyFolderSharing(infoContactModel.getLogin(), sharedFolder); boolean notify = notificationsMng.notifyFolderSharing(infoContactModel.getLogin(), sharedFolder);
if(!notify) if(!notify)
logger.error("An error occured when notify user: "+infoContactModel.getLogin()); logger.error("An error occured when notify user: "+infoContactModel.getLogin());
} }
@ -89,19 +92,19 @@ public class NotificationsProducer {
// e.printStackTrace(); // e.printStackTrace();
} }
} }
logger.trace("notifies share folder is completed"); logger.trace("notifies share folder is completed");
} }
}.start(); }.start();
} }
/** /**
* Runs a new thread to notify the contacts passed in input * Runs a new thread to notify the contacts passed in input
* @param folderItem * @param folderItem
* @param listContacts * @param listContacts
* @param sharedFolder * @param sharedFolder
*/ */
@ -110,34 +113,34 @@ public class NotificationsProducer {
new Thread(){ new Thread(){
@Override @Override
public void run() { public void run() {
logger.trace("Send notifies shared folder was renamed is running..."); logger.trace("Send notifies shared folder was renamed is running...");
try { try {
if(NotificationsUtil.checkIsRootFolderShared(folderItem.getId(), idsharedFolder)){ if(NotificationsUtil.checkIsRootFolderShared(folderItem.getId(), idsharedFolder)){
logger.trace("Notification isn't sent because the event is on root shared folder"); logger.trace("Notification isn't sent because the event is on root shared folder");
return; return;
} }
} catch (InternalErrorException e1) { } catch (InternalErrorException e1) {
logger.error("An error occurred in checkIsRootFolderShared ", e1); logger.error("An error occurred in checkIsRootFolderShared ", e1);
return; return;
} }
for (InfoContactModel infoContactModel : listSharedContact) { for (InfoContactModel infoContactModel : listSharedContact) {
try{ try{
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER //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()); logger.trace("Sending notification share folder "+itemOldName+" was renamed as " + itemNewName+ "for user "+infoContactModel.getLogin());
//DEBUG //DEBUG
System.out.println("Sending notification share folder "+itemOldName+" was renamed as " + itemNewName+ "for user "+infoContactModel.getLogin()); 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); boolean notify = notificationsMng.notifyFolderRenaming(infoContactModel.getLogin(), itemOldName, itemNewName, idsharedFolder);
if(!notify) if(!notify)
logger.error("An error occured when notify user: "+infoContactModel.getLogin()); logger.error("An error occured when notify user: "+infoContactModel.getLogin());
} }
@ -146,15 +149,15 @@ public class NotificationsProducer {
// e.printStackTrace(); // e.printStackTrace();
} }
} }
logger.trace("notifies share folder was renamed is completed"); logger.trace("notifies share folder was renamed is completed");
} }
}.start(); }.start();
} }
/** /**
* Runs a new thread to notify the contacts passed in input * Runs a new thread to notify the contacts passed in input
* @param listContacts * @param listContacts
@ -165,21 +168,21 @@ public class NotificationsProducer {
new Thread(){ new Thread(){
@Override @Override
public void run() { public void run() {
logger.trace("Send notifies shared item was updated is running..."); logger.trace("Send notifies shared item was updated is running...");
for (InfoContactModel infoContactModel : listSharedContact) { for (InfoContactModel infoContactModel : listSharedContact) {
try{ try{
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER //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()); logger.trace("Sending notification to user "+infoContactModel.getLogin() + " updated item "+item.getName());
//DEBUG //DEBUG
System.out.println("Sending notification to user "+infoContactModel.getLogin() + " updated item "+item.getName()); System.out.println("Sending notification to user "+infoContactModel.getLogin() + " updated item "+item.getName());
// notificationsMng.notifyItemRenaming(infoContactModel.getLogin(), previousName, item, sharedFolder); // notificationsMng.notifyItemRenaming(infoContactModel.getLogin(), previousName, item, sharedFolder);
boolean notify = notificationsMng.notifyItemRenaming(infoContactModel.getLogin(), previousName, item, sharedFolder); boolean notify = notificationsMng.notifyItemRenaming(infoContactModel.getLogin(), previousName, item, sharedFolder);
if(!notify) if(!notify)
@ -190,19 +193,19 @@ public class NotificationsProducer {
// e.printStackTrace(); // e.printStackTrace();
} }
} }
logger.trace("notifies shared item was updated is completed"); logger.trace("notifies shared item was updated is completed");
} }
}.start(); }.start();
} }
/** /**
* Runs a new thread to notify the new contacts passed in input * Runs a new thread to notify the new contacts passed in input
* @param listSharedContact - list of contacts already shared * @param listSharedContact - list of contacts already shared
* @param listSharingContact - list of "new" contacts witch share * @param listSharingContact - list of "new" contacts witch share
* @param sharedFolder - the shared folder * @param sharedFolder - the shared folder
*/ */
public void notifyAddedUsersToSharing(final List<InfoContactModel> listSharedContact, final List<InfoContactModel> listSharingContact, final WorkspaceSharedFolder sharedFolder) { public void notifyAddedUsersToSharing(final List<InfoContactModel> listSharedContact, final List<InfoContactModel> listSharingContact, final WorkspaceSharedFolder sharedFolder) {
@ -210,76 +213,76 @@ public class NotificationsProducer {
new Thread() { new Thread() {
@Override @Override
public void run() { public void run() {
try{ try{
DiffereceBeetweenInfoContactModel diff = new DiffereceBeetweenInfoContactModel(listSharingContact, listSharedContact); DiffereceBeetweenInfoContactModel diff = new DiffereceBeetweenInfoContactModel(listSharingContact, listSharedContact);
List<InfoContactModel> listExclusiveContacts = diff.getDifferentsContacts(); List<InfoContactModel> listExclusiveContacts = diff.getDifferentsContacts();
System.out.println("list exclusive contacts: "+listExclusiveContacts); System.out.println("list exclusive contacts: "+listExclusiveContacts);
if(listExclusiveContacts.size()>0){ if(listExclusiveContacts.size()>0){
if(listExclusiveContacts.size()==1){ //CASE ONLY ONE CONTACS WAS ADDED if(listExclusiveContacts.size()==1){ //CASE ONLY ONE CONTACS WAS ADDED
InfoContactModel infoContactModel = listExclusiveContacts.get(0); InfoContactModel infoContactModel = listExclusiveContacts.get(0);
for (InfoContactModel contact : listSharedContact) { //NOTIFIES ALREADY SHARED CONTACTS THATH A NEW USER WAS ADDED for (InfoContactModel contact : listSharedContact) { //NOTIFIES ALREADY SHARED CONTACTS THATH A NEW USER WAS ADDED
try{ try{
logger.trace("Sending notification to user "+contact.getLogin()+", added user "+ infoContactModel.getLogin() +" to share folder "+sharedFolder.getName()); logger.trace("Sending notification to user "+contact.getLogin()+", added user "+ infoContactModel.getLogin() +" to share folder "+sharedFolder.getName());
//DEBUG //DEBUG
// System.out.println("Sending notification added user "+ infoContactModel.getLogin() +" to share folder "+sharedFolder.getName() + " for user "+contact.getLogin()); // 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()); boolean notify = notificationsMng.notifyFolderAddedUser(contact.getLogin(), sharedFolder, infoContactModel.getLogin());
if(!notify) if(!notify)
logger.error("An error occured when notifies user: "+contact.getLogin()); logger.error("An error occured when notifies user: "+contact.getLogin());
}catch (Exception e) { }catch (Exception e) {
logger.error("An error occured in notifyFolderAddedUser ", e); logger.error("An error occured in notifyFolderAddedUser ", e);
// e.printStackTrace(); // e.printStackTrace();
} }
} }
List<InfoContactModel> listCts = new ArrayList<InfoContactModel>(); List<InfoContactModel> listCts = new ArrayList<InfoContactModel>();
listCts.add(infoContactModel); listCts.add(infoContactModel);
notifyFolderSharing(listCts, sharedFolder); //NOTIFIER NEW USER OF SHARING FOLDER notifyFolderSharing(listCts, sharedFolder); //NOTIFIER NEW USER OF SHARING FOLDER
}else{ //CASE MORE THEN ONE CONTACS WAS ADDED }else{ //CASE MORE THEN ONE CONTACS WAS ADDED
List<String> listLogins = UserUtil.getListLoginByInfoContactModel(listExclusiveContacts); List<String> listLogins = UserUtil.getListLoginByInfoContactModel(listExclusiveContacts);
for (InfoContactModel contact : listSharedContact) { //NOTIFIES ALREADY SHARED CONTACTS THATH A NEW USER WAS ADDED for (InfoContactModel contact : listSharedContact) { //NOTIFIES ALREADY SHARED CONTACTS THATH A NEW USER WAS ADDED
try{ try{
logger.trace("Sending notification to user "+contact.getLogin()+", added "+listLogins.size()+" users to share folder "+sharedFolder.getName()); logger.trace("Sending notification to user "+contact.getLogin()+", added "+listLogins.size()+" users to share folder "+sharedFolder.getName());
//DEBUG //DEBUG
// System.out.println("Sending notification added user "+ infoContactModel.getLogin() +" to share folder "+sharedFolder.getName() + " for user "+contact.getLogin()); // 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); boolean notify = notificationsMng.notifyFolderAddedUsers(contact.getLogin(), sharedFolder, listLogins);
if(!notify) if(!notify)
logger.error("An error occured when notifies user: "+contact.getLogin()); logger.error("An error occured when notifies user: "+contact.getLogin());
}catch (Exception e) { }catch (Exception e) {
logger.error("An error occured in notifyFolderAddedUser ", e); logger.error("An error occured in notifyFolderAddedUser ", e);
// e.printStackTrace(); // e.printStackTrace();
} }
} }
notifyFolderSharing(listExclusiveContacts, sharedFolder); //NOTIFIER NEW USER OF SHARING FOLDER notifyFolderSharing(listExclusiveContacts, sharedFolder); //NOTIFIER NEW USER OF SHARING FOLDER
} }
} }
}catch (Exception e) { }catch (Exception e) {
logger.error("An error occured in notifyAddedUserToSharing ", e); logger.error("An error occured in notifyAddedUserToSharing ", e);
// e.printStackTrace(); // e.printStackTrace();
@ -287,9 +290,9 @@ public class NotificationsProducer {
} }
}.start(); }.start();
} }
/** /**
* Runs a new thread to notify the contacts passed in input * Runs a new thread to notify the contacts passed in input
@ -298,26 +301,26 @@ public class NotificationsProducer {
*/ */
public void notifyFolderUnSharing(final List<InfoContactModel> listContacts, final WorkspaceSharedFolder unSharedFolder) { public void notifyFolderUnSharing(final List<InfoContactModel> listContacts, final WorkspaceSharedFolder unSharedFolder) {
new Thread() { new Thread() {
@Override @Override
public void run() { public void run() {
// printContacts(listContacts); // printContacts(listContacts);
logger.trace("Send notifies folder un share is running..."); logger.trace("Send notifies folder un share is running...");
for (InfoContactModel infoContactModel : listContacts) { for (InfoContactModel infoContactModel : listContacts) {
try{ try{
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER //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() +" un shared folder "+unSharedFolder.getName()); logger.trace("Sending notification to user "+infoContactModel.getLogin() +" un shared folder "+unSharedFolder.getName());
//DEBUG //DEBUG
// System.out.println("Sending notification to user "+infoContactModel.getLogin() +" un shared folder "+unSharedFolder.getName()); // 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.notifyFolderRemovedUser(infoContactModel.getLogin(), unSharedFolder);
if(!notify) if(!notify)
logger.error("An error occured when notifies user: "+infoContactModel.getLogin()); logger.error("An error occured when notifies user: "+infoContactModel.getLogin());
} }
@ -326,16 +329,16 @@ public class NotificationsProducer {
// e.printStackTrace(); // e.printStackTrace();
} }
} }
logger.trace("notifies of un share notifications is completed"); logger.trace("notifies of un share notifications is completed");
} }
}.start(); }.start();
} }
/** /**
* Runs a new thread to notify the contacts passed in input * Runs a new thread to notify the contacts passed in input
* @param listContacts * @param listContacts
@ -346,27 +349,27 @@ public class NotificationsProducer {
new Thread() { new Thread() {
@Override @Override
public void run() { public void run() {
// printContacts(listContacts); // printContacts(listContacts);
logger.trace("Send notifies added item in sharedfolder is running..."); logger.trace("Send notifies added item in sharedfolder is running...");
//DEBUG //DEBUG
System.out.println("Send notifies added item in sharedfolder is running..."); System.out.println("Send notifies added item in sharedfolder is running...");
for (InfoContactModel infoContactModel : listContacts) { for (InfoContactModel infoContactModel : listContacts) {
try{ try{
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER //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() +" added item "+workspaceItem.getName()+" in shared folder "+sharedFolder.getName()); logger.trace("Sending notification to user "+infoContactModel.getLogin() +" added item "+workspaceItem.getName()+" in shared folder "+sharedFolder.getName());
//DEBUG //DEBUG
System.out.println("Sending notification to user "+infoContactModel.getLogin() +" added item "+workspaceItem.getName()+" in shared folder "+sharedFolder.getName()); System.out.println("Sending notification to user "+infoContactModel.getLogin() +" added item "+workspaceItem.getName()+" in shared folder "+sharedFolder.getName());
//DEBUG //DEBUG
// System.out.println("Send notify folder un share user "+infoContactModel.getLogin()); // System.out.println("Send notify folder un share user "+infoContactModel.getLogin());
boolean notify = notificationsMng.notifyAddedItem(infoContactModel.getLogin(), workspaceItem, sharedFolder); boolean notify = notificationsMng.notifyAddedItem(infoContactModel.getLogin(), workspaceItem, sharedFolder);
if(!notify){ if(!notify){
@ -380,17 +383,17 @@ public class NotificationsProducer {
// e.printStackTrace(); // e.printStackTrace();
} }
} }
logger.trace("notifies of added item in shared folder is completed"); logger.trace("notifies of added item in shared folder is completed");
//DEBUG //DEBUG
// System.out.println("notifies of added item in shared folder is completed"); // System.out.println("notifies of added item in shared folder is completed");
} }
}.start(); }.start();
} }
/** /**
* Runs a new thread to notify the contacts passed in input * Runs a new thread to notify the contacts passed in input
* @param listContacts * @param listContacts
@ -401,27 +404,27 @@ public class NotificationsProducer {
new Thread() { new Thread() {
@Override @Override
public void run() { public void run() {
// printContacts(listContacts); // printContacts(listContacts);
logger.trace("Send notifies updated item in shared folder is running..."); logger.trace("Send notifies updated item in shared folder is running...");
//DEBUG //DEBUG
// System.out.println("Send notifies updated item in shared folder is running..."); // System.out.println("Send notifies updated item in shared folder is running...");
for (InfoContactModel infoContactModel : listContacts) { for (InfoContactModel infoContactModel : listContacts) {
try{ try{
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER //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()); logger.trace("Sending notification to user "+infoContactModel.getLogin() +" updated item "+workspaceItem.getName()+" in shared folder "+sharedFolder.getName());
//DEBUG //DEBUG
// System.out.println("Sending notification to user "+infoContactModel.getLogin() +" updated item "+workspaceItem.getName()+" in shared folder "+sharedFolder.getName()); // System.out.println("Sending notification to user "+infoContactModel.getLogin() +" updated item "+workspaceItem.getName()+" in shared folder "+sharedFolder.getName());
//DEBUG //DEBUG
// System.out.println("Send notify folder un share user "+infoContactModel.getLogin()); // System.out.println("Send notify folder un share user "+infoContactModel.getLogin());
boolean notify = notificationsMng.notifyUpdatedItem(infoContactModel.getLogin(), workspaceItem, sharedFolder); boolean notify = notificationsMng.notifyUpdatedItem(infoContactModel.getLogin(), workspaceItem, sharedFolder);
if(!notify){ if(!notify){
@ -435,20 +438,20 @@ public class NotificationsProducer {
e.printStackTrace(); e.printStackTrace();
} }
} }
logger.trace("notifies of updated item in shared folder is completed"); logger.trace("notifies of updated item in shared folder is completed");
//DEBUG //DEBUG
// System.out.println("notifies of updated item in shared folder is completed"); // System.out.println("notifies of updated item in shared folder is completed");
} }
}.start(); }.start();
} }
/** /**
* Runs a new thread to notify the contacts passed in input * Runs a new thread to notify the contacts passed in input
* @param listContacts * @param listContacts
@ -456,38 +459,38 @@ public class NotificationsProducer {
*/ */
public void notifyMovedItemToSharing(final List<InfoContactModel> listContacts, final WorkspaceItem workspaceItem, final WorkspaceSharedFolder sharedFolder) { public void notifyMovedItemToSharing(final List<InfoContactModel> listContacts, final WorkspaceItem workspaceItem, final WorkspaceSharedFolder sharedFolder) {
new Thread() { new Thread() {
@Override @Override
public void run() { public void run() {
logger.trace("Sending notification remove item in shared folder is running..."); logger.trace("Sending notification remove item in shared folder is running...");
// printContacts(listContacts); // printContacts(listContacts);
try { try {
if(NotificationsUtil.checkIsRootFolderShared(workspaceItem.getId(), sharedFolder.getId())){ if(NotificationsUtil.checkIsRootFolderShared(workspaceItem.getId(), sharedFolder.getId())){
logger.trace("Notification isn't sent because the event is on root shared folder"); logger.trace("Notification isn't sent because the event is on root shared folder");
return; return;
} }
} catch (InternalErrorException e1) { } catch (InternalErrorException e1) {
logger.error("An error occurred in checkIsRootFolderShared ", e1); logger.error("An error occurred in checkIsRootFolderShared ", e1);
return; return;
} }
logger.trace("Sending notification moved item in shared folder is running..."); logger.trace("Sending notification moved item in shared folder is running...");
// System.out.println("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) { for (InfoContactModel infoContactModel : listContacts) {
try{ try{
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER //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() +" moved item "+workspaceItem.getName()+" in shared folder "+sharedFolder.getName()); logger.trace("Sending notification to user "+infoContactModel.getLogin() +" moved item "+workspaceItem.getName()+" in shared folder "+sharedFolder.getName());
//DEBUG //DEBUG
// System.out.println("Sending notification to user "+infoContactModel.getLogin() +" moved item "+workspaceItem.getName()+" in shared folder "+sharedFolder.getName()); // System.out.println("Sending notification to user "+infoContactModel.getLogin() +" moved item "+workspaceItem.getName()+" in shared folder "+sharedFolder.getName());
@ -495,7 +498,7 @@ public class NotificationsProducer {
if(!notify){ if(!notify){
logger.error("An error occured when notify user: "+infoContactModel.getLogin()); logger.error("An error occured when notify user: "+infoContactModel.getLogin());
//DEBUG //DEBUG
// System.out.println("An error occured when notify user: "+infoContactModel.getLogin()); // System.out.println("An error occured when notify user: "+infoContactModel.getLogin());
} }
@ -505,20 +508,20 @@ public class NotificationsProducer {
e.printStackTrace(); e.printStackTrace();
} }
} }
logger.trace("notifies of moved item in shared folder is completed"); logger.trace("notifies of moved item in shared folder is completed");
//DEBUG //DEBUG
// System.out.println("notifies of moved item in shared folder is completed"); // System.out.println("notifies of moved item in shared folder is completed");
} }
}.start(); }.start();
} }
/** /**
* Runs a new thread to notify the contacts passed in input * Runs a new thread to notify the contacts passed in input
* @param listContacts * @param listContacts
@ -526,35 +529,35 @@ public class NotificationsProducer {
*/ */
public void notifyRemovedItemToSharing(final List<InfoContactModel> listContacts, final String itemName, final WorkspaceSharedFolder sharedFolder) { public void notifyRemovedItemToSharing(final List<InfoContactModel> listContacts, final String itemName, final WorkspaceSharedFolder sharedFolder) {
new Thread() { new Thread() {
@Override @Override
public void run() { public void run() {
logger.trace("Sending notification remove item in shared folder is running..."); logger.trace("Sending notification remove item in shared folder is running...");
// printContacts(listContacts); // printContacts(listContacts);
if(itemName==null || itemName.isEmpty()){ if(itemName==null || itemName.isEmpty()){
logger.trace("Notification isn't sent - itemName is null or empty"); logger.trace("Notification isn't sent - itemName is null or empty");
return; return;
} }
if(sharedFolder==null){ if(sharedFolder==null){
logger.trace("Notification isn't sent - sharedFolder is null"); logger.trace("Notification isn't sent - sharedFolder is null");
} }
logger.trace("Sending notification removed item in shared folder is running..."); logger.trace("Sending notification removed item in shared folder is running...");
// System.out.println("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) { for (InfoContactModel infoContactModel : listContacts) {
try{ try{
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER //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() +" removed item "+itemName+" in shared folder "+sharedFolder.getName()); logger.trace("Sending notification to user "+infoContactModel.getLogin() +" removed item "+itemName+" in shared folder "+sharedFolder.getName());
//DEBUG //DEBUG
// System.out.println("Sending notification to user "+infoContactModel.getLogin() +" removed item "+itemName+" in shared folder "+sharedFolder.getName()); // System.out.println("Sending notification to user "+infoContactModel.getLogin() +" removed item "+itemName+" in shared folder "+sharedFolder.getName());
@ -562,7 +565,7 @@ public class NotificationsProducer {
if(!notify){ if(!notify){
logger.error("An error occured when notify user: "+infoContactModel.getLogin()); logger.error("An error occured when notify user: "+infoContactModel.getLogin());
//DEBUG //DEBUG
// System.out.println("An error occured when notify user: "+infoContactModel.getLogin()); // System.out.println("An error occured when notify user: "+infoContactModel.getLogin());
} }
@ -572,16 +575,16 @@ public class NotificationsProducer {
// e.printStackTrace(); // e.printStackTrace();
} }
} }
logger.trace("notifies of moved item in shared folder is completed"); logger.trace("notifies of moved item in shared folder is completed");
//DEBUG //DEBUG
// System.out.println("notifies of moved item in shared folder is completed"); // System.out.println("notifies of moved item in shared folder is completed");
} }
}.start(); }.start();
} }
/** /**
* Runs a new thread to notify the contacts passed in input * Runs a new thread to notify the contacts passed in input
* @param listContacts * @param listContacts
@ -589,28 +592,28 @@ public class NotificationsProducer {
*/ */
public void notifySharedFolderDeleted(final List<InfoContactModel> listContacts, final String folderNameDeleted) { public void notifySharedFolderDeleted(final List<InfoContactModel> listContacts, final String folderNameDeleted) {
new Thread() { new Thread() {
@Override @Override
public void run() { public void run() {
// printContacts(listContacts); // printContacts(listContacts);
logger.trace("Send notifies shared folder deleted is running..."); logger.trace("Send notifies shared folder deleted is running...");
for (InfoContactModel infoContactModel : listContacts) { for (InfoContactModel infoContactModel : listContacts) {
try{ try{
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER //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() +" deleted shared folder "+folderNameDeleted); logger.trace("Sending notification to user "+infoContactModel.getLogin() +" deleted shared folder "+folderNameDeleted);
//DEBUG //DEBUG
System.out.println("Sending notification to user "+infoContactModel.getLogin() +" deleted shared folder "+folderNameDeleted); System.out.println("Sending notification to user "+infoContactModel.getLogin() +" deleted shared folder "+folderNameDeleted);
//TODO //TODO
// boolean notify = notificationsMng. // boolean notify = notificationsMng.
// if(!notify) // if(!notify)
// logger.error("An error occured when notifies user: "+infoContactModel.getLogin()); // logger.error("An error occured when notifies user: "+infoContactModel.getLogin());
} }
@ -619,19 +622,19 @@ public class NotificationsProducer {
// e.printStackTrace(); // e.printStackTrace();
} }
} }
logger.trace("notifies of deleted shared foder is completed"); logger.trace("notifies of deleted shared foder is completed");
} }
}.start(); }.start();
} }
//DEBUG //DEBUG
private void printContacts(List<InfoContactModel> listContacts){ private void printContacts(List<InfoContactModel> listContacts){
System.out.println("Print contacts"); System.out.println("Print contacts");
for (InfoContactModel infoContactModel : listContacts) { for (InfoContactModel infoContactModel : listContacts) {
System.out.println(infoContactModel); System.out.println(infoContactModel);
@ -639,26 +642,24 @@ public class NotificationsProducer {
System.out.println("End print contacts"); System.out.println("End print contacts");
} }
public static void main(String[] args) throws Exception /*public static void main(String[] args) throws Exception
{ {
String sessionID = "1"; String sessionID = "1";
String user = "francesco.mangiacrapa"; String user = "francesco.mangiacrapa";
String scopeString = "/gcube/devsec/devVRE"; String scopeString = "/gcube/devsec/devVRE";
String fullName = "Francesco Mangiacrapa"; String fullName = "Francesco Mangiacrapa";
ScopeBean scope; ScopeBean scope;
ASLSession session; ASLSession session;
session = SessionManager.getInstance().getASLSession(sessionID, user); session = SessionManager.getInstance().getASLSession(sessionID, user);
scope = new ScopeBean(scopeString); scope = new ScopeBean(scopeString);
session.setScope(scope.toString()); session.setScope(scope.toString());
session.setUserAvatarId(user + "Avatar"); session.setUserAvatarId(user + "Avatar");
session.setUserFullName(fullName); session.setUserFullName(fullName);
NotificationsProducer feeder = new NotificationsProducer(session); NotificationsProducer feeder = new NotificationsProducer(session);
}*/
}
} }

View File

@ -1,11 +1,12 @@
/** /**
* *
*/ */
package org.gcube.portlets.widgets.workspacesharingwidget.server.notifications; package org.gcube.portlets.widgets.workspacesharingwidget.server.notifications;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import org.gcube.common.homelibary.model.items.type.WorkspaceItemType; import org.gcube.common.homelibary.model.items.type.WorkspaceItemType;
@ -24,86 +25,89 @@ import org.slf4j.LoggerFactory;
* *
*/ */
public class NotificationsUtil { public class NotificationsUtil {
protected static Logger logger = LoggerFactory.getLogger(NotificationsUtil.class); protected static Logger logger = LoggerFactory.getLogger(NotificationsUtil.class);
/** /**
* Send a notification if an item is added or updated to sharing folder * Send a notification if an item is added or updated to sharing folder.
* @param httpSession *
* @param sourceItem * @param request the request
* @param sourceSharedId * @param httpSession the http session
* @param folderDestinationItem * @param sourceItem the source item
* @param sourceSharedId the source shared id
* @param folderDestinationItem the folder destination item
* @param isOverwrite the is overwrite
*/ */
public static void checkSendNotifyChangedItemToShare(HttpSession httpSession, final WorkspaceItem sourceItem, final String sourceSharedId, final WorkspaceItem folderDestinationItem, boolean isOverwrite) { public static void checkSendNotifyChangedItemToShare(HttpServletRequest request, HttpSession httpSession, final WorkspaceItem sourceItem, final String sourceSharedId, final WorkspaceItem folderDestinationItem, boolean isOverwrite) {
logger.info("checkSendNotifyAddItemToShare"); logger.info("checkSendNotifyAddItemToShare");
if(folderDestinationItem!=null){ if(folderDestinationItem!=null){
try{ try{
//if folder destination is shared folder //if folder destination is shared folder
if(folderDestinationItem.isShared()){ //Notify Added Item To Sharing? if(folderDestinationItem.isShared()){ //Notify Added Item To Sharing?
logger.info("checkNotifyAddItemToShare source item: "+sourceItem.getName()+" sourceSharedId: "+sourceSharedId + " folder destination: "+folderDestinationItem.getName() + " folder destination shared folder id: "+folderDestinationItem.getIdSharedFolder()); logger.info("checkNotifyAddItemToShare source item: "+sourceItem.getName()+" sourceSharedId: "+sourceSharedId + " folder destination: "+folderDestinationItem.getName() + " folder destination shared folder id: "+folderDestinationItem.getIdSharedFolder());
//share condition is true if source shared folder is not null //share condition is true if source shared folder is not null
boolean shareChangeCondition = sourceSharedId==null?false:true; boolean shareChangeCondition = sourceSharedId==null?false:true;
//System.out.println("shareChangeCondition add item: "+ shareChangeCondition); //System.out.println("shareChangeCondition add item: "+ shareChangeCondition);
logger.info("shareChangeCondition add item: "+shareChangeCondition); logger.info("shareChangeCondition add item: "+shareChangeCondition);
//if shareChangeCondition is true.. notifies added item to sharing //if shareChangeCondition is true.. notifies added item to sharing
if(shareChangeCondition){ if(shareChangeCondition){
Workspace workspace = WsUtil.getWorkspace(httpSession); Workspace workspace = WsUtil.getWorkspace(httpSession);
List<InfoContactModel> listContacts = getListUserSharedByFolderSharedId(workspace, folderDestinationItem.getIdSharedFolder()); List<InfoContactModel> listContacts = getListUserSharedByFolderSharedId(workspace, folderDestinationItem.getIdSharedFolder());
WorkspaceItem destinationSharedFolder = workspace.getItem(folderDestinationItem.getIdSharedFolder()); WorkspaceItem destinationSharedFolder = workspace.getItem(folderDestinationItem.getIdSharedFolder());
NotificationsProducer np = new NotificationsProducer(WsUtil.getAslSession(httpSession)); NotificationsProducer np = new NotificationsProducer(WsUtil.getAslSession(httpSession), request);
//SWITCH BEETWEEN ADDED OR UPDATED //SWITCH BEETWEEN ADDED OR UPDATED
if(!isOverwrite) if(!isOverwrite)
np.notifyAddedItemToSharing(listContacts, sourceItem, (WorkspaceSharedFolder) destinationSharedFolder); np.notifyAddedItemToSharing(listContacts, sourceItem, (WorkspaceSharedFolder) destinationSharedFolder);
else else
np.notifyUpdatedItemToSharing(listContacts, sourceItem, (WorkspaceSharedFolder) destinationSharedFolder); np.notifyUpdatedItemToSharing(listContacts, sourceItem, (WorkspaceSharedFolder) destinationSharedFolder);
logger.info("The notifies was sent correctly"); logger.info("The notifies was sent correctly");
// np.notifyAddedItemToSharing(listContacts, (WorkspaceFolder) folderDestinationItem); // np.notifyAddedItemToSharing(listContacts, (WorkspaceFolder) folderDestinationItem);
} }
} }
else else
logger.info("folder destination is not shared"); logger.info("folder destination is not shared");
}catch (Exception e) { }catch (Exception e) {
logger.error("An error occurred in checkSendNotifyAddItemToShare ",e); logger.error("An error occurred in checkSendNotifyAddItemToShare ",e);
} }
}else }else
logger.warn("The notifies is failure in checkSendNotifyAddItemToShare because folder destination item is null"); logger.warn("The notifies is failure in checkSendNotifyAddItemToShare because folder destination item is null");
} }
/** /**
* *
* @param workspace * @param workspace
* @param idSharedFolder * @param idSharedFolder
* @return * @return
* @throws Exception * @throws Exception
*/ */
public static List<InfoContactModel> getListUserSharedByFolderSharedId(Workspace workspace, String idSharedFolder) throws Exception { public static List<InfoContactModel> getListUserSharedByFolderSharedId(Workspace workspace, String idSharedFolder) throws Exception {
logger.info("getListUserSharedByFolderSharedId "+ idSharedFolder); logger.info("getListUserSharedByFolderSharedId "+ idSharedFolder);
try { try {
WorkspaceItem wsItem = workspace.getItem(idSharedFolder); WorkspaceItem wsItem = workspace.getItem(idSharedFolder);
if(isARootSharedFolder(wsItem)){ if(isARootSharedFolder(wsItem)){
WorkspaceSharedFolder wsFolder = (WorkspaceSharedFolder) wsItem; WorkspaceSharedFolder wsFolder = (WorkspaceSharedFolder) wsItem;
GWTWorkspaceSharingBuilder builder = new GWTWorkspaceSharingBuilder(); GWTWorkspaceSharingBuilder builder = new GWTWorkspaceSharingBuilder();
@ -113,16 +117,16 @@ public class NotificationsUtil {
logger.info("getListUserSharedByFolderSharedId return "+ listPortalLogin.size() + " user"); logger.info("getListUserSharedByFolderSharedId return "+ listPortalLogin.size() + " user");
return builder.buildGxtInfoContactsFromPortalLogins(listPortalLogin); return builder.buildGxtInfoContactsFromPortalLogins(listPortalLogin);
} }
else{ else{
logger.info("the item with id: "+idSharedFolder+ " is not "+WorkspaceItemType.SHARED_FOLDER); logger.info("the item with id: "+idSharedFolder+ " is not "+WorkspaceItemType.SHARED_FOLDER);
//DEBUG //DEBUG
//System.out.println("the item with id: "+folderSharedId+ " is not "+WorkspaceItemType.SHARED_FOLDER); //System.out.println("the item with id: "+folderSharedId+ " is not "+WorkspaceItemType.SHARED_FOLDER);
} }
return new ArrayList<InfoContactModel>(); return new ArrayList<InfoContactModel>();
} catch (Exception e) { } catch (Exception e) {
logger.error("Error in getListUserSharedByItemId ", e); logger.error("Error in getListUserSharedByItemId ", e);
throw new Exception(e.getMessage()); throw new Exception(e.getMessage());
@ -131,78 +135,78 @@ public class NotificationsUtil {
/** /**
* *
* @param httpSession * @param httpSession
* @param sourceItemIsShared * @param sourceItemIsShared
* @param oldItemName * @param oldItemName
* @param oldItemId * @param oldItemId
* @param sourceFolderSharedId * @param sourceFolderSharedId
*/ */
public static void checkSendNotifyRemoveItemToShare(HttpSession httpSession, final boolean sourceItemIsShared, final String oldItemName, String oldItemId, final String sourceFolderSharedId) { public static void checkSendNotifyRemoveItemToShare(HttpServletRequest request, HttpSession httpSession, final boolean sourceItemIsShared, final String oldItemName, String oldItemId, final String sourceFolderSharedId) {
logger.info("checkNotifyRemoveItemToShare:"); logger.info("checkNotifyRemoveItemToShare:");
try{ try{
if(!sourceItemIsShared){ if(!sourceItemIsShared){
logger.info("checkSendNotifyRemoveItemToShare returned, source item is not shared"); logger.info("checkSendNotifyRemoveItemToShare returned, source item is not shared");
return; return;
} }
String idSharedFolder = sourceFolderSharedId!=null?sourceFolderSharedId:""; String idSharedFolder = sourceFolderSharedId!=null?sourceFolderSharedId:"";
// System.out.println("shareChangeCondition remove item: "+ shareChangeCondition); // System.out.println("shareChangeCondition remove item: "+ shareChangeCondition);
boolean isRootFolderShared = checkIsRootFolderShared(oldItemId, idSharedFolder); boolean isRootFolderShared = checkIsRootFolderShared(oldItemId, idSharedFolder);
logger.info("isRootFolderShared is: "+ isRootFolderShared); logger.info("isRootFolderShared is: "+ isRootFolderShared);
if(isRootFolderShared){ if(isRootFolderShared){
logger.info("Notification doesn't send because the event is on root shared folder"); logger.info("Notification doesn't send because the event is on root shared folder");
return; return;
} }
boolean isSharedFolder = isASharedFolderForId(httpSession,idSharedFolder); boolean isSharedFolder = isASharedFolderForId(httpSession,idSharedFolder);
logger.info("idSharedFolder is: "+ idSharedFolder +" is shared folder: "+isSharedFolder); logger.info("idSharedFolder is: "+ idSharedFolder +" is shared folder: "+isSharedFolder);
//Notify Removed Item To Sharing? //Notify Removed Item To Sharing?
if(isSharedFolder && !isRootFolderShared){ if(isSharedFolder && !isRootFolderShared){
Workspace workspace = WsUtil.getWorkspace(httpSession); Workspace workspace = WsUtil.getWorkspace(httpSession);
//get contacts //get contacts
List<InfoContactModel> listContacts = getListUserSharedByFolderSharedId(workspace, idSharedFolder); List<InfoContactModel> listContacts = getListUserSharedByFolderSharedId(workspace, idSharedFolder);
WorkspaceItem sourceSharedFolder = workspace.getItem(idSharedFolder); WorkspaceItem sourceSharedFolder = workspace.getItem(idSharedFolder);
//System.out.println(" name sourceSharedFolder: "+ sourceSharedFolder.getName()); //System.out.println(" name sourceSharedFolder: "+ sourceSharedFolder.getName());
NotificationsProducer np = new NotificationsProducer(WsUtil.getAslSession(httpSession)); NotificationsProducer np = new NotificationsProducer(WsUtil.getAslSession(httpSession), request);
if(sourceSharedFolder instanceof WorkspaceSharedFolder) if(sourceSharedFolder instanceof WorkspaceSharedFolder)
np.notifyRemovedItemToSharing(listContacts, oldItemName, (WorkspaceSharedFolder) sourceSharedFolder); np.notifyRemovedItemToSharing(listContacts, oldItemName, (WorkspaceSharedFolder) sourceSharedFolder);
else else
logger.info("Source shared folder "+sourceSharedFolder + " is not instanceof WorkspaceSharedFolder, skipping"); logger.info("Source shared folder "+sourceSharedFolder + " is not instanceof WorkspaceSharedFolder, skipping");
logger.info("The notifies was sent correctly"); logger.info("The notifies was sent correctly");
} }
}catch (Exception e) { }catch (Exception e) {
logger.error("An error occurred in checkSendNotifyRemoveItemToShare ",e); logger.error("An error occurred in checkSendNotifyRemoveItemToShare ",e);
} }
} }
/** /**
* *
* @param wsItem * @param wsItem
* @return * @return
*/ */
@ -211,52 +215,52 @@ public class NotificationsUtil {
return wsItem.getType().equals(WorkspaceItemType.SHARED_FOLDER); return wsItem.getType().equals(WorkspaceItemType.SHARED_FOLDER);
return false; return false;
} }
/** /**
* *
* @param wsItem * @param wsItem
* @return * @return
*/ */
public static boolean isASharedFolderForId(HttpSession httpSession, String itemId){ public static boolean isASharedFolderForId(HttpSession httpSession, String itemId){
if(itemId==null || itemId.isEmpty()) if(itemId==null || itemId.isEmpty())
return false; return false;
try { try {
Workspace workspace = WsUtil.getWorkspace(httpSession); Workspace workspace = WsUtil.getWorkspace(httpSession);
WorkspaceItem wsItem = workspace.getItem(itemId); WorkspaceItem wsItem = workspace.getItem(itemId);
if(wsItem!=null) if(wsItem!=null)
return wsItem.getType().equals(WorkspaceItemType.SHARED_FOLDER); return wsItem.getType().equals(WorkspaceItemType.SHARED_FOLDER);
return false; return false;
} catch (Exception e) { } catch (Exception e) {
logger.error("An errror occurred in isASharedFolderForId", e); logger.error("An errror occurred in isASharedFolderForId", e);
return false; return false;
} }
} }
/** /**
* *
* @param itemId * @param itemId
* @param rootFolderSharedId * @param rootFolderSharedId
* @return * @return
*/ */
public static boolean checkIsRootFolderShared(String itemId, String rootFolderSharedId) { public static boolean checkIsRootFolderShared(String itemId, String rootFolderSharedId) {
logger.info("checkIsRootFolderShared between [itemid: "+itemId +", rootFolderSharedId: "+rootFolderSharedId+"]"); logger.info("checkIsRootFolderShared between [itemid: "+itemId +", rootFolderSharedId: "+rootFolderSharedId+"]");
if(itemId==null) if(itemId==null)
return false; return false;
if(rootFolderSharedId==null) if(rootFolderSharedId==null)
return false; return false;
if(itemId.compareTo(rootFolderSharedId)==0) if(itemId.compareTo(rootFolderSharedId)==0)
return true; return true;
return false; return false;
} }
} }

View File

@ -3,123 +3,45 @@ package org.gcube.portlets.widgets.workspacesharingwidget.server.util;
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor; import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor; import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Properties;
import org.gcube.common.resources.gcore.GenericResource; import org.gcube.common.resources.gcore.GenericResource;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.scope.impl.ScopeBean; import org.gcube.common.scope.impl.ScopeBean;
import org.gcube.common.scope.impl.ScopeBean.Type; import org.gcube.common.scope.impl.ScopeBean.Type;
import org.gcube.portal.custom.communitymanager.OrganizationsUtil;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.system.UserBelonging; import org.gcube.portlets.widgets.workspacesharingwidget.shared.system.UserBelonging;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.system.VO; import org.gcube.portlets.widgets.workspacesharingwidget.shared.system.VO;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.system.VRE; import org.gcube.portlets.widgets.workspacesharingwidget.shared.system.VRE;
import org.gcube.resources.discovery.client.api.DiscoveryClient; import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery; import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault;
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault;
import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayUserManager;
import org.gcube.vomanagement.usermanagement.model.UserModel;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* *
* @author Massimiliano Assante ISTI-CNR * @author Massimiliano Assante ISTI-CNR
* *
* @version 2.0 Jan 10th 2012 * @version 2.0 Jan 10th 2012
* *
* changed by Francesco Mangiacrapa * changed by Francesco Mangiacrapa
*/ */
public class LoginServiceUtil { public class LoginServiceUtil {
/** /**
* *
*/ */
public static final String ROOT_ORG = "rootorganization"; public static final String ROOT_ORG = "rootorganization";
/** /**
* *
*/ */
public static final String PUBLIC_LAYOUT_NAME = " Data e-Infrastructure gateway"; public static final String PUBLIC_LAYOUT_NAME = " Data e-Infrastructure gateway";
/** /**
* *
*/ */
public static final String GUEST_COMMUNITY_NAME = "Guest"; public static final String GUEST_COMMUNITY_NAME = "Guest";
private static final Logger _log = LoggerFactory.getLogger(LoginServiceUtil.class); private static final Logger _log = LoggerFactory.getLogger(LoginServiceUtil.class);
/**
*
* @param screenName
* @param organizatioId
* @return
*/
protected static boolean checkPending(String screenName, long organizationId) {
try {
for (UserModel userModel : new LiferayUserManager().listPendingUsersByGroup(""+organizationId))
if (userModel.getScreenName().compareTo(screenName) == 0) return true;
} catch (UserManagementSystemException e) {
e.printStackTrace();
} catch (GroupRetrievalFault e) {
e.printStackTrace();
} catch (UserRetrievalFault e) {
e.printStackTrace();
}
return false;
}
/**
* add a property to gcube-data.properties for root vo, it make the login portlet understand the installation was setup already
* @param rootVoName .
*/
protected static void appendRootOrganizationName(String rootVoName) {
Properties props = new Properties();
try {
String propertyfile = OrganizationsUtil.getTomcatFolder()+"conf/gcube-data.properties";
File propsFile = new File(propertyfile);
FileInputStream fis = new FileInputStream(propsFile);
props.load( fis);
props.setProperty(ROOT_ORG, rootVoName);
FileOutputStream fos = new FileOutputStream(propsFile);
props.store(fos, null);
}
//catch exception in case properties file does not exist
catch(IOException e) {
e.printStackTrace();
}
_log.info("Added property Root VO Name: " + rootVoName );
}
/**
* read the root VO name from a property file and retuns it
*/
protected static String getRootOrganizationName() {
//get the portles to look for from the property file
Properties props = new Properties();
String toReturn = "";
try {
String propertyfile = OrganizationsUtil.getTomcatFolder()+"conf/gcube-data.properties";
File propsFile = new File(propertyfile);
FileInputStream fis = new FileInputStream(propsFile);
props.load( fis);
toReturn = props.getProperty(ROOT_ORG);
}
//catch exception in case properties file does not exist
catch(IOException e) {
toReturn = "gcube";
_log.error("gcube-data.properties file not found under $CATALINA_HOME/conf dir, returning default VO Name " + toReturn);
return toReturn;
}
_log.debug("Returning Root VO Name: " + toReturn );
return toReturn;
}
/** /**
* simply returns fake VOS for debugging purpose * simply returns fake VOS for debugging purpose
* @return * @return
@ -143,12 +65,12 @@ public class LoginServiceUtil {
emVO.setImageURL("http://portal.d4science.research-infrastructures.eu/vologin/html/RedGrid.jpg"); emVO.setImageURL("http://portal.d4science.research-infrastructures.eu/vologin/html/RedGrid.jpg");
emVO.setUserBelonging(UserBelonging.NOT_BELONGING); emVO.setUserBelonging(UserBelonging.NOT_BELONGING);
// //
// //
VRE cool_EM_VRE = new VRE(); VRE cool_EM_VRE = new VRE();
cool_EM_VRE.setName("COOL EM VRE"); cool_EM_VRE.setName("COOL EM VRE");
cool_EM_VRE.setGroupName("/d4science.research-infrastructures.eu/EM/COOLEMVRE"); cool_EM_VRE.setGroupName("/d4science.research-infrastructures.eu/EM/COOLEMVRE");
cool_EM_VRE.setDescription("cool_EM_VRE VRE Description<br />"+ cool_EM_VRE.setDescription("cool_EM_VRE VRE Description<br />"+
"This Virtual Research Environment is for cool authors, managers and researchers who produce reports containing cool data."); "This Virtual Research Environment is for cool authors, managers and researchers who produce reports containing cool data.");
cool_EM_VRE.setImageURL("http://portal.d4science.research-infrastructures.eu/vologin/html/gcm-preview.jpg"); cool_EM_VRE.setImageURL("http://portal.d4science.research-infrastructures.eu/vologin/html/gcm-preview.jpg");
cool_EM_VRE.setUserBelonging(UserBelonging.BELONGING); cool_EM_VRE.setUserBelonging(UserBelonging.BELONGING);
@ -157,7 +79,7 @@ public class LoginServiceUtil {
VRE cool_EM_VRE2 = new VRE(); VRE cool_EM_VRE2 = new VRE();
cool_EM_VRE2.setName("COOL VRE 2"); cool_EM_VRE2.setName("COOL VRE 2");
cool_EM_VRE2.setGroupName("/d4science.research-infrastructures.eu/EM/COOLEMVRE2"); cool_EM_VRE2.setGroupName("/d4science.research-infrastructures.eu/EM/COOLEMVRE2");
cool_EM_VRE2.setDescription("Cool VRE Description<br />"+ cool_EM_VRE2.setDescription("Cool VRE Description<br />"+
"This Virtual Research Environment is for cool authors, managers and researchers who produce reports containing cool data."); "This Virtual Research Environment is for cool authors, managers and researchers who produce reports containing cool data.");
cool_EM_VRE2.setImageURL("http://portal.d4science.research-infrastructures.eu/vologin/html/aquamaps-preview.jpg"); cool_EM_VRE2.setImageURL("http://portal.d4science.research-infrastructures.eu/vologin/html/aquamaps-preview.jpg");
@ -166,7 +88,7 @@ public class LoginServiceUtil {
VRE cool_EM_VRE3 = new VRE(); VRE cool_EM_VRE3 = new VRE();
cool_EM_VRE3.setName("COOL EM VRE TRE"); cool_EM_VRE3.setName("COOL EM VRE TRE");
cool_EM_VRE3.setGroupName("/d4science.research-infrastructures.eu/EM/COOlVRE3"); cool_EM_VRE3.setGroupName("/d4science.research-infrastructures.eu/EM/COOlVRE3");
cool_EM_VRE3.setDescription("Cool VRE Description<br />"+ cool_EM_VRE3.setDescription("Cool VRE Description<br />"+
"This Virtual Research Environment is for cool authors, managers and researchers who produce reports containing cool data."); "This Virtual Research Environment is for cool authors, managers and researchers who produce reports containing cool data.");
cool_EM_VRE3.setImageURL("http://portal.d4science.research-infrastructures.eu/vologin/html/aquamaps-preview.jpg"); cool_EM_VRE3.setImageURL("http://portal.d4science.research-infrastructures.eu/vologin/html/aquamaps-preview.jpg");
@ -175,7 +97,7 @@ public class LoginServiceUtil {
VRE demo = new VRE(); VRE demo = new VRE();
demo.setName("Demo"); demo.setName("Demo");
demo.setGroupName("/d4science.research-infrastructures.eu/EM/Demo"); demo.setGroupName("/d4science.research-infrastructures.eu/EM/Demo");
demo.setDescription("Cool VRE Description<br />"+ demo.setDescription("Cool VRE Description<br />"+
"This Virtual Research Environment is for cool authors, managers and researchers who produce reports containing cool data."); "This Virtual Research Environment is for cool authors, managers and researchers who produce reports containing cool data.");
demo.setImageURL("http://portal.d4science.research-infrastructures.eu/vologin/html/RedGrid.jpg"); demo.setImageURL("http://portal.d4science.research-infrastructures.eu/vologin/html/RedGrid.jpg");
@ -184,7 +106,7 @@ public class LoginServiceUtil {
VRE vreGCM = new VRE(); VRE vreGCM = new VRE();
vreGCM.setName("GCM"); vreGCM.setName("GCM");
vreGCM.setGroupName("/d4science.research-infrastructures.eu/EM/GCM"); vreGCM.setGroupName("/d4science.research-infrastructures.eu/EM/GCM");
vreGCM.setDescription("Global Ocean Chlorophyll Monitoring (GCM) Virtual Research Environment<br />" vreGCM.setDescription("Global Ocean Chlorophyll Monitoring (GCM) Virtual Research Environment<br />"
+ "The phytoplankton plays a similar role to terrestrial green plants in the photosynthetic process and are credited with removing as much carbon dioxide from the atmosphere as their earthbound counterparts, making it important to monitor and model plankton into calculations of future climate change."); + "The phytoplankton plays a similar role to terrestrial green plants in the photosynthetic process and are credited with removing as much carbon dioxide from the atmosphere as their earthbound counterparts, making it important to monitor and model plankton into calculations of future climate change.");
vreGCM.setImageURL("http://portal.d4science.research-infrastructures.eu/vologin/html/aquamaps-preview.jpg"); vreGCM.setImageURL("http://portal.d4science.research-infrastructures.eu/vologin/html/aquamaps-preview.jpg");
vreGCM.setUserBelonging(UserBelonging.BELONGING); vreGCM.setUserBelonging(UserBelonging.BELONGING);
@ -204,7 +126,7 @@ public class LoginServiceUtil {
} }
/** /**
* *
* @param scopename a string * @param scopename a string
* @return true if any VRE Exists * @return true if any VRE Exists
*/ */
@ -215,13 +137,13 @@ public class LoginServiceUtil {
try { try {
_log.info("Searching for VREs into " + scope.name()); _log.info("Searching for VREs into " + scope.name());
String currScope = ScopeProvider.instance.get(); String currScope = ScopeProvider.instance.get();
ScopeProvider.instance.set(scope.toString()); ScopeProvider.instance.set(scope.toString());
SimpleQuery query = queryFor(GenericResource.class); SimpleQuery query = queryFor(GenericResource.class);
query.addCondition("$resource/Profile/SecondaryType/text() eq '"+ Type.VRE +"'"); query.addCondition("$resource/Profile/SecondaryType/text() eq '"+ Type.VRE +"'");
DiscoveryClient<GenericResource> client = clientFor(GenericResource.class); DiscoveryClient<GenericResource> client = clientFor(GenericResource.class);
boolean result = client.submit(query).size() > 0; boolean result = client.submit(query).size() > 0;
ScopeProvider.instance.set(currScope); ScopeProvider.instance.set(currScope);
return result; return result;
} catch (Exception e) { } catch (Exception e) {
_log.error("Generic Exception for " + scope.name() + " " + e.getMessage()); _log.error("Generic Exception for " + scope.name() + " " + e.getMessage());
@ -230,7 +152,7 @@ public class LoginServiceUtil {
} }
} }
/** /**
* *
* @param scopename a string * @param scopename a string
* @return an arraylist of <class>VRE</class> with just name and description filled * @return an arraylist of <class>VRE</class> with just name and description filled
*/ */
@ -242,7 +164,7 @@ public class LoginServiceUtil {
try { try {
_log.info("Searching for VREs into " + scope.name()); _log.info("Searching for VREs into " + scope.name());
String currScope = ScopeProvider.instance.get(); String currScope = ScopeProvider.instance.get();
ScopeProvider.instance.set(scope.toString()); ScopeProvider.instance.set(scope.toString());
SimpleQuery query = queryFor(GenericResource.class); SimpleQuery query = queryFor(GenericResource.class);
query.addCondition("$resource/Profile/SecondaryType/text() eq '"+ Type.VRE +"'"); query.addCondition("$resource/Profile/SecondaryType/text() eq '"+ Type.VRE +"'");
@ -250,7 +172,7 @@ public class LoginServiceUtil {
for (GenericResource genres : client.submit(query)) { for (GenericResource genres : client.submit(query)) {
toReturn.add(new VRE(genres.profile().name(), genres.profile().description(), "", "", "", null)); toReturn.add(new VRE(genres.profile().name(), genres.profile().description(), "", "", "", null));
} }
ScopeProvider.instance.set(currScope); ScopeProvider.instance.set(currScope);
return toReturn; return toReturn;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -258,5 +180,5 @@ public class LoginServiceUtil {
return null; return null;
} }
} }
} }

View File

@ -1,3 +1,6 @@
/*
*
*/
package org.gcube.portlets.widgets.workspacesharingwidget.server.util; package org.gcube.portlets.widgets.workspacesharingwidget.server.util;
import java.util.ArrayList; import java.util.ArrayList;
@ -8,12 +11,11 @@ import org.gcube.common.scope.impl.ScopeBean.Type;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel; import org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel;
import org.gcube.vomanagement.usermanagement.GroupManager; import org.gcube.vomanagement.usermanagement.GroupManager;
import org.gcube.vomanagement.usermanagement.UserManager; import org.gcube.vomanagement.usermanagement.UserManager;
import org.gcube.vomanagement.usermanagement.exception.UserManagementPortalException;
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException; import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault; import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault;
import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayGroupManager; import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayUserManager; import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
import org.gcube.vomanagement.usermanagement.model.UserModel; import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -47,19 +49,17 @@ public class UserUtil {
logger.info("Into portal: "+WsUtil.isWithinPortal()); logger.info("Into portal: "+WsUtil.isWithinPortal());
if (portalLogin.compareTo(WsUtil.TEST_USER) != 0 && WsUtil.isWithinPortal()) { //skip test.user if (portalLogin.compareTo(WsUtil.TEST_USER) != 0 && WsUtil.isWithinPortal()) { //skip test.user
UserModel curr = null; GCubeUser curr = null;
try { try {
try { try {
curr = um.getUserByScreenName(portalLogin); curr = um.getUserByUsername(portalLogin);
} catch (UserManagementSystemException e) { } catch (UserManagementSystemException e) {
logger.error("An error occurred in getUserFullName "+e,e); logger.error("An error occurred in getUserFullName "+e,e);
} catch (UserRetrievalFault e) { } catch (UserRetrievalFault e) {
logger.error("An error occurred in getUserFullName "+e,e); logger.error("An error occurred in getUserFullName "+e,e);
} }
} catch (UserManagementPortalException ume) {
logger.error("An error occurred in getUserFullName "+ume,ume);
}catch (Exception e) { }catch (Exception e) {
logger.error("An error occurred in getUserFullName "+e,e); logger.error("An error occurred in getUserFullName "+e,e);
logger.warn("Return portal login "+portalLogin); logger.warn("Return portal login "+portalLogin);
@ -87,7 +87,7 @@ public class UserUtil {
* @param scope the scope * @param scope the scope
* @return the organization users * @return the organization users
*/ */
public static List<UserModel> getOrganizationUsers(String scope) { public static List<GCubeUser> getOrganizationUsers(String scope) {
try { try {
logger.info("Getting organization users by scope: "+scope); logger.info("Getting organization users by scope: "+scope);
UserManager um = new LiferayUserManager(); UserManager um = new LiferayUserManager();

View File

@ -6,6 +6,7 @@ package org.gcube.portlets.widgets.workspacesharingwidget.server.util;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
@ -13,6 +14,7 @@ import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.application.framework.core.session.SessionManager; import org.gcube.application.framework.core.session.SessionManager;
import org.gcube.applicationsupportlayer.social.ApplicationNotificationsManager; import org.gcube.applicationsupportlayer.social.ApplicationNotificationsManager;
import org.gcube.applicationsupportlayer.social.NotificationsManager; import org.gcube.applicationsupportlayer.social.NotificationsManager;
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingSite;
import org.gcube.common.homelibrary.home.HomeLibrary; import org.gcube.common.homelibrary.home.HomeLibrary;
import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException; import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException; import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
@ -204,7 +206,15 @@ public class WsUtil {
} }
public static NotificationsManager getNotificationManager(ASLSession session)
/**
* Gets the notification manager.
*
* @param session the session
* @param request the request
* @return the notification manager
*/
public static NotificationsManager getNotificationManager(ASLSession session, HttpServletRequest request)
{ {
NotificationsManager notifMng = (NotificationsManager) session.getAttribute(NOTIFICATION_MANAGER); NotificationsManager notifMng = (NotificationsManager) session.getAttribute(NOTIFICATION_MANAGER);
@ -213,7 +223,8 @@ public class WsUtil {
try{ try{
logger.info("Create new NotificationsManager for user: "+session.getUsername()); logger.info("Create new NotificationsManager for user: "+session.getUsername());
logger.info("New ApplicationNotificationsManager with portlet class name: "+NOTIFICATION_PORTLET_CLASS_ID); logger.info("New ApplicationNotificationsManager with portlet class name: "+NOTIFICATION_PORTLET_CLASS_ID);
notifMng = new ApplicationNotificationsManager(session, NOTIFICATION_PORTLET_CLASS_ID); SocialNetworkingSite site = new SocialNetworkingSite(request);
notifMng = new ApplicationNotificationsManager(site, session.getScope(), null, NOTIFICATION_PORTLET_CLASS_ID);
session.setAttribute(NOTIFICATION_MANAGER, notifMng); session.setAttribute(NOTIFICATION_MANAGER, notifMng);
}catch (Exception e) { }catch (Exception e) {
logger.error("An error occurred instancing ApplicationNotificationsManager for user: "+session.getUsername(),e); logger.error("An error occurred instancing ApplicationNotificationsManager for user: "+session.getUsername(),e);
@ -223,14 +234,22 @@ public class WsUtil {
return notifMng; return notifMng;
} }
public static NotificationsProducer getNotificationProducer(ASLSession session)
/**
* Gets the notification producer.
*
* @param session the session
* @param request the request
* @return the notification producer
*/
public static NotificationsProducer getNotificationProducer(ASLSession session, HttpServletRequest request)
{ {
NotificationsProducer notifProducer = (NotificationsProducer) session.getAttribute(NOTIFICATION_PRODUCER); NotificationsProducer notifProducer = (NotificationsProducer) session.getAttribute(NOTIFICATION_PRODUCER);
if (notifProducer == null) { if (notifProducer == null) {
logger.info("Create new Notification Producer for user: "+session.getUsername()); logger.info("Create new Notification Producer for user: "+session.getUsername());
notifProducer = new NotificationsProducer(session); notifProducer = new NotificationsProducer(session, request);
session.setAttribute(NOTIFICATION_PRODUCER, notifProducer); session.setAttribute(NOTIFICATION_PRODUCER, notifProducer);
} }