diff --git a/pom.xml b/pom.xml index 61526be..f853bca 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ org.gcube.portlets.user workspace-tree-widget - 6.0.1-SNAPSHOT + 6.0.2-SNAPSHOT gCube Workspace Tree Widget gCube Workspace Tree Widget. diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceBuilder.java b/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceBuilder.java index 9900537..4c62ded 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceBuilder.java +++ b/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceBuilder.java @@ -997,18 +997,6 @@ public class GWTWorkspaceBuilder { } - public List getListLoginByInfoContactModel(List listContacts){ - - List listUsers = new ArrayList(); - - for (InfoContactModel infoContactModel : listContacts) { - listUsers.add(infoContactModel.getLogin()); - } - - return listUsers; - } - - protected List buildGXTListFileGridModelItem(List listWorkspaceItems, FileModel parentFileModel) throws InternalErrorException { diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java b/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java index 7346dea..86cd2de 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java @@ -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 listLogin = builder.getListLoginByInfoContactModel(listContacts); + + List 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; diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/notifications/NotificationsProducer.java b/src/main/java/org/gcube/portlets/user/workspace/server/notifications/NotificationsProducer.java index 80554c4..6f5acbd 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/server/notifications/NotificationsProducer.java +++ b/src/main/java/org/gcube/portlets/user/workspace/server/notifications/NotificationsProducer.java @@ -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 listSharedContact, final WorkspaceItem item, final WorkspaceFolder sharedFolder) { + public void notifyItemRenamed(final List 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 listSharedContact, final List listSharingContact, final WorkspaceSharedFolder sharedFolder) { + public void notifyAddedUsersToSharing(final List listSharedContact, final List listSharingContact, final WorkspaceSharedFolder sharedFolder) { new Thread() { @Override public void run() { +// try{ +// //CREATE TEMPORARY HASH +// HashMap hashLoginAlreadyShared = new HashMap(); +// +// 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 hashLoginAlreadyShared = new HashMap(); - - for (InfoContactModel infoContactModel : listSharedContact) { - hashLoginAlreadyShared.put(infoContactModel.getLogin(),infoContactModel); - } + + DiffereceBeetweenInfoContactModel diff = new DiffereceBeetweenInfoContactModel(listSharingContact, listSharedContact); - if(listSharedContact==null) - return; + List 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 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 diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/util/DiffereceBeetweenInfoContactModel.java b/src/main/java/org/gcube/portlets/user/workspace/server/util/DiffereceBeetweenInfoContactModel.java new file mode 100644 index 0000000..11ff5e6 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/workspace/server/util/DiffereceBeetweenInfoContactModel.java @@ -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 listOne; + private List listTwo; + + /** + * Get difference between listA and listB + * @param listA + * @param listB + */ + public DiffereceBeetweenInfoContactModel(List listA, List listB){ + + this.listOne = listA; + this.listTwo = listB; + + } + + /** + * + * @return what is in listA that is not in listB. + */ + public List getDifferentsContacts(){ + + if(this.listOne==null) + return new ArrayList(); + + if(this.listTwo==null || this.listTwo.size()==0) + return this.listOne; + + List difference = new ArrayList(); + + 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 listA = new ArrayList(); + 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 listB = new ArrayList(); + + 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()); + + } + + +} diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/util/UserUtil.java b/src/main/java/org/gcube/portlets/user/workspace/server/util/UserUtil.java index 3430b74..2972b4e 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/server/util/UserUtil.java +++ b/src/main/java/org/gcube/portlets/user/workspace/server/util/UserUtil.java @@ -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 getListLoginByInfoContactModel(List listContacts){ + + List listUsers = new ArrayList(); + + for (InfoContactModel infoContactModel : listContacts) { + listUsers.add(infoContactModel.getLogin()); + } + + return listUsers; + } }