Reputation: 480
I wonder what is the purpose of 'filterDirectory' parameter in Camel File component. I didn't managed to find any examples with this property. According to docs:
Filters the directory based on Simple language. For example to filter on current date, you can use a simple date pattern such as ${date:now:yyyMMdd}.
I wrote some sample route to check it behaviour:
public class FilterDirectoryRoute extends RouteBuilder {
private static final String FILE = "file:";
private static final String START_DIR = "C:/test/camel/filterDirectoryRoute";
private final Map<String, String> params = Map.of(
"noop", "true",
"recursive", "true",
"filterDirectory", "${date:now:yyyy/DDD}"
);
@Override
public void configure() {
from(FILE + START_DIR + fileParams(params))
.log(DEBUG, log, "date = ${date:now:yyyy/DDD}")
.log(DEBUG, log, "body = ${body}")
.end();
}
}
There is next structure of filterDirectoryRoute
directory:
π¦filterDirectoryRoute
β£ π2020
β β£ π1.txt
β β£ π105.txt
β β π15.txt
β π2021
β β£ π268
β β β π268.txt
β β£ π269
β β β π269.txt
β β£ π270
β β β π270.txt
β β£ π271
β β β π271.txt
β β£ π272
β β β π272.txt
With such configuration the route just traverse all files in directory and read it. So the filterDirectory
has no effect as it doesn't enter 2021/270
(270 is the current day of the year).
If I delete recursive
parameter no files are processed as there are no files in starting directory directly.
So the question is: how filterDirectory
option can be used and what it does?
Upvotes: 0
Views: 611
Reputation: 118
It seems to me that the filterDirectory
query-parameter is used in conjunction with the File Language. That means that you would have to construct a filter that in essence produces a boolean result. Something akin to filterDirectory="${file:name} == ${date:now:yyyy/DDD}"
.
NOTE: I have not verified this myself.
The following works and only reads the file 2.txt
.
@Component
public class SampleFileRoute extends RouteBuilder {
@Override
public void configure() throws Exception {
from("file://folder?recursive=true&filterDirectory=${file:name} == 2021")
.log("${header.CamelFileRelativePath}");
}
}
π¦folder
β£ π2020
β β£ π1.txt
β π2021
β β£ π2.txt
Upvotes: 4