Skip to content
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 @@ -9,6 +9,7 @@
import org.opensearch.dataprepper.model.annotations.AlsoRequired;
import org.opensearch.dataprepper.plugins.processor.mutateevent.TargetType;
import org.opensearch.dataprepper.typeconverter.TypeConverter;
import com.google.common.annotations.VisibleForTesting;

import java.util.HashMap;
import java.util.LinkedHashMap;
Expand All @@ -21,7 +22,6 @@
public class TargetsParameterConfig {
static final String MAP_KEY = "map";
static final String REGEX_KEY = "regex";
private final TypeConverter converter;
private final LinkedHashMap<Range<Float>, Object> rangeMappings = new LinkedHashMap<>();
private final Map<String, Object> individualMappings = new HashMap<>();
private final Map<Pattern, Object> compiledPatterns = new HashMap<>();
Expand Down Expand Up @@ -57,18 +57,17 @@ public class TargetsParameterConfig {
@JsonPropertyDescription("Specifies the data type for the target value.")
private TargetType targetType = TargetType.STRING;

public TargetsParameterConfig(){
converter = TargetType.STRING.getTargetConverter();
}
public TargetsParameterConfig(Map<String, Object> map, String target, RegexParameterConfiguration regexParameterConfig, String translateWhen, String defaultValue, TargetType targetType) {
public TargetsParameterConfig(){}

@VisibleForTesting
TargetsParameterConfig(Map<String, Object> map, String target, RegexParameterConfiguration regexParameterConfig, String translateWhen, String defaultValue, TargetType targetType) {
this.targetType = Optional
.ofNullable(targetType)
.orElse(TargetType.STRING);
this.target = target;
this.map = map;
this.defaultValue = defaultValue;
this.regexParameterConfig = regexParameterConfig;
this.converter = this.targetType.getTargetConverter();
this.translateWhen = translateWhen;
parseMappings();
}
Expand Down Expand Up @@ -109,11 +108,6 @@ public Map<Pattern, Object> fetchCompiledPatterns() {
return compiledPatterns;
}

public TypeConverter getConverter() {
return converter;
}


@AssertTrue(message = "pattern option is mandatory while configuring regex option")
public boolean isPatternPresent() {
return regexParameterConfig == null || regexParameterConfig.getPatterns() != null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private String getSourceValue(Object recordObject, String sourceKey) {
}

private Object getTargetValue(Object sourceObject, List<Object> targetValues, TargetsParameterConfig targetConfig) {
TypeConverter converter = targetConfig.getConverter();
TypeConverter converter = targetConfig.getTargetType().getTargetConverter();
if(sourceObject instanceof String) {
return converter.convert(targetValues.get(0));
}
Expand Down
Loading