Skip to content

Commit 947faee

Browse files
authored
Fix MDSLModelCreator: No duplicate endpoints (#68)
1 parent 5fd018f commit 947faee

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

org.contextmapper.dsl.tests/integ-test-files/mdsl/basic-mdsl-model-test.cml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ ContextMap {
88

99
// this relationship must be ignored, because it has no exposedAggregates
1010
CustomerManagementContext -> JustAnotherContext
11+
12+
// duplicate relationship should not change the result
13+
CustomerManagementContext -> ContractManagementContext {
14+
exposedAggregates = Customers
15+
}
1116

1217
}
1318

org.contextmapper.dsl/src/org/contextmapper/dsl/generator/mdsl/MDSLModelCreator.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,12 @@ private Map<String, UpstreamAPIContext> collectUpstreamContexts() {
181181
context.setUpstreamContext(relationship.getUpstream());
182182
upstreamContextMap.put(upstreamAPIName, context);
183183
}
184-
context.getExposedAggregates().addAll(relationship.getUpstreamExposedAggregates());
185-
context.getDownstreamContexts().add(relationship.getDownstream());
184+
for (Aggregate exposedAggregate : relationship.getUpstreamExposedAggregates()) {
185+
if (!context.getExposedAggregates().stream().map(agg -> agg.getName()).collect(Collectors.toList()).contains(exposedAggregate.getName()))
186+
context.getExposedAggregates().add(exposedAggregate);
187+
}
188+
if (!context.getDownstreamContexts().stream().map(bc -> bc.getName()).collect(Collectors.toList()).contains(relationship.getDownstream().getName()))
189+
context.getDownstreamContexts().add(relationship.getDownstream());
186190
context.addDownstreamConsumations(relationship.getDownstream().getName(), relationship.getUpstreamExposedAggregates());
187191
if (relationship.getImplementationTechnology() != null && !"".equals(relationship.getImplementationTechnology()))
188192
context.getImplementationTechnologies().add(relationship.getImplementationTechnology());
@@ -267,7 +271,10 @@ public void addDownstreamConsumations(String downstreamName, List<Aggregate> con
267271
if (!this.consumedAggregatesByDownstreamContext.containsKey(downstreamName)) {
268272
this.consumedAggregatesByDownstreamContext.put(downstreamName, Lists.newArrayList());
269273
}
270-
this.consumedAggregatesByDownstreamContext.get(downstreamName).addAll(consumedAggregates);
274+
for (Aggregate aggregate : consumedAggregates) {
275+
if (!this.consumedAggregatesByDownstreamContext.get(downstreamName).stream().map(agg -> agg.getName()).collect(Collectors.toList()).contains(aggregate.getName()))
276+
this.consumedAggregatesByDownstreamContext.get(downstreamName).add(aggregate);
277+
}
271278
}
272279

273280
public Map<String, List<Aggregate>> getConsumedAggregatesByDownstreamContext() {

0 commit comments

Comments
 (0)