Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translate Processor: Changed non-exact matching logic #3046

Merged
merged 1 commit into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,13 @@ private Optional<Object> matchesPatternEntry(final String sourceValue, TargetsPa
final boolean exact = targetConfig.getRegexParameterConfiguration().getExact();
for (Pattern pattern : compiledPatterns.keySet()) {
Matcher matcher = pattern.matcher(sourceValue);
if (matcher.matches() || (!exact && matcher.find())) {
if (matcher.matches()) {
return Optional.of(compiledPatterns.get(pattern));
}
if(!exact && matcher.find()) {
String targetValue = (String)compiledPatterns.get(pattern);
return Optional.of(matcher.replaceAll(targetValue));
}
}
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ void test_non_exact_matching() {
when(mockRegexConfig.getExact()).thenReturn(false);
when(mockRegexConfig.getPatterns()).thenReturn(createMapEntries(
createMapping("^(1[0-9]|20)$", "patternValue1"),
createMapping("foo", "bar2")));
createMapping("foo", "bar")));
targetsParameterConfig = new TargetsParameterConfig(null, "targetField", mockRegexConfig, null, null, null);
when(mappingsParameterConfig.getTargetsParameterConfigs()).thenReturn(List.of(targetsParameterConfig));

Expand All @@ -400,7 +400,13 @@ void test_non_exact_matching() {
final List<Record<Event>> translatedRecords = (List<Record<Event>>) processor.doExecute(Collections.singletonList(record));

assertTrue(translatedRecords.get(0).getData().containsKey("targetField"));
assertThat(translatedRecords.get(0).getData().get("targetField", String.class), is("bar2"));
assertThat(translatedRecords.get(0).getData().get("targetField", String.class), is("barter"));

final Record<Event> replaceAllRecord = getEvent("foofoo");
final List<Record<Event>> translatedReplaceAllRecords = (List<Record<Event>>) processor.doExecute(Collections.singletonList(replaceAllRecord));

assertTrue(translatedReplaceAllRecords.get(0).getData().containsKey("targetField"));
assertThat(translatedReplaceAllRecords.get(0).getData().get("targetField", String.class), is("barbar"));

final Record<Event> regexRecord = getEvent("15");
final List<Record<Event>> translatedRegexRecords = (List<Record<Event>>) processor.doExecute(Collections.singletonList(regexRecord));
Expand Down
Loading