@ -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 , HomeNotFound Exception {
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 ) ;
}
}
}
}
}