Update to handler data publishing

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@129475 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-06-27 14:27:48 +00:00
parent 6a022fa18c
commit 99166e43d8
10 changed files with 393 additions and 219 deletions

View File

@ -4,7 +4,6 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import org.gcube.portlets.user.workspace.client.ConstantsExplorer.WS_UPLOAD_TYPE;
import org.gcube.portlets.user.workspace.client.ConstantsExplorer.WsPortletInitOperation;
import org.gcube.portlets.user.workspace.client.event.AccountingHistoryEvent;
@ -60,6 +59,8 @@ import org.gcube.portlets.user.workspace.client.event.OpenUrlEvent;
import org.gcube.portlets.user.workspace.client.event.OpenUrlEventHandler;
import org.gcube.portlets.user.workspace.client.event.PasteItemEvent;
import org.gcube.portlets.user.workspace.client.event.PasteItemEventHandler;
import org.gcube.portlets.user.workspace.client.event.PublishOnDataCatalogueEvent;
import org.gcube.portlets.user.workspace.client.event.PublishOnDataCatalogueEventHandler;
import org.gcube.portlets.user.workspace.client.event.RefreshFolderEvent;
import org.gcube.portlets.user.workspace.client.event.RefreshItemEventHandler;
import org.gcube.portlets.user.workspace.client.event.RenameItemEvent;
@ -133,6 +134,7 @@ import org.gcube.portlets.user.workspace.shared.ReportAssignmentACL;
import org.gcube.portlets.user.workspace.shared.SessionExpiredException;
import org.gcube.portlets.user.workspace.shared.UserBean;
import org.gcube.portlets.user.workspace.shared.accounting.GxtAccountingField;
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.CreateDatasetForm;
import org.gcube.portlets.widgets.workspacesharingwidget.client.ConstantsSharing.LOAD_CONTACTS_AS;
import org.gcube.portlets.widgets.workspacesharingwidget.client.MultiDragConstants;
import org.gcube.portlets.widgets.workspacesharingwidget.client.MultiDragContactsEditPermissions;
@ -150,11 +152,13 @@ import com.extjs.gxt.ui.client.event.MessageBoxEvent;
import com.extjs.gxt.ui.client.widget.Dialog;
import com.extjs.gxt.ui.client.widget.Info;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.github.gwtbootstrap.client.ui.Modal;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.http.client.RequestBuilder;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.HasWidgets;
@ -173,9 +177,10 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
private boolean selectRootItem;
// private FileUploader fileUploader;
// private FileUploader fileUploader;
public static String myLogin;
public static String myLoginFirstName;
public static boolean ckanEditorOrAdmin;
//PRE-LOAD LIST OF USER FORM LIFERAY
private UserStore userStore = new UserStore();
@ -225,6 +230,44 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
*/
private void bind() {
eventBus.addHandler(PublishOnDataCatalogueEvent.TYPE, new PublishOnDataCatalogueEventHandler() {
@Override
public void onPublish(PublishOnDataCatalogueEvent publishEvent) {
// get the folder id
final String folderId = publishEvent.getFolderId();
if(folderId != null && !folderId.isEmpty()){
final Modal modal = new Modal(true, true);
// request who's doing the insert
rpcWorkspaceService.getUser(new AsyncCallback<String>() {
@Override
public void onSuccess(String username) {
if (username != null) {
modal.setTitle("Publish Product");
modal.addStyleName("insert-metadata-modal-style");
modal.add(new CreateDatasetForm(folderId, username));
modal.setCloseVisible(true);
modal.show();
}
else
Window.alert("Please, logout and login again then retry.");
}
@Override
public void onFailure(Throwable caught) {
Window.alert("Please, logout and login again then retry.");
}
});
}
}
});
eventBus.addHandler(UpdateWorkspaceSizeEvent.TYPE, new UpdateWorkspaceSizeEventHandler() {
@Override
@ -426,10 +469,10 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
FileModel parent = null;
//COMMENTED 26/02/2014
// if(parentFileModel==null){ //PARENT IS ROOT
// parent = explorerPanel.getAsycTreePanel().getRootItem();
// sourceFileModel.setParentFileModel(parent);
// }
// if(parentFileModel==null){ //PARENT IS ROOT
// parent = explorerPanel.getAsycTreePanel().getRootItem();
// sourceFileModel.setParentFileModel(parent);
// }
if(sourceFileModel.isDirectory()){
// explorerPanel.getAsycTreePanel().setExpandTreeLevel(sourceFileModel.getIdentifier(), true);
@ -515,7 +558,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
GWT.log("share completed throwing refresh folder : "+parentToRefresh.getName() +" get id: "+parentToRefresh.getIdentifier());
// eventBus.fireEvent(new RefreshFolderEvent(parentToRefresh, true, false, false));
// eventBus.fireEvent(new RefreshFolderEvent(parentToRefresh, true, false, false));
//TODO UPDATED ID
RefreshFolderEvent refEvent = new RefreshFolderEvent(parentToRefresh, true, true, false);
@ -703,8 +746,8 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
case CUT:
//TODO remove this comments
// if(pasteItemEvent.getFolderSourceId()==null || pasteItemEvent.getFolderSourceId().isEmpty())
// return;
// if(pasteItemEvent.getFolderSourceId()==null || pasteItemEvent.getFolderSourceId().isEmpty())
// return;
rpcWorkspaceService.moveItems(pasteItemEvent.getIds(), pasteItemEvent.getFolderDestinationId(), new AsyncCallback<Boolean>() {
@ -717,7 +760,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
}
new MessageBoxAlert("Error", caught.getMessage()+"." , null);
// System.out.println(caught.getMessage());
// System.out.println(caught.getMessage());
explorerPanel.getAsycTreePanel().reloadTreeLevelAndExpandFolder(pasteItemEvent.getFolderDestinationId(), false);
explorerPanel.getAsycTreePanel().reloadTreeLevelAndExpandFolder(pasteItemEvent.getFolderSourceId(), true);
}
@ -1006,7 +1049,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
GWT.log("doCompletedFileUploadEvent..."+parent);
if(parent!=null && completedFileUploadEvent.getItemIdentifier()!=null){
explorerPanel.getAsycTreePanel().reloadTreeLevelAndExpandFolder(completedFileUploadEvent.getParentId(), isLevelExpanded);
// explorerPanel.getAsycTreePanel().addItemIdAndExpandFolder(parent, completedFileUploadEvent.getItemIdentifier(), isLevelExpanded);
// explorerPanel.getAsycTreePanel().addItemIdAndExpandFolder(parent, completedFileUploadEvent.getItemIdentifier(), isLevelExpanded);
}
doUpdateWorkspaceSize(new UpdateWorkspaceSizeEvent());
notifySubscriber(completedFileUploadEvent);
@ -1113,7 +1156,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
@Override
public void onSmartFolderSelected(SmartFolderSelectedEvent smartFolderSelectedEvent) {
searching(true);
// System.out.println("Click smart folder : " + smartFolderSelectedEvent.getSmartFolderName());
// System.out.println("Click smart folder : " + smartFolderSelectedEvent.getSmartFolderName());
doSmartFolderSelected(smartFolderSelectedEvent);
}
@ -1231,8 +1274,8 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
}
notifySubscriber(event);
// doUpdateWorkspaceSize(new UpdateWorkspaceSizeEvent());
// eventBus.fireEvent(new UpdateWorkspaceSizeEvent());
// doUpdateWorkspaceSize(new UpdateWorkspaceSizeEvent());
// eventBus.fireEvent(new UpdateWorkspaceSizeEvent());
}
};
@ -1383,7 +1426,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
}
new MessageBoxAlert("Error", caught.getMessage()+"." , null);
// System.out.println(caught.getMessage());
// System.out.println(caught.getMessage());
explorerPanel.getAsycTreePanel().reloadTreeLevelAndExpandFolder(event.getTargetParentFileModel().getIdentifier(), false);
explorerPanel.getAsycTreePanel().reloadTreeLevelAndExpandFolder(event.getFileSourceModel().getParentFileModel().getIdentifier(), true);
}
@ -1562,12 +1605,12 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
String currentUrl = portalURL();
int last = currentUrl.lastIndexOf("/");
String reportUrl = currentUrl.substring(0,last+1) + ConstantsExplorer.REPORTGENERATION;
// new WindowOpenUrl(reportUrl, "_self", "");
// new WindowOpenUrl(reportUrl, "_self", "");
newBrowserWindow.setUrl(reportUrl);
}
else{
String reportUrl = url;
// new WindowOpenUrl(reportUrl, "_self", "");
// new WindowOpenUrl(reportUrl, "_self", "");
newBrowserWindow.setUrl(reportUrl);
}
}
@ -1598,12 +1641,12 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
GWT.log("currentUrl " +currentUrl);
GWT.log("reportUrl " +templateUrl);
newBrowserWindow.setUrl(templateUrl);
// new WindowOpenUrl(templateUrl, "_self", "");
// new WindowOpenUrl(templateUrl, "_self", "");
}else{
String templateUrl = url;
newBrowserWindow.setUrl(templateUrl);
// new WindowOpenUrl(templateUrl, "_self", "");
// new WindowOpenUrl(templateUrl, "_self", "");
}
}
@ -1695,7 +1738,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
sub.setParentItemSelected(subTreeEvent.getPathParentsList());
// if(openTreeMenuEvent && isShowTreeMenu==false)
// eventBus.fireEvent(new O)
// eventBus.fireEvent(new O)
}else if(event instanceof SmartFolderSelectedEvent){
@ -1894,7 +1937,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
this.explorerPanel.setSize(400, 600);
this.explorerPanel.getAsycTreePanel().setSizeTreePanel(350, 550);
// rootPanel.add(new BasicDNDExample()); //it's example of drag&drop
// rootPanel.add(new BasicDNDExample()); //it's example of drag&drop
}else
this.explorerPanel = new ExplorerPanel(instancingSmartFolder,instancingMessages);
@ -2016,7 +2059,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
});
}
// GWT.log(targets.toString());
// GWT.log(targets.toString());
if(targets.size()>=1 && multiDragContact.getSelectedAcl()!=null){
@ -2052,7 +2095,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
String names = "";
for (String name : result.getValidLogins()) {
// String name = infoContactModel.getName()!=null? infoContactModel.getName():infoContactModel.getLogin();
// String name = infoContactModel.getName()!=null? infoContactModel.getName():infoContactModel.getLogin();
names+="<li><i>"+name +";</i></li>";
}
@ -2066,7 +2109,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
//IF NOT CANCELLED
String clickedButton = be.getButtonClicked().getItemId();
if(clickedButton.equals(Dialog.YES)){
// doAddAdministratorToFolderId(file, logins);
// doAddAdministratorToFolderId(file, logins);
setACLToFolderId(file.getIdentifier(), logins, multiDragContact.getSelectedAclID());
multidrag.hide();
}else if(clickedButton.equals(Dialog.CANCEL)){
@ -2234,6 +2277,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
GWT.log("My login is: "+user.getUsername());
myLogin = user.getUsername();
myLoginFirstName = user.getFirstName();
ckanEditorOrAdmin = user.hasCataloguePermission();
}
});
}
@ -2559,11 +2603,11 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
if(fileModel.getGXTFolderItemType().equals(GXTFolderItemTypeEnum.URL_DOCUMENT)){
newBrowserWindow.setUrl(((GWTUrlDocument) result).getUrl());
// new WindowOpenUrl(((GWTUrlDocument) result).getUrl(), "_blank", "");
// new WindowOpenUrl(((GWTUrlDocument) result).getUrl(), "_blank", "");
GWT.log("URL_DOCUMENT Open " + ((GWTUrlDocument) result).getUrl());
}
else{
// new WindowOpenUrl(((GWTExternalUrl) result).getUrl(), "_blank", "");
// new WindowOpenUrl(((GWTExternalUrl) result).getUrl(), "_blank", "");
newBrowserWindow.setUrl(((GWTExternalUrl) result).getUrl());
GWT.log("ExternalUrl Open " + ((GWTExternalUrl) result).getUrl());
}

