add rootFolderId as parameter

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/widgets/ws-thredds-sync-widget@165495 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2018-03-28 12:55:45 +00:00
parent f68786adb8
commit f0e4af3c06
5 changed files with 67 additions and 35 deletions

View File

@ -284,6 +284,7 @@ public class WsThreddsWidgetViewManager {
conf.setRemotePath(remotePath); conf.setRemotePath(remotePath);
conf.setCatalogName(catalogueSelected.getName()); conf.setCatalogName(catalogueSelected.getName());
conf.setSelectedScope(getSelectedScope()); conf.setSelectedScope(getSelectedScope());
conf.setRootFolderId(folder.getFolderId());
WsThreddsWidget.eventBus.fireEvent(new PerformDoSyncEvent(folder, conf)); WsThreddsWidget.eventBus.fireEvent(new PerformDoSyncEvent(folder, conf));
} }

View File

@ -63,6 +63,12 @@ public class BeanConverter {
} }
/**
* To scope title.
*
* @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())
@ -98,14 +104,16 @@ public class BeanConverter {
} }
/** /**
* 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 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 targetScopeUserToken) { public static ThSynchFolderConfiguration toThSynchFolderConfiguration(WsThreddsSynchFolderConfiguration t, String rootFolderId, String targetScopeUserToken) {
if(t==null) if(t==null)
return null; return null;
@ -115,6 +123,7 @@ public class BeanConverter {
ts.setRemotePath(t.getRemotePath()); ts.setRemotePath(t.getRemotePath());
ts.setTargetToken(targetScopeUserToken); ts.setTargetToken(targetScopeUserToken);
ts.setToCreateCatalogName(t.getCatalogName()); ts.setToCreateCatalogName(t.getCatalogName());
ts.setRootFolderId(rootFolderId);
return ts; return ts;
}; };

View File

@ -99,7 +99,7 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
ThSynchFolderConfiguration config = null; ThSynchFolderConfiguration config = null;
if(clientConfig!=null) { if(clientConfig!=null) {
targetScopeUserToken = PortalContext.getConfiguration().getCurrentUserToken(clientConfig.getSelectedScope().getScopeName(), user.getUsername()); targetScopeUserToken = PortalContext.getConfiguration().getCurrentUserToken(clientConfig.getSelectedScope().getScopeName(), user.getUsername());
config = BeanConverter.toThSynchFolderConfiguration(clientConfig, targetScopeUserToken); config = BeanConverter.toThSynchFolderConfiguration(clientConfig, folderId, targetScopeUserToken);
logger.debug("Creating server config "+config); logger.debug("Creating server config "+config);
} }

View File

@ -33,6 +33,8 @@ public class WsThreddsSynchFolderConfiguration implements Serializable{
private Status status; //just for serialization private Status status; //just for serialization
private String rootFolderId;
/** /**
* Instantiates a new ws thredds synch folder configuration. * Instantiates a new ws thredds synch folder configuration.
@ -50,14 +52,34 @@ public class WsThreddsSynchFolderConfiguration implements Serializable{
* @param filter the filter * @param filter the filter
* @param catalogName the catalog name * @param catalogName the catalog name
*/ */
public WsThreddsSynchFolderConfiguration(String remotePath, GcubeScope theVRE, String filter, String catalogName) { public WsThreddsSynchFolderConfiguration(String remotePath, GcubeScope theVRE, String filter, String catalogName, String rootFolderId) {
super(); super();
this.remotePath = remotePath; this.remotePath = remotePath;
this.selectedScope = theVRE; this.selectedScope = theVRE;
this.filter = filter; this.filter = filter;
this.catalogName = catalogName; this.catalogName = catalogName;
this.rootFolderId = rootFolderId;
} }
/**
* @param rootFolderId the rootFolderId to set
*/
public void setRootFolderId(String rootFolderId) {
this.rootFolderId = rootFolderId;
}
/**
* @return the rootFolderId
*/
public String getRootFolderId() {
return rootFolderId;
}
/** /**
* Gets the remote path. * Gets the remote path.
* *
@ -169,10 +191,11 @@ public class WsThreddsSynchFolderConfiguration implements Serializable{
builder.append(catalogName); builder.append(catalogName);
builder.append(", status="); builder.append(", status=");
builder.append(status); builder.append(status);
builder.append(", rootFolderId=");
builder.append(rootFolderId);
builder.append("]"); builder.append("]");
return builder.toString(); return builder.toString();
} }
} }

View File

@ -2,7 +2,6 @@ package org.gcube.portlets.widgets.wsthreddssync;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.util.concurrent.Semaphore;
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;
@ -36,56 +35,56 @@ import org.gcube.usecases.ws.thredds.model.SynchFolderConfiguration;
* Feb 7, 2018 * Feb 7, 2018
*/ */
public class TestWsThreddsEngine { public class TestWsThreddsEngine {
public static String DEFAULT_SCOPE = "/gcube/devsec"; //DEV public static String DEFAULT_SCOPE = "/gcube/devsec"; //DEV
// public static String DEFAULT_SCOPE = "/d4science.research-infrastructures.eu/gCubeApps"; // public static String DEFAULT_SCOPE = "/d4science.research-infrastructures.eu/gCubeApps";
public static String TEST_USER = "francesco.mangiacrapa"; public static String TEST_USER = "francesco.mangiacrapa";
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 ProcessNotFoundException, InternalErrorException, WorkspaceInteractionException, InternalException, WorkspaceFolderNotFoundException, ItemNotFoundException, InsufficientPrivilegesException, ItemAlreadyExistException, HomeNotFoundException, UserNotFoundException, MalformedURLException, IOException {
// GET ENGINE : SINGLETON INSTANCE // GET ENGINE : SINGLETON INSTANCE
SyncEngine engine=SyncEngine.get(); SyncEngine engine=SyncEngine.get();
Workspace ws = HomeLibrary Workspace ws = HomeLibrary
.getHomeManagerFactory() .getHomeManagerFactory()
.getHomeManager() .getHomeManager()
.getHome(TEST_USER) .getHome(TEST_USER)
.getWorkspace(); .getWorkspace();
//TEST INFO... //TEST INFO...
//TestCommons.setScope(); //TestCommons.setScope();
ScopeBean scope = new ScopeBean(DEFAULT_SCOPE); ScopeBean scope = new ScopeBean(DEFAULT_SCOPE);
ScopeProvider.instance.set(scope.toString()); ScopeProvider.instance.set(scope.toString());
WorkspaceFolder folder=(WorkspaceFolder) ws.getItem(TEST_FOLDER_ID); WorkspaceFolder folder=(WorkspaceFolder) ws.getItem(TEST_FOLDER_ID);
// FOLDER CONFIGURATION BEAN // FOLDER CONFIGURATION BEAN
//SynchFolderConfiguration config=TestCommons.getSynchConfig(); //SynchFolderConfiguration config=TestCommons.getSynchConfig();
String filter = ""; String filter = "";
String remotePersistence = ""; String remotePersistence = "";
String remotePath = ""; String remotePath = "";
String targetToken = ""; String targetToken = "";
SynchFolderConfiguration config = new SynchFolderConfiguration(remotePath, filter, targetToken, remotePersistence); SynchFolderConfiguration config = new SynchFolderConfiguration(remotePath, filter, targetToken, remotePersistence, folder.getId());
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(folder.getId(), 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(folder.getId());
engine.unsetSynchronizedFolder(folder.getId(), false); engine.unsetSynchronizedFolder(folder.getId(), 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(folder.getId(), false);
}catch(WorkspaceNotSynchedException e) { }catch(WorkspaceNotSynchedException e) {
System.out.println("Folder not synched, configurin it.."); 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 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(folder.getId());
} }
// INVOKE SYNCHRONIZATION ON FOLDER // INVOKE SYNCHRONIZATION ON FOLDER
ProcessDescriptor descriptor=engine.doSync(folder.getId()); ProcessDescriptor descriptor=engine.doSync(folder.getId());
System.out.println("Obtained descriptor : "+descriptor); System.out.println("Obtained descriptor : "+descriptor);
SyncOperationCallBack syncCall = new SyncOperationCallBack() { SyncOperationCallBack syncCall = new SyncOperationCallBack() {
@Override @Override
public void onStep(ProcessStatus status, ProcessDescriptor descriptor) { public void onStep(ProcessStatus status, ProcessDescriptor descriptor) {
System.out.println("ON STEP : "+status+" "+descriptor); System.out.println("ON STEP : "+status+" "+descriptor);
System.out.println("LOG : \n"+ status.getLogBuilder().toString()); System.out.println("LOG : \n"+ status.getLogBuilder().toString());
if(status.getStatus().equals(ProcessStatus.Status.COMPLETED)) { if(status.getStatus().equals(ProcessStatus.Status.COMPLETED)) {
//COMPLETED FARE REMOVE DALLA MAPPA //COMPLETED FARE REMOVE DALLA MAPPA
} }
} }
}; };
// REGISTER CALLBACK TO MONITOR PROGRESS // REGISTER CALLBACK TO MONITOR PROGRESS
engine.registerCallBack(folder.getId(), syncCall); engine.registerCallBack(folder.getId(), syncCall);
engine.check(folder.getId(), true); engine.check(folder.getId(), 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
engine.shutDown(); engine.shutDown();
} }