moved a SHUB

updated pom version at 1.1.0
Task #17348 Migrate ws-thredds-sync components to SHUB

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/widgets/ws-thredds-sync-widget@181402 82a268e6-3cf1-43bd-a215-b396298e98cf
pull/1/head
Francesco Mangiacrapa 5 years ago
parent eb01b1fb21
commit da7900cc05

@ -11,11 +11,13 @@
<attributes> <attributes>
<attribute name="optional" value="true"/> <attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"> <classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">

@ -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.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8 org.eclipse.jdt.core.compiler.source=1.8

@ -1,5 +1,13 @@
<ReleaseNotes> <ReleaseNotes>
<Changeset component="org.gcube.portlets-widgets.ws-thredds-sync-widget.1-0-0" <Changeset
component="org.gcube.portlets-widgets.ws-thredds-sync-widget.1-1-0"
date="${buildDate}">
<Change>
[Task #17348] Migrate ws-thredds-sync components to SHUB
</Change>
</Changeset>
<Changeset
component="org.gcube.portlets-widgets.ws-thredds-sync-widget.1-0-0"
date="2018-03-16"> date="2018-03-16">
<Change>First Release</Change> <Change>First Release</Change>
</Changeset> </Changeset>

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
@ -12,7 +13,7 @@
<groupId>org.gcube.portlets.widgets</groupId> <groupId>org.gcube.portlets.widgets</groupId>
<artifactId>ws-thredds-sync-widget</artifactId> <artifactId>ws-thredds-sync-widget</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<version>1.0.0-SNAPSHOT</version> <version>1.1.0-SNAPSHOT</version>
<name>ws-thredds-sync-widget</name> <name>ws-thredds-sync-widget</name>
<description> <description>
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 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 @@
<version>[2.0.0-SNAPSHOT, 3-0-0-SNAPSHOT)</version> <version>[2.0.0-SNAPSHOT, 3-0-0-SNAPSHOT)</version>
</dependency> </dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>storagehub-client-wrapper</artifactId>
<version>[0.0.1-SNAPSHOT, 1.0.0-SNAPSHOT)</version>
</dependency>
<!-- LOGGER --> <!-- LOGGER -->

@ -2,7 +2,6 @@ package org.gcube.portlets.widgets.wsthreddssync.server;
import static org.gcube.common.authorization.client.Constants.authorizationService; 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.common.authorization.library.AuthorizationEntry;
import org.gcube.portal.wssynclibrary.shared.thredds.Sync_Status; import org.gcube.portal.wssynclibrary.shared.thredds.Sync_Status;
import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncFolderDescriptor; import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncFolderDescriptor;
@ -15,17 +14,18 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
// TODO: Auto-generated Javadoc
/** /**
* The Class BeanConverter. * The Class BeanConverter.
* *
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* Feb 16, 2018 *
* Aug 2, 2019
*/ */
public class BeanConverter { public class BeanConverter {
private static Logger logger = LoggerFactory.getLogger(BeanConverter.class); private static Logger logger = LoggerFactory.getLogger(BeanConverter.class);
/** /**
* To ws thredds folder config. * To ws thredds folder config.
* *
@ -33,32 +33,31 @@ public class BeanConverter {
* @param theStatus the the status * @param theStatus the the status
* @return the ws thredds synch folder descriptor * @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; return null;
WsThreddsSynchFolderDescriptor ws = new WsThreddsSynchFolderDescriptor(); WsThreddsSynchFolderDescriptor ws = new WsThreddsSynchFolderDescriptor();
ws.setServerFolderDescriptor(t); ws.setServerFolderDescriptor(t);
ws.setSyncStatus(theStatus); ws.setSyncStatus(theStatus);
//FROM TARGET TOKEN TO SCOPE // FROM TARGET TOKEN TO SCOPE
//t.getConfiguration().getTargetToken() // t.getConfiguration().getTargetToken()
if(t.getConfiguration().getTargetToken()!=null) { if (t.getConfiguration().getTargetToken() != null) {
try { try {
AuthorizationEntry entry = authorizationService().get(t.getConfiguration().getTargetToken()); AuthorizationEntry entry = authorizationService().get(t.getConfiguration().getTargetToken());
String scope = entry.getContext(); String scope = entry.getContext();
GcubeScope selectedScope = new GcubeScope(toScopeTitle(scope), scope, toGcubeScope(scope)); GcubeScope selectedScope = new GcubeScope(toScopeTitle(scope), scope, toGcubeScope(scope));
ws.setSelectedScope(selectedScope); ws.setSelectedScope(selectedScope);
logger.debug("Resolved SCOPE: "+selectedScope +" from token"); logger.debug("Resolved SCOPE: " + selectedScope + " from token");
}catch (Exception e) { } catch (Exception e) {
// TODO: handle exception // TODO: handle exception
} }
} }
return ws; return ws;
} }
@ -69,53 +68,54 @@ public class BeanConverter {
* @param scope the scope * @param scope the scope
* @return the string * @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 null;
return scope.substring(scope.lastIndexOf("/")+1, scope.length()); return scope.substring(scope.lastIndexOf("/") + 1, scope.length());
} }
/** /**
* To gcube scope. * To gcube scope.
* *
* @param scopeName the scope name * @param scopeName the scope name
* @return the gcube scope type * @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; return null;
int count = StringUtils.countMatches(scopeName, "/"); String[] components=scopeName.split("/");
if(count==1) if (components.length<2 || components.length>4)
return GcubeScopeType.ROOT; throw new IllegalArgumentException("scope "+scopeName+" is malformed");
else if(count==2)
return GcubeScopeType.VO; if(components.length>3) {
else if(count==3)
return GcubeScopeType.VRE; return GcubeScopeType.VRE;
}
return null; else if (components.length>2) {
return GcubeScopeType.VO;
}
else {
return GcubeScopeType.ROOT;
}
} }
/** /**
* To th synch folder configuration. * To th synch folder configuration.
* *
* @param t the t * @param t the t
* @param rootFolderId the root folder id * @param rootFolderId the root folder id
* @param targetScopeUserToken the target scope user token * @param targetScopeUserToken the target scope user token
* @return the th synch folder configuration * @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; return null;
ThSynchFolderConfiguration ts = new ThSynchFolderConfiguration(); ThSynchFolderConfiguration ts = new ThSynchFolderConfiguration();

@ -5,13 +5,16 @@ package org.gcube.portlets.widgets.wsthreddssync.server;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import org.gcube.common.homelibrary.home.HomeLibrary; //import org.gcube.common.homelibrary.home.HomeLibrary;
import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException; //import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException; //import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
import org.gcube.common.homelibrary.home.workspace.Workspace; //import org.gcube.common.homelibrary.home.workspace.Workspace;
import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException; //import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
import org.gcube.common.portal.PortalContext; import org.gcube.common.portal.PortalContext;
import org.gcube.common.scope.api.ScopeProvider; 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.gcube.vomanagement.usermanagement.model.GCubeUser;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -59,27 +62,38 @@ public class WsUtil {
return PortalContext.getConfiguration().getCurrentUser(httpServletRequest)==null; return PortalContext.getConfiguration().getCurrentUser(httpServletRequest)==null;
} }
/** /**
* Gets the workspace. * Gets the workspace from storage hub.
* *
* @param httpServletRequest the http servlet request * @param httpServletRequest the http servlet request
* @return the workspace * @return the workspace from storage hub
* @throws InternalErrorException the internal error exception * @throws Exception the exception
* @throws HomeNotFoundException the home not found exception
* @throws WorkspaceFolderNotFoundException the workspace folder not found exception
*/ */
public static Workspace getWorkspace(HttpServletRequest httpServletRequest) throws InternalErrorException, HomeNotFoundException, WorkspaceFolderNotFoundException public Workspace getWorkspaceFromStorageHub(HttpServletRequest httpServletRequest) throws Exception {
{
logger.trace("Get Workspace"); logger.trace("Get Workspace");
String scope = PortalContext.getConfiguration().getCurrentScope(httpServletRequest); // String scope = PortalContext.getConfiguration().getCurrentScope(httpServletRequest);
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(httpServletRequest);
ScopeProvider.instance.set(scope); GCubeUser user = null;
logger.trace("Scope provider instancied at: "+scope);
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()); String token = PortalContext.getConfiguration().getCurrentUserToken(scope, user.getUsername());
return workspace; 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);
}
} }
} }

