use of org.contextmapper.dsl.generator.mdsl.generatorcontext.UpstreamAPIContext in project context-mapper-dsl by ContextMapper.
the class MDSLModelCreator method collectUpstreamContexts.
private Map<String, UpstreamAPIContext> collectUpstreamContexts() {
Map<String, UpstreamAPIContext> upstreamContextMap = Maps.newHashMap();
List<UpstreamDownstreamRelationship> upstreamDownstreamRelationships = Lists.newLinkedList();
if (model.getMap() != null)
upstreamDownstreamRelationships = model.getMap().getRelationships().stream().filter(rel -> rel instanceof UpstreamDownstreamRelationship).map(rel -> (UpstreamDownstreamRelationship) rel).collect(Collectors.toList());
for (UpstreamDownstreamRelationship relationship : upstreamDownstreamRelationships) {
if (relationship.getUpstreamExposedAggregates().isEmpty())
continue;
String upstreamAPIName = relationship.getUpstream().getName() + API_NAME_EXTENSION;
UpstreamAPIContext context = null;
if (upstreamContextMap.containsKey(upstreamAPIName)) {
context = upstreamContextMap.get(upstreamAPIName);
} else {
context = new UpstreamAPIContext();
context.setApiName(mdslEncoder.encodeName(upstreamAPIName));
context.setUpstreamContext(relationship.getUpstream());
upstreamContextMap.put(upstreamAPIName, context);
}
context.getUpstreamRoles().addAll(relationship.getUpstreamRoles());
for (Aggregate exposedAggregate : relationship.getUpstreamExposedAggregates()) {
if (!context.getExposedAggregates().stream().map(agg -> agg.getName()).collect(Collectors.toList()).contains(exposedAggregate.getName()))
context.getExposedAggregates().add(exposedAggregate);
}
if (relationship.getUpstream().getApplication() != null)
context.setApplicationLayer(relationship.getUpstream().getApplication());
context.addDownstreamContext4Relationship(relationship);
if (relationship.getImplementationTechnology() != null && !"".equals(relationship.getImplementationTechnology()))
context.getImplementationTechnologies().add(relationship.getImplementationTechnology());
}
// add all contexts that are not upstream in an upstream-downstream relationship
for (BoundedContext bc : model.getBoundedContexts()) {
String apiName = bc.getName() + API_NAME_EXTENSION;
if (upstreamContextMap.containsKey(apiName) || (bc.getAggregates().isEmpty() && bc.getApplication() == null))
continue;
UpstreamAPIContext context = new UpstreamAPIContext();
context.setApiName(apiName);
context.setUpstreamContext(bc);
context.getExposedAggregates().addAll(bc.getAggregates());
context.setApplicationLayer(bc.getApplication());
upstreamContextMap.put(apiName, context);
}
return upstreamContextMap;
}
use of org.contextmapper.dsl.generator.mdsl.generatorcontext.UpstreamAPIContext in project context-mapper-dsl by ContextMapper.
the class MDSLModelCreator method checkPreconditions.
private void checkPreconditions() {
Map<String, UpstreamAPIContext> upstreamContexts = collectUpstreamContexts();
List<Aggregate> exposedAggregates = Lists.newArrayList();
List<Application> applications = Lists.newArrayList();
for (UpstreamAPIContext context : upstreamContexts.values()) {
exposedAggregates.addAll(context.getExposedAggregates());
if (context.getApplicationLayer() != null)
applications.add(context.getApplicationLayer());
}
if (exposedAggregates.isEmpty() && applications.isEmpty())
throw new GeneratorInputException("None of your upstream-downstream relationships exposes any Aggregates or application layers. Therefore there is nothing to generate. Use the 'exposedAggregates' attribute on your upstream-downstream relationships to specify which Aggregates are exposed by the upstream or model an 'Application' in your upstream.");
boolean atLeastOneAggregateWithAnOperation = false;
for (Aggregate exposedAggregate : exposedAggregates) {
Optional<DomainObject> aggregateRoot = exposedAggregate.getDomainObjects().stream().filter(o -> o instanceof DomainObject).map(o -> (DomainObject) o).filter(o -> o.isAggregateRoot()).findFirst();
if (aggregateRoot.isPresent() && !aggregateRoot.get().getOperations().isEmpty()) {
atLeastOneAggregateWithAnOperation = true;
break;
}
List<ServiceOperation> serviceOperations = exposedAggregate.getServices().stream().flatMap(s -> s.getOperations().stream()).collect(Collectors.toList());
if (!serviceOperations.isEmpty()) {
atLeastOneAggregateWithAnOperation = true;
break;
}
}
for (Application application : applications) {
if (!application.getCommands().isEmpty()) {
atLeastOneAggregateWithAnOperation = true;
break;
}
List<ServiceOperation> serviceOperations = application.getServices().stream().flatMap(s -> s.getOperations().stream()).collect(Collectors.toList());
if (!serviceOperations.isEmpty()) {
atLeastOneAggregateWithAnOperation = true;
break;
}
}
if (!atLeastOneAggregateWithAnOperation)
throw new GeneratorInputException("None of your exposed Aggregates contains either Service or 'Aggregate Root' operations/methods. Therefore there is nothing to generate. Add at least one operation/method to the 'Aggregate Root' or to a Service in one of your exposed Aggregates to get a result.");
}
use of org.contextmapper.dsl.generator.mdsl.generatorcontext.UpstreamAPIContext in project context-mapper-dsl by ContextMapper.
the class MDSLModelCreator method createServiceSpecifications.
public List<ServiceSpecification> createServiceSpecifications() {
checkPreconditions();
List<ServiceSpecification> specs = Lists.newArrayList();
Map<String, UpstreamAPIContext> upstreamContexts = collectUpstreamContexts();
for (String apiName : upstreamContexts.keySet()) {
UpstreamAPIContext context = upstreamContexts.get(apiName);
specs.add(createServiceSpecification(context.getApiName(), context));
}
return specs;
}
Aggregations