|
|
|
@ -2,7 +2,6 @@ package org.gcube.portlets.widgets.wsthreddssync;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.net.MalformedURLException;
|
|
|
|
|
import java.util.concurrent.Semaphore;
|
|
|
|
|
|
|
|
|
|
import org.gcube.common.homelibrary.home.HomeLibrary;
|
|
|
|
|
import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
|
|
|
|
@ -36,56 +35,56 @@ import org.gcube.usecases.ws.thredds.model.SynchFolderConfiguration;
|
|
|
|
|
* Feb 7, 2018
|
|
|
|
|
*/
|
|
|
|
|
public class TestWsThreddsEngine {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static String DEFAULT_SCOPE = "/gcube/devsec"; //DEV
|
|
|
|
|
// public static String DEFAULT_SCOPE = "/d4science.research-infrastructures.eu/gCubeApps";
|
|
|
|
|
public static String TEST_USER = "francesco.mangiacrapa";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String filter = "";
|
|
|
|
|
String remotePersistence = "";
|
|
|
|
|
String remotePath = "";
|
|
|
|
|
String targetToken = "";
|
|
|
|
|
SynchFolderConfiguration config = new SynchFolderConfiguration(remotePath, filter, targetToken, remotePersistence);
|
|
|
|
|
|
|
|
|
|
SynchFolderConfiguration config = new SynchFolderConfiguration(remotePath, filter, targetToken, remotePersistence, folder.getId());
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
//try to clean it up, first..
|
|
|
|
|
System.out.println("Cleaning it up..");
|
|
|
|
|
System.out.println("Cleaning it up..");
|
|
|
|
|
engine.unsetSynchronizedFolder(folder.getId(), false);
|
|
|
|
|
}catch(WorkspaceNotSynchedException e) {
|
|
|
|
|
// it was already cleared
|
|
|
|
|
}catch(WorkspaceLockedException e) {
|
|
|
|
|
engine.forceUnlock(folder.getId());
|
|
|
|
|
engine.unsetSynchronizedFolder(folder.getId(), false);
|
|
|
|
|
engine.unsetSynchronizedFolder(folder.getId(), false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}catch(WorkspaceNotSynchedException e) {
|
|
|
|
|
System.out.println("Folder not synched, configurin it..");
|
|
|
|
@ -94,37 +93,37 @@ public class TestWsThreddsEngine {
|
|
|
|
|
System.out.println("Workspace locked, going to force unlock.."); // MAINLY FOR TEST PURPOSES, OR WHEN SOMETHIGN GOES WRONG.. USE CAUTIOUSLY
|
|
|
|
|
engine.forceUnlock(folder.getId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// INVOKE SYNCHRONIZATION ON FOLDER
|
|
|
|
|
ProcessDescriptor descriptor=engine.doSync(folder.getId());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
System.out.println("Obtained descriptor : "+descriptor);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SyncOperationCallBack syncCall = new SyncOperationCallBack() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onStep(ProcessStatus status, ProcessDescriptor descriptor) {
|
|
|
|
|
System.out.println("ON STEP : "+status+" "+descriptor);
|
|
|
|
|
System.out.println("LOG : \n"+ status.getLogBuilder().toString());
|
|
|
|
|
if(status.getStatus().equals(ProcessStatus.Status.COMPLETED)) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//COMPLETED FARE REMOVE DALLA MAPPA
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// REGISTER CALLBACK TO MONITOR PROGRESS
|
|
|
|
|
engine.registerCallBack(folder.getId(), syncCall);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
engine.check(folder.getId(), true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// INVOKE WHEN PORTAL SHUTS DOWN TO FREE RESOURCES AND STOP SYNC PROCESSES
|
|
|
|
|
engine.shutDown();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|