Merge pull request 'task_21374' (#1) from task_21374 into master

Reviewed-on: #1
This commit is contained in:
Francesco Mangiacrapa 2021-05-25 10:30:55 +02:00
commit 07230a54f5
12 changed files with 755 additions and 496 deletions

View File

@ -4,6 +4,10 @@
All notable changes to this project will be documented in this file. 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). 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 ## [v1.4.0] - 2021-03-10

41
pom.xml
View File

@ -12,7 +12,7 @@
<groupId>org.gcube.portal</groupId> <groupId>org.gcube.portal</groupId>
<artifactId>ws-synchronized-module-library</artifactId> <artifactId>ws-synchronized-module-library</artifactId>
<version>1.4.0</version> <version>1.5.0-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>ws-synchronized-module-library</name> <name>ws-synchronized-module-library</name>
<description> <description>
@ -37,7 +37,7 @@
<dependency> <dependency>
<groupId>org.gcube.distribution</groupId> <groupId>org.gcube.distribution</groupId>
<artifactId>maven-portal-bom</artifactId> <artifactId>maven-portal-bom</artifactId>
<version>3.6.0</version> <version>3.6.1</version>
<type>pom</type> <type>pom</type>
<scope>import</scope> <scope>import</scope>
</dependency> </dependency>
@ -49,37 +49,6 @@
<dependency> <dependency>
<groupId>org.gcube.spatial.data</groupId> <groupId>org.gcube.spatial.data</groupId>
<artifactId>ws-thredds</artifactId> <artifactId>ws-thredds</artifactId>
<version>[0.1.0, 1.0.0-SNAPSHOT)</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-encryption</artifactId>
<scope>provided</scope>
</dependency>
<!-- FWS -->
<dependency>
<groupId>org.gcube.resources.discovery</groupId>
<artifactId>ic-client</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-scope-maps</artifactId>
<scope>compile</scope>
</dependency>
<!-- END FWS -->
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>storagehub-client-library</artifactId>
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version> <version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
@ -87,11 +56,13 @@
<!-- LOGGER --> <!-- LOGGER -->
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId> <artifactId>slf4j-api</artifactId>
<scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId> <artifactId>slf4j-log4j12</artifactId>
<scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -4,18 +4,17 @@
package org.gcube.portal.wssynclibrary; package org.gcube.portal.wssynclibrary;
import org.gcube.portal.wssynclibrary.shared.ItemNotSynched; 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. * The Interface DoCheckSyncItem.
* *
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Feb 8, 2018
* Feb 8, 2018
* @param <T> the generic type * @param <T> the generic type
*/ */
public interface DoCheckSyncItem<T> { public interface DoCheckSyncItem<T> {
/** /**
* Check item synched. * Check item synched.
* *
@ -26,4 +25,14 @@ public interface DoCheckSyncItem<T> {
*/ */
T checkItemSynched(String itemId) throws ItemNotSynched, 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 the exception
*/
T getConfiguration(String itemId) throws WorkspaceInteractionException, WorkspaceNotSynchedException, Exception;
} }

View File

