added main unsync facility
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/widgets/ws-thredds-sync-widget@165050 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
f983e1a5ba
commit
42df0a3a4f
|
@ -131,8 +131,8 @@ public class SyncronizeWithThredds {
|
||||||
}
|
}
|
||||||
|
|
||||||
}catch (Exception e) {
|
}catch (Exception e) {
|
||||||
logger.error("Error on isItemSynched for id: "+folderId, e);
|
logger.error("Error on getSynchedStatusFromItemProperty for id: "+folderId, e);
|
||||||
throw new Exception("Sorry an error occurred during read sync status from HL properties, try again later");
|
throw new Exception("Sorry, an error occurred during read sync status from HL properties, try again later");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,20 +192,21 @@ public class SyncronizeWithThredds {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Do un sync.
|
* Do un sync.
|
||||||
*
|
*
|
||||||
* @param itemId the item id
|
* @param folderId the folder id
|
||||||
* @param deleteRemoteContent the delete remote content
|
* @param deleteRemoteContent the delete remote content
|
||||||
* @param scope the scope
|
* @param scope the scope
|
||||||
* @param userToken the user token
|
* @param userToken the user token
|
||||||
* @return the boolean
|
* @return the boolean
|
||||||
* @throws Exception the exception
|
* @throws Exception the exception
|
||||||
*/
|
*/
|
||||||
public Boolean doUnSync(String itemId, boolean deleteRemoteContent, String scope, String userToken) throws Exception {
|
public Boolean doUnSync(String folderId, boolean deleteRemoteContent, String scope, String userToken) throws Exception {
|
||||||
|
|
||||||
setContextParameters(scope, userToken);
|
setContextParameters(scope, userToken);
|
||||||
return workspaceThreddsSynchronize.doUnSync(itemId, deleteRemoteContent);
|
return workspaceThreddsSynchronize.doUnSync(folderId, deleteRemoteContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,15 +6,19 @@ package org.gcube.portlets.widgets.wsthreddssync;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
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.HomeLibrary;
|
||||||
import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
|
import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
|
||||||
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
|
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.Workspace;
|
||||||
|
import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder;
|
||||||
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
|
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.ItemNotFoundException;
|
||||||
import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
|
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.portlets.widgets.wsthreddssync.server.SyncronizeWithThredds;
|
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 DEFAULT_SCOPE = "/gcube"; //DEV
|
||||||
public static String TEST_USER = "francesco.mangiacrapa";
|
public static String TEST_USER = "francesco.mangiacrapa";
|
||||||
//public static String FOLDER_SYNC = "d6dae663-91d1-4da7-b13d-959de6fb2f86"; //TestSync is root Folder
|
public static String TEST_USER_TOKEN = "0e2c7963-8d3e-4ea6-a56d-ffda530dd0fa-98187548"; //token user: Francesco Mangiacrapa - /gcube (root)
|
||||||
|
|
||||||
//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";
|
|
||||||
|
|
||||||
private static List<String> lstUnSynchedItem = new ArrayList<String>();
|
private static List<String> lstUnSynchedItem = new ArrayList<String>();
|
||||||
private static List<String> lstUnSynchedFailedItem = new ArrayList<String>();
|
private static List<String> lstUnSynchedFailedItem = new ArrayList<String>();
|
||||||
|
@ -123,7 +118,7 @@ public class UnSyncThreddsFolders {
|
||||||
if(depthUnsync)
|
if(depthUnsync)
|
||||||
unsycFirstLevel(ws, workspaceItem.getId(), 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 workspaceItem the workspace item
|
||||||
* @param itemId the item id
|
|
||||||
*/
|
*/
|
||||||
public static void unsynFolder(Workspace ws, String itemId) {
|
public static void unsynFolder(WorkspaceItem workspaceItem) {
|
||||||
|
|
||||||
|
if(workspaceItem==null)
|
||||||
if(itemId==null)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
try{
|
try{
|
||||||
if(syncService.isItemSynched(itemId, DEFAULT_SCOPE, TEST_USER)){
|
boolean synched = syncService.isItemSynched(workspaceItem.getId(), DEFAULT_SCOPE, TEST_USER);
|
||||||
Boolean unsynched = syncService.doUnSync(itemId, false, DEFAULT_SCOPE, TEST_USER_TOKEN);
|
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++;
|
totalAttempts++;
|
||||||
if(unsynched)
|
// if(unsynched)
|
||||||
lstUnSynchedItem.add(itemId);
|
// lstUnSynchedItem.add(workspaceItem.getId());
|
||||||
else
|
// else
|
||||||
lstUnSynchedFailedItem.add(itemId);
|
// lstUnSynchedFailedItem.add(workspaceItem.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
e.printStackTrace();
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue