Reputation: 13
I`m trying to read some files from a directory and have a delay between the detection of the file and the process of the file. I have this in a builder pattern :
/**
* The build function that will create a CompositeFileListFilter with the given filters
*
* @return {@link CompositeFileListFilter} that contains all the filters added
*/
public CompositeFileListFilter<File> build() {
CompositeFileListFilter<File> compositeFileListFilter = new CompositeFileListFilter<>();
boolean existsFilters = false;
// Add the prevent duplicates filter
if (this.preventDuplicates) {
compositeFileListFilter.addFilter(new AcceptOnceFileListFilter<File>());
existsFilters = true;
} else {
compositeFileListFilter.addFilter(new AcceptAllFileListFilter<File>());
existsFilters = true;
}
// Add the ignore hidden filter
if (this.ignoreHidden) {
compositeFileListFilter.addFilter(new IgnoreHiddenFileListFilter());
existsFilters = true;
} // Add the pattern file name filter
if (this.patternFilter != null) {
compositeFileListFilter.addFilter(new SimplePatternFileListFilter(patternFilter));
existsFilters = true;
}
// Add the process file after a period of time filter
if (this.lastModifiedFileListFilterAge > 0) {
LastModifiedFileListFilter filter = new LastModifiedFileListFilter();
filter.setAge(lastModifiedFileListFilterAge);
compositeFileListFilter.addFilter(filter);
existsFilters = true;
}
// Check if compositeFileListFilter contains any filter
if (!existsFilters) {
throw new IllegalStateException("At least one filter should be provided!");
}
return compositeFileListFilter;
}
and i`m creating the filters like this
CompositeFileListFilter<File> filters = new IntegrationFlowFileFilterBuilder()
.ignoreHidden(true)
.preventDuplicates(false)
.patternFilter(returnInformationInputFolderSetup.getPatternFolder())
.lastModifiedFileListFilterAge(120)
.build();
The problem is that all the other filters are working and only theLastModifiedFileListFilter is not working.. i`m reading a file and is processed in less than a second.
Does anyone know why this filter is not working?
Upvotes: 1
Views: 1429
Reputation: 121427
I have just tested your use-case with the:
@Test
public void testLastModifiedInComposite() throws IOException {
CompositeFileListFilter<File> compositeFileListFilter = new CompositeFileListFilter<>();
compositeFileListFilter.addFilter(new AcceptAllFileListFilter<>());
compositeFileListFilter.addFilter(new IgnoreHiddenFileListFilter());
compositeFileListFilter.addFilter(new SimplePatternFileListFilter("*.foo"));
compositeFileListFilter.addFilter(new LastModifiedFileListFilter(120));
given(this.fileMock.getName())
.willReturn("test.foo");
given(this.fileMock.lastModified())
.willReturn(System.currentTimeMillis());
List<File> filteredFiles = compositeFileListFilter.filterFiles(new File[] { this.fileMock });
assertTrue(filteredFiles.isEmpty());
compositeFileListFilter.close();
}
Pay attention that I specify the current time for the lastmodified
and this file indeed doesn't path LastModifiedFileListFilter
. Therefore I get an empty result. Just because my file is too young to be accepted by the LastModifiedFileListFilter
.
I would suggest you to debug the CompositeFileListFilter.filterFiles()
method to be sure what really is going on.
Also pay attention that there is a ChainFileListFilter
for a bit different point of view for the filtering functionality:
https://docs.spring.io/spring-integration/docs/4.3.12.RELEASE/reference/html/files.html#file-reading
Upvotes: 2