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
This commit is contained in:
Francesco Mangiacrapa 2015-11-05 10:23:01 +00:00
parent 36bfaf7032
commit 6d1205024f
10 changed files with 508 additions and 184 deletions

View File

@ -3,13 +3,17 @@ package org.gcube.portlets.user.workspace.client.model;
import java.io.Serializable; import java.io.Serializable;
import java.util.Comparator; import java.util.Comparator;
import org.gcube.portlets.user.workspace.shared.ContactLogin;
import com.extjs.gxt.ui.client.data.BaseModelData; 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"; public static final String ISGROUP = "isgroup";
/**
* Instantiates a new info contact model.
*/
public InfoContactModel() {} 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) { public InfoContactModel(String id, String login, String fullName, boolean isGroup) {
setId(id); setId(id);
setLogin(login); 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) { public void setIsGroup(boolean isGroup) {
set(ISGROUP,isGroup); set(ISGROUP,isGroup);
} }
/** /**
* @param isGroup * Checks if is group.
*
* @return true, if is group
*/ */
public boolean isGroup() { public boolean isGroup() {
return (Boolean) get(ISGROUP); return (Boolean) get(ISGROUP);
} }
/**
* Sets the name.
*
* @param name the new name
*/
public void setName(String name) { public void setName(String name) {
set(FULLNAME,name); set(FULLNAME,name);
} }
/**
* Gets the name.
*
* @return the name
*/
public String getName(){ public String getName(){
String name = (String) (get(FULLNAME)!=null?get(FULLNAME):""); String name = (String) (get(FULLNAME)!=null?get(FULLNAME):"");
return name; return name;
} }
/**
* Gets the id.
*
* @return the id
*/
public String getId() { public String getId() {
return get(ID); return get(ID);
} }
/**
* Sets the id.
*
* @param id the new id
*/
public void setId(String id) { public void setId(String id) {
set(ID, id); set(ID, id);
} }
/* (non-Javadoc)
* @see org.gcube.portlets.user.workspace.shared.ContactLogin#getLogin()
*/
public String getLogin() { public String getLogin() {
return get(LOGIN); return get(LOGIN);
} }
/**
* Sets the login.
*
* @param login the new login
*/
public void setLogin(String login) { public void setLogin(String login) {
set(LOGIN, login); set(LOGIN, login);
} }
@ -76,7 +123,14 @@ public class InfoContactModel extends BaseModelData implements Serializable {
public static Comparator<InfoContactModel> COMPARATORFULLNAME = new Comparator<InfoContactModel>() { public static Comparator<InfoContactModel> COMPARATORFULLNAME = new Comparator<InfoContactModel>() {
// This is where the sorting happens. // This is where the sorting happens.
public int compare(InfoContactModel o1, InfoContactModel o2) { 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<InfoContactModel> COMPARATORLOGINS = new Comparator<InfoContactModel>() { public static Comparator<InfoContactModel> COMPARATORLOGINS = new Comparator<InfoContactModel>() {
// This is where the sorting happens. // This is where the sorting happens.
public int compare(InfoContactModel o1, InfoContactModel o2) { 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 @Override
public String toString() { public String toString() {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();

View File

@ -1,6 +1,5 @@
package org.gcube.portlets.user.workspace.client.view.sharing; package org.gcube.portlets.user.workspace.client.view.sharing;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.gcube.portlets.user.workspace.client.AppControllerExplorer; 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.MultiDragContact;
import org.gcube.portlets.user.workspace.client.view.sharing.multisuggest.MultiValuePanel; 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.client.view.windows.MessageBoxAlert;
import org.gcube.portlets.user.workspace.shared.ListContact;
import org.gcube.portlets.user.workspace.shared.WorkspaceACL; import org.gcube.portlets.user.workspace.shared.WorkspaceACL;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment; 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.FlexTable;
import com.google.gwt.user.client.ui.Label; 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 { public class DialogShareFolder extends Dialog {
@ -50,35 +53,15 @@ public class DialogShareFolder extends Dialog {
private TextField<String> txtOwner; private TextField<String> txtOwner;
private PanelTogglePermission permission; private PanelTogglePermission permission;
private HorizontalPanel hpPermission = null; private HorizontalPanel hpPermission = null;
private InfoContactModel shareOwner = null;
private List<InfoContactModel> listAlreadyShared = new ArrayList<InfoContactModel>(){ private ListContact<InfoContactModel> listAlreadyShared = new ListContact<InfoContactModel>();
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;
};
};
/** /**
* Use to modify a shared folder or share an existing folder * Use to modify a shared folder or share an existing folder.
* @param folder *
* @param type * @param folderParentName the folder parent name
* @param folder the folder
* @param eventBus the event bus
*/ */
public DialogShareFolder(String folderParentName, final FileModel folder, HandlerManager eventBus) { public DialogShareFolder(String folderParentName, final FileModel folder, HandlerManager eventBus) {
initLayout(folderParentName); initLayout(folderParentName);
@ -163,31 +146,7 @@ public class DialogShareFolder extends Dialog {
if(hpPermission!=null) if(hpPermission!=null)
lc.add(hpPermission); lc.add(hpPermission);
lc.mask(); lc.mask();
userStore.getListSharedUserByFolderId(folder.getIdentifier(), new AsyncCallback<List<InfoContactModel>>() {
@Override
public void onSuccess(List<InfoContactModel> 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<InfoContactModel>() { userStore.getOwner(folder.getIdentifier(), new AsyncCallback<InfoContactModel>() {
@Override @Override
@ -197,9 +156,12 @@ public class DialogShareFolder extends Dialog {
@Override @Override
public void onSuccess(InfoContactModel result) { public void onSuccess(InfoContactModel result) {
shareOwner = result;
txtOwner.setValue(result.getName()); txtOwner.setValue(result.getName());
permissionControl(result.getLogin(), true); permissionControl(result.getLogin(), true);
fillRecipientAlreadyShared(folder.getIdentifier(), lc);
} }
}); });
setFocusWidget(suggestPanel.getBox()); setFocusWidget(suggestPanel.getBox());
@ -212,6 +174,59 @@ public class DialogShareFolder extends Dialog {
this.show(); this.show();
} }
/**
* Update recipient of share.
*
* @param listContacts the list contacts
*/
private void updateRecipientOfShare(List<InfoContactModel> 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<List<InfoContactModel>>() {
@Override
public void onSuccess(List<InfoContactModel> 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){ private void permissionControl(String owner, boolean showAlert){
GWT.log("Permission control compare between owner: "+owner +" and my login: "+AppControllerExplorer.myLogin); 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){ private void enableFormDialog(boolean bool){
getButtonById(Dialog.OK).setEnabled(bool); getButtonById(Dialog.OK).setEnabled(bool);
buttonMultiDrag.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() { public FileModel getParentFolder() {
return parentFolder; return parentFolder;
} }
/**
* Inits the layout.
*
* @param folderParentName the folder parent name
*/
public void initLayout(String folderParentName){ public void initLayout(String folderParentName){
FormLayout layout = new FormLayout(); FormLayout layout = new FormLayout();
layout.setLabelWidth(90); 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) { 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<InfoContactModel> getSharedListUsers() { public List<InfoContactModel> getSharedListUsers() {
// printSelectedUser(); // printSelectedUser();
return suggestPanel.getSelectedUser(); return suggestPanel.getSelectedUser();
} }
/**
* Adds the listners.
*/
public void addListners(){ public void addListners(){
this.getButtonById(Dialog.CANCEL).addSelectionListener(new SelectionListener<ButtonEvent>() { this.getButtonById(Dialog.CANCEL).addSelectionListener(new SelectionListener<ButtonEvent>() {
@ -368,19 +409,23 @@ public class DialogShareFolder extends Dialog {
List<InfoContactModel> exclusiveContacts = userStore.getExclusiveContactsFromAllContact(suggestPanel.getSelectedUser()); List<InfoContactModel> exclusiveContacts = userStore.getExclusiveContactsFromAllContact(suggestPanel.getSelectedUser());
multiDrag.addSourceContacts(exclusiveContacts); multiDrag.addSourceContacts(exclusiveContacts);
for (InfoContactModel infoContactModel : suggestPanel.getSelectedUser()) { for (InfoContactModel infoContactModel : suggestPanel.getSelectedUser()) {
if(!listAlreadyShared.contains(infoContactModel)) // if(!listAlreadyShared.contains(infoContactModel))
if(!isShareOwner(infoContactModel))
multiDrag.addTargetContact(infoContactModel); multiDrag.addTargetContact(infoContactModel);
} }
multiDrag.addAlreadySharedContacts(suggestPanel.getSelectedUser()); // multiDrag.addAlreadySharedContacts(suggestPanel.getSelectedUser());
multiDrag.addAlreadySharedContacts(listAlreadyShared);
multiDrag.getButtonById(Dialog.OK).addSelectionListener(new SelectionListener<ButtonEvent>() { multiDrag.getButtonById(Dialog.OK).addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override @Override
public void componentSelected(ButtonEvent ce) { public void componentSelected(ButtonEvent ce) {
initSuggestContacts(); // initSuggestContacts();
suggestPanel.resetItemSelected();
suggestPanel.addRecipient(shareOwner.getName(),false);
for (InfoContactModel infoContactModel : multiDrag.getTargetListContact()) { for (InfoContactModel infoContactModel : multiDrag.getTargetListContact()) {
suggestPanel.addRecipient(infoContactModel.getName(),true); 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){ private boolean listAlreadySharedContains(InfoContactModel contact){
if(contact==null) if(contact==null)
return false; return false;
for (InfoContactModel ct : listAlreadyShared) { 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 true;
} }
return false; return false;
} }
//DEBUG //DEBUG
/**
* Prints the selected user.
*/
@SuppressWarnings("unused")
private void printSelectedUser(){ private void printSelectedUser(){
System.out.println("SELETECTED USERS: "); System.out.println("SELETECTED USERS: ");
@ -412,16 +484,30 @@ public class DialogShareFolder extends Dialog {
System.out.println(contact); System.out.println(contact);
} }
/**
* Inits the suggest contacts.
*/
@SuppressWarnings("unused")
private void initSuggestContacts(){ private void initSuggestContacts(){
suggestPanel.resetItemSelected(); suggestPanel.resetItemSelected();
for (InfoContactModel contact : listAlreadyShared) for (InfoContactModel contact : listAlreadyShared)
suggestPanel.addRecipient(contact.getName(), false); suggestPanel.addRecipient(contact.getName(), false);
} }
/**
* Gets the name.
*
* @return the name
*/
public String getName() { public String getName() {
return txtName.getValue(); return txtName.getValue();
} }
/**
* Gets the description.
*
* @return the description
*/
public String getDescription() { public String getDescription() {
if(textAreaDescription.getValue()==null) if(textAreaDescription.getValue()==null)
return ""; return "";
@ -430,9 +516,10 @@ public class DialogShareFolder extends Dialog {
} }
/** /**
* * Checks if is valid form.
* @param displayAlert *
* @return * @param displayAlert the display alert
* @return true, if is valid form
*/ */
public boolean isValidForm(boolean displayAlert){ 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(){ public WorkspaceACL getSelectedACL(){
if(permission!=null) if(permission!=null)
return permission.getSelectedACL(); return permission.getSelectedACL();
return null; return null;
} }
/**
* Select acl for folder.
*
* @param folder the folder
*/
private void selectAclForFolder(FileModel folder){ private void selectAclForFolder(FileModel folder){
GWT.log("Loading ACL to: "+folder); GWT.log("Loading ACL to: "+folder);
AppControllerExplorer.rpcWorkspaceService.getACLBySharedFolderId(folder.getIdentifier(), new AsyncCallback<WorkspaceACL>() { AppControllerExplorer.rpcWorkspaceService.getACLBySharedFolderId(folder.getIdentifier(), new AsyncCallback<WorkspaceACL>() {

View File

@ -85,7 +85,7 @@ public class UserStore implements ContactFetcher{
List<InfoContactModel> listExclusiveContact = new ArrayList<InfoContactModel>(listAllContact); List<InfoContactModel> listExclusiveContact = new ArrayList<InfoContactModel>(listAllContact);
for (InfoContactModel contact : listSharedUser) { for (InfoContactModel contact : listSharedUser) {
if(listAllContact.contains(contact)){ if(listAllContact.contains(contact)){
// GWT.log("Removing not eclusive contact "+contact); GWT.log("Removing not eclusive contact "+contact);
listExclusiveContact.remove(contact); listExclusiveContact.remove(contact);
} }
} }

View File

@ -491,6 +491,7 @@ public class MultiDragContact extends Dialog {
} }
storeSource.add(listExtended); storeSource.add(listExtended);
// GWT.log("Added sources: "+listExtended.toString());
} }
gridAllContacts.unmask(); gridAllContacts.unmask();

View File

@ -2008,7 +2008,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
np.notifyFolderSharing(listContacts, sharedFolder); np.notifyFolderSharing(listContacts, sharedFolder);
else{ else{
// printContacts(listContacts); // printContacts(listContacts);
np.notifyAddedUsersToSharing(listSharedContact, listContacts, sharedFolder); np.notifyUpdatedUsersToSharing(listSharedContact, listContacts, sharedFolder);
} }
} }

View File

@ -20,9 +20,9 @@ import org.gcube.portlets.user.workspace.server.util.UserUtil;
import org.gcube.portlets.user.workspace.server.util.WsUtil; import org.gcube.portlets.user.workspace.server.util.WsUtil;
/** /**
* * The Class NotificationsProducer.
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* *
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
*/ */
public class NotificationsProducer { public class NotificationsProducer {
@ -36,8 +36,9 @@ public class NotificationsProducer {
/** /**
* * Instantiates a new notifications producer.
* @param aslSession *
* @param aslSession the asl session
*/ */
public NotificationsProducer(ASLSession aslSession) { public NotificationsProducer(ASLSession aslSession) {
this.notificationsMng = WsUtil.getNotificationManager(aslSession); this.notificationsMng = WsUtil.getNotificationManager(aslSession);
@ -45,23 +46,39 @@ public class NotificationsProducer {
this.userId = aslSession.getUsername(); this.userId = aslSession.getUsername();
} }
/**
* Gets the notifications mng.
*
* @return the notifications mng
*/
public NotificationsManager getNotificationsMng() { public NotificationsManager getNotificationsMng() {
return notificationsMng; return notificationsMng;
} }
/**
* Sets the notification mng.
*
* @param notificationMng the new notification mng
*/
public void setNotificationMng(NotificationsManager notificationMng) { public void setNotificationMng(NotificationsManager notificationMng) {
this.notificationsMng = notificationMng; this.notificationsMng = notificationMng;
} }
/**
* Gets the asl session.
*
* @return the asl session
*/
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.
* @param listContacts *
* @param sharedFolder * @param listContacts the list contacts
* @param sharedFolder the shared folder
*/ */
public void notifyFolderSharing(final List<InfoContactModel> listContacts, final WorkspaceSharedFolder sharedFolder) { public void notifyFolderSharing(final List<InfoContactModel> listContacts, final WorkspaceSharedFolder sharedFolder) {
@ -103,10 +120,13 @@ public class NotificationsProducer {
/** /**
* 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 listContacts * @param listSharedContact the list shared contact
* @param sharedFolder * @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<InfoContactModel> listSharedContact, final WorkspaceItem folderItem, final String itemOldName, final String itemNewName, final String idsharedFolder) { public void notifyFolderRenamed(final List<InfoContactModel> 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 * Runs a new thread to notify the contacts passed in input.
* @param listContacts *
* @param sharedFolder * @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<InfoContactModel> listSharedContact, final String previousName, final WorkspaceItem item, final WorkspaceSharedFolder sharedFolder) { public void notifyItemRenamed(final List<InfoContactModel> 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 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 * @param sharedFolder - the shared folder
*/ */
public void notifyAddedUsersToSharing(final List<InfoContactModel> listSharedContact, final List<InfoContactModel> listSharingContact, final WorkspaceSharedFolder sharedFolder) { public void notifyUpdatedUsersToSharing(final List<InfoContactModel> listSharedContact, final List<InfoContactModel> listSharingContact, final WorkspaceSharedFolder sharedFolder) {
new Thread() { new Thread() {
@Override @Override
public void run() { public void run() {
try{ try{
//NEW USER SHARED
DiffereceBeetweenInfoContactModel diff = new DiffereceBeetweenInfoContactModel(listSharingContact, listSharedContact); DiffereceBeetweenInfoContactModel diff = new DiffereceBeetweenInfoContactModel(listSharingContact, listSharedContact);
List<InfoContactModel> listExclusiveContacts = diff.getDifferentsContacts(); List<InfoContactModel> 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{ try{
@ -252,9 +277,9 @@ public class NotificationsProducer {
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 CONTACT WAS ADDED
List<String> listLogins = UserUtil.getListLoginByInfoContactModel(listExclusiveContacts); List<String> listLogins = UserUtil.getListLoginByInfoContactModel(listNewContactsShared);
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
@ -276,12 +301,23 @@ public class NotificationsProducer {
} }
} }
notifyFolderSharing(listNewContactsShared, sharedFolder); //NOTIFIER NEW USER OF SHARING FOLDER
notifyFolderSharing(listExclusiveContacts, sharedFolder); //NOTIFIER NEW USER OF SHARING FOLDER
} }
} }
//USER REMOVED FROM SHARE
DiffereceBeetweenInfoContactModel diff2 = new DiffereceBeetweenInfoContactModel(listSharedContact, listSharingContact);
List<InfoContactModel> 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) { }catch (Exception e) {
logger.error("An error occured in notifyAddedUserToSharing ", 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 * Runs a new thread to notify the contacts passed in input.
* @param listContacts *
* @param unSharedFolder * @param listContacts the list contacts
* @param unShareFolderId the un share folder id
* @param unSharedFolderName the un shared folder name
*/ */
public void notifyFolderUnSharing(final List<InfoContactModel> listContacts, final String unShareFolderId, final String unSharedFolderName) { public void notifyFolderUnSharing(final List<InfoContactModel> listContacts, final String unShareFolderId, final String unSharedFolderName) {
@ -337,13 +375,49 @@ public class NotificationsProducer {
}.start(); }.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 * Runs a new thread to notify the contacts passed in input.
* @param listContacts *
* @param workspaceItem * @param listContacts the list contacts
* @param workspaceItem the workspace item
* @param sharedFolder the shared folder
*/ */
public void notifyAddedItemToSharing(final List<InfoContactModel> listContacts, final WorkspaceItem workspaceItem, final WorkspaceSharedFolder sharedFolder) { public void notifyAddedItemToSharing(final List<InfoContactModel> 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 * Runs a new thread to notify the contacts passed in input.
* @param listContacts *
* @param workspaceItem * @param listContacts the list contacts
* @param workspaceItem the workspace item
* @param sharedFolder the shared folder
*/ */
public void notifyUpdatedItemToSharing(final List<InfoContactModel> listContacts, final WorkspaceItem workspaceItem, final WorkspaceSharedFolder sharedFolder) { public void notifyUpdatedItemToSharing(final List<InfoContactModel> 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 * Runs a new thread to notify the contacts passed in input.
* @param listContacts *
* @param sharedFolder * @param listContacts the list contacts
* @param workspaceItem the workspace item
* @param sharedFolder the shared folder
*/ */
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) {
@ -524,9 +602,11 @@ public class NotificationsProducer {
/** /**
* 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 sharedFolder * @param listContacts the list contacts
* @param itemName the item name
* @param sharedFolder the shared folder
*/ */
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) {
@ -587,9 +667,10 @@ public class NotificationsProducer {
} }
/** /**
* 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 unSharedFolder * @param listContacts the list contacts
* @param folderNameDeleted the folder name deleted
*/ */
public void notifySharedFolderDeleted(final List<InfoContactModel> listContacts, final String folderNameDeleted) { public void notifySharedFolderDeleted(final List<InfoContactModel> listContacts, final String folderNameDeleted) {
@ -633,9 +714,10 @@ public class NotificationsProducer {
/** /**
* Runs a new thread to notify the contacts passed in input * Runs a new thread to notify the contacts passed in input.
* @param userToNotify *
* @param sharedFolder * @param userToNotify the user to notify
* @param sharedFolder the shared folder
*/ */
public void notifyAdministratorUpgrade(final InfoContactModel userToNotify, final WorkspaceSharedFolder sharedFolder){ 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 * Runs a new thread to notify the contacts passed in input.
* @param userToNotify *
* @param sharedFolder * @param userToNotify the user to notify
* @param sharedFolder the shared folder
*/ */
public void notifyAdministratorDowngrade(final InfoContactModel userToNotify, final WorkspaceSharedFolder sharedFolder){ public void notifyAdministratorDowngrade(final InfoContactModel userToNotify, final WorkspaceSharedFolder sharedFolder){
@ -713,6 +796,11 @@ public class NotificationsProducer {
} }
//DEBUG //DEBUG
/**
* Prints the contacts.
*
* @param listContacts the list contacts
*/
private void printContacts(List<InfoContactModel> listContacts){ private void printContacts(List<InfoContactModel> listContacts){
System.out.println("Print contacts"); System.out.println("Print contacts");
@ -722,6 +810,12 @@ public class NotificationsProducer {
System.out.println("End print contacts"); 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 public static void main(String[] args) throws Exception
{ {
String sessionID = "1"; String sessionID = "1";

View File

@ -5,10 +5,12 @@ import java.util.List;
import org.gcube.portlets.user.workspace.client.model.InfoContactModel; import org.gcube.portlets.user.workspace.client.model.InfoContactModel;
/** /**
* * The Class DiffereceBeetweenInfoContactModel.
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* *
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Nov 4, 2015
*/ */
public class DiffereceBeetweenInfoContactModel { public class DiffereceBeetweenInfoContactModel {
@ -17,9 +19,10 @@ public class DiffereceBeetweenInfoContactModel {
private List<InfoContactModel> listTwo; private List<InfoContactModel> listTwo;
/** /**
* Get difference between listA and listB * Get difference between listA and listB .
* @param listA *
* @param listB * @param listA the list a
* @param listB the list b
*/ */
public DiffereceBeetweenInfoContactModel(List<InfoContactModel> listA, List<InfoContactModel> listB){ public DiffereceBeetweenInfoContactModel(List<InfoContactModel> listA, List<InfoContactModel> listB){
@ -29,7 +32,8 @@ public class DiffereceBeetweenInfoContactModel {
} }
/** /**
* * Gets the differents contacts.
*
* @return what is in listA that is not in listB. * @return what is in listA that is not in listB.
*/ */
public List<InfoContactModel> getDifferentsContacts(){ public List<InfoContactModel> getDifferentsContacts(){
@ -47,7 +51,7 @@ public class DiffereceBeetweenInfoContactModel {
for (InfoContactModel o1 : listOne) { for (InfoContactModel o1 : listOne) {
found = false; found = false;
for (InfoContactModel o2 : listTwo) { for (InfoContactModel o2 : listTwo) {
if(compare(o1,o2)==0){ if(InfoContactModel.COMPARATORLOGINS.compare(o1, o2)==0){
found = true; found = true;
break; break;
} }
@ -61,53 +65,32 @@ public class DiffereceBeetweenInfoContactModel {
} }
/** // /**
* // * test.
* @param o1 // *
* @param o2 // * @param args the arguments
* @return 0 if and only if o1.getName().compareTo(o2.getName())==0 && (o1.getLogin().compareTo(o2.getLogin())==0) is true // */
*/ // public static void main(String[] args) {
public int compare(InfoContactModel o1, InfoContactModel o2) { //
// List<InfoContactModel> listA = new ArrayList<InfoContactModel>();
if (o1 == null) { // listA.add(new InfoContactModel("federico.defaveri", "federico.defaveri", "Federico de Faveri", false));
return -1; // listA.add(new InfoContactModel("antonio.gioia", "antonio.gioia", "Antonio Gioia",false));
} else if (o2 == null) { // listA.add(new InfoContactModel("fabio.sinibaldi", "fabio.sinibaldi", "Fabio Sinibaldi", false));
return 1; // 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));
if (o1.getName().compareTo(o2.getName())==0 && (o1.getLogin().compareTo(o2.getLogin())==0)) //
return 0; // List<InfoContactModel> listB = new ArrayList<InfoContactModel>();
else //
return -2; // 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));
/** //
* test // DiffereceBeetweenInfoContactModel diff = new DiffereceBeetweenInfoContactModel(listA, listB);
* @param args //
*/ // System.out.println("the differce is: "+diff.getDifferentsContacts());
public static void main(String[] args) { //
// }
List<InfoContactModel> listA = new ArrayList<InfoContactModel>();
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<InfoContactModel> listB = new ArrayList<InfoContactModel>();
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());
}
} }

View File

@ -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();
}

View File

@ -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<T extends ContactLogin> extends ArrayList<T> 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;
}
}

View File

@ -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.homelibrary.home.workspace.folder.FolderItem;
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.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 = "/gcube/devsec"; //DEV
public static String DEFAULT_SCOPE = "/d4science.research-infrastructures.eu/gCubeApps/DESCRAMBLE"; public static String DEFAULT_SCOPE = "/d4science.research-infrastructures.eu/gCubeApps";
public static String TEST_USER = "massimiliano.assante"; public static String TEST_USER = "yann.laurent";
public static String FOLDER_ID = "4f0ff79d-3c1e-4d2a-bc74-6f731edcac98";
public static void main(String[] args) { public static void main(String[] args) {
@ -41,13 +43,23 @@ public class SizeRetrieving {
.getWorkspace(); .getWorkspace();
// //
System.out.println("start get root"); // System.out.println("start get root");
WorkspaceItem root = ws.getRoot(); // WorkspaceItem root = ws.getRoot();
// List<WorkspaceItem> children = (List<WorkspaceItem>) root.getChildren();
System.out.println("start get children"); System.out.println("start get children");
List<? extends WorkspaceItem> children = root.getChildren();
WorkspaceFolder folder = (WorkspaceFolder) ws.getItem(FOLDER_ID);
List<WorkspaceItem> children = (List<WorkspaceItem>) folder.getChildren();
// List<? extends WorkspaceItem> children = root.getChildren();
System.out.println("children size: "+children.size()); System.out.println("children size: "+children.size());
GWTWorkspaceBuilder builder = new GWTWorkspaceBuilder();
builder.buildGXTListFileGridModelItem(children, null);
/*
int i=0; int i=0;
for (WorkspaceItem workspaceItem : children) { for (WorkspaceItem workspaceItem : children) {
@ -70,7 +82,7 @@ public class SizeRetrieving {
} }
} }
} }*/
System.out.println("end"); System.out.println("end");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();