diff --git a/src/main/java/no/ssb/dapla/dlp/pseudo/func/map/MapFunc.java b/src/main/java/no/ssb/dapla/dlp/pseudo/func/map/MapFunc.java index 519ff1a..c0ea4d1 100644 --- a/src/main/java/no/ssb/dapla/dlp/pseudo/func/map/MapFunc.java +++ b/src/main/java/no/ssb/dapla/dlp/pseudo/func/map/MapFunc.java @@ -17,10 +17,16 @@ public class MapFunc extends AbstractPseudoFunc { public MapFunc(PseudoFuncConfig genericConfig) { super(genericConfig.getFuncDecl()); this.config = mapFuncConfigService.resolve(genericConfig); + this.mapper = loadMapper(); + this.mapper.setConfig(genericConfig.asMap()); + } + + public static Mapper loadMapper() { // TODO: Filter Service Implementation by some annotation (to choose the implementation that is used) - this.mapper = ServiceLoader.load(Mapper.class) + return ServiceLoader.load(Mapper.class) .findFirst() - .orElseThrow(() -> new IllegalStateException(getClass().getSimpleName() + " requires a " + Mapper.class.getName() + " implementation to be present on the classpath")); + .orElseThrow(() -> new IllegalStateException(MapFunc.class.getSimpleName() + " requires a " + + Mapper.class.getName() + " implementation to be present on the classpath")); } @Override diff --git a/src/main/java/no/ssb/dapla/dlp/pseudo/func/map/MapFuncConfig.java b/src/main/java/no/ssb/dapla/dlp/pseudo/func/map/MapFuncConfig.java index a74bebd..c9f28bb 100644 --- a/src/main/java/no/ssb/dapla/dlp/pseudo/func/map/MapFuncConfig.java +++ b/src/main/java/no/ssb/dapla/dlp/pseudo/func/map/MapFuncConfig.java @@ -8,9 +8,11 @@ @Builder public class MapFuncConfig { private final String context; + private final String versionTimestamp; @UtilityClass public static class Param { public static final String CONTEXT = "context"; + public static final String VERSION_TIMESTAMP = "versionTimestamp"; } } diff --git a/src/main/java/no/ssb/dapla/dlp/pseudo/func/map/MapFuncConfigService.java b/src/main/java/no/ssb/dapla/dlp/pseudo/func/map/MapFuncConfigService.java index 7d5c5ec..9216399 100644 --- a/src/main/java/no/ssb/dapla/dlp/pseudo/func/map/MapFuncConfigService.java +++ b/src/main/java/no/ssb/dapla/dlp/pseudo/func/map/MapFuncConfigService.java @@ -1,14 +1,13 @@ package no.ssb.dapla.dlp.pseudo.func.map; - import no.ssb.dapla.dlp.pseudo.func.PseudoFuncConfig; +import static no.ssb.dapla.dlp.pseudo.func.map.MapFuncConfig.Param.VERSION_TIMESTAMP; public class MapFuncConfigService { - public MapFuncConfig resolve(PseudoFuncConfig genericConfig) { - String context = genericConfig.getRequired(MapFuncConfig.Param.CONTEXT, String.class); return MapFuncConfig.builder() + .versionTimestamp(genericConfig.get(VERSION_TIMESTAMP, String.class).orElse(null)) .context(context) .build(); } diff --git a/src/main/java/no/ssb/dapla/dlp/pseudo/func/map/Mapper.java b/src/main/java/no/ssb/dapla/dlp/pseudo/func/map/Mapper.java index 44512bd..360fc30 100644 --- a/src/main/java/no/ssb/dapla/dlp/pseudo/func/map/Mapper.java +++ b/src/main/java/no/ssb/dapla/dlp/pseudo/func/map/Mapper.java @@ -1,8 +1,11 @@ package no.ssb.dapla.dlp.pseudo.func.map; +import java.util.Map; + public interface Mapper { void init(Object data); + void setConfig(Map config); Object map(Object data); Object restore(Object mapped);