enhancements

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/workspace-sharing-widget@92572 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2014-03-03 15:37:03 +00:00
parent a82619e6ca
commit 94dd4a056e
6 changed files with 279 additions and 4 deletions

View File

@ -8,7 +8,12 @@ import org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.WorkspaceSha
import org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing.DialogShareWItem;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.ACL_TYPE;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.FileModel;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.SessionExpiredException;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.widget.Dialog;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.Window;
import com.google.gwt.core.client.GWT;
@ -59,18 +64,19 @@ public class WorkspaceSharingController {
return;
}
initWindow();
initSharingDialog();
addListenersSharingDialog();
if(shareOnlyOwner){
loadMyLogin(true, true);
}else{
loadFileModel(true);
}
}
private void initWindow(){
private void initSharingDialog(){
sharingDialog = new DialogShareWItem();
sharingDialog.setSize(ConstantsSharing.WIDTH_DIALOG+20, ConstantsSharing.HEIGHT_DIALOG+20);
sharingDialog.mask("Loading File from Workspace", ConstantsSharing.LOADINGSTYLE);
@ -98,6 +104,69 @@ public class WorkspaceSharingController {
});
}
private void addListenersSharingDialog(){
sharingDialog.getButtonById(Dialog.OK).addListener(Events.Select, new Listener<BaseEvent>() {
@Override
public void handleEvent(BaseEvent be) {
if(sharingDialog.isValidForm(true)){
FileModel fileModel = sharingDialog.getFileToShare();
//create a lowest object to send to server
fileModel = new FileModel(fileModel.getIdentifier(), fileModel.getName(), fileModel.getParentFileModel(), fileModel.isDirectory(), fileModel.isShared());
fileModel.setDescription(sharingDialog.getDescription());
//DEBUG
/*
System.out.println("FileModel id "+fileModel.getIdentifier() + " name: "+fileModel.getName() + " parent " + fileModel.getParentFileModel());
for(InfoContactModel contact:finalDialog.getSharedListUsers() ){
System.out.println("Share with Contact "+contact) ;
}*/
GWT.log("ACL selected is "+sharingDialog.getSelectedACL());
final String itemName = fileModel.getName();
sharingDialog.mask("Sharing and setting permissions", ConstantsSharing.LOADINGSTYLE);
rpcWorkspaceSharingService.shareFolder(fileModel, sharingDialog.getSharedListUsers(), false, sharingDialog.getSelectedACL(), new AsyncCallback<Boolean>() {
@Override
public void onFailure(Throwable caught) {
if(caught instanceof SessionExpiredException){
GWT.log("Session expired");
sharingDialog.unmask();
sharingDialog.hide();
MessageBox.alert("Alert", "Server session expired", null);
return;
}else
MessageBox.alert("Error", caught.getMessage(), null);
}
@Override
public void onSuccess(Boolean result) {
if(result){
MessageBox.info("Info", "The item: "+itemName+" correctly shared", null);
sharingDialog.hide();
}
sharingDialog.unmask();
}
});
}
}
});
}
/**
*
* @param fileModel

View File

@ -53,4 +53,21 @@ public interface WorkspaceSharingService extends RemoteService {
* @throws Exception
*/
FileModel getFileModelByWorkpaceItemId(String itemId) throws Exception;
/**
* @return
* @throws Exception
*/
boolean isSessionExpired() throws Exception;
/**
* @param folder
* @param listContacts
* @param isNewFolder
* @param acl
* @return
* @throws Exception
*/
boolean shareFolder(FileModel folder, List<InfoContactModel> listContacts,
boolean isNewFolder, WorkspaceACL acl) throws Exception;
}

View File

@ -54,4 +54,12 @@ public interface WorkspaceSharingServiceAsync
void getFileModelByWorkpaceItemId(String itemId,
AsyncCallback<FileModel> callback);
void isSessionExpired(AsyncCallback<Boolean> callback);
void shareFolder(FileModel folder, List<InfoContactModel> listContacts,
boolean isNewFolder, WorkspaceACL acl,
AsyncCallback<Boolean> callback);
}

View File

