2018-03-14 11:30:57 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
package org.gcube.portlets.widgets.wsthreddssync;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import org.gcube.portlets.widgets.wsthreddssync.server.SyncronizeWithThredds;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Class UnSyncThreddsFolders.
|
|
|
|
*
|
|
|
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
|
|
|
* Mar 13, 2018
|
|
|
|
*/
|
|
|
|
public class UnSyncThreddsFolders {
|
|
|
|
|
|
|
|
public static String DEFAULT_SCOPE = "/gcube"; //DEV
|
|
|
|
public static String TEST_USER = "francesco.mangiacrapa";
|
2021-05-11 12:51:09 +02:00
|
|
|
public static String TEST_USER_TOKEN = "TOKEN";
|
2018-03-14 11:30:57 +01:00
|
|
|
|
|
|
|
private static List<String> lstUnSynchedItem = new ArrayList<String>();
|
|
|
|
private static List<String> lstUnSynchedFailedItem = new ArrayList<String>();
|
|
|
|
private static List<String> lstErrorItem = new ArrayList<String>();
|
|
|
|
private static long totalAttempts = 0;
|
2019-08-02 15:04:28 +02:00
|
|
|
|
|
|
|
static String scope = "/gcube/devsec";
|
|
|
|
static String token = "TOKEN";
|
2018-03-14 11:30:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
public static SyncronizeWithThredds syncService = new SyncronizeWithThredds();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The main method.
|
|
|
|
*
|
|
|
|
* @param args the arguments
|
|
|
|
* @throws WorkspaceFolderNotFoundException the workspace folder not found exception
|
|
|
|
* @throws InternalErrorException the internal error exception
|
|
|
|
* @throws HomeNotFoundException the home not found exception
|
|
|
|
*/
|
2021-05-11 13:01:01 +02:00
|
|
|
/*
|
2019-08-02 15:04:28 +02:00
|
|
|
public static void main(String[] args) throws Exception {
|
2018-03-14 11:30:57 +01:00
|
|
|
|
|
|
|
unsycFirstLevel(ws, ws.getRoot().getId(), false);
|
|
|
|
|
|
|
|
System.out.println("UnSync completed");
|
|
|
|
|
|
|
|
System.out.println("\nUnsync attempted: "+totalAttempts);
|
|
|
|
|
|
|
|
System.out.println("\nTotal failed unsync: "+lstUnSynchedFailedItem.size());
|
|
|
|
|
|
|
|
for (String string : args) {
|
|
|
|
System.out.println("Failed unsync: "+string);
|
|
|
|
}
|
|
|
|
|
|
|
|
System.out.println("\nUnsynched "+lstUnSynchedItem.size() +" item/s");
|
|
|
|
for (String string : lstUnSynchedItem) {
|
|
|
|
System.out.println("Unsynched id: "+string);
|
|
|
|
}
|
|
|
|
|
|
|
|
System.out.println("\nErros on "+lstErrorItem.size() +" item/s");
|
|
|
|
for (String string : lstErrorItem) {
|
|
|
|
System.out.println("Error on id: "+string);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-08-02 15:04:28 +02:00
|
|
|
public static void unsycFirstLevel(Workspace ws, String itemId, boolean depthUnsync) throws Exception{
|
2018-03-14 11:30:57 +01:00
|
|
|
|
|
|
|
WorkspaceItem item;
|
|
|
|
try {
|
|
|
|
|
|
|
|
item = ws.getItem(itemId);
|
|
|
|
|
|
|
|
if(item.isFolder()){
|
|
|
|
|
2019-08-02 15:04:28 +02:00
|
|
|
List<? extends WorkspaceItem> children = ws.getChildren(item.getId());
|
2018-03-14 11:30:57 +01:00
|
|
|
for (WorkspaceItem workspaceItem : children) {
|
|
|
|
if(depthUnsync)
|
|
|
|
unsycFirstLevel(ws, workspaceItem.getId(), depthUnsync);
|
|
|
|
|
2018-03-14 14:24:45 +01:00
|
|
|
unsynFolder(workspaceItem);
|
2018-03-14 11:30:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}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);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-03-14 14:24:45 +01:00
|
|
|
public static void unsynFolder(WorkspaceItem workspaceItem) {
|
2018-03-14 11:30:57 +01:00
|
|
|
|
2018-03-14 14:24:45 +01:00
|
|
|
if(workspaceItem==null)
|
2018-03-14 11:30:57 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
try{
|
2021-05-11 12:51:09 +02:00
|
|
|
ScopeProvider.instance.set(DEFAULT_SCOPE);
|
|
|
|
SecurityTokenProvider.instance.set(TEST_USER_TOKEN);
|
|
|
|
ThSyncFolderDescriptor synched = syncService.isItemSynched(workspaceItem.getId());
|
2018-03-14 14:24:45 +01:00
|
|
|
System.out.println("Is the workspace item: "+workspaceItem.getId() + " synched? "+synched +", Is folder? "+workspaceItem.isFolder());
|
|
|
|
|
2021-05-11 12:51:09 +02:00
|
|
|
if(synched != null){
|
2018-03-14 14:24:45 +01:00
|
|
|
//Boolean unsynched = syncService.doUnSync(workspaceItem.getId(), false, DEFAULT_SCOPE, TEST_USER_TOKEN);
|
2019-08-02 15:04:28 +02:00
|
|
|
Workspace ws = getWorkspace();
|
|
|
|
cleanItem(workspaceItem, ws);
|
2018-03-14 11:30:57 +01:00
|
|
|
totalAttempts++;
|
2018-03-14 14:24:45 +01:00
|
|
|
// if(unsynched)
|
|
|
|
// lstUnSynchedItem.add(workspaceItem.getId());
|
|
|
|
// else
|
|
|
|
// lstUnSynchedFailedItem.add(workspaceItem.getId());
|
2018-03-14 11:30:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}catch(Exception e){
|
|
|
|
e.printStackTrace();
|
2019-08-02 15:04:28 +02:00
|
|
|
lstErrorItem.add(workspaceItem.getId());
|
2018-03-14 11:30:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-08-02 15:04:28 +02:00
|
|
|
static void cleanItem(WorkspaceItem item, Workspace ws) throws Exception {
|
|
|
|
|
2019-10-21 12:42:46 +02:00
|
|
|
// Map<String, Object> props = ws.getMetadata(item.getId());
|
|
|
|
// if(props.containsKey(Constants.WorkspaceProperties.TBS)) {
|
|
|
|
// if(item.isFolder()) {
|
|
|
|
// //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);
|
|
|
|
// }
|
|
|
|
// }
|
2018-03-14 14:24:45 +01:00
|
|
|
}
|
2021-05-11 13:01:01 +02:00
|
|
|
*/
|
2018-03-14 14:24:45 +01:00
|
|
|
|
2018-03-14 11:30:57 +01:00
|
|
|
|
|
|
|
}
|