Skip to content

Commit 3767763

Browse files
committed
TEDEFO-5002 Add codelist dependencies and skip empty rules in graph
1 parent bd6f656 commit 3767763

7 files changed

Lines changed: 47 additions & 10 deletions

File tree

src/main/java/eu/europa/ted/efx/model/dependencies/DependencyGraph.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ private ObjectNode serializeDependsOn(final TargetDependencies entry) {
105105
ruleNode.put("ruleId", rule.getRuleId());
106106
this.putIfNotEmpty("fields", this.toStringArray(rule.getFields()), ruleNode);
107107
this.putIfNotEmpty("nodes", this.toStringArray(rule.getNodes()), ruleNode);
108+
this.putIfNotEmpty("codeLists", this.toStringArray(rule.getCodelists()), ruleNode);
108109
assertArray.add(ruleNode);
109110
}
110111
this.putIfNotEmpty("assert", assertArray, dependsOn);

src/main/java/eu/europa/ted/efx/model/dependencies/DependencySet.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public class DependencySet {
1212

1313
private final Set<String> fieldIds = new LinkedHashSet<>();
1414
private final Set<String> nodeIds = new LinkedHashSet<>();
15+
private final Set<String> codelistNames = new LinkedHashSet<>();
1516

1617
public void addField(final String fieldId) {
1718
this.fieldIds.add(fieldId);
@@ -21,6 +22,10 @@ public void addNode(final String nodeId) {
2122
this.nodeIds.add(nodeId);
2223
}
2324

25+
public void addCodelist(final String codelistName) {
26+
this.codelistNames.add(codelistName);
27+
}
28+
2429
public void removeField(final String fieldId) {
2530
this.fieldIds.remove(fieldId);
2631
}
@@ -32,6 +37,7 @@ public void removeNode(final String nodeId) {
3237
public void addAll(final DependencySet other) {
3338
this.fieldIds.addAll(other.fieldIds);
3439
this.nodeIds.addAll(other.nodeIds);
40+
this.codelistNames.addAll(other.codelistNames);
3541
}
3642

3743
public Set<String> getFieldIds() {
@@ -42,14 +48,19 @@ public Set<String> getNodeIds() {
4248
return Collections.unmodifiableSet(this.nodeIds);
4349
}
4450

51+
public Set<String> getCodelistNames() {
52+
return Collections.unmodifiableSet(this.codelistNames);
53+
}
54+
4555
public boolean isEmpty() {
46-
return this.fieldIds.isEmpty() && this.nodeIds.isEmpty();
56+
return this.fieldIds.isEmpty() && this.nodeIds.isEmpty() && this.codelistNames.isEmpty();
4757
}
4858

4959
public Set<String> allIds() {
5060
final Set<String> result = new LinkedHashSet<>();
5161
result.addAll(this.fieldIds);
5262
result.addAll(this.nodeIds);
63+
result.addAll(this.codelistNames);
5364
return Collections.unmodifiableSet(result);
5465
}
5566
}

src/main/java/eu/europa/ted/efx/model/dependencies/RuleDependency.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@ public class RuleDependency {
1212
private final String ruleId;
1313
private final Set<String> fields;
1414
private final Set<String> nodes;
15+
private final Set<String> codelists;
1516

16-
public RuleDependency(final String ruleId, final Set<String> fields, final Set<String> nodes) {
17+
public RuleDependency(final String ruleId, final Set<String> fields, final Set<String> nodes,
18+
final Set<String> codelists) {
1719
this.ruleId = ruleId;
1820
this.fields = Collections.unmodifiableSet(new LinkedHashSet<>(fields));
1921
this.nodes = Collections.unmodifiableSet(new LinkedHashSet<>(nodes));
22+
this.codelists = Collections.unmodifiableSet(new LinkedHashSet<>(codelists));
2023
}
2124

2225
public String getRuleId() {
@@ -30,4 +33,8 @@ public Set<String> getFields() {
3033
public Set<String> getNodes() {
3134
return this.nodes;
3235
}
36+
37+
public Set<String> getCodelists() {
38+
return this.codelists;
39+
}
3340
}

src/main/java/eu/europa/ted/efx/sdk2/EfxComputeDependencyExtractor.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ public void enterSimpleNodeReference(final SimpleNodeReferenceContext ctx) {
118118
this.stack.peek().addNode(ctx.NodeId().getText());
119119
}
120120

121+
@Override
122+
public void enterCodelistReference(final CodelistReferenceContext ctx) {
123+
this.stack.peek().addCodelist(ctx.codelistName.getText());
124+
}
125+
121126
// #endregion Listener methods
122127

123128
protected void resolveAlias(final String alias) {

src/main/java/eu/europa/ted/efx/sdk2/EfxValidationDependencyExtractor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ private void commitRule(final AsClauseContext asClause, final ForClauseContext f
183183
? this.graph.getOrCreateFieldEntry(targetId)
184184
: this.graph.getOrCreateNodeEntry(targetId);
185185

186-
target.addAssertDependency(new RuleDependency(ruleId, ruleDeps.getFieldIds(), ruleDeps.getNodeIds()));
186+
target.addAssertDependency(new RuleDependency(ruleId, ruleDeps.getFieldIds(), ruleDeps.getNodeIds(), ruleDeps.getCodelistNames()));
187187
}
188188

189189
// #endregion Rule lifecycle

src/test/resources/eu/europa/ted/efx/sdk2/EfxValidationDependencyExtractorTest/testComprehensive/expected.json

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,24 +68,31 @@
6868
} ]
6969
}
7070
}, {
71-
"id" : "BT-01-SubSubNode-Text",
71+
"id" : "BT-00-Code",
72+
"dependsOn" : {
73+
"assert" : [ {
74+
"ruleId" : "R-C02-003",
75+
"nodes" : [ "ND-Root" ],
76+
"codeLists" : [ "accessibility" ]
77+
} ]
78+
},
7279
"requiredBy" : {
7380
"assert" : {
74-
"fields" : [ "BT-01-SubNode-Text" ]
81+
"fields" : [ "BT-00-Text" ]
7582
}
7683
}
7784
}, {
78-
"id" : "BT-00-Repeatable-Text",
85+
"id" : "BT-01-SubSubNode-Text",
7986
"requiredBy" : {
8087
"assert" : {
81-
"fields" : [ "BT-00-Number" ]
88+
"fields" : [ "BT-01-SubNode-Text" ]
8289
}
8390
}
8491
}, {
85-
"id" : "BT-00-Code",
92+
"id" : "BT-00-Repeatable-Text",
8693
"requiredBy" : {
8794
"assert" : {
88-
"fields" : [ "BT-00-Text" ]
95+
"fields" : [ "BT-00-Number" ]
8996
}
9097
}
9198
}, {
@@ -135,7 +142,7 @@
135142
"id" : "ND-Root",
136143
"requiredBy" : {
137144
"assert" : {
138-
"fields" : [ "BT-00-Number", "BT-00-Text", "BT-00-EndDate" ],
145+
"fields" : [ "BT-00-Number", "BT-00-Text", "BT-00-EndDate", "BT-00-Code" ],
139146
"nodes" : [ "ND-RepeatableNode" ]
140147
}
141148
}

src/test/resources/eu/europa/ted/efx/sdk2/EfxValidationDependencyExtractorTest/testComprehensive/input.efx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,9 @@ WITH ND-Root
5050
ASSERT BT-00-StartDate is present and BT-00-EndDate is present and BT-00-StartDate <= BT-00-EndDate
5151
AS ERROR R-C02-002
5252
FOR BT-00-EndDate IN *
53+
54+
// Rule 8: Codelist reference
55+
WITH ND-Root
56+
ASSERT BT-00-Code in [...accessibility]
57+
AS ERROR R-C02-003
58+
FOR BT-00-Code IN *

0 commit comments

Comments
 (0)