integrated with SyncEngine.parseInfo
This commit is contained in:
parent
e4614f70ef
commit
60a2e10117
|
@ -35,14 +35,4 @@ public interface DoCheckSyncItem<T> {
|
|||
* @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;
|
||||
|
||||
}
|
||||
|
|
|
@ -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<SynchronizedElementInfo, ThSyncElementInfo> toThElementInfo = new Function<SynchronizedElementInfo, ThSyncElementInfo>() {
|
||||
public static Function<SynchronizedElementInfo, ThSyncElementInfo> toThSyncElementInfo = new Function<SynchronizedElementInfo, ThSyncElementInfo>() {
|
||||
|
||||
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<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:
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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<String, Object> 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<String, Object> 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;
|
||||
|
|
Loading…
Reference in New Issue