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

Added support for supplying a version timestamp for the 'map-sid' function #10

Merged
merged 2 commits into from
Sep 4, 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
10 changes: 8 additions & 2 deletions src/main/java/no/ssb/dapla/dlp/pseudo/func/map/MapFunc.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/no/ssb/dapla/dlp/pseudo/func/map/Mapper.java
Original file line number Diff line number Diff line change
@@ -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<String, Object> config);
Object map(Object data);

Object restore(Object mapped);
Expand Down