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

Behold signatur for asJson ellers knekker mye #136

Merged
merged 1 commit into from
Feb 2, 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
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