@ -1,12 +1,9 @@
package org.gcube.portal.wssynclibrary; package org.gcube.portal.wssynclibrary;
// TODO: Auto-generated Javadoc
/** /**
* The Interface DoConnectRepository. * The Interface DoConnectRepository.
* *
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Feb 14, 2018
* Feb 14, 2018
*/ */
public interface DoConnectRepository { public interface DoConnectRepository {
@ -14,8 +11,9 @@ public interface DoConnectRepository {
* Inits the repository. * Inits the repository.
* *
* @return true, if successful * @return true, if successful
* @throws Exception
*/ */
Boolean initRepository(); Boolean initRepository() throws Exception;
/** /**
* Shutdown repository. * Shutdown repository.

View File

@ -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();
}
}

View File

@ -0,0 +1,89 @@
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;
private ThStepReport stepReport;
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;
}
public ThStepReport getStepReport() {
return stepReport;
}
public void setStepReport(ThStepReport stepReport) {
this.stepReport = stepReport;
}
public String getLastupdateTime() {
return lastupdateTime;
}
public void setLastupdateTime(String lastupdateTime) {
this.lastupdateTime = lastupdateTime;
}
@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();
}
}

View File

@ -2,61 +2,54 @@ package org.gcube.portal.wssynclibrary.shared.thredds;
import java.io.Serializable; import java.io.Serializable;
// TODO: Auto-generated Javadoc
/** /**
* The Class ThSyncFolderDescriptor. * The Class ThSyncFolderDescriptor.
* *
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
* Feb 8, 2018 *
* May 13, 2021
*/ */
public class ThSyncFolderDescriptor implements Serializable { public class ThSyncFolderDescriptor implements Serializable {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = 4134777763175272691L; private static final long serialVersionUID = 4134777763175272691L;
/** The folder id. */
private String folderId; private String folderId;
/** The folder path. */
private String folderPath; private String folderPath;
/** The configuration. */
private ThSynchFolderConfiguration configuration; private ThSynchFolderConfiguration configuration;
/** The is locked. */
private boolean isLocked = false; private boolean isLocked = false;
private ThSyncElementInfo elementInfo;
/** The local process descriptor. */
private ThProcessDescriptor localProcessDescriptor = null; private ThProcessDescriptor localProcessDescriptor = null;
/** /**
* Instantiates a new s sync folder descriptor. * Instantiates a new s sync folder descriptor.
*/ */
public ThSyncFolderDescriptor() { 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 folderId the folder id
* @param folderPath the folder path * @param folderPath the folder path
* @param configuration the configuration * @param configuration the configuration
* @param isLocked the is locked * @param isLocked the is locked
* @param elementInfo the element info
* @param localProcessDescriptor the local process descriptor * @param localProcessDescriptor the local process descriptor
*/ */
public ThSyncFolderDescriptor(String folderId, String folderPath, ThSynchFolderConfiguration configuration, public ThSyncFolderDescriptor(String folderId, String folderPath, ThSynchFolderConfiguration configuration,
boolean isLocked, ThProcessDescriptor localProcessDescriptor) { boolean isLocked, ThSyncElementInfo elementInfo, ThProcessDescriptor localProcessDescriptor) {
super(); super();
this.folderId = folderId; this.folderId = folderId;
this.folderPath = folderPath; this.folderPath = folderPath;
this.configuration = configuration; this.configuration = configuration;
this.isLocked = isLocked; this.isLocked = isLocked;
this.elementInfo = elementInfo;
this.localProcessDescriptor = localProcessDescriptor; this.localProcessDescriptor = localProcessDescriptor;
} }
@ -150,8 +143,28 @@ public class ThSyncFolderDescriptor implements Serializable{
this.localProcessDescriptor = localProcessDescriptor; 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 @Override
public String toString() { public String toString() {
@ -164,13 +177,12 @@ public class ThSyncFolderDescriptor implements Serializable{
builder.append(configuration); builder.append(configuration);
builder.append(", isLocked="); builder.append(", isLocked=");
builder.append(isLocked); builder.append(isLocked);
builder.append(", elementInfo=");
builder.append(elementInfo);
builder.append(", localProcessDescriptor="); builder.append(", localProcessDescriptor=");
builder.append(localProcessDescriptor); builder.append(localProcessDescriptor);
builder.append("]"); builder.append("]");
return builder.toString(); return builder.toString();
} }
} }

View File

@ -2,13 +2,10 @@ package org.gcube.portal.wssynclibrary.shared.thredds;
import java.io.Serializable; import java.io.Serializable;
// TODO: Auto-generated Javadoc
/** /**
* The Class ThSynchFolderConfiguration. * The Class ThSynchFolderConfiguration.
* *
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Feb 8, 2018
* Feb 8, 2018
*/ */
public class ThSynchFolderConfiguration implements Serializable { public class ThSynchFolderConfiguration implements Serializable {
@ -21,8 +18,7 @@ public class ThSynchFolderConfiguration implements Serializable{
/** The filter. */ /** The filter. */
private String filter; private String filter;
/** The target token. */ private String targetContext;
private String targetToken;
/** The to create catalog name. */ /** The to create catalog name. */
private String toCreateCatalogName; private String toCreateCatalogName;
@ -32,25 +28,37 @@ public class ThSynchFolderConfiguration implements Serializable{
private String rootFolderId; private String rootFolderId;
/**
* Instantiates a new th synch folder configuration.
*/
public ThSynchFolderConfiguration() { 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(); super();
this.remotePath = remotePath; this.remotePath = remotePath;
this.filter = filter; this.filter = filter;
this.targetToken = targetToken; this.targetContext = targetContext;
this.toCreateCatalogName = toCreateCatalogName; this.toCreateCatalogName = toCreateCatalogName;
this.remotePersistence = remotePersistence; this.remotePersistence = remotePersistence;
this.rootFolderId = rootFolderId; this.rootFolderId = rootFolderId;
} }
/** /**
* Gets the root folder id.
*
* @return the rootFolderId * @return the rootFolderId
*/ */
public String getRootFolderId() { public String getRootFolderId() {
@ -58,8 +66,9 @@ public class ThSynchFolderConfiguration implements Serializable{
return rootFolderId; return rootFolderId;
} }
/** /**
* Sets the root folder id.
*
* @param rootFolderId the rootFolderId to set * @param rootFolderId the rootFolderId to set
*/ */
public void setRootFolderId(String rootFolderId) { public void setRootFolderId(String rootFolderId) {
@ -67,87 +76,105 @@ public class ThSynchFolderConfiguration implements Serializable{
this.rootFolderId = rootFolderId; this.rootFolderId = rootFolderId;
} }
/**
* Gets the remote path.
*
* @return the remote path
*/
public String getRemotePath() { public String getRemotePath() {
return remotePath; return remotePath;
} }
/**
* Sets the remote path.
*
* @param remotePath the new remote path
*/
public void setRemotePath(String remotePath) { public void setRemotePath(String remotePath) {
this.remotePath = remotePath; this.remotePath = remotePath;
} }
/**
* Gets the filter.
*
* @return the filter
*/
public String getFilter() { public String getFilter() {
return filter; return filter;
} }
/**
* Sets the filter.
*
* @param filter the new filter
*/
public void setFilter(String filter) { public void setFilter(String filter) {
this.filter = filter; this.filter = filter;
} }
/**
* Gets the target context.
*
public String getTargetToken() { * @return the target context
return targetToken; */
public String getTargetContext() {
return targetContext;
} }
/**
* Sets the target context.
*
public void setTargetToken(String targetToken) { * @param targetContext the new target context
this.targetToken = targetToken; */
public void setTargetContext(String targetContext) {
this.targetContext = targetContext;
} }
/**
* Gets the to create catalog name.
*
* @return the to create catalog name
*/
public String getToCreateCatalogName() { public String getToCreateCatalogName() {
return toCreateCatalogName; return toCreateCatalogName;
} }
/**
* Sets the to create catalog name.
*
* @param toCreateCatalogName the new to create catalog name
*/
public void setToCreateCatalogName(String toCreateCatalogName) { public void setToCreateCatalogName(String toCreateCatalogName) {
this.toCreateCatalogName = toCreateCatalogName; this.toCreateCatalogName = toCreateCatalogName;
} }
/**
* Gets the remote persistence.
*
* @return the remote persistence
*/
public String getRemotePersistence() { public String getRemotePersistence() {
return remotePersistence; return remotePersistence;
} }
/**
* Sets the remote persistence.
*
* @param remotePersistence the new remote persistence
*/
public void setRemotePersistence(String remotePersistence) { public void setRemotePersistence(String remotePersistence) {
this.remotePersistence = remotePersistence; this.remotePersistence = remotePersistence;
} }
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override @Override
public String toString() { public String toString() {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
builder.append("ThSynchFolderConfiguration [remotePath="); builder.append("ThSynchFolderConfiguration [remotePath=");
builder.append(remotePath); builder.append(remotePath);
builder.append(", filter="); builder.append(", filter=");
builder.append(filter); builder.append(filter);
builder.append(", targetToken="); builder.append(", targetContext=");
builder.append(targetToken); builder.append(targetContext);
builder.append(", toCreateCatalogName="); builder.append(", toCreateCatalogName=");
builder.append(toCreateCatalogName); builder.append(toCreateCatalogName);
builder.append(", remotePersistence="); builder.append(", remotePersistence=");
@ -158,5 +185,4 @@ public class ThSynchFolderConfiguration implements Serializable{
return builder.toString(); return builder.toString();
} }
} }

View File

@ -3,28 +3,29 @@ package org.gcube.portal.wssynclibrary.thredds;
import java.util.function.Function; import java.util.function.Function;
import org.gcube.portal.wssynclibrary.shared.thredds.Status; 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.ThCatalogueBean;
import org.gcube.portal.wssynclibrary.shared.thredds.ThProcessDescriptor; import org.gcube.portal.wssynclibrary.shared.thredds.ThProcessDescriptor;
import org.gcube.portal.wssynclibrary.shared.thredds.ThProcessStatus; 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.ThSyncFolderDescriptor;
import org.gcube.portal.wssynclibrary.shared.thredds.ThSynchFolderConfiguration; import org.gcube.portal.wssynclibrary.shared.thredds.ThSynchFolderConfiguration;
import org.gcube.usecases.ws.thredds.engine.impl.ProcessDescriptor; import org.gcube.usecases.ws.thredds.engine.impl.ProcessDescriptor;
import org.gcube.usecases.ws.thredds.engine.impl.ProcessStatus; import org.gcube.usecases.ws.thredds.engine.impl.ProcessStatus;
import org.gcube.usecases.ws.thredds.model.SyncFolderDescriptor; import org.gcube.usecases.ws.thredds.model.SyncFolderDescriptor;
import org.gcube.usecases.ws.thredds.model.SynchFolderConfiguration; 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.gcube.usecases.ws.thredds.model.gui.CatalogBean;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
// TODO: Auto-generated Javadoc
/** /**
* The Class ThreddsConverter. * The Class ThreddsConverter.
* *
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Feb 14, 2018
* Feb 14, 2018 * updated May 13, 2021
*/ */
public class ThreddsConverter { public class ThreddsConverter {
@ -38,13 +39,16 @@ public class ThreddsConverter {
public ThSyncFolderDescriptor apply(SyncFolderDescriptor t) { public ThSyncFolderDescriptor apply(SyncFolderDescriptor t) {
ThSyncFolderDescriptor mySync = new ThSyncFolderDescriptor(); ThSyncFolderDescriptor mySync = new ThSyncFolderDescriptor();
if (t == null) { if (t == null) {
logger.info("Input "+SyncFolderDescriptor.class.getSimpleName()+" is null, returning empty "+ThSyncFolderDescriptor.class.getSimpleName()); logger.info("Input " + SyncFolderDescriptor.class.getSimpleName() + " is null, returning empty "
+ ThSyncFolderDescriptor.class.getSimpleName());
return mySync; return mySync;
} }
mySync.setFolderId(t.getFolderId()); mySync.setFolderId(t.getFolderId());
mySync.setFolderPath(t.getFolderPath()); mySync.setFolderPath(t.getFolderPath());
mySync.setLocked(t.isLocked()); mySync.setLocked(t.getIsLocked());
Sync_Status theSyncStatus = toSyncStatus.apply(t.getStatus());
mySync.setElementInfo(new ThSyncElementInfo(theSyncStatus));
ThProcessDescriptor localProcessDescriptor = toThProcessDescriptor.apply(t.getLocalProcessDescriptor()); ThProcessDescriptor localProcessDescriptor = toThProcessDescriptor.apply(t.getLocalProcessDescriptor());
mySync.setLocalProcessDescriptor(localProcessDescriptor); mySync.setLocalProcessDescriptor(localProcessDescriptor);
ThSynchFolderConfiguration configuration = toThSynchFolderConfiguration.apply(t.getConfiguration()); ThSynchFolderConfiguration configuration = toThSynchFolderConfiguration.apply(t.getConfiguration());
@ -65,7 +69,9 @@ public class ThreddsConverter {
} }
SynchFolderConfiguration configuration = toSynchFolderConfiguration.apply(t.getConfiguration()); SynchFolderConfiguration configuration = toSynchFolderConfiguration.apply(t.getConfiguration());
return new SyncFolderDescriptor(t.getFolderId(), t.getFolderPath(), configuration); SynchronizedElementInfo sei = toSynchronizedElementInfo.apply(t.getElementInfo());
return new SyncFolderDescriptor(sei.getStatus(), t.getFolderId(), t.getFolderPath(), configuration,
t.isLocked());
} }
}; };
@ -79,39 +85,42 @@ public class ThreddsConverter {
return null; return null;
} }
String filter = t.getFilter()!=null && !t.getFilter().isEmpty()?t.getFilter():THREDDS_FILTER_NC_NCML_ASC; String filter = t.getFilter() != null && !t.getFilter().isEmpty() ? t.getFilter()
return new SynchFolderConfiguration(t.getRemotePath(), filter, t.getTargetToken(), t.getToCreateCatalogName(), t.getRootFolderId()); : THREDDS_FILTER_NC_NCML_ASC;
return new SynchFolderConfiguration(t.getRemotePath(), filter, t.getTargetContext(),
t.getToCreateCatalogName(), t.getRootFolderId());
} }
}; };
/** The to S synch folder configuration. */ /** The to S synch folder configuration. */
public static Function<SynchFolderConfiguration, ThSynchFolderConfiguration> toThSynchFolderConfiguration = new Function<SynchFolderConfiguration, ThSynchFolderConfiguration>() { public static Function<SynchFolderConfiguration, ThSynchFolderConfiguration> toThSynchFolderConfiguration = new Function<SynchFolderConfiguration, ThSynchFolderConfiguration>() {
public ThSynchFolderConfiguration apply(SynchFolderConfiguration t) { public ThSynchFolderConfiguration apply(SynchFolderConfiguration t) {
ThSynchFolderConfiguration mySync = new ThSynchFolderConfiguration(); ThSynchFolderConfiguration mySync = new ThSynchFolderConfiguration();
if (t == null) { if (t == null) {
logger.info("Input "+SynchFolderConfiguration.class.getSimpleName()+" is null, returning empty "+ThSynchFolderConfiguration.class.getSimpleName()); logger.info("Input " + SynchFolderConfiguration.class.getSimpleName() + " is null, returning empty "
+ ThSynchFolderConfiguration.class.getSimpleName());
return mySync; return mySync;
} }
mySync.setFilter(t.getFilter()); mySync.setFilter(t.getFilter());
mySync.setRemotePath(t.getRemotePath()); mySync.setRemotePath(t.getRemotePath());
mySync.setRemotePersistence(t.getRemotePersistence()); mySync.setRemotePersistence(t.getRemotePersistence());
mySync.setTargetToken(t.getTargetToken()); mySync.setTargetContext(t.getTargetContext());
mySync.setToCreateCatalogName(t.getToCreateCatalogName()); mySync.setToCreateCatalogName(t.getToCreateCatalogName());
mySync.setRootFolderId(t.getRootFolderId()); mySync.setRootFolderId(t.getRootFolderId());
return mySync; return mySync;
} }
}; };
/** The to S sync folder descriptor. */ /** The to S sync folder descriptor. */
public static Function<ProcessDescriptor, ThProcessDescriptor> toThProcessDescriptor = new Function<ProcessDescriptor, ThProcessDescriptor>() { public static Function<ProcessDescriptor, ThProcessDescriptor> toThProcessDescriptor = new Function<ProcessDescriptor, ThProcessDescriptor>() {
public ThProcessDescriptor apply(ProcessDescriptor t) { public ThProcessDescriptor apply(ProcessDescriptor t) {
ThProcessDescriptor mySync = new ThProcessDescriptor(); ThProcessDescriptor mySync = new ThProcessDescriptor();
if (t == null) { if (t == null) {
logger.info("Input "+ProcessDescriptor.class.getSimpleName()+" is null, returning empty "+ThProcessDescriptor.class.getSimpleName()); logger.info("Input " + ProcessDescriptor.class.getSimpleName() + " is null, returning empty "
+ ThProcessDescriptor.class.getSimpleName());
return mySync; return mySync;
} }
@ -124,7 +133,6 @@ public class ThreddsConverter {
} }
}; };
/** The to th catalogue bean. */ /** The to th catalogue bean. */
public static Function<CatalogBean, ThCatalogueBean> toThCatalogueBean = new Function<CatalogBean, ThCatalogueBean>() { public static Function<CatalogBean, ThCatalogueBean> toThCatalogueBean = new Function<CatalogBean, ThCatalogueBean>() {
@ -138,14 +146,14 @@ public class ThreddsConverter {
} }
}; };
/** The to th process status. */ /** The to th process status. */
public static Function<ProcessStatus, ThProcessStatus> toThProcessStatus = new Function<ProcessStatus, ThProcessStatus>() { public static Function<ProcessStatus, ThProcessStatus> toThProcessStatus = new Function<ProcessStatus, ThProcessStatus>() {
public ThProcessStatus apply(ProcessStatus t) { public ThProcessStatus apply(ProcessStatus t) {
ThProcessStatus mySync = new ThProcessStatus(); ThProcessStatus mySync = new ThProcessStatus();
if (t == null) { if (t == null) {
logger.info("Input "+ProcessStatus.class.getSimpleName()+" is null, returning empty "+ThProcessStatus.class.getSimpleName()); logger.info("Input " + ProcessStatus.class.getSimpleName() + " is null, returning empty "
+ ThProcessStatus.class.getSimpleName());
return mySync; return mySync;
} }
@ -184,11 +192,86 @@ public class ThreddsConverter {
break; break;
} }
} }
//mySync.setStatus(t.getStatus());
return mySync; return mySync;
} }
}; };
public static Function<SynchronizedElementInfo, ThSyncElementInfo> toThSyncElementInfo = new Function<SynchronizedElementInfo, ThSyncElementInfo>() {
public ThSyncElementInfo apply(SynchronizedElementInfo sei) {
if (sei == null) {
logger.info("Input " + SynchronizedElementInfo.class.getSimpleName() + " is null, returning null "
+ ThSyncElementInfo.class.getSimpleName());
return null;
}
ThSyncElementInfo toReturn = new ThSyncElementInfo();
Sync_Status theSyncStatus = toSyncStatus.apply(sei.getStatus());
toReturn.setSyncStatus(theSyncStatus);
toReturn.setLastupdateTime(sei.getLastupdateTime());
String lastSyncStatus = sei.getLastSynchronizationStatus() != null
? sei.getLastSynchronizationStatus().name()
: null;
toReturn.setStepReport(new ThStepReport(lastSyncStatus));
return toReturn;
}
};
public static Function<SynchronizationStatus, Sync_Status> toSyncStatus = new Function<SynchronizationStatus, Sync_Status>() {
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:
return Sync_Status.UP_TO_DATE;
case OUTDATED_WS:
return Sync_Status.OUTDATED_WS;
case OUTDATED_REMOTE:
return Sync_Status.OUTDATED_REMOTE;
default:
break;
}
}
return null;
}
};
public static Function<ThSyncElementInfo, SynchronizedElementInfo> toSynchronizedElementInfo = new Function<ThSyncElementInfo, SynchronizedElementInfo>() {
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);
}
};
} }

