diff --git a/datastore_server/source/java/ch/systemsx/cisd/etlserver/path/DataSetAndPathInfoDBConsistencyCheckTask.java b/datastore_server/source/java/ch/systemsx/cisd/etlserver/path/DataSetAndPathInfoDBConsistencyCheckTask.java index ca810a1a52cd5e45297487274f2484bd47d46ecf..5d3f2b3b55e7af4a23a937cd71e5dc0124d6a4e9 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/etlserver/path/DataSetAndPathInfoDBConsistencyCheckTask.java +++ b/datastore_server/source/java/ch/systemsx/cisd/etlserver/path/DataSetAndPathInfoDBConsistencyCheckTask.java @@ -20,22 +20,26 @@ import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import java.util.Properties; +import java.util.stream.Collectors; import org.apache.commons.lang.time.DateUtils; import org.apache.log4j.Logger; +import ch.ethz.sis.openbis.generic.asapi.v3.IApplicationServerApi; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset.DataSet; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset.fetchoptions.DataSetFetchOptions; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset.search.DataSetSearchCriteria; import ch.systemsx.cisd.common.logging.LogCategory; import ch.systemsx.cisd.common.logging.LogFactory; import ch.systemsx.cisd.common.maintenance.IMaintenanceTask; import ch.systemsx.cisd.common.time.DateTimeUtils; import ch.systemsx.cisd.common.utilities.ITimeProvider; import ch.systemsx.cisd.common.utilities.SystemTimeProvider; -import ch.systemsx.cisd.openbis.dss.generic.shared.IEncapsulatedOpenBISService; +import ch.systemsx.cisd.openbis.dss.generic.server.openbisauth.OpenBISAuthenticationInterceptor; import ch.systemsx.cisd.openbis.dss.generic.shared.IHierarchicalContentProvider; import ch.systemsx.cisd.openbis.dss.generic.shared.ServiceProvider; import ch.systemsx.cisd.openbis.dss.generic.shared.utils.DataSetAndPathInfoDBConsistencyChecker; import ch.systemsx.cisd.openbis.generic.shared.basic.BasicConstant; -import ch.systemsx.cisd.openbis.generic.shared.dto.SimpleDataSetInformationDTO; /** * @author Franz-Josef Elmer @@ -53,7 +57,7 @@ public class DataSetAndPathInfoDBConsistencyCheckTask implements IMaintenanceTas private static final Logger notificationLog = LogFactory.getLogger(LogCategory.NOTIFY, DataSetAndPathInfoDBConsistencyCheckTask.class); - private IEncapsulatedOpenBISService service; + private IApplicationServerApi service; private IHierarchicalContentProvider fileProvider; @@ -68,7 +72,7 @@ public class DataSetAndPathInfoDBConsistencyCheckTask implements IMaintenanceTas } DataSetAndPathInfoDBConsistencyCheckTask(IHierarchicalContentProvider fileProvider, - IHierarchicalContentProvider pathInfoProvider, IEncapsulatedOpenBISService service, + IHierarchicalContentProvider pathInfoProvider, IApplicationServerApi service, ITimeProvider timeProvider) { this.fileProvider = fileProvider; @@ -89,13 +93,20 @@ public class DataSetAndPathInfoDBConsistencyCheckTask implements IMaintenanceTas public void execute() { Date youngerThanDate = new Date(getTimeProvider().getTimeInMilliseconds() - timeInterval); - List<SimpleDataSetInformationDTO> dataSets = - getService().listOldestPhysicalDataSets(youngerThanDate, Integer.MAX_VALUE); + String sessionToken = login(); + DataSetSearchCriteria searchCriteria = new DataSetSearchCriteria(); + searchCriteria.withRegistrationDate().thatIsLaterThanOrEqualTo(youngerThanDate); + searchCriteria.withPhysicalData(); + DataSetFetchOptions fetchOptions = new DataSetFetchOptions(); + fetchOptions.withPhysicalData(); + List<DataSet> dataSets = getV3Api().searchDataSets(sessionToken, searchCriteria, fetchOptions).getObjects(); + List<String> dataSetCodes = dataSets.stream() + .map(dataSet -> dataSet.getCode()).collect(Collectors.toList()); operationLog.info("Check " + dataSets.size() + " data sets registered since " + DATE_FORMAT.format(youngerThanDate)); DataSetAndPathInfoDBConsistencyChecker checker = new DataSetAndPathInfoDBConsistencyChecker(fileProvider, pathInfoProvider); - checker.check(dataSets); + checker.checkDataSets(dataSetCodes); if (checker.noErrorAndInconsitencyFound() == false) { StringBuilder builder = new StringBuilder(); @@ -104,13 +115,24 @@ public class DataSetAndPathInfoDBConsistencyCheckTask implements IMaintenanceTas builder.append(checker.createReport()); notificationLog.error(builder.toString()); } + getV3Api().logout(sessionToken); } - - private IEncapsulatedOpenBISService getService() + + String login() + { + OpenBISAuthenticationInterceptor authenticationInterceptor + = ServiceProvider.getApplicationContext().getBean(OpenBISAuthenticationInterceptor.class); + String username = authenticationInterceptor.getUsername(); + String password = authenticationInterceptor.getPassword(); + String sessionToken = getV3Api().login(username, password); + return sessionToken; + } + + private IApplicationServerApi getV3Api() { if (service == null) { - service = ServiceProvider.getOpenBISService(); + service = ServiceProvider.getV3ApplicationService(); } return service; } diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/openbisauth/OpenBISAuthenticationInterceptor.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/openbisauth/OpenBISAuthenticationInterceptor.java index 67afb4ea490c8aa8cbda56a87c0b8c09b429cd48..a9faf3d594a8691d09986a7850e17f4724428a95 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/openbisauth/OpenBISAuthenticationInterceptor.java +++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/openbisauth/OpenBISAuthenticationInterceptor.java @@ -193,6 +193,16 @@ public class OpenBISAuthenticationInterceptor implements MethodInterceptor this.username = username; } + public String getUsername() + { + return username; + } + + public String getPassword() + { + return password; + } + public final void setPassword(String password) { this.password = password; diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/utils/DataSetAndPathInfoDBConsistencyChecker.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/utils/DataSetAndPathInfoDBConsistencyChecker.java index 06f5c407a126796827cbc7808cb7ac3cdc561db7..84a21024f9eb90aab5cc0d95843eb0543c6879e7 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/utils/DataSetAndPathInfoDBConsistencyChecker.java +++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/utils/DataSetAndPathInfoDBConsistencyChecker.java @@ -21,14 +21,12 @@ import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; import java.util.TreeMap; import java.util.stream.Collectors; -import java.util.stream.Stream; import org.apache.log4j.Logger; diff --git a/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/path/DataSetAndPathInfoDBConsistencyCheckTaskTest.java b/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/path/DataSetAndPathInfoDBConsistencyCheckTaskTest.java index 6018aaac8f0c25e79ba5c8868800a8eaeb3e58b8..dbe0224a51785c620a68f29343bfcdee88632e6b 100644 --- a/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/path/DataSetAndPathInfoDBConsistencyCheckTaskTest.java +++ b/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/path/DataSetAndPathInfoDBConsistencyCheckTaskTest.java @@ -32,17 +32,20 @@ import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; +import ch.ethz.sis.openbis.generic.asapi.v3.IApplicationServerApi; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.common.search.SearchResult; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset.DataSet; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset.PhysicalData; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset.fetchoptions.DataSetFetchOptions; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset.search.DataSetSearchCriteria; import ch.systemsx.cisd.common.logging.BufferedAppender; +import ch.systemsx.cisd.common.test.RecordingMatcher; import ch.systemsx.cisd.common.utilities.MockTimeProvider; import ch.systemsx.cisd.openbis.dss.generic.server.plugins.standard.MockContent; -import ch.systemsx.cisd.openbis.dss.generic.shared.IEncapsulatedOpenBISService; import ch.systemsx.cisd.openbis.dss.generic.shared.IHierarchicalContentProvider; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PhysicalDataSet; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.builders.DataSetBuilder; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.builders.DataStoreBuilder; -import ch.systemsx.cisd.openbis.generic.shared.dto.SimpleDataSetInformationDTO; -import ch.systemsx.cisd.openbis.generic.shared.translator.DataSetTranslator; -import ch.systemsx.cisd.openbis.generic.shared.translator.SimpleDataSetHelper; import ch.systemsx.cisd.openbis.util.LogRecordingUtils; /** @@ -50,11 +53,13 @@ import ch.systemsx.cisd.openbis.util.LogRecordingUtils; */ public class DataSetAndPathInfoDBConsistencyCheckTaskTest extends AssertJUnit { + private static final String SESSION_TOKEN = "session-123"; + private BufferedAppender logRecorder; private Mockery context; - private IEncapsulatedOpenBISService service; + private IApplicationServerApi service; private IHierarchicalContentProvider fileProvider; @@ -67,12 +72,23 @@ public class DataSetAndPathInfoDBConsistencyCheckTaskTest extends AssertJUnit { logRecorder = LogRecordingUtils.createRecorder("%-5p %c - %m%n", Level.INFO); context = new Mockery(); - service = context.mock(IEncapsulatedOpenBISService.class); + service = context.mock(IApplicationServerApi.class); fileProvider = context.mock(IHierarchicalContentProvider.class, "fileProvider"); pathInfoProvider = context.mock(IHierarchicalContentProvider.class, "pathInfoProvider"); task = new DataSetAndPathInfoDBConsistencyCheckTask(fileProvider, pathInfoProvider, - service, new MockTimeProvider(2010, 1000)); + service, new MockTimeProvider(2010, 1000)){ + @Override + String login() + { + return SESSION_TOKEN; + }}; + context.checking(new Expectations() + { + { + allowing(service).logout(SESSION_TOKEN); + } + }); Properties properties = new Properties(); properties.setProperty(DataSetAndPathInfoDBConsistencyCheckTask.CHECKING_TIME_INTERVAL_KEY, "1500 msec"); @@ -233,21 +249,33 @@ public class DataSetAndPathInfoDBConsistencyCheckTaskTest extends AssertJUnit private void prepareListDataSets(final Date youngerThanDate, final PhysicalDataSet... dataSets) { - final List<SimpleDataSetInformationDTO> translatedDataSets = - new ArrayList<SimpleDataSetInformationDTO>(); + List<DataSet> translatedDataSets = new ArrayList<DataSet>(); for (PhysicalDataSet physicalDataSet : dataSets) { - translatedDataSets.add(SimpleDataSetHelper.translate(DataSetTranslator - .translateToDescription(physicalDataSet))); + translatedDataSets.add(translate(physicalDataSet)); } context.checking(new Expectations() { { - one(service).listOldestPhysicalDataSets(youngerThanDate, Integer.MAX_VALUE); - will(returnValue(translatedDataSets)); + one(service).searchDataSets(with(SESSION_TOKEN), with(new RecordingMatcher<DataSetSearchCriteria>()), + with(new RecordingMatcher<DataSetFetchOptions>())); + will(returnValue(new SearchResult<>(translatedDataSets, translatedDataSets.size()))); } }); } + + private DataSet translate(PhysicalDataSet dataSet) + { + DataSet translatedDataSet = new DataSet(); + DataSetFetchOptions fetchOptions = new DataSetFetchOptions(); + fetchOptions.withPhysicalData(); + translatedDataSet.setFetchOptions(fetchOptions); + translatedDataSet.setCode(dataSet.getCode()); + PhysicalData physicalData = new PhysicalData(); + physicalData.setLocation(dataSet.getLocation()); + translatedDataSet.setPhysicalData(physicalData); + return translatedDataSet; + } private DataSetBuilder createDataSetBuilder() {