|
|
|
@ -6,15 +6,19 @@ package org.gcube.portlets.widgets.wsthreddssync;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
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.portlets.widgets.wsthreddssync.server.SyncronizeWithThredds;
|
|
|
|
|
import org.gcube.usecases.ws.thredds.Constants;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -28,16 +32,7 @@ public class UnSyncThreddsFolders {
|
|
|
|
|
|
|
|
|
|
public static String DEFAULT_SCOPE = "/gcube"; //DEV
|
|
|
|
|
public static String TEST_USER = "francesco.mangiacrapa";
|
|
|
|
|
//public static String FOLDER_SYNC = "d6dae663-91d1-4da7-b13d-959de6fb2f86"; //TestSync is root Folder
|
|
|
|
|
|
|
|
|
|
//token user: Francesco Mangiacrapa - /gcube (root)
|
|
|
|
|
//user.token=0e2c7963-8d3e-4ea6-a56d-ffda530dd0fa-98187548
|
|
|
|
|
|
|
|
|
|
public static String TEST_USER_TOKEN = "0e2c7963-8d3e-4ea6-a56d-ffda530dd0fa-98187548";
|
|
|
|
|
|
|
|
|
|
// public static String FOLDER_A = "983d4ab9-e8fd-4c6d-869e-734a730e3e50";
|
|
|
|
|
// public static String FOLDER_B = "94995b10-6fcb-4ed8-a3ea-4a6dd7d33a7a";
|
|
|
|
|
// public static String FOLDER_C = "e945fcfd-9da9-45a0-98a9-d1940d1720bb";
|
|
|
|
|
public static String TEST_USER_TOKEN = "0e2c7963-8d3e-4ea6-a56d-ffda530dd0fa-98187548"; //token user: Francesco Mangiacrapa - /gcube (root)
|
|
|
|
|
|
|
|
|
|
private static List<String> lstUnSynchedItem = new ArrayList<String>();
|
|
|
|
|
private static List<String> lstUnSynchedFailedItem = new ArrayList<String>();
|
|
|
|
@ -123,7 +118,7 @@ public class UnSyncThreddsFolders {
|
|
|
|
|
if(depthUnsync)
|
|
|
|
|
unsycFirstLevel(ws, workspaceItem.getId(), depthUnsync);
|
|
|
|
|
|
|
|
|
|
unsynFolder(ws, workspaceItem.getId());
|
|
|
|
|
unsynFolder(workspaceItem);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -140,59 +135,55 @@ public class UnSyncThreddsFolders {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Unsyn workspace sub tree.
|
|
|
|
|
* Unsyn folder.
|
|
|
|
|
*
|
|
|
|
|
* @param ws the ws
|
|
|
|
|
* @param itemId the item id
|
|
|
|
|
* @param workspaceItem the workspace item
|
|
|
|
|
*/
|
|
|
|
|
public static void unsynFolder(Workspace ws, String itemId) {
|
|
|
|
|
public static void unsynFolder(WorkspaceItem workspaceItem) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(itemId==null)
|
|
|
|
|
if(workspaceItem==null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
try{
|
|
|
|
|
if(syncService.isItemSynched(itemId, DEFAULT_SCOPE, TEST_USER)){
|
|
|
|
|
Boolean unsynched = syncService.doUnSync(itemId, false, DEFAULT_SCOPE, TEST_USER_TOKEN);
|
|
|
|
|
boolean synched = syncService.isItemSynched(workspaceItem.getId(), DEFAULT_SCOPE, TEST_USER);
|
|
|
|
|
System.out.println("Is the workspace item: "+workspaceItem.getId() + " synched? "+synched +", Is folder? "+workspaceItem.isFolder());
|
|
|
|
|
|
|
|
|
|
if(synched && workspaceItem.isFolder()){
|
|
|
|
|
//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);
|
|
|
|
|
totalAttempts++;
|
|
|
|
|
if(unsynched)
|
|
|
|
|
lstUnSynchedItem.add(itemId);
|
|
|
|
|
else
|
|
|
|
|
lstUnSynchedFailedItem.add(itemId);
|
|
|
|
|
// if(unsynched)
|
|
|
|
|
// lstUnSynchedItem.add(workspaceItem.getId());
|
|
|
|
|
// else
|
|
|
|
|
// lstUnSynchedFailedItem.add(workspaceItem.getId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}catch(Exception e){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
lstErrorItem.add(itemId);
|
|
|
|
|
try {
|
|
|
|
|
lstErrorItem.add(workspaceItem.getId());
|
|
|
|
|
}
|
|
|
|
|
catch (InternalErrorException e1) {
|
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
|
e1.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// WorkspaceItem item;
|
|
|
|
|
// try {
|
|
|
|
|
//
|
|
|
|
|
// item = ws.getItem(itemId);
|
|
|
|
|
//
|
|
|
|
|
// if(item.isFolder()){
|
|
|
|
|
//
|
|
|
|
|
// List<? extends WorkspaceItem> children = item.getChildren();
|
|
|
|
|
// for (WorkspaceItem workspaceItem : children) {
|
|
|
|
|
// unsynWorkspaceSubTree(ws, workspaceItem.getId());
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// }catch (ItemNotFoundException e) {
|
|
|
|
|
// // TODO Auto-generated catch block
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
// lstErrorItem.add(itemId);
|
|
|
|
|
//
|
|
|
|
|
// }catch (InternalErrorException e) {
|
|
|
|
|
// // TODO Auto-generated catch block
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
// lstErrorItem.add(itemId);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void cleanItem(WorkspaceItem item) throws InternalErrorException {
|
|
|
|
|
Properties props=item.getProperties();
|
|
|
|
|
if(props.hasProperty(Constants.WorkspaceProperties.TBS)) {
|
|
|
|
|
if(item.isFolder()) {
|
|
|
|
|
props.addProperties(Constants.cleanedFolderPropertiesMap);
|
|
|
|
|
for(WorkspaceItem child : ((WorkspaceFolder)item).getChildren())
|
|
|
|
|
cleanItem(child);
|
|
|
|
|
}else props.addProperties(Constants.cleanedItemPropertiesMap);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|