From 42df0a3a4f600c2178be2d37d85ed4e489c02062 Mon Sep 17 00:00:00 2001 From: Francesco Mangiacrapa Date: Wed, 14 Mar 2018 13:24:45 +0000 Subject: [PATCH] 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 --- .../server/SyncronizeWithThredds.java | 11 +-- .../wsthreddssync/UnSyncThreddsFolders.java | 89 +++++++++---------- 2 files changed, 46 insertions(+), 54 deletions(-) diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java index 4146b60..7f2ae33 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java @@ -131,8 +131,8 @@ public class SyncronizeWithThredds { } }catch (Exception e) { - logger.error("Error on isItemSynched for id: "+folderId, e); - throw new Exception("Sorry an error occurred during read sync status from HL properties, try again later"); + 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"); } } @@ -192,20 +192,21 @@ public class SyncronizeWithThredds { } + /** * Do un sync. * - * @param itemId the item id + * @param folderId the folder id * @param deleteRemoteContent the delete remote content * @param scope the scope * @param userToken the user token * @return the boolean * @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); - return workspaceThreddsSynchronize.doUnSync(itemId, deleteRemoteContent); + return workspaceThreddsSynchronize.doUnSync(folderId, deleteRemoteContent); } diff --git a/src/test/java/org/gcube/portlets/widgets/wsthreddssync/UnSyncThreddsFolders.java b/src/test/java/org/gcube/portlets/widgets/wsthreddssync/UnSyncThreddsFolders.java index 8aba483..a4cd369 100644 --- a/src/test/java/org/gcube/portlets/widgets/wsthreddssync/UnSyncThreddsFolders.java +++ b/src/test/java/org/gcube/portlets/widgets/wsthreddssync/UnSyncThreddsFolders.java @@ -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 lstUnSynchedItem = new ArrayList(); private static List lstUnSynchedFailedItem = new ArrayList(); @@ -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 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); + } + } + }