@ -1,33 +1,25 @@
package org.gcube.portlets.widgets.wsthreddssync.shared; package org.gcube.portlets.widgets.wsthreddssync.shared;
import java.io.Serializable; import java.io.Serializable;
import com.google.gwt.user.client.rpc.IsSerializable; 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 * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* Feb 14, 2018 *
* Aug 2, 2019
*/ */
public class GcubeScope implements Serializable, IsSerializable, Comparable<GcubeScope>{ public class GcubeScope implements Serializable, IsSerializable, Comparable<GcubeScope> {
/** /**
* *
*/ */
private static final long serialVersionUID = -6427520549519606384L; private static final long serialVersionUID = -6427520549519606384L;
private GcubeScopeType scopeType; private GcubeScopeType scopeType;
private String scopeTitle; private String scopeTitle;
private String scopeName; private String scopeName;
/** /**
@ -41,8 +33,8 @@ public class GcubeScope implements Serializable, IsSerializable, Comparable<Gcub
* Instantiates a new gcube scope. * Instantiates a new gcube scope.
* *
* @param scopeTitle the scope title * @param scopeTitle the scope title
* @param scopeName the scope name * @param scopeName the scope name
* @param scopeType the scope type * @param scopeType the scope type
*/ */
public GcubeScope(String scopeTitle, String scopeName, GcubeScopeType scopeType) { public GcubeScope(String scopeTitle, String scopeName, GcubeScopeType scopeType) {
@ -52,8 +44,9 @@ public class GcubeScope implements Serializable, IsSerializable, Comparable<Gcub
this.scopeType = scopeType; this.scopeType = scopeType;
} }
/** /**
* Gets the scope type.
*
* @return the scopeType * @return the scopeType
*/ */
public GcubeScopeType getScopeType() { public GcubeScopeType getScopeType() {
@ -61,8 +54,9 @@ public class GcubeScope implements Serializable, IsSerializable, Comparable<Gcub
return scopeType; return scopeType;
} }
/** /**
* Gets the scope title.
*
* @return the scopeTitle * @return the scopeTitle
*/ */
public String getScopeTitle() { public String getScopeTitle() {
@ -70,8 +64,9 @@ public class GcubeScope implements Serializable, IsSerializable, Comparable<Gcub
return scopeTitle; return scopeTitle;
} }
/** /**
* Gets the scope name.
*
* @return the scopeName * @return the scopeName
*/ */
public String getScopeName() { public String getScopeName() {
@ -79,8 +74,9 @@ public class GcubeScope implements Serializable, IsSerializable, Comparable<Gcub
return scopeName; return scopeName;
} }
/** /**
* Sets the scope type.
*
* @param scopeType the scopeType to set * @param scopeType the scopeType to set
*/ */
public void setScopeType(GcubeScopeType scopeType) { public void setScopeType(GcubeScopeType scopeType) {
@ -88,8 +84,9 @@ public class GcubeScope implements Serializable, IsSerializable, Comparable<Gcub
this.scopeType = scopeType; this.scopeType = scopeType;
} }
/** /**
* Sets the scope title.
*
* @param scopeTitle the scopeTitle to set * @param scopeTitle the scopeTitle to set
*/ */
public void setScopeTitle(String scopeTitle) { public void setScopeTitle(String scopeTitle) {
@ -97,8 +94,9 @@ public class GcubeScope implements Serializable, IsSerializable, Comparable<Gcub
this.scopeTitle = scopeTitle; this.scopeTitle = scopeTitle;
} }
/** /**
* Sets the scope name.
*
* @param scopeName the scopeName to set * @param scopeName the scopeName to set
*/ */
public void setScopeName(String scopeName) { public void setScopeName(String scopeName) {
@ -106,20 +104,24 @@ public class GcubeScope implements Serializable, IsSerializable, Comparable<Gcub
this.scopeName = scopeName; this.scopeName = scopeName;
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see java.lang.Comparable#compareTo(java.lang.Object) * @see java.lang.Comparable#compareTo(java.lang.Object)
*/ */
@Override @Override
public int compareTo(GcubeScope o) { public int compareTo(GcubeScope o) {
if(o==null) if (o == null)
return -1; return -1;
return this.getScopeName().compareTo(o.getScopeName()); return this.getScopeName().compareTo(o.getScopeName());
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see java.lang.Object#toString() * @see java.lang.Object#toString()
*/ */
@Override @Override
@ -136,5 +138,4 @@ public class GcubeScope implements Serializable, IsSerializable, Comparable<Gcub
return builder.toString(); return builder.toString();
} }
} }

@ -1,26 +1,8 @@
package org.gcube.portlets.widgets.wsthreddssync; package org.gcube.portlets.widgets.wsthreddssync;
import java.io.IOException;
import java.net.MalformedURLException;
import org.gcube.common.homelibrary.home.HomeLibrary;
import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
import org.gcube.common.homelibrary.home.exceptions.UserNotFoundException;
import org.gcube.common.homelibrary.home.workspace.Workspace;
import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder;
import org.gcube.common.homelibrary.home.workspace.exceptions.InsufficientPrivilegesException;
import org.gcube.common.homelibrary.home.workspace.exceptions.ItemAlreadyExistException;
import org.gcube.common.homelibrary.home.workspace.exceptions.ItemNotFoundException;
import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.scope.impl.ScopeBean;
import org.gcube.usecases.ws.thredds.SyncEngine; import org.gcube.usecases.ws.thredds.SyncEngine;
import org.gcube.usecases.ws.thredds.engine.impl.ProcessDescriptor; import org.gcube.usecases.ws.thredds.engine.impl.ProcessDescriptor;
import org.gcube.usecases.ws.thredds.engine.impl.ProcessStatus; import org.gcube.usecases.ws.thredds.engine.impl.ProcessStatus;
import org.gcube.usecases.ws.thredds.faults.InternalException;
import org.gcube.usecases.ws.thredds.faults.ProcessNotFoundException;
import org.gcube.usecases.ws.thredds.faults.WorkspaceInteractionException;
import org.gcube.usecases.ws.thredds.faults.WorkspaceLockedException; import org.gcube.usecases.ws.thredds.faults.WorkspaceLockedException;
import org.gcube.usecases.ws.thredds.faults.WorkspaceNotSynchedException; import org.gcube.usecases.ws.thredds.faults.WorkspaceNotSynchedException;
import org.gcube.usecases.ws.thredds.model.SyncOperationCallBack; import org.gcube.usecases.ws.thredds.model.SyncOperationCallBack;
@ -42,26 +24,12 @@ public class TestWsThreddsEngine {
public static String TEST_FOLDER_ID = ""; public static String TEST_FOLDER_ID = "";
public static void main(String[] args) throws ProcessNotFoundException, InternalErrorException, WorkspaceInteractionException, InternalException, WorkspaceFolderNotFoundException, ItemNotFoundException, InsufficientPrivilegesException, ItemAlreadyExistException, HomeNotFoundException, UserNotFoundException, MalformedURLException, IOException { public static void main(String[] args) throws Exception {
// GET ENGINE : SINGLETON INSTANCE // GET ENGINE : SINGLETON INSTANCE
SyncEngine engine=SyncEngine.get(); SyncEngine engine=SyncEngine.get();
Workspace ws = HomeLibrary
.getHomeManagerFactory()
.getHomeManager()
.getHome(TEST_USER)
.getWorkspace();
//TEST INFO...
//TestCommons.setScope();
ScopeBean scope = new ScopeBean(DEFAULT_SCOPE);
ScopeProvider.instance.set(scope.toString());
WorkspaceFolder folder=(WorkspaceFolder) ws.getItem(TEST_FOLDER_ID);
// FOLDER CONFIGURATION BEAN // FOLDER CONFIGURATION BEAN
//SynchFolderConfiguration config=TestCommons.getSynchConfig(); //SynchFolderConfiguration config=TestCommons.getSynchConfig();
@ -69,33 +37,33 @@ public class TestWsThreddsEngine {
String remotePersistence = ""; String remotePersistence = "";
String remotePath = ""; String remotePath = "";
String targetToken = ""; String targetToken = "";
SynchFolderConfiguration config = new SynchFolderConfiguration(remotePath, filter, targetToken, remotePersistence, folder.getId()); SynchFolderConfiguration config = new SynchFolderConfiguration(remotePath, filter, targetToken, remotePersistence, TEST_FOLDER_ID);
try { try {
//try to clean it up, first.. //try to clean it up, first..
System.out.println("Cleaning it up.."); System.out.println("Cleaning it up..");
engine.unsetSynchronizedFolder(folder.getId(), false); engine.unsetSynchronizedFolder(TEST_FOLDER_ID, false);
}catch(WorkspaceNotSynchedException e) { }catch(WorkspaceNotSynchedException e) {
// it was already cleared // it was already cleared
}catch(WorkspaceLockedException e) { }catch(WorkspaceLockedException e) {
engine.forceUnlock(folder.getId()); engine.forceUnlock(TEST_FOLDER_ID);
engine.unsetSynchronizedFolder(folder.getId(), false); engine.unsetSynchronizedFolder(TEST_FOLDER_ID, false);
} }
try { try {
// WHEN OPENING A FOLDER, INVOKE CHECK TO UPDATE SYNCH STATUS // WHEN OPENING A FOLDER, INVOKE CHECK TO UPDATE SYNCH STATUS
engine.check(folder.getId(), false); engine.check(TEST_FOLDER_ID, false);
}catch(WorkspaceNotSynchedException e) { }catch(WorkspaceNotSynchedException e) {
System.out.println("Folder not synched, configurin it.."); System.out.println("Folder not synched, configurin it..");
engine.setSynchronizedFolder(config, folder.getId()); engine.setSynchronizedFolder(config, TEST_FOLDER_ID);
}catch(WorkspaceLockedException e) { }catch(WorkspaceLockedException e) {
System.out.println("Workspace locked, going to force unlock.."); // MAINLY FOR TEST PURPOSES, OR WHEN SOMETHIGN GOES WRONG.. USE CAUTIOUSLY System.out.println("Workspace locked, going to force unlock.."); // MAINLY FOR TEST PURPOSES, OR WHEN SOMETHIGN GOES WRONG.. USE CAUTIOUSLY
engine.forceUnlock(folder.getId()); engine.forceUnlock(TEST_FOLDER_ID);
} }
// INVOKE SYNCHRONIZATION ON FOLDER // INVOKE SYNCHRONIZATION ON FOLDER
ProcessDescriptor descriptor=engine.doSync(folder.getId()); ProcessDescriptor descriptor=engine.doSync(TEST_FOLDER_ID);
System.out.println("Obtained descriptor : "+descriptor); System.out.println("Obtained descriptor : "+descriptor);
@ -115,10 +83,10 @@ public class TestWsThreddsEngine {
}; };
// REGISTER CALLBACK TO MONITOR PROGRESS // REGISTER CALLBACK TO MONITOR PROGRESS
engine.registerCallBack(folder.getId(), syncCall); engine.registerCallBack(TEST_FOLDER_ID, syncCall);
engine.check(folder.getId(), true); engine.check(TEST_FOLDER_ID, true);
// INVOKE WHEN PORTAL SHUTS DOWN TO FREE RESOURCES AND STOP SYNC PROCESSES // INVOKE WHEN PORTAL SHUTS DOWN TO FREE RESOURCES AND STOP SYNC PROCESSES

@ -1,10 +1,12 @@
package org.gcube.portlets.widgets.wsthreddssync; package org.gcube.portlets.widgets.wsthreddssync;
import org.gcube.common.homelibrary.home.HomeLibrary; import java.util.Map;
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.scope.api.ScopeProvider; 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; import org.gcube.portal.wssynclibrary.shared.ItemNotSynched;
public class TestWsThreddsQuery { public class TestWsThreddsQuery {
@ -13,7 +15,7 @@ public class TestWsThreddsQuery {
static String scope = "/gcube/devsec"; static String scope = "/gcube/devsec";
static String username = "francesco.mangiacrapa"; static String username = "francesco.mangiacrapa";
// NextNeext Francesco's Token // NextNeext Francesco's Token
static String token = "89257623-0570-4fbe-a15b-458bb84f4902-98187548"; static String token = "TOKEN";
public static final String WS_SYNCH_SYNCH_STATUS = "WS-SYNCH.SYNCH-STATUS"; public static final String WS_SYNCH_SYNCH_STATUS = "WS-SYNCH.SYNCH-STATUS";
public static void main(String[] args) { public static void main(String[] args) {
@ -26,16 +28,16 @@ public class TestWsThreddsQuery {
try { try {
ScopeProvider.instance.set(scope); ScopeProvider.instance.set(scope);
StorageHubWrapper shWrapper = new StorageHubWrapper(scope, token, false, false, true);
Workspace workspace = shWrapper.getWorkspace();
Map<String, Object> metadata = workspace.getMetadata(folderId);
Workspace workspace = HomeLibrary.getUserWorkspace(username); if (metadata == null || metadata.isEmpty()) {
WorkspaceFolder folder = (WorkspaceFolder) workspace.getItem(folderId);
Properties properties = folder.getProperties();
if (properties == null || properties.getProperties() == null || properties.getProperties().size() == 0) {
throw new ItemNotSynched("No properties to read"); 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("Current: " + WS_SYNCH_SYNCH_STATUS + " has value: " + wsSyncStatus);
//System.out.println("isSynched: " + isSynched); //System.out.println("isSynched: " + isSynched);

@ -5,18 +5,16 @@ package org.gcube.portlets.widgets.wsthreddssync;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider; 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.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.portlets.widgets.wsthreddssync.server.SyncronizeWithThredds;
import org.gcube.usecases.ws.thredds.Constants; import org.gcube.usecases.ws.thredds.Constants;
@ -38,6 +36,9 @@ public class UnSyncThreddsFolders {
private static List<String> lstUnSynchedFailedItem = new ArrayList<String>(); private static List<String> lstUnSynchedFailedItem = new ArrayList<String>();
private static List<String> lstErrorItem = new ArrayList<String>(); private static List<String> lstErrorItem = new ArrayList<String>();
private static long totalAttempts = 0; private static long totalAttempts = 0;
static String scope = "/gcube/devsec";
static String token = "TOKEN";
public static SyncronizeWithThredds syncService = new SyncronizeWithThredds(); public static SyncronizeWithThredds syncService = new SyncronizeWithThredds();
@ -51,13 +52,11 @@ public class UnSyncThreddsFolders {
* @throws HomeNotFoundException the home not found exception * @throws HomeNotFoundException the home not found exception
* @throws WorkspaceFolderNotFoundException the workspace folder not found exception * @throws WorkspaceFolderNotFoundException the workspace folder not found exception
*/ */
public static Workspace getWorkspace() throws InternalErrorException, HomeNotFoundException, WorkspaceFolderNotFoundException public static Workspace getWorkspace() throws Exception{
{
ScopeProvider.instance.set(scope);
System.out.println("Get Workspace scope: "+DEFAULT_SCOPE + " username: "+TEST_USER); StorageHubWrapper shWrapper = new StorageHubWrapper(scope, token, false, false, true);
ScopeProvider.instance.set(DEFAULT_SCOPE); return shWrapper.getWorkspace();
Workspace workspace = HomeLibrary.getUserWorkspace(TEST_USER);
return workspace;
} }
@ -69,7 +68,7 @@ public class UnSyncThreddsFolders {
* @throws InternalErrorException the internal error exception * @throws InternalErrorException the internal error exception
* @throws HomeNotFoundException the home not found 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(); Workspace ws = getWorkspace();
unsycFirstLevel(ws, ws.getRoot().getId(), false); unsycFirstLevel(ws, ws.getRoot().getId(), false);
@ -103,8 +102,9 @@ public class UnSyncThreddsFolders {
* @param ws the ws * @param ws the ws
* @param itemId the item id * @param itemId the item id
* @param depthUnsync the depth unsync * @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; WorkspaceItem item;
try { try {
@ -113,7 +113,7 @@ public class UnSyncThreddsFolders {
if(item.isFolder()){ if(item.isFolder()){
List<? extends WorkspaceItem> children = item.getChildren(); List<? extends WorkspaceItem> children = ws.getChildren(item.getId());
for (WorkspaceItem workspaceItem : children) { for (WorkspaceItem workspaceItem : children) {
if(depthUnsync) if(depthUnsync)
unsycFirstLevel(ws, workspaceItem.getId(), 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); //Boolean unsynched = syncService.doUnSync(workspaceItem.getId(), false, DEFAULT_SCOPE, TEST_USER_TOKEN);
ScopeProvider.instance.set(DEFAULT_SCOPE); ScopeProvider.instance.set(DEFAULT_SCOPE);
SecurityTokenProvider.instance.set(TEST_USER_TOKEN); SecurityTokenProvider.instance.set(TEST_USER_TOKEN);
cleanItem(workspaceItem); Workspace ws = getWorkspace();
cleanItem(workspaceItem, ws);
totalAttempts++; totalAttempts++;
// if(unsynched) // if(unsynched)
// lstUnSynchedItem.add(workspaceItem.getId()); // lstUnSynchedItem.add(workspaceItem.getId());
@ -163,25 +164,24 @@ public class UnSyncThreddsFolders {
}catch(Exception e){ }catch(Exception e){
e.printStackTrace(); e.printStackTrace();
try { lstErrorItem.add(workspaceItem.getId());
lstErrorItem.add(workspaceItem.getId());
}
catch (InternalErrorException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
} }
} }
static void cleanItem(WorkspaceItem item) throws InternalErrorException { static void cleanItem(WorkspaceItem item, Workspace ws) throws Exception {
Properties props=item.getProperties();
if(props.hasProperty(Constants.WorkspaceProperties.TBS)) { Map<String, Object> props = ws.getMetadata(item.getId());
if(props.containsKey(Constants.WorkspaceProperties.TBS)) {
if(item.isFolder()) { if(item.isFolder()) {
props.addProperties(Constants.cleanedFolderPropertiesMap); //props.addProperties(Constants.cleanedFolderPropertiesMap);
for(WorkspaceItem child : ((WorkspaceFolder)item).getChildren()) ws.updateMetadata(item.getId(), Constants.cleanedFolderPropertiesMap);
cleanItem(child); List<? extends WorkspaceItem> children = ws.getChildren(item.getId());
}else props.addProperties(Constants.cleanedItemPropertiesMap); for(WorkspaceItem child : children)
cleanItem(child, ws);
}else {
ws.updateMetadata(item.getId(), Constants.cleanedFolderPropertiesMap);
}
} }
} }

Loading…
Cancel
Save