From eea656ff8f16c3b2dd2dfa4e40ba21baf5997e61 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 3 Dec 2021 14:20:55 +0100 Subject: [PATCH] Fixed #19786. Moved to 1.4.0-SNAPSHOT --- .classpath | 6 +- .../com.gwtplugins.gdt.eclipse.core.prefs | 2 +- .settings/org.eclipse.wst.common.component | 32 ++- CHANGELOG.md | 4 + pom.xml | 4 +- .../WorkspaceResourcesExplorerPanel.java | 257 +++++++++++------- .../client/event/DownloadItemEvent.java | 28 +- .../client/grid/MenuMoreOptionsOnItem.java | 6 +- .../rpc/WorkspaceExplorerAppService.java | 32 ++- .../rpc/WorkspaceExplorerAppServiceAsync.java | 19 +- .../client/view/PopupContextMenu.java | 4 +- .../WorkspaceExplorerAppServiceImpl.java | 31 +++ .../server/workspace/ItemBuilder.java | 2 + .../server/workspace/WsInstanceUtil.java | 73 ++++- src/test/java/TestFolderIDDecrypt.java | 19 -- .../WorkspaceExplorerAppTests.java | 6 + 16 files changed, 356 insertions(+), 169 deletions(-) delete mode 100644 src/test/java/TestFolderIDDecrypt.java create mode 100644 src/test/java/org/gcube/portlets/user/workspaceexplorerapp/WorkspaceExplorerAppTests.java diff --git a/.classpath b/.classpath index 25b76d4..7be9cd5 100644 --- a/.classpath +++ b/.classpath @@ -1,12 +1,12 @@ - + - + @@ -35,5 +35,5 @@ - + diff --git a/.settings/com.gwtplugins.gdt.eclipse.core.prefs b/.settings/com.gwtplugins.gdt.eclipse.core.prefs index f4c7db0..1d3439d 100644 --- a/.settings/com.gwtplugins.gdt.eclipse.core.prefs +++ b/.settings/com.gwtplugins.gdt.eclipse.core.prefs @@ -1,6 +1,6 @@ eclipse.preferences.version=1 jarsExcludedFromWebInfLib= -lastWarOutDir=/home/francesco-mangiacrapa/git/workspace-explorer-app/target/workspace-explorer-app-1.3.1 +lastWarOutDir=/home/francescomangiacrapa/git/workspace-explorer-app/target/workspace-explorer-app-1.3.2-SNAPSHOT launchConfigExternalUrlPrefix= warSrcDir=src/main/webapp warSrcDirIsOutput=false diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index d36c6a2..cfc9f1d 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,10 +1,40 @@ - + + + + + + + + + + + + + + + + + + uses + + + + + + + + + + + + + diff --git a/CHANGELOG.md b/CHANGELOG.md index 206ca38..a4fe9e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [v1.4.0-SNAPSHOT] - 2021-12-03 + +[#19786] Integrated items of type "URL" + ## [v1.3.1] - 2020-09-25 [#19317] Just to include the storagehub-client-wrapper at 1.0.0 version diff --git a/pom.xml b/pom.xml index c139342..e3e55cf 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ org.gcube.portlets.user workspace-explorer-app - 1.3.1 + 1.4.0-SNAPSHOT war @@ -121,7 +121,7 @@ [1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT) compile - + org.gcube.core common-encryption diff --git a/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/client/WorkspaceResourcesExplorerPanel.java b/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/client/WorkspaceResourcesExplorerPanel.java index 4d30a65..d367d84 100644 --- a/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/client/WorkspaceResourcesExplorerPanel.java +++ b/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/client/WorkspaceResourcesExplorerPanel.java @@ -30,7 +30,6 @@ import org.gcube.portlets.user.workspaceexplorerapp.client.view.WorkspaceExplore import org.gcube.portlets.user.workspaceexplorerapp.shared.Item; import org.gcube.portlets.user.workspaceexplorerapp.shared.ItemType; -import com.github.gwtbootstrap.client.ui.constants.AlertType; import com.google.gwt.core.shared.GWT; import com.google.gwt.event.shared.HandlerManager; import com.google.gwt.http.client.RequestBuilder; @@ -46,49 +45,51 @@ import gwt.material.design.client.ui.MaterialToast; /** * The Class WorkspaceResourcesExplorerPanel. * - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Dec 3, 2015 + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Dec 3, 2021 */ -public class WorkspaceResourcesExplorerPanel extends DockPanel implements HasWorskpaceExplorerSelectNotificationListener{ +public class WorkspaceResourcesExplorerPanel extends DockPanel + implements HasWorskpaceExplorerSelectNotificationListener { public HandlerManager eventBus; private Breadcrumbs breadcrumbs; private boolean isSelect = false; private String captionTxt; -// private WorkspaceExplorerController controller; private List listeners = new ArrayList(); private VerticalPanel mainVP = new VerticalPanel(); -// private HorizontalPanel footerHP = new HorizontalPanel(); private WorkspaceExplorer wsExplorer; private ScrollPanel centerScrollable = new ScrollPanel(); -// private ScrollPanel southPanel = new ScrollPanel(); private String folderName; private Item baseFolder; - public static final DisplayField[] displayFields = new DisplayField[]{DisplayField.ICON, DisplayField.NAME, DisplayField.OWNER, DisplayField.CREATION_DATE}; + public static final DisplayField[] displayFields = new DisplayField[] { DisplayField.ICON, DisplayField.NAME, + DisplayField.OWNER, DisplayField.CREATION_DATE }; /** * Instantiates a new workspace folder explorer select panel. * - * @param eventBus the event bus - * @param folderId the folder id like root folder to explore + * @param eventBus the event bus + * @param folderId the folder id like root folder to explore * @param folderName the folder name * @throws Exception the exception */ - public WorkspaceResourcesExplorerPanel(HandlerManager eventBus, String folderId, String folderName) throws Exception { + public WorkspaceResourcesExplorerPanel(HandlerManager eventBus, String folderId, String folderName) + throws Exception { initExplorer(eventBus, folderId, folderName, ItemType.values(), ItemType.values()); } /** * Inits the explorer. * - * @param eventBus the event bus - * @param folderId the folder id - * @param folderName the folder name + * @param eventBus the event bus + * @param folderId the folder id + * @param folderName the folder name * @param selectableTypes the selectable types - * @param showableTypes the showable types + * @param showableTypes the showable types * @throws Exception the exception */ - private void initExplorer(HandlerManager eventBus, String folderId, String folderName, ItemType[] selectableTypes, ItemType[] showableTypes) throws Exception{ + private void initExplorer(HandlerManager eventBus, String folderId, String folderName, ItemType[] selectableTypes, + ItemType[] showableTypes) throws Exception { this.folderName = folderName; this.eventBus = eventBus; this.breadcrumbs = new Breadcrumbs(eventBus); @@ -98,7 +99,7 @@ public class WorkspaceResourcesExplorerPanel extends DockPanel implements HasWor Item item = new Item(folderId, folderName, true); this.baseFolder = item; wsExplorer.setBaseFolder(item); - if(folderId!=null && !folderId.isEmpty()) + if (folderId != null && !folderId.isEmpty()) wsExplorer.loadFolder(item); initPanel(""); } @@ -106,26 +107,27 @@ public class WorkspaceResourcesExplorerPanel extends DockPanel implements HasWor /** * Instantiates a new workspace explorer select panel. * - * @param folderId the folder id + * @param eventBus the event bus + * @param folderId the folder id * @param showOnlyFolders the show only folders * @throws Exception the exception */ - public WorkspaceResourcesExplorerPanel(HandlerManager eventBus, String folderId, boolean showOnlyFolders) throws Exception { + public WorkspaceResourcesExplorerPanel(HandlerManager eventBus, String folderId, boolean showOnlyFolders) + throws Exception { - if(showOnlyFolders){ + if (showOnlyFolders) { ItemType[] itemsType = new ItemType[1]; itemsType[0] = ItemType.FOLDER; initExplorer(eventBus, folderId, "", itemsType, itemsType); - }else{ + } else { initExplorer(eventBus, folderId, "", ItemType.values(), ItemType.values()); } } - /** * Bind events. */ - private void bindEvents(){ + private void bindEvents() { eventBus.addHandler(ClickItemEvent.TYPE, new ClickItemEventHandler() { @@ -150,12 +152,12 @@ public class WorkspaceResourcesExplorerPanel extends DockPanel implements HasWor @Override public void onLoadFolder(LoadFolderEvent loadFolderEvent) { - + GWT.log("LoadFolderEvent fired"); - Item item = loadFolderEvent.getTargetFolder()==null?baseFolder:loadFolderEvent.getTargetFolder(); + Item item = loadFolderEvent.getTargetFolder() == null ? baseFolder : loadFolderEvent.getTargetFolder(); - if(item.isFolder()){ + if (item.isFolder()) { try { wsExplorer.loadFolder(item); loadParentBreadcrumbByItemId(item.getId(), true); @@ -171,7 +173,7 @@ public class WorkspaceResourcesExplorerPanel extends DockPanel implements HasWor @Override public void onBreadcrumbClick(BreadcrumbClickEvent breadcrumbClickEvent) { - if(breadcrumbClickEvent.getTargetItem()!=null) + if (breadcrumbClickEvent.getTargetItem() != null) eventBus.fireEvent(new LoadFolderEvent(breadcrumbClickEvent.getTargetItem())); } }); @@ -182,22 +184,19 @@ public class WorkspaceResourcesExplorerPanel extends DockPanel implements HasWor public void onOrderDataBy(OrderDataByEvent orderDataByEvent) { wsExplorer.getItTables().sortDataBy(orderDataByEvent.getLabel()); - - /*ArrayList items = ItemComparatorUtility.sortItems(DisplayField.NAME, true, wsExplorer.getItTables().getDataProvider().getList()); - wsExplorer.updateExplorer(items);*/ } }); - eventBus.addHandler(RightClickItemEvent.TYPE, new RightClickItemEventHandler() { @Override public void onClick(RightClickItemEvent rightClickItemEvent) { - if(rightClickItemEvent.getItem()!=null && rightClickItemEvent.getItem().getId()!=null){ + if (rightClickItemEvent.getItem() != null && rightClickItemEvent.getItem().getId() != null) { PopupContextMenu popupCM = new PopupContextMenu(true, eventBus, rightClickItemEvent.getItem()); - popupCM.showPopup(rightClickItemEvent.getXPos(), Window.getScrollTop()+rightClickItemEvent.getYPos()); + popupCM.showPopup(rightClickItemEvent.getXPos(), + Window.getScrollTop() + rightClickItemEvent.getYPos()); } } }); @@ -208,24 +207,27 @@ public class WorkspaceResourcesExplorerPanel extends DockPanel implements HasWor public void onDownloadItem(DownloadItemEvent downloadItemEvent) { GWT.log("Fired event DownloadItemEvent"); String itemIds = ""; - if(downloadItemEvent.getItem()!=null) - itemIds = downloadItemEvent.getItem().getId()+WorkspaceExplorerAppConstants.IDS_SEPARATOR; - else{ + if (downloadItemEvent.getItem() != null) + itemIds = downloadItemEvent.getItem().getId() + WorkspaceExplorerAppConstants.IDS_SEPARATOR; + else { List lstItems = toList(wsExplorer.getItemsSelected()); for (Item item : lstItems) { - itemIds +=item.getId()+WorkspaceExplorerAppConstants.IDS_SEPARATOR; + itemIds += item.getId() + WorkspaceExplorerAppConstants.IDS_SEPARATOR; } } - GWT.log("itemIds: "+itemIds); - if(!itemIds.isEmpty()){ + GWT.log("itemIds: " + itemIds); + if (!itemIds.isEmpty()) { // MaterialToast.fireToast("Download..."); switch (downloadItemEvent.getType()) { case DOWNLOAD: MaterialToast.fireToast("Download..."); try { - new RequestBuilderWorkspaceValidateItem(RequestBuilder.GET,WorkspaceExplorerAppConstants.DOWNLOAD_WORKSPACE_SERVICE, WorkspaceExplorerAppConstants.IDS+"="+itemIds, "_self", downloadHandlerCallback); + new RequestBuilderWorkspaceValidateItem(RequestBuilder.GET, + WorkspaceExplorerAppConstants.DOWNLOAD_WORKSPACE_SERVICE, + WorkspaceExplorerAppConstants.IDS + "=" + itemIds, "_self", + downloadHandlerCallback); } catch (Exception e) { Window.alert("Sorry, an error occurred while contacting server, try again"); } @@ -234,8 +236,45 @@ public class WorkspaceResourcesExplorerPanel extends DockPanel implements HasWor // break; case OPEN: MaterialToast.fireToast("Showing..."); + + if (downloadItemEvent.getItem().getType().equals(ItemType.URL_DOCUMENT)) { + + final NewBrowserWindow newBrowserWindow = NewBrowserWindow.open("", "_blank", ""); + + final String theItemIds = itemIds; + + WorkspaceExplorerAppConstants.workspaceNavigatorService + .getUrlById(downloadItemEvent.getItem().getId(), new AsyncCallback() { + + @Override + public void onSuccess(String result) { + newBrowserWindow.setUrl(result); + + } + + @Override + public void onFailure(Throwable caught) { + try { + new RequestBuilderWorkspaceValidateItem(RequestBuilder.GET, + WorkspaceExplorerAppConstants.DOWNLOAD_WORKSPACE_SERVICE, + WorkspaceExplorerAppConstants.IDS + "=" + theItemIds + + "&viewContent=true", + "_blank", downloadHandlerCallback); + } catch (Exception e) { + Window.alert( + "Sorry, an error occurred while contacting server, try again"); + } + } + }); + + return; + } + try { - new RequestBuilderWorkspaceValidateItem(RequestBuilder.GET, WorkspaceExplorerAppConstants.DOWNLOAD_WORKSPACE_SERVICE, WorkspaceExplorerAppConstants.IDS+"="+itemIds+"&viewContent=true", "_blank", downloadHandlerCallback); + new RequestBuilderWorkspaceValidateItem(RequestBuilder.GET, + WorkspaceExplorerAppConstants.DOWNLOAD_WORKSPACE_SERVICE, + WorkspaceExplorerAppConstants.IDS + "=" + itemIds + "&viewContent=true", "_blank", + downloadHandlerCallback); } catch (Exception e) { Window.alert("Sorry, an error occurred while contacting server, try again"); @@ -249,64 +288,61 @@ public class WorkspaceResourcesExplorerPanel extends DockPanel implements HasWor }); } - /** * To list. * * @param items the items * @return the list */ - private List toList(Set items){ - if(items!=null && items.size()>0){ - List lstItems = new ArrayList (items.size()); + private List toList(Set items) { + if (items != null && items.size() > 0) { + List lstItems = new ArrayList(items.size()); lstItems.addAll(items); return lstItems; } return null; } - /** * Load parent breadcrumb by item id. * - * @param itemIdentifier the item identifier + * @param itemIdentifier the item identifier * @param includeItemAsParent the include item as parent */ - protected void loadParentBreadcrumbByItemId(final String itemIdentifier, boolean includeItemAsParent){ + protected void loadParentBreadcrumbByItemId(final String itemIdentifier, boolean includeItemAsParent) { - GWT.log("Reload Parent Breadcrumb: [Item id: "+itemIdentifier+"]"); + GWT.log("Reload Parent Breadcrumb: [Item id: " + itemIdentifier + "]"); - WorkspaceExplorerAppConstants.workspaceNavigatorService.getBreadcrumbsByItemIdentifierToParentLimit(itemIdentifier, baseFolder.getId(), includeItemAsParent, new AsyncCallback>() { + WorkspaceExplorerAppConstants.workspaceNavigatorService.getBreadcrumbsByItemIdentifierToParentLimit( + itemIdentifier, baseFolder.getId(), includeItemAsParent, new AsyncCallback>() { - @Override - public void onFailure(Throwable caught) { - GWT.log(caught.getMessage()); - Item goToBaseFolder = null; - //I'm adding go to folder only if is a sub-folder of baseFolder - if(itemIdentifier!=baseFolder.getId()) - goToBaseFolder = baseFolder; - - //wsExplorer.setAlert(caught.getMessage(), AlertType.ERROR, goToBaseFolder); - } + @Override + public void onFailure(Throwable caught) { + GWT.log(caught.getMessage()); + Item goToBaseFolder = null; + // I'm adding go to folder only if is a sub-folder of baseFolder + if (itemIdentifier != baseFolder.getId()) + goToBaseFolder = baseFolder; - @Override - public void onSuccess(List result) { - if(result!=null){ - breadcrumbs.setPath(result); -// clearMoreInfo(); - } - } - }); + // wsExplorer.setAlert(caught.getMessage(), AlertType.ERROR, goToBaseFolder); + } + + @Override + public void onSuccess(List result) { + if (result != null) { + breadcrumbs.setPath(result); + } + } + }); } /** * Refresh root folder view. */ - public void refreshRootFolderView(){ - //Item item = new Item(baseFolder.getId(), folderName, true); + public void refreshRootFolderView() { + // Item item = new Item(baseFolder.getId(), folderName, true); eventBus.fireEvent(new LoadFolderEvent(baseFolder)); } - /** * Inits the panel. @@ -319,14 +355,14 @@ public class WorkspaceResourcesExplorerPanel extends DockPanel implements HasWor this.getElement().setAttribute("id", "WorkspaceExplorerContainer"); this.getElement().addClassName("workspace-explorer-container"); - if(this.captionTxt!=null && !this.captionTxt.isEmpty()) + if (this.captionTxt != null && !this.captionTxt.isEmpty()) setTitle(this.captionTxt); - setWidth("100%"); - add(breadcrumbs, DockPanel.NORTH); + setWidth("100%"); + add(breadcrumbs, DockPanel.NORTH); mainVP.add(wsExplorer.getPanel()); - centerScrollable.add(mainVP); - add(centerScrollable, DockPanel.CENTER); + centerScrollable.add(mainVP); + add(centerScrollable, DockPanel.CENTER); } /** @@ -334,7 +370,7 @@ public class WorkspaceResourcesExplorerPanel extends DockPanel implements HasWor * * @param selected the selected */ - private void notifySelectedItem(Item selected){ + private void notifySelectedItem(Item selected) { for (WorskpaceExplorerSelectNotificationListener worskpaceExplorerNotificationListener : listeners) { worskpaceExplorerNotificationListener.onSelectedItem(selected); @@ -344,18 +380,17 @@ public class WorkspaceResourcesExplorerPanel extends DockPanel implements HasWor /** * Notify aborted. */ - private void notifyAborted(){ + private void notifyAborted() { for (WorskpaceExplorerSelectNotificationListener worskpaceExplorerNotificationListener : listeners) { worskpaceExplorerNotificationListener.onAborted(); } } - /** * Notify not valid selection. */ - private void notifyNotValidSelection(){ + private void notifyNotValidSelection() { for (WorskpaceExplorerSelectNotificationListener worskpaceExplorerNotificationListener : listeners) { worskpaceExplorerNotificationListener.onNotValidSelection(); @@ -368,7 +403,7 @@ public class WorkspaceResourcesExplorerPanel extends DockPanel implements HasWor * @param t the t */ @SuppressWarnings("unused") - private void notifyFailed(Throwable t){ + private void notifyFailed(Throwable t) { for (WorskpaceExplorerSelectNotificationListener worskpaceExplorerNotificationListener : listeners) { worskpaceExplorerNotificationListener.onFailed(t); @@ -393,22 +428,44 @@ public class WorkspaceResourcesExplorerPanel extends DockPanel implements HasWor return isSelect; } - /* (non-Javadoc) - * @see org.gcube.portlets.widgets.wsexplorer.client.notification.WorskpaceExplorerNotification.HasWorskpaceExplorerNotificationListener#addWorkspaceExplorerNotificationListener(org.gcube.portlets.widgets.wsexplorer.client.notification.WorskpaceExplorerNotification.WorskpaceExplorerNotificationListener) + /** + * Adds the workspace explorer select notification listener. + * + * @param handler the handler + */ + /* + * (non-Javadoc) + * + * @see org.gcube.portlets.widgets.wsexplorer.client.notification. + * WorskpaceExplorerNotification.HasWorskpaceExplorerNotificationListener# + * addWorkspaceExplorerNotificationListener(org.gcube.portlets.widgets. + * wsexplorer.client.notification.WorskpaceExplorerNotification. + * WorskpaceExplorerNotificationListener) */ @Override public void addWorkspaceExplorerSelectNotificationListener(WorskpaceExplorerSelectNotificationListener handler) { - if(handler!=null) + if (handler != null) listeners.add(handler); } - /* (non-Javadoc) - * @see org.gcube.portlets.widgets.wsexplorer.client.notification.WorskpaceExplorerNotification.HasWorskpaceExplorerNotificationListener#removeWorkspaceExplorerNotificationListener(org.gcube.portlets.widgets.wsexplorer.client.notification.WorskpaceExplorerNotification.WorskpaceExplorerNotificationListener) + /** + * Removes the workspace explorer select notification listener. + * + * @param handler the handler + */ + /* + * (non-Javadoc) + * + * @see org.gcube.portlets.widgets.wsexplorer.client.notification. + * WorskpaceExplorerNotification.HasWorskpaceExplorerNotificationListener# + * removeWorkspaceExplorerNotificationListener(org.gcube.portlets.widgets. + * wsexplorer.client.notification.WorskpaceExplorerNotification. + * WorskpaceExplorerNotificationListener) */ @Override public void removeWorkspaceExplorerSelectNotificationListener(WorskpaceExplorerSelectNotificationListener handler) { - if(handler!=null){ - if(listeners.contains(handler)) + if (handler != null) { + if (listeners.contains(handler)) listeners.remove(handler); } } @@ -419,18 +476,19 @@ public class WorkspaceResourcesExplorerPanel extends DockPanel implements HasWor * @param item the item * @return true, if successful */ - public boolean itemIsSelectable(Item item){ - GWT.log("Selectable type: "+wsExplorer.getSelectableTypes()); - GWT.log("item: "+item); - if (item!=null){ + public boolean itemIsSelectable(Item item) { + GWT.log("Selectable type: " + wsExplorer.getSelectableTypes()); + GWT.log("item: " + item); + if (item != null) { boolean selectable = wsExplorer.getSelectableTypes().contains(item.getType()); - return selectable?true:false; + return selectable ? true : false; } return false; } - /** + * Gets the ws explorer. + * * @return the wsExplorer */ public WorkspaceExplorer getWsExplorer() { @@ -456,11 +514,12 @@ public class WorkspaceResourcesExplorerPanel extends DockPanel implements HasWor @Override public void onSuccess(WindowOpenParameter windowOpenParam) { - String params = "?"+windowOpenParam.getParameters(); - if(params.length()>1) - params+="&"; - params+=WorkspaceExplorerAppConstants.REDIRECTONERROR+"="+windowOpenParam.isRedirectOnError(); - windowOpenParam.getBrowserWindow().setUrl(WorkspaceExplorerAppConstants.DOWNLOAD_WORKSPACE_SERVICE+params); + String params = "?" + windowOpenParam.getParameters(); + if (params.length() > 1) + params += "&"; + params += WorkspaceExplorerAppConstants.REDIRECTONERROR + "=" + windowOpenParam.isRedirectOnError(); + windowOpenParam.getBrowserWindow() + .setUrl(WorkspaceExplorerAppConstants.DOWNLOAD_WORKSPACE_SERVICE + params); } }; } diff --git a/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/client/event/DownloadItemEvent.java b/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/client/event/DownloadItemEvent.java index 9a63a03..b433825 100644 --- a/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/client/event/DownloadItemEvent.java +++ b/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/client/event/DownloadItemEvent.java @@ -1,29 +1,27 @@ package org.gcube.portlets.user.workspaceexplorerapp.client.event; import org.gcube.portlets.user.workspaceexplorerapp.client.download.DownloadType; -import org.gcube.portlets.user.workspaceexplorerapp.shared.ItemInterface; +import org.gcube.portlets.user.workspaceexplorerapp.shared.Item; import com.google.gwt.event.shared.GwtEvent; - /** * The Class ClickItemEvent. * - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Jul 6, 2015 + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Jul 6, 2015 */ public class DownloadItemEvent extends GwtEvent { public static Type TYPE = new Type(); - private ItemInterface item; + private Item item; private DownloadType type; /** * Instantiates a new click item event. * * @param itemDownload the item download - * @param type the type + * @param type the type */ - public DownloadItemEvent(ItemInterface itemDownload, DownloadType type) { + public DownloadItemEvent(Item itemDownload, DownloadType type) { this.item = itemDownload; this.type = type; } @@ -36,7 +34,9 @@ public class DownloadItemEvent extends GwtEvent { return type; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see com.google.gwt.event.shared.GwtEvent#getAssociatedType() */ @Override @@ -44,8 +44,12 @@ public class DownloadItemEvent extends GwtEvent { return TYPE; } - /* (non-Javadoc) - * @see com.google.gwt.event.shared.GwtEvent#dispatch(com.google.gwt.event.shared.EventHandler) + /* + * (non-Javadoc) + * + * @see + * com.google.gwt.event.shared.GwtEvent#dispatch(com.google.gwt.event.shared. + * EventHandler) */ @Override protected void dispatch(DownloadItemEventHandler handler) { @@ -54,10 +58,10 @@ public class DownloadItemEvent extends GwtEvent { /** * Gets the item. - * + * * @return the item */ - public ItemInterface getItem() { + public Item getItem() { return item; } } diff --git a/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/client/grid/MenuMoreOptionsOnItem.java b/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/client/grid/MenuMoreOptionsOnItem.java index cbbd32e..ea08a49 100644 --- a/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/client/grid/MenuMoreOptionsOnItem.java +++ b/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/client/grid/MenuMoreOptionsOnItem.java @@ -5,7 +5,7 @@ package org.gcube.portlets.user.workspaceexplorerapp.client.grid; import org.gcube.portlets.user.workspaceexplorerapp.client.download.DownloadType; import org.gcube.portlets.user.workspaceexplorerapp.client.event.DownloadItemEvent; -import org.gcube.portlets.user.workspaceexplorerapp.shared.ItemInterface; +import org.gcube.portlets.user.workspaceexplorerapp.shared.Item; import com.google.gwt.core.client.GWT; import com.google.gwt.event.dom.client.ClickEvent; @@ -42,7 +42,7 @@ public class MenuMoreOptionsOnItem extends Composite { private HandlerManager eventBus; - private ItemInterface itemToDownload; + private Item itemToDownload; private Command commandOnClick; @@ -86,7 +86,7 @@ public class MenuMoreOptionsOnItem extends Composite { * @param itemToDownload the item to download * @param commandOnClick the command on click */ - public void initOnItem(ItemInterface itemToDownload, Command commandOnClick){ + public void initOnItem(Item itemToDownload, Command commandOnClick){ this.itemToDownload = itemToDownload; this.commandOnClick = commandOnClick; } diff --git a/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/client/rpc/WorkspaceExplorerAppService.java b/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/client/rpc/WorkspaceExplorerAppService.java index 2438e4d..4727587 100644 --- a/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/client/rpc/WorkspaceExplorerAppService.java +++ b/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/client/rpc/WorkspaceExplorerAppService.java @@ -21,11 +21,18 @@ public interface WorkspaceExplorerAppService extends RemoteService { /** * Gets the folder. * - * @param folder the folder @param showableTypes the showable types @param - * purgeEmpyFolders the purge empy folders @param filterCriteria - * the filter criteria @return the folder @throws - * WorkspaceNavigatorServiceException the workspace navigator - * service exception @throws + * @param folder the folder @param showableTypes the showable + * types @param purgeEmpyFolders the purge empy + * folders @param filterCriteria the filter + * criteria @return the folder @throws + * WorkspaceNavigatorServiceException the workspace + * navigator service exception @throws + * @param showableTypes the showable types + * @param purgeEmpyFolders the purge empy folders + * @param filterCriteria the filter criteria + * @return the folder + * @throws WorkspaceNavigatorServiceException the workspace navigator service + * exception */ Item getFolder(Item folder, List showableTypes, boolean purgeEmpyFolders, FilterCriteria filterCriteria) throws WorkspaceNavigatorServiceException; @@ -71,12 +78,12 @@ public interface WorkspaceExplorerAppService extends RemoteService { /** * Gets the breadcrumbs by item identifier. * - * @param itemIdentifier the item identifier - * @param includeItemAsParent the include item as parent + * @param itemId the item id * @return the breadcrumbs by item identifier * @throws Exception the exception */ - //List getBreadcrumbsByItemIdentifier(String itemIdentifier, boolean includeItemAsParent) throws Exception; + // List getBreadcrumbsByItemIdentifier(String itemIdentifier, boolean + // includeItemAsParent) throws Exception; /** * Gets the public link for item id. @@ -96,4 +103,13 @@ public interface WorkspaceExplorerAppService extends RemoteService { */ String getFolderIdFromEncrypted(String encryptedFolderId) throws Exception; + /** + * Gets the url by id. + * + * @param itemId the item id + * @return the url by id + * @throws Exception the exception + */ + String getUrlById(String itemId) throws Exception; + } diff --git a/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/client/rpc/WorkspaceExplorerAppServiceAsync.java b/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/client/rpc/WorkspaceExplorerAppServiceAsync.java index 47c860f..7d250f3 100644 --- a/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/client/rpc/WorkspaceExplorerAppServiceAsync.java +++ b/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/client/rpc/WorkspaceExplorerAppServiceAsync.java @@ -64,12 +64,14 @@ public interface WorkspaceExplorerAppServiceAsync { /** * Gets the breadcrumbs by item identifier. * - * @param itemIdentifier the item identifier - * @param includeItemAsParent the include item as parent - * @param asyncCallback the async callback + * @param showableTypes the showable types + * @param purgeEmpyFolders the purge empy folders + * @param filterCriteria the filter criteria + * @param asyncCallback the async callback * @return the breadcrumbs by item identifier */ - //public void getBreadcrumbsByItemIdentifier(String itemIdentifier, boolean includeItemAsParent, AsyncCallback> asyncCallback); + // public void getBreadcrumbsByItemIdentifier(String itemIdentifier, boolean + // includeItemAsParent, AsyncCallback> asyncCallback); /** * Gets the my special folder. @@ -95,4 +97,13 @@ public interface WorkspaceExplorerAppServiceAsync { void getBreadcrumbsByItemIdentifierToParentLimit(String itemIdentifier, String parentLimit, boolean includeItemAsParent, AsyncCallback> callback); + /** + * Gets the url by id. + * + * @param itemId the item id + * @param callback the callback + * @return the url by id + */ + void getUrlById(String itemId, AsyncCallback callback); + } diff --git a/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/client/view/PopupContextMenu.java b/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/client/view/PopupContextMenu.java index db52470..b2bfec9 100644 --- a/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/client/view/PopupContextMenu.java +++ b/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/client/view/PopupContextMenu.java @@ -4,7 +4,7 @@ package org.gcube.portlets.user.workspaceexplorerapp.client.view; import org.gcube.portlets.user.workspaceexplorerapp.client.grid.MenuMoreOptionsOnItem; -import org.gcube.portlets.user.workspaceexplorerapp.shared.ItemInterface; +import org.gcube.portlets.user.workspaceexplorerapp.shared.Item; import com.google.gwt.core.shared.GWT; import com.google.gwt.event.shared.HandlerManager; @@ -30,7 +30,7 @@ public class PopupContextMenu extends PopupPanel{ * @param eventBus the event bus * @param itemToDownload the item to download */ - public PopupContextMenu(boolean autohide, HandlerManager eventBus, ItemInterface itemToDownload) { + public PopupContextMenu(boolean autohide, HandlerManager eventBus, Item itemToDownload) { super(autohide); GWT.log("PopupContextMenu opened"); menuOpts = new MenuMoreOptionsOnItem(eventBus); diff --git a/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/server/WorkspaceExplorerAppServiceImpl.java b/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/server/WorkspaceExplorerAppServiceImpl.java index 62cf24a..2957e08 100644 --- a/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/server/WorkspaceExplorerAppServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/server/WorkspaceExplorerAppServiceImpl.java @@ -15,6 +15,8 @@ import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder; import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem; import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItemType; import org.gcube.common.storagehubwrapper.shared.tohl.items.FileItem; +import org.gcube.common.storagehubwrapper.shared.tohl.items.URLFileItem; +import org.gcube.common.storagehubwrapper.shared.tohl.items.URLItem; import org.gcube.portlets.user.workspaceexplorerapp.client.WorkspaceExplorerAppConstants; import org.gcube.portlets.user.workspaceexplorerapp.client.rpc.WorkspaceExplorerAppService; import org.gcube.portlets.user.workspaceexplorerapp.server.workspace.ItemBuilder; @@ -461,5 +463,34 @@ public class WorkspaceExplorerAppServiceImpl extends RemoteServiceServlet implem throw new Exception("Sorry, an error occurred when decrypting the folder id. Try again or contact the support"); } } + + @Override + public String getUrlById(String itemId) throws Exception { + + try { + + if (itemId == null) + throw new Exception("Workspace itemId is null"); + + logger.debug("get URL by id: " + itemId); + Workspace workspace = getWorkspace(); + WorkspaceItem wsItem = workspace.getItemForExplorer(itemId, false, false, false); + // workspace + + if (wsItem instanceof org.gcube.common.storagehubwrapper.shared.tohl.impl.URLFileItem) { + URLFileItem fileItem = (URLFileItem) wsItem; + return WsInstanceUtil.getUrl(workspace, fileItem); + } else if (wsItem instanceof URLItem) { + URLItem urlFile = (URLItem) wsItem; + return urlFile.getValue().toString(); + } else { + throw new Exception("The itemId " + itemId + " is not a URLFileItem or a URLItem"); + } + + } catch (Exception e) { + logger.error("Error occurred in getUrlById: ", e); + throw new Exception(e.getMessage()); + } + } } diff --git a/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/server/workspace/ItemBuilder.java b/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/server/workspace/ItemBuilder.java index 896dd5d..d317e26 100644 --- a/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/server/workspace/ItemBuilder.java +++ b/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/server/workspace/ItemBuilder.java @@ -223,6 +223,8 @@ public class ItemBuilder { else return ItemType.UNKNOWN_TYPE; + case URL_ITEM: + return ItemType.URL_DOCUMENT; default: return null; diff --git a/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/server/workspace/WsInstanceUtil.java b/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/server/workspace/WsInstanceUtil.java index 3e4dca9..86a6274 100644 --- a/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/server/workspace/WsInstanceUtil.java +++ b/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/server/workspace/WsInstanceUtil.java @@ -3,18 +3,24 @@ */ package org.gcube.portlets.user.workspaceexplorerapp.server.workspace; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; + import javax.servlet.http.HttpSession; import org.gcube.common.storagehubwrapper.server.StorageHubWrapper; +import org.gcube.common.storagehubwrapper.server.tohl.Workspace; +import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.InternalErrorException; +import org.gcube.common.storagehubwrapper.shared.tohl.items.URLFileItem; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - /** * The Class WsUtil. * - * @author Francesco Mangiacrapa at ISTI-CNR Pisa (Italy) - * Apr 9, 2020 + * @author Francesco Mangiacrapa at ISTI-CNR Pisa (Italy) Apr 9, 2020 */ public class WsInstanceUtil { @@ -35,18 +41,18 @@ public class WsInstanceUtil { try { String scope = getScope(httpSession); String applicationToken = getApplicationToken(httpSession); - - if(applicationToken==null || applicationToken.isEmpty()) { + + if (applicationToken == null || applicationToken.isEmpty()) { throw new Exception("No Application Token found. Impossible to istance the SHUB"); } - + return new StorageHubWrapper(scope, applicationToken, false, false, false); } catch (Exception e) { logger.error("Error when instancing the storageHub wrapper", e); throw new Exception("Error on inizializing the StorageHub wrapper. Please contact the support!"); } } - + /** * Gets the workpace. * @@ -54,7 +60,8 @@ public class WsInstanceUtil { * @return the workpace * @throws Exception the exception */ - public static org.gcube.common.storagehubwrapper.server.tohl.Workspace getWorkspace(HttpSession httpSession) throws Exception { + public static org.gcube.common.storagehubwrapper.server.tohl.Workspace getWorkspace(HttpSession httpSession) + throws Exception { try { StorageHubWrapper wrapper = getStorageHubWrapper(httpSession); @@ -89,7 +96,6 @@ public class WsInstanceUtil { return scope; } - /** * Gets the application token. * @@ -102,17 +108,54 @@ public class WsInstanceUtil { String appTokenEnvVarName = null; try { logger.info("Reading " + ENVIRONMENT_VARIABLE_TOKEN_NAME + " from web.xml context"); - appTokenEnvVarName = httpSession.getServletContext() - .getInitParameter(ENVIRONMENT_VARIABLE_TOKEN_NAME); + appTokenEnvVarName = httpSession.getServletContext().getInitParameter(ENVIRONMENT_VARIABLE_TOKEN_NAME); logger.info("Found param-value '" + appTokenEnvVarName + "' from web context, reading its value from ENVIRONMENT"); appToken = System.getenv(appTokenEnvVarName); logger.info("Value of " + appTokenEnvVarName + " from ENVIRONMENT is: " + appToken); - - }catch (Exception e) { - logger.error("Error on reading the ENV VARIABLE '"+appTokenEnvVarName+"' from ENVIRONMENT"); + + } catch (Exception e) { + logger.error("Error on reading the ENV VARIABLE '" + appTokenEnvVarName + "' from ENVIRONMENT"); } - + return appToken; } + + /** + * Gets the url. + * + * @param workspace the workspace + * @param fileItem the file item + * @return the url + * @throws Exception the exception + */ + public static String getUrl(Workspace workspace, URLFileItem fileItem) throws Exception { + try { + return readStreamAsString( + workspace.downloadFile(fileItem.getId(), fileItem.getName(), null, null).getStream()); + } catch (IOException e) { + logger.error("GET URL error for file: " + fileItem, e); + throw new InternalErrorException(e.getMessage()); + } + } + + /** + * Read the entire input stream as string. The system encoding is used. + * + * @param is the input stream. + * @return the read string. + * @throws IOException Signals that an I/O exception has occurred. + */ + public static String readStreamAsString(InputStream is) throws java.io.IOException { + StringBuilder sb = new StringBuilder(1000); + BufferedReader reader = new BufferedReader(new InputStreamReader(is)); + char[] buf = new char[1024]; + int numRead = 0; + while ((numRead = reader.read(buf)) != -1) { + sb.append(buf, 0, numRead); + } + reader.close(); + return sb.toString(); + } + } diff --git a/src/test/java/TestFolderIDDecrypt.java b/src/test/java/TestFolderIDDecrypt.java deleted file mode 100644 index 9c55452..0000000 --- a/src/test/java/TestFolderIDDecrypt.java +++ /dev/null @@ -1,19 +0,0 @@ - - -/** - * - */ -/** - * - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Sep 16, 2016 - */ -public class TestFolderIDDecrypt { - - - public static void main(String[] args) { - - - - } -} diff --git a/src/test/java/org/gcube/portlets/user/workspaceexplorerapp/WorkspaceExplorerAppTests.java b/src/test/java/org/gcube/portlets/user/workspaceexplorerapp/WorkspaceExplorerAppTests.java new file mode 100644 index 0000000..616b15a --- /dev/null +++ b/src/test/java/org/gcube/portlets/user/workspaceexplorerapp/WorkspaceExplorerAppTests.java @@ -0,0 +1,6 @@ +package org.gcube.portlets.user.workspaceexplorerapp; + +public class WorkspaceExplorerAppTests { + + +} -- 2.17.1