Skip to content

Commit fb783ab

Browse files
committed
feat(flow-translator): use EipIds with EipChild to enable different namespace than parent
1 parent f462f65 commit fb783ab

File tree

17 files changed

+96
-70
lines changed

17 files changed

+96
-70
lines changed

flow-translator/flow-translator-lib/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>org.codice.keip</groupId>
88
<artifactId>flow-translator-lib</artifactId>
9-
<version>0.5.0</version>
9+
<version>0.6.0</version>
1010

1111
<packaging>jar</packaging>
1212

@@ -55,7 +55,7 @@
5555
<dependency>
5656
<groupId>org.codice.keip.schemas</groupId>
5757
<artifactId>validation</artifactId>
58-
<version>0.3.0</version>
58+
<version>0.4.0</version>
5959
<scope>test</scope>
6060
</dependency>
6161

@@ -89,7 +89,7 @@
8989
<dependency>
9090
<groupId>org.codice.keip.xsd</groupId>
9191
<artifactId>eip-schema-definitions</artifactId>
92-
<version>0.1.0</version>
92+
<version>0.3.0</version>
9393
<scope>test</scope>
9494
</dependency>
9595

flow-translator/flow-translator-lib/src/main/java/org/codice/keip/flow/ComponentRegistry.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,13 @@ public static ComponentRegistry fromJson(InputStream json) throws IOException {
4646

4747
for (var namespace : jsonMap.entrySet()) {
4848
for (var component : namespace.getValue()) {
49-
String name = component.get("name").textValue();
49+
JsonNode eipIdJson = component.get("eipId");
50+
EipId eipId =
51+
new EipId(eipIdJson.get("namespace").textValue(), eipIdJson.get("name").textValue());
5052
ConnectionType connectionType =
5153
ConnectionType.valueOf(component.get("connectionType").textValue().toUpperCase());
5254
Role role = Role.valueOf(component.get("role").textValue().toUpperCase());
53-
regMap.put(
54-
new EipId(namespace.getKey(), name), new ComponentProperties(connectionType, role));
55+
regMap.put(eipId, new ComponentProperties(connectionType, role));
5556
}
5657
}
5758

flow-translator/flow-translator-lib/src/main/java/org/codice/keip/flow/model/EipChild.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
import java.util.List;
55
import java.util.Map;
66

7-
// TODO: Support children with different namespaces than parent
8-
public record EipChild(String name, Map<String, Object> attributes, List<EipChild> children) {
7+
public record EipChild(EipId eipId, Map<String, Object> attributes, List<EipChild> children) {
98
@Override
109
public Map<String, Object> attributes() {
1110
if (attributes == null) {

flow-translator/flow-translator-lib/src/main/java/org/codice/keip/flow/xml/spring/BaseNodeTransformation.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ public final class BaseNodeTransformation {
1515

1616
public static XmlElement toXmlElement(EipNode node) {
1717
List<XmlElement> children =
18-
node.children().stream().map(c -> toXmlElement(c, node.eipId().namespace())).toList();
18+
node.children().stream().map(BaseNodeTransformation::toXmlElement).toList();
1919
return new XmlElement(
2020
node.eipId().namespace(), node.eipId().name(), node.attributes(), children);
2121
}
2222

23-
private static XmlElement toXmlElement(EipChild child, String prefix) {
23+
private static XmlElement toXmlElement(EipChild child) {
2424
List<XmlElement> children =
25-
child.children().stream().map(c -> toXmlElement(c, prefix)).toList();
26-
return new XmlElement(prefix, child.name(), child.attributes(), children);
25+
child.children().stream().map(BaseNodeTransformation::toXmlElement).toList();
26+
return new XmlElement(
27+
child.eipId().namespace(), child.eipId().name(), child.attributes(), children);
2728
}
2829
}

flow-translator/flow-translator-lib/src/main/java/org/codice/keip/flow/xml/spring/ChannelEdgeBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ private void processContentBasedRouters(EipNode node) {
107107
}
108108

109109
for (var child : node.children()) {
110-
if (CHANNEL_ROUTING_CHILDREN.contains(child.name())) {
110+
if (CHANNEL_ROUTING_CHILDREN.contains(child.eipId().name())) {
111111
Object channel = child.attributes().get(CHANNEL);
112112
if (channel == null) {
113113
throw new IllegalArgumentException(

flow-translator/flow-translator-lib/src/main/java/org/codice/keip/flow/xml/spring/DefaultXmlElementTransformer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ public EipNode apply(XmlElement element, ComponentRegistry registry) {
3838

3939
private EipChild convertChild(XmlElement element) {
4040
List<EipChild> children = element.children().stream().map(this::convertChild).toList();
41-
return new EipChild(element.localName(), element.attributes(), children);
41+
EipId id = new EipId(element.prefix(), element.localName());
42+
return new EipChild(id, element.attributes(), children);
4243
}
4344

4445
private void validateElement(XmlElement element, ComponentRegistry registry) {

flow-translator/flow-translator-lib/src/test/groovy/org/codice/keip/flow/model/FlowModelValidationTest.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ class FlowModelValidationTest extends Specification {
1919

2020
def "Fully specified Flow object passes schema validation"() {
2121
given:
22-
def child = new EipChild("c1", ["cKey1": "cVal1"], [])
22+
def child = new EipChild(new EipId("test-ns", "c1"),
23+
["cKey1": "cVal1"], [])
2324
def node = new EipNode("n1",
2425
new EipId("test-ns", "test-comp"),
2526
"test-label",

flow-translator/flow-translator-lib/src/test/groovy/org/codice/keip/flow/xml/spring/BaseNodeTransformationTest.groovy

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import spock.lang.Specification
99

1010
class BaseNodeTransformationTest extends Specification {
1111

12-
static final String TEST_NS = "test-ns"
13-
1412
def "single node to xml element"() {
1513
given:
1614
def name = "top"
@@ -20,7 +18,7 @@ class BaseNodeTransformationTest extends Specification {
2018
def element = BaseNodeTransformation.toXmlElement(node)
2119

2220
then:
23-
element.prefix() == TEST_NS
21+
element.prefix() == node.eipId().namespace()
2422
element.localName() == name
2523
element.attributes().isEmpty()
2624
element.children().isEmpty()
@@ -29,10 +27,10 @@ class BaseNodeTransformationTest extends Specification {
2927
def "single node with attributes and children to xml element"() {
3028
given:
3129
def grandchildAttrs = ["deepest-attr": "val"]
32-
def grandchild = new EipChild("grandchild", grandchildAttrs, null)
30+
def grandchild = new EipChild(new EipId("test-ns", "grandchild"), grandchildAttrs, null)
3331

3432
def childAttrs = ["child-attr1": "4"]
35-
def child = new EipChild("child", childAttrs, [grandchild])
33+
def child = new EipChild(new EipId("other", "child"), childAttrs, [grandchild])
3634

3735
def name = "top"
3836
def topAttrs = ["attr1": "123", "attr2": "abc"]
@@ -44,30 +42,36 @@ class BaseNodeTransformationTest extends Specification {
4442
def element = BaseNodeTransformation.toXmlElement(node)
4543

4644
then:
47-
element.prefix() == TEST_NS
45+
element.prefix() == node.eipId().namespace()
4846
element.localName() == name
4947
element.attributes() == topAttrs
5048
element.children().size() == 1
5149

5250
def aChild = element.children()[0]
53-
aChild.prefix() == TEST_NS
54-
aChild.localName() == child.name()
51+
aChild.prefix() == child.eipId().namespace()
52+
aChild.localName() == child.eipId().name()
5553
aChild.attributes() == childAttrs
5654
aChild.children().size() == 1
5755

5856
def aGrandchild = aChild.children()[0]
59-
aGrandchild.prefix() == TEST_NS
60-
aGrandchild.localName() == grandchild.name()
57+
aGrandchild.prefix() == grandchild.eipId().namespace()
58+
aGrandchild.localName() == grandchild.eipId().name()
6159
aGrandchild.attributes() == grandchildAttrs
6260
aGrandchild.children().isEmpty()
6361
}
6462

6563
def "single node with multiple children to xml element"() {
6664
given:
6765
def childAttrs1 = ["attr1": "one"]
68-
def child1 = new EipChild("child1", childAttrs1, null)
66+
def child1 = new EipChild(
67+
new EipId("test1", "child1"),
68+
childAttrs1,
69+
null)
6970

70-
def child2 = new EipChild("child2", null, null)
71+
def child2 = new EipChild(
72+
new EipId("test2", "child2"),
73+
null,
74+
null)
7175

7276
def name = "top"
7377
def node = createNodeStub("1", name)
@@ -77,28 +81,28 @@ class BaseNodeTransformationTest extends Specification {
7781
def element = BaseNodeTransformation.toXmlElement(node)
7882

7983
then:
80-
element.prefix() == TEST_NS
84+
element.prefix() == node.eipId().namespace()
8185
element.localName() == name
8286
element.attributes().isEmpty()
8387
element.children().size() == 2
8488

8589
def aChild1 = element.children()[0]
86-
aChild1.prefix() == TEST_NS
87-
aChild1.localName() == child1.name()
90+
aChild1.prefix() == child1.eipId().namespace()
91+
aChild1.localName() == child1.eipId().name()
8892
aChild1.attributes() == childAttrs1
8993
aChild1.children().isEmpty()
9094

9195
def aChild2 = element.children()[1]
92-
aChild2.prefix() == TEST_NS
93-
aChild2.localName() == child2.name()
96+
aChild2.prefix() == child2.eipId().namespace()
97+
aChild2.localName() == child2.eipId().name()
9498
aChild2.attributes().isEmpty()
9599
aChild2.children().isEmpty()
96100
}
97101

98102
EipNode createNodeStub(String nodeId, String eipName) {
99103
EipNode stub = Stub {
100104
id() >> nodeId
101-
eipId() >> new EipId(TEST_NS, eipName)
105+
eipId() >> new EipId("test-ns", eipName)
102106
role() >> Role.TRANSFORMER
103107
connectionType() >> ConnectionType.PASSTHRU
104108
}

flow-translator/flow-translator-lib/src/test/groovy/org/codice/keip/flow/xml/spring/ChannelEdgeBuilderTest.groovy

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ import static org.codice.keip.flow.xml.spring.ComponentIdentifiers.DIRECT_CHANNE
2424

2525
class ChannelEdgeBuilderTest extends Specification {
2626

27+
private static final MAPPING_ID = new EipId("test", "mapping")
28+
private static final RECIPIENT_ID = new EipId("test", "recipient")
29+
2730
def "no channel nodes -> disconnected graph"() {
2831
given:
2932
def nodes = [
@@ -230,9 +233,9 @@ class ChannelEdgeBuilderTest extends Specification {
230233
def sink2 = createNode("sink2", SINK, ["channel": "out2"])
231234
def sink3 = createNode("sink3", SINK, ["channel": "out3"])
232235
233-
EipChild mapping1 = new EipChild("mapping", ["value": "one", "channel": "out1"], [])
234-
EipChild mapping2 = new EipChild("mapping", ["value": "two", "channel": "out2"], [])
235-
EipChild other = new EipChild("other", ["key1": "val1"], [])
236+
EipChild mapping1 = new EipChild(MAPPING_ID, ["value": "one", "channel": "out1"], [])
237+
EipChild mapping2 = new EipChild(MAPPING_ID, ["value": "two", "channel": "out2"], [])
238+
EipChild other = new EipChild(new EipId("alt", "other"), ["key1": "val1"], [])
236239
router = router.withChildren([mapping1, mapping2, other])
237240
238241
def nodes = [source,
@@ -264,8 +267,8 @@ class ChannelEdgeBuilderTest extends Specification {
264267
def sink1 = createNode("sink1", SINK, ["channel": "out1"])
265268
def sink2 = createNode("sink2", SINK, ["channel": "out2"])
266269
267-
EipChild recipient1 = new EipChild("recipient", ["value": "one", "channel": "out1"], [])
268-
EipChild recipient2 = new EipChild("recipient", ["value": "two", "channel": "out2"], [])
270+
EipChild recipient1 = new EipChild(RECIPIENT_ID, ["value": "one", "channel": "out1"], [])
271+
EipChild recipient2 = new EipChild(RECIPIENT_ID, ["value": "two", "channel": "out2"], [])
269272
recList = recList.withChildren([recipient1, recipient2])
270273
271274
def nodes = [source,
@@ -298,8 +301,8 @@ class ChannelEdgeBuilderTest extends Specification {
298301
def sink1 = createNode("sink1", SINK, ["channel": "out1"])
299302
def sink2 = createNode("sink2", SINK, ["channel": "out2"])
300303
301-
EipChild mapping1 = new EipChild("mapping", ["value": "one", "channel": "out1"], [])
302-
EipChild mapping2 = new EipChild("mapping", ["value": "two"], [])
304+
EipChild mapping1 = new EipChild(MAPPING_ID, ["value": "one", "channel": "out1"], [])
305+
EipChild mapping2 = new EipChild(MAPPING_ID, ["value": "two"], [])
303306
router = router.withChildren([mapping1, mapping2])
304307
305308
def nodes = [source,
@@ -345,7 +348,7 @@ class ChannelEdgeBuilderTest extends Specification {
345348
346349
where:
347350
eipId | children
348-
DIRECT_CHANNEL | [new EipChild("queue", [:], [])]
351+
DIRECT_CHANNEL | [new EipChild(new EipId("test", "queue"), [:], [])]
349352
new EipId(Namespaces.INTEGRATION.eipNamespace(), "publish-subscribe-channel") | []
350353
}
351354

flow-translator/flow-translator-lib/src/test/groovy/org/codice/keip/flow/xml/spring/DefaultNodeTransformerTest.groovy

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,11 @@ class DefaultNodeTransformerTest extends Specification {
487487
connectionType() >> ConnectionType.SINK
488488
}
489489

490-
def childNode = new EipChild("child1", ["childAttr": "testval3"], null)
490+
def childNode = new EipChild(
491+
new EipId("child-ns", "child1"),
492+
["childAttr": "testval3"],
493+
null)
494+
491495
def attrs = ["testkey1": "testval1"]
492496
EipNode middle = Stub() {
493497
id() >> "middle"
@@ -517,7 +521,7 @@ class DefaultNodeTransformerTest extends Specification {
517521
first.children().size() == 1
518522

519523
def aChild = first.children()[0]
520-
aChild.prefix() == TEST_NS
524+
aChild.prefix() == childNode.eipId().namespace()
521525
aChild.localName() == "child1"
522526
aChild.attributes() == childNode.attributes()
523527
aChild.children().isEmpty()

0 commit comments

Comments
 (0)