From 7280ed81388401e59063cee79f10cfd10666ff5c Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 9 Apr 2020 17:58:03 +0200 Subject: [PATCH] migrating to shub --- .../client/SortByContextMenu.java | 8 +- .../workspaceexplorerapp/client/Util.java | 14 +- .../client/WorkspaceExplorerAppMainPanel.java | 12 +- .../client/WorkspaceExplorerFoooterPanel.java | 4 +- .../WorkspaceResourcesExplorerPanel.java | 4 +- .../client/grid/ItemsTable.java | 14 +- .../client/grid/MaterialIconCell.java | 4 +- .../client/grid/MenuMoreOptionsOnItem.java | 4 +- .../rpc/WorkspaceExplorerAppService.java | 207 ++++--- .../rpc/WorkspaceExplorerAppServiceAsync.java | 281 +++++----- .../DownloadWorkspaceExplorerServlet.java | 13 +- .../WorkspaceExplorerAppServiceImpl.java | 503 ++++++++++-------- .../server/{ => workspace}/ItemBuilder.java | 80 ++- .../server/{ => workspace}/WsUtil.java | 11 +- 14 files changed, 605 insertions(+), 554 deletions(-) rename src/main/java/org/gcube/portlets/user/workspaceexplorerapp/server/{ => workspace}/ItemBuilder.java (84%) rename src/main/java/org/gcube/portlets/user/workspaceexplorerapp/server/{ => workspace}/WsUtil.java (85%) diff --git a/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/client/SortByContextMenu.java b/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/client/SortByContextMenu.java index 956642d..f88f619 100644 --- a/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/client/SortByContextMenu.java +++ b/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/client/SortByContextMenu.java @@ -3,10 +3,6 @@ */ package org.gcube.portlets.user.workspaceexplorerapp.client; -import gwt.material.design.client.ui.MaterialColumn; -import gwt.material.design.client.ui.MaterialLink; -import gwt.material.design.client.ui.MaterialRow; - import java.util.List; import org.gcube.portlets.user.workspaceexplorerapp.client.event.OrderDataByEvent; @@ -17,6 +13,10 @@ import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.shared.HandlerManager; import com.google.gwt.user.client.ui.PopupPanel; +import gwt.material.design.client.ui.MaterialColumn; +import gwt.material.design.client.ui.MaterialLink; +import gwt.material.design.client.ui.MaterialRow; + /** * diff --git a/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/client/Util.java b/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/client/Util.java index 52a19f4..85a18e0 100644 --- a/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/client/Util.java +++ b/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/client/Util.java @@ -81,13 +81,13 @@ public class Util { if (item.isSharedFolder()) return WorkspaceExplorerResources.INSTANCE.shared_folder(); else return WorkspaceExplorerResources.INSTANCE.folder(); } - case EXTERNAL_IMAGE: return WorkspaceLightTreeResources.INSTANCE.external_image(); - case EXTERNAL_FILE: return WorkspaceLightTreeResources.INSTANCE.external_file(); - case EXTERNAL_PDF_FILE: return WorkspaceLightTreeResources.INSTANCE.external_pdf(); - case EXTERNAL_URL: return WorkspaceLightTreeResources.INSTANCE.external_url(); - case REPORT_TEMPLATE: return WorkspaceLightTreeResources.INSTANCE.report_template(); - case REPORT: return WorkspaceLightTreeResources.INSTANCE.report(); - case QUERY: return WorkspaceLightTreeResources.INSTANCE.query(); +// case EXTERNAL_IMAGE: return WorkspaceLightTreeResources.INSTANCE.external_image(); +// case EXTERNAL_FILE: return WorkspaceLightTreeResources.INSTANCE.external_file(); +// case EXTERNAL_PDF_FILE: return WorkspaceLightTreeResources.INSTANCE.external_pdf(); +// case EXTERNAL_URL: return WorkspaceLightTreeResources.INSTANCE.external_url(); +// case REPORT_TEMPLATE: return WorkspaceLightTreeResources.INSTANCE.report_template(); +// case REPORT: return WorkspaceLightTreeResources.INSTANCE.report(); +// case QUERY: return WorkspaceLightTreeResources.INSTANCE.query(); case DOCUMENT: return WorkspaceLightTreeResources.INSTANCE.document(); case METADATA: return WorkspaceLightTreeResources.INSTANCE.metadata(); case PDF_DOCUMENT: return WorkspaceLightTreeResources.INSTANCE.pdf_document(); diff --git a/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/client/WorkspaceExplorerAppMainPanel.java b/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/client/WorkspaceExplorerAppMainPanel.java index 656184b..dd9b1a0 100644 --- a/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/client/WorkspaceExplorerAppMainPanel.java +++ b/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/client/WorkspaceExplorerAppMainPanel.java @@ -3,12 +3,6 @@ */ package org.gcube.portlets.user.workspaceexplorerapp.client; -import gwt.material.design.client.constants.IconPosition; -import gwt.material.design.client.constants.IconType; -import gwt.material.design.client.ui.MaterialLink; -import gwt.material.design.client.ui.MaterialNavBar; -import gwt.material.design.client.ui.MaterialNavSection; - import java.util.ArrayList; import java.util.List; @@ -28,6 +22,12 @@ import com.google.gwt.user.client.ui.HTMLPanel; import com.google.gwt.user.client.ui.Image; import com.google.gwt.user.client.ui.Widget; +import gwt.material.design.client.constants.IconPosition; +import gwt.material.design.client.constants.IconType; +import gwt.material.design.client.ui.MaterialLink; +import gwt.material.design.client.ui.MaterialNavBar; +import gwt.material.design.client.ui.MaterialNavSection; + /** diff --git a/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/client/WorkspaceExplorerFoooterPanel.java b/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/client/WorkspaceExplorerFoooterPanel.java index 072d34d..c8126a7 100644 --- a/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/client/WorkspaceExplorerFoooterPanel.java +++ b/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/client/WorkspaceExplorerFoooterPanel.java @@ -3,14 +3,14 @@ */ package org.gcube.portlets.user.workspaceexplorerapp.client; -import gwt.material.design.client.ui.MaterialFooter; - import com.google.gwt.core.client.GWT; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.Widget; +import gwt.material.design.client.ui.MaterialFooter; + /** * 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 47785f6..7ad9f4c 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 @@ -3,8 +3,6 @@ */ package org.gcube.portlets.user.workspaceexplorerapp.client; -import gwt.material.design.client.ui.MaterialToast; - import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -42,6 +40,8 @@ import com.google.gwt.user.client.ui.DockPanel; import com.google.gwt.user.client.ui.ScrollPanel; import com.google.gwt.user.client.ui.VerticalPanel; +import gwt.material.design.client.ui.MaterialToast; + /** * The Class WorkspaceResourcesExplorerPanel. diff --git a/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/client/grid/ItemsTable.java b/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/client/grid/ItemsTable.java index 4881f20..a702a26 100644 --- a/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/client/grid/ItemsTable.java +++ b/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/client/grid/ItemsTable.java @@ -3,13 +3,6 @@ */ package org.gcube.portlets.user.workspaceexplorerapp.client.grid; -import gwt.material.design.client.base.MaterialImageCell; -import gwt.material.design.client.constants.IconPosition; -import gwt.material.design.client.constants.IconType; -import gwt.material.design.client.constants.ImageType; -import gwt.material.design.client.ui.MaterialIcon; -import gwt.material.design.client.ui.MaterialImage; - import java.util.Arrays; import java.util.Comparator; import java.util.Date; @@ -48,6 +41,13 @@ import com.google.gwt.user.cellview.client.TextColumn; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.Image; import com.google.gwt.user.client.ui.Label; + +import gwt.material.design.client.base.MaterialImageCell; +import gwt.material.design.client.constants.IconPosition; +import gwt.material.design.client.constants.IconType; +import gwt.material.design.client.constants.ImageType; +import gwt.material.design.client.ui.MaterialIcon; +import gwt.material.design.client.ui.MaterialImage; /** * The Class PackagesTable. * diff --git a/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/client/grid/MaterialIconCell.java b/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/client/grid/MaterialIconCell.java index c9c61f6..b040ac0 100644 --- a/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/client/grid/MaterialIconCell.java +++ b/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/client/grid/MaterialIconCell.java @@ -4,14 +4,14 @@ package org.gcube.portlets.user.workspaceexplorerapp.client.grid; -import gwt.material.design.client.ui.MaterialIcon; - import com.google.gwt.cell.client.AbstractCell; import com.google.gwt.cell.client.ValueUpdater; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.NativeEvent; import com.google.gwt.safehtml.shared.SafeHtmlBuilder; +import gwt.material.design.client.ui.MaterialIcon; + /** * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Mar 8, 2016 */ 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 356525a..cbbd32e 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 @@ -3,8 +3,6 @@ */ package org.gcube.portlets.user.workspaceexplorerapp.client.grid; -import gwt.material.design.client.ui.MaterialLink; - 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; @@ -19,6 +17,8 @@ import com.google.gwt.user.client.Command; import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.Widget; +import gwt.material.design.client.ui.MaterialLink; + /** * 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 874c9e9..f475082 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 @@ -4,156 +4,79 @@ import java.util.List; import org.gcube.portlets.user.workspaceexplorerapp.shared.FilterCriteria; import org.gcube.portlets.user.workspaceexplorerapp.shared.Item; -import org.gcube.portlets.user.workspaceexplorerapp.shared.ItemCategory; import org.gcube.portlets.user.workspaceexplorerapp.shared.ItemType; import org.gcube.portlets.user.workspaceexplorerapp.shared.WorkspaceNavigatorServiceException; import com.google.gwt.user.client.rpc.RemoteService; import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; - /** * The Interface WorkspaceExplorerAppService. * - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Jul 3, 2017 + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Jul 3, 2017 */ @RemoteServiceRelativePath("WorkspaceExplorerAppService") public interface WorkspaceExplorerAppService extends RemoteService { - - /** - * Gets the breadcrumbs by item identifier. - * - * @param itemIdentifier the item identifier - * @param includeItemAsParent the include item as parent - * @return the breadcrumbs by item identifier - * @throws Exception the exception - */ - List getBreadcrumbsByItemIdentifier(String itemIdentifier, - boolean includeItemAsParent) throws Exception; - - /** - * Check name. - * - * @param name the name - * @return true, if successful - * @throws WorkspaceNavigatorServiceException the workspace navigator service exception - */ - boolean checkName(String name) throws WorkspaceNavigatorServiceException; - /** * 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 */ - Item getFolder( - Item folder, List showableTypes, boolean purgeEmpyFolders, - FilterCriteria filterCriteria) throws WorkspaceNavigatorServiceException; + Item getFolder(Item folder, List showableTypes, boolean purgeEmpyFolders, FilterCriteria filterCriteria) + throws WorkspaceNavigatorServiceException; /** * Gets the root. * - * @param showableTypes the showable types + * @param showableTypes the showable types * @param purgeEmpyFolders the purge empy folders - * @param filterCriteria the filter criteria + * @param filterCriteria the filter criteria * @return the root - * @throws WorkspaceNavigatorServiceException the workspace navigator service exception + * @throws WorkspaceNavigatorServiceException the workspace navigator service + * exception */ - Item getRoot(List showableTypes, boolean purgeEmpyFolders, - FilterCriteria filterCriteria) + Item getRoot(List showableTypes, boolean purgeEmpyFolders, FilterCriteria filterCriteria) throws WorkspaceNavigatorServiceException; /** * Gets the my special folder. * - * @param showableTypes the showable types + * @param showableTypes the showable types * @param purgeEmpyFolders the purge empy folders - * @param filterCriteria the filter criteria + * @param filterCriteria the filter criteria * @return the my special folder - * @throws WorkspaceNavigatorServiceException the workspace navigator service exception + * @throws WorkspaceNavigatorServiceException the workspace navigator service + * exception */ - Item getMySpecialFolder(List showableTypes, - boolean purgeEmpyFolders, FilterCriteria filterCriteria) + Item getMySpecialFolder(List showableTypes, boolean purgeEmpyFolders, FilterCriteria filterCriteria) throws WorkspaceNavigatorServiceException; - /** - * Gets the item by category. - * - * @param category the category - * @return the item by category - * @throws WorkspaceNavigatorServiceException the workspace navigator service exception - */ - Item getItemByCategory(ItemCategory category)throws WorkspaceNavigatorServiceException; - - /** - * Gets the size by item id. - * - * @param itemId the item id - * @return the size by item id - * @throws Exception the exception - */ - Long getSizeByItemId(String itemId) throws Exception; - - /** - * Gets the mime type. - * - * @param itemId the item id - * @return the mime type - * @throws Exception the exception - */ - String getMimeType(String itemId) throws Exception; - - /** - * Gets the user acl for folder id. - * - * @param folderId the folder id - * @return the user acl for folder id - * @throws Exception the exception - */ - String getUserACLForFolderId(String folderId) throws Exception; - - - /** - * Gets the readable size by item id. - * - * @param id the id - * @return the readable size by item id - * @throws Exception the exception - */ - String getReadableSizeByItemId(String id) throws Exception; - /** * Gets the breadcrumbs by item identifier to parent limit. * - * @param itemIdentifier the item identifier - * @param parentLimit the parent limit + * @param itemIdentifier the item identifier + * @param parentLimit the parent limit * @param includeItemAsParent the include item as parent * @return the breadcrumbs by item identifier to parent limit * @throws Exception the exception */ - List getBreadcrumbsByItemIdentifierToParentLimit( - String itemIdentifier, String parentLimit, + List getBreadcrumbsByItemIdentifierToParentLimit(String itemIdentifier, String parentLimit, boolean includeItemAsParent) throws Exception; /** - * Creates the folder. + * Gets the breadcrumbs by item identifier. * - * @param nameFolder the name folder - * @param description the description - * @param parentId the parent id - * @return the item + * @param itemIdentifier the item identifier + * @param includeItemAsParent the include item as parent + * @return the breadcrumbs by item identifier * @throws Exception the exception */ - Item createFolder( - String nameFolder, String description, String parentId) - throws Exception; + List getBreadcrumbsByItemIdentifier(String itemIdentifier, boolean includeItemAsParent) throws Exception; /** * Gets the public link for item id. @@ -162,8 +85,7 @@ public interface WorkspaceExplorerAppService extends RemoteService { * @return the public link for item id * @throws Exception the exception */ - String getPublicLinkForItemId(String itemId) - throws Exception; + String getPublicLinkForItemId(String itemId) throws Exception; /** * Gets the folder id from encrypted. @@ -172,6 +94,77 @@ public interface WorkspaceExplorerAppService extends RemoteService { * @return the folder id from encrypted * @throws Exception the exception */ - String getFolderIdFromEncrypted(String encryptedFolderId) - throws Exception; + String getFolderIdFromEncrypted(String encryptedFolderId) throws Exception; +// +// /** +// * Check name. +// * +// * @param name the name +// * @return true, if successful +// * @throws WorkspaceNavigatorServiceException the workspace navigator service exception +// */ +// boolean checkName(String name) throws WorkspaceNavigatorServiceException; +// + +// +// /** +// * Gets the item by category. +// * +// * @param category the category +// * @return the item by category +// * @throws WorkspaceNavigatorServiceException the workspace navigator service exception +// */ +// Item getItemByCategory(ItemCategory category)throws WorkspaceNavigatorServiceException; +// +// /** +// * Gets the size by item id. +// * +// * @param itemId the item id +// * @return the size by item id +// * @throws Exception the exception +// */ +// Long getSizeByItemId(String itemId) throws Exception; +// +// /** +// * Gets the mime type. +// * +// * @param itemId the item id +// * @return the mime type +// * @throws Exception the exception +// */ +// String getMimeType(String itemId) throws Exception; +// +// /** +// * Gets the user acl for folder id. +// * +// * @param folderId the folder id +// * @return the user acl for folder id +// * @throws Exception the exception +// */ +// String getUserACLForFolderId(String folderId) throws Exception; +// +// +// /** +// * Gets the readable size by item id. +// * +// * @param id the id +// * @return the readable size by item id +// * @throws Exception the exception +// */ +// String getReadableSizeByItemId(String id) throws Exception; +// + +// /** +// * Creates the folder. +// * +// * @param nameFolder the name folder +// * @param description the description +// * @param parentId the parent id +// * @return the item +// * @throws Exception the exception +// */ +// Item createFolder( +// String nameFolder, String description, String parentId) +// 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 04c7681..9bdd4ca 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 @@ -7,162 +7,21 @@ import java.util.List; import org.gcube.portlets.user.workspaceexplorerapp.shared.FilterCriteria; import org.gcube.portlets.user.workspaceexplorerapp.shared.Item; -import org.gcube.portlets.user.workspaceexplorerapp.shared.ItemCategory; import org.gcube.portlets.user.workspaceexplorerapp.shared.ItemType; import com.google.gwt.user.client.rpc.AsyncCallback; - - /** * The Interface WorkspaceExplorerAppServiceAsync. * - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Jul 3, 2017 + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Jul 3, 2017 */ public interface WorkspaceExplorerAppServiceAsync { - - /** - * Gets the root. - * - * @param showableTypes the showable types - * @param purgeEmpyFolders the purge empy folders - * @param filterCriteria the filter criteria - * @param callback the callback - * @return the root - */ - public void getRoot(List showableTypes, boolean purgeEmpyFolders, - FilterCriteria filterCriteria, AsyncCallback callback); - - - /** - * Check name. - * - * @param name the name - * @param callback the callback - */ - public void checkName(String name, AsyncCallback callback); - - - - /** - * Gets the folder. - * - * @param folder the folder - * @param showableTypes the showable types - * @param purgeEmpyFolders the purge empy folders - * @param filterCriteria the filter criteria - * @param callback the callback - * @return the folder - */ - public void getFolder(Item folder, List showableTypes, - boolean purgeEmpyFolders, FilterCriteria filterCriteria, - AsyncCallback callback); - - - - /** - * Gets the breadcrumbs by item identifier. - * - * @param itemIdentifier the item identifier - * @param includeItemAsParent the include item as parent - * @param asyncCallback the async callback - * @return the breadcrumbs by item identifier - */ - public void getBreadcrumbsByItemIdentifier(String itemIdentifier, - boolean includeItemAsParent, AsyncCallback> asyncCallback); - - - /** - * Gets the my special folder. - * - * @param showableTypes the showable types - * @param purgeEmpyFolders the purge empy folders - * @param filterCriteria the filter criteria - * @param asyncCallback the async callback - * @return the my special folder - */ - public void getMySpecialFolder(List showableTypes, boolean purgeEmpyFolders, FilterCriteria filterCriteria, AsyncCallback asyncCallback); - - - /** - * Gets the item by category. - * - * @param category the category - * @param asyncCallback the async callback - * @return the item by category - */ - public void getItemByCategory(ItemCategory category, AsyncCallback asyncCallback); - - - /** - * Gets the size by item id. - * - * @param id the id - * @param asyncCallback the async callback - * @return the size by item id - */ - public void getSizeByItemId(String id, AsyncCallback asyncCallback); - - - /** - * Gets the readable size by item id. - * - * @param id the id - * @param asyncCallback the async callback - * @return the readable size by item id - */ - public void getReadableSizeByItemId(String id, AsyncCallback asyncCallback); - - /** - * Gets the mime type. - * - * @param id the id - * @param asyncCallback the async callback - * @return the mime type - */ - public void getMimeType(String id, AsyncCallback asyncCallback); - - /** - * Gets the user acl for folder id. - * - * @param id the id - * @param asyncCallback the async callback - * @return the user acl for folder id - */ - public void getUserACLForFolderId(String id, - AsyncCallback asyncCallback); - - /** - * Gets the breadcrumbs by item identifier to parent limit. - * - * @param itemIdentifier the item identifier - * @param parentLimit the parent limit - * @param includeItemAsParent the include item as parent - * @param callback the callback - * @return the breadcrumbs by item identifier to parent limit - */ - void getBreadcrumbsByItemIdentifierToParentLimit(String itemIdentifier, - String parentLimit, boolean includeItemAsParent, - AsyncCallback> callback); - - /** - * Creates the folder. - * - * @param nameFolder the name folder - * @param description the description - * @param parentId the parent id - * @param callback the callback - */ - void createFolder( - String nameFolder, String description, String parentId, - AsyncCallback callback); - /** * Gets the public link for item id. * - * @param itemId the item id + * @param itemId the item id * @param callback the callback * @return the public link for item id */ @@ -172,10 +31,140 @@ public interface WorkspaceExplorerAppServiceAsync { * Gets the folder id from encrypted. * * @param encodedFolderID the encoded folder id - * @param callback the callback + * @param callback the callback * @return the folder id from encrypted */ - void getFolderIdFromEncrypted( - String encodedFolderID, AsyncCallback callback); + void getFolderIdFromEncrypted(String encodedFolderID, AsyncCallback callback); + + /** + * Gets the root. + * + * @param showableTypes the showable types + * @param purgeEmpyFolders the purge empy folders + * @param filterCriteria the filter criteria + * @param callback the callback + * @return the root + */ + public void getRoot(List showableTypes, boolean purgeEmpyFolders, FilterCriteria filterCriteria, + AsyncCallback callback); + + /** + * Gets the folder. + * + * @param folder the folder + * @param showableTypes the showable types + * @param purgeEmpyFolders the purge empy folders + * @param filterCriteria the filter criteria + * @param callback the callback + * @return the folder + */ + public void getFolder(Item folder, List showableTypes, boolean purgeEmpyFolders, + FilterCriteria filterCriteria, AsyncCallback callback); + + /** + * Gets the breadcrumbs by item identifier. + * + * @param itemIdentifier the item identifier + * @param includeItemAsParent the include item as parent + * @param asyncCallback the async callback + * @return the breadcrumbs by item identifier + */ + public void getBreadcrumbsByItemIdentifier(String itemIdentifier, boolean includeItemAsParent, + AsyncCallback> asyncCallback); + + /** + * Gets the my special folder. + * + * @param showableTypes the showable types + * @param purgeEmpyFolders the purge empy folders + * @param filterCriteria the filter criteria + * @param asyncCallback the async callback + * @return the my special folder + */ + public void getMySpecialFolder(List showableTypes, boolean purgeEmpyFolders, + FilterCriteria filterCriteria, AsyncCallback asyncCallback); + + /** + * Gets the breadcrumbs by item identifier to parent limit. + * + * @param itemIdentifier the item identifier + * @param parentLimit the parent limit + * @param includeItemAsParent the include item as parent + * @param callback the callback + * @return the breadcrumbs by item identifier to parent limit + */ + void getBreadcrumbsByItemIdentifierToParentLimit(String itemIdentifier, String parentLimit, + boolean includeItemAsParent, AsyncCallback> callback); + +// +// +// /** +// * Check name. +// * +// * @param name the name +// * @param callback the callback +// */ +// public void checkName(String name, AsyncCallback callback); +// +// +// + +// +// /** +// * Gets the item by category. +// * +// * @param category the category +// * @param asyncCallback the async callback +// * @return the item by category +// */ +// public void getItemByCategory(ItemCategory category, AsyncCallback asyncCallback); +// + +// /** +// * Gets the size by item id. +// * +// * @param id the id +// * @param asyncCallback the async callback +// * @return the size by item id +// */ +// public void getSizeByItemId(String id, AsyncCallback asyncCallback); + +// /** +// * Gets the readable size by item id. +// * +// * @param id the id +// * @param asyncCallback the async callback +// * @return the readable size by item id +// */ +// public void getReadableSizeByItemId(String id, AsyncCallback asyncCallback); +// +// /** +// * Gets the mime type. +// * +// * @param id the id +// * @param asyncCallback the async callback +// * @return the mime type +// */ +// public void getMimeType(String id, AsyncCallback asyncCallback); + +// /** +// * Gets the user acl for folder id. +// * +// * @param id the id +// * @param asyncCallback the async callback +// * @return the user acl for folder id +// */ +// public void getUserACLForFolderId(String id, +// AsyncCallback asyncCallback); + +// /** +// * Creates the folder. +// * +// * @param nameFolder the name folder +// * @param description the description +// * @param parentId the parent id +// * @param callback the callback +// */ +// void createFolder(String nameFolder, String description, String parentId, AsyncCallback callback); } diff --git a/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/server/DownloadWorkspaceExplorerServlet.java b/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/server/DownloadWorkspaceExplorerServlet.java index d2179c7..7b10254 100644 --- a/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/server/DownloadWorkspaceExplorerServlet.java +++ b/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/server/DownloadWorkspaceExplorerServlet.java @@ -21,24 +21,21 @@ import javax.servlet.http.HttpServletResponse; import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; import org.apache.log4j.Logger; -import org.gcube.common.homelibrary.home.exceptions.InternalErrorException; -import org.gcube.common.homelibrary.home.workspace.Workspace; -import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder; -import org.gcube.common.homelibrary.home.workspace.WorkspaceItem; -import org.gcube.common.homelibrary.home.workspace.exceptions.ItemNotFoundException; -import org.gcube.common.homelibrary.home.workspace.folder.FolderItem; import org.gcube.common.homelibrary.home.workspace.folder.items.ExternalFile; import org.gcube.common.homelibrary.home.workspace.folder.items.ExternalImage; import org.gcube.common.homelibrary.home.workspace.folder.items.ExternalUrl; -import org.gcube.common.homelibrary.home.workspace.folder.items.GCubeItem; -import org.gcube.common.homelibrary.home.workspace.folder.items.Query; import org.gcube.common.homelibrary.home.workspace.folder.items.Report; import org.gcube.common.homelibrary.home.workspace.folder.items.ReportTemplate; import org.gcube.common.homelibrary.home.workspace.folder.items.ts.TimeSeries; import org.gcube.common.homelibrary.util.Extensions; import org.gcube.common.homelibrary.util.MimeTypeUtil; import org.gcube.common.homelibrary.util.zip.ZipUtil; +import org.gcube.common.storagehub.model.items.FolderItem; +import org.gcube.common.storagehubwrapper.server.tohl.Workspace; +import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.InternalErrorException; +import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.ItemNotFoundException; import org.gcube.portlets.user.workspaceexplorerapp.client.WorkspaceExplorerAppConstants; +import org.gcube.portlets.user.workspaceexplorerapp.server.workspace.WsUtil; import org.gcube.portlets.user.workspaceexplorerapp.shared.HandlerResultMessage; /** 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 ba5ba0f..f295a7d 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 @@ -1,24 +1,28 @@ package org.gcube.portlets.user.workspaceexplorerapp.server; +import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.concurrent.TimeUnit; +import javax.servlet.http.HttpSession; + import org.gcube.common.encryption.StringEncrypter; import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.storagehubwrapper.server.tohl.Workspace; +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.WorkspaceSharedFolder; import org.gcube.common.storagehubwrapper.shared.tohl.items.FileItem; -import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder; 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; +import org.gcube.portlets.user.workspaceexplorerapp.server.workspace.WorkspaceInstance; +import org.gcube.portlets.user.workspaceexplorerapp.server.workspace.WsUtil; import org.gcube.portlets.user.workspaceexplorerapp.shared.FilterCriteria; import org.gcube.portlets.user.workspaceexplorerapp.shared.Item; -import org.gcube.portlets.user.workspaceexplorerapp.shared.ItemCategory; import org.gcube.portlets.user.workspaceexplorerapp.shared.ItemType; import org.gcube.portlets.user.workspaceexplorerapp.shared.WorkspaceNavigatorServiceException; import org.slf4j.Logger; @@ -37,12 +41,32 @@ import com.google.gwt.user.server.rpc.RemoteServiceServlet; @SuppressWarnings("serial") public class WorkspaceExplorerAppServiceImpl extends RemoteServiceServlet implements WorkspaceExplorerAppService { + public static final String THE_WORKSPACE_SHUB_INSTANCIED = "THE_WORKSPACE_SHUB_INSTANCIED"; /** * */ public static final Logger logger = LoggerFactory.getLogger(WorkspaceExplorerAppServiceImpl.class); public static final String UTF_8 = "UTF-8"; + + /** + * Gets the workspace. + * + * @return the workspace + * @throws Exception + */ + private Workspace getWorkspace() throws Exception { + HttpSession httpSession = this.getThreadLocalRequest().getSession(); + Workspace workspace = (Workspace) httpSession.getAttribute(THE_WORKSPACE_SHUB_INSTANCIED); + + if(workspace==null) { + WorkspaceInstance workspaceInstance = new WorkspaceInstance(httpSession); + workspace = workspaceInstance.get(); + httpSession.setAttribute(THE_WORKSPACE_SHUB_INSTANCIED, workspace); + } + + return workspace; + } /** * {@inheritDoc} @@ -53,7 +77,7 @@ public class WorkspaceExplorerAppServiceImpl extends RemoteServiceServlet implem try { - Workspace workspace = WsUtil.getWorkspace(this.getThreadLocalRequest().getSession()); + Workspace workspace = getWorkspace(); logger.trace("Start getRoot..."); org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder root = workspace.getRoot(); @@ -62,7 +86,11 @@ public class WorkspaceExplorerAppServiceImpl extends RemoteServiceServlet implem long startTime = System.currentTimeMillis(); logger.trace("start time - " + startTime); - Item rootItem = ItemBuilder.getItem(null, root, root.getPath(), showableTypes, filterCriteria, true); + + Item rootItem = ItemBuilder.getItem(null, root, root.getPath(), showableTypes, filterCriteria); + //adding the children + List children = workspace.getChildren(root.getId()); + rootItem = ItemBuilder.addChildren(rootItem, "", children, showableTypes, filterCriteria); rootItem.setName(WorkspaceExplorerAppConstants.HOME_LABEL); rootItem.setIsRoot(true); @@ -100,19 +128,20 @@ public class WorkspaceExplorerAppServiceImpl extends RemoteServiceServlet implem * @param purgeEmpyFolders the purge empy folders * @param filterCriteria the filter criteria * @return the folder - * @throws Exception the exception + * @throws WorkspaceNavigatorServiceException the workspace navigator service exception */ @Override public Item getFolder(Item item, List showableTypes, boolean purgeEmpyFolders, FilterCriteria filterCriteria) throws WorkspaceNavigatorServiceException { logger.trace("getFolder item: "+item+" showableTypes: "+showableTypes+" purgeEmpyFolders: "+purgeEmpyFolders+" filterCriteria: "+filterCriteria); WorkspaceItem workspaceItem = null; + Workspace workspace = null; try { if(item==null || item.getId()==null) throw new Exception("Item id is null"); - Workspace workspace = WsUtil.getWorkspace(this.getThreadLocalRequest().getSession()); + workspace = getWorkspace(); workspaceItem = workspace.getItem(item.getId()); } catch (Exception e) { @@ -131,8 +160,10 @@ public class WorkspaceExplorerAppServiceImpl extends RemoteServiceServlet implem logger.trace("start time - " + startTime); String path = item.getPath()!=null && !item.getPath().isEmpty()?item.getPath():folder.getPath(); - - Item itemFolder = ItemBuilder.getItem(null, folder, path, showableTypes, filterCriteria, true); + Item itemFolder = ItemBuilder.getItem(null, folder, path, showableTypes, filterCriteria); + //adding the children + List children = workspace.getChildren(itemFolder.getId()); + itemFolder = ItemBuilder.addChildren(itemFolder, path, children, showableTypes, filterCriteria); // _log.trace("Only showable types:"); if (purgeEmpyFolders) { @@ -160,21 +191,21 @@ public class WorkspaceExplorerAppServiceImpl extends RemoteServiceServlet implem } - /** - * Gets the item by category. - * - * @param category the category - * @return the item by category - * @throws WorkspaceNavigatorServiceException the workspace navigator service exception - */ - /* (non-Javadoc) - * @see org.gcube.portlets.widgets.wsexplorer.client.rpc.WorkspaceExplorerService#getItemByCategory(org.gcube.portlets.widgets.wsexplorer.shared.ItemCategory) - */ - @Override - public Item getItemByCategory(ItemCategory category) throws WorkspaceNavigatorServiceException{ - logger.trace("GetItemByCategory category: "+category); - throw new WorkspaceNavigatorServiceException("The method getItemByCategory is not implemented"); - } +// /** +// * Gets the item by category. +// * +// * @param category the category +// * @return the item by category +// * @throws WorkspaceNavigatorServiceException the workspace navigator service exception +// */ +// /* (non-Javadoc) +// * @see org.gcube.portlets.widgets.wsexplorer.client.rpc.WorkspaceExplorerService#getItemByCategory(org.gcube.portlets.widgets.wsexplorer.shared.ItemCategory) +// */ +// @Override +// public Item getItemByCategory(ItemCategory category) throws WorkspaceNavigatorServiceException{ +// logger.trace("GetItemByCategory category: "+category); +// throw new WorkspaceNavigatorServiceException("The method getItemByCategory is not implemented"); +// } /** * {@inheritDoc} @@ -185,12 +216,16 @@ public class WorkspaceExplorerAppServiceImpl extends RemoteServiceServlet implem try { - Workspace workspace = WsUtil.getWorkspace(this.getThreadLocalRequest().getSession()); + Workspace workspace = getWorkspace(); WorkspaceItem folder = workspace.getMySpecialFolders(); long startTime = System.currentTimeMillis(); logger.trace("start time - " + startTime); - Item itemFolder = ItemBuilder.getItem(null, folder, folder.getPath(), showableTypes, filterCriteria, true); + Item itemFolder = ItemBuilder.getItem(null, folder, folder.getPath(), showableTypes, filterCriteria); + //adding the children + List children = workspace.getChildren(itemFolder.getId()); + itemFolder = ItemBuilder.addChildren(itemFolder, "", children, showableTypes, filterCriteria); + //OVERRIDING VRE FOLDERS NAME - SET SPECIAL FOLDER /Workspace/MySpecialFolders itemFolder.setName(WorkspaceExplorerAppConstants.VRE_FOLDERS_LABEL); itemFolder.setSpecialFolder(true); @@ -213,21 +248,21 @@ public class WorkspaceExplorerAppServiceImpl extends RemoteServiceServlet implem } } - /** - * {@inheritDoc} - */ - @Override - public boolean checkName(String name) throws WorkspaceNavigatorServiceException { - logger.trace("checkName name: "+name); - throw new WorkspaceNavigatorServiceException("The method checkName is not implemented"); -// try { -// Workspace workspace = WsUtil.getWorkspace(this.getThreadLocalRequest().getSession()); -// return workspace.isValidName(name); -// } catch (Exception e) { -// logger.error("Error during folder retrieving", e); -// throw new WorkspaceNavigatorServiceException(e.getMessage()); -// } - } +// /** +// * {@inheritDoc} +// */ +// @Override +// public boolean checkName(String name) throws WorkspaceNavigatorServiceException { +// logger.trace("checkName name: "+name); +// throw new WorkspaceNavigatorServiceException("The method checkName is not implemented"); +//// try { +//// Workspace workspace = WsUtil.getWorkspace(this.getThreadLocalRequest().getSession()); +//// return workspace.isValidName(name); +//// } catch (Exception e) { +//// logger.error("Error during folder retrieving", e); +//// throw new WorkspaceNavigatorServiceException(e.getMessage()); +//// } +// } /*protected void printName(String indentation, Item item) { @@ -250,7 +285,7 @@ public class WorkspaceExplorerAppServiceImpl extends RemoteServiceServlet implem logger.trace("ListParents By Item Identifier "+ itemIdentifier); try { - Workspace workspace = WsUtil.getWorkspace(this.getThreadLocalRequest().getSession()); + Workspace workspace = getWorkspace(); WorkspaceItem wsItem = workspace.getItem(itemIdentifier); logger.trace("workspace retrieve item name: "+wsItem.getName()); List parents = workspace.getParentsById(itemIdentifier); @@ -368,7 +403,7 @@ public class WorkspaceExplorerAppServiceImpl extends RemoteServiceServlet implem logger.trace("getBreadcrumbsByItemIdentifierToParentLimit by Item Identifier " + itemIdentifier +" and limit: "+parentLimit); try { - Workspace workspace = WsUtil.getWorkspace(this.getThreadLocalRequest().getSession()); + Workspace workspace = getWorkspace(); WorkspaceItem wsItem = workspace.getItem(itemIdentifier); logger.trace("workspace retrieve item name: "+wsItem.getName()); List parents = null; @@ -477,103 +512,103 @@ public class WorkspaceExplorerAppServiceImpl extends RemoteServiceServlet implem } } - /** - * Gets the size by item id. - * - * @param itemId the item id - * @return the size by item id - * @throws Exception the exception - */ - /* (non-Javadoc) - * @see org.gcube.portlets.widgets.wsexplorer.client.rpc.WorkspaceExplorerService#loadSizeByItemId(java.lang.String) - */ - @Override - public Long getSizeByItemId(String itemId) throws Exception { +// /** +// * Gets the size by item id. +// * +// * @param itemId the item id +// * @return the size by item id +// * @throws Exception the exception +// */ +// /* (non-Javadoc) +// * @see org.gcube.portlets.widgets.wsexplorer.client.rpc.WorkspaceExplorerService#loadSizeByItemId(java.lang.String) +// */ +// @Override +// public Long getSizeByItemId(String itemId) throws Exception { +// +// logger.info("get Size By ItemId "+ itemId); +// try { +// +// Workspace workspace = getWorkspace(); +// WorkspaceItem wsItem = workspace.getItem(itemId); +// Long size = new Long(-1); +// +// if(wsItem instanceof FileItem){ //ITEM +// FileItem fileItem = (FileItem) wsItem; +// size = new Long(fileItem.getSize()); +// } else if (wsItem instanceof WorkspaceFolder ){ //FOLDER +// WorkspaceFolder theFolder = (WorkspaceFolder) wsItem; +// //size = theFolder.getSize(); NOT SUPPORTED BY SHUB +// } else if (wsItem instanceof WorkspaceSharedFolder){ //SHARED FOLDER +// WorkspaceSharedFolder theFolder = (WorkspaceSharedFolder) wsItem; +// //size = theFolder.getSize(); NOT SUPPORTED BY SHUB +// } +// logger.info("returning size: " +size); +// return size; +// +// } catch (Exception e) { +// logger.error("get Size By ItemId ", e); +// throw new Exception(e.getMessage()); +// } +// } - logger.info("get Size By ItemId "+ itemId); - try { - - Workspace workspace = WsUtil.getWorkspace(this.getThreadLocalRequest().getSession()); - WorkspaceItem wsItem = workspace.getItem(itemId); - Long size = new Long(-1); - - if(wsItem instanceof FileItem){ //ITEM - FileItem fileItem = (FileItem) wsItem; - size = new Long(fileItem.getSize()); - } else if (wsItem instanceof WorkspaceFolder ){ //FOLDER - WorkspaceFolder theFolder = (WorkspaceFolder) wsItem; - //size = theFolder.getSize(); NOT SUPPORTED BY SHUB - } else if (wsItem instanceof WorkspaceSharedFolder){ //SHARED FOLDER - WorkspaceSharedFolder theFolder = (WorkspaceSharedFolder) wsItem; - //size = theFolder.getSize(); NOT SUPPORTED BY SHUB - } - logger.info("returning size: " +size); - return size; - - } catch (Exception e) { - logger.error("get Size By ItemId ", e); - throw new Exception(e.getMessage()); - } - } - - /** - * Gets the mime type. - * - * @param itemId the item id - * @return the mime type - * @throws Exception the exception - */ - /* (non-Javadoc) - * @see org.gcube.portlets.widgets.wsexplorer.client.rpc.WorkspaceExplorerService#getMimeType(java.lang.String) - */ - @Override - public String getMimeType(String itemId) throws Exception { - - logger.info("get MimeType By ItemId "+ itemId); - try { - - Workspace workspace = WsUtil.getWorkspace(this.getThreadLocalRequest().getSession()); - WorkspaceItem wsItem = workspace.getItem(itemId); - - if(wsItem instanceof FileItem) { - FileItem fileItem = (FileItem) wsItem; - return fileItem.getMimeType(); - }else - return null; - - } catch (Exception e) { - logger.error("get MimeType By ItemId ", e); - throw new Exception(e.getMessage()); - } - } +// /** +// * Gets the mime type. +// * +// * @param itemId the item id +// * @return the mime type +// * @throws Exception the exception +// */ +// /* (non-Javadoc) +// * @see org.gcube.portlets.widgets.wsexplorer.client.rpc.WorkspaceExplorerService#getMimeType(java.lang.String) +// */ +// @Override +// public String getMimeType(String itemId) throws Exception { +// +// logger.info("get MimeType By ItemId "+ itemId); +// try { +// +// Workspace workspace = getWorkspace(); +// WorkspaceItem wsItem = workspace.getItem(itemId); +// +// if(wsItem instanceof FileItem) { +// FileItem fileItem = (FileItem) wsItem; +// return fileItem.getMimeType(); +// }else +// return null; +// +// } catch (Exception e) { +// logger.error("get MimeType By ItemId ", e); +// throw new Exception(e.getMessage()); +// } +// } - /** - * Gets the user acl for folder id. - * - * @param folderId the folder id - * @return the user acl for folder id - * @throws Exception the exception - */ - @Override - public String getUserACLForFolderId(String folderId) throws Exception{ - try { - logger.info("Get user ACL to FOLDER id: "+folderId); - Workspace workspace = WsUtil.getWorkspace(this.getThreadLocalRequest().getSession()); - WorkspaceItem wsItem = workspace.getItem(folderId); - - if(!isASharedFolder(wsItem, false)) { - return "OWNER"; - } - else { - return wsItem.getACLUser().toString(); - } - } catch (Exception e) { - logger.error("Error in server get UserACLForFolderId", e); - String error = "An error occurred when getting ACL rules for selected folder. "+e.getMessage(); - throw new Exception(error); - } - } +// /** +// * Gets the user acl for folder id. +// * +// * @param folderId the folder id +// * @return the user acl for folder id +// * @throws Exception the exception +// */ +// @Override +// public String getUserACLForFolderId(String folderId) throws Exception{ +// try { +// logger.info("Get user ACL to FOLDER id: "+folderId); +// Workspace workspace = getWorkspace(); +// WorkspaceItem wsItem = workspace.getItem(folderId); +// +// if(!isASharedFolder(wsItem, false)) { +// return "OWNER"; +// } +// else { +// return wsItem.getACLUser().toString(); +// } +// } catch (Exception e) { +// logger.error("Error in server get UserACLForFolderId", e); +// String error = "An error occurred when getting ACL rules for selected folder. "+e.getMessage(); +// throw new Exception(error); +// } +// } /** @@ -601,92 +636,93 @@ public class WorkspaceExplorerAppServiceImpl extends RemoteServiceServlet implem } - /** - * Gets the readable size by item id. - * - * @param itemId the item id - * @return the readable size by item id - * @throws Exception the exception - */ - /* (non-Javadoc) - * @see org.gcube.portlets.widgets.wsexplorer.client.rpc.WorkspaceExplorerService#getFormattedSizeByItemId(java.lang.String, org.gcube.portlets.widgets.wsexplorer.shared.SizeFormatter) - */ - @Override - public String getReadableSizeByItemId(String itemId) throws Exception { +// /** +// * Gets the readable size by item id. +// * +// * @param itemId the item id +// * @return the readable size by item id +// * @throws Exception the exception +// */ +// /* (non-Javadoc) +// * @see org.gcube.portlets.widgets.wsexplorer.client.rpc.WorkspaceExplorerService#getFormattedSizeByItemId(java.lang.String, org.gcube.portlets.widgets.wsexplorer.shared.SizeFormatter) +// */ +// @Override +// public String getReadableSizeByItemId(String itemId) throws Exception { +// +// try{ +// logger.info("getFormattedSize ByItemId "+ itemId); +// long size = getSizeByItemId(itemId); +// return StringUtil.readableFileSize(size); +// } catch (Exception e) { +// logger.error("getFormattedSize By ItemId ", e); +// throw new Exception(e.getMessage()); +// } +// } - try{ - logger.info("getFormattedSize ByItemId "+ itemId); - long size = getSizeByItemId(itemId); - return StringUtil.readableFileSize(size); - } catch (Exception e) { - logger.error("getFormattedSize By ItemId ", e); - throw new Exception(e.getMessage()); - } - } - - /** - * Creates the folder. - * - * @param nameFolder the name folder - * @param description the description - * @param parentId the parent id - * @return the item - * @throws Exception the exception - */ - /* (non-Javadoc) - * @see org.gcube.portlets.user.workspaceexplorerapp.client.rpc.WorkspaceExplorerAppService#createFolder(java.lang.String, java.lang.String, java.lang.String) - */ - @Override - public Item createFolder(String nameFolder, String description, String parentId) throws Exception { - - logger.debug("creating folder: "+nameFolder +", parent id: "+parentId); - - try { - - if(parentId==null || parentId.isEmpty()) - throw new Exception("Parent id is null or empty"); - - if(nameFolder == null) - nameFolder = "Empty Folder"; - - Workspace workspace = WsUtil.getWorkspace(this.getThreadLocalRequest().getSession()); - WorkspaceFolder wsFolder = workspace.createFolder(nameFolder, description, parentId); - List allTypes = Arrays.asList(ItemType.values()); - - Item parent = null; - try{ - String parentPath = wsFolder.getParent()!=null?wsFolder.getParent().getPath():""; - parent = ItemBuilder.getItem(null, wsFolder.getParent(), parentPath, allTypes, null, false); - }catch(Exception e){ - logger.error("Get parent thown an exception, is it the root id? "+parentId); - } - - //TODO PATCH TO AVOID PROBLEM ON GETPATH. FOR EXAMPLE WHEN PARENT IS ROOT - String itemPath = null; - try{ - itemPath = wsFolder.getPath(); - }catch(Exception e){ - logger.error("Get path thown an exception, for id: "+wsFolder.getId()); - itemPath= wsFolder.isFolder()?workspace.getRoot().getPath()+"/"+wsFolder.getName():workspace.getRoot().getPath(); - } - - return ItemBuilder.getItem(parent, wsFolder, itemPath, allTypes, null, false); - - } catch(InsufficientPrivilegesException e){ - String error = "Insufficient Privileges to create the folder"; - logger.error(error, e); - throw new Exception(error); - } catch (ItemAlreadyExistException e) { - String error = "An error occurred on creating folder, " +e.getMessage(); - logger.error(error, e); - throw new Exception(error); - } catch (Exception e) { - String error = "An error occurred on the sever during creating folder. Try again"; - logger.error(error, e); - throw new Exception(error); - } - - } +// /** +// * Creates the folder. +// * +// * @param nameFolder the name folder +// * @param description the description +// * @param parentId the parent id +// * @return the item +// * @throws Exception the exception +// */ +// /* (non-Javadoc) +// * @see org.gcube.portlets.user.workspaceexplorerapp.client.rpc.WorkspaceExplorerAppService#createFolder(java.lang.String, java.lang.String, java.lang.String) +// */ +// @Override +// public Item createFolder(String nameFolder, String description, String parentId) throws Exception { +// +// logger.debug("creating folder: "+nameFolder +", parent id: "+parentId); +// throw new WorkspaceNavigatorServiceException("The method 'createFolder' is not implemented"); +// +// /*try { +// +// if(parentId==null || parentId.isEmpty()) +// throw new Exception("Parent id is null or empty"); +// +// if(nameFolder == null) +// nameFolder = "Empty Folder"; +// +// Workspace workspace = getWorkspace(); +// WorkspaceFolder wsFolder = workspace.createFolder(nameFolder, description, parentId); +// List allTypes = Arrays.asList(ItemType.values()); +// +// Item parent = null; +// try{ +// String parentPath = wsFolder.getParent()!=null?wsFolder.getParent().getPath():""; +// parent = ItemBuilder.getItem(null, wsFolder.getParent(), parentPath, allTypes, null, false); +// }catch(Exception e){ +// logger.error("Get parent thown an exception, is it the root id? "+parentId); +// } +// +// //TODO PATCH TO AVOID PROBLEM ON GETPATH. FOR EXAMPLE WHEN PARENT IS ROOT +// String itemPath = null; +// try{ +// itemPath = wsFolder.getPath(); +// }catch(Exception e){ +// logger.error("Get path thown an exception, for id: "+wsFolder.getId()); +// itemPath= wsFolder.isFolder()?workspace.getRoot().getPath()+"/"+wsFolder.getName():workspace.getRoot().getPath(); +// } +// +// return ItemBuilder.getItem(parent, wsFolder, itemPath, allTypes, null, false); +// +// } catch(InsufficientPrivilegesException e){ +// String error = "Insufficient Privileges to create the folder"; +// logger.error(error, e); +// throw new Exception(error); +// } catch (ItemAlreadyExistException e) { +// String error = "An error occurred on creating folder, " +e.getMessage(); +// logger.error(error, e); +// throw new Exception(error); +// } catch (Exception e) { +// String error = "An error occurred on the sever during creating folder. Try again"; +// logger.error(error, e); +// throw new Exception(error); +// }*/ +// +// } /** @@ -703,31 +739,30 @@ public class WorkspaceExplorerAppServiceImpl extends RemoteServiceServlet implem try{ if(itemId==null) - throw new Exception("Sorry, The Public Link for empty item is unavailable (itemId is null)"); + throw new Exception("Sorry, the itemId is null. The public link for empty item is unavailable"); - Workspace workspace = WsUtil.getWorkspace(this.getThreadLocalRequest().getSession()); + Workspace workspace = getWorkspace(); WorkspaceItem wsItem = workspace.getItem(itemId); if(wsItem==null) - throw new Exception("Sorry, The Public Link for empty item is unavailable"); + throw new Exception("Sorry, the workspace item is null. The public link for empty item is unavailable"); - if(wsItem.getType().equals(WorkspaceItemType.FOLDER_ITEM)){ + if(wsItem instanceof FileItem){ - FolderItem folderItem = (FolderItem) wsItem; - String uriRequest = folderItem.getPublicLink(false); + URL theURL = workspace.getPublicLinkForFile(wsItem.getId()); - if(uriRequest==null || uriRequest.isEmpty()) - throw new Exception("Sorry, public link on "+folderItem.getName() +" is not available"); - - return uriRequest; + if(theURL==null) + throw new Exception("Sorry, the public link for "+wsItem.getName() +" is not available"); + + return theURL.toString(); }else{ logger.warn("ItemId: "+ itemId +" is not available, sent exception Public Link unavailable"); - throw new Exception("Sorry, The Public Link for selected item is unavailable"); + throw new Exception("Sorry, the Public Link for selected item is unavailable"); } }catch (Exception e) { - logger.error("Error getPublicLinkForItemId for item: "+itemId, e); + logger.error("Error on getting public link for item: "+itemId, e); throw new Exception(e.getMessage()); } diff --git a/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/server/ItemBuilder.java b/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/server/workspace/ItemBuilder.java similarity index 84% rename from src/main/java/org/gcube/portlets/user/workspaceexplorerapp/server/ItemBuilder.java rename to src/main/java/org/gcube/portlets/user/workspaceexplorerapp/server/workspace/ItemBuilder.java index 982b780..5cda3df 100644 --- a/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/server/ItemBuilder.java +++ b/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/server/workspace/ItemBuilder.java @@ -1,7 +1,7 @@ /** * */ -package org.gcube.portlets.user.workspaceexplorerapp.server; +package org.gcube.portlets.user.workspaceexplorerapp.server.workspace; import java.util.Calendar; import java.util.Date; @@ -12,8 +12,8 @@ import java.util.Map.Entry; 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.WorkspaceSharedFolder; +import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.InternalErrorException; import org.gcube.common.storagehubwrapper.shared.tohl.items.FileItem; import org.gcube.common.storagehubwrapper.shared.tohl.items.PropertyMap; import org.gcube.portlets.user.workspaceexplorerapp.client.Util; @@ -84,7 +84,7 @@ public class ItemBuilder { * @return the item * @throws InternalErrorException the internal error exception */ - public static Item getItem(Item parent, WorkspaceItem workspaceItem, String workspaceItemPath, List showableTypes, FilterCriteria filterCriteria, boolean loadChildren) throws Exception + public static Item getItem(Item parent, WorkspaceItem workspaceItem, String workspaceItemPath, List showableTypes, FilterCriteria filterCriteria) throws Exception { try { @@ -129,22 +129,22 @@ public class ItemBuilder { return null; } - if(loadChildren){ - //TODO A PATCH TO AVOID A SLOW GETPATH - // workspaceItemPath = workspaceItem.getPath(); - for (WorkspaceItem child: workspaceItem.getChildren()){ - String itemPath = workspaceItemPath; - if(child.isFolder()) - itemPath+="/"+child.getName(); - - // _log.trace("\nConverting child item: "+child.getName()); - Item itemChild = getItem(item, child, itemPath, showableTypes, filterCriteria, false); - // _log.trace("Item: "+child.getName() +" converted!!!"); - if (itemChild!=null){ - item.addChild(itemChild); - } - } - } +// if(loadChildren){ +// //TODO A PATCH TO AVOID A SLOW GETPATH +// // workspaceItemPath = workspaceItem.getPath(); +// for (WorkspaceItem child: workspaceItem.getChildren()){ +// String itemPath = workspaceItemPath; +// if(child.isFolder()) +// itemPath+="/"+child.getName(); +// +// // _log.trace("\nConverting child item: "+child.getName()); +// Item itemChild = getItem(item, child, itemPath, showableTypes, filterCriteria, false); +// // _log.trace("Item: "+child.getName() +" converted!!!"); +// if (itemChild!=null){ +// item.addChild(itemChild); +// } +// } +// } return item; }catch (Exception e) { @@ -152,6 +152,42 @@ public class ItemBuilder { throw new Exception("Error on retrieving the item: "+workspaceItem.getName()); } } + + + /** + * Adds the children. + * + * @param item the item + * @param itemPathBuilt the item path built + * @param children the children + * @param showableTypes the showable types + * @param filterCriteria the filter criteria + * @return the item with the children added + * @throws Exception the exception + */ + public static Item addChildren(Item item, String itemPathBuilt, List children, List showableTypes, FilterCriteria filterCriteria) throws Exception { + + if(item==null) + return null; + + if(children==null) + return item; + + for (WorkspaceItem child: children){ + String itemPath = itemPathBuilt; + if(child.isFolder()) { + itemPath+="/"+child.getName(); + } + + Item itemChild = getItem(item, child, itemPath, showableTypes, filterCriteria); +// _log.trace("Item: "+child.getName() +" converted!!!"); + if (itemChild!=null){ + item.addChild(itemChild); + } + } + + return item; + } /** @@ -375,7 +411,7 @@ public class ItemBuilder { //name = shared.isVreFolder()?shared.getDisplayName():wsFolder.getName(); name = shared.isVreFolder()?shared.getName():wsFolder.getName(); //not implemented by SHUB - }else if(isSpecialFolder(wsFolder)){ + }else {if(isSpecialFolder(wsFolder)){ //MANAGEMENT SPECIAL FOLDER name = WorkspaceExplorerAppConstants.VRE_FOLDERS_LABEL; isSpecialFolder = true; @@ -399,10 +435,10 @@ public class ItemBuilder { * @param wsFolder the ws folder * @return true, if is special folder */ - public static boolean isSpecialFolder(WorkspaceFolder wsFolder){ + public static boolean isSpecialFolder(WorkspaceFolder wsFolder, boolean parentIsRoot){ try { - return wsFolder.getName().compareTo(WorkspaceExplorerAppConstants.SPECIAL_FOLDERS_NAME)==0 && wsFolder.getParentId()!=null && wsFolder.getParent().isRoot(); + return wsFolder.getName().compareTo(WorkspaceExplorerAppConstants.SPECIAL_FOLDERS_NAME)==0 && wsFolder.getParentId()!=null && parentIsRoot; } catch (Exception e) { _log.warn("isSpecialFolder exception, returning false"); return false; diff --git a/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/server/WsUtil.java b/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/server/workspace/WsUtil.java similarity index 85% rename from src/main/java/org/gcube/portlets/user/workspaceexplorerapp/server/WsUtil.java rename to src/main/java/org/gcube/portlets/user/workspaceexplorerapp/server/workspace/WsUtil.java index 5164631..74d10b3 100644 --- a/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/server/WsUtil.java +++ b/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/server/workspace/WsUtil.java @@ -1,7 +1,7 @@ /** * */ -package org.gcube.portlets.user.workspaceexplorerapp.server; +package org.gcube.portlets.user.workspaceexplorerapp.server.workspace; import javax.servlet.http.HttpSession; @@ -9,11 +9,12 @@ import org.gcube.common.storagehubwrapper.server.StorageHubWrapper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -// TODO: Auto-generated Javadoc + /** * The Class WsUtil. * - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Sep 13, 2016 + * @author Francesco Mangiacrapa at ISTI-CNR Pisa (Italy) + * Apr 9, 2020 */ public class WsUtil { @@ -28,7 +29,7 @@ public class WsUtil { * @return the storage hub wrapper * @throws Exception the exception */ - public static StorageHubWrapper getStorageHubWrapper(HttpSession httpSession) throws Exception { + private static StorageHubWrapper getStorageHubWrapper(HttpSession httpSession) throws Exception { try { String scope = getScope(httpSession); @@ -52,7 +53,7 @@ public class WsUtil { * @return the workpace * @throws Exception the exception */ - public static org.gcube.common.storagehubwrapper.server.tohl.Workspace getWorkspace(HttpSession httpSession) throws Exception { + protected static org.gcube.common.storagehubwrapper.server.tohl.Workspace getWorkspace(HttpSession httpSession) throws Exception { try { StorageHubWrapper wrapper = getStorageHubWrapper(httpSession);