Francesco Mangiacrapa 2014-02-11 15:41:56 +00:00
parent c8f88e8ab5
commit c552fa334a
8 changed files with 224 additions and 184 deletions

View File

@ -343,16 +343,20 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
fileModel.setDescription(finalDialog.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) ;
//
// }
/*
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) ;
}*/
System.out.println("ACL is "+finalDialog.getSelectedACL());
Info.display("Info", "An operation of sharing was submitted");
explorerPanel.mask("Submitting operation");
rpcWorkspaceService.shareFolder(fileModel, finalDialog.getSharedListUsers(), isNewFolder, new AsyncCallback<Boolean>() {
rpcWorkspaceService.shareFolder(fileModel, finalDialog.getSharedListUsers(), isNewFolder, finalDialog.getSelectedACL(), new AsyncCallback<Boolean>() {
@Override
public void onFailure(Throwable caught) {

View File

@ -107,7 +107,8 @@ public interface GWTWorkspaceService extends RemoteService{
public GWTWorkspaceItem getTimeSeriesById(String identifier) throws Exception;
boolean shareFolder(FileModel folder, List<InfoContactModel> listContacts, boolean isNewFolder) throws Exception;
boolean shareFolder(FileModel folder, List<InfoContactModel> listContacts,
boolean isNewFolder, WorkspaceACL acl) throws Exception;
public List<InfoContactModel> getListUserSharedByFolderSharedId(String itemId) throws Exception;

View File

@ -109,7 +109,8 @@ public interface GWTWorkspaceServiceAsync {
AsyncCallback<GWTWorkspaceItem> callback);
void shareFolder(FileModel folder, List<InfoContactModel> listContacts,
boolean isNewFolder, AsyncCallback<Boolean> callback);
boolean isNewFolder, WorkspaceACL acl,
AsyncCallback<Boolean> callback);
void getListUserSharedByFolderSharedId(String itemId,
AsyncCallback<List<InfoContactModel>> callback);

View File

@ -15,14 +15,9 @@ import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.widget.Dialog;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.form.CheckBox;
import com.extjs.gxt.ui.client.widget.form.CheckBoxGroup;
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
import com.extjs.gxt.ui.client.widget.tips.ToolTipConfig;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Label;
/**
@ -35,10 +30,10 @@ public class DialogPermission extends Dialog {
private FileModel parentFolder = null;
private UserStore userStore = new UserStore();
private MultiValuePanel suggestPanel = new MultiValuePanel(userStore);
private CheckBoxGroup checkGroup = new CheckBoxGroup();
private LayoutContainer lc = new LayoutContainer();
private PanelPermission panelPermission;
private DialogPermission INSTANCE = this;
private List<InfoContactModel> listAlreadyShared = new ArrayList<InfoContactModel>(){
/**
*
*/
@ -86,9 +81,6 @@ public class DialogPermission extends Dialog {
setButtonAlign(HorizontalAlignment.CENTER);
setWidth(widthDialog);
setButtons(Dialog.OKCANCEL);
lc.setStyleAttribute("margin-top", "10px");
lc.setStyleAttribute("margin-bottom", "10px");
lc.setSize(480, 50);
}
/**
@ -96,70 +88,31 @@ public class DialogPermission extends Dialog {
*/
public DialogPermission(String folderParentName, HandlerManager eventBus) {
AppControllerExplorer.rpcWorkspaceService.getACLs(new AsyncCallback<List<WorkspaceACL>>() {
@Override
public void onSuccess(List<WorkspaceACL> result) {
panelPermission = new PanelPermission(result);
INSTANCE.layout(true);
}
@Override
public void onFailure(Throwable caught) {
INSTANCE.add(new Label("Error on recovering ACLs"));
}
});
initLayout(folderParentName);
this.setIcon(Resources.getIconSharedFolder());
setHeading("Set permission to folder: "+folderParentName);
setWidth(widthDialog);
setButtons(Dialog.OKCANCEL);
FlexTable flexTable = new FlexTable();
flexTable.setStyleName("userssuggest");
Label lableShareWith = new Label("Administrators");
flexTable.setWidget(0, 0, lableShareWith);
flexTable.setWidget(0, 1, suggestPanel);
checkGroup.mask("Loading");
AppControllerExplorer.rpcWorkspaceService.getACLs(new AsyncCallback<List<WorkspaceACL>>() {
@Override
public void onSuccess(List<WorkspaceACL> result) {
for (WorkspaceACL acl : result) {
CheckBox box = createCheckBox(acl);
checkGroup.add(box);
}
checkGroup.unmask();
lc.layout();
}
@Override
public void onFailure(Throwable caught) {
checkGroup.unmask();
}
});
Label labelOthers = new Label("Others");
flexTable.setWidget(2, 0, labelOthers);
flexTable.setWidget(2, 1, checkGroup);
lc.add(flexTable);
add(lc);
add(panelPermission);
addListners();
}
private CheckBox createCheckBox(WorkspaceACL acl){
CheckBox check = new CheckBox();
// check.setId(dsm.getId());
// check.setBoxLabel(dsm.getName() + " ("+property+")");
check.setBoxLabel(acl.getLabel());
check.setValueAttribute(acl.getLabel());
check.setData("WORKSPACEACL", acl);
check.setToolTip(new ToolTipConfig(acl.getLabel()));
return check;
}
public List<InfoContactModel> getSharedListUsers() {
// printSelectedUser();
return suggestPanel.getSelectedUser();
}
public void addListners(){
@ -181,89 +134,8 @@ public class DialogPermission extends Dialog {
}
});
/* buttonMultiDrag.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
final MultiDragContact multiDrag = new MultiDragContact();
multiDrag.show();
List<InfoContactModel> exclusiveContacts = userStore.getExclusiveContactsFromAllContact(suggestPanel.getSelectedUser());
multiDrag.addSourceContacts(exclusiveContacts);
for (InfoContactModel infoContactModel : suggestPanel.getSelectedUser()) {
if(!listAlreadyShared.contains(infoContactModel))
multiDrag.addTargetContact(infoContactModel);
}
multiDrag.addAlreadySharedContacts(suggestPanel.getSelectedUser());
// multiDrag.addTargetContacts(suggestPanel.getSelectedUser());
multiDrag.getButtonById(Dialog.OK).addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
initSuggestContacts();
for (InfoContactModel infoContactModel : multiDrag.getTargetListContact()) {
suggestPanel.addRecipient(infoContactModel.getName(),true);
}
// for (InfoContactModel infoContactModel : multiDrag.getTargetListContact()) {
//
// if(!listAlreadySharedContains(infoContactModel))
// suggestPanel.addRecipient(infoContactModel.getName(),true);
// }
suggestPanel.boxSetFocus();
// printSelectedUser();
}
});
}
});*/
}
private boolean listAlreadySharedContains(InfoContactModel contact){
if(contact==null)
return false;
for (InfoContactModel ct : listAlreadyShared) {
if(ct.getLogin().compareTo(contact.getLogin())==0){
return true;
}
}
return false;
}
//DEBUG
private void printSelectedUser(){
System.out.println("SELETECTED USERS: ");
for (InfoContactModel contact : suggestPanel.getSelectedUser())
System.out.println(contact);
}
private void initSuggestContacts(){
suggestPanel.resetItemSelected();
for (InfoContactModel contact : listAlreadyShared) {
suggestPanel.addRecipient(contact.getName(), false);
}
}
/**
*
* @param displayAlert

View File

@ -3,6 +3,7 @@ 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;
import org.gcube.portlets.user.workspace.client.ConstantsExplorer;
import org.gcube.portlets.user.workspace.client.model.FileModel;
import org.gcube.portlets.user.workspace.client.model.InfoContactModel;
@ -10,6 +11,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.WorkspaceACL;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.Scroll;
@ -24,7 +26,6 @@ import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Label;
@ -44,6 +45,7 @@ public class DialogShareFolder extends Dialog {
private MultiValuePanel suggestPanel = new MultiValuePanel(userStore);
private Button buttonMultiDrag = new Button("Choose Contacts");
private TextField<String> txtOwner;
private PanelPermission permission;
private List<InfoContactModel> listAlreadyShared = new ArrayList<InfoContactModel>(){
@ -119,7 +121,7 @@ public class DialogShareFolder extends Dialog {
lc.setStyleAttribute("margin-bottom", "10px");
lc.setSize(480, 50);
FlexTable flexTable = new FlexTable();
final FlexTable flexTable = new FlexTable();
flexTable.setStyleName("userssuggest");
Label labelShareWith = new Label("Share with users");
flexTable.setWidget(0, 0, labelShareWith);
@ -137,22 +139,27 @@ public class DialogShareFolder extends Dialog {
if(!folder.isShared()){ //SETTABLE PERMISSION ONLY IF FOLDER IS NOT ALREADY SHARED
Label labelProperty = new Label("Property");
Anchor anchorPermission = new Anchor("Set Permissions");
Label labelProperty = new Label("Permissions");
// final ToggleButton togglePermission = new ToggleButton("Set Permissions");
flexTable.setWidget(3, 0, labelProperty);
flexTable.setWidget(3, 1, anchorPermission);
final DialogPermission permission = new DialogPermission(folderParentName, eventBus);
anchorPermission.addClickHandler(new ClickHandler() {
flexTable.setWidget(3, 1, Resources.getIconLoading().createImage());
AppControllerExplorer.rpcWorkspaceService.getACLs(new AsyncCallback<List<WorkspaceACL>>() {
@Override
public void onClick(ClickEvent event) {
permission.show();
public void onSuccess(List<WorkspaceACL> result) {
permission = new PanelPermission(result);
flexTable.setWidget(3, 1, permission);
lc.layout();
}
@Override
public void onFailure(Throwable caught) {
flexTable.setWidget(3, 1, new Label("Error on recovering ACLs"));
}
});
// flexTable.setWidget(3, 1, permission);
}
lc.add(flexTable);
@ -215,7 +222,7 @@ public class DialogShareFolder extends Dialog {
setScrollMode(Scroll.AUTOY);
setBodyStyle("padding: 9px; background: none");
setWidth(widthDialog);
setHeight(380);
setHeight(397);
setResizable(true);
setButtonAlign(HorizontalAlignment.CENTER);
setWidth(widthDialog);
@ -230,7 +237,7 @@ public class DialogShareFolder extends Dialog {
initLayout(folderParentName);
this.setIcon(Resources.getIconSharedFolder());
setHeading("Create a new shared folder in: "+folderParentName);
setHeight(375);
setWidth(widthDialog);
setButtons(Dialog.OKCANCEL);
@ -245,12 +252,12 @@ public class DialogShareFolder extends Dialog {
textAreaDescription.setHeight(heightTextArea);
textAreaDescription.setWidth(380);
LayoutContainer lc = new LayoutContainer();
final LayoutContainer lc = new LayoutContainer();
lc.setStyleAttribute("margin-top", "10px");
lc.setStyleAttribute("margin-bottom", "10px");
lc.setSize(480, 50);
FlexTable flexTable = new FlexTable();
final FlexTable flexTable = new FlexTable();
flexTable.setStyleName("userssuggest");
Label lableShareWith = new Label("Share with users");
flexTable.setWidget(0, 0, lableShareWith);
@ -266,6 +273,30 @@ public class DialogShareFolder extends Dialog {
flexTable.setWidget(2, 0, labelDescription);
flexTable.setWidget(2, 1, textAreaDescription);
Label labelProperty = new Label("Permissions");
// final ToggleButton togglePermission = new ToggleButton("Set Permissions");
flexTable.setWidget(3, 0, labelProperty);
flexTable.setWidget(3, 1, Resources.getIconLoading().createImage());
AppControllerExplorer.rpcWorkspaceService.getACLs(new AsyncCallback<List<WorkspaceACL>>() {
@Override
public void onSuccess(List<WorkspaceACL> result) {
permission = new PanelPermission(result);
flexTable.setWidget(3, 1, permission);
lc.layout();
}
@Override
public void onFailure(Throwable caught) {
flexTable.setWidget(3, 1, new Label("Error on recovering ACLs"));
}
});
lc.add(flexTable);
setFocusWidget(txtName);
@ -421,4 +452,10 @@ public class DialogShareFolder extends Dialog {
return true;
}
public WorkspaceACL getSelectedACL(){
if(permission!=null)
return permission.getSelectedACL();
return null;
}
}

View File

@ -0,0 +1,91 @@
package org.gcube.portlets.user.workspace.client.view.sharing;
import java.util.List;
import org.gcube.portlets.user.workspace.shared.WorkspaceACL;
import org.gcube.portlets.user.workspace.shared.WorkspaceACL.USER_TYPE;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.form.Radio;
import com.extjs.gxt.ui.client.widget.form.RadioGroup;
import com.extjs.gxt.ui.client.widget.tips.ToolTipConfig;
public class PanelPermission extends LayoutContainer {
protected static final String WORKSPACEACL = "WORKSPACEACL";
private RadioGroup radioGroup = new RadioGroup();
public PanelPermission(List<WorkspaceACL> acls) {
setStyleAttribute("margin-top", "10px");
setStyleAttribute("margin-bottom", "10px");
setSize(350, 30);
radioGroup.mask("Loading ACLs");
for (WorkspaceACL acl : acls) {
if(acl.getUserType().equals(USER_TYPE.OTHER)){
Radio radio = createRadio(acl);
radioGroup.add(radio);
}
}
radioGroup.unmask();
add(radioGroup);
}
private Radio createRadio(WorkspaceACL acl) {
Radio radio = new Radio();
// check.setId(dsm.getId());
// check.setBoxLabel(dsm.getName() + " ("+property+")");
radio.setBoxLabel(acl.getLabel());
radio.setValueAttribute(acl.getLabel());
radio.setData(WORKSPACEACL, acl);
radio.setToolTip(new ToolTipConfig(acl.getLabel()));
radio.setValue(acl.getDefaultValue());
return radio;
}
public WorkspaceACL getSelectedACL() {
if (radioGroup.getValue()!=null)
return (WorkspaceACL) radioGroup.getValue().getData(WORKSPACEACL);
return null;
}
/*
public List<WorkspaceACL> getCheckedGroupList() {
List<WorkspaceACL> listDS = new ArrayList<WorkspaceACL>();
List<Radio> values = new ArrayList<Radio>();
if (radioGroup.getValue()!=null){
Radio radio = radioGroup.getValue();
values.add((Radio) radio);
}
else {
List<Field<?>> listChecks = radioGroup.getAll();
for (Field<?> field : listChecks) {
values.add((Radio) field);
}
}
for (Radio radio : values) {
if (radio.isEnabled()){
WorkspaceACL acl = (WorkspaceACL) radio.getData(WORKSPACEACL);
listDS.add(acl);
}
}
if (listDS.size() == 0)
return null;
return listDS;
}
*/
}

View File

@ -58,6 +58,7 @@ import org.gcube.portlets.user.workspace.server.util.WsUtil;
import org.gcube.portlets.user.workspace.server.util.scope.ScopeUtilFilter;
import org.gcube.portlets.user.workspace.shared.SessionExpiredException;
import org.gcube.portlets.user.workspace.shared.WorkspaceACL;
import org.gcube.portlets.user.workspace.shared.WorkspaceACL.USER_TYPE;
import org.gcube.portlets.user.workspace.shared.accounting.GxtAccountingEntryType;
import org.gcube.portlets.user.workspace.shared.accounting.GxtAccountingField;
import org.gcube.portlets.user.workspaceapplicationhandler.ApplicationReaderFromGenericResource;
@ -1797,7 +1798,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
}
@Override
public boolean shareFolder(FileModel folder, List<InfoContactModel> listContacts, boolean isNewFolder) throws Exception {
public boolean shareFolder(FileModel folder, List<InfoContactModel> listContacts, boolean isNewFolder, WorkspaceACL acl) throws Exception {
if(isSessionExpired())
throw new SessionExpiredException();
@ -1844,16 +1845,18 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
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: ");
/*System.out.println("SHARED CONTACS: ");
printContacts(listSharedContact);
System.out.println("NEW CONTACS: ");
printContacts(listContacts);
printContacts(listContacts);*/
np.notifyAddedUsersToSharing(listSharedContact, listContacts, sharedFolder);
}
}
@ -2461,13 +2464,15 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
@Override
public void setACLs(String folderId, List<String> listLogins, String aclType) throws Exception{
try {
// AccessManager am = HomeLibrary.getHomeManagerFactory().getAccessManager();
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");
workspaceLogger.trace("Setting ACL for folder id: "+folderId);
workspaceLogger.trace("ACL type is: "+aclType);
Workspace workspace = getWorkspace();
WorkspaceItem wsItem = workspace.getItem(folderId);
@ -2477,6 +2482,8 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
ite.setACL(listLogins, ACLType.valueOf(aclType));
}else
throw new Exception("Source item is not shared or shared folder");
workspaceLogger.trace("Setting ACL completed, retuning");
} catch (Exception e) {
workspaceLogger.error("Error in set ACLs", e);
String error = ConstantsExplorer.SERVER_ERROR +" setting permissions. "+e.getMessage();
@ -2498,21 +2505,21 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
switch (acl) {
case ADMINISTRATOR:
acls.add(new WorkspaceACL(acl.toString(), acl.toString()));
acls.add(new WorkspaceACL(acl.toString(), acl.toString(), false, USER_TYPE.ADMINISTRATOR));
break;
case READ_ONLY:
acls.add(new WorkspaceACL(acl.toString(), "Read Only"));
acls.add(new WorkspaceACL(acl.toString(), "Read Only", false, USER_TYPE.OTHER));
break;
case WRITE_OWNER:
acls.add(new WorkspaceACL(acl.toString(), "Write Owner"));
acls.add(new WorkspaceACL(acl.toString(), "Write Owner", true, USER_TYPE.OTHER));
break;
case WRITE_ALL:
acls.add(new WorkspaceACL(acl.toString(), "Write All"));
acls.add(new WorkspaceACL(acl.toString(), "Write All", false, USER_TYPE.OTHER));
break;
default:
acls.add(new WorkspaceACL(acl.toString(), acl.toString()));
acls.add(new WorkspaceACL(acl.toString(), acl.toString(), false, USER_TYPE.OTHER));
break;
}
}

View File

@ -16,12 +16,17 @@ public class WorkspaceACL implements Serializable{
private String id;
private String label;
private boolean defaultValue;
private USER_TYPE userType;
public enum USER_TYPE{ADMINISTRATOR, GROUP, OWNER, OTHER};
public WorkspaceACL(String id, String label) {
public WorkspaceACL(String id, String label, boolean defaultValue, USER_TYPE userType) {
super();
this.id = id;
this.label = label;
this.defaultValue = defaultValue;
this.userType = userType;
}
@ -46,6 +51,24 @@ public class WorkspaceACL implements Serializable{
this.label = label;
}
public boolean getDefaultValue() {
return defaultValue;
}
public void setDefaultValue(boolean defaultValue) {
this.defaultValue = defaultValue;
}
public USER_TYPE getUserType() {
return userType;
}
public void setUserType(USER_TYPE userType) {
this.userType = userType;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
@ -53,6 +76,10 @@ public class WorkspaceACL implements Serializable{
builder.append(id);
builder.append(", label=");
builder.append(label);
builder.append(", defaultValue=");
builder.append(defaultValue);
builder.append(", userType=");
builder.append(userType);
builder.append("]");
return builder.toString();
}