use of org.contextmapper.dsl.generator.mdsl.model.OrchestrationFlow in project context-mapper-dsl by ContextMapper.
the class MDSLModelCreator method createServiceSpecification.
private ServiceSpecification createServiceSpecification(String apiName, UpstreamAPIContext context) {
ServiceSpecification specification = new ServiceSpecification();
specification.setName(mdslEncoder.encodeName(apiName));
if (context.getUpstreamRoles().contains(UpstreamRole.OPEN_HOST_SERVICE) && context.getUpstreamRoles().contains(UpstreamRole.PUBLISHED_LANGUAGE)) {
specification.setUsageContext(APIUsageContext.PUBLIC_API);
} else if (context.getUpstreamRoles().contains(UpstreamRole.OPEN_HOST_SERVICE)) {
specification.setUsageContext(APIUsageContext.COMMUNITY_API);
}
if (context.getApplicationLayer() != null) {
specification.addEndpoint(createEndpoint(context.getApplicationLayer(), specification));
for (DomainEvent de : context.getApplicationLayer().getEvents()) {
specification.addEventType(de.getName());
// TODO map data structure, not just name (if present)
}
// add event types for all domain events in all exposed aggregates
for (Aggregate exposedAggregate : context.getExposedAggregates()) {
for (SimpleDomainObject objectInAggregate : exposedAggregate.getDomainObjects()) {
// check type of domain object (entity? event?...?):
if (objectInAggregate instanceof DomainEvent) {
DomainEvent de = (DomainEvent) objectInAggregate;
// TODO make sure names are unique/do not add duplicates
specification.addEventType(de.getName());
}
}
}
for (CommandEvent ce : context.getApplicationLayer().getCommands()) {
specification.addCommandType(ce.getName());
}
EList<Flow> flows = context.getApplicationLayer().getFlows();
for (Flow cmlFlow : flows) {
OrchestrationFlow mdslFlow = new OrchestrationFlow();
mdslFlow.setName(cmlFlow.getName());
for (FlowStep step : cmlFlow.getSteps()) {
mapFlowStep(mdslFlow, step);
}
specification.addFlow(mdslFlow);
}
}
for (Aggregate aggregate : context.getExposedAggregates()) {
specification.addEndpoint(createEndpoint(aggregate, specification));
}
for (DataType dataType : dataTypeCreator.getAllDataTypes()) {
specification.addDataType(dataType);
}
specification.addProvider(createProvider(context, specification.getEndpoints()));
for (DownstreamContext downstreamContext : context.getDownstreamContexts()) {
specification.addClient(createClient(downstreamContext));
}
return specification;
}
use of org.contextmapper.dsl.generator.mdsl.model.OrchestrationFlow in project context-mapper-dsl by ContextMapper.
the class MDSLModelCreatorTest method canCreateMDSLModelWithFlow.
@Test
void canCreateMDSLModelWithFlow() throws IOException {
// given
CMLResource input = getResourceCopyOfTestCML("application-flow-example.cml");
MDSLModelCreator mdslCreator = new MDSLModelCreator(input.getContextMappingModel());
// when
List<ServiceSpecification> serviceSpecifications = mdslCreator.createServiceSpecifications();
// then
assertEquals(1, serviceSpecifications.size());
ServiceSpecification spec = serviceSpecifications.get(0);
assertEquals("SampleSystemAPI", spec.getName());
// one endpoint for flow, one endpoint for aggregate
assertEquals(2, spec.getEndpoints().size());
EndpointContract endpoint = spec.getEndpoints().get(0);
assertEquals("SampleApplication", endpoint.getName());
// one operation for each flow step
assertEquals(6, endpoint.getOperations().size());
OrchestrationFlow flow = spec.getFlows().get(0);
assertEquals("SampleFlow", flow.getName());
// must match number of steps in CML input
assertEquals(9, flow.getSteps().size());
}
Aggregations