Browse Source

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 3 years ago
parent
commit
da7900cc05
  1. 2
      .classpath
  2. 1
      .settings/org.eclipse.jdt.core.prefs
  3. 10
      distro/changelog.xml
  4. 10
      pom.xml
  5. 72
      src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/BeanConverter.java
  6. 52
      src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/WsUtil.java
  7. 51
      src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/GcubeScope.java
  8. 54
      src/test/java/org/gcube/portlets/widgets/wsthreddssync/TestWsThreddsEngine.java
  9. 24
      src/test/java/org/gcube/portlets/widgets/wsthreddssync/TestWsThreddsQuery.java
  10. 68
      src/test/java/org/gcube/portlets/widgets/wsthreddssync/UnSyncThreddsFolders.java

2
.classpath

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

1
.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

10
distro/changelog.xml

@ -1,5 +1,13 @@
<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">
<Change>First Release</Change>
</Changeset>

10
pom.xml

@ -1,5 +1,6 @@
<?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">
<modelVersion>4.0.0</modelVersion>
<parent>
@ -12,7 +13,7 @@
<groupId>org.gcube.portlets.widgets</groupId>
<artifactId>ws-thredds-sync-widget</artifactId>
<packaging>jar</packaging>
<version>1.0.0-SNAPSHOT</version>
<version>1.1.0-SNAPSHOT</version>
<name>ws-thredds-sync-widget</name>
<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
@ -100,6 +101,11 @@
<version>[2.0.0-SNAPSHOT, 3-0-0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>storagehub-client-wrapper</artifactId>
<version>[0.0.1-SNAPSHOT, 1.0.0-SNAPSHOT)</version>
</dependency>
<!-- LOGGER -->

72
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();

52
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);
}
}
}

51
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<GcubeScope>{
public class GcubeScope implements Serializable, IsSerializable, Comparable<GcubeScope> {
/**
*
*/
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<Gcub
* Instantiates a new gcube scope.
*
* @param scopeTitle the scope title
* @param scopeName the scope name
* @param scopeType the scope type
* @param scopeName the scope name
* @param scopeType the scope type
*/
public GcubeScope(String scopeTitle, String scopeName, GcubeScopeType scopeType) {
@ -52,8 +44,9 @@ public class GcubeScope implements Serializable, IsSerializable, Comparable<Gcub
this.scopeType = scopeType;
}
/**
* Gets the scope type.
*
* @return the scopeType
*/
public GcubeScopeType getScopeType() {
@ -61,8 +54,9 @@ public class GcubeScope implements Serializable, IsSerializable, Comparable<Gcub
return scopeType;
}
/**
* Gets the scope title.
*
* @return the scopeTitle
*/
public String getScopeTitle() {
@ -70,8 +64,9 @@ public class GcubeScope implements Serializable, IsSerializable, Comparable<Gcub
return scopeTitle;
}
/**
* Gets the scope name.
*
* @return the scopeName
*/
public String getScopeName() {
@ -79,8 +74,9 @@ public class GcubeScope implements Serializable, IsSerializable, Comparable<Gcub
return scopeName;
}
/**
* Sets the scope type.
*
* @param scopeType the scopeType to set
*/
public void setScopeType(GcubeScopeType scopeType) {
@ -88,8 +84,9 @@ public class GcubeScope implements Serializable, IsSerializable, Comparable<Gcub
this.scopeType = scopeType;
}
/**
* Sets the scope title.
*
* @param scopeTitle the scopeTitle to set
*/
public void setScopeTitle(String scopeTitle) {
@ -97,8 +94,9 @@ public class GcubeScope implements Serializable, IsSerializable, Comparable<Gcub
this.scopeTitle = scopeTitle;
}
/**
* Sets the scope name.
*
* @param scopeName the scopeName to set
*/
public void setScopeName(String scopeName) {
@ -106,20 +104,24 @@ public class GcubeScope implements Serializable, IsSerializable, Comparable<Gcub
this.scopeName = scopeName;
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
@Override
public int compareTo(GcubeScope o) {
if(o==null)
if (o == null)
return -1;
return this.getScopeName().compareTo(o.getScopeName());
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
@ -136,5 +138,4 @@ public class GcubeScope implements Serializable, IsSerializable, Comparable<Gcub
return builder.toString();
}
}

54
src/test/java/org/gcube/portlets/widgets/wsthreddssync/TestWsThreddsEngine.java

@ -1,26 +1,8 @@
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.engine.impl.ProcessDescriptor;
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.WorkspaceNotSynchedException;
import org.gcube.usecases.ws.thredds.model.SyncOperationCallBack;
@ -42,26 +24,12 @@ public class TestWsThreddsEngine {
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
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
//SynchFolderConfiguration config=TestCommons.getSynchConfig();
@ -69,33 +37,33 @@ public class TestWsThreddsEngine {
String remotePersistence = "";
String remotePath = "";
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 to clean it up, first..
System.out.println("Cleaning it up..");
engine.unsetSynchronizedFolder(folder.getId(), false);
engine.unsetSynchronizedFolder(TEST_FOLDER_ID, false);
}catch(WorkspaceNotSynchedException e) {
// it was already cleared
}catch(WorkspaceLockedException e) {
engine.forceUnlock(folder.getId());
engine.unsetSynchronizedFolder(folder.getId(), false);
engine.forceUnlock(TEST_FOLDER_ID);
engine.unsetSynchronizedFolder(TEST_FOLDER_ID, false);
}
try {
// WHEN OPENING A FOLDER, INVOKE CHECK TO UPDATE SYNCH STATUS
engine.check(folder.getId(), false);
engine.check(TEST_FOLDER_ID, false);
}catch(WorkspaceNotSynchedException e) {
System.out.println("Folder not synched, configurin it..");
engine.setSynchronizedFolder(config, folder.getId());
engine.setSynchronizedFolder(config, TEST_FOLDER_ID);
}catch(WorkspaceLockedException e) {
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
ProcessDescriptor descriptor=engine.doSync(folder.getId());
ProcessDescriptor descriptor=engine.doSync(TEST_FOLDER_ID);
System.out.println("Obtained descriptor : "+descriptor);
@ -115,10 +83,10 @@ public class TestWsThreddsEngine {
};
// 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

24
src/test/java/org/gcube/portlets/widgets/wsthreddssync/TestWsThreddsQuery.java

@ -1,10 +1,12 @@
package org.gcube.portlets.widgets.wsthreddssync;
import org.gcube.common.homelibrary.home.HomeLibrary;
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 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 {
@ -13,7 +15,7 @@ public class TestWsThreddsQuery {
static String scope = "/gcube/devsec";
static String username = "francesco.mangiacrapa";
// 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 void main(String[] args) {
@ -26,16 +28,16 @@ public class TestWsThreddsQuery {
try {
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);
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);

68
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<String> lstUnSynchedFailedItem = new ArrayList<String>();
private static List<String> lstErrorItem = new ArrayList<String>();
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<? extends WorkspaceItem> children = item.getChildren();
List<? extends WorkspaceItem> 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<String, Object> 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<? extends WorkspaceItem> children = ws.getChildren(item.getId());
for(WorkspaceItem child : children)
cleanItem(child, ws);
}else {
ws.updateMetadata(item.getId(), Constants.cleanedFolderPropertiesMap);
}
}
}

Loading…
Cancel
Save