From 38c401219407917315dc663288b00b3553a13f1e Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 7 May 2021 18:30:40 +0200 Subject: [PATCH 01/15] moved to 1.5.0-SNAPSHOT. Starting migration to ws-thredds.1.x --- CHANGELOG.md | 4 + pom.xml | 6 +- .../wssynclibrary/DoConnectRepository.java | 10 +- .../thredds/ThSynchFolderConfiguration.java | 134 +++++--- .../thredds/ThreddsConverter.java | 173 +++++----- .../thredds/WorkspaceThreddsSynchronize.java | 320 +++++++++--------- ...orkspaceThreddsSynchronizedRepository.java | 2 - 7 files changed, 344 insertions(+), 305 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f4f5f1..a2a7243 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [v1.5.0-SNAPSHOT] - 2021-05-07 + +[#21374] Moved to ws-thredds 1.x + ## [v1.4.0] - 2021-03-10 diff --git a/pom.xml b/pom.xml index 05e09b9..c5bc464 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ org.gcube.portal ws-synchronized-module-library - 1.4.0 + 1.5.0-SNAPSHOT jar ws-synchronized-module-library @@ -37,7 +37,7 @@ org.gcube.distribution maven-portal-bom - 3.6.0 + 3.6.1 pom import @@ -49,7 +49,7 @@ org.gcube.spatial.data ws-thredds - [0.1.0, 1.0.0-SNAPSHOT) + [1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT) compile diff --git a/src/main/java/org/gcube/portal/wssynclibrary/DoConnectRepository.java b/src/main/java/org/gcube/portal/wssynclibrary/DoConnectRepository.java index 741c168..b3744ec 100644 --- a/src/main/java/org/gcube/portal/wssynclibrary/DoConnectRepository.java +++ b/src/main/java/org/gcube/portal/wssynclibrary/DoConnectRepository.java @@ -1,21 +1,19 @@ package org.gcube.portal.wssynclibrary; - -// TODO: Auto-generated Javadoc /** * The Interface DoConnectRepository. * - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Feb 14, 2018 + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Feb 14, 2018 */ public interface DoConnectRepository { - + /** * Inits the repository. * * @return true, if successful + * @throws Exception */ - Boolean initRepository(); + Boolean initRepository() throws Exception; /** * Shutdown repository. diff --git a/src/main/java/org/gcube/portal/wssynclibrary/shared/thredds/ThSynchFolderConfiguration.java b/src/main/java/org/gcube/portal/wssynclibrary/shared/thredds/ThSynchFolderConfiguration.java index c7563ec..ccf4d5f 100644 --- a/src/main/java/org/gcube/portal/wssynclibrary/shared/thredds/ThSynchFolderConfiguration.java +++ b/src/main/java/org/gcube/portal/wssynclibrary/shared/thredds/ThSynchFolderConfiguration.java @@ -2,15 +2,13 @@ package org.gcube.portal.wssynclibrary.shared.thredds; import java.io.Serializable; - // TODO: Auto-generated Javadoc /** * The Class ThSynchFolderConfiguration. * - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Feb 8, 2018 + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Feb 8, 2018 */ -public class ThSynchFolderConfiguration implements Serializable{ +public class ThSynchFolderConfiguration implements Serializable { /** The Constant serialVersionUID. */ private static final long serialVersionUID = -5807533629170443212L; @@ -21,36 +19,47 @@ public class ThSynchFolderConfiguration implements Serializable{ /** The filter. */ private String filter; - /** The target token. */ - private String targetToken; + private String targetContext; /** The to create catalog name. */ private String toCreateCatalogName; /** The remote persistence. */ - private String remotePersistence="thredds"; + private String remotePersistence = "thredds"; private String rootFolderId; - + /** + * Instantiates a new th synch folder configuration. + */ public ThSynchFolderConfiguration() { // TODO Auto-generated constructor stub } - public ThSynchFolderConfiguration(String remotePath, String filter, String targetToken, String toCreateCatalogName, - String remotePersistence, String rootFolderId) { + /** + * Instantiates a new th synch folder configuration. + * + * @param remotePath the remote path + * @param filter the filter + * @param targetContext the target context + * @param toCreateCatalogName the to create catalog name + * @param remotePersistence the remote persistence + * @param rootFolderId the root folder id + */ + public ThSynchFolderConfiguration(String remotePath, String filter, String targetContext, + String toCreateCatalogName, String remotePersistence, String rootFolderId) { super(); this.remotePath = remotePath; this.filter = filter; - this.targetToken = targetToken; + this.targetContext = targetContext; this.toCreateCatalogName = toCreateCatalogName; this.remotePersistence = remotePersistence; this.rootFolderId = rootFolderId; } - - /** + * Gets the root folder id. + * * @return the rootFolderId */ public String getRootFolderId() { @@ -58,8 +67,9 @@ public class ThSynchFolderConfiguration implements Serializable{ return rootFolderId; } - /** + * Sets the root folder id. + * * @param rootFolderId the rootFolderId to set */ public void setRootFolderId(String rootFolderId) { @@ -67,87 +77,105 @@ public class ThSynchFolderConfiguration implements Serializable{ this.rootFolderId = rootFolderId; } - + /** + * Gets the remote path. + * + * @return the remote path + */ public String getRemotePath() { return remotePath; } - - - + /** + * Sets the remote path. + * + * @param remotePath the new remote path + */ public void setRemotePath(String remotePath) { this.remotePath = remotePath; } - - - + /** + * Gets the filter. + * + * @return the filter + */ public String getFilter() { return filter; } - - - + /** + * Sets the filter. + * + * @param filter the new filter + */ public void setFilter(String filter) { this.filter = filter; } - - - - public String getTargetToken() { - return targetToken; + /** + * Gets the target context. + * + * @return the target context + */ + public String getTargetContext() { + return targetContext; } - - - - public void setTargetToken(String targetToken) { - this.targetToken = targetToken; + /** + * Sets the target context. + * + * @param targetContext the new target context + */ + public void setTargetContext(String targetContext) { + this.targetContext = targetContext; } - - - + /** + * Gets the to create catalog name. + * + * @return the to create catalog name + */ public String getToCreateCatalogName() { return toCreateCatalogName; } - - - + /** + * Sets the to create catalog name. + * + * @param toCreateCatalogName the new to create catalog name + */ public void setToCreateCatalogName(String toCreateCatalogName) { this.toCreateCatalogName = toCreateCatalogName; } - - - + /** + * Gets the remote persistence. + * + * @return the remote persistence + */ public String getRemotePersistence() { return remotePersistence; } - - - + /** + * Sets the remote persistence. + * + * @param remotePersistence the new remote persistence + */ public void setRemotePersistence(String remotePersistence) { this.remotePersistence = remotePersistence; } - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ @Override public String toString() { - StringBuilder builder = new StringBuilder(); builder.append("ThSynchFolderConfiguration [remotePath="); builder.append(remotePath); builder.append(", filter="); builder.append(filter); - builder.append(", targetToken="); - builder.append(targetToken); + builder.append(", targetContext="); + builder.append(targetContext); builder.append(", toCreateCatalogName="); builder.append(toCreateCatalogName); builder.append(", remotePersistence="); @@ -158,5 +186,7 @@ public class ThSynchFolderConfiguration implements Serializable{ return builder.toString(); } + + } diff --git a/src/main/java/org/gcube/portal/wssynclibrary/thredds/ThreddsConverter.java b/src/main/java/org/gcube/portal/wssynclibrary/thredds/ThreddsConverter.java index 0d7e47c..c7dbcf1 100644 --- a/src/main/java/org/gcube/portal/wssynclibrary/thredds/ThreddsConverter.java +++ b/src/main/java/org/gcube/portal/wssynclibrary/thredds/ThreddsConverter.java @@ -16,15 +16,10 @@ import org.gcube.usecases.ws.thredds.model.gui.CatalogBean; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - - - -// TODO: Auto-generated Javadoc /** * The Class ThreddsConverter. * - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Feb 14, 2018 + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Feb 14, 2018 */ public class ThreddsConverter { @@ -35,135 +30,137 @@ public class ThreddsConverter { /** The to S sync folder descriptor. */ public static Function toThSyncFolderDescriptor = new Function() { - public ThSyncFolderDescriptor apply(SyncFolderDescriptor t) { - ThSyncFolderDescriptor mySync = new ThSyncFolderDescriptor(); - if(t==null) { - logger.info("Input "+SyncFolderDescriptor.class.getSimpleName()+" is null, returning empty "+ThSyncFolderDescriptor.class.getSimpleName()); - return mySync; - } + public ThSyncFolderDescriptor apply(SyncFolderDescriptor t) { + ThSyncFolderDescriptor mySync = new ThSyncFolderDescriptor(); + if (t == null) { + logger.info("Input " + SyncFolderDescriptor.class.getSimpleName() + " is null, returning empty " + + ThSyncFolderDescriptor.class.getSimpleName()); + return mySync; + } - mySync.setFolderId(t.getFolderId()); - mySync.setFolderPath(t.getFolderPath()); - mySync.setLocked(t.isLocked()); - ThProcessDescriptor localProcessDescriptor = toThProcessDescriptor.apply(t.getLocalProcessDescriptor()); + mySync.setFolderId(t.getFolderId()); + mySync.setFolderPath(t.getFolderPath()); + mySync.setLocked(t.isLocked()); + ThProcessDescriptor localProcessDescriptor = toThProcessDescriptor.apply(t.getLocalProcessDescriptor()); mySync.setLocalProcessDescriptor(localProcessDescriptor); ThSynchFolderConfiguration configuration = toThSynchFolderConfiguration.apply(t.getConfiguration()); mySync.setConfiguration(configuration); - return mySync; - } + return mySync; + } }; /** The to S sync folder descriptor. */ public static Function toSyncFolderDescriptor = new Function() { - public SyncFolderDescriptor apply(ThSyncFolderDescriptor t) { + public SyncFolderDescriptor apply(ThSyncFolderDescriptor t) { - if(t==null) { - logger.warn("Input "+ThSyncFolderDescriptor.class.getSimpleName()+" is null, returning null"); - return null; - } + if (t == null) { + logger.warn("Input " + ThSyncFolderDescriptor.class.getSimpleName() + " is null, returning null"); + return null; + } - SynchFolderConfiguration configuration = toSynchFolderConfiguration.apply(t.getConfiguration()); + SynchFolderConfiguration configuration = toSynchFolderConfiguration.apply(t.getConfiguration()); return new SyncFolderDescriptor(t.getFolderId(), t.getFolderPath(), configuration); - } + } }; /** The to synch folder configuration. */ public static Function toSynchFolderConfiguration = new Function() { - public SynchFolderConfiguration apply(ThSynchFolderConfiguration t) { + public SynchFolderConfiguration apply(ThSynchFolderConfiguration t) { - if(t==null) { - logger.warn("Input "+ThSynchFolderConfiguration.class.getSimpleName()+" is null, returning null"); - return null; - } + if (t == null) { + logger.warn("Input " + ThSynchFolderConfiguration.class.getSimpleName() + " is null, returning null"); + return null; + } - String filter = t.getFilter()!=null && !t.getFilter().isEmpty()?t.getFilter():THREDDS_FILTER_NC_NCML_ASC; - return new SynchFolderConfiguration(t.getRemotePath(), filter, t.getTargetToken(), t.getToCreateCatalogName(), t.getRootFolderId()); - } + String filter = t.getFilter() != null && !t.getFilter().isEmpty() ? t.getFilter() + : THREDDS_FILTER_NC_NCML_ASC; + return new SynchFolderConfiguration(t.getRemotePath(), filter, t.getTargetContext(), + t.getToCreateCatalogName(), t.getRootFolderId()); + } }; - /** The to S synch folder configuration. */ public static Function toThSynchFolderConfiguration = new Function() { - public ThSynchFolderConfiguration apply(SynchFolderConfiguration t) { - ThSynchFolderConfiguration mySync = new ThSynchFolderConfiguration(); - if(t==null) { - logger.info("Input "+SynchFolderConfiguration.class.getSimpleName()+" is null, returning empty "+ThSynchFolderConfiguration.class.getSimpleName()); - return mySync; - } - mySync.setFilter(t.getFilter()); - mySync.setRemotePath(t.getRemotePath()); - mySync.setRemotePersistence(t.getRemotePersistence()); - mySync.setTargetToken(t.getTargetToken()); - mySync.setToCreateCatalogName(t.getToCreateCatalogName()); - mySync.setRootFolderId(t.getRootFolderId()); - return mySync; - } + public ThSynchFolderConfiguration apply(SynchFolderConfiguration t) { + ThSynchFolderConfiguration mySync = new ThSynchFolderConfiguration(); + if (t == null) { + logger.info("Input " + SynchFolderConfiguration.class.getSimpleName() + " is null, returning empty " + + ThSynchFolderConfiguration.class.getSimpleName()); + return mySync; + } + mySync.setFilter(t.getFilter()); + mySync.setRemotePath(t.getRemotePath()); + mySync.setRemotePersistence(t.getRemotePersistence()); + mySync.setTargetContext(t.getTargetContext()); + mySync.setToCreateCatalogName(t.getToCreateCatalogName()); + mySync.setRootFolderId(t.getRootFolderId()); + return mySync; + } }; - /** The to S sync folder descriptor. */ public static Function toThProcessDescriptor = new Function() { - public ThProcessDescriptor apply(ProcessDescriptor t) { - ThProcessDescriptor mySync = new ThProcessDescriptor(); - if(t==null) { - logger.info("Input "+ProcessDescriptor.class.getSimpleName()+" is null, returning empty "+ThProcessDescriptor.class.getSimpleName()); - return mySync; - } + public ThProcessDescriptor apply(ProcessDescriptor t) { + ThProcessDescriptor mySync = new ThProcessDescriptor(); + if (t == null) { + logger.info("Input " + ProcessDescriptor.class.getSimpleName() + " is null, returning empty " + + ThProcessDescriptor.class.getSimpleName()); + return mySync; + } - mySync.setFolderId(t.getFolderId()); - mySync.setFolderPath(t.getFolderPath()); - mySync.setProcessId(t.getProcessId()); - ThSynchFolderConfiguration fc = toThSynchFolderConfiguration.apply(t.getSynchConfiguration()); - mySync.setSynchConfiguration(fc); - return mySync; - } + mySync.setFolderId(t.getFolderId()); + mySync.setFolderPath(t.getFolderPath()); + mySync.setProcessId(t.getProcessId()); + ThSynchFolderConfiguration fc = toThSynchFolderConfiguration.apply(t.getSynchConfiguration()); + mySync.setSynchConfiguration(fc); + return mySync; + } }; - /** The to th catalogue bean. */ public static Function toThCatalogueBean = new Function() { @Override public ThCatalogueBean apply(CatalogBean t) { - if(t==null) + if (t == null) return null; return new ThCatalogueBean(t.getName(), t.getPath(), t.getIsDefault()); } }; - /** The to th process status. */ public static Function toThProcessStatus = new Function() { - public ThProcessStatus apply(ProcessStatus t) { - ThProcessStatus mySync = new ThProcessStatus(); - if(t==null) { - logger.info("Input "+ProcessStatus.class.getSimpleName()+" is null, returning empty "+ThProcessStatus.class.getSimpleName()); - return mySync; - } + public ThProcessStatus apply(ProcessStatus t) { + ThProcessStatus mySync = new ThProcessStatus(); + if (t == null) { + logger.info("Input " + ProcessStatus.class.getSimpleName() + " is null, returning empty " + + ThProcessStatus.class.getSimpleName()); + return mySync; + } - mySync.setCurrentMessage(t.getCurrentMessage()); - mySync.setPercentCompleted(t.getPercent()); + mySync.setCurrentMessage(t.getCurrentMessage()); + mySync.setPercentCompleted(t.getPercent()); - if(t.getErrorCount()!=null) - mySync.setErrorCount(t.getErrorCount().get()); - if(t.getLogBuilder()!=null) - mySync.setLogBuilder(t.getLogBuilder().toString()); - if(t.getQueuedTransfers()!=null) - mySync.setQueuedTransfers(t.getQueuedTransfers().get()); - if(t.getServedTransfers()!=null) - mySync.setServedTransfers(t.getServedTransfers().get()); + if (t.getErrorCount() != null) + mySync.setErrorCount(t.getErrorCount().get()); + if (t.getLogBuilder() != null) + mySync.setLogBuilder(t.getLogBuilder().toString()); + if (t.getQueuedTransfers() != null) + mySync.setQueuedTransfers(t.getQueuedTransfers().get()); + if (t.getServedTransfers() != null) + mySync.setServedTransfers(t.getServedTransfers().get()); - if(t.getStatus()!=null) { + if (t.getStatus() != null) { - switch (t.getStatus()) { + switch (t.getStatus()) { case COMPLETED: mySync.setStatus(Status.COMPLETED); break; @@ -183,12 +180,10 @@ public class ThreddsConverter { default: break; } - } - //mySync.setStatus(t.getStatus()); - return mySync; - } + } + // mySync.setStatus(t.getStatus()); + return mySync; + } }; - - } diff --git a/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java b/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java index ac44864..9f688a1 100644 --- a/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java +++ b/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java @@ -34,21 +34,19 @@ import org.gcube.usecases.ws.thredds.model.gui.CatalogBean; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - -// TODO: Auto-generated Javadoc /** * The Class WorkspaceThreddsSynchronize. * - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Feb 14, 2018 + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Feb 14, 2018 */ -public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronizedRepository{ +public class WorkspaceThreddsSynchronize + implements WorkspaceThreddsSynchronizedRepository { /** The logger. */ private static Logger logger = LoggerFactory.getLogger(WorkspaceThreddsSynchronize.class); /** The engine. */ - private SyncEngine engine=null; + private SyncEngine engine = null; /** The instance. */ private static WorkspaceThreddsSynchronize instance = null; @@ -69,7 +67,6 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized engine = SyncEngine.get(); } - /** * Gets the single instance of WorkspaceThreddsSynchronize. * @@ -90,62 +87,68 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized */ public static StorageHubClient getStorageHubInstance() { - if(storageHubInstance==null) + if (storageHubInstance == null) storageHubInstance = new StorageHubClient(); return storageHubInstance; } - - - /* (non-Javadoc) - * @see org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#isItemSynchronized(java.lang.String) + /* + * (non-Javadoc) + * + * @see org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository# + * isItemSynchronized(java.lang.String) */ /** * Check item synched. * * @param itemId the item id * @return the th sync folder descriptor - * @throws ItemNotSynched the item not synched + * @throws ItemNotSynched the item not synched * @throws WorkspaceFolderLocked the workspace folder locked - * @throws Exception the exception + * @throws Exception the exception */ @Override - public ThSyncFolderDescriptor checkItemSynched(String itemId) throws ItemNotSynched, WorkspaceFolderLocked, Exception { - logger.debug("Perfoming checkItemSynched for id: "+itemId); + public ThSyncFolderDescriptor checkItemSynched(String itemId) + throws ItemNotSynched, WorkspaceFolderLocked, Exception { + logger.debug("Perfoming checkItemSynched for id: " + itemId); try { // WHEN OPENING A FOLDER, INVOKE CHECK TO UPDATE SYNCH STATUS SyncFolderDescriptor desc = engine.check(itemId, false); - logger.debug("The item id: "+itemId +" is synched"); + logger.debug("The item id: " + itemId + " is synched"); ThSyncFolderDescriptor descr = ThreddsConverter.toThSyncFolderDescriptor.apply(desc); - logger.trace("CheckItemSynched for id: "+itemId+" returning descriptor: "+descr); + logger.trace("CheckItemSynched for id: " + itemId + " returning descriptor: " + descr); return descr; - }catch(WorkspaceNotSynchedException e) { - String err = "The item id: "+itemId +" is not synched"; + } catch (WorkspaceNotSynchedException e) { + String err = "The item id: " + itemId + " is not synched"; logger.trace(err); - throw new ItemNotSynched("The item id: "+itemId +" is not synched"); + throw new ItemNotSynched("The item id: " + itemId + " is not synched"); // System.out.println("Folder not synched, configurin it.."); - //engine.setSynchronizedFolder(config, folder.getId()); - }catch(WorkspaceLockedException e) { - //logger.warn("Workspace locked, going to force unlock.."); - throw new WorkspaceFolderLocked(itemId, "The folder id: "+itemId +" is currently locked. Another sync process is in progress"); - //engine.forceUnlock(itemId); + // engine.setSynchronizedFolder(config, folder.getId()); + } catch (WorkspaceLockedException e) { + // logger.warn("Workspace locked, going to force unlock.."); + throw new WorkspaceFolderLocked(itemId, + "The folder id: " + itemId + " is currently locked. Another sync process is in progress"); + // engine.forceUnlock(itemId); } catch (WorkspaceInteractionException | InternalException e) { - logger.error("Error: ",e); - if(e instanceof WorkspaceInteractionException) - throw new Exception("Sorry, an error occurred during check syncronization due to WS interection for the itemId: "+itemId); - else if(e instanceof InternalException) - throw new Exception("Sorry, an Internal Exception occurred during check syncronization for the itemId: "+itemId); + logger.error("Error: ", e); + if (e instanceof WorkspaceInteractionException) + throw new Exception( + "Sorry, an error occurred during check syncronization due to WS interection for the itemId: " + + itemId); + else if (e instanceof InternalException) + throw new Exception( + "Sorry, an Internal Exception occurred during check syncronization for the itemId: " + itemId); - throw new Exception("Sorry, an error occurred server side during chck syncronization for the itemId: "+itemId); + throw new Exception( + "Sorry, an error occurred server side during chck syncronization for the itemId: " + itemId); } } - /** * Sets the synchronized folder. * @@ -154,32 +157,31 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized * @return the th sync folder descriptor * @throws Exception the exception */ - public ThSyncFolderDescriptor setSynchronizedFolder(ThSynchFolderConfiguration thConfig, String itemId) throws Exception { + public ThSyncFolderDescriptor setSynchronizedFolder(ThSynchFolderConfiguration thConfig, String itemId) + throws Exception { SynchFolderConfiguration config = ThreddsConverter.toSynchFolderConfiguration.apply(thConfig); - if(thConfig.getRemotePath()==null || thConfig.getRemotePath().isEmpty()) + if (thConfig.getRemotePath() == null || thConfig.getRemotePath().isEmpty()) throw new Exception("A valid remote path must be provided"); - if(thConfig.getToCreateCatalogName()==null || thConfig.getToCreateCatalogName().isEmpty()) + if (thConfig.getToCreateCatalogName() == null || thConfig.getToCreateCatalogName().isEmpty()) throw new Exception("A valid Catalogue Name must be provided"); - if(thConfig.getTargetToken()==null || thConfig.getTargetToken().isEmpty()) - throw new Exception("A valid Target Token must be provided"); - try { engine.setSynchronizedFolder(config, itemId); } catch (WorkspaceInteractionException | InternalException e) { - logger.error("Error on setSynchronizedFolder for config: "+thConfig); - logger.error("Using itemId: "+itemId,e); + logger.error("Error on setSynchronizedFolder for config: " + thConfig); + logger.error("Using itemId: " + itemId, e); throw new Exception("Error on setSynchronizedFolder"); } return null; } - - - /* (non-Javadoc) - * @see org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#doSynchronization(java.lang.String) + /* + * (non-Javadoc) + * + * @see org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository# + * doSynchronization(java.lang.String) */ /** * Do sync. @@ -196,7 +198,7 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized ProcessDescriptor descriptor = engine.doSync(itemId); ThSyncStatus synStatus = mapCallBack.get(itemId); - if(synStatus==null) { + if (synStatus == null) { registerCallbackForId(itemId); descriptor = engine.getProcessDescriptorByFolderId(itemId); @@ -204,25 +206,31 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized updateMapCallback(itemId, status, descriptor); } - logger.debug("DoSync returning status: "+synStatus); + logger.debug("DoSync returning status: " + synStatus); return synStatus; } catch (WorkspaceInteractionException | InternalException | ProcessNotFoundException e) { - logger.error("Error: ",e); + logger.error("Error: ", e); - if(e instanceof WorkspaceInteractionException) - throw new Exception("Sorry, an error occurred during syncronization due to WS interection for the itemId: "+itemId); - else if(e instanceof InternalException) - throw new Exception("Sorry, an Internal Exception occurred during syncronization for the itemId: "+itemId); + if (e instanceof WorkspaceInteractionException) + throw new Exception( + "Sorry, an error occurred during syncronization due to WS interection for the itemId: " + + itemId); + else if (e instanceof InternalException) + throw new Exception( + "Sorry, an Internal Exception occurred during syncronization for the itemId: " + itemId); - throw new Exception("Sorry, an error occurred server side during syncronization for the itemId: "+itemId); + throw new Exception( + "Sorry, an error occurred server side during syncronization for the itemId: " + itemId); } } - - /* (non-Javadoc) - * @see org.gcube.portal.wssynclibrary.DoSyncItem#getSyncStatus(java.lang.String) + /* + * (non-Javadoc) + * + * @see + * org.gcube.portal.wssynclibrary.DoSyncItem#getSyncStatus(java.lang.String) */ /** * Monitor sync status. @@ -230,7 +238,7 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized * @param itemId the item id * @return the th sync status * @throws ItemNotSynched the item not synched - * @throws Exception the exception + * @throws Exception the exception */ @Override public ThSyncStatus monitorSyncStatus(String itemId) throws ItemNotSynched, Exception { @@ -238,8 +246,8 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized try { ThSyncStatus synStatus = mapCallBack.get(itemId); - if(synStatus==null) { - try{ + if (synStatus == null) { + try { registerCallbackForId(itemId); ProcessDescriptor descriptor = engine.getProcessDescriptorByFolderId(itemId); @@ -247,84 +255,95 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized updateMapCallback(itemId, status, descriptor); ThSyncStatus thSyncStatus = mapCallBack.get(itemId); - if(thSyncStatus==null) - throw new Exception("No sync status found for item id: "+itemId); + if (thSyncStatus == null) + throw new Exception("No sync status found for item id: " + itemId); return thSyncStatus; - }catch(ProcessNotFoundException e){ - throw new Exception("Monitor is not available here. The sync process is in progress on another machine"); + } catch (ProcessNotFoundException e) { + throw new Exception( + "Monitor is not available here. The sync process is in progress on another machine"); } } - if(synStatus.getProcessStatus()!=null) { - if(synStatus.getProcessStatus().getStatus()!=null) { - if(synStatus.getProcessStatus().getStatus().equals(Status.COMPLETED)) { - //TODO NOW? + if (synStatus.getProcessStatus() != null) { + if (synStatus.getProcessStatus().getStatus() != null) { + if (synStatus.getProcessStatus().getStatus().equals(Status.COMPLETED)) { + // TODO NOW? mapCallBack.put(itemId, null); } } } - logger.trace("MonitorSyncStatus for item: "+itemId+" returning: "+synStatus); + logger.trace("MonitorSyncStatus for item: " + itemId + " returning: " + synStatus); return synStatus; } catch (Exception e) { - throw new Exception("Sorry, an error occurred during getting sync status for itemId: "+itemId, e); + throw new Exception("Sorry, an error occurred during getting sync status for itemId: " + itemId, e); } } - - /* (non-Javadoc) - * @see org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#removeSync(java.lang.String) + /* + * (non-Javadoc) + * + * @see + * org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#removeSync( + * java.lang.String) */ /** * Removes the sync. * * @param itemId the item id * @return the boolean + * @throws Exception the exception */ @Override - public Boolean removeSync(String itemId) { - return null; - // TODO Auto-generated method stub - + public Boolean removeSync(String itemId) throws Exception { + throw new Exception("removeSync not implemented"); } - - /* (non-Javadoc) - * @see org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#stopSync(java.lang.String) + /* + * (non-Javadoc) + * + * @see + * org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#stopSync(java. + * lang.String) */ /** * Stop sync. * * @param itemId the item id * @return the boolean + * @throws Exception the exception */ @Override - public Boolean stopSync(String itemId) { - return false; - + public Boolean stopSync(String itemId) throws Exception { + throw new Exception("stopSync not implemented"); } - - /* (non-Javadoc) - * @see org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#initRepository() + /* + * (non-Javadoc) + * + * @see + * org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#initRepository + * () */ /** * Inits the repository. * * @return the boolean + * @throws Exception the exception */ @Override - public Boolean initRepository() { - return false; - + public Boolean initRepository() throws Exception { + throw new Exception("initRepository not implemented"); } - - /* (non-Javadoc) - * @see org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#shutDownRepository() + /* + * (non-Javadoc) + * + * @see org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository# + * shutDownRepository() */ /** * Shut down repository. @@ -336,15 +355,18 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized try { engine.shutDown(); return true; - }catch (Exception e) { + } catch (Exception e) { return null; } } - - /* (non-Javadoc) - * @see org.gcube.portal.wssynclibrary.thredds.WorkspaceThreddsSynchronizedRepository#decribeSyncRepository() + /* + * (non-Javadoc) + * + * @see + * org.gcube.portal.wssynclibrary.thredds.WorkspaceThreddsSynchronizedRepository + * #decribeSyncRepository() */ /** * Decribe sync repository. @@ -356,51 +378,51 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized return "Sync repository for Thredds"; } - /** * Gets the synched status from item property. * - * @param itemId the item id + * @param itemId the item id * @param username the username * @return the synched status from item property * @throws ItemNotSynched the item not synched - * @throws Exception the exception + * @throws Exception the exception */ - public Sync_Status getSynchedStatusFromItemProperty(String itemId, String username) throws ItemNotSynched, Exception{ + public Sync_Status getSynchedStatusFromItemProperty(String itemId, String username) + throws ItemNotSynched, Exception { - if(itemId==null) + if (itemId == null) throw new Exception("Invalid parameter itemId is null"); String scope = ScopeProvider.instance.get(); - if(scope == null || scope.isEmpty()) + if (scope == null || scope.isEmpty()) throw new Exception("You must set a valid scope into ScopeProvider instance"); String wsSyncStatus = null; - try{ + try { Map map = storageHubInstance.open(itemId).asItem().get().getMetadata().getMap(); wsSyncStatus = (String) map.get(WS_SYNCH_SYNCH_STATUS); - logger.debug("Item id: "+itemId+" read from Shub has current: "+WS_SYNCH_SYNCH_STATUS +" value at: "+wsSyncStatus); - if(wsSyncStatus==null) + logger.debug("Item id: " + itemId + " read from Shub has current: " + WS_SYNCH_SYNCH_STATUS + " value at: " + + wsSyncStatus); + if (wsSyncStatus == null) return null; return Sync_Status.valueOf(wsSyncStatus); - }catch (Exception e) { - logger.warn(wsSyncStatus + " is not value of "+Sync_Status.values()+", returning null"); + } catch (Exception e) { + logger.warn(wsSyncStatus + " is not value of " + Sync_Status.values() + ", returning null"); return null; } } - /** * Register callback for id. * * @param itemId the item id * @throws ProcessNotFoundException the process not found exception - * @throws Exception the exception + * @throws Exception the exception */ @Override - public void registerCallbackForId(String itemId) throws ProcessNotFoundException, Exception{ + public void registerCallbackForId(String itemId) throws ProcessNotFoundException, Exception { try { @@ -408,86 +430,78 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized @Override public void onStep(ProcessStatus status, ProcessDescriptor descriptor) { - logger.debug("ON STEP : "+status+" "+descriptor); - logger.debug("LOG : \n"+ status.getLogBuilder().toString()); - if(status.getStatus().equals(ProcessStatus.Status.COMPLETED)) { - //mapCallBack.remove(itemId); + logger.debug("ON STEP : " + status + " " + descriptor); + logger.debug("LOG : \n" + status.getLogBuilder().toString()); + if (status.getStatus().equals(ProcessStatus.Status.COMPLETED)) { + // mapCallBack.remove(itemId); } updateMapCallback(itemId, status, descriptor); } }; // REGISTER CALLBACK TO MONITOR PROGRESS - logger.debug("Registering callback on itemId: "+itemId); + logger.debug("Registering callback on itemId: " + itemId); engine.registerCallBack(itemId, callback); - }catch (ProcessNotFoundException e) { - logger.error("Register callback for id: "+itemId+" threw ProcessNotFoundException: ", e); + } catch (ProcessNotFoundException e) { + logger.error("Register callback for id: " + itemId + " threw ProcessNotFoundException: ", e); throw e; - }catch (Exception e) { - logger.error("Register callback exception: ",e); - throw new Exception("An error occurred on registering callback for: "+itemId, e); + } catch (Exception e) { + logger.error("Register callback exception: ", e); + throw new Exception("An error occurred on registering callback for: " + itemId, e); } } - /** * Update map callback. * - * @param itemId the item id - * @param status the status + * @param itemId the item id + * @param status the status * @param descriptor the descriptor */ private void updateMapCallback(String itemId, ProcessStatus status, ProcessDescriptor descriptor) { ThProcessDescriptor thDesc = ThreddsConverter.toThProcessDescriptor.apply(descriptor); ThProcessStatus thStatus = ThreddsConverter.toThProcessStatus.apply(status); mapCallBack.put(itemId, new ThSyncStatus(thDesc, thStatus)); - logger.debug("Update map for "+itemId +" with new "+thStatus); + logger.debug("Update map for " + itemId + " with new " + thStatus); } - - /** - * Gets the available catalogues by token. - * - * @param token the token - * @return the available catalogues by token + * Gets the available catalogues. you need to set the context caller. + * + * @return the available catalogues * @throws Exception the exception */ - public List getAvailableCataloguesByToken(String token) throws Exception{ + public List getAvailableCatalogues() throws Exception { + logger.debug("called Get Available Catalogues"); + Set ctlgs = engine.getAvailableCatalogs(); - if(token==null || token.isEmpty()) - throw new Exception("Invalid parameter token null or empty"); - - String printToken = token.substring(0, token.length()-5)+"XXXXX"; - logger.debug("Get Available Catalogues by token: "+printToken); - Set ctlgs = engine.getAvailableCatalogsByToken(token); - - if(ctlgs==null || ctlgs.size()==0){ - logger.debug("No Catalogue available for token: "+printToken +" returning empty list"); + if (ctlgs == null || ctlgs.size() == 0) { + logger.info("No Catalogue available in the current context, returning empty list"); return new ArrayList(1); } List listCtlgs = new ArrayList(ctlgs.size()); - for(CatalogBean bean: ctlgs){ - System.out.println(bean.getName()+" in "+bean.getPath()+" Default : "+bean.getIsDefault()); - ThCatalogueBean toBean = ThreddsConverter.toThCatalogueBean.apply(bean); - if(toBean!=null) - listCtlgs.add(toBean); + for (CatalogBean bean : ctlgs) { + logger.debug(bean.getName() + " in " + bean.getPath() + " Default : " + bean.getIsDefault()); + ThCatalogueBean toBean = ThreddsConverter.toThCatalogueBean.apply(bean); + if (toBean != null) + listCtlgs.add(toBean); } Collections.sort(listCtlgs); - logger.debug("Returning sorted Catalogue list with: "+listCtlgs.size() +" item/s"); + logger.info("Returning sorted Catalogue list with: " + listCtlgs.size() + " item/s"); return listCtlgs; } - - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.gcube.portal.wssynclibrary.DoSyncItem#doUnSync(java.lang.String) */ /** * Do un sync. * - * @param itemId the item id + * @param itemId the item id * @param deleteRemoteContent the delete remote content * @return the boolean * @throws Exception the exception @@ -495,15 +509,15 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized @Override public Boolean doUnSync(String itemId, boolean deleteRemoteContent) throws Exception { - if(itemId==null) + if (itemId == null) throw new Exception("Invalid parameter: itemId is null"); - try{ + try { engine.unsetSynchronizedFolder(itemId, deleteRemoteContent); return true; - }catch(Exception e){ - logger.error("Unset Syncronized folder exception: ",e); - throw new Exception("An error occurred on deleting configuration to the item id: "+itemId, e); + } catch (Exception e) { + logger.error("Unset Syncronized folder exception: ", e); + throw new Exception("An error occurred on deleting configuration to the item id: " + itemId, e); } } } diff --git a/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronizedRepository.java b/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronizedRepository.java index e18371d..25a9c3b 100644 --- a/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronizedRepository.java +++ b/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronizedRepository.java @@ -4,8 +4,6 @@ import org.gcube.portal.wssynclibrary.DoCheckSyncItem; import org.gcube.portal.wssynclibrary.DoConnectRepository; import org.gcube.portal.wssynclibrary.DoSyncItem; - -// TODO: Auto-generated Javadoc /** * The Interface WorkspaceThreddsSynchronizedRepository. * From 3816d9f04b6aeb5259a3057e2f6220bf8ad45564 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Mon, 10 May 2021 10:12:46 +0200 Subject: [PATCH 02/15] integrated with methods https://support.d4science.org/issues/21346#note-4 --- .../portal/wssynclibrary/DoCheckSyncItem.java | 14 +++++++++++++ .../thredds/ThSyncFolderDescriptor.java | 4 ---- .../thredds/WorkspaceThreddsSynchronize.java | 20 +++++++++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/gcube/portal/wssynclibrary/DoCheckSyncItem.java b/src/main/java/org/gcube/portal/wssynclibrary/DoCheckSyncItem.java index 6b4ee83..8b56022 100644 --- a/src/main/java/org/gcube/portal/wssynclibrary/DoCheckSyncItem.java +++ b/src/main/java/org/gcube/portal/wssynclibrary/DoCheckSyncItem.java @@ -4,6 +4,8 @@ package org.gcube.portal.wssynclibrary; import org.gcube.portal.wssynclibrary.shared.ItemNotSynched; +import org.gcube.usecases.ws.thredds.faults.WorkspaceInteractionException; +import org.gcube.usecases.ws.thredds.faults.WorkspaceNotSynchedException; // TODO: Auto-generated Javadoc /** @@ -25,5 +27,17 @@ public interface DoCheckSyncItem { * @throws Exception the exception */ T checkItemSynched(String itemId) throws ItemNotSynched, Exception; + + + /** + * Gets the configuration. + * + * @param itemId the item id + * @return the configuration + * @throws WorkspaceInteractionException the workspace interaction exception + * @throws WorkspaceNotSynchedException the workspace not synched exception + * @throws Exception + */ + T getConfiguration(String itemId) throws WorkspaceInteractionException, WorkspaceNotSynchedException, Exception; } diff --git a/src/main/java/org/gcube/portal/wssynclibrary/shared/thredds/ThSyncFolderDescriptor.java b/src/main/java/org/gcube/portal/wssynclibrary/shared/thredds/ThSyncFolderDescriptor.java index 883c6c7..cc18132 100644 --- a/src/main/java/org/gcube/portal/wssynclibrary/shared/thredds/ThSyncFolderDescriptor.java +++ b/src/main/java/org/gcube/portal/wssynclibrary/shared/thredds/ThSyncFolderDescriptor.java @@ -2,10 +2,6 @@ package org.gcube.portal.wssynclibrary.shared.thredds; import java.io.Serializable; - - -// TODO: Auto-generated Javadoc - /** * The Class ThSyncFolderDescriptor. * diff --git a/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java b/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java index 9f688a1..14aa93a 100644 --- a/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java +++ b/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java @@ -520,4 +520,24 @@ public class WorkspaceThreddsSynchronize throw new Exception("An error occurred on deleting configuration to the item id: " + itemId, e); } } + + @Override + public ThSyncFolderDescriptor getConfiguration(String itemId) + throws WorkspaceInteractionException, WorkspaceNotSynchedException, Exception { + + if (itemId == null) + throw new Exception("Invalid parameter: itemId is null"); + + try { + SynchFolderConfiguration syncFolderConfig = engine.getConfig(itemId); + ThSynchFolderConfiguration toFolderConfig = ThreddsConverter.toThSynchFolderConfiguration + .apply(syncFolderConfig); + + return new ThSyncFolderDescriptor(itemId, null, toFolderConfig, false, null); + + } catch (Exception e) { + logger.error("GetConfig error on folder: "+itemId, e); + throw new Exception("An error occurred on getting (sync) configuration for the item id: " + itemId, e); + } + } } From 41715b376997007821ca3e4d535043abcbf88166 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 11 May 2021 12:04:27 +0200 Subject: [PATCH 03/15] added getInfo method from SyncEngine --- pom.xml | 6 +- .../thredds/ThreddsConverter.java | 21 ++++ .../thredds/WorkspaceThreddsSynchronize.java | 102 ++++++------------ 3 files changed, 60 insertions(+), 69 deletions(-) diff --git a/pom.xml b/pom.xml index c5bc464..2e7555e 100644 --- a/pom.xml +++ b/pom.xml @@ -87,11 +87,13 @@ org.slf4j - slf4j-log4j12 + slf4j-api + provided org.slf4j - slf4j-api + slf4j-log4j12 + provided diff --git a/src/main/java/org/gcube/portal/wssynclibrary/thredds/ThreddsConverter.java b/src/main/java/org/gcube/portal/wssynclibrary/thredds/ThreddsConverter.java index c7dbcf1..f841b11 100644 --- a/src/main/java/org/gcube/portal/wssynclibrary/thredds/ThreddsConverter.java +++ b/src/main/java/org/gcube/portal/wssynclibrary/thredds/ThreddsConverter.java @@ -3,6 +3,7 @@ package org.gcube.portal.wssynclibrary.thredds; import java.util.function.Function; import org.gcube.portal.wssynclibrary.shared.thredds.Status; +import org.gcube.portal.wssynclibrary.shared.thredds.Sync_Status; import org.gcube.portal.wssynclibrary.shared.thredds.ThCatalogueBean; import org.gcube.portal.wssynclibrary.shared.thredds.ThProcessDescriptor; import org.gcube.portal.wssynclibrary.shared.thredds.ThProcessStatus; @@ -12,6 +13,7 @@ import org.gcube.usecases.ws.thredds.engine.impl.ProcessDescriptor; import org.gcube.usecases.ws.thredds.engine.impl.ProcessStatus; import org.gcube.usecases.ws.thredds.model.SyncFolderDescriptor; import org.gcube.usecases.ws.thredds.model.SynchFolderConfiguration; +import org.gcube.usecases.ws.thredds.model.SynchronizedElementInfo; import org.gcube.usecases.ws.thredds.model.gui.CatalogBean; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -92,6 +94,7 @@ public class ThreddsConverter { + ThSynchFolderConfiguration.class.getSimpleName()); return mySync; } + mySync.setFilter(t.getFilter()); mySync.setRemotePath(t.getRemotePath()); mySync.setRemotePersistence(t.getRemotePersistence()); @@ -185,5 +188,23 @@ public class ThreddsConverter { return mySync; } }; + + + public static Function toSyncStatus = new Function() { + + public Sync_Status apply(SynchronizedElementInfo sei) { + + if (sei == null) { + logger.info("Input " + SynchronizedElementInfo.class.getSimpleName() + " is null, returning null " + + Sync_Status.class.getSimpleName()); + return null; + } + + logger.warn("toSyncStatus not implemented yet!!!!!!"); + + return null; + } + }; + } diff --git a/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java b/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java index 14aa93a..78899ab 100644 --- a/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java +++ b/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java @@ -7,7 +7,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.storagehub.client.dsl.StorageHubClient; import org.gcube.portal.wssynclibrary.shared.ItemNotSynched; import org.gcube.portal.wssynclibrary.shared.WorkspaceFolderLocked; @@ -30,10 +29,12 @@ import org.gcube.usecases.ws.thredds.faults.WorkspaceNotSynchedException; import org.gcube.usecases.ws.thredds.model.SyncFolderDescriptor; import org.gcube.usecases.ws.thredds.model.SyncOperationCallBack; import org.gcube.usecases.ws.thredds.model.SynchFolderConfiguration; +import org.gcube.usecases.ws.thredds.model.SynchronizedElementInfo; import org.gcube.usecases.ws.thredds.model.gui.CatalogBean; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +// TODO: Auto-generated Javadoc /** * The Class WorkspaceThreddsSynchronize. * @@ -53,8 +54,6 @@ public class WorkspaceThreddsSynchronize private static StorageHubClient storageHubInstance; - public static final String WS_SYNCH_SYNCH_STATUS = "WS-SYNCH.SYNCH-STATUS"; - /** The map call back. */ // Fully synchronized HashMap private Map mapCallBack = Collections.synchronizedMap(new HashMap<>()); @@ -94,12 +93,6 @@ public class WorkspaceThreddsSynchronize } - /* - * (non-Javadoc) - * - * @see org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository# - * isItemSynchronized(java.lang.String) - */ /** * Check item synched. * @@ -148,12 +141,11 @@ public class WorkspaceThreddsSynchronize } } - /** * Sets the synchronized folder. * * @param thConfig the th config - * @param itemId the item id + * @param itemId the item id * @return the th sync folder descriptor * @throws Exception the exception */ @@ -177,12 +169,6 @@ public class WorkspaceThreddsSynchronize return null; } - /* - * (non-Javadoc) - * - * @see org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository# - * doSynchronization(java.lang.String) - */ /** * Do sync. * @@ -226,12 +212,6 @@ public class WorkspaceThreddsSynchronize } - /* - * (non-Javadoc) - * - * @see - * org.gcube.portal.wssynclibrary.DoSyncItem#getSyncStatus(java.lang.String) - */ /** * Monitor sync status. * @@ -378,42 +358,6 @@ public class WorkspaceThreddsSynchronize return "Sync repository for Thredds"; } - /** - * Gets the synched status from item property. - * - * @param itemId the item id - * @param username the username - * @return the synched status from item property - * @throws ItemNotSynched the item not synched - * @throws Exception the exception - */ - public Sync_Status getSynchedStatusFromItemProperty(String itemId, String username) - throws ItemNotSynched, Exception { - - if (itemId == null) - throw new Exception("Invalid parameter itemId is null"); - - String scope = ScopeProvider.instance.get(); - if (scope == null || scope.isEmpty()) - throw new Exception("You must set a valid scope into ScopeProvider instance"); - - String wsSyncStatus = null; - try { - - Map map = storageHubInstance.open(itemId).asItem().get().getMetadata().getMap(); - wsSyncStatus = (String) map.get(WS_SYNCH_SYNCH_STATUS); - logger.debug("Item id: " + itemId + " read from Shub has current: " + WS_SYNCH_SYNCH_STATUS + " value at: " - + wsSyncStatus); - if (wsSyncStatus == null) - return null; - - return Sync_Status.valueOf(wsSyncStatus); - } catch (Exception e) { - logger.warn(wsSyncStatus + " is not value of " + Sync_Status.values() + ", returning null"); - return null; - } - } - /** * Register callback for id. * @@ -440,7 +384,7 @@ public class WorkspaceThreddsSynchronize }; // REGISTER CALLBACK TO MONITOR PROGRESS - logger.debug("Registering callback on itemId: " + itemId); + logger.debug("Registering callback for itemId: " + itemId); engine.registerCallBack(itemId, callback); } catch (ProcessNotFoundException e) { logger.error("Register callback for id: " + itemId + " threw ProcessNotFoundException: ", e); @@ -493,15 +437,11 @@ public class WorkspaceThreddsSynchronize return listCtlgs; } - /* - * (non-Javadoc) - * - * @see org.gcube.portal.wssynclibrary.DoSyncItem#doUnSync(java.lang.String) - */ + /** * Do un sync. * - * @param itemId the item id + * @param itemId the item id * @param deleteRemoteContent the delete remote content * @return the boolean * @throws Exception the exception @@ -521,6 +461,15 @@ public class WorkspaceThreddsSynchronize } } + /** + * Gets the configuration. + * + * @param itemId the item id + * @return the configuration + * @throws WorkspaceInteractionException the workspace interaction exception + * @throws WorkspaceNotSynchedException the workspace not synched exception + * @throws Exception the exception + */ @Override public ThSyncFolderDescriptor getConfiguration(String itemId) throws WorkspaceInteractionException, WorkspaceNotSynchedException, Exception { @@ -536,8 +485,27 @@ public class WorkspaceThreddsSynchronize return new ThSyncFolderDescriptor(itemId, null, toFolderConfig, false, null); } catch (Exception e) { - logger.error("GetConfig error on folder: "+itemId, e); + logger.error("GetConfig error on folder: " + itemId, e); throw new Exception("An error occurred on getting (sync) configuration for the item id: " + itemId, e); } } + + + /** + * Gets the info. + * + * @param itemId the item id + * @return the info + * @throws Exception the exception + */ + public Sync_Status getInfo(String itemId) throws Exception { + + if (itemId == null) + throw new Exception("Invalid parameter: itemId is null"); + + SynchronizedElementInfo infoStatus = engine.getInfo(itemId); + Sync_Status infoSyncStatus = ThreddsConverter.toSyncStatus.apply(infoStatus); + + return infoSyncStatus; + } } From ae835cee168b8ab8b04a34414046469b0019ea93 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 11 May 2021 12:55:07 +0200 Subject: [PATCH 04/15] removed unused dependencies --- pom.xml | 31 ------------------------------- 1 file changed, 31 deletions(-) diff --git a/pom.xml b/pom.xml index 2e7555e..e67bed0 100644 --- a/pom.xml +++ b/pom.xml @@ -53,37 +53,6 @@ compile - - commons-lang - commons-lang - provided - - - - org.gcube.core - common-encryption - provided - - - - org.gcube.resources.discovery - ic-client - provided - - - org.gcube.core - common-scope-maps - compile - - - - - org.gcube.common - storagehub-client-library - [1.0.0-SNAPSHOT,2.0.0-SNAPSHOT) - compile - - org.slf4j From db1e0729a3344f0e98b3b56b9d6a196fe55df413 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Wed, 12 May 2021 15:08:01 +0200 Subject: [PATCH 05/15] updated the getConfiguration method --- .../thredds/WorkspaceThreddsSynchronize.java | 313 ++++++++---------- 1 file changed, 144 insertions(+), 169 deletions(-) diff --git a/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java b/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java index 78899ab..b630c76 100644 --- a/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java +++ b/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java @@ -7,7 +7,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.gcube.common.storagehub.client.dsl.StorageHubClient; import org.gcube.portal.wssynclibrary.shared.ItemNotSynched; import org.gcube.portal.wssynclibrary.shared.WorkspaceFolderLocked; import org.gcube.portal.wssynclibrary.shared.thredds.Status; @@ -34,7 +33,6 @@ import org.gcube.usecases.ws.thredds.model.gui.CatalogBean; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -// TODO: Auto-generated Javadoc /** * The Class WorkspaceThreddsSynchronize. * @@ -52,8 +50,6 @@ public class WorkspaceThreddsSynchronize /** The instance. */ private static WorkspaceThreddsSynchronize instance = null; - private static StorageHubClient storageHubInstance; - /** The map call back. */ // Fully synchronized HashMap private Map mapCallBack = Collections.synchronizedMap(new HashMap<>()); @@ -74,25 +70,10 @@ public class WorkspaceThreddsSynchronize public static WorkspaceThreddsSynchronize getInstance() { if (instance == null) { instance = new WorkspaceThreddsSynchronize(); - storageHubInstance = new StorageHubClient(); } return instance; } - /** - * Gets the storage hub instance. - * - * @return the storage hub instance - */ - public static StorageHubClient getStorageHubInstance() { - - if (storageHubInstance == null) - storageHubInstance = new StorageHubClient(); - - return storageHubInstance; - - } - /** * Check item synched. * @@ -263,6 +244,150 @@ public class WorkspaceThreddsSynchronize } } + /** + * Register callback for id. + * + * @param itemId the item id + * @throws ProcessNotFoundException the process not found exception + * @throws Exception the exception + */ + @Override + public void registerCallbackForId(String itemId) throws ProcessNotFoundException, Exception { + + try { + + SyncOperationCallBack callback = new SyncOperationCallBack() { + + @Override + public void onStep(ProcessStatus status, ProcessDescriptor descriptor) { + logger.debug("ON STEP : " + status + " " + descriptor); + logger.debug("LOG : \n" + status.getLogBuilder().toString()); + if (status.getStatus().equals(ProcessStatus.Status.COMPLETED)) { + // mapCallBack.remove(itemId); + } + updateMapCallback(itemId, status, descriptor); + } + }; + + // REGISTER CALLBACK TO MONITOR PROGRESS + logger.debug("Registering callback for itemId: " + itemId); + engine.registerCallBack(itemId, callback); + } catch (ProcessNotFoundException e) { + logger.error("Register callback for id: " + itemId + " threw ProcessNotFoundException: ", e); + throw e; + } catch (Exception e) { + logger.error("Register callback exception: ", e); + throw new Exception("An error occurred on registering callback for: " + itemId, e); + } + } + + /** + * Update map callback. + * + * @param itemId the item id + * @param status the status + * @param descriptor the descriptor + */ + private void updateMapCallback(String itemId, ProcessStatus status, ProcessDescriptor descriptor) { + ThProcessDescriptor thDesc = ThreddsConverter.toThProcessDescriptor.apply(descriptor); + ThProcessStatus thStatus = ThreddsConverter.toThProcessStatus.apply(status); + mapCallBack.put(itemId, new ThSyncStatus(thDesc, thStatus)); + logger.debug("Update map for " + itemId + " with new " + thStatus); + } + + /** + * Gets the available catalogues. you need to set the context caller. + * + * @return the available catalogues + * @throws Exception the exception + */ + public List getAvailableCatalogues() throws Exception { + logger.debug("called Get Available Catalogues"); + Set ctlgs = engine.getAvailableCatalogs(); + + if (ctlgs == null || ctlgs.size() == 0) { + logger.info("No Catalogue available in the current context, returning empty list"); + return new ArrayList(1); + } + + List listCtlgs = new ArrayList(ctlgs.size()); + for (CatalogBean bean : ctlgs) { + logger.debug(bean.getName() + " in " + bean.getPath() + " Default : " + bean.getIsDefault()); + ThCatalogueBean toBean = ThreddsConverter.toThCatalogueBean.apply(bean); + if (toBean != null) + listCtlgs.add(toBean); + } + + Collections.sort(listCtlgs); + logger.info("Returning sorted Catalogue list with: " + listCtlgs.size() + " item/s"); + return listCtlgs; + } + + /** + * Do un sync. + * + * @param itemId the item id + * @param deleteRemoteContent the delete remote content + * @return the boolean + * @throws Exception the exception + */ + @Override + public Boolean doUnSync(String itemId, boolean deleteRemoteContent) throws Exception { + + if (itemId == null) + throw new Exception("Invalid parameter: itemId is null"); + + try { + engine.unsetSynchronizedFolder(itemId, deleteRemoteContent); + return true; + } catch (Exception e) { + logger.error("Unset Syncronized folder exception: ", e); + throw new Exception("An error occurred on deleting configuration to the item id: " + itemId, e); + } + } + + /** + * Gets the configuration. + * + * @param itemId the item id + * @return the configuration + * @throws WorkspaceInteractionException the workspace interaction exception + * @throws WorkspaceNotSynchedException the workspace not synched exception + * @throws Exception the exception + */ + @Override + public ThSyncFolderDescriptor getConfiguration(String itemId) + throws WorkspaceInteractionException, WorkspaceNotSynchedException, Exception { + + if (itemId == null) + throw new Exception("Invalid parameter: itemId is null"); + + SynchFolderConfiguration syncFolderConfig = engine.getConfig(itemId); + ThSynchFolderConfiguration toFolderConfig = ThreddsConverter.toThSynchFolderConfiguration + .apply(syncFolderConfig); + + return new ThSyncFolderDescriptor(itemId, null, toFolderConfig, false, null); + + } + + /** + * Gets the info. + * + * @param itemId the item id + * @return the info + * @throws Exception the exception + */ + public Sync_Status getInfo(String itemId) throws Exception { + + if (itemId == null) + throw new Exception("Invalid parameter: itemId is null"); + + SynchronizedElementInfo infoStatus = engine.getInfo(itemId); + Sync_Status infoSyncStatus = ThreddsConverter.toSyncStatus.apply(infoStatus); + + return infoSyncStatus; + } + /* * (non-Javadoc) * @@ -358,154 +483,4 @@ public class WorkspaceThreddsSynchronize return "Sync repository for Thredds"; } - /** - * Register callback for id. - * - * @param itemId the item id - * @throws ProcessNotFoundException the process not found exception - * @throws Exception the exception - */ - @Override - public void registerCallbackForId(String itemId) throws ProcessNotFoundException, Exception { - - try { - - SyncOperationCallBack callback = new SyncOperationCallBack() { - - @Override - public void onStep(ProcessStatus status, ProcessDescriptor descriptor) { - logger.debug("ON STEP : " + status + " " + descriptor); - logger.debug("LOG : \n" + status.getLogBuilder().toString()); - if (status.getStatus().equals(ProcessStatus.Status.COMPLETED)) { - // mapCallBack.remove(itemId); - } - updateMapCallback(itemId, status, descriptor); - } - }; - - // REGISTER CALLBACK TO MONITOR PROGRESS - logger.debug("Registering callback for itemId: " + itemId); - engine.registerCallBack(itemId, callback); - } catch (ProcessNotFoundException e) { - logger.error("Register callback for id: " + itemId + " threw ProcessNotFoundException: ", e); - throw e; - } catch (Exception e) { - logger.error("Register callback exception: ", e); - throw new Exception("An error occurred on registering callback for: " + itemId, e); - } - } - - /** - * Update map callback. - * - * @param itemId the item id - * @param status the status - * @param descriptor the descriptor - */ - private void updateMapCallback(String itemId, ProcessStatus status, ProcessDescriptor descriptor) { - ThProcessDescriptor thDesc = ThreddsConverter.toThProcessDescriptor.apply(descriptor); - ThProcessStatus thStatus = ThreddsConverter.toThProcessStatus.apply(status); - mapCallBack.put(itemId, new ThSyncStatus(thDesc, thStatus)); - logger.debug("Update map for " + itemId + " with new " + thStatus); - } - - /** - * Gets the available catalogues. you need to set the context caller. - * - * @return the available catalogues - * @throws Exception the exception - */ - public List getAvailableCatalogues() throws Exception { - logger.debug("called Get Available Catalogues"); - Set ctlgs = engine.getAvailableCatalogs(); - - if (ctlgs == null || ctlgs.size() == 0) { - logger.info("No Catalogue available in the current context, returning empty list"); - return new ArrayList(1); - } - - List listCtlgs = new ArrayList(ctlgs.size()); - for (CatalogBean bean : ctlgs) { - logger.debug(bean.getName() + " in " + bean.getPath() + " Default : " + bean.getIsDefault()); - ThCatalogueBean toBean = ThreddsConverter.toThCatalogueBean.apply(bean); - if (toBean != null) - listCtlgs.add(toBean); - } - - Collections.sort(listCtlgs); - logger.info("Returning sorted Catalogue list with: " + listCtlgs.size() + " item/s"); - return listCtlgs; - } - - - /** - * Do un sync. - * - * @param itemId the item id - * @param deleteRemoteContent the delete remote content - * @return the boolean - * @throws Exception the exception - */ - @Override - public Boolean doUnSync(String itemId, boolean deleteRemoteContent) throws Exception { - - if (itemId == null) - throw new Exception("Invalid parameter: itemId is null"); - - try { - engine.unsetSynchronizedFolder(itemId, deleteRemoteContent); - return true; - } catch (Exception e) { - logger.error("Unset Syncronized folder exception: ", e); - throw new Exception("An error occurred on deleting configuration to the item id: " + itemId, e); - } - } - - /** - * Gets the configuration. - * - * @param itemId the item id - * @return the configuration - * @throws WorkspaceInteractionException the workspace interaction exception - * @throws WorkspaceNotSynchedException the workspace not synched exception - * @throws Exception the exception - */ - @Override - public ThSyncFolderDescriptor getConfiguration(String itemId) - throws WorkspaceInteractionException, WorkspaceNotSynchedException, Exception { - - if (itemId == null) - throw new Exception("Invalid parameter: itemId is null"); - - try { - SynchFolderConfiguration syncFolderConfig = engine.getConfig(itemId); - ThSynchFolderConfiguration toFolderConfig = ThreddsConverter.toThSynchFolderConfiguration - .apply(syncFolderConfig); - - return new ThSyncFolderDescriptor(itemId, null, toFolderConfig, false, null); - - } catch (Exception e) { - logger.error("GetConfig error on folder: " + itemId, e); - throw new Exception("An error occurred on getting (sync) configuration for the item id: " + itemId, e); - } - } - - - /** - * Gets the info. - * - * @param itemId the item id - * @return the info - * @throws Exception the exception - */ - public Sync_Status getInfo(String itemId) throws Exception { - - if (itemId == null) - throw new Exception("Invalid parameter: itemId is null"); - - SynchronizedElementInfo infoStatus = engine.getInfo(itemId); - Sync_Status infoSyncStatus = ThreddsConverter.toSyncStatus.apply(infoStatus); - - return infoSyncStatus; - } } From cae34434faeb5ea867df090552260bfbfc4c34d9 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 13 May 2021 12:51:40 +0200 Subject: [PATCH 06/15] removed getElementInfo from WorkspaceThreddsSynchronize and moved under check method --- .../shared/thredds/ThSyncElementInfo.java | 47 ++++++++++++ .../thredds/ThSyncFolderDescriptor.java | 72 +++++++++++------- .../thredds/ThreddsConverter.java | 74 +++++++++++++++---- .../thredds/WorkspaceThreddsSynchronize.java | 22 +----- 4 files changed, 153 insertions(+), 62 deletions(-) create mode 100644 src/main/java/org/gcube/portal/wssynclibrary/shared/thredds/ThSyncElementInfo.java diff --git a/src/main/java/org/gcube/portal/wssynclibrary/shared/thredds/ThSyncElementInfo.java b/src/main/java/org/gcube/portal/wssynclibrary/shared/thredds/ThSyncElementInfo.java new file mode 100644 index 0000000..9a23297 --- /dev/null +++ b/src/main/java/org/gcube/portal/wssynclibrary/shared/thredds/ThSyncElementInfo.java @@ -0,0 +1,47 @@ +package org.gcube.portal.wssynclibrary.shared.thredds; + +import java.io.Serializable; + +/** + * The Class ThSyncElementInfo. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * May 13, 2021 + */ +public class ThSyncElementInfo implements Serializable { + + /** + * + */ + private static final long serialVersionUID = 6248465200945019743L; + + private Sync_Status syncStatus; + + public ThSyncElementInfo() { + + } + + public ThSyncElementInfo(Sync_Status syncStatus) { + super(); + this.syncStatus = syncStatus; + } + + public Sync_Status getSyncStatus() { + return syncStatus; + } + + public void setSyncStatus(Sync_Status syncStatus) { + this.syncStatus = syncStatus; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("ThSyncElementInfo [syncStatus="); + builder.append(syncStatus); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/src/main/java/org/gcube/portal/wssynclibrary/shared/thredds/ThSyncFolderDescriptor.java b/src/main/java/org/gcube/portal/wssynclibrary/shared/thredds/ThSyncFolderDescriptor.java index cc18132..e36f365 100644 --- a/src/main/java/org/gcube/portal/wssynclibrary/shared/thredds/ThSyncFolderDescriptor.java +++ b/src/main/java/org/gcube/portal/wssynclibrary/shared/thredds/ThSyncFolderDescriptor.java @@ -5,54 +5,51 @@ import java.io.Serializable; /** * The Class ThSyncFolderDescriptor. * - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Feb 8, 2018 + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * May 13, 2021 */ -public class ThSyncFolderDescriptor implements Serializable{ +public class ThSyncFolderDescriptor implements Serializable { - - /** The Constant serialVersionUID. */ private static final long serialVersionUID = 4134777763175272691L; - /** The folder id. */ private String folderId; - /** The folder path. */ private String folderPath; - /** The configuration. */ private ThSynchFolderConfiguration configuration; - /** The is locked. */ - private boolean isLocked=false; - - - /** The local process descriptor. */ - private ThProcessDescriptor localProcessDescriptor=null; - + private boolean isLocked = false; + + private ThSyncElementInfo elementInfo; + + private ThProcessDescriptor localProcessDescriptor = null; + /** * Instantiates a new s sync folder descriptor. */ public ThSyncFolderDescriptor() { - // TODO Auto-generated constructor stub + } /** - * Instantiates a new s sync folder descriptor. + * Instantiates a new th sync folder descriptor. * - * @param folderId the folder id - * @param folderPath the folder path - * @param configuration the configuration - * @param isLocked the is locked + * @param folderId the folder id + * @param folderPath the folder path + * @param configuration the configuration + * @param isLocked the is locked + * @param elementInfo the element info * @param localProcessDescriptor the local process descriptor */ public ThSyncFolderDescriptor(String folderId, String folderPath, ThSynchFolderConfiguration configuration, - boolean isLocked, ThProcessDescriptor localProcessDescriptor) { + boolean isLocked, ThSyncElementInfo elementInfo, ThProcessDescriptor localProcessDescriptor) { super(); this.folderId = folderId; this.folderPath = folderPath; this.configuration = configuration; this.isLocked = isLocked; + this.elementInfo = elementInfo; this.localProcessDescriptor = localProcessDescriptor; } @@ -146,8 +143,28 @@ public class ThSyncFolderDescriptor implements Serializable{ this.localProcessDescriptor = localProcessDescriptor; } - /* (non-Javadoc) - * @see java.lang.Object#toString() + /** + * Gets the element info. + * + * @return the element info + */ + public ThSyncElementInfo getElementInfo() { + return elementInfo; + } + + /** + * Sets the element info. + * + * @param elementInfo the new element info + */ + public void setElementInfo(ThSyncElementInfo elementInfo) { + this.elementInfo = elementInfo; + } + + /** + * To string. + * + * @return the string */ @Override public String toString() { @@ -160,13 +177,12 @@ public class ThSyncFolderDescriptor implements Serializable{ builder.append(configuration); builder.append(", isLocked="); builder.append(isLocked); + builder.append(", elementInfo="); + builder.append(elementInfo); builder.append(", localProcessDescriptor="); builder.append(localProcessDescriptor); builder.append("]"); return builder.toString(); } - - - - + } diff --git a/src/main/java/org/gcube/portal/wssynclibrary/thredds/ThreddsConverter.java b/src/main/java/org/gcube/portal/wssynclibrary/thredds/ThreddsConverter.java index f841b11..6b86c3e 100644 --- a/src/main/java/org/gcube/portal/wssynclibrary/thredds/ThreddsConverter.java +++ b/src/main/java/org/gcube/portal/wssynclibrary/thredds/ThreddsConverter.java @@ -7,6 +7,7 @@ import org.gcube.portal.wssynclibrary.shared.thredds.Sync_Status; import org.gcube.portal.wssynclibrary.shared.thredds.ThCatalogueBean; import org.gcube.portal.wssynclibrary.shared.thredds.ThProcessDescriptor; import org.gcube.portal.wssynclibrary.shared.thredds.ThProcessStatus; +import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncElementInfo; import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncFolderDescriptor; import org.gcube.portal.wssynclibrary.shared.thredds.ThSynchFolderConfiguration; import org.gcube.usecases.ws.thredds.engine.impl.ProcessDescriptor; @@ -14,6 +15,7 @@ import org.gcube.usecases.ws.thredds.engine.impl.ProcessStatus; import org.gcube.usecases.ws.thredds.model.SyncFolderDescriptor; import org.gcube.usecases.ws.thredds.model.SynchFolderConfiguration; import org.gcube.usecases.ws.thredds.model.SynchronizedElementInfo; +import org.gcube.usecases.ws.thredds.model.SynchronizedElementInfo.SynchronizationStatus; import org.gcube.usecases.ws.thredds.model.gui.CatalogBean; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -22,6 +24,7 @@ import org.slf4j.LoggerFactory; * The Class ThreddsConverter. * * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Feb 14, 2018 + * updated May 13, 2021 */ public class ThreddsConverter { @@ -42,7 +45,8 @@ public class ThreddsConverter { mySync.setFolderId(t.getFolderId()); mySync.setFolderPath(t.getFolderPath()); - mySync.setLocked(t.isLocked()); + mySync.setLocked(t.getIsLocked()); + mySync.setElementInfo(toThElementInfo.apply(t.getInfo())); ThProcessDescriptor localProcessDescriptor = toThProcessDescriptor.apply(t.getLocalProcessDescriptor()); mySync.setLocalProcessDescriptor(localProcessDescriptor); ThSynchFolderConfiguration configuration = toThSynchFolderConfiguration.apply(t.getConfiguration()); @@ -63,7 +67,8 @@ public class ThreddsConverter { } SynchFolderConfiguration configuration = toSynchFolderConfiguration.apply(t.getConfiguration()); - return new SyncFolderDescriptor(t.getFolderId(), t.getFolderPath(), configuration); + SynchronizedElementInfo sei = toSynchronizedElementInfo.apply(t.getElementInfo()); + return new SyncFolderDescriptor(t.getFolderId(), t.getFolderPath(), configuration, sei); } }; @@ -94,7 +99,7 @@ public class ThreddsConverter { + ThSynchFolderConfiguration.class.getSimpleName()); return mySync; } - + mySync.setFilter(t.getFilter()); mySync.setRemotePath(t.getRemotePath()); mySync.setRemotePersistence(t.getRemotePersistence()); @@ -188,23 +193,66 @@ public class ThreddsConverter { return mySync; } }; - - - public static Function toSyncStatus = new Function() { - public Sync_Status apply(SynchronizedElementInfo sei) { - + public static Function toThElementInfo = new Function() { + + public ThSyncElementInfo apply(SynchronizedElementInfo sei) { + if (sei == null) { logger.info("Input " + SynchronizedElementInfo.class.getSimpleName() + " is null, returning null " - + Sync_Status.class.getSimpleName()); + + ThSyncElementInfo.class.getSimpleName()); return null; } - - logger.warn("toSyncStatus not implemented yet!!!!!!"); - - return null; + + ThSyncElementInfo toReturn = new ThSyncElementInfo(); + SynchronizationStatus status = sei.getStatus(); + + if (status != null) { + switch (status) { + case UP_TO_DATE: + toReturn.setSyncStatus(Sync_Status.UP_TO_DATE); + break; + case OUTDATED_WS: + toReturn.setSyncStatus(Sync_Status.OUTDATED_WS); + break; + case OUTDATED_REMOTE: + toReturn.setSyncStatus(Sync_Status.OUTDATED_REMOTE); + default: + break; + } + } + return toReturn; } }; + public static Function toSynchronizedElementInfo = new Function() { + public SynchronizedElementInfo apply(ThSyncElementInfo sei) { + + if (sei == null) { + logger.info("Input " + ThSyncElementInfo.class.getSimpleName() + " is null, returning null " + + SynchronizedElementInfo.class.getSimpleName()); + return null; + } + + Sync_Status status = sei.getSyncStatus(); + SynchronizationStatus theStatus = null; + if (status != null) { + + switch (status) { + case UP_TO_DATE: + theStatus = SynchronizedElementInfo.SynchronizationStatus.UP_TO_DATE; + break; + case OUTDATED_WS: + theStatus = SynchronizedElementInfo.SynchronizationStatus.OUTDATED_WS; + break; + case OUTDATED_REMOTE: + theStatus = SynchronizedElementInfo.SynchronizationStatus.OUTDATED_REMOTE; + default: + break; + } + } + return new SynchronizedElementInfo(theStatus); + } + }; } diff --git a/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java b/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java index b630c76..0950e61 100644 --- a/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java +++ b/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java @@ -10,7 +10,6 @@ import java.util.Set; import org.gcube.portal.wssynclibrary.shared.ItemNotSynched; import org.gcube.portal.wssynclibrary.shared.WorkspaceFolderLocked; import org.gcube.portal.wssynclibrary.shared.thredds.Status; -import org.gcube.portal.wssynclibrary.shared.thredds.Sync_Status; import org.gcube.portal.wssynclibrary.shared.thredds.ThCatalogueBean; import org.gcube.portal.wssynclibrary.shared.thredds.ThProcessDescriptor; import org.gcube.portal.wssynclibrary.shared.thredds.ThProcessStatus; @@ -28,7 +27,6 @@ import org.gcube.usecases.ws.thredds.faults.WorkspaceNotSynchedException; import org.gcube.usecases.ws.thredds.model.SyncFolderDescriptor; import org.gcube.usecases.ws.thredds.model.SyncOperationCallBack; import org.gcube.usecases.ws.thredds.model.SynchFolderConfiguration; -import org.gcube.usecases.ws.thredds.model.SynchronizedElementInfo; import org.gcube.usecases.ws.thredds.model.gui.CatalogBean; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -366,28 +364,10 @@ public class WorkspaceThreddsSynchronize ThSynchFolderConfiguration toFolderConfig = ThreddsConverter.toThSynchFolderConfiguration .apply(syncFolderConfig); - return new ThSyncFolderDescriptor(itemId, null, toFolderConfig, false, null); + return new ThSyncFolderDescriptor(itemId, null, toFolderConfig, false, null,null); } - /** - * Gets the info. - * - * @param itemId the item id - * @return the info - * @throws Exception the exception - */ - public Sync_Status getInfo(String itemId) throws Exception { - - if (itemId == null) - throw new Exception("Invalid parameter: itemId is null"); - - SynchronizedElementInfo infoStatus = engine.getInfo(itemId); - Sync_Status infoSyncStatus = ThreddsConverter.toSyncStatus.apply(infoStatus); - - return infoSyncStatus; - } - /* * (non-Javadoc) * From 462f5787faf7c9b8f17051a9bd37b24792eb0c3d Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 13 May 2021 15:00:41 +0200 Subject: [PATCH 07/15] add gitignore --- target/.gitignore | 1 - 1 file changed, 1 deletion(-) delete mode 100644 target/.gitignore diff --git a/target/.gitignore b/target/.gitignore deleted file mode 100644 index 840e7d3..0000000 --- a/target/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/classes/ From e4614f70ef660fe7265306b74dc50de8127f21a5 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 13 May 2021 15:24:55 +0200 Subject: [PATCH 08/15] added method isItemSynched --- .../portal/wssynclibrary/DoCheckSyncItem.java | 23 ++++++++------ .../thredds/ThSynchFolderConfiguration.java | 6 +--- .../thredds/WorkspaceThreddsSynchronize.java | 30 ++++++++++++++++++- 3 files changed, 44 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/gcube/portal/wssynclibrary/DoCheckSyncItem.java b/src/main/java/org/gcube/portal/wssynclibrary/DoCheckSyncItem.java index 8b56022..b202d42 100644 --- a/src/main/java/org/gcube/portal/wssynclibrary/DoCheckSyncItem.java +++ b/src/main/java/org/gcube/portal/wssynclibrary/DoCheckSyncItem.java @@ -7,37 +7,42 @@ import org.gcube.portal.wssynclibrary.shared.ItemNotSynched; import org.gcube.usecases.ws.thredds.faults.WorkspaceInteractionException; import org.gcube.usecases.ws.thredds.faults.WorkspaceNotSynchedException; -// TODO: Auto-generated Javadoc /** * The Interface DoCheckSyncItem. * - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Feb 8, 2018 + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Feb 8, 2018 * @param the generic type */ public interface DoCheckSyncItem { - /** * Check item synched. * * @param itemId the item id * @return the t * @throws ItemNotSynched the item not synched - * @throws Exception the exception + * @throws Exception the exception */ T checkItemSynched(String itemId) throws ItemNotSynched, Exception; - - + /** * Gets the configuration. * * @param itemId the item id * @return the configuration * @throws WorkspaceInteractionException the workspace interaction exception - * @throws WorkspaceNotSynchedException the workspace not synched exception - * @throws Exception + * @throws WorkspaceNotSynchedException the workspace not synched exception + * @throws Exception the exception */ T getConfiguration(String itemId) throws WorkspaceInteractionException, WorkspaceNotSynchedException, Exception; + /** + * Checks if is item synched. + * + * @param itemId the item id + * @return true, if is item synched + * @throws Exception the exception + */ + boolean isItemSynched(String itemId) throws Exception; + } diff --git a/src/main/java/org/gcube/portal/wssynclibrary/shared/thredds/ThSynchFolderConfiguration.java b/src/main/java/org/gcube/portal/wssynclibrary/shared/thredds/ThSynchFolderConfiguration.java index ccf4d5f..71b18a6 100644 --- a/src/main/java/org/gcube/portal/wssynclibrary/shared/thredds/ThSynchFolderConfiguration.java +++ b/src/main/java/org/gcube/portal/wssynclibrary/shared/thredds/ThSynchFolderConfiguration.java @@ -2,7 +2,6 @@ package org.gcube.portal.wssynclibrary.shared.thredds; import java.io.Serializable; -// TODO: Auto-generated Javadoc /** * The Class ThSynchFolderConfiguration. * @@ -33,7 +32,7 @@ public class ThSynchFolderConfiguration implements Serializable { * Instantiates a new th synch folder configuration. */ public ThSynchFolderConfiguration() { - // TODO Auto-generated constructor stub + } /** @@ -186,7 +185,4 @@ public class ThSynchFolderConfiguration implements Serializable { return builder.toString(); } - - - } diff --git a/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java b/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java index 0950e61..9f6c488 100644 --- a/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java +++ b/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java @@ -31,6 +31,7 @@ import org.gcube.usecases.ws.thredds.model.gui.CatalogBean; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +// TODO: Auto-generated Javadoc /** * The Class WorkspaceThreddsSynchronize. * @@ -364,7 +365,34 @@ public class WorkspaceThreddsSynchronize ThSynchFolderConfiguration toFolderConfig = ThreddsConverter.toThSynchFolderConfiguration .apply(syncFolderConfig); - return new ThSyncFolderDescriptor(itemId, null, toFolderConfig, false, null,null); + return new ThSyncFolderDescriptor(itemId, null, toFolderConfig, false, null, null); + + } + + /** + * Checks if is item synched. + * + * @param itemId the item id + * @return true, if is item synched + * @throws Exception the exception + */ + @Override + public boolean isItemSynched(String itemId) throws Exception { + + ThSyncFolderDescriptor config = null; + try { + config = getConfiguration(itemId); + } catch (WorkspaceNotSynchedException e) { + logger.debug("WorkspaceNotSynchedException catched, the item id: " + itemId + " is not synched"); + } catch (Exception e) { + logger.debug("Error on getting configuration for the item id: " + itemId + + ", returning null (means not synched)"); + } + + if (config != null) + return true; + + return false; } From 60a2e101175af39d08a64164a3979a3608c01005 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 14 May 2021 12:09:59 +0200 Subject: [PATCH 09/15] integrated with SyncEngine.parseInfo --- .../portal/wssynclibrary/DoCheckSyncItem.java | 10 ----- .../thredds/ThreddsConverter.java | 39 ++++++++++++------- .../thredds/WorkspaceThreddsSynchronize.java | 36 ++++++++++++++--- 3 files changed, 57 insertions(+), 28 deletions(-) diff --git a/src/main/java/org/gcube/portal/wssynclibrary/DoCheckSyncItem.java b/src/main/java/org/gcube/portal/wssynclibrary/DoCheckSyncItem.java index b202d42..430cd49 100644 --- a/src/main/java/org/gcube/portal/wssynclibrary/DoCheckSyncItem.java +++ b/src/main/java/org/gcube/portal/wssynclibrary/DoCheckSyncItem.java @@ -35,14 +35,4 @@ public interface DoCheckSyncItem { * @throws Exception the exception */ T getConfiguration(String itemId) throws WorkspaceInteractionException, WorkspaceNotSynchedException, Exception; - - /** - * Checks if is item synched. - * - * @param itemId the item id - * @return true, if is item synched - * @throws Exception the exception - */ - boolean isItemSynched(String itemId) throws Exception; - } diff --git a/src/main/java/org/gcube/portal/wssynclibrary/thredds/ThreddsConverter.java b/src/main/java/org/gcube/portal/wssynclibrary/thredds/ThreddsConverter.java index 6b86c3e..ced67e8 100644 --- a/src/main/java/org/gcube/portal/wssynclibrary/thredds/ThreddsConverter.java +++ b/src/main/java/org/gcube/portal/wssynclibrary/thredds/ThreddsConverter.java @@ -46,7 +46,8 @@ public class ThreddsConverter { mySync.setFolderId(t.getFolderId()); mySync.setFolderPath(t.getFolderPath()); mySync.setLocked(t.getIsLocked()); - mySync.setElementInfo(toThElementInfo.apply(t.getInfo())); + Sync_Status theSyncStatus = toSyncStatus.apply(t.getStatus()); + mySync.setElementInfo(new ThSyncElementInfo(theSyncStatus)); ThProcessDescriptor localProcessDescriptor = toThProcessDescriptor.apply(t.getLocalProcessDescriptor()); mySync.setLocalProcessDescriptor(localProcessDescriptor); ThSynchFolderConfiguration configuration = toThSynchFolderConfiguration.apply(t.getConfiguration()); @@ -68,7 +69,8 @@ public class ThreddsConverter { SynchFolderConfiguration configuration = toSynchFolderConfiguration.apply(t.getConfiguration()); SynchronizedElementInfo sei = toSynchronizedElementInfo.apply(t.getElementInfo()); - return new SyncFolderDescriptor(t.getFolderId(), t.getFolderPath(), configuration, sei); + return new SyncFolderDescriptor(sei.getStatus(), t.getFolderId(), t.getFolderPath(), configuration, + t.isLocked()); } }; @@ -189,12 +191,11 @@ public class ThreddsConverter { break; } } - // mySync.setStatus(t.getStatus()); return mySync; } }; - public static Function toThElementInfo = new Function() { + public static Function toThSyncElementInfo = new Function() { public ThSyncElementInfo apply(SynchronizedElementInfo sei) { @@ -205,23 +206,35 @@ public class ThreddsConverter { } ThSyncElementInfo toReturn = new ThSyncElementInfo(); - SynchronizationStatus status = sei.getStatus(); + Sync_Status theSyncStatus = toSyncStatus.apply(sei.getStatus()); + toReturn.setSyncStatus(theSyncStatus); + return toReturn; + } + }; - if (status != null) { - switch (status) { + public static Function toSyncStatus = new Function() { + + public Sync_Status apply(SynchronizationStatus synchronizationStatus) { + + if (synchronizationStatus == null) { + logger.info("Input " + SynchronizationStatus.class.getSimpleName() + " is null, returning null " + + Sync_Status.class.getSimpleName()); + return null; + } + + if (synchronizationStatus != null) { + switch (synchronizationStatus) { case UP_TO_DATE: - toReturn.setSyncStatus(Sync_Status.UP_TO_DATE); - break; + return Sync_Status.UP_TO_DATE; case OUTDATED_WS: - toReturn.setSyncStatus(Sync_Status.OUTDATED_WS); - break; + return Sync_Status.OUTDATED_WS; case OUTDATED_REMOTE: - toReturn.setSyncStatus(Sync_Status.OUTDATED_REMOTE); + return Sync_Status.OUTDATED_REMOTE; default: break; } } - return toReturn; + return null; } }; diff --git a/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java b/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java index 9f6c488..c27ba74 100644 --- a/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java +++ b/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java @@ -13,6 +13,7 @@ import org.gcube.portal.wssynclibrary.shared.thredds.Status; import org.gcube.portal.wssynclibrary.shared.thredds.ThCatalogueBean; import org.gcube.portal.wssynclibrary.shared.thredds.ThProcessDescriptor; import org.gcube.portal.wssynclibrary.shared.thredds.ThProcessStatus; +import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncElementInfo; import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncFolderDescriptor; import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus; import org.gcube.portal.wssynclibrary.shared.thredds.ThSynchFolderConfiguration; @@ -24,9 +25,11 @@ import org.gcube.usecases.ws.thredds.faults.ProcessNotFoundException; import org.gcube.usecases.ws.thredds.faults.WorkspaceInteractionException; import org.gcube.usecases.ws.thredds.faults.WorkspaceLockedException; import org.gcube.usecases.ws.thredds.faults.WorkspaceNotSynchedException; +import org.gcube.usecases.ws.thredds.model.ContainerType; import org.gcube.usecases.ws.thredds.model.SyncFolderDescriptor; import org.gcube.usecases.ws.thredds.model.SyncOperationCallBack; import org.gcube.usecases.ws.thredds.model.SynchFolderConfiguration; +import org.gcube.usecases.ws.thredds.model.SynchronizedElementInfo; import org.gcube.usecases.ws.thredds.model.gui.CatalogBean; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -353,6 +356,8 @@ public class WorkspaceThreddsSynchronize * @throws WorkspaceInteractionException the workspace interaction exception * @throws WorkspaceNotSynchedException the workspace not synched exception * @throws Exception the exception + * + * NB. it is time consuming due to it calls the SHUB */ @Override public ThSyncFolderDescriptor getConfiguration(String itemId) @@ -369,19 +374,40 @@ public class WorkspaceThreddsSynchronize } + + /** + * Gets the element info. + * + * @param itemProperties the item properties read from SHUB by accessing to Metadata.Map() of a item + * @param itemType the item type + * @return the element info + * @throws WorkspaceNotSynchedException the workspace not synched exception + */ + public ThSyncElementInfo getElementInfo(Map itemProperties, ContainerType itemType) throws WorkspaceNotSynchedException { + + if (itemProperties == null || itemProperties.isEmpty()) + return null; + + SynchronizedElementInfo theSEI = SyncEngine.parseInfo(itemProperties, itemType); + return ThreddsConverter.toThSyncElementInfo.apply(theSEI); + + } + + /** * Checks if is item synched. * * @param itemId the item id + * @param itemProperties the item properties + * @param itemType the item type * @return true, if is item synched * @throws Exception the exception */ - @Override - public boolean isItemSynched(String itemId) throws Exception { + public boolean isItemSynched(String itemId, Map itemProperties, ContainerType itemType) throws Exception { - ThSyncFolderDescriptor config = null; + ThSyncElementInfo sinInfo = null; try { - config = getConfiguration(itemId); + sinInfo = getElementInfo(itemProperties,itemType); } catch (WorkspaceNotSynchedException e) { logger.debug("WorkspaceNotSynchedException catched, the item id: " + itemId + " is not synched"); } catch (Exception e) { @@ -389,7 +415,7 @@ public class WorkspaceThreddsSynchronize + ", returning null (means not synched)"); } - if (config != null) + if (sinInfo != null) return true; return false; From 0c317804ed566472bf141e8bddc0c93650369183 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 14 May 2021 12:32:54 +0200 Subject: [PATCH 10/15] added the getConfiguration method --- .../thredds/WorkspaceThreddsSynchronize.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java b/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java index c27ba74..d5cc386 100644 --- a/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java +++ b/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java @@ -357,7 +357,8 @@ public class WorkspaceThreddsSynchronize * @throws WorkspaceNotSynchedException the workspace not synched exception * @throws Exception the exception * - * NB. it is time consuming due to it calls the SHUB + * NB. it is time consuming due to it + * calls the SHUB */ @Override public ThSyncFolderDescriptor getConfiguration(String itemId) @@ -374,16 +375,17 @@ public class WorkspaceThreddsSynchronize } - /** * Gets the element info. * - * @param itemProperties the item properties read from SHUB by accessing to Metadata.Map() of a item - * @param itemType the item type + * @param itemProperties the item properties read from SHUB by accessing to + * Metadata.Map() of a item + * @param itemType the item type * @return the element info * @throws WorkspaceNotSynchedException the workspace not synched exception */ - public ThSyncElementInfo getElementInfo(Map itemProperties, ContainerType itemType) throws WorkspaceNotSynchedException { + public ThSyncElementInfo getElementInfo(Map itemProperties, ContainerType itemType) + throws WorkspaceNotSynchedException { if (itemProperties == null || itemProperties.isEmpty()) return null; @@ -393,21 +395,19 @@ public class WorkspaceThreddsSynchronize } - /** * Checks if is item synched. * - * @param itemId the item id + * @param itemId the item id * @param itemProperties the item properties - * @param itemType the item type + * @param itemType the item type * @return true, if is item synched - * @throws Exception the exception */ - public boolean isItemSynched(String itemId, Map itemProperties, ContainerType itemType) throws Exception { + public boolean isItemSynched(String itemId, Map itemProperties, ContainerType itemType) { ThSyncElementInfo sinInfo = null; try { - sinInfo = getElementInfo(itemProperties,itemType); + sinInfo = getElementInfo(itemProperties, itemType); } catch (WorkspaceNotSynchedException e) { logger.debug("WorkspaceNotSynchedException catched, the item id: " + itemId + " is not synched"); } catch (Exception e) { From 7d9104991d1e7e96e2df7a781b21b353862f870e Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 14 May 2021 16:22:45 +0200 Subject: [PATCH 11/15] added log --- .../wssynclibrary/thredds/WorkspaceThreddsSynchronize.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java b/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java index d5cc386..48429d5 100644 --- a/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java +++ b/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java @@ -391,12 +391,13 @@ public class WorkspaceThreddsSynchronize return null; SynchronizedElementInfo theSEI = SyncEngine.parseInfo(itemProperties, itemType); + logger.debug("the SynchronizedElementInfo returned is: "+theSEI); return ThreddsConverter.toThSyncElementInfo.apply(theSEI); } /** - * Checks if is item synched. + * Checks if is item synched. This calls the {@link SyncEngine#parseInfo(Map, ContainerType)} * * @param itemId the item id * @param itemProperties the item properties @@ -411,8 +412,8 @@ public class WorkspaceThreddsSynchronize } catch (WorkspaceNotSynchedException e) { logger.debug("WorkspaceNotSynchedException catched, the item id: " + itemId + " is not synched"); } catch (Exception e) { - logger.debug("Error on getting configuration for the item id: " + itemId - + ", returning null (means not synched)"); + logger.debug("Error on getting SyncElementInfo for the item id: " + itemId + + ", returning null (means not synched)", e); } if (sinInfo != null) From 5ac0e064dc04610bfcf32cb41ab7f19d84084eb4 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Mon, 17 May 2021 18:10:57 +0200 Subject: [PATCH 12/15] improved management of exceptions in the checkItemSynched --- .../thredds/WorkspaceThreddsSynchronize.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java b/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java index 48429d5..aad176a 100644 --- a/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java +++ b/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java @@ -113,14 +113,14 @@ public class WorkspaceThreddsSynchronize logger.error("Error: ", e); if (e instanceof WorkspaceInteractionException) throw new Exception( - "Sorry, an error occurred during check syncronization due to WS interection for the itemId: " - + itemId); + "Sorry, a WorkspaceInteraction error occurred during check syncronization for the itemId: " + + itemId+". Try again or contact the support"); else if (e instanceof InternalException) throw new Exception( - "Sorry, an Internal Exception occurred during check syncronization for the itemId: " + itemId); + "Sorry, an Internal error occurred during check syncronization for the itemId: " + itemId+". Try again or contact the support"); throw new Exception( - "Sorry, an error occurred server side during chck syncronization for the itemId: " + itemId); + "Sorry, an error occurred server side during chck syncronization for the itemId: " + itemId+". Try again or contact the support"); } } @@ -370,7 +370,7 @@ public class WorkspaceThreddsSynchronize SynchFolderConfiguration syncFolderConfig = engine.getConfig(itemId); ThSynchFolderConfiguration toFolderConfig = ThreddsConverter.toThSynchFolderConfiguration .apply(syncFolderConfig); - + return new ThSyncFolderDescriptor(itemId, null, toFolderConfig, false, null, null); } From 6506500f91943a3843b76627b1b910ab5c84871a Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 18 May 2021 12:47:19 +0200 Subject: [PATCH 13/15] compleated the bean ThSyncElementInfo --- .../shared/thredds/ThSyncElementInfo.java | 65 +++++++++++++++++++ .../thredds/ThreddsConverter.java | 2 + 2 files changed, 67 insertions(+) diff --git a/src/main/java/org/gcube/portal/wssynclibrary/shared/thredds/ThSyncElementInfo.java b/src/main/java/org/gcube/portal/wssynclibrary/shared/thredds/ThSyncElementInfo.java index 9a23297..2f08f09 100644 --- a/src/main/java/org/gcube/portal/wssynclibrary/shared/thredds/ThSyncElementInfo.java +++ b/src/main/java/org/gcube/portal/wssynclibrary/shared/thredds/ThSyncElementInfo.java @@ -2,6 +2,8 @@ package org.gcube.portal.wssynclibrary.shared.thredds; import java.io.Serializable; +import org.gcube.usecases.ws.thredds.model.StepReport; + /** * The Class ThSyncElementInfo. * @@ -18,23 +20,86 @@ public class ThSyncElementInfo implements Serializable { private Sync_Status syncStatus; + private StepReport.Status lastSynchronizationStatus; + + private String lastupdateTime; + + /** + * Instantiates a new th sync element info. + */ public ThSyncElementInfo() { } + /** + * Instantiates a new th sync element info. + * + * @param syncStatus the sync status + */ public ThSyncElementInfo(Sync_Status syncStatus) { super(); this.syncStatus = syncStatus; } + /** + * Gets the sync status. + * + * @return the sync status + */ public Sync_Status getSyncStatus() { return syncStatus; } + /** + * Sets the sync status. + * + * @param syncStatus the new sync status + */ public void setSyncStatus(Sync_Status syncStatus) { this.syncStatus = syncStatus; } + /** + * Gets the last synchronization status. + * + * @return the last synchronization status + */ + public StepReport.Status getLastSynchronizationStatus() { + return lastSynchronizationStatus; + } + + /** + * Sets the last synchronization status. + * + * @param lastSynchronizationStatus the new last synchronization status + */ + public void setLastSynchronizationStatus(StepReport.Status lastSynchronizationStatus) { + this.lastSynchronizationStatus = lastSynchronizationStatus; + } + + /** + * Gets the lastupdate time. + * + * @return the lastupdate time + */ + public String getLastupdateTime() { + return lastupdateTime; + } + + /** + * Sets the lastupdate time. + * + * @param lastupdateTime the new lastupdate time + */ + public void setLastupdateTime(String lastupdateTime) { + this.lastupdateTime = lastupdateTime; + } + + /** + * To string. + * + * @return the string + */ @Override public String toString() { StringBuilder builder = new StringBuilder(); diff --git a/src/main/java/org/gcube/portal/wssynclibrary/thredds/ThreddsConverter.java b/src/main/java/org/gcube/portal/wssynclibrary/thredds/ThreddsConverter.java index ced67e8..9de5ac6 100644 --- a/src/main/java/org/gcube/portal/wssynclibrary/thredds/ThreddsConverter.java +++ b/src/main/java/org/gcube/portal/wssynclibrary/thredds/ThreddsConverter.java @@ -208,6 +208,8 @@ public class ThreddsConverter { ThSyncElementInfo toReturn = new ThSyncElementInfo(); Sync_Status theSyncStatus = toSyncStatus.apply(sei.getStatus()); toReturn.setSyncStatus(theSyncStatus); + toReturn.setLastupdateTime(sei.getLastupdateTime()); + toReturn.setLastSynchronizationStatus(sei.getLastSynchronizationStatus()); return toReturn; } }; From 55d1edde3039652c60d7c8d9f4a306b0adaacf52 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 18 May 2021 16:12:33 +0200 Subject: [PATCH 14/15] added new class ThStepReport --- .../shared/thredds/ThStepReport.java | 68 +++++++++++++++++++ .../shared/thredds/ThSyncElementInfo.java | 43 +++--------- .../thredds/ThreddsConverter.java | 6 +- 3 files changed, 83 insertions(+), 34 deletions(-) create mode 100644 src/main/java/org/gcube/portal/wssynclibrary/shared/thredds/ThStepReport.java diff --git a/src/main/java/org/gcube/portal/wssynclibrary/shared/thredds/ThStepReport.java b/src/main/java/org/gcube/portal/wssynclibrary/shared/thredds/ThStepReport.java new file mode 100644 index 0000000..be7ff2c --- /dev/null +++ b/src/main/java/org/gcube/portal/wssynclibrary/shared/thredds/ThStepReport.java @@ -0,0 +1,68 @@ +package org.gcube.portal.wssynclibrary.shared.thredds; + +import java.io.Serializable; + +/** + * The Class ThStepReport. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * May 18, 2021 + */ +public class ThStepReport implements Serializable { + + /** + * + */ + private static final long serialVersionUID = -1678408521458644765L; + private String stepReportStatus; + + /** + * Instantiates a new th step report. + */ + public ThStepReport() { + + } + + /** + * Instantiates a new th step report. + * + * @param stepReportStatus the step report status + */ + public ThStepReport(String stepReportStatus) { + this.stepReportStatus = stepReportStatus; + } + + /** + * Gets the step report status. + * + * @return the step report status + */ + public String getStepReportStatus() { + return stepReportStatus; + } + + /** + * Sets the step report status. + * + * @param stepReportStatus the new step report status + */ + public void setStepReportStatus(String stepReportStatus) { + this.stepReportStatus = stepReportStatus; + } + + /** + * To string. + * + * @return the string + */ + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("ThStepReport [stepReportStatus="); + builder.append(stepReportStatus); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/src/main/java/org/gcube/portal/wssynclibrary/shared/thredds/ThSyncElementInfo.java b/src/main/java/org/gcube/portal/wssynclibrary/shared/thredds/ThSyncElementInfo.java index 2f08f09..d1b1947 100644 --- a/src/main/java/org/gcube/portal/wssynclibrary/shared/thredds/ThSyncElementInfo.java +++ b/src/main/java/org/gcube/portal/wssynclibrary/shared/thredds/ThSyncElementInfo.java @@ -2,8 +2,6 @@ package org.gcube.portal.wssynclibrary.shared.thredds; import java.io.Serializable; -import org.gcube.usecases.ws.thredds.model.StepReport; - /** * The Class ThSyncElementInfo. * @@ -20,7 +18,7 @@ public class ThSyncElementInfo implements Serializable { private Sync_Status syncStatus; - private StepReport.Status lastSynchronizationStatus; + private ThStepReport stepReport; private String lastupdateTime; @@ -59,54 +57,33 @@ public class ThSyncElementInfo implements Serializable { this.syncStatus = syncStatus; } - /** - * Gets the last synchronization status. - * - * @return the last synchronization status - */ - public StepReport.Status getLastSynchronizationStatus() { - return lastSynchronizationStatus; + public ThStepReport getStepReport() { + return stepReport; } - /** - * Sets the last synchronization status. - * - * @param lastSynchronizationStatus the new last synchronization status - */ - public void setLastSynchronizationStatus(StepReport.Status lastSynchronizationStatus) { - this.lastSynchronizationStatus = lastSynchronizationStatus; + public void setStepReport(ThStepReport stepReport) { + this.stepReport = stepReport; } - /** - * Gets the lastupdate time. - * - * @return the lastupdate time - */ public String getLastupdateTime() { return lastupdateTime; } - /** - * Sets the lastupdate time. - * - * @param lastupdateTime the new lastupdate time - */ public void setLastupdateTime(String lastupdateTime) { this.lastupdateTime = lastupdateTime; } - /** - * To string. - * - * @return the string - */ @Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append("ThSyncElementInfo [syncStatus="); builder.append(syncStatus); + builder.append(", stepReport="); + builder.append(stepReport); + builder.append(", lastupdateTime="); + builder.append(lastupdateTime); builder.append("]"); return builder.toString(); } -} +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portal/wssynclibrary/thredds/ThreddsConverter.java b/src/main/java/org/gcube/portal/wssynclibrary/thredds/ThreddsConverter.java index 9de5ac6..fbdf465 100644 --- a/src/main/java/org/gcube/portal/wssynclibrary/thredds/ThreddsConverter.java +++ b/src/main/java/org/gcube/portal/wssynclibrary/thredds/ThreddsConverter.java @@ -7,6 +7,7 @@ import org.gcube.portal.wssynclibrary.shared.thredds.Sync_Status; import org.gcube.portal.wssynclibrary.shared.thredds.ThCatalogueBean; import org.gcube.portal.wssynclibrary.shared.thredds.ThProcessDescriptor; import org.gcube.portal.wssynclibrary.shared.thredds.ThProcessStatus; +import org.gcube.portal.wssynclibrary.shared.thredds.ThStepReport; import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncElementInfo; import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncFolderDescriptor; import org.gcube.portal.wssynclibrary.shared.thredds.ThSynchFolderConfiguration; @@ -209,7 +210,10 @@ public class ThreddsConverter { Sync_Status theSyncStatus = toSyncStatus.apply(sei.getStatus()); toReturn.setSyncStatus(theSyncStatus); toReturn.setLastupdateTime(sei.getLastupdateTime()); - toReturn.setLastSynchronizationStatus(sei.getLastSynchronizationStatus()); + String lastSyncStatus = sei.getLastSynchronizationStatus() != null + ? sei.getLastSynchronizationStatus().name() + : null; + toReturn.setStepReport(new ThStepReport(lastSyncStatus)); return toReturn; } }; From d9459d6479d421c885502e659d8b5bdc0683fab9 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 20 May 2021 17:30:44 +0200 Subject: [PATCH 15/15] passing the exceptions --- .../thredds/WorkspaceThreddsSynchronize.java | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java b/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java index aad176a..aafd53a 100644 --- a/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java +++ b/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java @@ -179,18 +179,8 @@ public class WorkspaceThreddsSynchronize return synStatus; } catch (WorkspaceInteractionException | InternalException | ProcessNotFoundException e) { - logger.error("Error: ", e); - - if (e instanceof WorkspaceInteractionException) - throw new Exception( - "Sorry, an error occurred during syncronization due to WS interection for the itemId: " - + itemId); - else if (e instanceof InternalException) - throw new Exception( - "Sorry, an Internal Exception occurred during syncronization for the itemId: " + itemId); - - throw new Exception( - "Sorry, an error occurred server side during syncronization for the itemId: " + itemId); + logger.error("DoSync Error: ", e); + throw e; } }