diff --git a/.classpath b/.classpath index 3f8870e..40dd4f8 100644 --- a/.classpath +++ b/.classpath @@ -11,11 +11,13 @@ + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index 6e80039..4e4a3ad 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -5,4 +5,5 @@ org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.release=disabled org.eclipse.jdt.core.compiler.source=1.8 diff --git a/distro/changelog.xml b/distro/changelog.xml index 70d408a..68bb22e 100644 --- a/distro/changelog.xml +++ b/distro/changelog.xml @@ -1,5 +1,13 @@ - + + [Task #17348] Migrate ws-thredds-sync components to SHUB + + + First Release diff --git a/pom.xml b/pom.xml index c5612f3..286424f 100644 --- a/pom.xml +++ b/pom.xml @@ -1,5 +1,6 @@ - 4.0.0 @@ -12,7 +13,7 @@ org.gcube.portlets.widgets ws-thredds-sync-widget jar - 1.0.0-SNAPSHOT + 1.1.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 @@ -100,6 +101,11 @@ [2.0.0-SNAPSHOT, 3-0-0-SNAPSHOT) + + org.gcube.common + storagehub-client-wrapper + [0.0.1-SNAPSHOT, 1.0.0-SNAPSHOT) + 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 bf806a2..008e8cf 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 @@ -2,7 +2,6 @@ package org.gcube.portlets.widgets.wsthreddssync.server; import static org.gcube.common.authorization.client.Constants.authorizationService; -import org.apache.commons.lang.StringUtils; import org.gcube.common.authorization.library.AuthorizationEntry; import org.gcube.portal.wssynclibrary.shared.thredds.Sync_Status; import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncFolderDescriptor; @@ -15,17 +14,18 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -// TODO: Auto-generated Javadoc /** * The Class BeanConverter. * - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Feb 16, 2018 + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * + * Aug 2, 2019 */ public class BeanConverter { private static Logger logger = LoggerFactory.getLogger(BeanConverter.class); + /** * To ws thredds folder config. * @@ -33,32 +33,31 @@ 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, + Sync_Status theStatus) { - if(t==null) + if (t == null) return null; WsThreddsSynchFolderDescriptor ws = new WsThreddsSynchFolderDescriptor(); ws.setServerFolderDescriptor(t); ws.setSyncStatus(theStatus); - //FROM TARGET TOKEN TO SCOPE - //t.getConfiguration().getTargetToken() + // FROM TARGET TOKEN TO SCOPE + // t.getConfiguration().getTargetToken() - if(t.getConfiguration().getTargetToken()!=null) { + if (t.getConfiguration().getTargetToken() != null) { try { AuthorizationEntry entry = authorizationService().get(t.getConfiguration().getTargetToken()); String scope = entry.getContext(); GcubeScope selectedScope = new GcubeScope(toScopeTitle(scope), scope, toGcubeScope(scope)); ws.setSelectedScope(selectedScope); - logger.debug("Resolved SCOPE: "+selectedScope +" from token"); - }catch (Exception e) { + logger.debug("Resolved SCOPE: " + selectedScope + " from token"); + } catch (Exception e) { // TODO: handle exception } } - - return ws; } @@ -69,53 +68,54 @@ public class BeanConverter { * @param scope the scope * @return the string */ - public static String toScopeTitle(String scope){ + public static String toScopeTitle(String scope) { - if(scope==null || scope.isEmpty()) + if (scope == null || scope.isEmpty()) return null; - return scope.substring(scope.lastIndexOf("/")+1, scope.length()); + return scope.substring(scope.lastIndexOf("/") + 1, scope.length()); } - - /** * To gcube scope. * * @param scopeName the scope name * @return the gcube scope type */ - public static GcubeScopeType toGcubeScope(String scopeName){ + public static GcubeScopeType toGcubeScope(String scopeName) { - if(scopeName==null) + if (scopeName == null) return null; - - int count = StringUtils.countMatches(scopeName, "/"); - - if(count==1) - return GcubeScopeType.ROOT; - else if(count==2) - return GcubeScopeType.VO; - else if(count==3) + + String[] components=scopeName.split("/"); + + if (components.length<2 || components.length>4) + throw new IllegalArgumentException("scope "+scopeName+" is malformed"); + + if(components.length>3) { return GcubeScopeType.VRE; - - return null; - + } + else if (components.length>2) { + return GcubeScopeType.VO; + } + else { + return GcubeScopeType.ROOT; + } } - /** * To th synch folder configuration. * - * @param t the t - * @param rootFolderId the root folder id + * @param t the t + * @param rootFolderId the root folder id * @param targetScopeUserToken the target scope user token * @return the th synch folder configuration */ - public static ThSynchFolderConfiguration toThSynchFolderConfiguration(WsThreddsSynchFolderConfiguration t, String rootFolderId, String targetScopeUserToken) { + public static ThSynchFolderConfiguration toThSynchFolderConfiguration(WsThreddsSynchFolderConfiguration t, + String rootFolderId, String targetScopeUserToken) { - if(t==null) + if (t == null) return null; ThSynchFolderConfiguration ts = new ThSynchFolderConfiguration(); 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 34c0073..2315ec7 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 @@ -5,13 +5,16 @@ package org.gcube.portlets.widgets.wsthreddssync.server; 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.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.user.workspace.server.util.WsUtil; import org.gcube.vomanagement.usermanagement.model.GCubeUser; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -59,27 +62,38 @@ public class WsUtil { return PortalContext.getConfiguration().getCurrentUser(httpServletRequest)==null; } - /** - * Gets the workspace. + * Gets the workspace from storage hub. * * @param httpServletRequest the http servlet request - * @return the workspace - * @throws InternalErrorException the internal error exception - * @throws HomeNotFoundException the home not found exception - * @throws WorkspaceFolderNotFoundException the workspace folder not found exception + * @return the workspace from storage hub + * @throws Exception the exception */ - public static Workspace getWorkspace(HttpServletRequest httpServletRequest) throws InternalErrorException, HomeNotFoundException, WorkspaceFolderNotFoundException - { + public Workspace getWorkspaceFromStorageHub(HttpServletRequest httpServletRequest) throws Exception { logger.trace("Get Workspace"); - String scope = PortalContext.getConfiguration().getCurrentScope(httpServletRequest); - GCubeUser user = PortalContext.getConfiguration().getCurrentUser(httpServletRequest); +// String scope = PortalContext.getConfiguration().getCurrentScope(httpServletRequest); - ScopeProvider.instance.set(scope); - logger.trace("Scope provider instancied at: "+scope); + 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); - Workspace workspace = HomeLibrary.getUserWorkspace(user.getUsername()); - return workspace; + 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); + } } } diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/GcubeScope.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/GcubeScope.java index a2ca4df..41391f7 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/GcubeScope.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/GcubeScope.java @@ -1,33 +1,25 @@ package org.gcube.portlets.widgets.wsthreddssync.shared; - import java.io.Serializable; import com.google.gwt.user.client.rpc.IsSerializable; - -// TODO: Auto-generated Javadoc /** - * The Class GcubeVRE. + * The Class GcubeScope. * - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Feb 14, 2018 + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * + * Aug 2, 2019 */ -public class GcubeScope implements Serializable, IsSerializable, Comparable{ - +public class GcubeScope implements Serializable, IsSerializable, Comparable { /** * */ private static final long serialVersionUID = -6427520549519606384L; - private GcubeScopeType scopeType; - - private String scopeTitle; - - private String scopeName; /** @@ -41,8 +33,8 @@ public class GcubeScope implements Serializable, IsSerializable, Comparable metadata = workspace.getMetadata(folderId); - Workspace workspace = HomeLibrary.getUserWorkspace(username); - WorkspaceFolder folder = (WorkspaceFolder) workspace.getItem(folderId); - Properties properties = folder.getProperties(); - - if (properties == null || properties.getProperties() == null || properties.getProperties().size() == 0) { + if (metadata == null || metadata.isEmpty()) { throw new ItemNotSynched("No properties to read"); } - String wsSyncStatus = properties.getProperties().get(WS_SYNCH_SYNCH_STATUS); + 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); 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 a4cd369..f87aeff 100644 --- a/src/test/java/org/gcube/portlets/widgets/wsthreddssync/UnSyncThreddsFolders.java +++ b/src/test/java/org/gcube/portlets/widgets/wsthreddssync/UnSyncThreddsFolders.java @@ -5,18 +5,16 @@ 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.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.Properties; -import org.gcube.common.homelibrary.home.workspace.Workspace; -import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder; -import org.gcube.common.homelibrary.home.workspace.WorkspaceItem; -import org.gcube.common.homelibrary.home.workspace.exceptions.ItemNotFoundException; -import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException; 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.portlets.widgets.wsthreddssync.server.SyncronizeWithThredds; import org.gcube.usecases.ws.thredds.Constants; @@ -38,6 +36,9 @@ public class UnSyncThreddsFolders { private static List lstUnSynchedFailedItem = new ArrayList(); private static List lstErrorItem = new ArrayList(); private static long totalAttempts = 0; + + static String scope = "/gcube/devsec"; + static String token = "TOKEN"; public static SyncronizeWithThredds syncService = new SyncronizeWithThredds(); @@ -51,13 +52,11 @@ public class UnSyncThreddsFolders { * @throws HomeNotFoundException the home not found exception * @throws WorkspaceFolderNotFoundException the workspace folder not found exception */ - public static Workspace getWorkspace() throws InternalErrorException, HomeNotFoundException, WorkspaceFolderNotFoundException - { - - System.out.println("Get Workspace scope: "+DEFAULT_SCOPE + " username: "+TEST_USER); - ScopeProvider.instance.set(DEFAULT_SCOPE); - Workspace workspace = HomeLibrary.getUserWorkspace(TEST_USER); - return workspace; + public static Workspace getWorkspace() throws Exception{ + + ScopeProvider.instance.set(scope); + StorageHubWrapper shWrapper = new StorageHubWrapper(scope, token, false, false, true); + return shWrapper.getWorkspace(); } @@ -69,7 +68,7 @@ public class UnSyncThreddsFolders { * @throws InternalErrorException the internal error exception * @throws HomeNotFoundException the home not found exception */ - public static void main(String[] args) throws WorkspaceFolderNotFoundException, InternalErrorException, HomeNotFoundException { + public static void main(String[] args) throws Exception { Workspace ws = getWorkspace(); unsycFirstLevel(ws, ws.getRoot().getId(), false); @@ -103,8 +102,9 @@ public class UnSyncThreddsFolders { * @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){ + public static void unsycFirstLevel(Workspace ws, String itemId, boolean depthUnsync) throws Exception{ WorkspaceItem item; try { @@ -113,7 +113,7 @@ public class UnSyncThreddsFolders { if(item.isFolder()){ - List children = item.getChildren(); + List children = ws.getChildren(item.getId()); for (WorkspaceItem workspaceItem : children) { if(depthUnsync) unsycFirstLevel(ws, workspaceItem.getId(), depthUnsync); @@ -153,7 +153,8 @@ public class UnSyncThreddsFolders { //Boolean unsynched = syncService.doUnSync(workspaceItem.getId(), false, DEFAULT_SCOPE, TEST_USER_TOKEN); ScopeProvider.instance.set(DEFAULT_SCOPE); SecurityTokenProvider.instance.set(TEST_USER_TOKEN); - cleanItem(workspaceItem); + Workspace ws = getWorkspace(); + cleanItem(workspaceItem, ws); totalAttempts++; // if(unsynched) // lstUnSynchedItem.add(workspaceItem.getId()); @@ -163,25 +164,24 @@ public class UnSyncThreddsFolders { }catch(Exception e){ e.printStackTrace(); - try { - lstErrorItem.add(workspaceItem.getId()); - } - catch (InternalErrorException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } + lstErrorItem.add(workspaceItem.getId()); } } - static void cleanItem(WorkspaceItem item) throws InternalErrorException { - Properties props=item.getProperties(); - if(props.hasProperty(Constants.WorkspaceProperties.TBS)) { + static void cleanItem(WorkspaceItem item, Workspace ws) throws Exception { + + Map props = ws.getMetadata(item.getId()); + if(props.containsKey(Constants.WorkspaceProperties.TBS)) { if(item.isFolder()) { - props.addProperties(Constants.cleanedFolderPropertiesMap); - for(WorkspaceItem child : ((WorkspaceFolder)item).getChildren()) - cleanItem(child); - }else props.addProperties(Constants.cleanedItemPropertiesMap); + //props.addProperties(Constants.cleanedFolderPropertiesMap); + ws.updateMetadata(item.getId(), Constants.cleanedFolderPropertiesMap); + List children = ws.getChildren(item.getId()); + for(WorkspaceItem child : children) + cleanItem(child, ws); + }else { + ws.updateMetadata(item.getId(), Constants.cleanedFolderPropertiesMap); + } } }