use of org.contextmapper.dsl.validation.ValidationMessages.EXPOSED_AGGREGATE_NOT_PART_OF_UPSTREAM_CONTEXT in project context-mapper-dsl by ContextMapper.
the class ContextMapSemanticsValidator method validateThatExposedAggregateIsPartOfUpstreamContext.
@Check
public void validateThatExposedAggregateIsPartOfUpstreamContext(final ContextMap map) {
for (Relationship rel : map.getRelationships()) {
if (rel instanceof UpstreamDownstreamRelationship) {
UpstreamDownstreamRelationship relationship = (UpstreamDownstreamRelationship) rel;
BoundedContext upstreamContext = ((UpstreamDownstreamRelationship) relationship).getUpstream();
int aggregateRefIndex = 0;
for (Aggregate aggregate : relationship.getUpstreamExposedAggregates()) {
List<String> aggregates = upstreamContext.getAggregates().stream().map(a -> a.getName()).collect(Collectors.toList());
for (SculptorModule module : upstreamContext.getModules()) {
aggregates.addAll(module.getAggregates().stream().map(b -> b.getName()).collect(Collectors.toList()));
}
if (!aggregates.contains(aggregate.getName()))
error(String.format(EXPOSED_AGGREGATE_NOT_PART_OF_UPSTREAM_CONTEXT, aggregate.getName(), upstreamContext.getName()), relationship, UPSTREAM_DOWNSTREAM_RELATIONSHIP__UPSTREAM_EXPOSED_AGGREGATES, aggregateRefIndex);
aggregateRefIndex++;
}
}
}
}
Aggregations