diff --git a/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java b/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java index cf542ca..24cfb5c 100644 --- a/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java +++ b/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java @@ -209,16 +209,27 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized try { - //ThSyncFolderDescriptor descr = checkItemSynched(itemId); ThSyncStatus synStatus = mapCallBack.get(itemId); - if(synStatus==null) { - logger.info("The sync is not on-going...,returning process status null"); -// String err = "The item id: "+itemId +" is not cached as synched"; -// throw new ItemNotSynched(err); - return new ThSyncStatus(null, null); + + try{ + + registerCallbackForId(itemId); + ProcessDescriptor descriptor = engine.getProcessDescriptorByFolderId(itemId); + ProcessStatus status = engine.getProcessStatusByFolderId(itemId); + updateMapCallback(itemId, status, descriptor); + ThSyncStatus thSyncStatus = mapCallBack.get(itemId); + + if(thSyncStatus==null) + throw new Exception("No sync status found for item id: "+itemId); + + return thSyncStatus; + + }catch(ProcessNotFoundException e){ + throw new Exception("Monitor is not available here. The sync process is in progress on another machine"); + } } if(synStatus.getProcessStatus()!=null) { @@ -233,11 +244,8 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized logger.trace("MonitorSyncStatus for item: "+itemId+" returning: "+synStatus); return synStatus; -// } catch (ItemNotSynched e) { -// String err = "The item id: "+itemId +" is not synched repository side"; -// throw new ItemNotSynched(err); } catch (Exception e) { - throw new Exception("Sorry, an error occurred during syncronization for itemId: "+itemId); + throw new Exception("Sorry, an error occurred during getting sync status for itemId: "+itemId, e); } } @@ -356,7 +364,7 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized * @throws Exception the exception */ @Override - public void registerCallbackForId(String itemId) throws Exception{ + public void registerCallbackForId(String itemId) throws ProcessNotFoundException, Exception{ try { @@ -377,8 +385,11 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized logger.debug("Registering callback on 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("No Process found for item id: "+itemId+ ", refresh an try again"); + throw new Exception("An error occurred on registering callback for: "+itemId, e); } }