diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/DataSetTable.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/DataSetTable.java index a4459e54be7e9933711c37b1f5239a76a9ec786a..8a79d7f74182dda775c8a278c8e9c1352865a674 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/DataSetTable.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/DataSetTable.java @@ -22,9 +22,11 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedHashSet; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -863,6 +865,16 @@ public final class DataSetTable extends AbstractDataSetBusinessObject implements Map<DataStorePE, List<ExternalDataPE>> datasetsByStore = groupExternalDataByDataStores(); Map<DataStoreWithService, List<ExternalDataPE>> datasetsWithService = enrichWithService(datasetsByStore); + + boolean needRefresh = prepareForUnarchiving(datasetsWithService); + + if (needRefresh) + { + datasetsByStore = groupExternalDataByDataStores(); + datasetsWithService = + enrichWithService(datasetsByStore); + } + int result = filterByStatusAndUpdate(datasetsByStore, DataSetArchivingStatus.ARCHIVED, DataSetArchivingStatus.UNARCHIVE_PENDING); @@ -870,6 +882,52 @@ public final class DataSetTable extends AbstractDataSetBusinessObject implements return result; } + /** + * Asks datastore servers for the extended list of datasets to unarchive, and reloads itself. + * + * @return true if the reaload of data has happened + */ + private boolean prepareForUnarchiving(Map<DataStoreWithService, List<ExternalDataPE>> datasetsWithService) + { + List<String> result = new LinkedList<String>(); + + boolean enhancementsFound = false; + + for (Entry<DataStoreWithService, List<ExternalDataPE>> entry : datasetsWithService.entrySet()) + { + DataStoreWithService dssws = entry.getKey(); + DataStorePE dataStore = dssws.dataStore; + IDataStoreService service = dssws.service; + List<ExternalDataPE> datasets = entry.getValue(); + if (datasets.isEmpty()) + { + continue; + } + + List<String> dataSetCodes = new LinkedList<String>(); + for (ExternalDataPE data : datasets) + { + dataSetCodes.add(data.getCode()); + } + + List<String> enhancedCodes = service.getDataSetCodesForUnarchiving(dataStore.getSessionToken(), session.getSessionToken(), + dataSetCodes, tryGetLoggedUserId()); + result.addAll(enhancedCodes); + + if (new HashSet<String>(enhancedCodes).containsAll(dataSetCodes)) + { + enhancementsFound = true; + } + } + + if (enhancementsFound) + { + loadByDataSetCodes(result, false, true); + return true; + } + return false; + } + @Override public int lockDatasets() { diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/IDataStoreService.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/IDataStoreService.java index e941a8963f89aaa5f8f76dbe8b8999c4813f9b99..c3deba03d07429cad9a93907048daf8adc77bfd3 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/IDataStoreService.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/IDataStoreService.java @@ -127,6 +127,13 @@ public interface IDataStoreService public void unarchiveDatasets(String sessionToken, String userSessionToken, List<DatasetDescription> datasets, String userId, String userEmailOrNull); + /** + * Asks arcvhiver to provide an extended list of data sets to unarchive. + * + * @param userId id of user who initiated unarchiving. + */ + public List<String> getDataSetCodesForUnarchiving(String sessionToken, String userSessionToken, List<String> datasets, String userId); + /** * Gets the link from a service that supports the IReportingPluginTask#createLink method. *