diff --git a/imixs-archive-exporter/README.md b/imixs-archive-exporter/README.md index 53bc872..5c68943 100644 --- a/imixs-archive-exporter/README.md +++ b/imixs-archive-exporter/README.md @@ -16,11 +16,20 @@ The Imixs-Archive-Exporter is controlled by corresponding [EventLog Entries](htt 60000 my-documents/ + \.pdf$ ``` -On each corresponding worklfow event a new event log entry `file.export` will be created. The Imixs-Archive-Exporter periodically check this event log entries and exports the corresponding files into a configured data space. +On each corresponding workflow event a new event log entry `file.export` will be created. The Imixs-Archive-Exporter periodically check this event log entries and exports the corresponding files into a configured data space. + +## Path + +The optional event parameter `path` can be used to specify the target path for the file to be exported. + +## Filter + +The optional event parameter `filter` can be used to specify a regular expression to match the file name. This option can be used to export only a part of file from a workitem. For example the regular expression `\.pdf$` exports only files with the suffix '.pdf'. # Configuration diff --git a/imixs-archive-exporter/src/main/java/org/imixs/archive/export/services/SchedulerService.java b/imixs-archive-exporter/src/main/java/org/imixs/archive/export/services/SchedulerService.java index 81b4550..62c1b1d 100644 --- a/imixs-archive-exporter/src/main/java/org/imixs/archive/export/services/SchedulerService.java +++ b/imixs-archive-exporter/src/main/java/org/imixs/archive/export/services/SchedulerService.java @@ -26,6 +26,8 @@ import java.util.Map; import java.util.Optional; import java.util.logging.Logger; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.eclipse.microprofile.config.inject.ConfigProperty; import org.eclipse.microprofile.metrics.MetricRegistry; @@ -232,11 +234,17 @@ public void onTimeout(jakarta.ejb.Timer _timer) { id = eventLogEntry.getItemValueString("id"); ref = eventLogEntry.getItemValueString("ref"); String path = ""; + String filter = ""; + Pattern pattern = null; // test if we have a data structure with a path information List dataList = eventLogEntry.getItemValue("data"); if (dataList != null && dataList.size() > 0) { ItemCollection dataItemCol = new ItemCollection(dataList.get(0)); path = dataItemCol.getItemValueString("path"); + filter = dataItemCol.getItemValueString("filter"); + if (!filter.isEmpty()) { + pattern = Pattern.compile(filter); + } } try { @@ -247,6 +255,15 @@ public void onTimeout(jakarta.ejb.Timer _timer) { // iterate over all Files and export it for (FileData fileData : fileDataList) { + // in case of a exiting filter, we test if the file name matches the filter + // criteria + if (pattern != null) { + Matcher matcher = pattern.matcher(fileData.getName()); + if (!matcher.find()) { + // no match! + continue; + } + } fileService.writeFileData(fileData, path); success++; } diff --git a/imixs-archive-exporter/src/test/java/org/imixs/archive/exporter/TestFilter.java b/imixs-archive-exporter/src/test/java/org/imixs/archive/exporter/TestFilter.java new file mode 100644 index 0000000..5a795ca --- /dev/null +++ b/imixs-archive-exporter/src/test/java/org/imixs/archive/exporter/TestFilter.java @@ -0,0 +1,38 @@ +package org.imixs.archive.exporter; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Test the Optional expression + * + * @author rsoika + * + */ +public class TestFilter { + + /** + * Test filter regex + * + */ + @Test + public void testOptional() { + String name = "example.pdf"; + + String filter = "(\\.pdf$)"; + + Pattern pattern = Pattern.compile(filter); + Matcher matcher = pattern.matcher(name); + + if (!matcher.find()) { + Assert.fail(); + } + + // Assert.assertTrue(name.matches(filter)); + + } + +}