From f9b894b8d83548976e4ada818cec31a68029fcee Mon Sep 17 00:00:00 2001 From: felmer <felmer> Date: Mon, 6 Feb 2017 10:24:11 +0000 Subject: [PATCH] SSDM-4655: property 'data-set-types' replaced by 'data-set-type'. This less general solutions allows to nail down the search. SVN: 37686 --- .../path/PathInfoDatabaseRefreshingTask.java | 32 +++++++------------ .../PathInfoDatabaseRefreshingTaskTest.java | 25 +++++++-------- 2 files changed, 23 insertions(+), 34 deletions(-) diff --git a/datastore_server/source/java/ch/systemsx/cisd/etlserver/path/PathInfoDatabaseRefreshingTask.java b/datastore_server/source/java/ch/systemsx/cisd/etlserver/path/PathInfoDatabaseRefreshingTask.java index 3bfd3e8c7f6..9efe2419658 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/etlserver/path/PathInfoDatabaseRefreshingTask.java +++ b/datastore_server/source/java/ch/systemsx/cisd/etlserver/path/PathInfoDatabaseRefreshingTask.java @@ -25,7 +25,6 @@ import java.util.Comparator; import java.util.Date; import java.util.List; import java.util.Properties; -import java.util.regex.Pattern; import org.apache.log4j.Logger; @@ -44,7 +43,9 @@ import ch.systemsx.cisd.openbis.dss.generic.shared.utils.PathInfoDataSourceProvi import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.SearchCriteria; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.SearchCriteria.CompareMode; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.SearchCriteria.MatchClause; +import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.SearchCriteria.MatchClauseAttribute; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.SearchCriteria.MatchClauseTimeAttribute; +import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.SearchCriteria.SearchOperator; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.AbstractExternalData; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetArchivingStatus; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PhysicalDataSet; @@ -58,7 +59,7 @@ import net.lemnik.eodsql.QueryTool; */ public class PathInfoDatabaseRefreshingTask extends AbstractPathInfoDatabaseFeedingTask implements IMaintenanceTask { - static final String DATA_SET_TYPES_KEY = "data-set-types"; + static final String DATA_SET_TYPE_KEY = "data-set-type"; static final String TIME_STAMP_OF_YOUNGEST_DATA_SET_KEY = "time-stamp-of-youngest-data-set"; @@ -96,7 +97,7 @@ public class PathInfoDatabaseRefreshingTask extends AbstractPathInfoDatabaseFeed private int chunkSize; - private List<Pattern> dataSetTypePatterns; + private String dataSetType; public PathInfoDatabaseRefreshingTask() { @@ -137,7 +138,7 @@ public class PathInfoDatabaseRefreshingTask extends AbstractPathInfoDatabaseFeed } chunkSize = PropertyUtils.getInt(properties, CHUNK_SIZE_KEY, DEFAULT_CHUNK_SIZE); computeChecksum = PropertyUtils.getBoolean(properties, COMPUTE_CHECKSUM_KEY, true); - dataSetTypePatterns = PropertyUtils.getPatterns(properties, DATA_SET_TYPES_KEY); + dataSetType = properties.getProperty(DATA_SET_TYPE_KEY); } private String tryGetTimeStampAndCodeOfYoungestDataSet(Properties properties) @@ -200,8 +201,13 @@ public class PathInfoDatabaseRefreshingTask extends AbstractPathInfoDatabaseFeed { String timeStampAndCode = getLastTimeStampAndCode(); SearchCriteria searchCriteria = new SearchCriteria(); + searchCriteria.setOperator(SearchOperator.MATCH_ALL_CLAUSES); searchCriteria.addMatchClause(MatchClause.createTimeAttributeMatch(MatchClauseTimeAttribute.REGISTRATION_DATE, CompareMode.LESS_THAN_OR_EQUAL, extractTimeStamp(timeStampAndCode), "0")); + if (dataSetType != null) + { + searchCriteria.addMatchClause(MatchClause.createAttributeMatch(MatchClauseAttribute.TYPE, dataSetType)); + } List<AbstractExternalData> dataSets = service.searchForDataSets(searchCriteria); Collections.sort(dataSets, REVERSE_REGISTRATION_DATE_COMPARATOR); List<PhysicalDataSet> result = new ArrayList<>(); @@ -230,23 +236,7 @@ public class PathInfoDatabaseRefreshingTask extends AbstractPathInfoDatabaseFeed { return false; } - if (renderTimeStampAndCode(physicalDataSet).compareTo(timeStampAndCode) >= 0) - { - return false; - } - if (dataSetTypePatterns.isEmpty()) - { - return true; - } - String dataSetType = physicalDataSet.getDataSetType().getCode(); - for (Pattern dataSetTypePattern : dataSetTypePatterns) - { - if (dataSetTypePattern.matcher(dataSetType).matches()) - { - return true; - } - } - return false; + return renderTimeStampAndCode(physicalDataSet).compareTo(timeStampAndCode) < 0; } @Override diff --git a/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/path/PathInfoDatabaseRefreshingTaskTest.java b/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/path/PathInfoDatabaseRefreshingTaskTest.java index d7f06ee16d6..124d34648bc 100644 --- a/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/path/PathInfoDatabaseRefreshingTaskTest.java +++ b/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/path/PathInfoDatabaseRefreshingTaskTest.java @@ -210,38 +210,37 @@ public class PathInfoDatabaseRefreshingTaskTest extends AbstractFileSystemTestCa } @Test - public void testDataSetTypesSecondRun() + public void testDataSetTypeAndSecondRun() { Properties properties = new Properties(); properties.setProperty(TIME_STAMP_OF_YOUNGEST_DATA_SET_KEY, T5); File stateFile = new File(store, "ts.txt"); FileUtilities.writeToFile(stateFile, T3); properties.setProperty(PathInfoDatabaseRefreshingTask.STATE_FILE_KEY, stateFile.getPath()); - properties.setProperty(PathInfoDatabaseRefreshingTask.DATA_SET_TYPES_KEY, "A.*, B.*"); + properties.setProperty(PathInfoDatabaseRefreshingTask.DATA_SET_TYPE_KEY, "A"); task.setUp(null, properties); - PhysicalDataSet ds1 = new DataSetBuilder(1).code("wrong-type").type("C1").registrationDate(asDate(T1)) - .status(AVAILABLE).getDataSet(); - PhysicalDataSet ds2 = new DataSetBuilder(1).code("ds-2").type("A1").registrationDate(asDate(T1)) + PhysicalDataSet ds1 = new DataSetBuilder(1).code("ds-1").registrationDate(asDate(T1)) + .status(AVAILABLE).location("1/ds-1").getDataSet(); + PhysicalDataSet ds2 = new DataSetBuilder(1).code("ds-2").registrationDate(asDate(T2)) .status(AVAILABLE).location("1/ds-2").getDataSet(); - PhysicalDataSet ds3 = new DataSetBuilder(1).code("ds-3").type("B1").registrationDate(asDate(T2)) - .status(AVAILABLE).location("1/ds-3").getDataSet(); - PhysicalDataSet ds4 = new DataSetBuilder(1).code("too-young").type("B1").registrationDate(asDate(T4)) + PhysicalDataSet ds3 = new DataSetBuilder(1).code("too-young").registrationDate(asDate(T4)) .status(AVAILABLE).getDataSet(); - RecordingMatcher<SearchCriteria> criteriaMatcher = prepareGetPhysicalDataSets(ds1, ds2, ds3, ds4); + RecordingMatcher<SearchCriteria> criteriaMatcher = prepareGetPhysicalDataSets(ds1, ds2, ds3); + prepareDeleteAndLockDataSet(ds1); prepareDeleteAndLockDataSet(ds2); - prepareDeleteAndLockDataSet(ds3); task.execute(); assertEquals("SearchCriteria[MATCH_ALL_CLAUSES,[SearchCriteria.TimeAttributeMatchClause[" - + "ATTRIBUTE,REGISTRATION_DATE," + T3 + ",LESS_THAN_OR_EQUAL]],[]]", + + "ATTRIBUTE,REGISTRATION_DATE," + T3 + ",LESS_THAN_OR_EQUAL], " + + "SearchCriteria.AttributeMatchClause[ATTRIBUTE,TYPE,A,EQUALS]],[]]", criteriaMatcher.recordedObject().toString()); assertEquals(LOG_PREFIX + "Refresh path info for 2 physical data sets.\n" + - LOG_PREFIX + "Paths inside data set ds-3 successfully added to database.\n" + LOG_PREFIX + "Paths inside data set ds-2 successfully added to database.\n" + + LOG_PREFIX + "Paths inside data set ds-1 successfully added to database.\n" + LOG_PREFIX + "Path info for 2 physical data sets refreshed in 0 secs.", logRecorder.getLogContent()); - assertEquals(T1 + " [ds-2]", FileUtilities.loadToString(stateFile).trim()); + assertEquals(T1 + " [ds-1]", FileUtilities.loadToString(stateFile).trim()); } @Test -- GitLab