Search in sources :

Example 1 with OrchestrationFlow

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;
}
Also used : ServiceSpecification(org.contextmapper.dsl.generator.mdsl.model.ServiceSpecification) DomainEvent(org.contextmapper.tactic.dsl.tacticdsl.DomainEvent) SimpleDomainObject(org.contextmapper.tactic.dsl.tacticdsl.SimpleDomainObject) CommandEvent(org.contextmapper.tactic.dsl.tacticdsl.CommandEvent) OrchestrationFlow(org.contextmapper.dsl.generator.mdsl.model.OrchestrationFlow) DataType(org.contextmapper.dsl.generator.mdsl.model.DataType) FlowStep(org.contextmapper.dsl.contextMappingDSL.FlowStep) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) DownstreamContext(org.contextmapper.dsl.generator.mdsl.generatorcontext.DownstreamContext) OrchestrationFlow(org.contextmapper.dsl.generator.mdsl.model.OrchestrationFlow) Flow(org.contextmapper.dsl.contextMappingDSL.Flow)

Example 2 with OrchestrationFlow

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());
}
Also used : ServiceSpecification(org.contextmapper.dsl.generator.mdsl.model.ServiceSpecification) EndpointContract(org.contextmapper.dsl.generator.mdsl.model.EndpointContract) MDSLModelCreator(org.contextmapper.dsl.generator.mdsl.MDSLModelCreator) CMLResource(org.contextmapper.dsl.cml.CMLResource) OrchestrationFlow(org.contextmapper.dsl.generator.mdsl.model.OrchestrationFlow) AbstractCMLInputFileTest(org.contextmapper.dsl.AbstractCMLInputFileTest) Test(org.junit.jupiter.api.Test)

Aggregations

OrchestrationFlow (org.contextmapper.dsl.generator.mdsl.model.OrchestrationFlow)2 ServiceSpecification (org.contextmapper.dsl.generator.mdsl.model.ServiceSpecification)2 AbstractCMLInputFileTest (org.contextmapper.dsl.AbstractCMLInputFileTest)1 CMLResource (org.contextmapper.dsl.cml.CMLResource)1 Aggregate (org.contextmapper.dsl.contextMappingDSL.Aggregate)1 Flow (org.contextmapper.dsl.contextMappingDSL.Flow)1 FlowStep (org.contextmapper.dsl.contextMappingDSL.FlowStep)1 MDSLModelCreator (org.contextmapper.dsl.generator.mdsl.MDSLModelCreator)1 DownstreamContext (org.contextmapper.dsl.generator.mdsl.generatorcontext.DownstreamContext)1 DataType (org.contextmapper.dsl.generator.mdsl.model.DataType)1 EndpointContract (org.contextmapper.dsl.generator.mdsl.model.EndpointContract)1 CommandEvent (org.contextmapper.tactic.dsl.tacticdsl.CommandEvent)1 DomainEvent (org.contextmapper.tactic.dsl.tacticdsl.DomainEvent)1 SimpleDomainObject (org.contextmapper.tactic.dsl.tacticdsl.SimpleDomainObject)1 Test (org.junit.jupiter.api.Test)1