Skip to content
Snippets Groups Projects
Commit 8fd0e78a authored by gpawel's avatar gpawel
Browse files

[LMS-2181] more like expressions

SVN: 21637
parent 3d4ededb
No related branches found
No related tags found
No related merge requests found
...@@ -84,11 +84,15 @@ public class DatabaseBasedDataSetPathInfoProvider implements IDataSetPathInfoPro ...@@ -84,11 +84,15 @@ public class DatabaseBasedDataSetPathInfoProvider implements IDataSetPathInfoPro
public List<DataSetFileRecord> listDataSetFilesByRelativePathLikeExpression(long dataSetId, public List<DataSetFileRecord> listDataSetFilesByRelativePathLikeExpression(long dataSetId,
String relativePathLikeExpression); String relativePathLikeExpression);
// FIXME we should have 2 methods, one with regexp one with like
@Select(SELECT_DATA_SET_FILES @Select(SELECT_DATA_SET_FILES
+ "WHERE dase_id = ?{1} AND relative_path = '?{2}' AND file_name ~ ?{3}") + "WHERE dase_id = ?{1} AND relative_path = '?{2}' AND file_name ~ ?{3}")
public List<DataSetFileRecord> listDataSetFilesByFilenameRegex(long dataSetId, public List<DataSetFileRecord> listDataSetFilesByFilenameRegex(long dataSetId,
String startingPath, String filenameRegex); String startingPath, String filenameRegex);
@Select(SELECT_DATA_SET_FILES
+ "WHERE dase_id = ?{1} AND relative_path = '?{2}' AND file_name LIKE ?{3}")
public List<DataSetFileRecord> listDataSetFilesByFilenameLikeExpression(long dataSetId,
String startingPath, String filenameLikeExpression);
} }
private static interface ILoader private static interface ILoader
...@@ -216,9 +220,20 @@ public class DatabaseBasedDataSetPathInfoProvider implements IDataSetPathInfoPro ...@@ -216,9 +220,20 @@ public class DatabaseBasedDataSetPathInfoProvider implements IDataSetPathInfoPro
public List<DataSetPathInfo> listMatchingPathInfos(String startingPath, public List<DataSetPathInfo> listMatchingPathInfos(String startingPath,
String fileNamePattern) String fileNamePattern)
{ {
List<DataSetFileRecord> records = String likeExpressionOrNull =
dao.listDataSetFilesByFilenameRegex(dataSetId, startingPath, DBUtils.tryToTranslateRegExpToLikePattern(prepareDBStyleRegex(fileNamePattern));
prepareDBStyleRegex(fileNamePattern)); List<DataSetFileRecord> records;
if (likeExpressionOrNull == null)
{
records =
dao.listDataSetFilesByFilenameRegex(dataSetId, startingPath,
prepareDBStyleRegex(fileNamePattern));
} else
{
records =
dao.listDataSetFilesByFilenameLikeExpression(dataSetId, startingPath,
likeExpressionOrNull);
}
return asPathInfos(records); return asPathInfos(records);
} }
......
...@@ -335,12 +335,12 @@ public class DatabaseBasedDataSetPathInfoProviderTest extends AssertJUnit ...@@ -335,12 +335,12 @@ public class DatabaseBasedDataSetPathInfoProviderTest extends AssertJUnit
} }
@Test @Test
void testListMatchingPathInfosWithFileNamePattern() void testListMatchingPathInfosWithFileNameRegExpPattern()
{ {
ISingleDataSetPathInfoProvider provider = createSingleDataSetPathInfoProvider(); ISingleDataSetPathInfoProvider provider = createSingleDataSetPathInfoProvider();
final String startingPath = "dir"; final String startingPath = "dir";
final String regex = "child.*"; final String regex = "(child.*|child)";
// NOTE: data in records are not significant // NOTE: data in records are not significant
final DataSetFileRecord rc1 = record(3L, 2L, "dir/child_dir", "child_dir", 20, true); final DataSetFileRecord rc1 = record(3L, 2L, "dir/child_dir", "child_dir", 20, true);
...@@ -361,6 +361,33 @@ public class DatabaseBasedDataSetPathInfoProviderTest extends AssertJUnit ...@@ -361,6 +361,33 @@ public class DatabaseBasedDataSetPathInfoProviderTest extends AssertJUnit
check(rc2, list.get(1)); check(rc2, list.get(1));
} }
@Test
void testListMatchingPathInfosWithFileNameLikePattern()
{
ISingleDataSetPathInfoProvider provider = createSingleDataSetPathInfoProvider();
final String startingPath = "dir";
final String regex = "child.*";
// NOTE: data in records are not significant
final DataSetFileRecord rc1 = record(3L, 2L, "dir/child_dir", "child_dir", 20, true);
final DataSetFileRecord rc2 = record(4L, 2L, "dir/child_file", "child_file", 30, false);
context.checking(new Expectations()
{
{
one(dao).listDataSetFilesByFilenameLikeExpression(DATA_SET_ID, startingPath,
"child%");
will(returnValue(Arrays.asList(rc1, rc2)));
}
});
List<DataSetPathInfo> list = provider.listMatchingPathInfos(startingPath, regex);
sort(list);
check(rc1, list.get(0));
check(rc2, list.get(1));
}
private ISingleDataSetPathInfoProvider createSingleDataSetPathInfoProvider() private ISingleDataSetPathInfoProvider createSingleDataSetPathInfoProvider()
{ {
return new DatabaseBasedDataSetPathInfoProvider.SingleDataSetPathInfoProvider(DATA_SET_ID, return new DatabaseBasedDataSetPathInfoProvider.SingleDataSetPathInfoProvider(DATA_SET_ID,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment