From 1ffc7616c93ca8e2d79601d98dc4c32ecc97d035 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Mon, 10 May 2021 17:01:32 +0200 Subject: [PATCH 01/20] starting on #21379 --- pom.xml | 9 +- .../wsthreddssync/server/BeanConverter.java | 26 ++-- .../server/SyncronizeWithThredds.java | 112 ++++++++++++++++-- .../ThreddsWorkspaceSyncServiceImpl.java | 95 ++++++--------- 4 files changed, 163 insertions(+), 79 deletions(-) diff --git a/pom.xml b/pom.xml index 0914765..61da039 100644 --- a/pom.xml +++ b/pom.xml @@ -42,7 +42,7 @@ org.gcube.distribution maven-portal-bom - 3.6.0 + 3.6.1 pom import @@ -88,6 +88,13 @@ [1.0.0, 2.0.0-SNAPSHOT) + + org.gcube.portal + oidc-library-portal + [1.0.0, 2.0.0-SNAPSHOT) + provided + + diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/BeanConverter.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/BeanConverter.java index 5fa7a67..3593a6f 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/BeanConverter.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/BeanConverter.java @@ -14,6 +14,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +// TODO: Auto-generated Javadoc /** * The Class BeanConverter. * @@ -36,7 +37,7 @@ public class BeanConverter { public static WsThreddsSynchFolderDescriptor toWsThreddsFolderConfig(ThSyncFolderDescriptor t, Sync_Status theStatus) { - if (t == null) + if (t == null || t.getConfiguration()==null) return null; WsThreddsSynchFolderDescriptor ws = new WsThreddsSynchFolderDescriptor(); @@ -45,16 +46,16 @@ public class BeanConverter { // FROM TARGET TOKEN TO SCOPE // t.getConfiguration().getTargetToken() + + String targetContext = t.getConfiguration().getTargetContext(); - if (t.getConfiguration().getTargetToken() != null) { + if (targetContext != null) { try { - AuthorizationEntry entry = authorizationService().get(t.getConfiguration().getTargetToken()); - String scope = entry.getContext(); - GcubeScope selectedScope = new GcubeScope(toScopeTitle(scope), scope, toGcubeScope(scope)); + GcubeScope selectedScope = new GcubeScope(toScopeTitle(targetContext), targetContext, toGcubeScope(targetContext)); ws.setSelectedScope(selectedScope); - logger.debug("Resolved SCOPE: " + selectedScope + " from token"); + logger.debug("Got target SCOPE: " + selectedScope + " from configuration"); } catch (Exception e) { - logger.error("I cannot resolve the scope for the token: "+t.getConfiguration().getTargetToken()); + logger.error("I cannot read the scope for: "+targetContext); } } @@ -104,16 +105,17 @@ public class BeanConverter { } } + /** * To th synch folder configuration. * - * @param t the t - * @param rootFolderId the root folder id - * @param targetScopeUserToken the target scope user token + * @param t the t + * @param rootFolderId the root folder id + * @param targetContext the target context * @return the th synch folder configuration */ public static ThSynchFolderConfiguration toThSynchFolderConfiguration(WsThreddsSynchFolderConfiguration t, - String rootFolderId, String targetScopeUserToken) { + String rootFolderId, String targetContext) { if (t == null) return null; @@ -121,7 +123,7 @@ public class BeanConverter { ThSynchFolderConfiguration ts = new ThSynchFolderConfiguration(); ts.setFilter(t.getFilter()); ts.setRemotePath(t.getRemotePath()); - ts.setTargetToken(targetScopeUserToken); + ts.setTargetContext(targetContext); ts.setToCreateCatalogName(t.getCatalogName()); ts.setRootFolderId(rootFolderId); return ts; diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java index c6bd2be..5ca8e2c 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java @@ -5,8 +5,14 @@ package org.gcube.portlets.widgets.wsthreddssync.server; import java.util.List; +import javax.servlet.http.HttpServletRequest; + import org.gcube.common.authorization.library.provider.SecurityTokenProvider; +import org.gcube.common.authorization.library.provider.UmaJWTProvider; +import org.gcube.common.portal.PortalContext; import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.oidc.rest.JWTToken; +import org.gcube.portal.oidc.lr62.OIDCUmaUtil; import org.gcube.portal.wssynclibrary.shared.ItemNotSynched; import org.gcube.portal.wssynclibrary.shared.WorkspaceFolderLocked; import org.gcube.portal.wssynclibrary.shared.thredds.Sync_Status; @@ -15,9 +21,11 @@ import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncFolderDescriptor; import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus; import org.gcube.portal.wssynclibrary.shared.thredds.ThSynchFolderConfiguration; import org.gcube.portal.wssynclibrary.thredds.WorkspaceThreddsSynchronize; +import org.gcube.vomanagement.usermanagement.model.GCubeUser; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +// TODO: Auto-generated Javadoc /** * The Class SyncronizeWithThredds. * @@ -61,6 +69,54 @@ public class SyncronizeWithThredds { SecurityTokenProvider.instance.set(userToken); } + + /** + * Change context for UMA. + * + * @param httpRequest the http request + * @param user the user + * @param targetScope the target scope + * @return the string representing the previous UMA Token read from {@link UmaJWTProvider#get()} + */ + private String changeContextForUMA(HttpServletRequest httpRequest, GCubeUser user, String targetScope) { + logger.debug("Setting UMA context with target scope: "+targetScope +", user: "+user.getUsername()); + String previousUMAToken = null; + try { + previousUMAToken=UmaJWTProvider.instance.get(); + JWTToken umaToken = OIDCUmaUtil.getUMAToken(httpRequest, user.getUsername(), targetScope); + setContextForUMA(umaToken.getRaw()); + }catch (Exception e) { + logger.warn("Error on set context for UMA: ",e); + if(previousUMAToken!=null) { + logger.info("Setting previous UMA Token: "+previousUMAToken.substring(0,10)+"-MASKED-TOKEN"); + setContextForUMA(previousUMAToken); + } + } + + return previousUMAToken; + } + + /** + * Reset context for UMA. + * + * @param umaToken the uma token + * @return the string + */ + private void setContextForUMA(String umaToken) { + logger.info("called set context for UMA"); + + if(umaToken==null || umaToken.isEmpty()) { + logger.info("Uma Token is null or empty, skipping operation"); + return; + } + + logger.info("Going to set UMA Token: "+umaToken.substring(0,10)+"-MASKED-TOKEN"); + UmaJWTProvider.instance.set(umaToken); + logger.debug("UmaJWTProvider instance set performed to : "+umaToken.substring(0,10)+"-MASKED-TOKEN"); + + } + + /** * Do sync folder. @@ -225,19 +281,57 @@ public class SyncronizeWithThredds { } - /** - * Gets the available catalogues by token. + * Gets the available catalogues. * - * @param scope the scope - * @param userToken the user token - * @param targetToken the target token - * @return the available catalogues by token + * @param httpRequest the http request + * @param user the user + * @param targetScope the target scope + * @return the available catalogues * @throws Exception the exception */ - public List getAvailableCataloguesByToken(String scope, String userToken, String targetToken) throws Exception { - setContextParameters(scope, userToken); - return workspaceThreddsSynchronize.getAvailableCataloguesByToken(targetToken); + public List getAvailableCatalogues(HttpServletRequest httpRequest, GCubeUser user, + String targetScope) throws Exception { + String originalScope = null; + String originalToken = null; + String previousUmaToken = null; + List listCatalogues = null; + try { + // context switch for Uma token + previousUmaToken = changeContextForUMA(httpRequest, user, targetScope); + + // context switch for gcube-token and scope + PortalContext pConfig = PortalContext.getConfiguration(); + String wsScope = pConfig.getCurrentScope(httpRequest); + String wsUserToken = pConfig.getCurrentUserToken(wsScope, user.getUsername()); + // Thread Local contexts + originalScope = wsScope; + originalToken = wsUserToken; + // getting token into target scope + String targetScopeUserToken = PortalContext.getConfiguration().getCurrentUserToken(targetScope, + user.getUsername()); + setContextParameters(targetScope, targetScopeUserToken); + + // calling the engine + listCatalogues = workspaceThreddsSynchronize.getAvailableCatalogues(); + } catch (Exception e) { + logger.error("Error on getting available Catalogues in the scope: " + targetScope, e); + } finally { + + // resetting UMA token in the WS scope + setContextForUMA(previousUmaToken); + + if (originalScope != null && originalScope.compareTo(targetScope) != 0) { + logger.info("Resetting the scope: " + originalScope + " which was original WS context"); + ScopeProvider.instance.set(originalScope); + if (originalToken != null) { + logger.info("Resetting the user token: " + originalToken.substring(0, 10) + + "-MASKED-TOKEN which was original WS context"); + SecurityTokenProvider.instance.set(originalToken); + } + } + } + return listCatalogues; } } diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java index 373e869..9125512 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java @@ -82,6 +82,40 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem return false; } } + + //MOVED + + /** + * Gets the available THREDDS catalogues for target scope. + * + * @param targetFullScope the target scope + * @return the available catalogues for scope + * @throws Exception the exception + */ + @Override + public List getAvailableCataloguesForScope(String targetFullScope) throws Exception { + + if(targetFullScope==null) + throw new Exception("Invalid scope null"); + + List listCtlgs = null; + try { + GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); + listCtlgs = getSyncService().getAvailableCatalogues(this.getThreadLocalRequest(), user, targetFullScope); + + logger.debug("Retuning "+listCtlgs.size()+" Catalogues for scope: "+targetFullScope); + if(logger.isDebugEnabled()){ + for (ThCatalogueBean thCatalogueBean : listCtlgs) { + logger.debug(thCatalogueBean.toString()); + } + } + }catch (Exception e) { + logger.error("Error on checking available Catalogue in the scope: "+targetFullScope, e); + } + + return listCtlgs; + } + @@ -102,12 +136,11 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem try { GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); - String targetScopeUserToken = null; ThSynchFolderConfiguration config = null; - if(clientConfig!=null) { - targetScopeUserToken = PortalContext.getConfiguration().getCurrentUserToken(clientConfig.getSelectedScope().getScopeName(), user.getUsername()); - config = BeanConverter.toThSynchFolderConfiguration(clientConfig, folderId, targetScopeUserToken); - logger.debug("Creating server config "+config); + if (clientConfig != null && clientConfig.getSelectedScope() != null) { + config = BeanConverter.toThSynchFolderConfiguration(clientConfig, folderId, + clientConfig.getSelectedScope().getScopeName()); + logger.debug("Creating server config " + config); } logger.info("Calling doSyncFolder on folderId: "+folderId +", config: "+config); @@ -125,58 +158,6 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem } - - /** - * Gets the available THREDDS catalogues for target scope. - * - * @param targetFullScope the target scope - * @return the available catalogues for scope - * @throws Exception the exception - */ - @Override - public List getAvailableCataloguesForScope(String targetFullScope) throws Exception { - - if(targetFullScope==null) - throw new Exception("Invalid scope null"); - - String originalScope = null; - String originalToken = null; - List listCtlgs = null; - try { - GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); - String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest()); - String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername()); - //Thread Local contexts - originalScope = wsScope; - originalToken = wsUserToken; - - String targetScopeUserToken = PortalContext.getConfiguration().getCurrentUserToken(targetFullScope, user.getUsername()); - listCtlgs = getSyncService().getAvailableCataloguesByToken(targetFullScope, wsUserToken, targetScopeUserToken); - - logger.debug("Retuning "+listCtlgs.size()+" Catalogues for scope: "+targetFullScope); - if(logger.isDebugEnabled()){ - for (ThCatalogueBean thCatalogueBean : listCtlgs) { - logger.debug(thCatalogueBean.toString()); - } - } - }catch (Exception e) { - logger.error("Error on checking available Catalogue in the scope: "+targetFullScope, e); - }finally { - - if(originalScope!=null && originalScope.compareTo(targetFullScope)!=0) { - logger.info("Resetting the scope: "+originalScope + " which was original WS context"); - ScopeProvider.instance.set(originalScope); - if(originalToken!=null) { - logger.info("Resetting the user token: "+originalToken.substring(0,10)+"-MASKED-TOKEN which was original WS context"); - SecurityTokenProvider.instance.set(originalToken); - } - - } - } - - return listCtlgs; - } - /** * Gets the list of Scopes (Root-VO, VOs and VREs) for user and the Thredds roles that user has in them. -- 2.17.1 From 5d027814f07df4ab57bb5a26bfa103d83357baf1 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Mon, 10 May 2021 17:01:57 +0200 Subject: [PATCH 02/20] moved to 1.4.0-SNAPSHOT --- CHANGELOG.md | 6 ++++++ pom.xml | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c458be6..5206acd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,12 @@ 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-05-10 + +[#20847] Support the roles of THREDDS Admin and THREDDS Publisher + + ## [v1.3.0] - 2021-03-17 [#20847] Support the roles of THREDDS Admin and THREDDS Publisher diff --git a/pom.xml b/pom.xml index 61da039..3df5f35 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ org.gcube.portlets.widgets ws-thredds-sync-widget jar - 1.3.0 + 1.4.0-SNAPSHOT ws-thredds-sync-widget gCube ws-thredds-sync-widget is a widget to use and interact with ws-thredds facility in order to syncronize the Workspace folders with Thredds Reporitory folders -- 2.17.1 From f2dc0cce19ed189a9a4b3a1d1de292e55a80aaf2 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Mon, 10 May 2021 18:08:39 +0200 Subject: [PATCH 03/20] in progess --- .../wsthreddssync/server/BeanConverter.java | 3 - .../server/SyncronizeWithThredds.java | 251 +++++++++--------- .../ThreddsWorkspaceSyncServiceImpl.java | 109 ++++---- .../WsThreddsSynchFolderDescriptor.java | 10 +- 4 files changed, 196 insertions(+), 177 deletions(-) diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/BeanConverter.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/BeanConverter.java index 3593a6f..e57055b 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/BeanConverter.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/BeanConverter.java @@ -1,8 +1,5 @@ package org.gcube.portlets.widgets.wsthreddssync.server; -import static org.gcube.common.authorization.client.Constants.authorizationService; - -import org.gcube.common.authorization.library.AuthorizationEntry; import org.gcube.portal.wssynclibrary.shared.thredds.Sync_Status; import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncFolderDescriptor; import org.gcube.portal.wssynclibrary.shared.thredds.ThSynchFolderConfiguration; diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java index 5ca8e2c..c41c12e 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java @@ -21,6 +21,7 @@ import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncFolderDescriptor; import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus; import org.gcube.portal.wssynclibrary.shared.thredds.ThSynchFolderConfiguration; import org.gcube.portal.wssynclibrary.thredds.WorkspaceThreddsSynchronize; +import org.gcube.usecases.ws.thredds.faults.WorkspaceNotSynchedException; import org.gcube.vomanagement.usermanagement.model.GCubeUser; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -44,55 +45,54 @@ public class SyncronizeWithThredds { /** The Constant sdf. */ //private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss"); - /** * Instantiates a new publish on thredds. * * @param wsScopeUserToken the ws scope user token - * @param username the username - * @param httpSession the http session + * @param username the username + * @param httpSession the http session */ public SyncronizeWithThredds() { this.workspaceThreddsSynchronize = WorkspaceThreddsSynchronize.getInstance(); } - /** * Sets the context parameters. * - * @param scope the scope + * @param scope the scope * @param userToken the user token */ private void setContextParameters(String scope, String userToken) { - logger.debug("Setting context parameters with scope: "+scope +", user token: "+userToken.substring(0,10)+"-MASKED-TOKEN"); + logger.debug("Setting context parameters with scope: " + scope + ", user token: " + userToken.substring(0, 10) + + "-MASKED-TOKEN"); ScopeProvider.instance.set(scope); SecurityTokenProvider.instance.set(userToken); } - /** * Change context for UMA. * * @param httpRequest the http request - * @param user the user + * @param user the user * @param targetScope the target scope - * @return the string representing the previous UMA Token read from {@link UmaJWTProvider#get()} + * @return the string representing the previous UMA Token read from + * {@link UmaJWTProvider#get()} */ private String changeContextForUMA(HttpServletRequest httpRequest, GCubeUser user, String targetScope) { - logger.debug("Setting UMA context with target scope: "+targetScope +", user: "+user.getUsername()); + logger.debug("Setting UMA context with target scope: " + targetScope + ", user: " + user.getUsername()); String previousUMAToken = null; try { - previousUMAToken=UmaJWTProvider.instance.get(); + previousUMAToken = UmaJWTProvider.instance.get(); JWTToken umaToken = OIDCUmaUtil.getUMAToken(httpRequest, user.getUsername(), targetScope); setContextForUMA(umaToken.getRaw()); - }catch (Exception e) { - logger.warn("Error on set context for UMA: ",e); - if(previousUMAToken!=null) { - logger.info("Setting previous UMA Token: "+previousUMAToken.substring(0,10)+"-MASKED-TOKEN"); + } catch (Exception e) { + logger.warn("Error on set context for UMA: ", e); + if (previousUMAToken != null) { + logger.info("Setting previous UMA Token: " + previousUMAToken.substring(0, 10) + "-MASKED-TOKEN"); setContextForUMA(previousUMAToken); } } - + return previousUMAToken; } @@ -104,18 +104,103 @@ public class SyncronizeWithThredds { */ private void setContextForUMA(String umaToken) { logger.info("called set context for UMA"); - - if(umaToken==null || umaToken.isEmpty()) { + + if (umaToken == null || umaToken.isEmpty()) { logger.info("Uma Token is null or empty, skipping operation"); return; } - - logger.info("Going to set UMA Token: "+umaToken.substring(0,10)+"-MASKED-TOKEN"); + + logger.info("Going to set UMA Token: " + umaToken.substring(0, 10) + "-MASKED-TOKEN"); UmaJWTProvider.instance.set(umaToken); - logger.debug("UmaJWTProvider instance set performed to : "+umaToken.substring(0,10)+"-MASKED-TOKEN"); - + logger.debug("UmaJWTProvider instance set performed to : " + umaToken.substring(0, 10) + "-MASKED-TOKEN"); + } + + /** + * Checks if is item synched. + * + * @param folderId the folder id + * @return the th sync folder descriptor + * @throws ItemNotSynched the item not synched + * @throws Exception the exception + */ + public ThSyncFolderDescriptor isItemSynched(String folderId) throws ItemNotSynched, Exception { + ThSyncFolderDescriptor config = null; + try { + config = workspaceThreddsSynchronize.getConfiguration(folderId); + } catch (WorkspaceNotSynchedException e) { + logger.debug("WorkspaceNotSynchedException catched, the item id: " + folderId + " is not synched"); + throw new ItemNotSynched("the item id: " + folderId + " is not synched"); + } catch (Exception e) { + logger.debug("Error on getting configuration for the item id: " + folderId + ", returning null (means not synched)"); + return null; + } + + return config; + } + + /** + * Gets the available catalogues. + * + * @param httpRequest the http request + * @param user the user + * @param targetScope the target scope + * @return the available catalogues + * @throws Exception the exception + */ + public List getAvailableCatalogues(HttpServletRequest httpRequest, GCubeUser user, + String targetScope) throws Exception { + String originalScope = null; + String originalToken = null; + String previousUmaToken = null; + List listCatalogues = null; + try { + // context switch for Uma token + previousUmaToken = changeContextForUMA(httpRequest, user, targetScope); + + // context switch for gcube-token and scope + PortalContext pConfig = PortalContext.getConfiguration(); + String wsScope = pConfig.getCurrentScope(httpRequest); + String wsUserToken = pConfig.getCurrentUserToken(wsScope, user.getUsername()); + // Thread Local contexts + originalScope = wsScope; + originalToken = wsUserToken; + // getting token into target scope + String targetScopeUserToken = PortalContext.getConfiguration().getCurrentUserToken(targetScope, + user.getUsername()); + setContextParameters(targetScope, targetScopeUserToken); + + // calling the engine + listCatalogues = workspaceThreddsSynchronize.getAvailableCatalogues(); + } catch (Exception e) { + logger.error("Error on getting available Catalogues in the scope: " + targetScope, e); + } finally { + + // resetting UMA token in the WS scope + setContextForUMA(previousUmaToken); + + if (originalScope != null && originalScope.compareTo(targetScope) != 0) { + logger.info("Resetting the scope: " + originalScope + " which was original WS context"); + ScopeProvider.instance.set(originalScope); + if (originalToken != null) { + logger.info("Resetting the user token: " + originalToken.substring(0, 10) + + "-MASKED-TOKEN which was original WS context"); + SecurityTokenProvider.instance.set(originalToken); + } + } + } + return listCatalogues; + } + + + + + + //NOT UPDATED + + + /** @@ -167,52 +252,33 @@ public class SyncronizeWithThredds { - /** - * Gets the synched status from item property. - * - * @param folderId the folder id - * @param scope the scope - * @param username the username - * @return the synched status from item property - * @throws Exception the exception - */ - public Sync_Status getSynchedStatusFromItemProperty(String folderId, String scope, String username) throws Exception{ - - try { - try { - ScopeProvider.instance.set(scope); - return workspaceThreddsSynchronize.getSynchedStatusFromItemProperty(folderId, username); - }catch (ItemNotSynched e) { - logger.info("The folder id: "+folderId +" is not synched returning null as "+Sync_Status.class.getSimpleName()); - return null; - } - - }catch (Exception e) { - logger.error("Error on getSynchedStatusFromItemProperty for id: "+folderId, e); - throw new Exception("Sorry, an error occurred during read sync status from HL properties, try again later"); - } - } +// /** +// * Gets the synched status from item property. +// * +// * @param folderId the folder id +// * @param scope the scope +// * @param username the username +// * @return the synched status from item property +// * @throws Exception the exception +// */ +// public Sync_Status getSynchedStatusFromItemProperty(String folderId, String scope, String username) throws Exception{ +// +// try { +// try { +// ScopeProvider.instance.set(scope); +// return workspaceThreddsSynchronize.getSynchedStatusFromItemProperty(folderId, username); +// }catch (ItemNotSynched e) { +// logger.info("The folder id: "+folderId +" is not synched returning null as "+Sync_Status.class.getSimpleName()); +// return null; +// } +// +// }catch (Exception e) { +// logger.error("Error on getSynchedStatusFromItemProperty for id: "+folderId, e); +// throw new Exception("Sorry, an error occurred during read sync status from HL properties, try again later"); +// } +// } - /** - * Checks if is item synched. - * - * @param folderId the folder id - * @param scope the scope - * @param username the username - * @return true, if is item synched - * @throws ItemNotSynched the item not synched - * @throws Exception the exception - */ - public boolean isItemSynched(String folderId, String scope, String username) throws ItemNotSynched, Exception{ - - Sync_Status value = getSynchedStatusFromItemProperty(folderId, scope, username); - - if(value!=null) - return true; - - return false; - } /** @@ -281,57 +347,4 @@ public class SyncronizeWithThredds { } - /** - * Gets the available catalogues. - * - * @param httpRequest the http request - * @param user the user - * @param targetScope the target scope - * @return the available catalogues - * @throws Exception the exception - */ - public List getAvailableCatalogues(HttpServletRequest httpRequest, GCubeUser user, - String targetScope) throws Exception { - String originalScope = null; - String originalToken = null; - String previousUmaToken = null; - List listCatalogues = null; - try { - // context switch for Uma token - previousUmaToken = changeContextForUMA(httpRequest, user, targetScope); - - // context switch for gcube-token and scope - PortalContext pConfig = PortalContext.getConfiguration(); - String wsScope = pConfig.getCurrentScope(httpRequest); - String wsUserToken = pConfig.getCurrentUserToken(wsScope, user.getUsername()); - // Thread Local contexts - originalScope = wsScope; - originalToken = wsUserToken; - // getting token into target scope - String targetScopeUserToken = PortalContext.getConfiguration().getCurrentUserToken(targetScope, - user.getUsername()); - setContextParameters(targetScope, targetScopeUserToken); - - // calling the engine - listCatalogues = workspaceThreddsSynchronize.getAvailableCatalogues(); - } catch (Exception e) { - logger.error("Error on getting available Catalogues in the scope: " + targetScope, e); - } finally { - - // resetting UMA token in the WS scope - setContextForUMA(previousUmaToken); - - if (originalScope != null && originalScope.compareTo(targetScope) != 0) { - logger.info("Resetting the scope: " + originalScope + " which was original WS context"); - ScopeProvider.instance.set(originalScope); - if (originalToken != null) { - logger.info("Resetting the user token: " + originalToken.substring(0, 10) - + "-MASKED-TOKEN which was original WS context"); - SecurityTokenProvider.instance.set(originalToken); - } - } - } - return listCatalogues; - } - } diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java index 9125512..fa62f65 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java @@ -7,9 +7,7 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.portal.PortalContext; -import org.gcube.common.scope.api.ScopeProvider; import org.gcube.portal.wssynclibrary.shared.ItemNotSynched; import org.gcube.portal.wssynclibrary.shared.WorkspaceFolderLocked; import org.gcube.portal.wssynclibrary.shared.thredds.Sync_Status; @@ -83,8 +81,7 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem } } - //MOVED - + /** * Gets the available THREDDS catalogues for target scope. * @@ -92,6 +89,7 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem * @return the available catalogues for scope * @throws Exception the exception */ + //UPDATED @Override public List getAvailableCataloguesForScope(String targetFullScope) throws Exception { @@ -100,6 +98,7 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem List listCtlgs = null; try { + GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); listCtlgs = getSyncService().getAvailableCatalogues(this.getThreadLocalRequest(), user, targetFullScope); @@ -116,6 +115,59 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem return listCtlgs; } + + /** + * Checks if is item synched. + * + * @param folderId the folder id + * @return the ws thredds synch folder descriptor + * @throws WorkspaceFolderLocked the workspace folder locked + * @throws Exception the exception + */ + /* (non-Javadoc) + * @see org.gcube.portlets.widgets.wsthreddssync.client.rpc.ThreddsWorkspaceSyncService#isItemSynched(java.lang.String) + */ + //UPDATED + @Override + public WsThreddsSynchFolderDescriptor isItemSynched(String folderId) throws WorkspaceFolderLocked, Exception{ + + logger.debug("Performing isItemSynched for foldeId: "+folderId); + + try { + + ThSyncFolderDescriptor theConfig = getSyncService().isItemSynched(folderId); + + if(theConfig!=null) { + logger.info("Folder id: "+folderId+" is synched"); + + //String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername()); + //ThSyncFolderDescriptor serverFolderSync = getSyncService().checkItemSynched(folderId,wsScope,wsUserToken); + + //the status is not set here (into isItemSynched implementation). + Sync_Status theStatus = null; + WsThreddsSynchFolderDescriptor toWsThreddFolder = BeanConverter.toWsThreddsFolderConfig(theConfig, theStatus); + logger.debug("IsItemSynched for id: "+folderId +" returning: "+toWsThreddFolder); + return toWsThreddFolder; + } + + logger.info("Folder id: "+folderId+" is not synched, returning null descriptor"); + return null; + + } catch (ItemNotSynched e) { + logger.info("The folderId: "+folderId +" is not synched, returning null FolderDescriptor"); + return null; + + } catch (WorkspaceFolderLocked e) { + logger.warn(e.getMessage() +", sending exception to client..."); + throw new WorkspaceFolderLocked(e.getFolderId(), e.getMessage()); + + }catch (Exception e) { + logger.info("Error on isItemSynched for folderId: "+folderId, e); + throw new Exception(e); + } + } + + @@ -317,55 +369,6 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem return null; } - - /** - * Checks if is item synched. - * - * @param folderId the folder id - * @return the ws thredds synch folder descriptor - * @throws WorkspaceFolderLocked the workspace folder locked - * @throws Exception the exception - */ - /* (non-Javadoc) - * @see org.gcube.portlets.widgets.wsthreddssync.client.rpc.ThreddsWorkspaceSyncService#isItemSynched(java.lang.String) - */ - @Override - public WsThreddsSynchFolderDescriptor isItemSynched(String folderId) throws WorkspaceFolderLocked, Exception{ - - logger.debug("Performing isItemSynched for foldeId: "+folderId); - - try { - - GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); - String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest()); - Sync_Status theStatus = getSyncService().getSynchedStatusFromItemProperty(folderId, wsScope, user.getUsername()); - - if(theStatus!=null) { - logger.info("Folder id: "+folderId+" is synched"); - String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername()); - ThSyncFolderDescriptor serverFolderSync = getSyncService().checkItemSynched(folderId,wsScope,wsUserToken); - WsThreddsSynchFolderDescriptor toWsThreddFolder = BeanConverter.toWsThreddsFolderConfig(serverFolderSync, theStatus); - logger.debug("IsItemSynched for id: "+folderId +" returning: "+toWsThreddFolder); - return toWsThreddFolder; - } - - logger.info("Folder id: "+folderId+" is not synched, returning null descriptor"); - return null; - - } catch (ItemNotSynched e) { - logger.info("The folderId: "+folderId +" is not synched, returning null FolderDescriptor"); - return null; - - } catch (WorkspaceFolderLocked e) { - logger.warn(e.getMessage() +", sending exception to client..."); - throw new WorkspaceFolderLocked(e.getFolderId(), e.getMessage()); - - }catch (Exception e) { - logger.info("Error on isItemSynched for folderId: "+folderId, e); - throw new Exception(e); - } - } - /** * Register callback for id. diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/WsThreddsSynchFolderDescriptor.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/WsThreddsSynchFolderDescriptor.java index 906401a..5d9a446 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/WsThreddsSynchFolderDescriptor.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/WsThreddsSynchFolderDescriptor.java @@ -10,8 +10,9 @@ import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncFolderDescriptor; /** * The Class WsThreddsSynchFolderDescriptor. * - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Feb 20, 2018 + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * May 10, 2021 */ public class WsThreddsSynchFolderDescriptor implements Serializable { @@ -109,6 +110,11 @@ public class WsThreddsSynchFolderDescriptor implements Serializable { this.serverFolderDescriptor = serverFolderDescriptor; } + /** + * To string. + * + * @return the string + */ /* (non-Javadoc) * @see java.lang.Object#toString() */ -- 2.17.1 From 8f191559c3efb4bafd9bb8879051bd9bc479b39f Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 11 May 2021 11:09:02 +0200 Subject: [PATCH 04/20] first complete commit for task #21379 --- CHANGELOG.md | 2 +- pom.xml | 2 +- .../server/SyncronizeWithThredds.java | 255 ++++++++++-------- .../ThreddsWorkspaceSyncServiceImpl.java | 136 +++++----- 4 files changed, 213 insertions(+), 182 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5206acd..1224e4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ## [v1.4.0-SNAPSHOT] - 2021-05-10 -[#20847] Support the roles of THREDDS Admin and THREDDS Publisher +[#21379] Moved to new ws-synchronized-module-library (based on w-thredds 1.x) and performed UMA tokens "context switches" ## [v1.3.0] - 2021-03-17 diff --git a/pom.xml b/pom.xml index 3df5f35..e46acdc 100644 --- a/pom.xml +++ b/pom.xml @@ -92,7 +92,7 @@ org.gcube.portal oidc-library-portal [1.0.0, 2.0.0-SNAPSHOT) - provided + compile diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java index c41c12e..10ef3e7 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java @@ -14,8 +14,6 @@ import org.gcube.common.scope.api.ScopeProvider; import org.gcube.oidc.rest.JWTToken; import org.gcube.portal.oidc.lr62.OIDCUmaUtil; import org.gcube.portal.wssynclibrary.shared.ItemNotSynched; -import org.gcube.portal.wssynclibrary.shared.WorkspaceFolderLocked; -import org.gcube.portal.wssynclibrary.shared.thredds.Sync_Status; import org.gcube.portal.wssynclibrary.shared.thredds.ThCatalogueBean; import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncFolderDescriptor; import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus; @@ -30,12 +28,10 @@ import org.slf4j.LoggerFactory; /** * The Class SyncronizeWithThredds. * - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Feb 7, 2018 + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Feb 7, 2018 */ public class SyncronizeWithThredds { - /** The logger. */ private Logger logger = LoggerFactory.getLogger(SyncronizeWithThredds.class); @@ -43,7 +39,8 @@ public class SyncronizeWithThredds { private WorkspaceThreddsSynchronize workspaceThreddsSynchronize; /** The Constant sdf. */ - //private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss"); + // private static final SimpleDateFormat sdf = new + // SimpleDateFormat("yyyy.MM.dd.HH.mm.ss"); /** * Instantiates a new publish on thredds. @@ -116,14 +113,13 @@ public class SyncronizeWithThredds { } - /** * Checks if is item synched. * * @param folderId the folder id * @return the th sync folder descriptor * @throws ItemNotSynched the item not synched - * @throws Exception the exception + * @throws Exception the exception */ public ThSyncFolderDescriptor isItemSynched(String folderId) throws ItemNotSynched, Exception { ThSyncFolderDescriptor config = null; @@ -133,7 +129,8 @@ public class SyncronizeWithThredds { logger.debug("WorkspaceNotSynchedException catched, the item id: " + folderId + " is not synched"); throw new ItemNotSynched("the item id: " + folderId + " is not synched"); } catch (Exception e) { - logger.debug("Error on getting configuration for the item id: " + folderId + ", returning null (means not synched)"); + logger.debug("Error on getting configuration for the item id: " + folderId + + ", returning null (means not synched)"); return null; } @@ -175,6 +172,7 @@ public class SyncronizeWithThredds { listCatalogues = workspaceThreddsSynchronize.getAvailableCatalogues(); } catch (Exception e) { logger.error("Error on getting available Catalogues in the scope: " + targetScope, e); + } finally { // resetting UMA token in the WS scope @@ -192,152 +190,188 @@ public class SyncronizeWithThredds { } return listCatalogues; } - - - - - - //NOT UPDATED - - - - /** * Do sync folder. * - * @param folderId the folder id - * @param thConfig the th config - * @param scope the scope - * @param userToken the user token + * @param folderId the folder id + * @param thConfig the th config + * @param httpRequest the http request + * @param user the user * @return the th sync status * @throws Exception the exception */ - public synchronized ThSyncStatus doSyncFolder(final String folderId, ThSynchFolderConfiguration thConfig, String scope, String userToken) throws Exception{ - logger.debug("Perfoming doSynFolder on folderId: "+folderId); + public synchronized ThSyncStatus doSyncFolder(final String folderId, ThSynchFolderConfiguration thConfig, + HttpServletRequest httpRequest, GCubeUser user) throws Exception { + logger.debug("called doSynFolder for folderId: " + folderId); + boolean firstSync = false; + String originalScope = null; + String originalToken = null; + String previousUmaToken = null; + + if (thConfig == null) { + throw new Exception("A valid folder configuration must be provided to perform the synchronization"); + } + + String targetScope = thConfig.getTargetContext(); + if (targetScope == null || targetScope.isEmpty()) { + throw new Exception("Error, the target scope is not valid!"); + } + + logger.info("going to doSynFolder for folderId: " + folderId + ", target scope is: " + targetScope); try { - setContextParameters(scope, userToken); + // context switch for Uma token + previousUmaToken = changeContextForUMA(httpRequest, user, targetScope); + + // context switch for gcube-token and scope + PortalContext pConfig = PortalContext.getConfiguration(); + String wsScope = pConfig.getCurrentScope(httpRequest); + String wsUserToken = pConfig.getCurrentUserToken(wsScope, user.getUsername()); + // Thread Local contexts + originalScope = wsScope; + originalToken = wsUserToken; + // getting token into target scope + String targetScopeUserToken = PortalContext.getConfiguration().getCurrentUserToken(targetScope, + user.getUsername()); + setContextParameters(targetScope, targetScopeUserToken); + ThSyncFolderDescriptor folder = workspaceThreddsSynchronize.checkItemSynched(folderId); - }catch (ItemNotSynched e) { + + } catch (ItemNotSynched e) { firstSync = true; - // TODO: handle exception - }catch (Exception e) { - logger.error("Error on check item sync: ",e); + } catch (Exception e) { + logger.error("Error on check item sync: ", e); throw new Exception("Sorry an error occurred during folder publishing, refresh and try again"); } - try{ + try { - if(firstSync) { - if(thConfig==null) { - throw new Exception("A valid folder configuration must be provided to perform the synchronization"); - } - - logger.info("First sync setting synchronized folder configuration: "+thConfig); + if (firstSync) { + logger.info("First sync setting the synchronized folder configuration: " + thConfig); workspaceThreddsSynchronize.setSynchronizedFolder(thConfig, folderId); } - logger.info("Calling do sync on folder id: "+folderId); + logger.info("Calling do sync on folder id: " + folderId); return workspaceThreddsSynchronize.doSync(folderId); - //SessionUtil.setTransferPublishingOnThredds(httpSession, status); - }catch (Exception e) { - logger.error("Error on do sync: ",e); - throw new Exception(e.getMessage() +", refresh and try again"); + } catch (Exception e) { + logger.error("Error on do sync: ", e); + throw new Exception(e.getMessage() + ", refresh and try again"); + + } finally { + + // resetting UMA token in the WS scope + setContextForUMA(previousUmaToken); + + if (originalScope != null && originalScope.compareTo(targetScope) != 0) { + logger.info("Resetting the scope: " + originalScope + " which was original WS context"); + ScopeProvider.instance.set(originalScope); + if (originalToken != null) { + logger.info("Resetting the user token: " + originalToken.substring(0, 10) + + "-MASKED-TOKEN which was original WS context"); + SecurityTokenProvider.instance.set(originalToken); + } + } } } - - - -// /** -// * Gets the synched status from item property. -// * -// * @param folderId the folder id -// * @param scope the scope -// * @param username the username -// * @return the synched status from item property -// * @throws Exception the exception -// */ -// public Sync_Status getSynchedStatusFromItemProperty(String folderId, String scope, String username) throws Exception{ -// -// try { -// try { -// ScopeProvider.instance.set(scope); -// return workspaceThreddsSynchronize.getSynchedStatusFromItemProperty(folderId, username); -// }catch (ItemNotSynched e) { -// logger.info("The folder id: "+folderId +" is not synched returning null as "+Sync_Status.class.getSimpleName()); -// return null; -// } -// -// }catch (Exception e) { -// logger.error("Error on getSynchedStatusFromItemProperty for id: "+folderId, e); -// throw new Exception("Sorry, an error occurred during read sync status from HL properties, try again later"); -// } -// } - - - - /** - * Check item synched. + * Do un sync. * - * @param folderId the folder id - * @param scope the scope - * @param userToken the user token - * @return the th sync folder descriptor - * @throws ItemNotSynched the item not synched - * @throws WorkspaceFolderLocked the workspace folder locked + * @param folderId the folder id + * @param deleteRemoteContent the delete remote content + * @param thConfig the th config + * @param httpRequest the http request + * @param user the user + * @return the boolean * @throws Exception the exception */ - public ThSyncFolderDescriptor checkItemSynched(String folderId, String scope, String userToken) throws ItemNotSynched, WorkspaceFolderLocked, Exception{ - setContextParameters(scope, userToken); - return workspaceThreddsSynchronize.checkItemSynched(folderId); + public Boolean doUnSync(String folderId, boolean deleteRemoteContent, ThSynchFolderConfiguration thConfig, + HttpServletRequest httpRequest, GCubeUser user) throws Exception { + logger.debug("called doUnSync for folderId: " + folderId); + + String originalScope = null; + String originalToken = null; + String previousUmaToken = null; + + if (thConfig == null) { + throw new Exception("A valid folder configuration must be provided to perform the synchronization"); + } + + String targetScope = thConfig.getTargetContext(); + if (targetScope == null || targetScope.isEmpty()) { + throw new Exception("Error, the target scope is not valid!"); + } + + logger.info("going to doSynFolder for folderId: " + folderId + ", target scope is: " + targetScope); + + try { + // context switch for Uma token + previousUmaToken = changeContextForUMA(httpRequest, user, targetScope); + + // context switch for gcube-token and scope + PortalContext pConfig = PortalContext.getConfiguration(); + String wsScope = pConfig.getCurrentScope(httpRequest); + String wsUserToken = pConfig.getCurrentUserToken(wsScope, user.getUsername()); + // Thread Local contexts + originalScope = wsScope; + originalToken = wsUserToken; + // getting token into target scope + String targetScopeUserToken = PortalContext.getConfiguration().getCurrentUserToken(targetScope, + user.getUsername()); + setContextParameters(targetScope, targetScopeUserToken); + + return workspaceThreddsSynchronize.doUnSync(folderId, deleteRemoteContent); + + } catch (ItemNotSynched e) { + throw new Exception("The item with id: " + folderId + " is not synched"); + } catch (Exception e) { + logger.error("Error on check item sync: ", e); + throw new Exception("Sorry an error occurred during folder publishing, refresh and try again"); + + } finally { + + // resetting UMA token in the WS scope + setContextForUMA(previousUmaToken); + + if (originalScope != null && originalScope.compareTo(targetScope) != 0) { + logger.info("Resetting the scope: " + originalScope + " which was original WS context"); + ScopeProvider.instance.set(originalScope); + if (originalToken != null) { + logger.info("Resetting the user token: " + originalToken.substring(0, 10) + + "-MASKED-TOKEN which was original WS context"); + SecurityTokenProvider.instance.set(originalToken); + } + } + } } + // NOT UPDATED + /** * Gets the sync status. * - * @param itemId the item id - * @param scope the scope + * @param itemId the item id + * @param scope the scope * @param userToken the user token * @return the sync status * @throws ItemNotSynched the item not synched - * @throws Exception the exception + * @throws Exception the exception */ - public ThSyncStatus monitorSyncStatus(String itemId, String scope, String userToken) throws ItemNotSynched, Exception{ + public ThSyncStatus monitorSyncStatus(String itemId, String scope, String userToken) + throws ItemNotSynched, Exception { setContextParameters(scope, userToken); return workspaceThreddsSynchronize.monitorSyncStatus(itemId); } - - - /** - * Do un sync. - * - * @param folderId the folder id - * @param deleteRemoteContent the delete remote content - * @param scope the scope - * @param userToken the user token - * @return the boolean - * @throws Exception the exception - */ - public Boolean doUnSync(String folderId, boolean deleteRemoteContent, String scope, String userToken) throws Exception { - - setContextParameters(scope, userToken); - return workspaceThreddsSynchronize.doUnSync(folderId, deleteRemoteContent); - } - - - /** * Register callback for id. * - * @param folderId the folder id - * @param scope the scope + * @param folderId the folder id + * @param scope the scope * @param userToken the user token * @throws Exception the exception */ @@ -346,5 +380,4 @@ public class SyncronizeWithThredds { workspaceThreddsSynchronize.registerCallbackForId(folderId); } - } diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java index fa62f65..0d62ea6 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java @@ -130,8 +130,7 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem //UPDATED @Override public WsThreddsSynchFolderDescriptor isItemSynched(String folderId) throws WorkspaceFolderLocked, Exception{ - - logger.debug("Performing isItemSynched for foldeId: "+folderId); + logger.debug("called isItemSynched for folderId: "+folderId); try { @@ -146,7 +145,7 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem //the status is not set here (into isItemSynched implementation). Sync_Status theStatus = null; WsThreddsSynchFolderDescriptor toWsThreddFolder = BeanConverter.toWsThreddsFolderConfig(theConfig, theStatus); - logger.debug("IsItemSynched for id: "+folderId +" returning: "+toWsThreddFolder); + logger.debug("isItemSynched for id: "+folderId +" returning: "+toWsThreddFolder); return toWsThreddFolder; } @@ -154,7 +153,7 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem return null; } catch (ItemNotSynched e) { - logger.info("The folderId: "+folderId +" is not synched, returning null FolderDescriptor"); + logger.info("The folderId: "+folderId +" is not synched, returning null for "+WsThreddsSynchFolderDescriptor.class.getSimpleName()); return null; } catch (WorkspaceFolderLocked e) { @@ -168,23 +167,27 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem } - - - /** * Do sync folder. * * @param folderId the folder id - * @param clientConfig the th config + * @param clientConfig the client config * @return the th sync status * @throws Exception the exception */ - /* (non-Javadoc) - * @see org.gcube.portlets.widgets.wsthreddssync.client.rpc.ThreddsWorkspaceSyncService#doSyncFolder(java.lang.String, org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderDescriptor) + /* + * (non-Javadoc) + * + * @see org.gcube.portlets.widgets.wsthreddssync.client.rpc. + * ThreddsWorkspaceSyncService#doSyncFolder(java.lang.String, + * org.gcube.portlets.widgets.wsthreddssync.shared. + * WsThreddsSynchFolderDescriptor) */ + //UPDATED @Override - public ThSyncStatus doSyncFolder(final String folderId, WsThreddsSynchFolderConfiguration clientConfig) throws Exception{ - logger.info("Performing doSyncFolder method on id: "+folderId +", config: "+clientConfig); + public ThSyncStatus doSyncFolder(final String folderId, WsThreddsSynchFolderConfiguration clientConfig) + throws Exception { + logger.info("Performing doSyncFolder method on id: " + folderId + ", config: " + clientConfig); try { GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); @@ -195,20 +198,51 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem logger.debug("Creating server config " + config); } - logger.info("Calling doSyncFolder on folderId: "+folderId +", config: "+config); - String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest()); - String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername()); +// logger.info("Calling doSyncFolder on folderId: "+folderId +", config: "+config); +// String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest()); +// String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername()); - ThSyncStatus status = getSyncService().doSyncFolder(folderId, config, wsScope, wsUserToken); - logger.debug("Returning for folderId "+folderId+" the syncStatus: "+status); + ThSyncStatus status = getSyncService().doSyncFolder(folderId, config, this.getThreadLocalRequest(), user); + logger.debug("Returning for folderId " + folderId + " the syncStatus: " + status); return status; - }catch (Exception e) { - logger.error("Do sync Folder error: ",e); + } catch (Exception e) { + logger.error("Do sync Folder error: ", e); throw new Exception("Sorry, an error occurred during synchonization phase, try again later"); } } + + /** + * Do sync folder. + * + * @param folderId the folder id + * @return the th sync status + * @throws Exception the exception + */ + /* + * (non-Javadoc) + * + * @see org.gcube.portlets.widgets.wsthreddssync.client.rpc. + * ThreddsWorkspaceSyncService#doSyncFolder(java.lang.String, + * org.gcube.portlets.widgets.wsthreddssync.shared. + * WsThreddsSynchFolderDescriptor) + */ + // Updated + @Override + public Boolean doUnSyncFolder(final String folderId) throws Exception { + logger.info("Performing unsync on folder id: " + folderId); + try { + GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); + ThSyncFolderDescriptor foldeDesr = getSyncService().isItemSynched(folderId); + return getSyncService().doUnSync(folderId, true, foldeDesr.getConfiguration(), + this.getThreadLocalRequest(), user); + } catch (Exception e) { + logger.error("Do un sync Folder error: ", e); + throw new Exception( + "Sorry, an error occurred on deleting sync configurations, refresh and try again later"); + } + } /** @@ -257,11 +291,11 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem */ @Override public List getListOfDataManagerScopesForLoggedUser() throws Exception{ - logger.info("getListOfVREsForLoggedUser...: "); + logger.info("called getListOfVREsForLoggedUser...: "); GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); long userId = user.getUserId(); - // Instanciate the manager + // Instantiate the manager GroupManager groupManager = new LiferayGroupManager(); List listOfScopes = new ArrayList(); @@ -318,12 +352,6 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem listOfScopes.add(gcubeScope); } - //ADDING THE ROOT SCOPE - /*String infraName = PortalContext.getConfiguration().getInfrastructureName(); - GcubeScope gcubeRoot = new GcubeScope(infraName, "/"+infraName, GcubeScopeType.ROOT); - listOfScopes.add(gcubeRoot)*/ - - } catch (UserRetrievalFault | UserManagementSystemException | GroupRetrievalFault e) { @@ -370,18 +398,18 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem } - /** - * Register callback for id. - * - * @param folderId the folder id - * @throws Exception the exception - */ - public void registerCallbackForId(String folderId) throws Exception{ - GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); - String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest()); - String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername()); - getSyncService().registerCallbackForId(folderId, wsScope, wsUserToken); - } +// /** +// * Register callback for id. +// * +// * @param folderId the folder id +// * @throws Exception the exception +// */ +// private void registerCallbackForId(String folderId) throws Exception{ +// GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); +// String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest()); +// String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername()); +// getSyncService().registerCallbackForId(folderId, wsScope, wsUserToken); +// } /** @@ -403,34 +431,4 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem return getSyncService().monitorSyncStatus(folderId, wsScope, wsUserToken); } - - /** - * Do sync folder. - * - * @param folderId the folder id - * @return the th sync status - * @throws Exception the exception - */ - /* (non-Javadoc) - * @see org.gcube.portlets.widgets.wsthreddssync.client.rpc.ThreddsWorkspaceSyncService#doSyncFolder(java.lang.String, org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderDescriptor) - */ - @Override - public Boolean doUnSyncFolder(final String folderId) throws Exception{ - logger.info("Performing unsync on folder id: "+folderId); - -// String scope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest()); -// GCubeUser username = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); -// String groupName = PortalContext.getConfiguration().getCurrentGroupName(this.getThreadLocalRequest()); -// new GcubeVRE(groupName, scope) - try { - GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); - String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest()); - String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername()); - return getSyncService().doUnSync(folderId, false, wsScope, wsUserToken); - }catch (Exception e) { - logger.error("Do un sync Folder error: ",e); - throw new Exception("Sorry, an error occurred on deleting sync configurations, refresh and try again later"); - } - } - } -- 2.17.1 From 23de9f1abb5689e3f049b40adb82816596820e1a Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 11 May 2021 12:05:50 +0200 Subject: [PATCH 05/20] integrated the getInfo from SyncEngine (it is not implemented in the library) --- pom.xml | 13 +- .../server/SyncronizeWithThredds.java | 19 +- .../ThreddsWorkspaceSyncServiceImpl.java | 257 ++++++++---------- 3 files changed, 126 insertions(+), 163 deletions(-) diff --git a/pom.xml b/pom.xml index e46acdc..200e159 100644 --- a/pom.xml +++ b/pom.xml @@ -95,13 +95,6 @@ compile - - - - - - - org.gcube.common authorization-client @@ -118,11 +111,13 @@ org.slf4j - slf4j-log4j12 + slf4j-api + provided org.slf4j - slf4j-api + slf4j-log4j12 + provided diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java index 10ef3e7..536a997 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java @@ -14,6 +14,7 @@ import org.gcube.common.scope.api.ScopeProvider; import org.gcube.oidc.rest.JWTToken; import org.gcube.portal.oidc.lr62.OIDCUmaUtil; import org.gcube.portal.wssynclibrary.shared.ItemNotSynched; +import org.gcube.portal.wssynclibrary.shared.thredds.Sync_Status; import org.gcube.portal.wssynclibrary.shared.thredds.ThCatalogueBean; import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncFolderDescriptor; import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus; @@ -24,7 +25,6 @@ import org.gcube.vomanagement.usermanagement.model.GCubeUser; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -// TODO: Auto-generated Javadoc /** * The Class SyncronizeWithThredds. * @@ -348,8 +348,6 @@ public class SyncronizeWithThredds { } } - // NOT UPDATED - /** * Gets the sync status. * @@ -375,9 +373,22 @@ public class SyncronizeWithThredds { * @param userToken the user token * @throws Exception the exception */ - public void registerCallbackForId(String folderId, String scope, String userToken) throws Exception { + protected void registerCallbackForId(String folderId, String scope, String userToken) throws Exception { setContextParameters(scope, userToken); workspaceThreddsSynchronize.registerCallbackForId(folderId); } + /** + * Gets the sync status info. + * + * @param itemId the item id + * @return the sync status info + * @throws Exception the exception + */ + public Sync_Status getSyncStatusInfo(String itemId, String scope, String userToken) throws Exception { + setContextParameters(scope, userToken); + return workspaceThreddsSynchronize.getInfo(itemId); + + } + } diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java index 0d62ea6..1784d2d 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java @@ -35,12 +35,11 @@ import org.slf4j.LoggerFactory; import com.google.gwt.user.server.rpc.RemoteServiceServlet; import com.liferay.portal.service.UserLocalServiceUtil; - +// TODO: Auto-generated Javadoc /** * The server side implementation of the RPC service. * - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Feb 14, 2018 + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Feb 14, 2018 */ @SuppressWarnings("serial") public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implements ThreddsWorkspaceSyncService { @@ -58,10 +57,10 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem */ public synchronized SyncronizeWithThredds getSyncService() { - if(syncThredds==null) + if (syncThredds == null) syncThredds = new SyncronizeWithThredds(); - return syncThredds; + return syncThredds; } @@ -74,14 +73,12 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem try { UserLocalServiceUtil.getService(); return true; - } - catch (Exception ex) { + } catch (Exception ex) { logger.warn("Development Mode ON"); return false; } } - - + /** * Gets the available THREDDS catalogues for target scope. * @@ -89,101 +86,88 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem * @return the available catalogues for scope * @throws Exception the exception */ - //UPDATED + // UPDATED @Override public List getAvailableCataloguesForScope(String targetFullScope) throws Exception { - if(targetFullScope==null) + if (targetFullScope == null) throw new Exception("Invalid scope null"); List listCtlgs = null; try { - + GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); listCtlgs = getSyncService().getAvailableCatalogues(this.getThreadLocalRequest(), user, targetFullScope); - - logger.debug("Retuning "+listCtlgs.size()+" Catalogues for scope: "+targetFullScope); - if(logger.isDebugEnabled()){ + + logger.debug("Retuning " + listCtlgs.size() + " Catalogues for scope: " + targetFullScope); + if (logger.isDebugEnabled()) { for (ThCatalogueBean thCatalogueBean : listCtlgs) { logger.debug(thCatalogueBean.toString()); } } - }catch (Exception e) { - logger.error("Error on checking available Catalogue in the scope: "+targetFullScope, e); + } catch (Exception e) { + logger.error("Error on checking available Catalogue in the scope: " + targetFullScope, e); } - + return listCtlgs; } - - + /** * Checks if is item synched. * * @param folderId the folder id * @return the ws thredds synch folder descriptor * @throws WorkspaceFolderLocked the workspace folder locked - * @throws Exception the exception + * @throws Exception the exception */ - /* (non-Javadoc) - * @see org.gcube.portlets.widgets.wsthreddssync.client.rpc.ThreddsWorkspaceSyncService#isItemSynched(java.lang.String) - */ - //UPDATED + // UPDATED @Override - public WsThreddsSynchFolderDescriptor isItemSynched(String folderId) throws WorkspaceFolderLocked, Exception{ - logger.debug("called isItemSynched for folderId: "+folderId); + public WsThreddsSynchFolderDescriptor isItemSynched(String folderId) throws WorkspaceFolderLocked, Exception { + logger.debug("called isItemSynched for folderId: " + folderId); try { ThSyncFolderDescriptor theConfig = getSyncService().isItemSynched(folderId); - if(theConfig!=null) { - logger.info("Folder id: "+folderId+" is synched"); - - //String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername()); - //ThSyncFolderDescriptor serverFolderSync = getSyncService().checkItemSynched(folderId,wsScope,wsUserToken); - - //the status is not set here (into isItemSynched implementation). - Sync_Status theStatus = null; - WsThreddsSynchFolderDescriptor toWsThreddFolder = BeanConverter.toWsThreddsFolderConfig(theConfig, theStatus); - logger.debug("isItemSynched for id: "+folderId +" returning: "+toWsThreddFolder); + if (theConfig != null) { + logger.info("Folder id: " + folderId + " is synched"); + GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); + String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest()); + String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername()); + Sync_Status theStatus = getSyncService().getSyncStatusInfo(folderId,wsScope,wsUserToken); + WsThreddsSynchFolderDescriptor toWsThreddFolder = BeanConverter.toWsThreddsFolderConfig(theConfig, + theStatus); + logger.debug("isItemSynched for id: " + folderId + " returning: " + toWsThreddFolder); return toWsThreddFolder; } - logger.info("Folder id: "+folderId+" is not synched, returning null descriptor"); + logger.info("Folder id: " + folderId + " is not synched, returning null descriptor"); return null; } catch (ItemNotSynched e) { - logger.info("The folderId: "+folderId +" is not synched, returning null for "+WsThreddsSynchFolderDescriptor.class.getSimpleName()); + logger.info("The folderId: " + folderId + " is not synched, returning null for " + + WsThreddsSynchFolderDescriptor.class.getSimpleName()); return null; } catch (WorkspaceFolderLocked e) { - logger.warn(e.getMessage() +", sending exception to client..."); + logger.warn(e.getMessage() + ", sending exception to client..."); throw new WorkspaceFolderLocked(e.getFolderId(), e.getMessage()); - }catch (Exception e) { - logger.info("Error on isItemSynched for folderId: "+folderId, e); + } catch (Exception e) { + logger.info("Error on isItemSynched for folderId: " + folderId, e); throw new Exception(e); } } - /** * Do sync folder. * - * @param folderId the folder id + * @param folderId the folder id * @param clientConfig the client config * @return the th sync status * @throws Exception the exception */ - /* - * (non-Javadoc) - * - * @see org.gcube.portlets.widgets.wsthreddssync.client.rpc. - * ThreddsWorkspaceSyncService#doSyncFolder(java.lang.String, - * org.gcube.portlets.widgets.wsthreddssync.shared. - * WsThreddsSynchFolderDescriptor) - */ - //UPDATED + // UPDATED @Override public ThSyncStatus doSyncFolder(final String folderId, WsThreddsSynchFolderConfiguration clientConfig) throws Exception { @@ -198,10 +182,6 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem logger.debug("Creating server config " + config); } -// logger.info("Calling doSyncFolder on folderId: "+folderId +", config: "+config); -// String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest()); -// String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername()); - ThSyncStatus status = getSyncService().doSyncFolder(folderId, config, this.getThreadLocalRequest(), user); logger.debug("Returning for folderId " + folderId + " the syncStatus: " + status); @@ -211,22 +191,14 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem throw new Exception("Sorry, an error occurred during synchonization phase, try again later"); } } - + /** - * Do sync folder. + * Do un sync folder. * * @param folderId the folder id - * @return the th sync status + * @return the boolean * @throws Exception the exception */ - /* - * (non-Javadoc) - * - * @see org.gcube.portlets.widgets.wsthreddssync.client.rpc. - * ThreddsWorkspaceSyncService#doSyncFolder(java.lang.String, - * org.gcube.portlets.widgets.wsthreddssync.shared. - * WsThreddsSynchFolderDescriptor) - */ // Updated @Override public Boolean doUnSyncFolder(final String folderId) throws Exception { @@ -235,8 +207,8 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem try { GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); ThSyncFolderDescriptor foldeDesr = getSyncService().isItemSynched(folderId); - return getSyncService().doUnSync(folderId, true, foldeDesr.getConfiguration(), - this.getThreadLocalRequest(), user); + return getSyncService().doUnSync(folderId, true, foldeDesr.getConfiguration(), this.getThreadLocalRequest(), + user); } catch (Exception e) { logger.error("Do un sync Folder error: ", e); throw new Exception( @@ -244,45 +216,43 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem } } - /** - * Gets the list of Scopes (Root-VO, VOs and VREs) for user and the Thredds roles that user has in them. + * Gets the list of Scopes (Root-VO, VOs and VREs) for user and the Thredds + * roles that user has in them. * * @return the VREs and Thredds roles for a given user * @throws Exception the exception */ @Override - public Map getScopesWithThreddsRolesForLoggedUser() throws Exception{ + public Map getScopesWithThreddsRolesForLoggedUser() throws Exception { logger.info("called getScopesWithThreddsRolesForLoggedUser"); - + GCubeUser user = null; Map mapScopesRoles = null; - - //DEV MODE - if (!isWithinPortal()){ + + // DEV MODE + if (!isWithinPortal()) { mapScopesRoles = new HashMap(); mapScopesRoles.put("/gcube/devsec/devVRE", GatewayRolesThredds.DATA_EDITOR); // mapScopesRoles.put( "/gcube", GatewayRolesThredds.THREDDS_PUBLISHER); // mapScopesRoles.put( "/gcube/devNext/NextNext", GatewayRolesThredds.THREDDS_PUBLISHER); return mapScopesRoles; } - + try { user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); mapScopesRoles = WsUtil.getScopesWithThreddsRolesForUser(user); - - logger.info("returning Map(scopes,roles): "+mapScopesRoles); + + logger.info("returning Map(scopes,roles): " + mapScopesRoles); return mapScopesRoles; - }catch (Exception e) { + } catch (Exception e) { String errorMsg = "An error occurred on checking user roles. Refresh the page and try again."; - logger.error("An error occurred on checking user roles for user: "+user, e); + logger.error("An error occurred on checking user roles for user: " + user, e); throw new Exception(errorMsg); - } + } } - - /** * Gets the list scope with the role Data-Manager for logged user. * @@ -290,7 +260,7 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem * @throws Exception the exception */ @Override - public List getListOfDataManagerScopesForLoggedUser() throws Exception{ + public List getListOfDataManagerScopesForLoggedUser() throws Exception { logger.info("called getListOfVREsForLoggedUser...: "); GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); long userId = user.getUserId(); @@ -298,9 +268,9 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem // Instantiate the manager GroupManager groupManager = new LiferayGroupManager(); List listOfScopes = new ArrayList(); - - //DEV MODE - if (!isWithinPortal()){ + + // DEV MODE + if (!isWithinPortal()) { listOfScopes.add(new GcubeScope("devVRE", "/gcube/devsec/devVRE", GcubeScopeType.VRE)); listOfScopes.add(new GcubeScope("NextNext", "/gcube/devNext/NextNext", GcubeScopeType.VRE)); listOfScopes.add(new GcubeScope("devNext", "/gcube/devNext", GcubeScopeType.VO)); @@ -313,104 +283,94 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem try { String gatewayHostname = GenericUtils.getGatewayClientHostname(getThreadLocalRequest()); - //list of Scopes filtered for gateway + // list of Scopes filtered for gateway Set filteredGroupsForGatw = groupManager.listGroupsByUserAndSite(userId, gatewayHostname); - - //List listOfGroups = groupManager.listGroupsByUser(userId); + + // List listOfGroups = groupManager.listGroupsByUser(userId); List listOfGroups = new ArrayList(filteredGroupsForGatw); - logger.info("list of VREs in the gateway "+gatewayHostname+" are "+listOfGroups.size()); + logger.info("list of VREs in the gateway " + gatewayHostname + " are " + listOfGroups.size()); for (GCubeGroup gCubeGroup : listOfGroups) { long groupId = gCubeGroup.getGroupId(); String fullScope = groupManager.getInfrastructureScope(groupId); - logger.debug("For groupId: "+groupId+" got full scope: "+fullScope); - GcubeScopeType scopeType=null; - if(groupManager.isVRE(groupId)){ - scopeType = GcubeScopeType.VRE; - }else if(groupManager.isVO(groupId)){ - scopeType = GcubeScopeType.VO; + logger.debug("For groupId: " + groupId + " got full scope: " + fullScope); + GcubeScopeType scopeType = null; + if (groupManager.isVRE(groupId)) { + scopeType = GcubeScopeType.VRE; + } else if (groupManager.isVO(groupId)) { + scopeType = GcubeScopeType.VO; } // }else if(groupManager.isRootVO(gCubeGroup.getGroupId())){ // scopeType = GcubeScopeType.ROOT; // } - if(scopeType!=null){ + if (scopeType != null) { GatewayRolesThredds roles = WsUtil.getThreddsRoleFor(user, gCubeGroup); - //Adding only the scope where the user has the THREDDS_ADMIN role - GcubeScope gcubeScope = checkDataManagerCapacityAndThreddsCatalogue(roles, gCubeGroup.getGroupName(), fullScope, groupManager, scopeType); - if(gcubeScope!=null) { + // Adding only the scope where the user has the THREDDS_ADMIN role + GcubeScope gcubeScope = checkDataManagerCapacityAndThreddsCatalogue(roles, + gCubeGroup.getGroupName(), fullScope, groupManager, scopeType); + if (gcubeScope != null) { listOfScopes.add(gcubeScope); } } } - + GCubeGroup theRootVO = groupManager.getRootVO(); GatewayRolesThredds roles = WsUtil.getThreddsRoleFor(user, theRootVO); String rootVOFullScope = groupManager.getInfrastructureScope(theRootVO.getGroupId()); - ///ADDING THE ROOT SCOPE if the user has the THREDDS_ADMIN role in the ROOT-VO - GcubeScope gcubeScope = checkDataManagerCapacityAndThreddsCatalogue(roles, theRootVO.getGroupName(), rootVOFullScope, groupManager, GcubeScopeType.ROOT); - if(gcubeScope!=null) { + /// ADDING THE ROOT SCOPE if the user has the THREDDS_ADMIN role in the ROOT-VO + GcubeScope gcubeScope = checkDataManagerCapacityAndThreddsCatalogue(roles, theRootVO.getGroupName(), + rootVOFullScope, groupManager, GcubeScopeType.ROOT); + if (gcubeScope != null) { listOfScopes.add(gcubeScope); } - } - catch (UserRetrievalFault | UserManagementSystemException - | GroupRetrievalFault e) { + } catch (UserRetrievalFault | UserManagementSystemException | GroupRetrievalFault e) { logger.error("Error occurred server-side getting VRE folders: ", e); throw new Exception("Sorry, an error occurred server-side getting VRE folders, try again later"); } - - if(listOfScopes.isEmpty()) { - throw new Exception("No scope detected with the needed role: "+GatewayRolesThredds.DATA_MANAGER.getRoleName()+". Contact the VRE manager or the portal administrator"); + + if (listOfScopes.isEmpty()) { + throw new Exception( + "No scope detected with the needed role: " + GatewayRolesThredds.DATA_MANAGER.getRoleName() + + ". Contact the VRE manager or the portal administrator"); } Collections.sort(listOfScopes); - logger.info("Returning list of allowed scope/s with: "+GatewayRolesThredds.DATA_MANAGER + " role/s: "+listOfScopes); + logger.info("Returning list of allowed scope/s with: " + GatewayRolesThredds.DATA_MANAGER + " role/s: " + + listOfScopes); return listOfScopes; } - - + /** - * Checks if for the input scope: - * - the user has the role {@link GatewayRolesThredds.#THREDDS_ADMIN} - * - the scope has an available THREDDS catalogue configured + * Checks if for the input scope: - the user has the role + * {@link GatewayRolesThredds.#THREDDS_ADMIN} - the scope has an available + * THREDDS catalogue configured * - * @param role the role - * @param scopeName the scope name e.g. devVRE - * @param fullScope the full scope e.g. /gcube/devsec/devVRE + * @param role the role + * @param scopeName the scope name e.g. devVRE + * @param fullScope the full scope e.g. /gcube/devsec/devVRE * @param groupManager the group manager - * @param scopeType the scope type - * @return the gcube scope {@link GcubeScope} if the two conditions (see description) are satisfied, null otherwise + * @param scopeType the scope type + * @return the gcube scope {@link GcubeScope} if the two conditions (see + * description) are satisfied, null otherwise * @throws Exception the exception */ - private GcubeScope checkDataManagerCapacityAndThreddsCatalogue(GatewayRolesThredds role, String scopeName, String fullScope, GroupManager groupManager, GcubeScopeType scopeType) throws Exception { - logger.debug("checking Data-Manager capacity and THREEDS catalogues for role: "+role, "scope name: "+scopeName+", scope: "+fullScope + " scope type: "+scopeType); - if(role!=null && role.getRoleName().equalsIgnoreCase(GatewayRolesNames.DATA_MANAGER.getRoleName())){ + private GcubeScope checkDataManagerCapacityAndThreddsCatalogue(GatewayRolesThredds role, String scopeName, + String fullScope, GroupManager groupManager, GcubeScopeType scopeType) throws Exception { + logger.debug("checking Data-Manager capacity and THREEDS catalogues for role: " + role, + "scope name: " + scopeName + ", scope: " + fullScope + " scope type: " + scopeType); + if (role != null && role.getRoleName().equalsIgnoreCase(GatewayRolesNames.DATA_MANAGER.getRoleName())) { try { List list = getAvailableCataloguesForScope(fullScope); - if(list!=null) { + if (list != null) { return new GcubeScope(scopeName, fullScope, scopeType); } - }catch (Exception e) { - logger.error("Error on checking available catalogue for scope: "+fullScope, e); + } catch (Exception e) { + logger.error("Error on checking available catalogue for scope: " + fullScope, e); } } return null; } - - -// /** -// * Register callback for id. -// * -// * @param folderId the folder id -// * @throws Exception the exception -// */ -// private void registerCallbackForId(String folderId) throws Exception{ -// GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); -// String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest()); -// String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername()); -// getSyncService().registerCallbackForId(folderId, wsScope, wsUserToken); -// } - /** * Monitor sync status. @@ -418,13 +378,10 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem * @param folderId the folder id * @return the th sync status * @throws ItemNotSynched the item not synched - * @throws Exception the exception - */ - /* (non-Javadoc) - * @see org.gcube.portlets.widgets.wsthreddssync.client.rpc.ThreddsWorkspaceSyncService#monitorSyncStatus(java.lang.String) + * @throws Exception the exception */ @Override - public ThSyncStatus monitorSyncStatus(String folderId) throws ItemNotSynched, Exception{ + public ThSyncStatus monitorSyncStatus(String folderId) throws ItemNotSynched, Exception { GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest()); String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername()); -- 2.17.1 From d972d8e2f3221f63a387490e9ff0825a0cfa1a12 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 11 May 2021 12:51:09 +0200 Subject: [PATCH 06/20] cleaned test cases --- .../wsthreddssync/server/SyncronizeWithThredds.java | 2 +- .../widgets/wsthreddssync/TestWsThreddsEngine.java | 9 --------- .../widgets/wsthreddssync/TestWsThreddsQuery.java | 2 -- .../widgets/wsthreddssync/UnSyncThreddsFolders.java | 13 ++++++------- 4 files changed, 7 insertions(+), 19 deletions(-) diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java index 536a997..f3240c5 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java @@ -121,7 +121,7 @@ public class SyncronizeWithThredds { * @throws ItemNotSynched the item not synched * @throws Exception the exception */ - public ThSyncFolderDescriptor isItemSynched(String folderId) throws ItemNotSynched, Exception { + public ThSyncFolderDescriptor isItemSynched(String folderId) throws ItemNotSynched { ThSyncFolderDescriptor config = null; try { config = workspaceThreddsSynchronize.getConfiguration(folderId); diff --git a/src/test/java/org/gcube/portlets/widgets/wsthreddssync/TestWsThreddsEngine.java b/src/test/java/org/gcube/portlets/widgets/wsthreddssync/TestWsThreddsEngine.java index e05ba39..ab508d9 100644 --- a/src/test/java/org/gcube/portlets/widgets/wsthreddssync/TestWsThreddsEngine.java +++ b/src/test/java/org/gcube/portlets/widgets/wsthreddssync/TestWsThreddsEngine.java @@ -1,17 +1,8 @@ package org.gcube.portlets.widgets.wsthreddssync; -import org.gcube.portal.wssynclibrary.thredds.WorkspaceThreddsSynchronize; import org.gcube.portlets.widgets.wsthreddssync.server.SyncronizeWithThredds; -import org.gcube.usecases.ws.thredds.SyncEngine; -import org.gcube.usecases.ws.thredds.engine.impl.ProcessDescriptor; -import org.gcube.usecases.ws.thredds.engine.impl.ProcessStatus; -import org.gcube.usecases.ws.thredds.faults.WorkspaceLockedException; -import org.gcube.usecases.ws.thredds.faults.WorkspaceNotSynchedException; -import org.gcube.usecases.ws.thredds.model.SyncOperationCallBack; -import org.gcube.usecases.ws.thredds.model.SynchFolderConfiguration; -// TODO: Auto-generated Javadoc /** * The Class TestWsThreddsEngine. * diff --git a/src/test/java/org/gcube/portlets/widgets/wsthreddssync/TestWsThreddsQuery.java b/src/test/java/org/gcube/portlets/widgets/wsthreddssync/TestWsThreddsQuery.java index a23e663..255cb7e 100644 --- a/src/test/java/org/gcube/portlets/widgets/wsthreddssync/TestWsThreddsQuery.java +++ b/src/test/java/org/gcube/portlets/widgets/wsthreddssync/TestWsThreddsQuery.java @@ -5,8 +5,6 @@ import java.util.Map; import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.storagehubwrapper.server.StorageHubWrapper; import org.gcube.common.storagehubwrapper.server.tohl.Workspace; -import org.gcube.common.storagehubwrapper.shared.tohl.Properties; -import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder; import org.gcube.portal.wssynclibrary.shared.ItemNotSynched; public class TestWsThreddsQuery { diff --git a/src/test/java/org/gcube/portlets/widgets/wsthreddssync/UnSyncThreddsFolders.java b/src/test/java/org/gcube/portlets/widgets/wsthreddssync/UnSyncThreddsFolders.java index c1a69eb..a30b794 100644 --- a/src/test/java/org/gcube/portlets/widgets/wsthreddssync/UnSyncThreddsFolders.java +++ b/src/test/java/org/gcube/portlets/widgets/wsthreddssync/UnSyncThreddsFolders.java @@ -5,7 +5,6 @@ package org.gcube.portlets.widgets.wsthreddssync; import java.util.ArrayList; import java.util.List; -import java.util.Map; import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.scope.api.ScopeProvider; @@ -15,8 +14,8 @@ import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem; import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.InternalErrorException; import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.ItemNotFoundException; import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.WorkspaceFolderNotFoundException; +import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncFolderDescriptor; import org.gcube.portlets.widgets.wsthreddssync.server.SyncronizeWithThredds; -import org.gcube.usecases.ws.thredds.Constants; @@ -30,7 +29,7 @@ public class UnSyncThreddsFolders { public static String DEFAULT_SCOPE = "/gcube"; //DEV public static String TEST_USER = "francesco.mangiacrapa"; - public static String TEST_USER_TOKEN = "0e2c7963-8d3e-4ea6-a56d-ffda530dd0fa-98187548"; //token user: Francesco Mangiacrapa - /gcube (root) + public static String TEST_USER_TOKEN = "TOKEN"; private static List lstUnSynchedItem = new ArrayList(); private static List lstUnSynchedFailedItem = new ArrayList(); @@ -146,13 +145,13 @@ public class UnSyncThreddsFolders { return; try{ - boolean synched = syncService.isItemSynched(workspaceItem.getId(), DEFAULT_SCOPE, TEST_USER); + ScopeProvider.instance.set(DEFAULT_SCOPE); + SecurityTokenProvider.instance.set(TEST_USER_TOKEN); + ThSyncFolderDescriptor synched = syncService.isItemSynched(workspaceItem.getId()); System.out.println("Is the workspace item: "+workspaceItem.getId() + " synched? "+synched +", Is folder? "+workspaceItem.isFolder()); - if(synched && workspaceItem.isFolder()){ + if(synched != null){ //Boolean unsynched = syncService.doUnSync(workspaceItem.getId(), false, DEFAULT_SCOPE, TEST_USER_TOKEN); - ScopeProvider.instance.set(DEFAULT_SCOPE); - SecurityTokenProvider.instance.set(TEST_USER_TOKEN); Workspace ws = getWorkspace(); cleanItem(workspaceItem, ws); totalAttempts++; -- 2.17.1 From 24e6bca0b0131754d2e3bdc2ed4cedfadd795a17 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 11 May 2021 13:01:01 +0200 Subject: [PATCH 07/20] removed unused dependencies --- pom.xml | 34 ++---- .../widgets/wsthreddssync/server/WsUtil.java | 113 +++++------------- .../wsthreddssync/TestWsThreddsQuery.java | 25 ++-- .../wsthreddssync/UnSyncThreddsFolders.java | 40 +------ 4 files changed, 54 insertions(+), 158 deletions(-) diff --git a/pom.xml b/pom.xml index 200e159..8f1573e 100644 --- a/pom.xml +++ b/pom.xml @@ -62,19 +62,6 @@ gwt-bootstrap - - - org.gcube.common.portal - portal-manager - provided - - - - com.liferay.portal - portal-service - provided - - org.gcube.dvos @@ -92,22 +79,21 @@ org.gcube.portal oidc-library-portal [1.0.0, 2.0.0-SNAPSHOT) - compile + + + + + org.gcube.common.portal + portal-manager + provided - org.gcube.common - authorization-client - [2.0.0, 3-0-0-SNAPSHOT) + com.liferay.portal + portal-service + provided - - org.gcube.common - storagehub-client-wrapper - [1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT) - - - org.slf4j diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/WsUtil.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/WsUtil.java index b722156..51ec50d 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/WsUtil.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/WsUtil.java @@ -10,15 +10,7 @@ import java.util.Map; import javax.servlet.http.HttpServletRequest; -//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.workspace.Workspace; -//import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException; import org.gcube.common.portal.PortalContext; -import org.gcube.common.scope.api.ScopeProvider; -import org.gcube.common.storagehubwrapper.server.StorageHubWrapper; -import org.gcube.common.storagehubwrapper.server.tohl.Workspace; import org.gcube.portlets.widgets.wsthreddssync.shared.GatewayRolesThredds; import org.gcube.vomanagement.usermanagement.GroupManager; import org.gcube.vomanagement.usermanagement.RoleManager; @@ -39,17 +31,13 @@ import com.liferay.portal.service.UserLocalServiceUtil; /** * The Class WsUtil. * - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Nov 25, 2016 + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Nov 25, 2016 */ public class WsUtil { - - /** The logger. */ private static Logger logger = LoggerFactory.getLogger(WsUtil.class); - /** * Checks if is within portal. * @@ -59,14 +47,12 @@ public class WsUtil { try { UserLocalServiceUtil.getService(); return true; - } - catch (Exception ex) { + } catch (Exception ex) { logger.trace("Development Mode ON"); return false; } } - /** * Checks if is session expired. * @@ -76,119 +62,86 @@ public class WsUtil { */ public static boolean isSessionExpired(HttpServletRequest httpServletRequest) throws Exception { logger.trace("workspace session validating..."); - return PortalContext.getConfiguration().getCurrentUser(httpServletRequest)==null; + return PortalContext.getConfiguration().getCurrentUser(httpServletRequest) == null; } /** - * Gets the workspace from storage hub. - * - * @param httpServletRequest the http servlet request - * @return the workspace from storage hub - * @throws Exception the exception - */ - public Workspace getWorkspaceFromStorageHub(HttpServletRequest httpServletRequest) throws Exception { - logger.trace("Get Workspace"); -// String scope = PortalContext.getConfiguration().getCurrentScope(httpServletRequest); - - GCubeUser user = null; - - try { - String scope = PortalContext.getConfiguration().getCurrentScope(httpServletRequest); - user = PortalContext.getConfiguration().getCurrentUser(httpServletRequest); - if (user == null || user.getUsername().isEmpty()) - throw new Exception("Session expired"); - - ScopeProvider.instance.set(scope); - logger.trace("Scope provider instancied at: "+scope); - - logger.debug("Getting " + StorageHubWrapper.class.getSimpleName() + " for user: " + user.getUsername() - + " by using the scope: " + scope); - - String token = PortalContext.getConfiguration().getCurrentUserToken(scope, user.getUsername()); - StorageHubWrapper shWrapper = new StorageHubWrapper(scope, token, false, false, true); - return shWrapper.getWorkspace(); - } catch (Exception e) { - logger.error("Error on getting the Workspace via SHUB wrapper", e); - throw new Exception("Error on gettig the Workspace for userId: " + user); - } - } - - /** - * Gets the list of Scopes (Root-VO, VOs and VREs) for user and the Thredds roles that user has in them. + * Gets the list of Scopes (Root-VO, VOs and VREs) for user and the Thredds + * roles that user has in them. * * @param user the user * @return the VREs and Thredds roles for a given user */ - public static Map getScopesWithThreddsRolesForUser(GCubeUser user){ - logger.info("called getScopesThreddsRolesForUser user: "+user+", in all contexts"); - + public static Map getScopesWithThreddsRolesForUser(GCubeUser user) { + logger.info("called getScopesThreddsRolesForUser user: " + user + ", in all contexts"); + GroupManager groupManager = new LiferayGroupManager(); Map mapRoleByGroupSingleVre = new HashMap(); try { - - //Retrieving the list of VOs and VREs + + // Retrieving the list of VOs and VREs List listOfGroups = groupManager.listGroupsByUser(user.getUserId()); - //adding also the ROOT-VO + // adding also the ROOT-VO listOfGroups.add(groupManager.getRootVO()); for (GCubeGroup gCubeGroup : listOfGroups) { GatewayRolesThredds threddsRole = getThreddsRoleFor(user, gCubeGroup); - if(threddsRole != null) { + if (threddsRole != null) { String toFullScope = groupManager.getInfrastructureScope(gCubeGroup.getGroupId()); mapRoleByGroupSingleVre.put(toFullScope, threddsRole); } } - - logger.info("For user: "+user+", returning Map (VRE, ThreddsRoles) " + mapRoleByGroupSingleVre); + + logger.info("For user: " + user + ", returning Map (VRE, ThreddsRoles) " + mapRoleByGroupSingleVre); return mapRoleByGroupSingleVre; - }catch (UserManagementSystemException | UserRetrievalFault | GroupRetrievalFault e) { - logger.error("An error occurred during geThreddsVreRolesForUser: "+user, e); + } catch (UserManagementSystemException | UserRetrievalFault | GroupRetrievalFault e) { + logger.error("An error occurred during geThreddsVreRolesForUser: " + user, e); return null; - } + } } - /** * Gets the (highest) thredds role for the user in the scope * - * @param user the user + * @param user the user * @param scope the vre * @return the thredds role for */ - public static GatewayRolesThredds getThreddsRoleFor(GCubeUser user, GCubeGroup scope){ - if(user==null || scope==null) { - logger.warn("called getThreddsRoleFor with invalid parameter user: "+user+", in the scope: "+scope, ", returning null"); + public static GatewayRolesThredds getThreddsRoleFor(GCubeUser user, GCubeGroup scope) { + if (user == null || scope == null) { + logger.warn("called getThreddsRoleFor with invalid parameter user: " + user + ", in the scope: " + scope, + ", returning null"); return null; } - - logger.info("called getThreddsRoleFor user: "+user.getUsername()+", in the scope: "+scope.getGroupName()); + + logger.info("called getThreddsRoleFor user: " + user.getUsername() + ", in the scope: " + scope.getGroupName()); try { RoleManager roleManager = new LiferayRoleManager(); List roles = roleManager.listRolesByUserAndGroup(user.getUserId(), scope.getGroupId()); List threddsRoles = new ArrayList(); for (GCubeRole gCubeRole : roles) { - if(gCubeRole.getRoleName().equalsIgnoreCase(GatewayRolesThredds.DATA_MANAGER.getRoleName())){ + if (gCubeRole.getRoleName().equalsIgnoreCase(GatewayRolesThredds.DATA_MANAGER.getRoleName())) { threddsRoles.add(GatewayRolesThredds.DATA_MANAGER); } - if(gCubeRole.getRoleName().equalsIgnoreCase(GatewayRolesThredds.DATA_EDITOR.getRoleName())){ + if (gCubeRole.getRoleName().equalsIgnoreCase(GatewayRolesThredds.DATA_EDITOR.getRoleName())) { threddsRoles.add(GatewayRolesThredds.DATA_EDITOR); } } - - logger.info("For user: "+user.getUsername()+" in the scope: "+scope.getGroupName()+" read the role/s: " + threddsRoles); - + + logger.info("For user: " + user.getUsername() + " in the scope: " + scope.getGroupName() + + " read the role/s: " + threddsRoles); + GatewayRolesThredds toReturn = null; if (threddsRoles.contains(GatewayRolesThredds.DATA_MANAGER)) toReturn = GatewayRolesThredds.DATA_MANAGER; else if (threddsRoles.contains(GatewayRolesThredds.DATA_EDITOR)) toReturn = GatewayRolesThredds.DATA_EDITOR; - + logger.info("returning highest role: " + toReturn); return toReturn; - }catch (UserRetrievalFault | GroupRetrievalFault e) { - logger.error("An error occurred during getVreRoleForUser: "+user, e); + } catch (UserRetrievalFault | GroupRetrievalFault e) { + logger.error("An error occurred during getVreRoleForUser: " + user, e); return null; } } - } diff --git a/src/test/java/org/gcube/portlets/widgets/wsthreddssync/TestWsThreddsQuery.java b/src/test/java/org/gcube/portlets/widgets/wsthreddssync/TestWsThreddsQuery.java index 255cb7e..51e2257 100644 --- a/src/test/java/org/gcube/portlets/widgets/wsthreddssync/TestWsThreddsQuery.java +++ b/src/test/java/org/gcube/portlets/widgets/wsthreddssync/TestWsThreddsQuery.java @@ -1,12 +1,5 @@ package org.gcube.portlets.widgets.wsthreddssync; -import java.util.Map; - -import org.gcube.common.scope.api.ScopeProvider; -import org.gcube.common.storagehubwrapper.server.StorageHubWrapper; -import org.gcube.common.storagehubwrapper.server.tohl.Workspace; -import org.gcube.portal.wssynclibrary.shared.ItemNotSynched; - public class TestWsThreddsQuery { final static String folderId = "61ea6d91-4b09-43ec-91c4-b2fdb9b8c538"; @@ -14,21 +7,20 @@ public class TestWsThreddsQuery { static String username = "francesco.mangiacrapa"; // NextNeext Francesco's Token static String token = "TOKEN"; - public static final String WS_SYNCH_SYNCH_STATUS = "WS-SYNCH.SYNCH-STATUS"; + /* public static void main(String[] args) { isItemSynched(); - + } + - public static void isItemSynched(){ - + public static void isItemSynched() { + try { ScopeProvider.instance.set(scope); - - StorageHubWrapper shWrapper = new StorageHubWrapper(scope, token, false, false, true); - Workspace workspace = shWrapper.getWorkspace(); + Map metadata = workspace.getMetadata(folderId); if (metadata == null || metadata.isEmpty()) { @@ -38,12 +30,13 @@ public class TestWsThreddsQuery { String wsSyncStatus = (String) metadata.get(WS_SYNCH_SYNCH_STATUS); System.out.println("Current: " + WS_SYNCH_SYNCH_STATUS + " has value: " + wsSyncStatus); - //System.out.println("isSynched: " + isSynched); + // System.out.println("isSynched: " + isSynched); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } - + } + */ } diff --git a/src/test/java/org/gcube/portlets/widgets/wsthreddssync/UnSyncThreddsFolders.java b/src/test/java/org/gcube/portlets/widgets/wsthreddssync/UnSyncThreddsFolders.java index a30b794..fc7fcd1 100644 --- a/src/test/java/org/gcube/portlets/widgets/wsthreddssync/UnSyncThreddsFolders.java +++ b/src/test/java/org/gcube/portlets/widgets/wsthreddssync/UnSyncThreddsFolders.java @@ -6,15 +6,6 @@ package org.gcube.portlets.widgets.wsthreddssync; import java.util.ArrayList; import java.util.List; -import org.gcube.common.authorization.library.provider.SecurityTokenProvider; -import org.gcube.common.scope.api.ScopeProvider; -import org.gcube.common.storagehubwrapper.server.StorageHubWrapper; -import org.gcube.common.storagehubwrapper.server.tohl.Workspace; -import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem; -import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.InternalErrorException; -import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.ItemNotFoundException; -import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.WorkspaceFolderNotFoundException; -import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncFolderDescriptor; import org.gcube.portlets.widgets.wsthreddssync.server.SyncronizeWithThredds; @@ -43,21 +34,6 @@ public class UnSyncThreddsFolders { public static SyncronizeWithThredds syncService = new SyncronizeWithThredds(); - /** - * Gets the workspace. - * - * @return the workspace - * @throws InternalErrorException the internal error exception - * @throws HomeNotFoundException the home not found exception - * @throws WorkspaceFolderNotFoundException the workspace folder not found exception - */ - public static Workspace getWorkspace() throws Exception{ - - ScopeProvider.instance.set(scope); - StorageHubWrapper shWrapper = new StorageHubWrapper(scope, token, false, false, true); - return shWrapper.getWorkspace(); - } - /** * The main method. @@ -67,9 +43,9 @@ public class UnSyncThreddsFolders { * @throws InternalErrorException the internal error exception * @throws HomeNotFoundException the home not found exception */ + /* public static void main(String[] args) throws Exception { - Workspace ws = getWorkspace(); unsycFirstLevel(ws, ws.getRoot().getId(), false); System.out.println("UnSync completed"); @@ -95,14 +71,6 @@ public class UnSyncThreddsFolders { - /** - * Unsyc first level. - * - * @param ws the ws - * @param itemId the item id - * @param depthUnsync the depth unsync - * @throws Exception - */ public static void unsycFirstLevel(Workspace ws, String itemId, boolean depthUnsync) throws Exception{ WorkspaceItem item; @@ -134,11 +102,6 @@ public class UnSyncThreddsFolders { } - /** - * Unsyn folder. - * - * @param workspaceItem the workspace item - */ public static void unsynFolder(WorkspaceItem workspaceItem) { if(workspaceItem==null) @@ -183,6 +146,7 @@ public class UnSyncThreddsFolders { // } // } } + */ } -- 2.17.1 From ac7fb2101bc8ce884540d582ad9746f49ca3f3a9 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Wed, 12 May 2021 16:32:30 +0200 Subject: [PATCH 08/20] fixing method isItemSynched --- .../server/SyncronizeWithThredds.java | 15 ++++++++++++--- .../server/ThreddsWorkspaceSyncServiceImpl.java | 14 ++++++++------ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java index f3240c5..af067e0 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java @@ -25,6 +25,7 @@ import org.gcube.vomanagement.usermanagement.model.GCubeUser; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +// TODO: Auto-generated Javadoc /** * The Class SyncronizeWithThredds. * @@ -116,12 +117,18 @@ public class SyncronizeWithThredds { /** * Checks if is item synched. * - * @param folderId the folder id + * @param folderId the folder id + * @param scope the scope + * @param userToken the user token * @return the th sync folder descriptor * @throws ItemNotSynched the item not synched * @throws Exception the exception */ - public ThSyncFolderDescriptor isItemSynched(String folderId) throws ItemNotSynched { + public ThSyncFolderDescriptor isItemSynched(String folderId, String scope, String userToken) + throws ItemNotSynched, Exception { + + setContextParameters(scope, userToken); + ThSyncFolderDescriptor config = null; try { config = workspaceThreddsSynchronize.getConfiguration(folderId); @@ -381,7 +388,9 @@ public class SyncronizeWithThredds { /** * Gets the sync status info. * - * @param itemId the item id + * @param itemId the item id + * @param scope the scope + * @param userToken the user token * @return the sync status info * @throws Exception the exception */ diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java index 1784d2d..0a6e57e 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java @@ -126,14 +126,14 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem logger.debug("called isItemSynched for folderId: " + folderId); try { - - ThSyncFolderDescriptor theConfig = getSyncService().isItemSynched(folderId); + GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); + String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest()); + String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername()); + + ThSyncFolderDescriptor theConfig = getSyncService().isItemSynched(folderId,wsScope,wsUserToken); if (theConfig != null) { logger.info("Folder id: " + folderId + " is synched"); - GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); - String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest()); - String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername()); Sync_Status theStatus = getSyncService().getSyncStatusInfo(folderId,wsScope,wsUserToken); WsThreddsSynchFolderDescriptor toWsThreddFolder = BeanConverter.toWsThreddsFolderConfig(theConfig, theStatus); @@ -206,7 +206,9 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem try { GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); - ThSyncFolderDescriptor foldeDesr = getSyncService().isItemSynched(folderId); + String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest()); + String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername()); + ThSyncFolderDescriptor foldeDesr = getSyncService().isItemSynched(folderId,wsScope,wsUserToken); return getSyncService().doUnSync(folderId, true, foldeDesr.getConfiguration(), this.getThreadLocalRequest(), user); } catch (Exception e) { -- 2.17.1 From 2cdc935d37f10f06461c7ad3d0b55a706d5acd82 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 13 May 2021 15:02:53 +0200 Subject: [PATCH 09/20] removed geSyncStatus --- .../binder/ShowThreddsFolderInfoView.java | 8 +-- .../wsthreddssync/server/BeanConverter.java | 5 +- .../server/SyncronizeWithThredds.java | 29 +++++----- .../ThreddsWorkspaceSyncServiceImpl.java | 5 +- .../WsThreddsSynchFolderDescriptor.java | 54 ++----------------- 5 files changed, 26 insertions(+), 75 deletions(-) diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/ShowThreddsFolderInfoView.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/ShowThreddsFolderInfoView.java index 0fd0728..a9c32dc 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/ShowThreddsFolderInfoView.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/ShowThreddsFolderInfoView.java @@ -214,9 +214,7 @@ public abstract class ShowThreddsFolderInfoView extends Composite { return; } - if(syncFolderDesc.getSyncStatus()!=null) { - this.field_folder_status.setValue(syncFolderDesc.getSyncStatus().toString()); - } + if(syncFolderDesc.getSelectedScope()!=null) { String toValue = FormatUtil.toScopeValue(syncFolderDesc.getSelectedScope()); @@ -231,6 +229,9 @@ public abstract class ShowThreddsFolderInfoView extends Composite { this.field_folder_path.setValue(sfd.getFolderPath()); this.field_folder_path.setTitle(sfd.getFolderPath()); this.field_folder_locked.setValue(sfd.isLocked()+""); + + if(sfd.getElementInfo()!=null) + this.field_folder_status.setValue(sfd.getElementInfo().getSyncStatus().toString()); ThSynchFolderConfiguration config = sfd.getConfiguration(); @@ -239,6 +240,7 @@ public abstract class ShowThreddsFolderInfoView extends Composite { this.field_catalogue_name.setTitle(config.getToCreateCatalogName()); this.field_remote_path.setValue(config.getRemotePath()); this.field_remote_path.setTitle(config.getRemotePath()); + } diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/BeanConverter.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/BeanConverter.java index e57055b..9700a16 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/BeanConverter.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/BeanConverter.java @@ -1,6 +1,5 @@ package org.gcube.portlets.widgets.wsthreddssync.server; -import org.gcube.portal.wssynclibrary.shared.thredds.Sync_Status; import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncFolderDescriptor; import org.gcube.portal.wssynclibrary.shared.thredds.ThSynchFolderConfiguration; import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeScope; @@ -31,15 +30,13 @@ public class BeanConverter { * @param theStatus the the status * @return the ws thredds synch folder descriptor */ - public static WsThreddsSynchFolderDescriptor toWsThreddsFolderConfig(ThSyncFolderDescriptor t, - Sync_Status theStatus) { + public static WsThreddsSynchFolderDescriptor toWsThreddsFolderConfig(ThSyncFolderDescriptor t) { if (t == null || t.getConfiguration()==null) return null; WsThreddsSynchFolderDescriptor ws = new WsThreddsSynchFolderDescriptor(); ws.setServerFolderDescriptor(t); - ws.setSyncStatus(theStatus); // FROM TARGET TOKEN TO SCOPE // t.getConfiguration().getTargetToken() diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java index af067e0..bfd4041 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java @@ -14,7 +14,6 @@ import org.gcube.common.scope.api.ScopeProvider; import org.gcube.oidc.rest.JWTToken; import org.gcube.portal.oidc.lr62.OIDCUmaUtil; import org.gcube.portal.wssynclibrary.shared.ItemNotSynched; -import org.gcube.portal.wssynclibrary.shared.thredds.Sync_Status; import org.gcube.portal.wssynclibrary.shared.thredds.ThCatalogueBean; import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncFolderDescriptor; import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus; @@ -385,19 +384,19 @@ public class SyncronizeWithThredds { workspaceThreddsSynchronize.registerCallbackForId(folderId); } - /** - * Gets the sync status info. - * - * @param itemId the item id - * @param scope the scope - * @param userToken the user token - * @return the sync status info - * @throws Exception the exception - */ - public Sync_Status getSyncStatusInfo(String itemId, String scope, String userToken) throws Exception { - setContextParameters(scope, userToken); - return workspaceThreddsSynchronize.getInfo(itemId); - - } +// /** +// * Gets the sync status info. +// * +// * @param itemId the item id +// * @param scope the scope +// * @param userToken the user token +// * @return the sync status info +// * @throws Exception the exception +// */ +// public Sync_Status getSyncStatusInfo(String itemId, String scope, String userToken) throws Exception { +// setContextParameters(scope, userToken); +// return workspaceThreddsSynchronize.getInfoAfterCheck(itemId); +// +// } } diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java index 0a6e57e..af771cf 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java @@ -10,7 +10,6 @@ import java.util.Set; import org.gcube.common.portal.PortalContext; import org.gcube.portal.wssynclibrary.shared.ItemNotSynched; import org.gcube.portal.wssynclibrary.shared.WorkspaceFolderLocked; -import org.gcube.portal.wssynclibrary.shared.thredds.Sync_Status; import org.gcube.portal.wssynclibrary.shared.thredds.ThCatalogueBean; import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncFolderDescriptor; import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus; @@ -134,9 +133,7 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem if (theConfig != null) { logger.info("Folder id: " + folderId + " is synched"); - Sync_Status theStatus = getSyncService().getSyncStatusInfo(folderId,wsScope,wsUserToken); - WsThreddsSynchFolderDescriptor toWsThreddFolder = BeanConverter.toWsThreddsFolderConfig(theConfig, - theStatus); + WsThreddsSynchFolderDescriptor toWsThreddFolder = BeanConverter.toWsThreddsFolderConfig(theConfig); logger.debug("isItemSynched for id: " + folderId + " returning: " + toWsThreddFolder); return toWsThreddFolder; } diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/WsThreddsSynchFolderDescriptor.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/WsThreddsSynchFolderDescriptor.java index 5d9a446..6f0b605 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/WsThreddsSynchFolderDescriptor.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/WsThreddsSynchFolderDescriptor.java @@ -2,17 +2,14 @@ package org.gcube.portlets.widgets.wsthreddssync.shared; import java.io.Serializable; -import org.gcube.portal.wssynclibrary.shared.thredds.Sync_Status; import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncFolderDescriptor; - -// TODO: Auto-generated Javadoc /** * The Class WsThreddsSynchFolderDescriptor. * * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * - * May 10, 2021 + * May 13, 2021 */ public class WsThreddsSynchFolderDescriptor implements Serializable { @@ -25,33 +22,24 @@ public class WsThreddsSynchFolderDescriptor implements Serializable { private ThSyncFolderDescriptor serverFolderDescriptor; - private Sync_Status syncStatus; - /** * Instantiates a new ws thredds synch folder configuration. */ public WsThreddsSynchFolderDescriptor() { - // TODO Auto-generated constructor stub } - /** * Instantiates a new ws thredds synch folder descriptor. * - * @param selectedScope the selected scope + * @param selectedScope the selected scope * @param serverFolderDescriptor the server folder descriptor - * @param syncStatus the sync status */ - public WsThreddsSynchFolderDescriptor(GcubeScope selectedScope, ThSyncFolderDescriptor serverFolderDescriptor, - Sync_Status syncStatus) { + public WsThreddsSynchFolderDescriptor(GcubeScope selectedScope, ThSyncFolderDescriptor serverFolderDescriptor) { super(); this.selectedScope = selectedScope; this.serverFolderDescriptor = serverFolderDescriptor; - this.syncStatus = syncStatus; } - - /** * Gets the selected scope. * @@ -62,26 +50,6 @@ public class WsThreddsSynchFolderDescriptor implements Serializable { return selectedScope; } - /** - * Sets the sync status. - * - * @param syncStatus - * the new sync status - */ - public void setSyncStatus(Sync_Status syncStatus) { - this.syncStatus = syncStatus; - } - - /** - * Gets the sync status. - * - * @return the sync status - */ - public Sync_Status getSyncStatus() { - return syncStatus; - } - - /** * Sets the selected scope. * @@ -103,33 +71,21 @@ public class WsThreddsSynchFolderDescriptor implements Serializable { /** * Sets the server folder descriptor. * - * @param serverFolderDescriptor - * the new server folder descriptor + * @param serverFolderDescriptor the new server folder descriptor */ public void setServerFolderDescriptor(ThSyncFolderDescriptor serverFolderDescriptor) { this.serverFolderDescriptor = serverFolderDescriptor; } - /** - * To string. - * - * @return the string - */ - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ @Override public String toString() { StringBuilder builder = new StringBuilder(); - builder.append("WsThreddsSynchFolderDescriptor [selectedVRE="); + builder.append("WsThreddsSynchFolderDescriptor [selectedScope="); builder.append(selectedScope); builder.append(", serverFolderDescriptor="); builder.append(serverFolderDescriptor); - builder.append(", syncStatus="); - builder.append(syncStatus); builder.append("]"); return builder.toString(); } - } -- 2.17.1 From 74839e1d039d12606365757e48808c5a30004e2c Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 13 May 2021 15:43:39 +0200 Subject: [PATCH 10/20] only formatted --- .../WsThreddsSynchFolderConfiguration.java | 55 ++++--------------- 1 file changed, 12 insertions(+), 43 deletions(-) diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/WsThreddsSynchFolderConfiguration.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/WsThreddsSynchFolderConfiguration.java index f0d997d..9a43a7a 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/WsThreddsSynchFolderConfiguration.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/WsThreddsSynchFolderConfiguration.java @@ -4,16 +4,12 @@ import java.io.Serializable; import org.gcube.portal.wssynclibrary.shared.thredds.Status; - -// TODO: Auto-generated Javadoc /** * The Class WsThreddsSynchFolderConfiguration. * - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Feb 16, 2018 + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Feb 16, 2018 */ -public class WsThreddsSynchFolderConfiguration implements Serializable{ - +public class WsThreddsSynchFolderConfiguration implements Serializable { /** * @@ -31,28 +27,27 @@ public class WsThreddsSynchFolderConfiguration implements Serializable{ /** The to create catalog name. */ private String catalogName; - private Status status; //just for serialization + private Status status; // just for serialization private String rootFolderId; - /** * Instantiates a new ws thredds synch folder configuration. */ public WsThreddsSynchFolderConfiguration() { - // TODO Auto-generated constructor stub - } + } /** * Instantiates a new ws thredds synch folder configuration. * - * @param remotePath the remote path - * @param theVRE the the vre - * @param filter the filter + * @param remotePath the remote path + * @param theVRE the the vre + * @param filter the filter * @param catalogName the catalog name */ - public WsThreddsSynchFolderConfiguration(String remotePath, GcubeScope theVRE, String filter, String catalogName, String rootFolderId) { + public WsThreddsSynchFolderConfiguration(String remotePath, GcubeScope theVRE, String filter, String catalogName, + String rootFolderId) { super(); this.remotePath = remotePath; this.selectedScope = theVRE; @@ -61,7 +56,6 @@ public class WsThreddsSynchFolderConfiguration implements Serializable{ this.rootFolderId = rootFolderId; } - /** * @param rootFolderId the rootFolderId to set */ @@ -70,7 +64,6 @@ public class WsThreddsSynchFolderConfiguration implements Serializable{ this.rootFolderId = rootFolderId; } - /** * @return the rootFolderId */ @@ -79,7 +72,6 @@ public class WsThreddsSynchFolderConfiguration implements Serializable{ return rootFolderId; } - /** * Gets the remote path. * @@ -98,7 +90,6 @@ public class WsThreddsSynchFolderConfiguration implements Serializable{ this.remotePath = remotePath; } - /** * @return the selectedScope */ @@ -107,17 +98,6 @@ public class WsThreddsSynchFolderConfiguration implements Serializable{ return selectedScope; } - - /** - * @return the status - */ - public Status getStatus() { - - return status; - } - - - /** * @param selectedScope the selectedScope to set */ @@ -126,17 +106,6 @@ public class WsThreddsSynchFolderConfiguration implements Serializable{ this.selectedScope = selectedScope; } - - - /** - * @param status the status to set - */ - public void setStatus(Status status) { - - this.status = status; - } - - /** * Gets the filter. * @@ -173,8 +142,9 @@ public class WsThreddsSynchFolderConfiguration implements Serializable{ this.catalogName = catalogName; } - - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see java.lang.Object#toString() */ @Override @@ -197,5 +167,4 @@ public class WsThreddsSynchFolderConfiguration implements Serializable{ return builder.toString(); } - } -- 2.17.1 From dd3dc4a0cce774f1723ca0bce210b12a17717d17 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 14 May 2021 12:34:25 +0200 Subject: [PATCH 11/20] integrated with getConfiguration method --- .../wsthreddssync/client/WsThreddsWidget.java | 2 +- .../rpc/ThreddsWorkspaceSyncService.java | 11 +-- .../rpc/ThreddsWorkspaceSyncServiceAsync.java | 89 ++++++++----------- .../server/SyncronizeWithThredds.java | 55 ++++++------ .../ThreddsWorkspaceSyncServiceImpl.java | 6 +- 5 files changed, 77 insertions(+), 86 deletions(-) diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/WsThreddsWidget.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/WsThreddsWidget.java index 64c17a8..b8a44e8 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/WsThreddsWidget.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/WsThreddsWidget.java @@ -176,7 +176,7 @@ public class WsThreddsWidget implements HasWsSyncNotificationListner { //at least one THREDDS rights is assigned GWT.log("Performing isItemSynched: "+folder.getFolderId()); - WsThreddsWidget.wsThreddsSyncService.isItemSynched(folder.getFolderId(), new AsyncCallback() { + WsThreddsWidget.wsThreddsSyncService.getConfiguration(folder.getFolderId(), new AsyncCallback() { @Override public void onSuccess(WsThreddsSynchFolderDescriptor result) { diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/rpc/ThreddsWorkspaceSyncService.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/rpc/ThreddsWorkspaceSyncService.java index 4c20452..9fed1c5 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/rpc/ThreddsWorkspaceSyncService.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/rpc/ThreddsWorkspaceSyncService.java @@ -16,6 +16,7 @@ import com.google.gwt.user.client.rpc.RemoteService; import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; +// TODO: Auto-generated Javadoc /** * The Interface ThreddsWorkspaceSyncService. * @@ -25,15 +26,16 @@ import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; @RemoteServiceRelativePath("wsthreddssync") public interface ThreddsWorkspaceSyncService extends RemoteService { + /** - * Checks if is item synched. + * Gets the configuration. * * @param folderId the folder id - * @return the ws thredds synch folder descriptor + * @return the configuration * @throws WorkspaceFolderLocked the workspace folder locked * @throws Exception the exception */ - WsThreddsSynchFolderDescriptor isItemSynched(String folderId) throws WorkspaceFolderLocked, Exception; + WsThreddsSynchFolderDescriptor getConfiguration(String folderId) throws WorkspaceFolderLocked, Exception; /** * Do sync folder. @@ -85,9 +87,8 @@ public interface ThreddsWorkspaceSyncService extends RemoteService { /** * Gets the list of Scopes (Root-VO, VOs and VREs) for user and the Thredds roles that user has in them. * - * @param user the user * @return the VREs and Thredds roles for a given user - * @throws Exception + * @throws Exception the exception */ Map getScopesWithThreddsRolesForLoggedUser() throws Exception; } diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/rpc/ThreddsWorkspaceSyncServiceAsync.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/rpc/ThreddsWorkspaceSyncServiceAsync.java index 0372091..dd61d97 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/rpc/ThreddsWorkspaceSyncServiceAsync.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/rpc/ThreddsWorkspaceSyncServiceAsync.java @@ -13,68 +13,59 @@ import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderDescr import com.google.gwt.core.client.GWT; import com.google.gwt.user.client.rpc.AsyncCallback; - /** * The Interface ThreddsWorkspaceSyncServiceAsync. * - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Mar 8, 2018 + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Mar 8, 2018 */ -public interface ThreddsWorkspaceSyncServiceAsync -{ - - /** - * Utility class to get the RPC Async interface from client-side code. - * - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Mar 8, 2018 - */ - public static final class Util - { - private static ThreddsWorkspaceSyncServiceAsync instance; - - /** - * Gets the single instance of Util. - * - * @return single instance of Util - */ - public static final ThreddsWorkspaceSyncServiceAsync getInstance() - { - if ( instance == null ) - { - instance = (ThreddsWorkspaceSyncServiceAsync) GWT.create( ThreddsWorkspaceSyncService.class ); - } - return instance; - } - - /** - * Instantiates a new util. - */ - private Util() - { - // Utility class should not be instantiated - } - } - +public interface ThreddsWorkspaceSyncServiceAsync { /** - * Checks if is item synched. + * Utility class to get the RPC Async interface from client-side code. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Mar 8, 2018 + */ + public static final class Util { + private static ThreddsWorkspaceSyncServiceAsync instance; + + /** + * Gets the single instance of Util. + * + * @return single instance of Util + */ + public static final ThreddsWorkspaceSyncServiceAsync getInstance() { + if (instance == null) { + instance = (ThreddsWorkspaceSyncServiceAsync) GWT.create(ThreddsWorkspaceSyncService.class); + } + return instance; + } + + /** + * Instantiates a new util. + */ + private Util() { + // Utility class should not be instantiated + } + } + + /** + * Gets the configuration. * * @param folderId the folder id * @param callback the callback + * @return the configuration */ - void isItemSynched(String folderId, AsyncCallback callback); - + void getConfiguration(String folderId, AsyncCallback callback); /** * Do sync folder. * - * @param folderId the folder id + * @param folderId the folder id * @param clientConfig the client config - * @param callback the callback + * @param callback the callback */ - void doSyncFolder(String folderId, WsThreddsSynchFolderConfiguration clientConfig, AsyncCallback callback); - + void doSyncFolder(String folderId, WsThreddsSynchFolderConfiguration clientConfig, + AsyncCallback callback); /** * Monitor sync status. @@ -84,8 +75,6 @@ public interface ThreddsWorkspaceSyncServiceAsync */ void monitorSyncStatus(String folderId, AsyncCallback callback); - - /** * Gets the list of scopes for logged user. * @@ -97,13 +86,12 @@ public interface ThreddsWorkspaceSyncServiceAsync /** * Gets the available catalogues for scope. * - * @param scope the scope + * @param scope the scope * @param callback the callback * @return the available catalogues for scope */ void getAvailableCataloguesForScope(String scope, AsyncCallback> callback); - /** * Do un sync folder. * @@ -112,6 +100,5 @@ public interface ThreddsWorkspaceSyncServiceAsync */ void doUnSyncFolder(String folderId, AsyncCallback callback); - void getScopesWithThreddsRolesForLoggedUser(AsyncCallback> callback); } diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java index bfd4041..5807a4d 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java @@ -4,6 +4,7 @@ package org.gcube.portlets.widgets.wsthreddssync.server; import java.util.List; +import java.util.Map; import javax.servlet.http.HttpServletRequest; @@ -20,6 +21,7 @@ import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus; import org.gcube.portal.wssynclibrary.shared.thredds.ThSynchFolderConfiguration; import org.gcube.portal.wssynclibrary.thredds.WorkspaceThreddsSynchronize; import org.gcube.usecases.ws.thredds.faults.WorkspaceNotSynchedException; +import org.gcube.usecases.ws.thredds.model.ContainerType; import org.gcube.vomanagement.usermanagement.model.GCubeUser; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -116,28 +118,44 @@ public class SyncronizeWithThredds { /** * Checks if is item synched. * - * @param folderId the folder id - * @param scope the scope - * @param userToken the user token - * @return the th sync folder descriptor + * @param folderId the folder id + * @param scope the scope + * @param userToken the user token + * @param itemProperties the item properties + * @param itemType the item type + * @return true, if is item synched * @throws ItemNotSynched the item not synched * @throws Exception the exception */ - public ThSyncFolderDescriptor isItemSynched(String folderId, String scope, String userToken) - throws ItemNotSynched, Exception { + public boolean isItemSynched(String folderId, String scope, String userToken, Map itemProperties, + ContainerType itemType) throws ItemNotSynched, Exception { setContextParameters(scope, userToken); + return workspaceThreddsSynchronize.isItemSynched(folderId, itemProperties, itemType); + } + + /** + * Gets the configuration. + * + * @param folderId the folder id + * @param scope the scope + * @param userToken the user token + * @return the configuration + * @throws ItemNotSynched the item not synched + * @throws Exception the exception + */ + public ThSyncFolderDescriptor getConfiguration(String folderId, String scope, String userToken) + throws ItemNotSynched, Exception { ThSyncFolderDescriptor config = null; try { + setContextParameters(scope, userToken); config = workspaceThreddsSynchronize.getConfiguration(folderId); + } catch (WorkspaceNotSynchedException e) { - logger.debug("WorkspaceNotSynchedException catched, the item id: " + folderId + " is not synched"); - throw new ItemNotSynched("the item id: " + folderId + " is not synched"); + logger.debug("WorkspaceNotSynchedException catched. The item with id: " + folderId + " is not synched"); } catch (Exception e) { - logger.debug("Error on getting configuration for the item id: " + folderId - + ", returning null (means not synched)"); - return null; + logger.error("Error on reading the configuration for id: " + folderId, e); } return config; @@ -384,19 +402,4 @@ public class SyncronizeWithThredds { workspaceThreddsSynchronize.registerCallbackForId(folderId); } -// /** -// * Gets the sync status info. -// * -// * @param itemId the item id -// * @param scope the scope -// * @param userToken the user token -// * @return the sync status info -// * @throws Exception the exception -// */ -// public Sync_Status getSyncStatusInfo(String itemId, String scope, String userToken) throws Exception { -// setContextParameters(scope, userToken); -// return workspaceThreddsSynchronize.getInfoAfterCheck(itemId); -// -// } - } diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java index af771cf..6bab207 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java @@ -121,7 +121,7 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem */ // UPDATED @Override - public WsThreddsSynchFolderDescriptor isItemSynched(String folderId) throws WorkspaceFolderLocked, Exception { + public WsThreddsSynchFolderDescriptor getConfiguration(String folderId) throws WorkspaceFolderLocked, Exception { logger.debug("called isItemSynched for folderId: " + folderId); try { @@ -129,7 +129,7 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest()); String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername()); - ThSyncFolderDescriptor theConfig = getSyncService().isItemSynched(folderId,wsScope,wsUserToken); + ThSyncFolderDescriptor theConfig = getSyncService().getConfiguration(folderId,wsScope,wsUserToken); if (theConfig != null) { logger.info("Folder id: " + folderId + " is synched"); @@ -205,7 +205,7 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest()); String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername()); - ThSyncFolderDescriptor foldeDesr = getSyncService().isItemSynched(folderId,wsScope,wsUserToken); + ThSyncFolderDescriptor foldeDesr = getSyncService().getConfiguration(folderId,wsScope,wsUserToken); return getSyncService().doUnSync(folderId, true, foldeDesr.getConfiguration(), this.getThreadLocalRequest(), user); } catch (Exception e) { -- 2.17.1 From 5cc52d9e3ca972a47cb1408a5ca302c336d0059e Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Mon, 17 May 2021 18:17:40 +0200 Subject: [PATCH 12/20] the getConfiguration method has been updated by including also the engine.check --- .../wsthreddssync/client/WsThreddsWidget.java | 14 ++++++++--- .../rpc/ThreddsWorkspaceSyncService.java | 15 ++++++++--- .../rpc/ThreddsWorkspaceSyncServiceAsync.java | 10 +++++++- .../binder/MonitorFolderSyncStatusView.java | 1 - .../server/SyncronizeWithThredds.java | 25 +++++++++++++++---- .../ThreddsWorkspaceSyncServiceImpl.java | 21 ++++++++++------ 6 files changed, 64 insertions(+), 22 deletions(-) diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/WsThreddsWidget.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/WsThreddsWidget.java index b8a44e8..f2d4f70 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/WsThreddsWidget.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/WsThreddsWidget.java @@ -176,7 +176,7 @@ public class WsThreddsWidget implements HasWsSyncNotificationListner { //at least one THREDDS rights is assigned GWT.log("Performing isItemSynched: "+folder.getFolderId()); - WsThreddsWidget.wsThreddsSyncService.getConfiguration(folder.getFolderId(), new AsyncCallback() { + WsThreddsWidget.wsThreddsSyncService.getConfiguration(folder.getFolderId(), true, new AsyncCallback() { @Override public void onSuccess(WsThreddsSynchFolderDescriptor result) { @@ -196,7 +196,12 @@ public class WsThreddsWidget implements HasWsSyncNotificationListner { @Override public void onFailure(Throwable caught) { - box.hide(); + try { + hpLoader.clear(); + hpLoader.setVisible(false); + }catch (Exception e) { + //Silent + } if(caught instanceof WorkspaceFolderLocked){ viewManager.showMonitorSyncToFolder(folder,syncEventsListeners); @@ -204,7 +209,10 @@ public class WsThreddsWidget implements HasWsSyncNotificationListner { } viewManager.cancelMonitor(folder); - Window.alert(caught.getMessage()); + Alert alert = new Alert(caught.getMessage(), AlertType.ERROR); + alert.setClose(false); + box.add(alert); + //Window.alert(caught.getMessage()); } }); } diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/rpc/ThreddsWorkspaceSyncService.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/rpc/ThreddsWorkspaceSyncService.java index 9fed1c5..59d1e16 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/rpc/ThreddsWorkspaceSyncService.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/rpc/ThreddsWorkspaceSyncService.java @@ -11,6 +11,7 @@ import org.gcube.portlets.widgets.wsthreddssync.shared.GatewayRolesThredds; import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeScope; import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderConfiguration; import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderDescriptor; +import org.gcube.usecases.ws.thredds.SyncEngine; import com.google.gwt.user.client.rpc.RemoteService; import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; @@ -30,12 +31,16 @@ public interface ThreddsWorkspaceSyncService extends RemoteService { /** * Gets the configuration. * - * @param folderId the folder id - * @return the configuration + * @param folderId the folder id + * @param loadStatus the load status. If true it loads the status by calling the + * {@link SyncEngine#check(String, boolean)} but it is time + * consuming. No otherwise. + * @return the ws thredds synch folder descriptor * @throws WorkspaceFolderLocked the workspace folder locked - * @throws Exception the exception + * @throws Exception the exception */ - WsThreddsSynchFolderDescriptor getConfiguration(String folderId) throws WorkspaceFolderLocked, Exception; + WsThreddsSynchFolderDescriptor getConfiguration(String folderId, boolean loadStatus) + throws WorkspaceFolderLocked, Exception; /** * Do sync folder. @@ -91,4 +96,6 @@ public interface ThreddsWorkspaceSyncService extends RemoteService { * @throws Exception the exception */ Map getScopesWithThreddsRolesForLoggedUser() throws Exception; + + } diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/rpc/ThreddsWorkspaceSyncServiceAsync.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/rpc/ThreddsWorkspaceSyncServiceAsync.java index dd61d97..4e6bb34 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/rpc/ThreddsWorkspaceSyncServiceAsync.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/rpc/ThreddsWorkspaceSyncServiceAsync.java @@ -13,6 +13,7 @@ import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderDescr import com.google.gwt.core.client.GWT; import com.google.gwt.user.client.rpc.AsyncCallback; +// TODO: Auto-generated Javadoc /** * The Interface ThreddsWorkspaceSyncServiceAsync. * @@ -52,10 +53,11 @@ public interface ThreddsWorkspaceSyncServiceAsync { * Gets the configuration. * * @param folderId the folder id + * @param loadStatus the load status * @param callback the callback * @return the configuration */ - void getConfiguration(String folderId, AsyncCallback callback); + void getConfiguration(String folderId, boolean loadStatus, AsyncCallback callback); /** * Do sync folder. @@ -100,5 +102,11 @@ public interface ThreddsWorkspaceSyncServiceAsync { */ void doUnSyncFolder(String folderId, AsyncCallback callback); + /** + * Gets the scopes with thredds roles for logged user. + * + * @param callback the callback + * @return the scopes with thredds roles for logged user + */ void getScopesWithThreddsRolesForLoggedUser(AsyncCallback> callback); } diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/MonitorFolderSyncStatusView.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/MonitorFolderSyncStatusView.java index f80a7f7..3bc422a 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/MonitorFolderSyncStatusView.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/MonitorFolderSyncStatusView.java @@ -26,7 +26,6 @@ import com.google.gwt.user.client.ui.HTMLPanel; import com.google.gwt.user.client.ui.Widget; - // TODO: Auto-generated Javadoc /** * The Class ShowThreddsFolderInfoView. diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java index 5807a4d..ed07d7d 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java @@ -15,11 +15,13 @@ import org.gcube.common.scope.api.ScopeProvider; import org.gcube.oidc.rest.JWTToken; import org.gcube.portal.oidc.lr62.OIDCUmaUtil; import org.gcube.portal.wssynclibrary.shared.ItemNotSynched; +import org.gcube.portal.wssynclibrary.shared.WorkspaceFolderLocked; import org.gcube.portal.wssynclibrary.shared.thredds.ThCatalogueBean; import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncFolderDescriptor; import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus; import org.gcube.portal.wssynclibrary.shared.thredds.ThSynchFolderConfiguration; import org.gcube.portal.wssynclibrary.thredds.WorkspaceThreddsSynchronize; +import org.gcube.usecases.ws.thredds.SyncEngine; import org.gcube.usecases.ws.thredds.faults.WorkspaceNotSynchedException; import org.gcube.usecases.ws.thredds.model.ContainerType; import org.gcube.vomanagement.usermanagement.model.GCubeUser; @@ -137,25 +139,38 @@ public class SyncronizeWithThredds { /** * Gets the configuration. * - * @param folderId the folder id - * @param scope the scope - * @param userToken the user token + * @param folderId the folder id + * @param loadStatus the load status. If true it loads the status by calling the + * {@link SyncEngine#check(String, boolean)} but it is time + * consuming. Otherwise it callas the + * {@link SyncEngine#getConfig(String)} without sync status + * @param scope the scope + * @param userToken the user token * @return the configuration * @throws ItemNotSynched the item not synched * @throws Exception the exception */ - public ThSyncFolderDescriptor getConfiguration(String folderId, String scope, String userToken) + public ThSyncFolderDescriptor getConfiguration(String folderId, boolean loadStatus, String scope, String userToken) throws ItemNotSynched, Exception { ThSyncFolderDescriptor config = null; try { setContextParameters(scope, userToken); - config = workspaceThreddsSynchronize.getConfiguration(folderId); + + if (loadStatus) { + config = workspaceThreddsSynchronize.checkItemSynched(folderId); + } else { + config = workspaceThreddsSynchronize.getConfiguration(folderId); + } } catch (WorkspaceNotSynchedException e) { logger.debug("WorkspaceNotSynchedException catched. The item with id: " + folderId + " is not synched"); + } catch (WorkspaceFolderLocked e1) { + logger.info("The folder with id: " + folderId + " is locked"); + throw new Exception("The folder with id: "+folderId +" is currently locked. Another sync process is in progress"); } catch (Exception e) { logger.error("Error on reading the configuration for id: " + folderId, e); + throw e; } return config; diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java index 6bab207..082f5d5 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java @@ -20,6 +20,7 @@ import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeScope; import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeScopeType; import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderConfiguration; import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderDescriptor; +import org.gcube.usecases.ws.thredds.SyncEngine; import org.gcube.vomanagement.usermanagement.GroupManager; import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault; import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException; @@ -34,7 +35,7 @@ import org.slf4j.LoggerFactory; import com.google.gwt.user.server.rpc.RemoteServiceServlet; import com.liferay.portal.service.UserLocalServiceUtil; -// TODO: Auto-generated Javadoc + /** * The server side implementation of the RPC service. * @@ -112,24 +113,28 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem } /** - * Checks if is item synched. + * Gets the configuration. * - * @param folderId the folder id + * @param folderId the folder id + * @param loadStatus the load status. If true it loads the status by calling the + * {@link SyncEngine#check(String, boolean)} but it is time + * consuming. No otherwise. * @return the ws thredds synch folder descriptor * @throws WorkspaceFolderLocked the workspace folder locked * @throws Exception the exception */ - // UPDATED @Override - public WsThreddsSynchFolderDescriptor getConfiguration(String folderId) throws WorkspaceFolderLocked, Exception { + public WsThreddsSynchFolderDescriptor getConfiguration(String folderId, boolean loadStatus) + throws WorkspaceFolderLocked, Exception { logger.debug("called isItemSynched for folderId: " + folderId); try { GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest()); String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername()); - - ThSyncFolderDescriptor theConfig = getSyncService().getConfiguration(folderId,wsScope,wsUserToken); + + ThSyncFolderDescriptor theConfig = getSyncService().getConfiguration(folderId, loadStatus, wsScope, + wsUserToken); if (theConfig != null) { logger.info("Folder id: " + folderId + " is synched"); @@ -205,7 +210,7 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest()); String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername()); - ThSyncFolderDescriptor foldeDesr = getSyncService().getConfiguration(folderId,wsScope,wsUserToken); + ThSyncFolderDescriptor foldeDesr = getSyncService().getConfiguration(folderId, false, wsScope, wsUserToken); return getSyncService().doUnSync(folderId, true, foldeDesr.getConfiguration(), this.getThreadLocalRequest(), user); } catch (Exception e) { -- 2.17.1 From 54600fe288a1767cad70be4728140b9cc5a7a838 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 18 May 2021 12:55:44 +0200 Subject: [PATCH 13/20] adding context switch to getConfiguration when needed --- .../server/SyncronizeWithThredds.java | 72 ++++++++++++++----- .../ThreddsWorkspaceSyncServiceImpl.java | 10 +-- 2 files changed, 56 insertions(+), 26 deletions(-) diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java index ed07d7d..a8252f4 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java @@ -28,11 +28,12 @@ import org.gcube.vomanagement.usermanagement.model.GCubeUser; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -// TODO: Auto-generated Javadoc + /** * The Class SyncronizeWithThredds. * * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Feb 7, 2018 + * updated May, 2021 */ public class SyncronizeWithThredds { @@ -40,7 +41,7 @@ public class SyncronizeWithThredds { private Logger logger = LoggerFactory.getLogger(SyncronizeWithThredds.class); /** The workspace thredds synchronize. */ - private WorkspaceThreddsSynchronize workspaceThreddsSynchronize; + private WorkspaceThreddsSynchronize workspaceThreddsSynchronizeLib; /** The Constant sdf. */ // private static final SimpleDateFormat sdf = new @@ -54,7 +55,7 @@ public class SyncronizeWithThredds { * @param httpSession the http session */ public SyncronizeWithThredds() { - this.workspaceThreddsSynchronize = WorkspaceThreddsSynchronize.getInstance(); + this.workspaceThreddsSynchronizeLib = WorkspaceThreddsSynchronize.getInstance(); } /** @@ -133,7 +134,7 @@ public class SyncronizeWithThredds { ContainerType itemType) throws ItemNotSynched, Exception { setContextParameters(scope, userToken); - return workspaceThreddsSynchronize.isItemSynched(folderId, itemProperties, itemType); + return workspaceThreddsSynchronizeLib.isItemSynched(folderId, itemProperties, itemType); } /** @@ -142,25 +143,44 @@ public class SyncronizeWithThredds { * @param folderId the folder id * @param loadStatus the load status. If true it loads the status by calling the * {@link SyncEngine#check(String, boolean)} but it is time - * consuming. Otherwise it callas the + * consuming. Otherwise it calls the * {@link SyncEngine#getConfig(String)} without sync status - * @param scope the scope - * @param userToken the user token + * @param httpRequest the http request + * @param user the user * @return the configuration * @throws ItemNotSynched the item not synched * @throws Exception the exception */ - public ThSyncFolderDescriptor getConfiguration(String folderId, boolean loadStatus, String scope, String userToken) + public ThSyncFolderDescriptor getConfiguration(String folderId, boolean loadStatus, HttpServletRequest httpRequest, GCubeUser user) throws ItemNotSynched, Exception { ThSyncFolderDescriptor config = null; + String wsScope = PortalContext.getConfiguration().getCurrentScope(httpRequest); + String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername()); + String originalScope = wsScope; + String originalToken = wsUserToken; + String previousUmaToken = null; + String targetScope = null; try { - setContextParameters(scope, userToken); + + setContextParameters(wsScope, wsUserToken); if (loadStatus) { - config = workspaceThreddsSynchronize.checkItemSynched(folderId); + + config = workspaceThreddsSynchronizeLib.getConfiguration(folderId); + // context switch for UMA token + targetScope = config.getConfiguration().getTargetContext(); + previousUmaToken = changeContextForUMA(httpRequest, user, targetScope); + + // context switch for gcube-token and scope + // getting token into target scope + String targetScopeUserToken = PortalContext.getConfiguration().getCurrentUserToken(targetScope, + user.getUsername()); + setContextParameters(targetScope, targetScopeUserToken); + + config = workspaceThreddsSynchronizeLib.checkItemSynched(folderId); } else { - config = workspaceThreddsSynchronize.getConfiguration(folderId); + config = workspaceThreddsSynchronizeLib.getConfiguration(folderId); } } catch (WorkspaceNotSynchedException e) { @@ -171,6 +191,22 @@ public class SyncronizeWithThredds { } catch (Exception e) { logger.error("Error on reading the configuration for id: " + folderId, e); throw e; + } finally { + + if(previousUmaToken!=null) { + // resetting UMA token in the WS scope + setContextForUMA(previousUmaToken); + } + + if (originalScope != null && targetScope!=null && originalScope.compareTo(targetScope) != 0) { + logger.info("Resetting the scope: " + originalScope + " which was original WS context"); + ScopeProvider.instance.set(originalScope); + if (originalToken != null) { + logger.info("Resetting the user token: " + originalToken.substring(0, 10) + + "-MASKED-TOKEN which was original WS context"); + SecurityTokenProvider.instance.set(originalToken); + } + } } return config; @@ -208,7 +244,7 @@ public class SyncronizeWithThredds { setContextParameters(targetScope, targetScopeUserToken); // calling the engine - listCatalogues = workspaceThreddsSynchronize.getAvailableCatalogues(); + listCatalogues = workspaceThreddsSynchronizeLib.getAvailableCatalogues(); } catch (Exception e) { logger.error("Error on getting available Catalogues in the scope: " + targetScope, e); @@ -276,7 +312,7 @@ public class SyncronizeWithThredds { user.getUsername()); setContextParameters(targetScope, targetScopeUserToken); - ThSyncFolderDescriptor folder = workspaceThreddsSynchronize.checkItemSynched(folderId); + ThSyncFolderDescriptor folder = workspaceThreddsSynchronizeLib.checkItemSynched(folderId); } catch (ItemNotSynched e) { firstSync = true; @@ -289,11 +325,11 @@ public class SyncronizeWithThredds { if (firstSync) { logger.info("First sync setting the synchronized folder configuration: " + thConfig); - workspaceThreddsSynchronize.setSynchronizedFolder(thConfig, folderId); + workspaceThreddsSynchronizeLib.setSynchronizedFolder(thConfig, folderId); } logger.info("Calling do sync on folder id: " + folderId); - return workspaceThreddsSynchronize.doSync(folderId); + return workspaceThreddsSynchronizeLib.doSync(folderId); } catch (Exception e) { logger.error("Error on do sync: ", e); @@ -362,7 +398,7 @@ public class SyncronizeWithThredds { user.getUsername()); setContextParameters(targetScope, targetScopeUserToken); - return workspaceThreddsSynchronize.doUnSync(folderId, deleteRemoteContent); + return workspaceThreddsSynchronizeLib.doUnSync(folderId, deleteRemoteContent); } catch (ItemNotSynched e) { throw new Exception("The item with id: " + folderId + " is not synched"); @@ -401,7 +437,7 @@ public class SyncronizeWithThredds { throws ItemNotSynched, Exception { setContextParameters(scope, userToken); - return workspaceThreddsSynchronize.monitorSyncStatus(itemId); + return workspaceThreddsSynchronizeLib.monitorSyncStatus(itemId); } /** @@ -414,7 +450,7 @@ public class SyncronizeWithThredds { */ protected void registerCallbackForId(String folderId, String scope, String userToken) throws Exception { setContextParameters(scope, userToken); - workspaceThreddsSynchronize.registerCallbackForId(folderId); + workspaceThreddsSynchronizeLib.registerCallbackForId(folderId); } } diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java index 082f5d5..73fe01f 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java @@ -130,11 +130,7 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem try { GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); - String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest()); - String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername()); - - ThSyncFolderDescriptor theConfig = getSyncService().getConfiguration(folderId, loadStatus, wsScope, - wsUserToken); + ThSyncFolderDescriptor theConfig = getSyncService().getConfiguration(folderId, loadStatus, this.getThreadLocalRequest(), user); if (theConfig != null) { logger.info("Folder id: " + folderId + " is synched"); @@ -208,9 +204,7 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem try { GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); - String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest()); - String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername()); - ThSyncFolderDescriptor foldeDesr = getSyncService().getConfiguration(folderId, false, wsScope, wsUserToken); + ThSyncFolderDescriptor foldeDesr = getSyncService().getConfiguration(folderId, false, this.getThreadLocalRequest(), user); return getSyncService().doUnSync(folderId, true, foldeDesr.getConfiguration(), this.getThreadLocalRequest(), user); } catch (Exception e) { -- 2.17.1 From d3d1e13b4c67ecfffbfbccff783f189929434289 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 18 May 2021 15:31:58 +0200 Subject: [PATCH 14/20] updated css --- .../wsthreddssync/client/WsThreddsWidget.java | 2 +- .../client/view/WsThreddsWidgetViewManager.java | 3 ++- .../wsthreddssync/public/WsThreddsWidget.css | 14 ++++++++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/WsThreddsWidget.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/WsThreddsWidget.java index f2d4f70..ae13bd8 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/WsThreddsWidget.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/WsThreddsWidget.java @@ -37,7 +37,6 @@ import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.HorizontalPanel; -// TODO: Auto-generated Javadoc /** * The Class WsThreddsWidget. * @@ -148,6 +147,7 @@ public class WsThreddsWidget implements HasWsSyncNotificationListner { } final Modal box = new Modal(true); + box.setWidth(600); box.setTitle("Checking authorizations and configurations..."); final HorizontalPanel hpLoader = new HorizontalPanel(); LoaderIcon loader = new LoaderIcon("Checking authorizations and folder configurations..."); diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/WsThreddsWidgetViewManager.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/WsThreddsWidgetViewManager.java index ca695b4..f335ac0 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/WsThreddsWidgetViewManager.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/WsThreddsWidgetViewManager.java @@ -340,7 +340,8 @@ public class WsThreddsWidgetViewManager { //GWT.log("WsThreddsSynchFolderDescriptor is: "+folderDescriptor); final Modal box = new Modal(true); - //box.setWidth(WIDHT_DIALOG+"px"); + box.getElement().addClassName("modal-sync-widget-config"); + box.setWidth(600); box.setTitle("Thredds Sync Information for: "+FormatUtil.getFolderTitle(folder.getFoderName(), 20)); final AbstractViewDialogBox panelView = new AbstractViewDialogBox() { diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/public/WsThreddsWidget.css b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/public/WsThreddsWidget.css index bd03bab..429a381 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/public/WsThreddsWidget.css +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/public/WsThreddsWidget.css @@ -23,8 +23,18 @@ width: 750px !important; } -.myLittleMarginLeft{ - +.myLittleMarginLeft { margin-left: 25px !important; +} + +.modal-sync-widget-config { +} + +.modal-sync-widget-config .modal-body { + max-height: 600px; +} + +.modal-sync-widget-config form input, form select { + width: 300px; } \ No newline at end of file -- 2.17.1 From 64b53656f96e79fcba3a532086a42bfa891c4aa6 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 18 May 2021 16:25:45 +0200 Subject: [PATCH 15/20] added some comments --- .../view/WsThreddsWidgetViewManager.java | 1 - .../binder/ShowThreddsFolderInfoView.java | 154 ++++++++---------- .../binder/ShowThreddsFolderInfoView.ui.xml | 53 +++--- 3 files changed, 97 insertions(+), 111 deletions(-) diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/WsThreddsWidgetViewManager.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/WsThreddsWidgetViewManager.java index f335ac0..512b97f 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/WsThreddsWidgetViewManager.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/WsThreddsWidgetViewManager.java @@ -359,7 +359,6 @@ public class WsThreddsWidgetViewManager { final boolean isCreateConfiguration = folderDescriptor==null?true:false; - //is the user a THREDDS_ADMIN (so DATA_MANAGER) in at least one scope? boolean isThreddsAdmin = false; diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/ShowThreddsFolderInfoView.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/ShowThreddsFolderInfoView.java index a9c32dc..50acb61 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/ShowThreddsFolderInfoView.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/ShowThreddsFolderInfoView.java @@ -1,6 +1,5 @@ package org.gcube.portlets.widgets.wsthreddssync.client.view.binder; - import java.util.HashMap; import java.util.List; import java.util.Map; @@ -31,48 +30,41 @@ import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.HTMLPanel; import com.google.gwt.user.client.ui.Widget; - /** * The Class ShowThreddsFolderInfoView. * - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Feb 15, 2018 + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Feb 15, 2018 */ public abstract class ShowThreddsFolderInfoView extends Composite { - /** The ui binder. */ - private static ShowThreddsFolderInfoViewUiBinder uiBinder = - GWT.create(ShowThreddsFolderInfoViewUiBinder.class); + private static ShowThreddsFolderInfoViewUiBinder uiBinder = GWT.create(ShowThreddsFolderInfoViewUiBinder.class); /** * The Interface ShowThreddsFolderInfoViewUiBinder. * - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Feb 15, 2018 + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Feb 15, 2018 */ - interface ShowThreddsFolderInfoViewUiBinder - extends UiBinder { + interface ShowThreddsFolderInfoViewUiBinder extends UiBinder { } - @UiField TextBox field_folder_status; @UiField ListBox field_select_scope; - @UiField TextBox field_catalogue_name; - @UiField TextBox field_remote_path; @UiField TextBox field_folder_path; +// @UiField +// TextBox field_sync_updated; @UiField TextBox field_folder_locked; @@ -80,16 +72,13 @@ public abstract class ShowThreddsFolderInfoView extends Composite { @UiField Button button_do_unsync; - - /*@UiField - TextBox field_last_sync; - */ - + /* + * @UiField TextBox field_last_sync; + */ @UiField ControlGroup cg_catalogue_name; - @UiField ControlGroup cg_remote_path; @@ -107,15 +96,14 @@ public abstract class ShowThreddsFolderInfoView extends Composite { private boolean isCreateConfiguration; - - /** * The Enum SUBMIT_ACTION. * - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Mar 12, 2018 + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Mar 12, 2018 */ - public static enum SUBMIT_ACTION {CREATE_UPDATE_CONFIGURATION, DO_UNSYNC, DO_SYNC}; + public static enum SUBMIT_ACTION { + CREATE_UPDATE_CONFIGURATION, DO_UNSYNC, DO_SYNC + }; /** * Submit handler. @@ -128,25 +116,22 @@ public abstract class ShowThreddsFolderInfoView extends Composite { * Sets the error. * * @param visible the visible - * @param error the error + * @param error the error */ public abstract void setError(boolean visible, String error); - /** - * Because this class has a default constructor, it can - * be used as a binder template. In other words, it can be used in other - * *.ui.xml files as follows: - * - * Hello! - * - * Note that depending on the widget that is used, it may be necessary to - * implement HasHTML instead of HasText. + * Because this class has a default constructor, it can be used as a binder + * template. In other words, it can be used in other *.ui.xml files as follows: + * + * Hello! Note that + * depending on the widget that is used, it may be necessary to implement + * HasHTML instead of HasText. * - * @param folderId the folder id + * @param folderId the folder id * @param isCreateConfiguration the is create configuration - * @param mapScopeThreddsRoles the map scope thredds roles + * @param mapScopeThreddsRoles the map scope thredds roles */ public ShowThreddsFolderInfoView(String folderId, boolean isCreateConfiguration) { this.folderId = folderId; @@ -168,33 +153,34 @@ public abstract class ShowThreddsFolderInfoView extends Composite { @Override public void onClick(ClickEvent event) { setError(false, ""); - //boolean isValid = validateSubmit(); - //if(isValid) + // boolean isValid = validateSubmit(); + // if(isValid) submitHandler(SUBMIT_ACTION.DO_SYNC); } }); - if(isCreateConfiguration) { - WsThreddsWidget.wsThreddsSyncService.getListOfDataManagerScopesForLoggedUser(new AsyncCallback>() { + if (isCreateConfiguration) { + WsThreddsWidget.wsThreddsSyncService + .getListOfDataManagerScopesForLoggedUser(new AsyncCallback>() { - @Override - public void onSuccess(List result) { + @Override + public void onSuccess(List result) { - for (GcubeScope gcubeScope : result) { - String toValue = FormatUtil.toScopeValue(gcubeScope); - mapScopes.put(gcubeScope.getScopeName(), gcubeScope); - field_select_scope.addItem(toValue, gcubeScope.getScopeName()); + for (GcubeScope gcubeScope : result) { + String toValue = FormatUtil.toScopeValue(gcubeScope); + mapScopes.put(gcubeScope.getScopeName(), gcubeScope); + field_select_scope.addItem(toValue, gcubeScope.getScopeName()); - } - } + } + } - @Override - public void onFailure(Throwable caught) { - // TODO Auto-generated method stub + @Override + public void onFailure(Throwable caught) { + // TODO Auto-generated method stub - } - }); + } + }); } } @@ -202,21 +188,19 @@ public abstract class ShowThreddsFolderInfoView extends Composite { /** * Update view to result. * - * @param folder the folder + * @param folder the folder * @param syncFolderDesc the sync folder desc */ public void updateViewToResult(final WsFolder folder, WsThreddsSynchFolderDescriptor syncFolderDesc) { this.field_select_scope.clear(); - if(syncFolderDesc==null) { + if (syncFolderDesc == null) { pager.getRight().setVisible(false); return; } - - - if(syncFolderDesc.getSelectedScope()!=null) { + if (syncFolderDesc.getSelectedScope() != null) { String toValue = FormatUtil.toScopeValue(syncFolderDesc.getSelectedScope()); this.field_select_scope.addItem(toValue, syncFolderDesc.getSelectedScope().getScopeName()); this.field_select_scope.setValue(0, syncFolderDesc.getSelectedScope().getScopeName()); @@ -224,39 +208,38 @@ public abstract class ShowThreddsFolderInfoView extends Composite { } ThSyncFolderDescriptor sfd = syncFolderDesc.getServerFolderDescriptor(); - if(sfd!=null) { + if (sfd != null) { this.field_folder_path.setValue(sfd.getFolderPath()); this.field_folder_path.setTitle(sfd.getFolderPath()); - this.field_folder_locked.setValue(sfd.isLocked()+""); - - if(sfd.getElementInfo()!=null) + this.field_folder_locked.setValue(sfd.isLocked() + ""); + + if (sfd.getElementInfo() != null) { this.field_folder_status.setValue(sfd.getElementInfo().getSyncStatus().toString()); + } ThSynchFolderConfiguration config = sfd.getConfiguration(); - if(config!=null) { + if (config != null) { + this.field_catalogue_name.setValue(config.getToCreateCatalogName()); this.field_catalogue_name.setTitle(config.getToCreateCatalogName()); this.field_remote_path.setValue(config.getRemotePath()); this.field_remote_path.setTitle(config.getRemotePath()); - + } - ThProcessDescriptor lpd = sfd.getLocalProcessDescriptor(); - if(lpd!=null) { - //this.field_last_sync.setValue(DateTimeFormat.getFormat(DATE_FORMAT_YYYY_MM_DD_HH_MM_SS).format(new Date(lpd.getLaunchTime()))); + if (lpd != null) { + // this.field_last_sync.setValue(DateTimeFormat.getFormat(DATE_FORMAT_YYYY_MM_DD_HH_MM_SS).format(new + // Date(lpd.getLaunchTime()))); ThSynchFolderConfiguration sc = lpd.getSynchConfiguration(); - if(sc!=null) { - - //this.field_select_vre.setValue(sc.get, value); - + if (sc != null) { + // this.field_select_vre.setValue(sc.get, value); } } } - button_do_unsync.setVisible(true); button_do_unsync.addClickHandler(new ClickHandler() { @@ -278,8 +261,6 @@ public abstract class ShowThreddsFolderInfoView extends Composite { return isCreateConfiguration; } - - /** * Validate submit. * @@ -289,13 +270,13 @@ public abstract class ShowThreddsFolderInfoView extends Composite { cg_catalogue_name.setType(ControlGroupType.NONE); cg_remote_path.setType(ControlGroupType.NONE); - if(field_catalogue_name.getValue()==null || field_catalogue_name.getValue().isEmpty()){ + if (field_catalogue_name.getValue() == null || field_catalogue_name.getValue().isEmpty()) { cg_catalogue_name.setType(ControlGroupType.ERROR); setError(true, "Unit Title field is required"); return false; } - if(field_remote_path.getValue()==null || field_remote_path.getValue().isEmpty()){ + if (field_remote_path.getValue() == null || field_remote_path.getValue().isEmpty()) { cg_remote_path.setType(ControlGroupType.ERROR); setError(true, "Folder Name field is required"); return false; @@ -304,7 +285,6 @@ public abstract class ShowThreddsFolderInfoView extends Composite { return true; } - /** * Gets the remote path. * @@ -319,24 +299,21 @@ public abstract class ShowThreddsFolderInfoView extends Composite { * * @return the catalogue name */ - public String getCatalogueName(){ + public String getCatalogueName() { return field_catalogue_name.getValue(); } - - /** * Gets the selected scope. * * @return the selected scope */ - public GcubeScope getSelectedScope(){ - //String item = field_select_scope.getSelectedItemText(); + public GcubeScope getSelectedScope() { + // String item = field_select_scope.getSelectedItemText(); String scope = field_select_scope.getSelectedValue(); return mapScopes.get(scope); } - /** * Gets the pager. * @@ -351,11 +328,10 @@ public abstract class ShowThreddsFolderInfoView extends Composite { * * @return the main panel */ - public HTMLPanel getMainPanel(){ + public HTMLPanel getMainPanel() { return form_unit_fields; } - - + /** * Show unsync. * @@ -365,6 +341,4 @@ public abstract class ShowThreddsFolderInfoView extends Composite { button_do_unsync.setVisible(show); } - - } diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/ShowThreddsFolderInfoView.ui.xml b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/ShowThreddsFolderInfoView.ui.xml index f511cd0..f4f6f9d 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/ShowThreddsFolderInfoView.ui.xml +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/ShowThreddsFolderInfoView.ui.xml @@ -1,6 +1,7 @@ + xmlns:g="urn:import:com.google.gwt.user.client.ui" + xmlns:b="urn:import:com.github.gwtbootstrap.client.ui"> .noBorder { border: 0px; @@ -13,36 +14,46 @@ Sync Status - + Folder Path - + Locked - + + + + + + + + + + Catalogue Name - + Published in the Scope - + @@ -50,22 +61,24 @@ Remote Path - + - - - - - - - + + + + + + + + - Delete Synchronize + Delete Synchronize -- 2.17.1 From 1aa4d7b3f6219615ce3c3fcdfa776f2721b6105e Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Wed, 19 May 2021 17:29:16 +0200 Subject: [PATCH 16/20] added internal getConfiguration --- .../ThreddsWorkspaceSyncServiceImpl.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java index 73fe01f..8b9f8f2 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java @@ -7,6 +7,8 @@ import java.util.List; import java.util.Map; import java.util.Set; +import javax.servlet.http.HttpServletRequest; + import org.gcube.common.portal.PortalContext; import org.gcube.portal.wssynclibrary.shared.ItemNotSynched; import org.gcube.portal.wssynclibrary.shared.WorkspaceFolderLocked; @@ -36,6 +38,7 @@ import com.google.gwt.user.server.rpc.RemoteServiceServlet; import com.liferay.portal.service.UserLocalServiceUtil; +// TODO: Auto-generated Javadoc /** * The server side implementation of the RPC service. * @@ -127,10 +130,26 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem public WsThreddsSynchFolderDescriptor getConfiguration(String folderId, boolean loadStatus) throws WorkspaceFolderLocked, Exception { logger.debug("called isItemSynched for folderId: " + folderId); + GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); + return getConfiguration(folderId, loadStatus, this.getThreadLocalRequest(), user); + } + + + /** + * Gets the configuration. + * + * @param folderId the folder id + * @param loadStatus the load status + * @param httpRequest the http request + * @param user the user + * @return the configuration + * @throws Exception the exception + */ + public WsThreddsSynchFolderDescriptor getConfiguration(String folderId, boolean loadStatus, HttpServletRequest httpRequest, GCubeUser user) throws Exception { + logger.debug("called internal getConfiguration for folderId: " + folderId); try { - GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); - ThSyncFolderDescriptor theConfig = getSyncService().getConfiguration(folderId, loadStatus, this.getThreadLocalRequest(), user); + ThSyncFolderDescriptor theConfig = getSyncService().getConfiguration(folderId, loadStatus, httpRequest, user); if (theConfig != null) { logger.info("Folder id: " + folderId + " is synched"); -- 2.17.1 From a7fb141f1a78d82adba2b87bb27054033f4eb3b3 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Wed, 19 May 2021 18:18:01 +0200 Subject: [PATCH 17/20] moved oidc-library-portal to provided --- pom.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 8f1573e..1116577 100644 --- a/pom.xml +++ b/pom.xml @@ -42,7 +42,7 @@ org.gcube.distribution maven-portal-bom - 3.6.1 + 3.6.1-SNAPSHOT pom import @@ -79,6 +79,7 @@ org.gcube.portal oidc-library-portal [1.0.0, 2.0.0-SNAPSHOT) + provided -- 2.17.1 From 63c9250ef567cf7221109e3a7b13a9984cf040c7 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 20 May 2021 11:01:03 +0200 Subject: [PATCH 18/20] [#21444] Moved to maven-portal-bom >= 3.6.2-SNAPSHOT --- pom.xml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 1116577..008063e 100644 --- a/pom.xml +++ b/pom.xml @@ -42,7 +42,7 @@ org.gcube.distribution maven-portal-bom - 3.6.1-SNAPSHOT + 3.6.2-SNAPSHOT pom import @@ -78,8 +78,6 @@ org.gcube.portal oidc-library-portal - [1.0.0, 2.0.0-SNAPSHOT) - provided -- 2.17.1 From 9704fdd3e9eb9266eb3fa3f2a4c45cd39de7083d Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 20 May 2021 11:01:19 +0200 Subject: [PATCH 19/20] updated changelog --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1224e4f..e3c6636 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,8 +6,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ## [v1.4.0-SNAPSHOT] - 2021-05-10 -[#21379] Moved to new ws-synchronized-module-library (based on w-thredds 1.x) and performed UMA tokens "context switches" +####Enhancements +[#21379] Moved to new ws-synchronized-module-library (based on w-thredds 1.x) and performed UMA tokens "context switches" +[#21444] Moved to maven-portal-bom >= 3.6.2-SNAPSHOT ## [v1.3.0] - 2021-03-17 -- 2.17.1 From 23df1ec77044c8244116f5e0c3c456d39fc07bd9 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 20 May 2021 17:32:00 +0200 Subject: [PATCH 20/20] fixing config==null on doSync; improved management of exceptions --- CHANGELOG.md | 2 +- .../wsthreddssync/client/WsThreddsWidget.java | 18 +++++++++++++----- .../server/SyncronizeWithThredds.java | 6 +++--- .../ThreddsWorkspaceSyncServiceImpl.java | 7 ++++++- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e3c6636..7ee7a17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ## [v1.4.0-SNAPSHOT] - 2021-05-10 -####Enhancements +#### Enhancements [#21379] Moved to new ws-synchronized-module-library (based on w-thredds 1.x) and performed UMA tokens "context switches" [#21444] Moved to maven-portal-bom >= 3.6.2-SNAPSHOT diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/WsThreddsWidget.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/WsThreddsWidget.java index ae13bd8..45bb2a4 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/WsThreddsWidget.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/WsThreddsWidget.java @@ -283,21 +283,29 @@ public class WsThreddsWidget implements HasWsSyncNotificationListner { * @param config the config */ private void performFolderSync(final WsFolder folder, WsThreddsSynchFolderConfiguration config) { - GWT.log("Performing doSyncFolder on: "+folder); + GWT.log("Performing doSyncFolder on: "+folder+" and config: "+config); final Modal box = new Modal(true); box.setTitle("Starting synchronization..."); box.hide(false); - LoaderIcon loader = new LoaderIcon("Inizializiting synchronization to the folder: "+folder.getFoderName()); + final LoaderIcon loader = new LoaderIcon("Inizializiting synchronization to the folder: "+folder.getFoderName()); box.add(loader); wsThreddsSyncService.doSyncFolder(folder.getFolderId(), config, new AsyncCallback() { @Override public void onFailure(Throwable caught) { - Window.alert(caught.getMessage()); + //Window.alert(caught.getMessage()); viewManager.cancelMonitor(folder); - if(box!=null) - box.hide(); + if(box!=null) { + try { + box.remove(loader); + }catch (Exception e) { + + } + Alert alertError = new Alert(caught.getMessage(), AlertType.ERROR); + alertError.setClose(false); + box.add(alertError); + } } diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java index a8252f4..590f738 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java @@ -318,7 +318,7 @@ public class SyncronizeWithThredds { firstSync = true; } catch (Exception e) { logger.error("Error on check item sync: ", e); - throw new Exception("Sorry an error occurred during folder publishing, refresh and try again"); + throw e; } try { @@ -332,8 +332,8 @@ public class SyncronizeWithThredds { return workspaceThreddsSynchronizeLib.doSync(folderId); } catch (Exception e) { - logger.error("Error on do sync: ", e); - throw new Exception(e.getMessage() + ", refresh and try again"); + logger.error("Error on doSyncFolder for folderId: "+folderId, e); + throw e; } finally { diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java index 8b9f8f2..7e3bfb7 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java @@ -197,6 +197,11 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem config = BeanConverter.toThSynchFolderConfiguration(clientConfig, folderId, clientConfig.getSelectedScope().getScopeName()); logger.debug("Creating server config " + config); + }else { + logger.info("The config sent from client is null, Loading it from ws-thredds"); + ThSyncFolderDescriptor descr = getSyncService().getConfiguration(folderId, false, this.getThreadLocalRequest(), user); + logger.info("From ws-thredds loaded the config: "+config); + config = descr.getConfiguration(); } ThSyncStatus status = getSyncService().doSyncFolder(folderId, config, this.getThreadLocalRequest(), user); @@ -205,7 +210,7 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem return status; } catch (Exception e) { logger.error("Do sync Folder error: ", e); - throw new Exception("Sorry, an error occurred during synchonization phase, try again later"); + throw new Exception("Sorry, an error occurred during synchonization phase. The server encountered the error: "+e.getMessage(), e); } } -- 2.17.1