Skip to content

Commit

Permalink
Added support for supplying a version timestamp for the 'map-sid' fun…
Browse files Browse the repository at this point in the history
…ction (#10)

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

* Removed SidMapperMock and replace by mockito mocks

---------

Co-authored-by: Skaar, Bjørn-Andre <[email protected]>
  • Loading branch information
mallport and Skaar, Bjørn-Andre authored Sep 4, 2023
1 parent c3b3ae0 commit 9acae4c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
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

0 comments on commit 9acae4c

Please sign in to comment.