View File

@ -7,15 +7,13 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; 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.ItemNotSynched;
import org.gcube.portal.wssynclibrary.shared.WorkspaceFolderLocked; import org.gcube.portal.wssynclibrary.shared.WorkspaceFolderLocked;
import org.gcube.portal.wssynclibrary.shared.thredds.Status; 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.ThCatalogueBean;
import org.gcube.portal.wssynclibrary.shared.thredds.ThProcessDescriptor; import org.gcube.portal.wssynclibrary.shared.thredds.ThProcessDescriptor;
import org.gcube.portal.wssynclibrary.shared.thredds.ThProcessStatus; 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.ThSyncFolderDescriptor;
import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus; import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus;
import org.gcube.portal.wssynclibrary.shared.thredds.ThSynchFolderConfiguration; import org.gcube.portal.wssynclibrary.shared.thredds.ThSynchFolderConfiguration;
@ -27,22 +25,23 @@ import org.gcube.usecases.ws.thredds.faults.ProcessNotFoundException;
import org.gcube.usecases.ws.thredds.faults.WorkspaceInteractionException; import org.gcube.usecases.ws.thredds.faults.WorkspaceInteractionException;
import org.gcube.usecases.ws.thredds.faults.WorkspaceLockedException; import org.gcube.usecases.ws.thredds.faults.WorkspaceLockedException;
import org.gcube.usecases.ws.thredds.faults.WorkspaceNotSynchedException; 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.SyncFolderDescriptor;
import org.gcube.usecases.ws.thredds.model.SyncOperationCallBack; import org.gcube.usecases.ws.thredds.model.SyncOperationCallBack;
import org.gcube.usecases.ws.thredds.model.SynchFolderConfiguration; 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.gcube.usecases.ws.thredds.model.gui.CatalogBean;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
// TODO: Auto-generated Javadoc // TODO: Auto-generated Javadoc
/** /**
* The Class WorkspaceThreddsSynchronize. * The Class WorkspaceThreddsSynchronize.
* *
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Feb 14, 2018
* Feb 14, 2018
*/ */
public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronizedRepository<ThSyncStatus, ThSyncFolderDescriptor>{ public class WorkspaceThreddsSynchronize
implements WorkspaceThreddsSynchronizedRepository<ThSyncStatus, ThSyncFolderDescriptor> {
/** The logger. */ /** The logger. */
private static Logger logger = LoggerFactory.getLogger(WorkspaceThreddsSynchronize.class); private static Logger logger = LoggerFactory.getLogger(WorkspaceThreddsSynchronize.class);
@ -53,10 +52,6 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized
/** The instance. */ /** The instance. */
private static WorkspaceThreddsSynchronize instance = null; private static WorkspaceThreddsSynchronize instance = null;
private static StorageHubClient storageHubInstance;
public static final String WS_SYNCH_SYNCH_STATUS = "WS-SYNCH.SYNCH-STATUS";
/** The map call back. */ /** The map call back. */
// Fully synchronized HashMap // Fully synchronized HashMap
private Map<String, ThSyncStatus> mapCallBack = Collections.synchronizedMap(new HashMap<>()); private Map<String, ThSyncStatus> mapCallBack = Collections.synchronizedMap(new HashMap<>());
@ -69,7 +64,6 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized
engine = SyncEngine.get(); engine = SyncEngine.get();
} }
/** /**
* Gets the single instance of WorkspaceThreddsSynchronize. * Gets the single instance of WorkspaceThreddsSynchronize.
* *
@ -78,30 +72,10 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized
public static WorkspaceThreddsSynchronize getInstance() { public static WorkspaceThreddsSynchronize getInstance() {
if (instance == null) { if (instance == null) {
instance = new WorkspaceThreddsSynchronize(); instance = new WorkspaceThreddsSynchronize();
storageHubInstance = new StorageHubClient();
} }
return instance; return instance;
} }
/**
* Gets the storage hub instance.
*
* @return the storage hub instance
*/
public static StorageHubClient getStorageHubInstance() {
if(storageHubInstance==null)
storageHubInstance = new StorageHubClient();
return storageHubInstance;
}
/* (non-Javadoc)
* @see org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#isItemSynchronized(java.lang.String)
*/
/** /**
* Check item synched. * Check item synched.
* *
@ -112,7 +86,8 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized
* @throws Exception the exception * @throws Exception the exception
*/ */
@Override @Override
public ThSyncFolderDescriptor checkItemSynched(String itemId) throws ItemNotSynched, WorkspaceFolderLocked, Exception { public ThSyncFolderDescriptor checkItemSynched(String itemId)
throws ItemNotSynched, WorkspaceFolderLocked, Exception {
logger.debug("Perfoming checkItemSynched for id: " + itemId); logger.debug("Perfoming checkItemSynched for id: " + itemId);
try { try {
// WHEN OPENING A FOLDER, INVOKE CHECK TO UPDATE SYNCH STATUS // WHEN OPENING A FOLDER, INVOKE CHECK TO UPDATE SYNCH STATUS
@ -131,21 +106,24 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized
// engine.setSynchronizedFolder(config, folder.getId()); // engine.setSynchronizedFolder(config, folder.getId());
} catch (WorkspaceLockedException e) { } catch (WorkspaceLockedException e) {
// logger.warn("Workspace locked, going to force unlock.."); // 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"); throw new WorkspaceFolderLocked(itemId,
"The folder id: " + itemId + " is currently locked. Another sync process is in progress");
// engine.forceUnlock(itemId); // engine.forceUnlock(itemId);
} catch (WorkspaceInteractionException | InternalException e) { } catch (WorkspaceInteractionException | InternalException e) {
logger.error("Error: ", e); logger.error("Error: ", e);
if (e instanceof WorkspaceInteractionException) if (e instanceof WorkspaceInteractionException)
throw new Exception("Sorry, an error occurred during check syncronization due to WS interection for the itemId: "+itemId); throw new Exception(
"Sorry, a WorkspaceInteraction error occurred during check syncronization for the itemId: "
+ itemId+". Try again or contact the support");
else if (e instanceof InternalException) 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 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); throw new Exception(
"Sorry, an error occurred server side during chck syncronization for the itemId: " + itemId+". Try again or contact the support");
} }
} }
/** /**
* Sets the synchronized folder. * Sets the synchronized folder.
* *
@ -154,7 +132,8 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized
* @return the th sync folder descriptor * @return the th sync folder descriptor
* @throws Exception the exception * @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); SynchFolderConfiguration config = ThreddsConverter.toSynchFolderConfiguration.apply(thConfig);
if (thConfig.getRemotePath() == null || thConfig.getRemotePath().isEmpty()) if (thConfig.getRemotePath() == null || thConfig.getRemotePath().isEmpty())
@ -163,9 +142,6 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized
if (thConfig.getToCreateCatalogName() == null || thConfig.getToCreateCatalogName().isEmpty()) if (thConfig.getToCreateCatalogName() == null || thConfig.getToCreateCatalogName().isEmpty())
throw new Exception("A valid Catalogue Name must be provided"); 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 { try {
engine.setSynchronizedFolder(config, itemId); engine.setSynchronizedFolder(config, itemId);
} catch (WorkspaceInteractionException | InternalException e) { } catch (WorkspaceInteractionException | InternalException e) {
@ -176,11 +152,6 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized
return null; return null;
} }
/* (non-Javadoc)
* @see org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#doSynchronization(java.lang.String)
*/
/** /**
* Do sync. * Do sync.
* *
@ -208,22 +179,12 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized
return synStatus; return synStatus;
} catch (WorkspaceInteractionException | InternalException | ProcessNotFoundException e) { } catch (WorkspaceInteractionException | InternalException | ProcessNotFoundException e) {
logger.error("Error: ",e); logger.error("DoSync Error: ", e);
throw 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);
} }
} }
/* (non-Javadoc)
* @see org.gcube.portal.wssynclibrary.DoSyncItem#getSyncStatus(java.lang.String)
*/
/** /**
* Monitor sync status. * Monitor sync status.
* *
@ -253,7 +214,8 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized
return thSyncStatus; return thSyncStatus;
} catch (ProcessNotFoundException e) { } catch (ProcessNotFoundException e) {
throw new Exception("Monitor is not available here. The sync process is in progress on another machine"); throw new Exception(
"Monitor is not available here. The sync process is in progress on another machine");
} }
} }
@ -274,124 +236,6 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized
} }
} }
/* (non-Javadoc)
* @see org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#removeSync(java.lang.String)
*/
/**
* Removes the sync.
*
* @param itemId the item id
* @return the boolean
*/
@Override
public Boolean removeSync(String itemId) {
return null;
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#stopSync(java.lang.String)
*/
/**
* Stop sync.
*
* @param itemId the item id
* @return the boolean
*/
@Override
public Boolean stopSync(String itemId) {
return false;
}
/* (non-Javadoc)
* @see org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#initRepository()
*/
/**
* Inits the repository.
*
* @return the boolean
*/
@Override
public Boolean initRepository() {
return false;
}
/* (non-Javadoc)
* @see org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#shutDownRepository()
*/
/**
* Shut down repository.
*
* @return the boolean
*/
@Override
public Boolean shutDownRepository() {
try {
engine.shutDown();
return true;
}catch (Exception e) {
return null;
}
}
/* (non-Javadoc)
* @see org.gcube.portal.wssynclibrary.thredds.WorkspaceThreddsSynchronizedRepository#decribeSyncRepository()
*/
/**
* Decribe sync repository.
*
* @return the string
*/
@Override
public String decribeSyncRepository() {
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<String, Object> 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. * Register callback for id.
* *
@ -418,7 +262,7 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized
}; };
// REGISTER CALLBACK TO MONITOR PROGRESS // REGISTER CALLBACK TO MONITOR PROGRESS
logger.debug("Registering callback on itemId: "+itemId); logger.debug("Registering callback for itemId: " + itemId);
engine.registerCallBack(itemId, callback); engine.registerCallBack(itemId, callback);
} catch (ProcessNotFoundException e) { } catch (ProcessNotFoundException e) {
logger.error("Register callback for id: " + itemId + " threw ProcessNotFoundException: ", e); logger.error("Register callback for id: " + itemId + " threw ProcessNotFoundException: ", e);
@ -429,7 +273,6 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized
} }
} }
/** /**
* Update map callback. * Update map callback.
* *
@ -444,46 +287,34 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized
logger.debug("Update map for " + itemId + " with new " + thStatus); logger.debug("Update map for " + itemId + " with new " + thStatus);
} }
/** /**
* Gets the available catalogues by token. * Gets the available catalogues. you need to set the context caller.
* *
* @param token the token * @return the available catalogues
* @return the available catalogues by token
* @throws Exception the exception * @throws Exception the exception
*/ */
public List<ThCatalogueBean> getAvailableCataloguesByToken(String token) throws Exception{ public List<ThCatalogueBean> getAvailableCatalogues() throws Exception {
logger.debug("called Get Available Catalogues");
if(token==null || token.isEmpty()) Set<CatalogBean> ctlgs = engine.getAvailableCatalogs();
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<CatalogBean> ctlgs = engine.getAvailableCatalogsByToken(token);
if (ctlgs == null || ctlgs.size() == 0) { if (ctlgs == null || ctlgs.size() == 0) {
logger.debug("No Catalogue available for token: "+printToken +" returning empty list"); logger.info("No Catalogue available in the current context, returning empty list");
return new ArrayList<ThCatalogueBean>(1); return new ArrayList<ThCatalogueBean>(1);
} }
List<ThCatalogueBean> listCtlgs = new ArrayList<ThCatalogueBean>(ctlgs.size()); List<ThCatalogueBean> listCtlgs = new ArrayList<ThCatalogueBean>(ctlgs.size());
for (CatalogBean bean : ctlgs) { for (CatalogBean bean : ctlgs) {
System.out.println(bean.getName()+" in "+bean.getPath()+" Default : "+bean.getIsDefault()); logger.debug(bean.getName() + " in " + bean.getPath() + " Default : " + bean.getIsDefault());
ThCatalogueBean toBean = ThreddsConverter.toThCatalogueBean.apply(bean); ThCatalogueBean toBean = ThreddsConverter.toThCatalogueBean.apply(bean);
if (toBean != null) if (toBean != null)
listCtlgs.add(toBean); listCtlgs.add(toBean);
} }
Collections.sort(listCtlgs); 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; return listCtlgs;
} }
/* (non-Javadoc)
* @see org.gcube.portal.wssynclibrary.DoSyncItem#doUnSync(java.lang.String)
*/
/** /**
* Do un sync. * Do un sync.
* *
@ -506,4 +337,175 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized
throw new Exception("An error occurred on deleting configuration to the item id: " + itemId, 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
*
* NB. it is time consuming due to it
* calls the SHUB
*/
@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, null);
}
/**
* 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<String, Object> itemProperties, ContainerType itemType)
throws WorkspaceNotSynchedException {
if (itemProperties == null || itemProperties.isEmpty())
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. This calls the {@link SyncEngine#parseInfo(Map, ContainerType)}
*
* @param itemId the item id
* @param itemProperties the item properties
* @param itemType the item type
* @return true, if is item synched
*/
public boolean isItemSynched(String itemId, Map<String, Object> itemProperties, ContainerType itemType) {
ThSyncElementInfo sinInfo = null;
try {
sinInfo = getElementInfo(itemProperties, itemType);
} catch (WorkspaceNotSynchedException e) {
logger.debug("WorkspaceNotSynchedException catched, the item id: " + itemId + " is not synched");
} catch (Exception e) {
logger.debug("Error on getting SyncElementInfo for the item id: " + itemId
+ ", returning null (means not synched)", e);
}
if (sinInfo != null)
return true;
return false;
}
/*
* (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) throws Exception {
throw new Exception("removeSync not implemented");
}
/*
* (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) throws Exception {
throw new Exception("stopSync not implemented");
}
/*
* (non-Javadoc)
*
* @see
* org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#initRepository
* ()
*/
/**
* Inits the repository.
*
* @return the boolean
* @throws Exception the exception
*/
@Override
public Boolean initRepository() throws Exception {
throw new Exception("initRepository not implemented");
}
/*
* (non-Javadoc)
*
* @see org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#
* shutDownRepository()
*/
/**
* Shut down repository.
*
* @return the boolean
*/
@Override
public Boolean shutDownRepository() {
try {
engine.shutDown();
return true;
} catch (Exception e) {
return null;
}
}
/*
* (non-Javadoc)
*
* @see
* org.gcube.portal.wssynclibrary.thredds.WorkspaceThreddsSynchronizedRepository
* #decribeSyncRepository()
*/
/**
* Decribe sync repository.
*
* @return the string
*/
@Override
public String decribeSyncRepository() {
return "Sync repository for Thredds";
}
} }

View File

@ -4,8 +4,6 @@ import org.gcube.portal.wssynclibrary.DoCheckSyncItem;
import org.gcube.portal.wssynclibrary.DoConnectRepository; import org.gcube.portal.wssynclibrary.DoConnectRepository;
import org.gcube.portal.wssynclibrary.DoSyncItem; import org.gcube.portal.wssynclibrary.DoSyncItem;
// TODO: Auto-generated Javadoc
/** /**
* The Interface WorkspaceThreddsSynchronizedRepository. * The Interface WorkspaceThreddsSynchronizedRepository.
* *

1
target/.gitignore vendored
View File

@ -1 +0,0 @@
/classes/