From 6d1205024f95a4b3c45c9e4da48551d78f855aef Mon Sep 17 00:00:00 2001 From: Francesco Mangiacrapa Date: Thu, 5 Nov 2015 10:23:01 +0000 Subject: [PATCH] 124: Workspace / Remove a user from a shared folder Task-Url: https://support.d4science.org/issues/124 Updated Dialog Share Folder and server side to remove user from a shared folder git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@120188 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../client/model/InfoContactModel.java | 76 +++++- .../view/sharing/DialogShareFolder.java | 221 +++++++++++++----- .../client/view/sharing/UserStore.java | 2 +- .../multisuggest/MultiDragContact.java | 1 + .../server/GWTWorkspaceServiceImpl.java | 2 +- .../notifications/NotificationsProducer.java | 200 +++++++++++----- .../DiffereceBeetweenInfoContactModel.java | 93 +++----- .../user/workspace/shared/ContactLogin.java | 21 ++ .../user/workspace/shared/ListContact.java | 52 +++++ .../user/workspace/SizeRetrieving.java | 24 +- 10 files changed, 508 insertions(+), 184 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/workspace/shared/ContactLogin.java create mode 100644 src/main/java/org/gcube/portlets/user/workspace/shared/ListContact.java diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/model/InfoContactModel.java b/src/main/java/org/gcube/portlets/user/workspace/client/model/InfoContactModel.java index e7ffb2c..b40531b 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/model/InfoContactModel.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/model/InfoContactModel.java @@ -3,13 +3,17 @@ package org.gcube.portlets.user.workspace.client.model; import java.io.Serializable; import java.util.Comparator; +import org.gcube.portlets.user.workspace.shared.ContactLogin; + import com.extjs.gxt.ui.client.data.BaseModelData; /** - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * The Class InfoContactModel. * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Nov 4, 2015 */ -public class InfoContactModel extends BaseModelData implements Serializable { +public class InfoContactModel extends BaseModelData implements ContactLogin, Serializable { /** @@ -23,8 +27,19 @@ public class InfoContactModel extends BaseModelData implements Serializable { public static final String ISGROUP = "isgroup"; + /** + * Instantiates a new info contact model. + */ public InfoContactModel() {} + /** + * Instantiates a new info contact model. + * + * @param id the id + * @param login the login + * @param fullName the full name + * @param isGroup the is group + */ public InfoContactModel(String id, String login, String fullName, boolean isGroup) { setId(id); setLogin(login); @@ -33,41 +48,73 @@ public class InfoContactModel extends BaseModelData implements Serializable { } /** - * @param isGroup + * Sets the checks if is group. + * + * @param isGroup the new checks if is group */ public void setIsGroup(boolean isGroup) { set(ISGROUP,isGroup); } /** - * @param isGroup + * Checks if is group. + * + * @return true, if is group */ public boolean isGroup() { return (Boolean) get(ISGROUP); } + /** + * Sets the name. + * + * @param name the new name + */ public void setName(String name) { set(FULLNAME,name); } + /** + * Gets the name. + * + * @return the name + */ public String getName(){ String name = (String) (get(FULLNAME)!=null?get(FULLNAME):""); return name; } + /** + * Gets the id. + * + * @return the id + */ public String getId() { return get(ID); } + /** + * Sets the id. + * + * @param id the new id + */ public void setId(String id) { set(ID, id); } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.shared.ContactLogin#getLogin() + */ public String getLogin() { return get(LOGIN); } + /** + * Sets the login. + * + * @param login the new login + */ public void setLogin(String login) { set(LOGIN, login); } @@ -76,7 +123,14 @@ public class InfoContactModel extends BaseModelData implements Serializable { public static Comparator COMPARATORFULLNAME = new Comparator() { // This is where the sorting happens. public int compare(InfoContactModel o1, InfoContactModel o2) { - return o1.getName().compareToIgnoreCase(o2.getName()); + + if(o1==null) + return -1; + + if(o2==null) + return 1; + + return o1.getName().compareTo(o2.getName()); } }; @@ -84,10 +138,20 @@ public class InfoContactModel extends BaseModelData implements Serializable { public static Comparator COMPARATORLOGINS = new Comparator() { // This is where the sorting happens. public int compare(InfoContactModel o1, InfoContactModel o2) { - return o1.getLogin().compareToIgnoreCase(o2.getLogin()); + + if(o1==null) + return -1; + + if(o2==null) + return 1; + + return o1.getLogin().compareTo(o2.getLogin()); } }; + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ @Override public String toString() { StringBuilder builder = new StringBuilder(); diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/view/sharing/DialogShareFolder.java b/src/main/java/org/gcube/portlets/user/workspace/client/view/sharing/DialogShareFolder.java index ac0fec9..6ccfc32 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/view/sharing/DialogShareFolder.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/view/sharing/DialogShareFolder.java @@ -1,6 +1,5 @@ package org.gcube.portlets.user.workspace.client.view.sharing; -import java.util.ArrayList; import java.util.List; import org.gcube.portlets.user.workspace.client.AppControllerExplorer; @@ -11,6 +10,7 @@ import org.gcube.portlets.user.workspace.client.resources.Resources; import org.gcube.portlets.user.workspace.client.view.sharing.multisuggest.MultiDragContact; import org.gcube.portlets.user.workspace.client.view.sharing.multisuggest.MultiValuePanel; import org.gcube.portlets.user.workspace.client.view.windows.MessageBoxAlert; +import org.gcube.portlets.user.workspace.shared.ListContact; import org.gcube.portlets.user.workspace.shared.WorkspaceACL; import com.extjs.gxt.ui.client.Style.HorizontalAlignment; @@ -33,9 +33,12 @@ import com.google.gwt.user.client.ui.Button; import com.google.gwt.user.client.ui.FlexTable; import com.google.gwt.user.client.ui.Label; + /** - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * The Class DialogShareFolder. * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Nov 4, 2015 */ public class DialogShareFolder extends Dialog { @@ -50,35 +53,15 @@ public class DialogShareFolder extends Dialog { private TextField txtOwner; private PanelTogglePermission permission; private HorizontalPanel hpPermission = null; - - private List listAlreadyShared = new ArrayList(){ - - private static final long serialVersionUID = 1L; - - /** - * Compare Login - */ - @Override - public boolean contains(Object o) { - - if(o==null) - return false; - - InfoContactModel contact = (InfoContactModel) o; - - for (int i = 0; i < listAlreadyShared.size(); i++){ - if (contact.getName().compareTo(listAlreadyShared.get(i).getName())==0) - return true; - } - - return false; - }; - }; + private InfoContactModel shareOwner = null; + private ListContact listAlreadyShared = new ListContact(); /** - * Use to modify a shared folder or share an existing folder - * @param folder - * @param type + * Use to modify a shared folder or share an existing folder. + * + * @param folderParentName the folder parent name + * @param folder the folder + * @param eventBus the event bus */ public DialogShareFolder(String folderParentName, final FileModel folder, HandlerManager eventBus) { initLayout(folderParentName); @@ -163,31 +146,7 @@ public class DialogShareFolder extends Dialog { if(hpPermission!=null) lc.add(hpPermission); lc.mask(); - userStore.getListSharedUserByFolderId(folder.getIdentifier(), new AsyncCallback>() { - - @Override - public void onSuccess(List listContacts) { - - if(listContacts!=null){ - for (InfoContactModel infoContactModel : listContacts) { -// System.out.println(infoContactModel); - if(infoContactModel!=null && infoContactModel.getName()!=null){ - listAlreadyShared.add(infoContactModel); - suggestPanel.addRecipient(infoContactModel.getName(),false); - } - } - } - lc.unmask(); - } - - @Override - public void onFailure(Throwable caught) { - lc.unmask(); - - } - }); - userStore.getOwner(folder.getIdentifier(), new AsyncCallback() { @Override @@ -197,9 +156,12 @@ public class DialogShareFolder extends Dialog { @Override public void onSuccess(InfoContactModel result) { + shareOwner = result; txtOwner.setValue(result.getName()); permissionControl(result.getLogin(), true); + fillRecipientAlreadyShared(folder.getIdentifier(), lc); } + }); setFocusWidget(suggestPanel.getBox()); @@ -212,6 +174,59 @@ public class DialogShareFolder extends Dialog { this.show(); } + /** + * Update recipient of share. + * + * @param listContacts the list contacts + */ + private void updateRecipientOfShare(List listContacts){ + suggestPanel.resetItemSelected(); + for (InfoContactModel contact : listContacts){ + if(contact!=null && contact.getName()!=null){ + if(!isShareOwner(contact)) //skip owner + suggestPanel.addRecipient(contact.getName(), true); + else + suggestPanel.addRecipient(contact.getName(), false); //owner is not deletable + } + } + } + + + /** + * Fill recipient already shared. + * + * @param folderId the folder id + * @param lc the lc + */ + private void fillRecipientAlreadyShared(String folderId, final LayoutContainer lc) { + + userStore.getListSharedUserByFolderId(folderId, + new AsyncCallback>() { + + @Override + public void onSuccess(List listContacts) { + + if (listContacts != null) { + listAlreadyShared.addAll(listContacts); + updateRecipientOfShare(listContacts); + } + lc.unmask(); + } + + @Override + public void onFailure(Throwable caught) { + lc.unmask(); + } + }); + + } + + /** + * Permission control. + * + * @param owner the owner + * @param showAlert the show alert + */ private void permissionControl(String owner, boolean showAlert){ GWT.log("Permission control compare between owner: "+owner +" and my login: "+AppControllerExplorer.myLogin); @@ -224,6 +239,11 @@ public class DialogShareFolder extends Dialog { } } + /** + * Enable form dialog. + * + * @param bool the bool + */ private void enableFormDialog(boolean bool){ getButtonById(Dialog.OK).setEnabled(bool); buttonMultiDrag.setEnabled(bool); @@ -233,10 +253,20 @@ public class DialogShareFolder extends Dialog { } + /** + * Gets the parent folder. + * + * @return the parent folder + */ public FileModel getParentFolder() { return parentFolder; } + /** + * Inits the layout. + * + * @param folderParentName the folder parent name + */ public void initLayout(String folderParentName){ FormLayout layout = new FormLayout(); layout.setLabelWidth(90); @@ -254,7 +284,10 @@ public class DialogShareFolder extends Dialog { } /** - * Use to create a new shared folder + * Use to create a new shared folder. + * + * @param folderParentName the folder parent name + * @param eventBus the event bus */ public DialogShareFolder(String folderParentName, HandlerManager eventBus) { @@ -332,12 +365,20 @@ public class DialogShareFolder extends Dialog { } + /** + * Gets the shared list users. + * + * @return the shared list users + */ public List getSharedListUsers() { // printSelectedUser(); return suggestPanel.getSelectedUser(); } + /** + * Adds the listners. + */ public void addListners(){ this.getButtonById(Dialog.CANCEL).addSelectionListener(new SelectionListener() { @@ -368,19 +409,23 @@ public class DialogShareFolder extends Dialog { List exclusiveContacts = userStore.getExclusiveContactsFromAllContact(suggestPanel.getSelectedUser()); multiDrag.addSourceContacts(exclusiveContacts); - for (InfoContactModel infoContactModel : suggestPanel.getSelectedUser()) { - if(!listAlreadyShared.contains(infoContactModel)) +// if(!listAlreadyShared.contains(infoContactModel)) + if(!isShareOwner(infoContactModel)) multiDrag.addTargetContact(infoContactModel); } - multiDrag.addAlreadySharedContacts(suggestPanel.getSelectedUser()); +// multiDrag.addAlreadySharedContacts(suggestPanel.getSelectedUser()); + + multiDrag.addAlreadySharedContacts(listAlreadyShared); multiDrag.getButtonById(Dialog.OK).addSelectionListener(new SelectionListener() { @Override public void componentSelected(ButtonEvent ce) { - initSuggestContacts(); +// initSuggestContacts(); + suggestPanel.resetItemSelected(); + suggestPanel.addRecipient(shareOwner.getName(),false); for (InfoContactModel infoContactModel : multiDrag.getTargetListContact()) { suggestPanel.addRecipient(infoContactModel.getName(),true); } @@ -392,19 +437,46 @@ public class DialogShareFolder extends Dialog { }); } + + /** + * Checks if is share owner. + * + * @param infoContactModel the info contact model + * @return true, if is share owner + */ + public boolean isShareOwner(InfoContactModel infoContactModel){ + + if(infoContactModel!=null && shareOwner!=null && InfoContactModel.COMPARATORLOGINS.compare(infoContactModel, shareOwner)==0) + return true; + + return false; + } + + + /** + * List already shared contains. + * + * @param contact the contact + * @return true, if successful + */ private boolean listAlreadySharedContains(InfoContactModel contact){ if(contact==null) return false; for (InfoContactModel ct : listAlreadyShared) { - if(ct.getLogin().compareTo(contact.getLogin())==0) + if(InfoContactModel.COMPARATORLOGINS.compare(ct, contact)==0) +// if(ct.getLogin().compareTo(contact.getLogin())==0) return true; } return false; } //DEBUG + /** + * Prints the selected user. + */ + @SuppressWarnings("unused") private void printSelectedUser(){ System.out.println("SELETECTED USERS: "); @@ -412,16 +484,30 @@ public class DialogShareFolder extends Dialog { System.out.println(contact); } + /** + * Inits the suggest contacts. + */ + @SuppressWarnings("unused") private void initSuggestContacts(){ suggestPanel.resetItemSelected(); for (InfoContactModel contact : listAlreadyShared) suggestPanel.addRecipient(contact.getName(), false); } + /** + * Gets the name. + * + * @return the name + */ public String getName() { return txtName.getValue(); } + /** + * Gets the description. + * + * @return the description + */ public String getDescription() { if(textAreaDescription.getValue()==null) return ""; @@ -430,9 +516,10 @@ public class DialogShareFolder extends Dialog { } /** - * - * @param displayAlert - * @return + * Checks if is valid form. + * + * @param displayAlert the display alert + * @return true, if is valid form */ public boolean isValidForm(boolean displayAlert){ @@ -454,12 +541,22 @@ public class DialogShareFolder extends Dialog { } + /** + * Gets the selected acl. + * + * @return the selected acl + */ public WorkspaceACL getSelectedACL(){ if(permission!=null) return permission.getSelectedACL(); return null; } + /** + * Select acl for folder. + * + * @param folder the folder + */ private void selectAclForFolder(FileModel folder){ GWT.log("Loading ACL to: "+folder); AppControllerExplorer.rpcWorkspaceService.getACLBySharedFolderId(folder.getIdentifier(), new AsyncCallback() { diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/view/sharing/UserStore.java b/src/main/java/org/gcube/portlets/user/workspace/client/view/sharing/UserStore.java index b507c94..91b4210 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/view/sharing/UserStore.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/view/sharing/UserStore.java @@ -85,7 +85,7 @@ public class UserStore implements ContactFetcher{ List listExclusiveContact = new ArrayList(listAllContact); for (InfoContactModel contact : listSharedUser) { if(listAllContact.contains(contact)){ -// GWT.log("Removing not eclusive contact "+contact); + GWT.log("Removing not eclusive contact "+contact); listExclusiveContact.remove(contact); } } diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/view/sharing/multisuggest/MultiDragContact.java b/src/main/java/org/gcube/portlets/user/workspace/client/view/sharing/multisuggest/MultiDragContact.java index 052d75e..47036f8 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/view/sharing/multisuggest/MultiDragContact.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/view/sharing/multisuggest/MultiDragContact.java @@ -491,6 +491,7 @@ public class MultiDragContact extends Dialog { } storeSource.add(listExtended); +// GWT.log("Added sources: "+listExtended.toString()); } gridAllContacts.unmask(); 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 4396f42..0bac6b4 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 @@ -2008,7 +2008,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT np.notifyFolderSharing(listContacts, sharedFolder); else{ // printContacts(listContacts); - np.notifyAddedUsersToSharing(listSharedContact, listContacts, sharedFolder); + np.notifyUpdatedUsersToSharing(listSharedContact, listContacts, sharedFolder); } } 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 2f606d3..08f0e13 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 @@ -20,9 +20,9 @@ import org.gcube.portlets.user.workspace.server.util.UserUtil; import org.gcube.portlets.user.workspace.server.util.WsUtil; /** - * - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * The Class NotificationsProducer. * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it */ public class NotificationsProducer { @@ -36,8 +36,9 @@ public class NotificationsProducer { /** - * - * @param aslSession + * Instantiates a new notifications producer. + * + * @param aslSession the asl session */ public NotificationsProducer(ASLSession aslSession) { this.notificationsMng = WsUtil.getNotificationManager(aslSession); @@ -45,23 +46,39 @@ public class NotificationsProducer { this.userId = aslSession.getUsername(); } + /** + * Gets the notifications mng. + * + * @return the notifications mng + */ public NotificationsManager getNotificationsMng() { return notificationsMng; } + /** + * Sets the notification mng. + * + * @param notificationMng the new notification mng + */ public void setNotificationMng(NotificationsManager notificationMng) { this.notificationsMng = notificationMng; } + /** + * Gets the asl session. + * + * @return the asl session + */ public ASLSession getAslSession() { return aslSession; } /** - * Runs a new thread to notify the contacts passed in input - * @param listContacts - * @param sharedFolder + * Runs a new thread to notify the contacts passed in input. + * + * @param listContacts the list contacts + * @param sharedFolder the shared folder */ public void notifyFolderSharing(final List listContacts, final WorkspaceSharedFolder sharedFolder) { @@ -103,10 +120,13 @@ public class NotificationsProducer { /** - * Runs a new thread to notify the contacts passed in input - * @param folderItem - * @param listContacts - * @param sharedFolder + * Runs a new thread to notify the contacts passed in input. + * + * @param listSharedContact the list shared contact + * @param folderItem the folder item + * @param itemOldName the item old name + * @param itemNewName the item new name + * @param idsharedFolder the idshared folder */ public void notifyFolderRenamed(final List listSharedContact, final WorkspaceItem folderItem, final String itemOldName, final String itemNewName, final String idsharedFolder) { @@ -159,9 +179,12 @@ public class NotificationsProducer { /** - * Runs a new thread to notify the contacts passed in input - * @param listContacts - * @param sharedFolder + * Runs a new thread to notify the contacts passed in input. + * + * @param listSharedContact the list shared contact + * @param previousName the previous name + * @param item the item + * @param sharedFolder the shared folder */ public void notifyItemRenamed(final List listSharedContact, final String previousName, final WorkspaceItem item, final WorkspaceSharedFolder sharedFolder) { @@ -203,32 +226,34 @@ public class NotificationsProducer { /** - * Runs a new thread to notify the new contacts passed in input + * Runs a new thread to notify the updated (add/remove) contacts to sharing + * * @param listSharedContact - list of contacts already shared - * @param listSharingContact - list of "new" contacts witch share + * @param listSharingContact - list of "new" contacts to share * @param sharedFolder - the shared folder */ - public void notifyAddedUsersToSharing(final List listSharedContact, final List listSharingContact, final WorkspaceSharedFolder sharedFolder) { + public void notifyUpdatedUsersToSharing(final List listSharedContact, final List listSharingContact, final WorkspaceSharedFolder sharedFolder) { new Thread() { @Override public void run() { try{ - + + //NEW USER SHARED DiffereceBeetweenInfoContactModel diff = new DiffereceBeetweenInfoContactModel(listSharingContact, listSharedContact); - List listExclusiveContacts = diff.getDifferentsContacts(); + List listNewContactsShared = diff.getDifferentsContacts(); - System.out.println("list exclusive contacts: "+listExclusiveContacts); + logger.trace("list new contacts shared: "+listNewContactsShared.size()); - if(listExclusiveContacts.size()>0){ + if(listNewContactsShared.size()>0){ - if(listExclusiveContacts.size()==1){ //CASE ONLY ONE CONTACS WAS ADDED + if(listNewContactsShared.size()==1){ //CASE ONLY ONE CONTACS WAS ADDED - InfoContactModel infoContactModel = listExclusiveContacts.get(0); + InfoContactModel infoContactModel = listNewContactsShared.get(0); - for (InfoContactModel contact : listSharedContact) { //NOTIFIES ALREADY SHARED CONTACTS THATH A NEW USER WAS ADDED + for (InfoContactModel contact : listSharedContact) { //NOTIFIES ALREADY SHARED CONTACTS THAT A NEW USER WAS ADDED try{ @@ -252,9 +277,9 @@ public class NotificationsProducer { listCts.add(infoContactModel); notifyFolderSharing(listCts, sharedFolder); //NOTIFIER NEW USER OF SHARING FOLDER - }else{ //CASE MORE THEN ONE CONTACS WAS ADDED + }else{ //CASE MORE THEN ONE CONTACT WAS ADDED - List listLogins = UserUtil.getListLoginByInfoContactModel(listExclusiveContacts); + List listLogins = UserUtil.getListLoginByInfoContactModel(listNewContactsShared); for (InfoContactModel contact : listSharedContact) { //NOTIFIES ALREADY SHARED CONTACTS THATH A NEW USER WAS ADDED @@ -276,12 +301,23 @@ public class NotificationsProducer { } } - - notifyFolderSharing(listExclusiveContacts, sharedFolder); //NOTIFIER NEW USER OF SHARING FOLDER - + notifyFolderSharing(listNewContactsShared, sharedFolder); //NOTIFIER NEW USER OF SHARING FOLDER } } + + //USER REMOVED FROM SHARE + DiffereceBeetweenInfoContactModel diff2 = new DiffereceBeetweenInfoContactModel(listSharedContact, listSharingContact); + + List listRemovedUsersFromShare = diff2.getDifferentsContacts(); + + logger.trace("list removed contacts from share: "+listNewContactsShared.size()); + + if(listRemovedUsersFromShare.size()>0){ + + for (InfoContactModel contact : listRemovedUsersFromShare) + notifyFolderRemovedUser(contact, sharedFolder); + } }catch (Exception e) { logger.error("An error occured in notifyAddedUserToSharing ", e); @@ -295,9 +331,11 @@ public class NotificationsProducer { /** - * Runs a new thread to notify the contacts passed in input - * @param listContacts - * @param unSharedFolder + * Runs a new thread to notify the contacts passed in input. + * + * @param listContacts the list contacts + * @param unShareFolderId the un share folder id + * @param unSharedFolderName the un shared folder name */ public void notifyFolderUnSharing(final List listContacts, final String unShareFolderId, final String unSharedFolderName) { @@ -337,13 +375,49 @@ public class NotificationsProducer { }.start(); } + + /** + * Notify folder removed user. + * + * @param userUnShared the user un shared + * @param unSharedFolder the un shared folder + */ + public void notifyFolderRemovedUser(final InfoContactModel userUnShared, final WorkspaceSharedFolder shareFolder) { + + new Thread() { + @Override + public void run() { + + logger.trace("Send notifies removed user from shared folder is running..."); + try{ + //NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER + if(userUnShared.getLogin().compareTo(userId)!=0){ + + logger.trace("Sending notification to user "+userUnShared.getLogin() +" unshared from folder "+shareFolder.getName()); + boolean notify = notificationsMng.notifyFolderRemovedUser(userUnShared.getLogin(), (WorkspaceSharedFolder) shareFolder); + + if(!notify) + logger.error("An error occured when notifies user: "+userUnShared.getLogin()); + } + + }catch (Exception e) { + logger.error("An error occured in notifyFolderRemovedUser ", e); + } + + logger.trace("notifies of un unshare user is completed"); + } + + }.start(); + } /** - * Runs a new thread to notify the contacts passed in input - * @param listContacts - * @param workspaceItem + * Runs a new thread to notify the contacts passed in input. + * + * @param listContacts the list contacts + * @param workspaceItem the workspace item + * @param sharedFolder the shared folder */ public void notifyAddedItemToSharing(final List listContacts, final WorkspaceItem workspaceItem, final WorkspaceSharedFolder sharedFolder) { @@ -396,9 +470,11 @@ public class NotificationsProducer { /** - * Runs a new thread to notify the contacts passed in input - * @param listContacts - * @param workspaceItem + * Runs a new thread to notify the contacts passed in input. + * + * @param listContacts the list contacts + * @param workspaceItem the workspace item + * @param sharedFolder the shared folder */ public void notifyUpdatedItemToSharing(final List listContacts, final WorkspaceItem workspaceItem, final WorkspaceSharedFolder sharedFolder) { @@ -454,9 +530,11 @@ public class NotificationsProducer { /** - * Runs a new thread to notify the contacts passed in input - * @param listContacts - * @param sharedFolder + * Runs a new thread to notify the contacts passed in input. + * + * @param listContacts the list contacts + * @param workspaceItem the workspace item + * @param sharedFolder the shared folder */ public void notifyMovedItemToSharing(final List listContacts, final WorkspaceItem workspaceItem, final WorkspaceSharedFolder sharedFolder) { @@ -524,9 +602,11 @@ public class NotificationsProducer { /** - * Runs a new thread to notify the contacts passed in input - * @param listContacts - * @param sharedFolder + * Runs a new thread to notify the contacts passed in input. + * + * @param listContacts the list contacts + * @param itemName the item name + * @param sharedFolder the shared folder */ public void notifyRemovedItemToSharing(final List listContacts, final String itemName, final WorkspaceSharedFolder sharedFolder) { @@ -587,9 +667,10 @@ public class NotificationsProducer { } /** - * Runs a new thread to notify the contacts passed in input - * @param listContacts - * @param unSharedFolder + * Runs a new thread to notify the contacts passed in input. + * + * @param listContacts the list contacts + * @param folderNameDeleted the folder name deleted */ public void notifySharedFolderDeleted(final List listContacts, final String folderNameDeleted) { @@ -633,9 +714,10 @@ public class NotificationsProducer { /** - * Runs a new thread to notify the contacts passed in input - * @param userToNotify - * @param sharedFolder + * Runs a new thread to notify the contacts passed in input. + * + * @param userToNotify the user to notify + * @param sharedFolder the shared folder */ public void notifyAdministratorUpgrade(final InfoContactModel userToNotify, final WorkspaceSharedFolder sharedFolder){ @@ -673,9 +755,10 @@ public class NotificationsProducer { } /** - * Runs a new thread to notify the contacts passed in input - * @param userToNotify - * @param sharedFolder + * Runs a new thread to notify the contacts passed in input. + * + * @param userToNotify the user to notify + * @param sharedFolder the shared folder */ public void notifyAdministratorDowngrade(final InfoContactModel userToNotify, final WorkspaceSharedFolder sharedFolder){ @@ -713,6 +796,11 @@ public class NotificationsProducer { } //DEBUG + /** + * Prints the contacts. + * + * @param listContacts the list contacts + */ private void printContacts(List listContacts){ System.out.println("Print contacts"); @@ -722,6 +810,12 @@ public class NotificationsProducer { System.out.println("End print contacts"); } + /** + * The main method. + * + * @param args the arguments + * @throws Exception the exception + */ public static void main(String[] args) throws Exception { String sessionID = "1"; 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 index 7619cfb..699b90f 100644 --- 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 @@ -5,10 +5,12 @@ import java.util.List; import org.gcube.portlets.user.workspace.client.model.InfoContactModel; + /** - * - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * The Class DiffereceBeetweenInfoContactModel. * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Nov 4, 2015 */ public class DiffereceBeetweenInfoContactModel { @@ -17,9 +19,10 @@ public class DiffereceBeetweenInfoContactModel { private List listTwo; /** - * Get difference between listA and listB - * @param listA - * @param listB + * Get difference between listA and listB . + * + * @param listA the list a + * @param listB the list b */ public DiffereceBeetweenInfoContactModel(List listA, List listB){ @@ -29,7 +32,8 @@ public class DiffereceBeetweenInfoContactModel { } /** - * + * Gets the differents contacts. + * * @return what is in listA that is not in listB. */ public List getDifferentsContacts(){ @@ -47,7 +51,7 @@ public class DiffereceBeetweenInfoContactModel { for (InfoContactModel o1 : listOne) { found = false; for (InfoContactModel o2 : listTwo) { - if(compare(o1,o2)==0){ + if(InfoContactModel.COMPARATORLOGINS.compare(o1, o2)==0){ found = true; break; } @@ -61,53 +65,32 @@ public class DiffereceBeetweenInfoContactModel { } - /** - * - * @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", false)); - listA.add(new InfoContactModel("antonio.gioia", "antonio.gioia", "Antonio Gioia",false)); - listA.add(new InfoContactModel("fabio.sinibaldi", "fabio.sinibaldi", "Fabio Sinibaldi", false)); - listA.add(new InfoContactModel("pasquale.pagano", "pasquale.pagano", "Pasquale Pagano",false)); - listA.add(new InfoContactModel("francesco.mangiacrapa", "francesco.mangiacrapa", "Francesco Mangiacrapa",false)); - listA.add(new InfoContactModel("massimiliano.assante", "massimiliano.assante", "Massimiliano Assante",false)); - - List listB = new ArrayList(); - - listB.add(new InfoContactModel("federico.defaveri", "federico.defaveri", "Federico de Faveri",false)); - listB.add(new InfoContactModel("fabio.sinibaldi", "fabio.sinibaldi", "Fabio Sinibaldi",false)); - listB.add(new InfoContactModel("antonio.gioia", "antonio.gioia", "Antonio Gioia",false)); - listB.add(new InfoContactModel("pasquale.pagano", "pasquale.pagano", "Pasquale Pagano",false)); - - DiffereceBeetweenInfoContactModel diff = new DiffereceBeetweenInfoContactModel(listA, listB); - - System.out.println("the differce is: "+diff.getDifferentsContacts()); - - } - +// /** +// * test. +// * +// * @param args the arguments +// */ +// public static void main(String[] args) { +// +// List listA = new ArrayList(); +// listA.add(new InfoContactModel("federico.defaveri", "federico.defaveri", "Federico de Faveri", false)); +// listA.add(new InfoContactModel("antonio.gioia", "antonio.gioia", "Antonio Gioia",false)); +// listA.add(new InfoContactModel("fabio.sinibaldi", "fabio.sinibaldi", "Fabio Sinibaldi", false)); +// listA.add(new InfoContactModel("pasquale.pagano", "pasquale.pagano", "Pasquale Pagano",false)); +// listA.add(new InfoContactModel("francesco.mangiacrapa", "francesco.mangiacrapa", "Francesco Mangiacrapa",false)); +// listA.add(new InfoContactModel("massimiliano.assante", "massimiliano.assante", "Massimiliano Assante",false)); +// +// List listB = new ArrayList(); +// +// listB.add(new InfoContactModel("federico.defaveri", "federico.defaveri", "Federico de Faveri",false)); +// listB.add(new InfoContactModel("fabio.sinibaldi", "fabio.sinibaldi", "Fabio Sinibaldi",false)); +// listB.add(new InfoContactModel("antonio.gioia", "antonio.gioia", "Antonio Gioia",false)); +// listB.add(new InfoContactModel("pasquale.pagano", "pasquale.pagano", "Pasquale Pagano",false)); +// +// 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/shared/ContactLogin.java b/src/main/java/org/gcube/portlets/user/workspace/shared/ContactLogin.java new file mode 100644 index 0000000..91a3825 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/workspace/shared/ContactLogin.java @@ -0,0 +1,21 @@ +/** + * + */ +package org.gcube.portlets.user.workspace.shared; + +/** + * The Interface ContactLogin. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Nov 4, 2015 + */ +public interface ContactLogin { + + /** + * Gets the login. + * + * @return the login + */ + String getLogin(); + +} diff --git a/src/main/java/org/gcube/portlets/user/workspace/shared/ListContact.java b/src/main/java/org/gcube/portlets/user/workspace/shared/ListContact.java new file mode 100644 index 0000000..cdcea88 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/workspace/shared/ListContact.java @@ -0,0 +1,52 @@ +/** + * + */ +package org.gcube.portlets.user.workspace.shared; + +import java.io.Serializable; +import java.util.ArrayList; + +/** + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Nov 4, 2015 + */ +public class ListContact extends ArrayList implements Serializable{ + + + /** + * + */ + private static final long serialVersionUID = 544202687567940083L; + + /** + * + */ + public ListContact() { + } + + /* (non-Javadoc) + * @see java.util.ArrayList#contains(java.lang.Object) + */ + @Override + public boolean contains(Object o) { + + if(o==null) + return false; + + ContactLogin contact = (ContactLogin) o; + + if(contact.getLogin()==null) + return false; + + + for (int i = 0; i < this.size(); i++){ + + ContactLogin log = get(i); + if (log.getLogin()!=null && log.getLogin().compareTo(contact.getLogin())==0) + return true; + } + + return false; + } +} diff --git a/src/test/java/org/gcube/portlets/user/workspace/SizeRetrieving.java b/src/test/java/org/gcube/portlets/user/workspace/SizeRetrieving.java index 826427b..4e16aa9 100644 --- a/src/test/java/org/gcube/portlets/user/workspace/SizeRetrieving.java +++ b/src/test/java/org/gcube/portlets/user/workspace/SizeRetrieving.java @@ -13,6 +13,7 @@ import org.gcube.common.homelibrary.home.workspace.WorkspaceItem; import org.gcube.common.homelibrary.home.workspace.folder.FolderItem; import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.impl.ScopeBean; +import org.gcube.portlets.user.workspace.server.GWTWorkspaceBuilder; /** * @@ -24,8 +25,9 @@ public class SizeRetrieving { // public static String DEFAULT_SCOPE = "/gcube/devsec"; //DEV - public static String DEFAULT_SCOPE = "/d4science.research-infrastructures.eu/gCubeApps/DESCRAMBLE"; - public static String TEST_USER = "massimiliano.assante"; + public static String DEFAULT_SCOPE = "/d4science.research-infrastructures.eu/gCubeApps"; + public static String TEST_USER = "yann.laurent"; + public static String FOLDER_ID = "4f0ff79d-3c1e-4d2a-bc74-6f731edcac98"; public static void main(String[] args) { @@ -41,13 +43,23 @@ public class SizeRetrieving { .getWorkspace(); // - System.out.println("start get root"); - WorkspaceItem root = ws.getRoot(); +// System.out.println("start get root"); +// WorkspaceItem root = ws.getRoot(); +// List children = (List) root.getChildren(); System.out.println("start get children"); - List children = root.getChildren(); + + WorkspaceFolder folder = (WorkspaceFolder) ws.getItem(FOLDER_ID); + List children = (List) folder.getChildren(); +// List children = root.getChildren(); System.out.println("children size: "+children.size()); + + GWTWorkspaceBuilder builder = new GWTWorkspaceBuilder(); + + builder.buildGXTListFileGridModelItem(children, null); + + /* int i=0; for (WorkspaceItem workspaceItem : children) { @@ -70,7 +82,7 @@ public class SizeRetrieving { } } - } + }*/ System.out.println("end"); } catch (Exception e) { e.printStackTrace();