added getInfo method from SyncEngine
This commit is contained in:
parent
3816d9f04b
commit
41715b3769
6
pom.xml
6
pom.xml
|
@ -87,11 +87,13 @@
|
|||
<!-- LOGGER -->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
|
|
@ -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<SynchronizedElementInfo, Sync_Status> toSyncStatus = new Function<SynchronizedElementInfo, Sync_Status>() {
|
||||
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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<String, ThSyncStatus> 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<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.
|
||||
*
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue