Skip to content

Commit

Permalink
Behold signatur for asJson ellers knekker mye (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
jolarsen authored Feb 2, 2023
1 parent 3bebb29 commit 1c40e94
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public RuleDescriptionDigraph(RuleDescription root, RuleNodeIdProducer idProduce
}

//bruk istedet den andre constructoren
@Deprecated(forRemoval = true, since = "2.5.0")
@Deprecated(forRemoval = true, since = "2.6.0")
public RuleDescriptionDigraph(RuleDescription root, RuleNodeIdProducer idProducer) {
this.idProducer = idProducer;
this.root = process(root);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/no/nav/fpsak/nare/doc/RuleNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ public class RuleNode {
private final Operator operator;
private RuleDescription rule;

@Deprecated(forRemoval = true, since = "2.5.0")
@Deprecated(forRemoval = true, since = "2.6.0")
public RuleNode(String ruleId, String ruleDescription, Operator operator) {
this.id = UUID.randomUUID().toString();
this.ruleId = ruleId;
this.ruleDescription = ruleDescription;
this.operator = operator;
}

@Deprecated(forRemoval = true, since = "2.5.0")
@Deprecated(forRemoval = true, since = "2.6.0")
public RuleNode(RuleDescription node) {
this.id = UUID.randomUUID().toString();
this.ruleId = node.getRuleIdentification();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,26 @@

public class EvaluationSerializer {


public static String asJson(Evaluation evaluation) {
var desc = evaluation.toRuleDescription();
RuleDescriptionDigraph digraph = new RuleDescriptionDigraph(desc, new EvaluationSerializer.IncrementalIdProcucer(), Map.of());
return digraph.toJson();
}

public static String asJson(Evaluation evaluation, EvaluationVersion... versions) {
var desc = evaluation.toRuleDescription();
RuleDescriptionDigraph digraph = new RuleDescriptionDigraph(desc, new EvaluationSerializer.IncrementalIdProcucer(), toVerisonsMap(versions));
RuleDescriptionDigraph digraph = new RuleDescriptionDigraph(desc, new EvaluationSerializer.IncrementalIdProcucer(), toVersionsMap(versions));
return digraph.toJson();
}

public static String asJson(Specification<?> specification, EvaluationVersion... versions) {
RuleDescriptionDigraph digraph = new RuleDescriptionDigraph(specification.ruleDescription(), new EvaluationSerializer.IncrementalIdProcucer(), toVerisonsMap(versions));
RuleDescriptionDigraph digraph = new RuleDescriptionDigraph(specification.ruleDescription(), new EvaluationSerializer.IncrementalIdProcucer(), toVersionsMap(versions));
return digraph.toJson();
}

private static Map<String, String> toVerisonsMap(EvaluationVersion[] versions) {
Map<String, String> map = Arrays.stream(versions).collect(Collectors.toMap(EvaluationVersion::getName, EvaluationVersion::getVersion));
private static Map<String, String> toVersionsMap(EvaluationVersion[] versions) {
Map<String, String> map = Arrays.stream(versions).collect(Collectors.toMap(EvaluationVersion::name, EvaluationVersion::version));
//hvis ingen versjoner er oppgitt, sender inn null for å unngå å få med versjon-elementet i sin helhet
return map.isEmpty() ? null : map;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@

import java.util.Objects;

public class EvaluationVersion {
private String name;
private String version;
public record EvaluationVersion(String name, String version) {

public EvaluationVersion(String name, String version) {
public EvaluationVersion {
Objects.requireNonNull(name, "name");
Objects.requireNonNull(name, "version");
this.name = name;
this.version = version;
Objects.requireNonNull(version, "version");
}

@Deprecated(forRemoval = true, since = "2.6.0")
public String getName() {
return name;
}

@Deprecated(forRemoval = true, since = "2.6.0")
public String getVersion() {
return version;
}
Expand Down

0 comments on commit 1c40e94

Please sign in to comment.