@ -268,7 +268,11 @@ public class DialogShareWItem extends Dialog {
permission.setEnabled(bool);
}
public FileModel getParentFolder() {
/**
*
* @return
*/
public FileModel getFileToShare() {
return fileToShare;
}

View File

@ -13,15 +13,20 @@ import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
import org.gcube.common.homelibrary.home.workspace.WorkspaceItemType;
import org.gcube.common.homelibrary.home.workspace.WorkspaceSharedFolder;
import org.gcube.common.homelibrary.home.workspace.accessmanager.ACLType;
import org.gcube.common.homelibrary.home.workspace.exceptions.InsufficientPrivilegesException;
import org.gcube.common.homelibrary.home.workspace.exceptions.ItemAlreadyExistException;
import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
import org.gcube.common.homelibrary.home.workspace.exceptions.WrongDestinationException;
import org.gcube.portlets.widgets.workspacesharingwidget.client.ConstantsSharing;
import org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.WorkspaceSharingService;
import org.gcube.portlets.widgets.workspacesharingwidget.server.notifications.NotificationsProducer;
import org.gcube.portlets.widgets.workspacesharingwidget.server.notifications.NotificationsUtil;
import org.gcube.portlets.widgets.workspacesharingwidget.server.util.ScopeUtilFilter;
import org.gcube.portlets.widgets.workspacesharingwidget.server.util.UserUtil;
import org.gcube.portlets.widgets.workspacesharingwidget.server.util.WsUtil;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.FileModel;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.SessionExpiredException;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.WorkspaceACL;
import org.gcube.vomanagement.usermanagement.GroupManager;
import org.gcube.vomanagement.usermanagement.UserManager;
@ -242,6 +247,152 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
throw new Exception(error);
}
}
/* (non-Javadoc)
* @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#isSessionExpired()
*/
@Override
public boolean isSessionExpired() throws Exception {
return WsUtil.isSessionExpired(this.getThreadLocalRequest().getSession());
}
// DEBUG
private void printContacts(List<InfoContactModel> listContacts) {
boolean testMode = isTestMode();
if (testMode)
System.out.println("Contacts: ");
else
logger.debug("Contacts:");
for (InfoContactModel infoContactModel : listContacts) {
if (testMode)
System.out.println("User: " + infoContactModel);
else
logger.debug("User: " + infoContactModel);
}
}
@Override
public boolean shareFolder(FileModel folder, List<InfoContactModel> listContacts, boolean isNewFolder, WorkspaceACL acl) throws Exception {
if(isSessionExpired())
throw new SessionExpiredException();
try {
Workspace workspace = getWorkspace();
logger.info("sharing item id: "+ folder.getIdentifier()
+ " name: "+ folder.getName()
// + " parent name: " + folder.getParentFileModel().getName()
+ " listContacts size: " + listContacts.size());
// //DEBUG
//System.out.println("shareFolder "+ folder.getIdentifier() + " name: "+ folder.getName() + " parent name: " + folder.getParentFileModel().getName() + " listContacts size: " + listContacts.size());
// for (InfoContactModel infoContactModel : listContacts) {
// System.out.println("share with "+ infoContactModel.getLogin());
// }
printContacts(listContacts);
List<String> listLogin = UserUtil.getListLoginByInfoContactModel(listContacts);
WorkspaceSharedFolder sharedFolder = null;
List<InfoContactModel> listSharedContact = null;
boolean sourceFolderIsShared = folder.isShared();
if(sourceFolderIsShared){ //if source folder is already share... retrieve old list of sharing to notify
listSharedContact = getListUserSharedByFolderSharedId(folder.getIdentifier());
}
if(listLogin.size()>0){
if(!isNewFolder){
sharedFolder = workspace.shareFolder(listLogin, folder.getIdentifier());
sharedFolder.setDescription(folder.getDescription()); //SET NEW DESCRIPTION
}
else
sharedFolder = workspace.createSharedFolder(folder.getName(), folder.getDescription(), listLogin, folder.getParentFileModel().getIdentifier());
}
boolean created = sharedFolder==null?false:true;
if(acl!=null)
setACLs(sharedFolder.getId(), listLogin, acl.getId().toString());
if(created){
NotificationsProducer np = getNotificationProducer();
if(!sourceFolderIsShared) //if source folder is not already shared
np.notifyFolderSharing(listContacts, sharedFolder);
else{
/*System.out.println("SHARED CONTACS: ");
printContacts(listSharedContact);
System.out.println("NEW CONTACS: ");
printContacts(listContacts);*/
np.notifyAddedUsersToSharing(listSharedContact, listContacts, sharedFolder);
}
}
return created;
} catch (InsufficientPrivilegesException e) {
logger.error("Error in shareFolder ", e);
String error = "An error occurred on creating shared folder. "+ e.getMessage();
throw new Exception(error);
} catch (ItemAlreadyExistException e) {
logger.error("Error in shareFolder ", e);
String error = "An error occurred on creating shared folder. "+ e.getMessage();
throw new Exception(error);
} catch (WrongDestinationException e) {
logger.error("Error in shareFolder ", e);
String error = "An error occurred on creating shared folder. "+ e.getMessage();
throw new Exception(error);
} catch (Exception e) {
logger.error("Error in shareFolder ", e);
e.printStackTrace();
String error = ConstantsSharing.SERVER_ERROR+" sharing item.";
throw new Exception(error);
}
}
public void setACLs(String folderId, List<String> listLogins, String aclType) throws Exception{
try {
if(folderId == null)
throw new Exception("Folder id is null");
if(listLogins==null || listLogins.size()==0)
throw new Exception("List Logins is null or empty");
logger.info("Setting ACL for folder id: "+folderId);
logger.info("ACL type is: "+aclType);
Workspace workspace = getWorkspace();
WorkspaceItem wsItem = workspace.getItem(folderId);
if(wsItem.isShared() && (wsItem.getType().equals(WorkspaceItemType.SHARED_FOLDER))){
WorkspaceSharedFolder ite = (WorkspaceSharedFolder) workspace.getItemByPath(wsItem.getPath());
ite.setACL(listLogins, ACLType.valueOf(aclType));
}else
throw new Exception("Source item is not shared or shared folder");
logger.info("Setting ACL completed, retuning");
} catch (Exception e) {
logger.info("Error in set ACLs", e);
String error = ConstantsSharing.SERVER_ERROR +" setting permissions. "+e.getMessage();
throw new Exception(error);
}
}
}

View File

@ -0,0 +1,26 @@
/**
*
*/
package org.gcube.portlets.widgets.workspacesharingwidget.shared;
/**
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* @Mar 3, 2014
*
*/
public class SessionExpiredException extends Exception{
/**
*
*/
private static final long serialVersionUID = -4706569045335951710L;
/**
*
*/
public SessionExpiredException() {
super("Server session expired");
}
}