Skip to content

Commit

Permalink
added regular expression
Browse files Browse the repository at this point in the history
Issue #177
  • Loading branch information
rsoika committed Jun 19, 2023
1 parent 73d165b commit b4c4566
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
11 changes: 10 additions & 1 deletion imixs-archive-exporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,20 @@ The Imixs-Archive-Exporter is controlled by corresponding [EventLog Entries](htt
<timeout>60000</timeout>
<document>
<path>my-documents/</path>
<filter>\.pdf$</filter>
</document>
</eventlog>
```

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Map> 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 {
Expand All @@ -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++;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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));

}

}

0 comments on commit b4c4566

Please sign in to comment.