removed getElementInfo from WorkspaceThreddsSynchronize and moved under

check method
This commit is contained in:
Francesco Mangiacrapa 2021-05-13 12:51:40 +02:00
parent db1e0729a3
commit cae34434fa
4 changed files with 153 additions and 62 deletions

View File

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

View File

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

View File

@ -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<SynchronizedElementInfo, Sync_Status> toSyncStatus = new Function<SynchronizedElementInfo, Sync_Status>() {
public Sync_Status apply(SynchronizedElementInfo sei) {
public static Function<SynchronizedElementInfo, ThSyncElementInfo> toThElementInfo = new Function<SynchronizedElementInfo, ThSyncElementInfo>() {
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<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

@ -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)
*