From 06b3a2a987b899c13fb567d71ccbffa46f3d710c Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Wed, 8 Apr 2020 18:17:48 +0200 Subject: [PATCH] starting migration to SHUB --- .classpath | 5 - ...se.wst.common.project.facet.core.prefs.xml | 7 ++ ....eclipse.wst.common.project.facet.core.xml | 1 + pom.xml | 30 ++--- .../server/ItemBuilder.java | 45 ++++---- .../WorkspaceExplorerAppServiceImpl.java | 12 +- .../workspaceexplorerapp/server/WsUtil.java | 103 ++++++++++++------ .../workspaceexplorerapp/shared/ItemType.java | 43 +++++--- 8 files changed, 143 insertions(+), 103 deletions(-) create mode 100644 .settings/org.eclipse.wst.common.project.facet.core.prefs.xml diff --git a/.classpath b/.classpath index 3754268..8a11f23 100644 --- a/.classpath +++ b/.classpath @@ -17,11 +17,6 @@ - - - - - diff --git a/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml b/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml new file mode 100644 index 0000000..cc81385 --- /dev/null +++ b/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/.settings/org.eclipse.wst.common.project.facet.core.xml b/.settings/org.eclipse.wst.common.project.facet.core.xml index ee39ed3..430a1c8 100644 --- a/.settings/org.eclipse.wst.common.project.facet.core.xml +++ b/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -2,4 +2,5 @@ + diff --git a/pom.xml b/pom.xml index 09f0291..5a433ed 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ org.gcube.portlets.user workspace-explorer-app - 1.2.0-SNAPSHOT + 1.3.0-SNAPSHOT war @@ -73,7 +73,6 @@ compile - com.github.gwtmaterialdesign @@ -114,24 +113,16 @@ - - - - - - - + + + + org.gcube.common + storagehub-client-wrapper + [0.0.1, 1.0.0-SNAPSHOT) + compile @@ -166,13 +163,6 @@ 1.8 - - - - - - - org.slf4j @@ -249,7 +239,7 @@ org.apache.maven.plugins maven-war-plugin - ${maven-war-plugin.version} + compile diff --git a/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/server/ItemBuilder.java b/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/server/ItemBuilder.java index 1f2f933..9afed8c 100644 --- a/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/server/ItemBuilder.java +++ b/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/server/ItemBuilder.java @@ -10,13 +10,8 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; -import org.gcube.common.homelibary.model.items.type.WorkspaceItemType; -import org.gcube.common.homelibrary.home.exceptions.InternalErrorException; -import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder; -import org.gcube.common.homelibrary.home.workspace.WorkspaceItem; -import org.gcube.common.homelibrary.home.workspace.WorkspaceSharedFolder; -import org.gcube.common.homelibrary.home.workspace.folder.FolderItem; -import org.gcube.common.homelibrary.home.workspace.folder.items.ExternalFile; +import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem; +import org.gcube.common.storagehubwrapper.shared.tohl.items.FileItem; import org.gcube.portlets.user.workspaceexplorerapp.client.Util; import org.gcube.portlets.user.workspaceexplorerapp.client.WorkspaceExplorerAppConstants; import org.gcube.portlets.user.workspaceexplorerapp.shared.FilterCriteria; @@ -163,32 +158,38 @@ public class ItemBuilder { * @return the item type * @throws InternalErrorException the internal error exception */ - protected static ItemType getItemType(WorkspaceItem item) throws InternalErrorException - { - switch(item.getType()) - { - case SHARED_FOLDER: - case FOLDER:{ + protected static ItemType getItemType(WorkspaceItem item) { + switch (item.getType()) { + case SHARED_FOLDER: + case FOLDER: { // if (item.isRoot()) return ItemType.ROOT; - return ItemType.FOLDER; - } - case FOLDER_ITEM: return getFolderItemType((FolderItem) item); + return ItemType.FOLDER; + } + case FILE_ITEM: - default: - return null; + if (item instanceof FileItem) + + return getFileItemType((FileItem) item); + + else + return ItemType.UNKNOWN_TYPE; + + default: + return null; } } + /** - * Gets the folder item type. + * Gets the file item type. * * @param item the item - * @return the folder item type + * @return the file item type */ - protected static ItemType getFolderItemType(FolderItem item){ + protected static ItemType getFileItemType(FileItem item){ try{ - return ItemType.valueOf(item.getFolderItemType().toString()); + return ItemType.valueOf(item.getFileItemType().toString()); }catch (Exception e) { _log.error("Item Type non found: ",e); return ItemType.UNKNOWN_TYPE; 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 610dfa3..5ab7f41 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 @@ -7,15 +7,9 @@ import java.util.List; import java.util.concurrent.TimeUnit; import org.gcube.common.encryption.StringEncrypter; -import org.gcube.common.homelibary.model.items.type.WorkspaceItemType; -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.WorkspaceSharedFolder; -import org.gcube.common.homelibrary.home.workspace.exceptions.InsufficientPrivilegesException; -import org.gcube.common.homelibrary.home.workspace.exceptions.ItemAlreadyExistException; -import org.gcube.common.homelibrary.home.workspace.folder.FolderItem; import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.common.storagehubwrapper.server.tohl.Workspace; +import org.gcube.common.storagehubwrapper.shared.tohl.impl.WorkspaceFolder; import org.gcube.portlets.user.workspaceexplorerapp.client.WorkspaceExplorerAppConstants; import org.gcube.portlets.user.workspaceexplorerapp.client.rpc.WorkspaceExplorerAppService; import org.gcube.portlets.user.workspaceexplorerapp.shared.FilterCriteria; @@ -57,7 +51,7 @@ public class WorkspaceExplorerAppServiceImpl extends RemoteServiceServlet implem Workspace workspace = WsUtil.getWorkspace(this.getThreadLocalRequest().getSession()); logger.trace("Start getRoot..."); - WorkspaceItem root = workspace.getRoot(); + org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder root = workspace.getRoot(); logger.trace("GetRoot - Replyiing root"); long startTime = System.currentTimeMillis(); diff --git a/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/server/WsUtil.java b/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/server/WsUtil.java index 927b2a3..f4516d1 100644 --- a/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/server/WsUtil.java +++ b/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/server/WsUtil.java @@ -5,22 +5,15 @@ package org.gcube.portlets.user.workspaceexplorerapp.server; import javax.servlet.http.HttpSession; -import org.gcube.common.homelibrary.home.HomeLibrary; -import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException; -import org.gcube.common.homelibrary.home.exceptions.InternalErrorException; -import org.gcube.common.homelibrary.home.exceptions.UserNotFoundException; -import org.gcube.common.homelibrary.home.workspace.Workspace; -import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException; -import org.gcube.common.scope.api.ScopeProvider; +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 francesco.mangiacrapa@isti.cnr.it Sep 13, 2016 */ public class WsUtil { @@ -29,40 +22,88 @@ public class WsUtil { public static final String SESSION_SCOPE = "session_scope"; /** - * Gets the workspace. + * Gets the storage hub wrapper. * * @param httpSession the http session - * @return the workspace - * @throws InternalErrorException the internal error exception - * @throws HomeNotFoundException the home not found exception - * @throws WorkspaceFolderNotFoundException the workspace folder not found exception - * @throws UserNotFoundException the user not found exception + * @return the storage hub wrapper + * @throws Exception the exception */ - public static Workspace getWorkspace(HttpSession httpSession) throws InternalErrorException, HomeNotFoundException, WorkspaceFolderNotFoundException, UserNotFoundException { -// ASLSession session = getASLSession(httpSession); + public static StorageHubWrapper getStorageHubWrapper(HttpSession httpSession) throws Exception { - String scope = getScope(httpSession); - //GET CONTEXT - logger.info("Setting scope: "+scope); - ScopeProvider.instance.set(scope); - return HomeLibrary.getHomeManagerFactory().getHomeManager().getGuestLogin().getWorkspace(); + try { + String scope = getScope(httpSession); + // TODO + String token = "MUST BE PROVIDED"; + logger.debug("Getting " + StorageHubWrapper.class.getSimpleName() + + " by token: " + token.substring(0, 10) +" MASKED TOKEN" + + " by using the scope: " + scope); + + return new StorageHubWrapper(scope, token, false, false, true); + } catch (Exception e) { + logger.error("Error during getting storageHub wrapper", e); + throw new Exception("Error on inizializing the StorageHub"); + } } + + + /** + * Gets the workpace. + * + * @param httpSession the http session + * @return the workpace + * @throws Exception the exception + */ + public static org.gcube.common.storagehubwrapper.server.tohl.Workspace getWorkspace(HttpSession httpSession) throws Exception { + + try { + StorageHubWrapper wrapper = getStorageHubWrapper(httpSession); + return wrapper.getWorkspace(); + } catch (Exception e) { + logger.error("Error on getting the Workspace", e); + throw new Exception("Error on getting the Workspace"); + } + } + +// /** +// * Gets the workspace. +// * +// * @param httpSession the http session +// * @return the workspace +// * @throws InternalErrorException the internal error exception +// * @throws HomeNotFoundException the home not found exception +// * @throws WorkspaceFolderNotFoundException the workspace folder not found +// * exception +// * @throws UserNotFoundException the user not found exception +// */ +// public static Workspace getWorkspace(HttpSession httpSession) throws InternalErrorException, HomeNotFoundException, +// WorkspaceFolderNotFoundException, UserNotFoundException { +//// ASLSession session = getASLSession(httpSession); +// +// String scope = getScope(httpSession); +// // GET CONTEXT +// logger.info("Setting scope: " + scope); +// ScopeProvider.instance.set(scope); +// return HomeLibrary.getHomeManagerFactory().getHomeManager().getGuestLogin().getWorkspace(); +// } /** * Gets the scope. * + * @param httpSession the http session * @return the scope */ - public static String getScope(HttpSession httpSession){ - String scope = (String) httpSession.getAttribute(SESSION_SCOPE); - logger.info("Variable "+SESSION_SCOPE + " read from httpsession is: "+scope); + public static String getScope(HttpSession httpSession) { + String scope = (String) httpSession.getAttribute(SESSION_SCOPE); + logger.info("Variable " + SESSION_SCOPE + " read from httpsession is: " + scope); - if(scope==null){ - logger.info("Variable "+SESSION_SCOPE + " is null reading from web.xml context"); - String variableScopeName = httpSession.getServletContext().getInitParameter(ENVIRONMENT_VARIABLE_SCOPE_NAME); - logger.info("Found param-value '"+variableScopeName+"' from web context, reading its value from ENVIRONMENT"); + if (scope == null) { + logger.info("Variable " + SESSION_SCOPE + " is null reading from web.xml context"); + String variableScopeName = httpSession.getServletContext() + .getInitParameter(ENVIRONMENT_VARIABLE_SCOPE_NAME); + logger.info("Found param-value '" + variableScopeName + + "' from web context, reading its value from ENVIRONMENT"); scope = System.getenv(variableScopeName); - logger.info("Value of "+variableScopeName+" from ENVIRONMENT is: "+scope); + logger.info("Value of " + variableScopeName + " from ENVIRONMENT is: " + scope); } httpSession.setAttribute(ENVIRONMENT_VARIABLE_SCOPE_NAME, scope); diff --git a/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/shared/ItemType.java b/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/shared/ItemType.java index e71f6b7..17d73e8 100644 --- a/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/shared/ItemType.java +++ b/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/shared/ItemType.java @@ -3,29 +3,40 @@ */ package org.gcube.portlets.user.workspaceexplorerapp.shared; - /** * The Enum ItemType. * - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Jun 18, 2015 + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Jun 18, 2015 */ public enum ItemType { - - FOLDER, //MANDATORY - EXTERNAL_IMAGE, - EXTERNAL_FILE, - EXTERNAL_PDF_FILE, - EXTERNAL_URL, - QUERY, - REPORT_TEMPLATE, - REPORT, + + FOLDER, + + // KINDS OF FILES + /** + * Document. + */ DOCUMENT, - METADATA, - PDF_DOCUMENT, + /** + * Image document. + */ IMAGE_DOCUMENT, + /** + * PDF document. + */ + PDF_DOCUMENT, + /** + * Url document. + */ URL_DOCUMENT, + /** + * Metadata. + */ + METADATA, + /** + * A gCube item. + */ GCUBE_ITEM, - TIME_SERIES, - UNKNOWN_TYPE; + + UNKNOWN_TYPE }