View File

@ -32,6 +32,7 @@ public class ConstantsExplorer {
public static final String MESSAGE_ADD_SMART_FOLDER = "New Smart Folder";
public static final String MESSAGE_ADD_FOLDER = "New Folder";
public static final String MESSAGE_ADD_SHARED_FOLDER = "New Shared Folder";
public static final String MESSAGE_DATA_CATALOGUE_PUBLISH = "Publish on Catalogue";
public static final String MESSAGE_ADD = "Add";
public static final String MESSAGE_ADD_FOLDER_IN = "Create a new folder in: ";
public static final String MESSAGE_ITEM_NAME = "Item Name";

View File

@ -10,6 +10,7 @@ public enum WorkspaceOperation {
PREVIEW("PRW", "PRW"),
RENAME("RNM", "RNM"),
INSERT_SHARED_FOLDER("ISHF", "ASHF"), // Insert shared Folder
PUBLISH_ON_DATA_CATALOGUE("PODC", "PODC"),
SHARE("SHR", "SHR"), // SHARE
UNSHARE("USHR", "USHR"), // UNSHARE
UPLOAD_ARCHIVE("UPA", "UPA"), // Upload Archive

View File

@ -0,0 +1,46 @@
package org.gcube.portlets.user.workspace.client.event;
import com.google.gwt.event.shared.GwtEvent;
/**
* The Class PublishOnDataCatalogueEvent
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
public class PublishOnDataCatalogueEvent extends GwtEvent<PublishOnDataCatalogueEventHandler> {
public static Type<PublishOnDataCatalogueEventHandler> TYPE = new Type<PublishOnDataCatalogueEventHandler>();
private String folderId;
/**
* Instantiates a new insert metadata event.
*/
public PublishOnDataCatalogueEvent(String folderId) {
this.folderId = folderId;
}
/**
* @return the folderId
*/
public String getFolderId() {
return folderId;
}
/* (non-Javadoc)
* @see com.google.gwt.event.shared.GwtEvent#getAssociatedType()
*/
@Override
public Type<PublishOnDataCatalogueEventHandler> getAssociatedType() {
return TYPE;
}
/* (non-Javadoc)
* @see com.google.gwt.event.shared.GwtEvent#dispatch(com.google.gwt.event.shared.EventHandler)
*/
@Override
protected void dispatch(PublishOnDataCatalogueEventHandler handler) {
handler.onPublish(this);
}
}

View File

@ -0,0 +1,18 @@
package org.gcube.portlets.user.workspace.client.event;
import com.google.gwt.event.shared.EventHandler;
/**
* The Interface PublishOnDataCatalogueEventHandler
* @author Costantino Perciante at ISTI-CNR
* (costantino.perciante@isti.cnr.it)
*/
public interface PublishOnDataCatalogueEventHandler extends EventHandler {
/**
* On insert metadata.
*
* @param loadSelecteReleaseEvent the load selecte release event
*/
void onPublish(PublishOnDataCatalogueEvent loadSelecteReleaseEvent);
}

View File

@ -700,5 +700,10 @@ public interface GWTWorkspaceService extends RemoteService{
* @return true if he can publish, false otherwise
*/
boolean hasUserRoleAdminOrEditor();
/**
* Retrieve the username of the user into the session
* @return the username of the current user
*/
String getUser();
}

View File

@ -690,4 +690,10 @@ public interface GWTWorkspaceServiceAsync {
*/
void hasUserRoleAdminOrEditor(AsyncCallback<Boolean> callback);
/**
* Retrieve the username of the user into the session
* @return the username of the current user
*/
void getUser(AsyncCallback<String> callback);
}

View File

@ -26,6 +26,7 @@ import org.gcube.portlets.user.workspace.client.event.ImagePreviewEvent;
import org.gcube.portlets.user.workspace.client.event.OpenReportsEvent;
import org.gcube.portlets.user.workspace.client.event.OpenUrlEvent;
import org.gcube.portlets.user.workspace.client.event.PasteItemEvent;
import org.gcube.portlets.user.workspace.client.event.PublishOnDataCatalogueEvent;
import org.gcube.portlets.user.workspace.client.event.RefreshFolderEvent;
import org.gcube.portlets.user.workspace.client.event.RenameItemEvent;
import org.gcube.portlets.user.workspace.client.event.SendMessageEvent;
@ -58,7 +59,7 @@ public class ContextMenuTree {
private Menu contextMenu = new Menu();
private HandlerManager eventBus = AppControllerExplorer.getEventBus();
private List<FileModel> listSelectedItems = null;
private MenuItem mnRead = new MenuItem();
private boolean hideSharing = false;
@ -102,7 +103,7 @@ public class ContextMenuTree {
});
contextMenu.add(previewImage);
//Open Url
MenuItem openUrl = new MenuItem();
@ -169,12 +170,12 @@ public class ContextMenuTree {
//END SPECIFIC OPERATION
MenuItem mnGetInfo = new MenuItem();
mnGetInfo.setId(WorkspaceOperation.GET_INFO.getId());
mnGetInfo.setText(ConstantsExplorer.MESSAGE_GET_INFO);
mnGetInfo.setIcon(Resources.getIconInfo());
mnGetInfo.addSelectionListener(new SelectionListener<MenuEvent>() {
public void componentSelected(MenuEvent ce) {
@ -183,16 +184,16 @@ public class ContextMenuTree {
}
}
});
contextMenu.add(mnGetInfo);
//SHARE LINK
MenuItem mnGetLink = new MenuItem();
mnGetLink.setId(WorkspaceOperation.SHARE_LINK.getId());
mnGetLink.setText(ConstantsExplorer.MESSAGE_SHARE_LINK);
mnGetLink.setIcon(Resources.getIconShareLink());
mnGetLink.addSelectionListener(new SelectionListener<MenuEvent>() {
public void componentSelected(MenuEvent ce) {
@ -201,15 +202,15 @@ public class ContextMenuTree {
}
}
});
contextMenu.add(mnGetLink);
//PUBLIC LINK
MenuItem mnPublicLink = new MenuItem();
mnPublicLink.setId(WorkspaceOperation.PUBLIC_LINK.getId());
mnPublicLink.setText(ConstantsExplorer.MESSAGE_PUBLIC_LINK);
mnPublicLink.setIcon(Resources.getIconPublicLink());
mnPublicLink.addSelectionListener(new SelectionListener<MenuEvent>() {
public void componentSelected(MenuEvent ce) {
@ -218,21 +219,21 @@ public class ContextMenuTree {
}
}
});
contextMenu.add(mnPublicLink);
contextMenu.add(new SeparatorMenuItem());
MenuItem mnHistory = new MenuItem();
mnHistory.setIcon(Resources.getIconHistory());
mnHistory.setId(WorkspaceOperation.HISTORY.getId());
mnHistory.setText(ConstantsExplorer.HISTORY);
mnHistory.addSelectionListener(new SelectionListener<MenuEvent>() {
@Override
public void componentSelected(MenuEvent ce) {
final FileModel sourceFileModel = listSelectedItems.get(0);
if (sourceFileModel != null) {
@ -242,30 +243,30 @@ public class ContextMenuTree {
}
});
contextMenu.add(mnHistory);
//ACCOUNTING READ
mnRead = new MenuItem();
mnRead.setIcon(Resources.getIconRead());
mnRead.setId(WorkspaceOperation.ACCREAD.getId());
mnRead.setText(ConstantsExplorer.ACCREAD);
mnRead.addSelectionListener(new SelectionListener<MenuEvent>() {
@Override
public void componentSelected(MenuEvent ce) {
final FileModel sourceFileModel = listSelectedItems.get(0);
if (sourceFileModel != null) {
eventBus.fireEvent(new AccountingReadersEvent(sourceFileModel));
}
}
});
//COMMENTED AT 29/08/2013
// contextMenu.add(mnRead);
// contextMenu.add(mnRead);
contextMenu.add(new SeparatorMenuItem());
MenuItem insertFolder = new MenuItem();
@ -304,8 +305,28 @@ public class ContextMenuTree {
}
});
contextMenu.add(createShareFolder);
// publish on data catalogue
MenuItem publishOnDataCatalogue = new MenuItem();
publishOnDataCatalogue.setId(WorkspaceOperation.PUBLISH_ON_DATA_CATALOGUE.getId());
publishOnDataCatalogue.setText(ConstantsExplorer.MESSAGE_DATA_CATALOGUE_PUBLISH);
publishOnDataCatalogue.setIcon(Resources.getIconPublicLink()); // TODO change icon
publishOnDataCatalogue.addSelectionListener(new SelectionListener<MenuEvent>() {
public void componentSelected(MenuEvent ce) {
FileModel sourceFileModel = listSelectedItems.get(0);
String folderId = sourceFileModel.getIdentifier();
if (sourceFileModel != null) {
eventBus.fireEvent(new PublishOnDataCatalogueEvent(folderId));
}
}
});
publishOnDataCatalogue.setVisible(false);
contextMenu.add(publishOnDataCatalogue);
MenuItem editPermissions = new MenuItem();
editPermissions.setId(WorkspaceOperation.EDIT_PERMISSIONS.getId());
editPermissions.setText(ConstantsExplorer.EDIT_PERMISSIONS);
@ -321,7 +342,7 @@ public class ContextMenuTree {
}
}
});
contextMenu.add(editPermissions);
@ -355,17 +376,17 @@ public class ContextMenuTree {
copy.addSelectionListener(new SelectionListener<MenuEvent>() {
public void componentSelected(MenuEvent ce) {
// //HERE THE MULTI-SELECTION IS NOT ENABLED
// for (FileModel target : listSelectedItems) {
// if(target.getIdentifier()!=null){
// CopyAndPaste.copy(target.getIdentifier()));
// eventBus.fireEvent(new CopytemEvent(target.getIdentifier()));
// }
// }
//
// //HERE THE MULTI-SELECTION IS NOT ENABLED
// for (FileModel target : listSelectedItems) {
// if(target.getIdentifier()!=null){
// CopyAndPaste.copy(target.getIdentifier()));
// eventBus.fireEvent(new CopytemEvent(target.getIdentifier()));
// }
// }
//
List<String> ids = FileModelUtils.convertFileModelsToIds(listSelectedItems);
if(ids.size()>0){
CutCopyAndPaste.copy(ids, OperationType.COPY);
eventBus.fireEvent(new CopytemEvent(ids));
@ -407,7 +428,7 @@ public class ContextMenuTree {
share.addSelectionListener(new SelectionListener<MenuEvent>() {
public void componentSelected(MenuEvent ce) {
FileModel sourceFileModel = listSelectedItems.get(0);
if (sourceFileModel != null) {
@ -416,7 +437,7 @@ public class ContextMenuTree {
}
});
contextMenu.add(share);
MenuItem unShare = new MenuItem();
@ -437,7 +458,7 @@ public class ContextMenuTree {
});
contextMenu.add(unShare);
MenuItem rename = new MenuItem();
rename.setId(WorkspaceOperation.RENAME.getId());
rename.setText("Rename Item");
@ -593,7 +614,7 @@ public class ContextMenuTree {
contextMenu.add(downloadArchive);
contextMenu.add(new SeparatorMenuItem());
MenuItem changePermission = new MenuItem();
changePermission.setId(WorkspaceOperation.VRE_CHANGE_PERIMISSIONS.getId());
changePermission.setText("Change Permission");
@ -610,14 +631,14 @@ public class ContextMenuTree {
}
});
contextMenu.add(changePermission);
contextMenu.add(new SeparatorMenuItem());
MenuItem addAdministrator = new MenuItem();
// addAdministrator.setId(WorkspaceOperation.ADD_ADMINISTRATOR.getId());
// addAdministrator.setId(WorkspaceOperation.ADD_ADMINISTRATOR.getId());
addAdministrator.setText("Manage Administrator/s");
addAdministrator.setIcon(Resources.getIconManageAdministrator());
@ -629,8 +650,8 @@ public class ContextMenuTree {
}
}
});
// contextMenu.add(addAdministrator);
// contextMenu.add(addAdministrator);
MenuItem refreshItem = new MenuItem();
refreshItem.setId(WorkspaceOperation.REFRESH_FOLDER.getId());
@ -645,10 +666,10 @@ public class ContextMenuTree {
}
}
});
contextMenu.add(refreshItem);
contextMenu.add(new SeparatorMenuItem());
}
/**
@ -680,17 +701,17 @@ public class ContextMenuTree {
printSelected();
if(targetFileModel!=null){
if(targetFileModel.getParentFileModel()==null){
Info.display("Wait", "loading available operations..");
AppControllerExplorer.rpcWorkspaceService.getParentByItemId(targetFileModel.getIdentifier(), new AsyncCallback<FileModel>() {
@Override
public void onFailure(Throwable caught) {
Info.display("Error", "sorry an error occurrend on loading available operations");
}
@Override
@ -701,19 +722,19 @@ public class ContextMenuTree {
}
else
Info.display("Error", "sorry an error occurrend on loading available operations");
}
});
}
else
viewContextMenu(targetFileModel, posX, posY);
}
}
/**
* View context menu.
*
@ -722,7 +743,7 @@ public class ContextMenuTree {
* @param posY the pos y
*/
private void viewContextMenu(FileModel targetFileModel, int posX, int posY){
contextMenuSwitch(targetFileModel);
contextMenu.getItemByItemId(WorkspaceOperation.INSERT_FOLDER.getId()).setVisible(false); //set invisible create folder
contextMenu.getItemByItemId(WorkspaceOperation.INSERT_SHARED_FOLDER.getId()).setVisible(false); //set invisible create shared folder
@ -731,11 +752,11 @@ public class ContextMenuTree {
contextMenu.getItemByItemId(WorkspaceOperation.UPLOAD_ARCHIVE.getId()).setVisible(false); //set invisible upload archive
contextMenu.getItemByItemId(WorkspaceOperation.ADD_URL.getId()).setVisible(false); //set invisible add url
contextMenu.getItemByItemId(WorkspaceOperation.REFRESH_FOLDER.getId()).setVisible(false); //set invisible refresh
// contextMenu.getItemByItemId(WorkspaceOperation.SHARE.getId()).setVisible(false); //set invisible share
// contextMenu.getItemByItemId(WorkspaceOperation.UNSHARE.getId()).setVisible(false); //set invisible unshare
// contextMenu.getItemByItemId(WorkspaceOperation.SHARE.getId()).setVisible(false); //set invisible share
// contextMenu.getItemByItemId(WorkspaceOperation.UNSHARE.getId()).setVisible(false); //set invisible unshare
contextMenu.showAt(posX, posY);
}
@ -766,7 +787,7 @@ public class ContextMenuTree {
contextMenu.getItemByItemId(WorkspaceOperation.SENDTO.getId()).setVisible(true); //send to
contextMenu.getItemByItemId(WorkspaceOperation.DOWNLOAD.getId()).setVisible(true); //DOWNLOAD
contextMenu.getItemByItemId(WorkspaceOperation.COPY.getId()).setEnabled(true); //DOWNLOAD
contextMenu.getItemByItemId(WorkspaceOperation.PREVIEW.getId()).setVisible(false); //preview image
contextMenu.getItemByItemId(WorkspaceOperation.LINK.getId()).setVisible(false); //open link
contextMenu.getItemByItemId(WorkspaceOperation.SHOW.getId()).setVisible(false); //show
@ -775,39 +796,39 @@ public class ContextMenuTree {
contextMenu.getItemByItemId(WorkspaceOperation.PASTE.getId()).setEnabled(false); //paste
contextMenu.getItemByItemId(WorkspaceOperation.REFRESH_FOLDER.getId()).setVisible(false); //refresh
contextMenu.getItemByItemId(WorkspaceOperation.PUBLIC_LINK.getId()).setVisible(false); //public link
// contextMenu.getItemByItemId(WorkspaceOperation.ADD_ADMINISTRATOR.getId()).setVisible(false); //public link
// contextMenu.getItemByItemId(WorkspaceOperation.ADD_ADMINISTRATOR.getId()).setVisible(false); //public link
contextMenu.getItemByItemId(WorkspaceOperation.EDIT_PERMISSIONS.getId()).setVisible(false);
contextMenu.getItemByItemId(WorkspaceOperation.SHARE.getId()).setVisible(false); //SHARE
contextMenu.getItemByItemId(WorkspaceOperation.UNSHARE.getId()).setVisible(false); //UNSHARE
contextMenu.getItemByItemId(WorkspaceOperation.SHARE_LINK.getId()).setVisible(false); //SHARE
contextMenu.getItemByItemId(WorkspaceOperation.VRE_CHANGE_PERIMISSIONS.getId()).setVisible(false); //VRE CHANGE PERMISSIONS
if(selectedItem.isShared()){ //SHARE LINK ON SHARED ITEM
contextMenu.getItemByItemId(WorkspaceOperation.SHARE_LINK.getId()).setVisible(true);
}
//IS VRE FOLDER or SPECIAL FOLDER?
if(selectedItem.isVreFolder() || selectedItem.isSpecialFolder()){
contextMenu.getItemByItemId(WorkspaceOperation.SHARE.getId()).setVisible(false); //SHARE
contextMenu.getItemByItemId(WorkspaceOperation.INSERT_SHARED_FOLDER.getId()).setVisible(false); //insert shared folder
contextMenu.getItemByItemId(WorkspaceOperation.UNSHARE.getId()).setVisible(false); //UNSHARE
contextMenu.getItemByItemId(WorkspaceOperation.RENAME.getId()).setVisible(false); //RENAME
contextMenu.getItemByItemId(WorkspaceOperation.REMOVE.getId()).setVisible(false); //REMOVE
contextMenu.getItemByItemId(WorkspaceOperation.REFRESH_FOLDER.getId()).setVisible(true); //REFRESH_FOLDER
//ADDED 14/03/2014
if(selectedItem.isVreFolder()){
contextMenu.getItemByItemId(WorkspaceOperation.VRE_CHANGE_PERIMISSIONS.getId()).setVisible(true); //REFRESH_FOLDER
if(CutCopyAndPaste.getCopiedIdsFilesModel()!=null)
contextMenu.getItemByItemId(WorkspaceOperation.PASTE.getId()).setEnabled(true); //enable paste button
}
// if(selectedItem.isVreFolder() && CutCopyAndPaste.getCopiedIdsFilesModel()!=null)
// contextMenu.getItemByItemId(WorkspaceOperation.PASTE.getId()).setEnabled(true); //enable paste button
// if(selectedItem.isVreFolder() && CutCopyAndPaste.getCopiedIdsFilesModel()!=null)
// contextMenu.getItemByItemId(WorkspaceOperation.PASTE.getId()).setEnabled(true); //enable paste button
else if(selectedItem.isSpecialFolder()){
contextMenu.getItemByItemId(WorkspaceOperation.COPY.getId()).setEnabled(false);
contextMenu.getItemByItemId(WorkspaceOperation.PASTE.getId()).setEnabled(false);
@ -818,20 +839,23 @@ public class ContextMenuTree {
contextMenu.getItemByItemId(WorkspaceOperation.INSERT_FOLDER.getId()).setVisible(false); //insert folder
contextMenu.getItemByItemId(WorkspaceOperation.DOWNLOAD.getId()).setVisible(false);
}
return;
}
//CASE DIRECTORY
if(selectedItem.isDirectory()){
if(AppControllerExplorer.ckanEditorOrAdmin)
contextMenu.getItemByItemId(WorkspaceOperation.PUBLISH_ON_DATA_CATALOGUE.getId()).setVisible(true);
contextMenu.getItemByItemId(WorkspaceOperation.SHARE.getId()).setVisible(true); //SHARE
contextMenu.getItemByItemId(WorkspaceOperation.SHOW.getId()).setVisible(false); //show
contextMenu.getItemByItemId(WorkspaceOperation.REFRESH_FOLDER.getId()).setVisible(true); //refresh
contextMenu.getItemByItemId(WorkspaceOperation.SENDTO.getId()).setVisible(false); //send to
if(selectedItem.isShared()){//IS SHARED
// contextMenu.getItemByItemId(WorkspaceOperation.ADD_ADMINISTRATOR.getId()).setVisible(true); //add administrator
// contextMenu.getItemByItemId(WorkspaceOperation.ADD_ADMINISTRATOR.getId()).setVisible(true); //add administrator
if(selectedItem.isShareable()){ //IS SHARABLE
contextMenu.getItemByItemId(WorkspaceOperation.INSERT_SHARED_FOLDER.getId()).setVisible(false); //insert shared folder
contextMenu.getItemByItemId(WorkspaceOperation.UNSHARE.getId()).setVisible(true);
@ -912,7 +936,7 @@ public class ContextMenuTree {
contextMenu.getItemByItemId(WorkspaceOperation.PASTE.getId()).setEnabled(true); //enable paste button
}
/**
* The method return input file model if is directory otherwise parent of file model.
*

View File

@ -118,17 +118,27 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
// ckan utils methods
private CKanUtilsImpl instance;
private Object LOCK = new Object();
@Override
public void init(){
/**
* Retrieve the ckan utils object
* @return
*/
private CKanUtilsImpl getCkanUtils(){
// retrieve ckan information
try{
String currentScope = ScopeProvider.instance.get();
instance = new CKanUtilsImpl(currentScope);
}catch(Exception e){
workspaceLogger.error("Unable to retrieve ckan information");
if(instance == null){
synchronized (LOCK) {
if(instance == null){
try{
String currentScope = WsUtil.getAslSession(this.getThreadLocalRequest().getSession()).getScope();
instance = new CKanUtilsImpl(currentScope);
}catch(Exception e){
workspaceLogger.error("Unable to retrieve ckan information");
}
}
}
}
return instance;
}
/**
@ -2685,7 +2695,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
String email = username+"@isti.cnr.it";
String firstName = "Testing";
String lastName = "User";
boolean catalogueEditor = false;
if (isWithinPortal() && username.compareTo(WsUtil.TEST_USER) != 0) {
try {
@ -2694,6 +2704,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
firstName = user.getFirstName();
lastName = user.getLastName();
email = user.getEmail();
// check if he has catalogue role
catalogueEditor = hasUserRoleAdminOrEditor();
}catch (UserManagementSystemException e) {
workspaceLogger.error("UserManagementSystemException for username: "+username);
}
@ -2702,7 +2715,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
}
}
return new UserBean(username, firstName, lastName, email);
return new UserBean(username, firstName, lastName, email, catalogueEditor);
}
/**
@ -3420,101 +3433,101 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
public boolean hasUserRoleAdminOrEditor() {
ASLSession asl = WsUtil.getAslSession(this.getThreadLocalRequest().getSession());
String username = asl.getUsername();
// check if this information was already into the ASL Session
String role = (String)asl.getAttribute(CKAN_ROLE);
if(role != null)
switch(role){
case "editor" :
case "admin" : return true;
default: return false; // member
}
try{
if(!isWithinPortal()){
workspaceLogger.warn("OUT FROM PORTAL DETECTED RETURNING TRUE");
asl.setAttribute(CKAN_ROLE, "editor");
return true;
}
// first of all, check if the user is a sysadmin in the catalog (in this case he can do everything)
boolean isSysAdmin = instance.isSysAdmin(username, getUserCKanTokenFromSession());
if(isSysAdmin){
workspaceLogger.debug("The user is a sysadmin of the catalog -> he can edit/add");
asl.setAttribute(CKAN_ROLE, "admin");
return true;
}else{
// retrieve the liferay's roles for the user
UserManager userManager = new LiferayUserManager();
RoleManager roleManager = new LiferayRoleManager();
GroupManager groupManager = new LiferayGroupManager();
// we need to iterate over vres
List<GCubeGroup> groups = groupManager.listGroups();
for (GCubeGroup gCubeGroup : groups) {
String groupName = gCubeGroup.getGroupName();
// skip if it is not a vre
if(!groupManager.isVRE(gCubeGroup.getGroupId()))
continue;
List<GCubeRole> roles = roleManager.listRolesByUserAndGroup(userManager.getUserId(username), groupManager.getGroupId(groupName));
// the default one
RolesIntoOrganization correspondentRoleToCheck = RolesIntoOrganization.MEMBER;
String roleToSetInSession = null;
// NOTE: it is supposed that there is just one role for this person correspondent to the one in the catalog
for (GCubeRole gCubeRole : roles) {
workspaceLogger.debug("User " + username + " has role " + gCubeRole.getRoleName() + " in " + groupName);
if(gCubeRole.getRoleName().equalsIgnoreCase(CkanRolesIntoLiferay.CATALOG_ADMIN.toString())){
correspondentRoleToCheck = RolesIntoOrganization.ADMIN;
roleToSetInSession = "admin";
break;
}else if(gCubeRole.getRoleName().equalsIgnoreCase(CkanRolesIntoLiferay.CATALOG_EDITOR.toString())){
correspondentRoleToCheck = RolesIntoOrganization.EDITOR;
roleToSetInSession = "editor";
break;
}
}
// if the role is member, keep continuing
if(correspondentRoleToCheck.equals(RolesIntoOrganization.MEMBER))
continue;
// with this invocation, we check if the role is present in ckan and if it is not it will be added
boolean res = instance.checkRole(username, groupName, correspondentRoleToCheck);
// set the role in the asl session
if(res){
}
return res;
}
}
}catch(Exception e){
workspaceLogger.error("Unable to retrieve the role information for this user. Returning FALSE", e);
if(!isWithinPortal()){
workspaceLogger.warn("OUT FROM PORTAL DETECTED RETURNING TRUE");
asl.setAttribute(CKAN_ROLE, "editor");
return true;
}
workspaceLogger.debug("Unable to check the role into ckan organization, returning FALSE");
// set the role member into the asl
asl.setAttribute(CKAN_ROLE, "member");
// check if this information was already into the ASL Session (true means the user has at least in one org
// the role editor/admin), false that he is just a member so he cannot publish
Boolean role = (Boolean)asl.getAttribute(CKAN_ROLE);
// return false
return false;
// if the attribute was already set..
if(role != null)
return role;
else{
try{
// first of all, check if the user is a sysadmin in the catalog (in this case he can do everything)
boolean isSysAdmin = getCkanUtils().isSysAdmin(username, getUserCKanTokenFromSession());
if(isSysAdmin){
workspaceLogger.debug("The user is a sysadmin of the catalog -> he can edit/add");
asl.setAttribute(CKAN_ROLE, true);
return true;
}else{
// retrieve the liferay's roles for the user
UserManager userManager = new LiferayUserManager();
RoleManager roleManager = new LiferayRoleManager();
GroupManager groupManager = new LiferayGroupManager();
// we need to iterate over vres of the user
List<GCubeGroup> groups = groupManager.listGroupsByUser(userManager.getUserId(username));
workspaceLogger.debug("The list of organizations of the user " + username + " is " + groups);
boolean toReturn = false;
for (GCubeGroup gCubeGroup : groups) {
String groupName = gCubeGroup.getGroupName();
// skip if it is not a vre
if(!groupManager.isVRE(gCubeGroup.getGroupId()))
continue;
List<GCubeRole> roles = roleManager.listRolesByUserAndGroup(userManager.getUserId(username), groupManager.getGroupId(groupName));
// the default one
RolesIntoOrganization correspondentRoleToCheck = RolesIntoOrganization.MEMBER;
// NOTE: it is supposed that there is just one role for this person correspondent to the one in the catalog
for (GCubeRole gCubeRole : roles) {
workspaceLogger.debug("User " + username + " has role " + gCubeRole.getRoleName() + " in " + groupName);
if(gCubeRole.getRoleName().equalsIgnoreCase(CkanRolesIntoLiferay.CATALOG_ADMIN)){
correspondentRoleToCheck = RolesIntoOrganization.ADMIN;
toReturn = true;
break;
}else if(gCubeRole.getRoleName().equalsIgnoreCase(CkanRolesIntoLiferay.CATALOG_EDITOR)){
correspondentRoleToCheck = RolesIntoOrganization.EDITOR;
toReturn = true;
break;
}
}
// if the role is member, continue
if(correspondentRoleToCheck.equals(RolesIntoOrganization.MEMBER))
continue;
// with this invocation, we check if the role is present in ckan and if it is not it will be added
toReturn &= getCkanUtils().checkRole(username, groupName, correspondentRoleToCheck);
}
// set true in the asl session
workspaceLogger.debug("Setting CKAN_ROLE for " + username + " to " + toReturn);
asl.setAttribute(CKAN_ROLE, toReturn);
return toReturn;
}
}catch(Exception e){
workspaceLogger.error("Unable to retrieve the role information for this user. Returning FALSE", e);
}
workspaceLogger.debug("Unable to check the role into ckan organization, returning FALSE");
// set the role member into the asl
asl.setAttribute(CKAN_ROLE, false);
// return false
return false;
}
}
/**
@ -3534,7 +3547,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
token = (String)this.getThreadLocalRequest().getSession().getAttribute(CKAN_TOKEN_KEY);
else{
token = instance.getApiKeyFromUsername(username);
token = getCkanUtils().getApiKeyFromUsername(username);
this.getThreadLocalRequest().getSession().setAttribute(CKAN_TOKEN_KEY, token);
workspaceLogger.debug("Ckan token has been set for user " + username);
}
@ -3543,4 +3556,11 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
return token;
}
@Override
public String getUser() {
HttpSession httpSession = this.getThreadLocalRequest().getSession();
ASLSession session = WsUtil.getAslSession(httpSession);
return session.getUsername();
}
}

View File

@ -8,13 +8,12 @@ public class UserBean implements Serializable {
private String firstName;
private String lastName;
private String email;
private boolean cataloguePermission;
public UserBean(String username, String firstName, String lastName,
String email) {
String email, boolean cataloguePermission) {
super();
this.cataloguePermission = cataloguePermission;
this.username = username;
this.firstName = firstName;
this.lastName = lastName;
@ -46,7 +45,17 @@ public class UserBean implements Serializable {
public void setEmail(String email) {
this.email = email;
}
public boolean hasCataloguePermission() {
return cataloguePermission;
}
public void setCataloguePermission(boolean cataloguePermission) {
this.cataloguePermission = cataloguePermission;
}
@Override
public String toString() {
return "UserBean [username=" + username + ", firstName=" + firstName
+ ", lastName=" + lastName + ", email=" + email
+ ", cataloguePermission=" + cataloguePermission + "]";
}
}