added notification for more users

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@71718 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2013-03-25 16:35:27 +00:00
parent 110557f426
commit cbd896729a
6 changed files with 251 additions and 60 deletions

View File

@ -10,7 +10,7 @@
<groupId>org.gcube.portlets.user</groupId>
<artifactId>workspace-tree-widget</artifactId>
<version>6.0.1-SNAPSHOT</version>
<version>6.0.2-SNAPSHOT</version>
<name>gCube Workspace Tree Widget</name>
<description>
gCube Workspace Tree Widget.

View File

@ -997,18 +997,6 @@ public class GWTWorkspaceBuilder {
}
public List<String> getListLoginByInfoContactModel(List<InfoContactModel> listContacts){
List<String> listUsers = new ArrayList<String>();
for (InfoContactModel infoContactModel : listContacts) {
listUsers.add(infoContactModel.getLogin());
}
return listUsers;
}
protected List<FileGridModel> buildGXTListFileGridModelItem(List<WorkspaceItem> listWorkspaceItems, FileModel parentFileModel) throws InternalErrorException
{

View File

@ -30,7 +30,6 @@ import org.gcube.portlets.user.homelibrary.home.workspace.folder.FolderItem;
import org.gcube.portlets.user.homelibrary.home.workspace.folder.FolderItemType;
import org.gcube.portlets.user.homelibrary.home.workspace.folder.items.ExternalUrl;
import org.gcube.portlets.user.homelibrary.home.workspace.folder.items.ts.TimeSeries;
import org.gcube.portlets.user.homelibrary.home.workspace.search.SearchFolderItem;
import org.gcube.portlets.user.homelibrary.home.workspace.search.SearchItem;
import org.gcube.portlets.user.homelibrary.home.workspace.sharing.WorkspaceMessage;
import org.gcube.portlets.user.workspace.client.ConstantsExplorer;
@ -49,6 +48,7 @@ import org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService;
import org.gcube.portlets.user.workspace.client.workspace.GWTWorkspaceItem;
import org.gcube.portlets.user.workspace.server.notifications.NotificationsProducer;
import org.gcube.portlets.user.workspace.server.util.AllScope;
import org.gcube.portlets.user.workspace.server.util.UserUtil;
import org.gcube.portlets.user.workspace.server.util.Util;
import org.gcube.portlets.user.workspaceapplicationhandler.ApplicationReaderFromGenericResource;
@ -482,7 +482,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
}
@Override
public Boolean renameItem(String itemId, String newName, String oldName) throws Exception {
public Boolean renameItem(String itemId, String newName, String previousName) throws Exception {
workspaceLogger.trace("renameItem itemId: "+itemId+" newName: "+newName);
@ -491,7 +491,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
GCUBEClientLog logger = new GCUBEClientLog(GWTWorkspaceServiceImpl.class);
logger.trace("rename item itemId: "+itemId+" old name "+ oldName +", new name: "+newName);
logger.trace("rename item itemId: "+itemId+" old name "+ previousName +", new name: "+newName);
workspace.renameItem(itemId, newName);
@ -505,10 +505,10 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
NotificationsProducer notification = getNotificationProducer();
listSharedContact = getListUserSharedByFolderSharedId(wsItem.getIdSharedFolder());
if(Util.isASharedFolder(wsItem)){
notification.notifyFolderRenamed(listSharedContact, oldName, newName, wsItem.getIdSharedFolder());
notification.notifyFolderRenamed(listSharedContact, previousName, newName, wsItem.getIdSharedFolder());
}else{
WorkspaceFolder sharedFolder = (WorkspaceFolder) workspace.getItem(wsItem.getIdSharedFolder());
notification.notifyItemUpdated(listSharedContact, wsItem, sharedFolder);
notification.notifyItemRenamed(listSharedContact, previousName, wsItem, sharedFolder);
}
}catch (Exception e) {
workspaceLogger.error("An error occurred in checkNotify ", e);
@ -1564,10 +1564,8 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
// }
printContacts(listContacts);
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder();
List<String> listLogin = builder.getListLoginByInfoContactModel(listContacts);
List<String> listLogin = UserUtil.getListLoginByInfoContactModel(listContacts);
WorkspaceSharedFolder sharedFolder = null;
@ -1594,8 +1592,13 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
NotificationsProducer np = getNotificationProducer();
if(!sourceFolderIsShared) //if source folder is not already shared
np.notifyFolderSharing(listContacts, sharedFolder);
else
np.notifyAddedUserToSharing(listSharedContact, listContacts, sharedFolder);
else{
System.out.println("SHARED CONTACS: ");
printContacts(listSharedContact);
System.out.println("NEW CONTACS: ");
printContacts(listContacts);
np.notifyAddedUsersToSharing(listSharedContact, listContacts, sharedFolder);
}
}
return created;

View File

@ -15,6 +15,8 @@ import org.gcube.portlets.user.homelibrary.home.workspace.WorkspaceFolder;
import org.gcube.portlets.user.homelibrary.home.workspace.WorkspaceItem;
import org.gcube.portlets.user.homelibrary.home.workspace.WorkspaceSharedFolder;
import org.gcube.portlets.user.workspace.client.model.InfoContactModel;
import org.gcube.portlets.user.workspace.server.util.DiffereceBeetweenInfoContactModel;
import org.gcube.portlets.user.workspace.server.util.UserUtil;
import org.gcube.portlets.user.workspace.server.util.Util;
/**
@ -147,7 +149,7 @@ public class NotificationsProducer {
* @param listContacts
* @param sharedFolder
*/
public void notifyItemUpdated(final List<InfoContactModel> listSharedContact, final WorkspaceItem item, final WorkspaceFolder sharedFolder) {
public void notifyItemRenamed(final List<InfoContactModel> listSharedContact, final String previousName, final WorkspaceItem item, final WorkspaceFolder sharedFolder) {
new Thread(){
@Override
@ -165,7 +167,9 @@ public class NotificationsProducer {
//DEBUG
System.out.println("Sending notification to user "+infoContactModel.getLogin() + " updated item "+item.getName());
boolean notify = notificationsMng.notifyUpdatedItem(infoContactModel.getLogin(), item, sharedFolder);
// notificationsMng.notifyItemRenaming(infoContactModel.getLogin(), previousName, item, sharedFolder);
boolean notify = notificationsMng.notifyItemRenaming(infoContactModel.getLogin(), previousName, item);
if(!notify)
gcubeLogger.error("An error occured when notify user: "+infoContactModel.getLogin());
@ -190,53 +194,120 @@ public class NotificationsProducer {
* @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) {
public void notifyAddedUsersToSharing(final List<InfoContactModel> listSharedContact, final List<InfoContactModel> listSharingContact, final WorkspaceSharedFolder sharedFolder) {
new Thread() {
@Override
public void run() {
// try{
// //CREATE TEMPORARY HASH
// HashMap<String, InfoContactModel> hashLoginAlreadyShared = new HashMap<String, InfoContactModel>();
//
// for (InfoContactModel infoContactModel : listSharedContact) {
// hashLoginAlreadyShared.put(infoContactModel.getLogin(),infoContactModel);
// }
//
// if(listSharedContact==null)
// return;
//
// for (InfoContactModel infoContactModel : listSharingContact) {
//
//
// if(hashLoginAlreadyShared.get(infoContactModel.getLogin())==null){ //if is new contact.. notifies share
//
// //NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
// if(infoContactModel.getLogin().compareTo(userId)!=0){
//
// for (InfoContactModel contact : listSharedContact) { //NOTIFIES ALREADY SHARED CONTACTS
//
// try{
//
// gcubeLogger.trace("Sending notification to user "+contact.getLogin()+", added user "+ infoContactModel.getLogin() +" to share folder "+sharedFolder.getName());
//
// //DEBUG
//// System.out.println("Sending notification added user "+ infoContactModel.getLogin() +" to share folder "+sharedFolder.getName() + " for user "+contact.getLogin());
//
// boolean notify = notificationsMng.notifyFolderAddedUser(contact.getLogin(), sharedFolder, infoContactModel.getLogin());
//
// if(!notify)
// gcubeLogger.error("An error occured when notifies user: "+infoContactModel.getLogin());
//
// }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();
// }
try{
//CREATE TEMPORARY HASH
HashMap<String, InfoContactModel> hashLoginAlreadyShared = new HashMap<String, InfoContactModel>();
for (InfoContactModel infoContactModel : listSharedContact) {
hashLoginAlreadyShared.put(infoContactModel.getLogin(),infoContactModel);
}
DiffereceBeetweenInfoContactModel diff = new DiffereceBeetweenInfoContactModel(listSharingContact, listSharedContact);
if(listSharedContact==null)
return;
List<InfoContactModel> listExclusiveContacts = diff.getDifferentsContacts();
for (InfoContactModel infoContactModel : listSharingContact) {
if(hashLoginAlreadyShared.get(infoContactModel.getLogin())==null){ //if is new contact.. notifies share
System.out.println("list exclusive contacts: "+listExclusiveContacts);
if(listExclusiveContacts.size()>0){
if(listExclusiveContacts.size()==1){ //CASE ONLY ONE CONTACS WAS ADDED
InfoContactModel infoContactModel = listExclusiveContacts.get(0);
for (InfoContactModel contact : listSharedContact) { //NOTIFIES ALREADY SHARED CONTACTS THATH A NEW USER WAS ADDED
try{
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
if(infoContactModel.getLogin().compareTo(userId)!=0){
for (InfoContactModel contact : listSharedContact) { //NOTIFIES ALREADY SHARED CONTACTS
gcubeLogger.trace("Sending notification to user "+contact.getLogin()+", added user "+ infoContactModel.getLogin() +" to share folder "+sharedFolder.getName());
try{
gcubeLogger.trace("Sending notification to user "+contact.getLogin()+", added user "+ infoContactModel.getLogin() +" to share folder "+sharedFolder.getName());
//DEBUG
// System.out.println("Sending notification added user "+ infoContactModel.getLogin() +" to share folder "+sharedFolder.getName() + " for user "+contact.getLogin());
boolean notify = notificationsMng.notifyFolderAddedUser(contact.getLogin(), sharedFolder, infoContactModel.getLogin());
if(!notify)
gcubeLogger.error("An error occured when notifies user: "+infoContactModel.getLogin());
//DEBUG
// System.out.println("Sending notification added user "+ infoContactModel.getLogin() +" to share folder "+sharedFolder.getName() + " for user "+contact.getLogin());
}catch (Exception e) {
gcubeLogger.error("An error occured in notifyFolderAddedUser ", e);
e.printStackTrace();
}
boolean notify = notificationsMng.notifyFolderAddedUser(contact.getLogin(), sharedFolder, infoContactModel.getLogin());
if(!notify)
gcubeLogger.error("An error occured when notifies user: "+contact.getLogin());
}catch (Exception e) {
gcubeLogger.error("An error occured in notifyFolderAddedUser ", e);
e.printStackTrace();
}
}
}
}
}else{ //CASE MORE THEN ONE CONTACS WAS ADDED
List<String> listLogins = UserUtil.getListLoginByInfoContactModel(listExclusiveContacts);
for (InfoContactModel contact : listSharedContact) { //NOTIFIES ALREADY SHARED CONTACTS THATH A NEW USER WAS ADDED
try{
gcubeLogger.trace("Sending notification to user "+contact.getLogin()+", added "+listLogins.size()+" users to share folder "+sharedFolder.getName());
//DEBUG
// System.out.println("Sending notification added user "+ infoContactModel.getLogin() +" to share folder "+sharedFolder.getName() + " for user "+contact.getLogin());
boolean notify = notificationsMng.notifyFolderAddedUsers(contact.getLogin(), sharedFolder, listLogins);
if(!notify)
gcubeLogger.error("An error occured when notifies user: "+contact.getLogin());
}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();
@ -247,6 +318,7 @@ public class NotificationsProducer {
}
/**
* Runs a new thread to notify the contacts passed in input
* @param listContacts

View File

@ -0,0 +1,113 @@
package org.gcube.portlets.user.workspace.server.util;
import java.util.ArrayList;
import java.util.List;
import org.gcube.portlets.user.workspace.client.model.InfoContactModel;
/**
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
*
*/
public class DiffereceBeetweenInfoContactModel {
private List<InfoContactModel> listOne;
private List<InfoContactModel> listTwo;
/**
* Get difference between listA and listB
* @param listA
* @param listB
*/
public DiffereceBeetweenInfoContactModel(List<InfoContactModel> listA, List<InfoContactModel> listB){
this.listOne = listA;
this.listTwo = listB;
}
/**
*
* @return what is in listA that is not in listB.
*/
public List<InfoContactModel> getDifferentsContacts(){
if(this.listOne==null)
return new ArrayList<InfoContactModel>();
if(this.listTwo==null || this.listTwo.size()==0)
return this.listOne;
List<InfoContactModel> difference = new ArrayList<InfoContactModel>();
boolean found;
for (InfoContactModel o1 : listOne) {
found = false;
for (InfoContactModel o2 : listTwo) {
if(compare(o1,o2)==0){
found = true;
break;
}
}
if(!found)
difference.add(o1);
}
return difference;
}
/**
*
* @param o1
* @param o2
* @return 0 if and only if o1.getName().compareTo(o2.getName())==0 && (o1.getLogin().compareTo(o2.getLogin())==0) is true
*/
public int compare(InfoContactModel o1, InfoContactModel o2) {
if (o1 == null) {
return -1;
} else if (o2 == null) {
return 1;
}
if (o1.getName().compareTo(o2.getName())==0 && (o1.getLogin().compareTo(o2.getLogin())==0))
return 0;
else
return -2;
}
/**
* test
* @param args
*/
public static void main(String[] args) {
List<InfoContactModel> listA = new ArrayList<InfoContactModel>();
listA.add(new InfoContactModel("federico.defaveri", "federico.defaveri", "Federico de Faveri"));
listA.add(new InfoContactModel("antonio.gioia", "antonio.gioia", "Antonio Gioia"));
listA.add(new InfoContactModel("fabio.sinibaldi", "fabio.sinibaldi", "Fabio Sinibaldi"));
listA.add(new InfoContactModel("pasquale.pagano", "pasquale.pagano", "Pasquale Pagano"));
listA.add(new InfoContactModel("francesco.mangiacrapa", "francesco.mangiacrapa", "Francesco Mangiacrapa"));
listA.add(new InfoContactModel("massimiliano.assante", "massimiliano.assante", "Massimiliano Assante"));
List<InfoContactModel> listB = new ArrayList<InfoContactModel>();
listB.add(new InfoContactModel("federico.defaveri", "federico.defaveri", "Federico de Faveri"));
listB.add(new InfoContactModel("fabio.sinibaldi", "fabio.sinibaldi", "Fabio Sinibaldi"));
listB.add(new InfoContactModel("antonio.gioia", "antonio.gioia", "Antonio Gioia"));
listB.add(new InfoContactModel("pasquale.pagano", "pasquale.pagano", "Pasquale Pagano"));
DiffereceBeetweenInfoContactModel diff = new DiffereceBeetweenInfoContactModel(listA, listB);
System.out.println("the differce is: "+diff.getDifferentsContacts());
}
}

View File

@ -1,6 +1,10 @@
package org.gcube.portlets.user.workspace.server.util;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import org.gcube.portlets.user.workspace.client.model.InfoContactModel;
import org.gcube.vomanagement.usermanagement.UserManager;
import org.gcube.vomanagement.usermanagement.exception.UserManagementPortalException;
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
@ -51,4 +55,15 @@ public class UserUtil {
return "";
}
public static List<String> getListLoginByInfoContactModel(List<InfoContactModel> listContacts){
List<String> listUsers = new ArrayList<String>();
for (InfoContactModel infoContactModel : listContacts) {
listUsers.add(infoContactModel.getLogin());
}
return listUsers;
}
}