updated the getConfiguration method
This commit is contained in:
parent
ae835cee16
commit
db1e0729a3
|
@ -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<String, ThSyncStatus> 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<ThCatalogueBean> getAvailableCatalogues() throws Exception {
|
||||
logger.debug("called Get Available Catalogues");
|
||||
Set<CatalogBean> ctlgs = engine.getAvailableCatalogs();
|
||||
|
||||
if (ctlgs == null || ctlgs.size() == 0) {
|
||||
logger.info("No Catalogue available in the current context, returning empty list");
|
||||
return new ArrayList<ThCatalogueBean>(1);
|
||||
}
|
||||
|
||||
List<ThCatalogueBean> listCtlgs = new ArrayList<ThCatalogueBean>(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<ThCatalogueBean> getAvailableCatalogues() throws Exception {
|
||||
logger.debug("called Get Available Catalogues");
|
||||
Set<CatalogBean> ctlgs = engine.getAvailableCatalogs();
|
||||
|
||||
if (ctlgs == null || ctlgs.size() == 0) {
|
||||
logger.info("No Catalogue available in the current context, returning empty list");
|
||||
return new ArrayList<ThCatalogueBean>(1);
|
||||
}
|
||||
|
||||
List<ThCatalogueBean> listCtlgs = new ArrayList<ThCatalogueBean>(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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue