Search in sources :

Example 1 with CommandEvent

use of org.contextmapper.tactic.dsl.tacticdsl.CommandEvent in project context-mapper-dsl by ContextMapper.

the class ApplicationFlowSemanticsValidator method commandInvokationMustReferCommandInSameContext.

@Check
public void commandInvokationMustReferCommandInSameContext(final CommandInvokation commandInvokation) {
    CMLModelObjectsResolvingHelper helper = new CMLModelObjectsResolvingHelper((ContextMappingModel) EcoreUtil2.getRootContainer(commandInvokation));
    BoundedContext currentContext = helper.resolveBoundedContext(commandInvokation);
    for (CommandEvent commandEvent : commandInvokation.getCommands()) {
        BoundedContext commandContext = helper.resolveBoundedContext((EObject) commandEvent);
        if (commandContext == null || !currentContext.getName().equals(commandContext.getName()))
            error(String.format(COMMAND_OR_OPERATION_IS_NOT_PART_OF_BOUNDED_CONTEXT, commandEvent.getName(), currentContext.getName()), commandInvokation, ContextMappingDSLPackage.Literals.COMMAND_INVOKATION__COMMANDS, commandInvokation.getCommands().indexOf(commandEvent));
    }
}
Also used : CMLModelObjectsResolvingHelper(org.contextmapper.dsl.cml.CMLModelObjectsResolvingHelper) CommandEvent(org.contextmapper.tactic.dsl.tacticdsl.CommandEvent) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) Check(org.eclipse.xtext.validation.Check)

Example 2 with CommandEvent

use of org.contextmapper.tactic.dsl.tacticdsl.CommandEvent in project context-mapper-dsl by ContextMapper.

the class PlantUMLBoundedContextClassDiagramCreatorTest method respectEventsAndCommandsAndServicesFromApplicationLayer.

@Test
public void respectEventsAndCommandsAndServicesFromApplicationLayer() {
    // given
    BoundedContext boundedContext = ContextMappingDSLFactory.eINSTANCE.createBoundedContext();
    Application app = ContextMappingDSLFactory.eINSTANCE.createApplication();
    boundedContext.setApplication(app);
    DomainEvent testEvent = TacticdslFactory.eINSTANCE.createDomainEvent();
    testEvent.setName("TestEvent");
    app.getEvents().add(testEvent);
    CommandEvent testCommand = TacticdslFactory.eINSTANCE.createCommandEvent();
    testCommand.setName("TestCommand");
    app.getCommands().add(testCommand);
    Service testService = TacticdslFactory.eINSTANCE.createService();
    testService.setName("TestService");
    app.getServices().add(testService);
    // when
    String plantUML = this.creator.createDiagram(boundedContext);
    // then
    assertTrue(plantUML.contains("package \"'Application'\" <<Rectangle>> {" + System.lineSeparator()));
    assertTrue(plantUML.contains("	class TestEvent <<(E,#ff9f4b) Domain Event>> {" + System.lineSeparator() + "	}" + System.lineSeparator()));
    assertTrue(plantUML.contains("	class TestCommand <<(C,#3bc5e9) Command>> {" + System.lineSeparator() + "	}" + System.lineSeparator()));
    assertTrue(plantUML.contains("	class TestService <<(S,DarkSeaGreen) Service>> {" + System.lineSeparator() + "	}" + System.lineSeparator()));
}
Also used : DomainEvent(org.contextmapper.tactic.dsl.tacticdsl.DomainEvent) CommandEvent(org.contextmapper.tactic.dsl.tacticdsl.CommandEvent) Service(org.contextmapper.tactic.dsl.tacticdsl.Service) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) Application(org.contextmapper.dsl.contextMappingDSL.Application) AbstractCMLInputFileTest(org.contextmapper.dsl.AbstractCMLInputFileTest) Test(org.junit.jupiter.api.Test)

Example 3 with CommandEvent

use of org.contextmapper.tactic.dsl.tacticdsl.CommandEvent in project context-mapper-dsl by ContextMapper.

the class PlantUMLBoundedContextClassDiagramCreatorTest method canCreateInheritance4CommandEvent.

@Test
public void canCreateInheritance4CommandEvent() {
    // given
    BoundedContext boundedContext = ContextMappingDSLFactory.eINSTANCE.createBoundedContext();
    Aggregate aggregate = ContextMappingDSLFactory.eINSTANCE.createAggregate();
    aggregate.setName("testAggregate");
    boundedContext.getAggregates().add(aggregate);
    CommandEvent event1 = TacticdslFactory.eINSTANCE.createCommandEvent();
    event1.setName("Customer");
    CommandEvent event2 = TacticdslFactory.eINSTANCE.createCommandEvent();
    event2.setName("AbstractEvent");
    event1.setExtends(event2);
    aggregate.getDomainObjects().add(event1);
    aggregate.getDomainObjects().add(event2);
    // when
    String plantUML = this.creator.createDiagram(boundedContext);
    // then
    assertTrue(plantUML.contains("	class Customer <<(C,#3bc5e9) Command>> {" + System.lineSeparator() + "	}" + System.lineSeparator()));
    assertTrue(plantUML.contains("	class AbstractEvent <<(C,#3bc5e9) Command>> {" + System.lineSeparator() + "	}" + System.lineSeparator()));
    assertTrue(plantUML.contains("Customer --|> AbstractEvent" + System.lineSeparator()));
}
Also used : CommandEvent(org.contextmapper.tactic.dsl.tacticdsl.CommandEvent) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) AbstractCMLInputFileTest(org.contextmapper.dsl.AbstractCMLInputFileTest) Test(org.junit.jupiter.api.Test)

Example 4 with CommandEvent

use of org.contextmapper.tactic.dsl.tacticdsl.CommandEvent 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 5 with CommandEvent

use of org.contextmapper.tactic.dsl.tacticdsl.CommandEvent in project context-mapper-dsl by ContextMapper.

the class PlantUMLBoundedContextClassDiagramCreator method printApplication.

private void printApplication(Application application, int indentation) {
    printIndentation(indentation);
    String name = StringUtils.isNotEmpty(application.getName()) ? application.getName() : "Application";
    sb.append("package ").append("\"'").append(name).append("'").append("\"").append(" <<Rectangle>> ").append("{");
    linebreak();
    if (!application.getFlows().isEmpty()) {
        printIndentation(indentation + 1);
        sb.append("legend left");
        linebreak();
        printIndentation(indentation + 2);
        sb.append("This application layer contains flow definitions (visualization available via BPMN Sketch Miner).");
        linebreak();
        printIndentation(indentation + 1);
        sb.append("end legend");
        linebreak();
    }
    for (DomainEvent event : application.getEvents()) {
        printDomainObject(event, indentation + 1);
    }
    for (CommandEvent command : application.getCommands()) {
        printDomainObject(command, indentation + 1);
    }
    for (Service service : application.getServices()) {
        printService(service, indentation + 1);
    }
    printIndentation(indentation);
    sb.append("}");
    linebreak();
}
Also used : DomainEvent(org.contextmapper.tactic.dsl.tacticdsl.DomainEvent) CommandEvent(org.contextmapper.tactic.dsl.tacticdsl.CommandEvent) Service(org.contextmapper.tactic.dsl.tacticdsl.Service)

Aggregations

CommandEvent (org.contextmapper.tactic.dsl.tacticdsl.CommandEvent)8 BoundedContext (org.contextmapper.dsl.contextMappingDSL.BoundedContext)5 DomainEvent (org.contextmapper.tactic.dsl.tacticdsl.DomainEvent)5 Aggregate (org.contextmapper.dsl.contextMappingDSL.Aggregate)4 AbstractCMLInputFileTest (org.contextmapper.dsl.AbstractCMLInputFileTest)3 InvalidParameterException (java.security.InvalidParameterException)2 Application (org.contextmapper.dsl.contextMappingDSL.Application)2 CommandInvokationStep (org.contextmapper.dsl.contextMappingDSL.CommandInvokationStep)2 ConcurrentCommandInvokation (org.contextmapper.dsl.contextMappingDSL.ConcurrentCommandInvokation)2 DomainEventProductionStep (org.contextmapper.dsl.contextMappingDSL.DomainEventProductionStep)2 EitherCommandOrOperation (org.contextmapper.dsl.contextMappingDSL.EitherCommandOrOperation)2 EitherCommandOrOperationInvokation (org.contextmapper.dsl.contextMappingDSL.EitherCommandOrOperationInvokation)2 EventProduction (org.contextmapper.dsl.contextMappingDSL.EventProduction)2 ExclusiveAlternativeCommandInvokation (org.contextmapper.dsl.contextMappingDSL.ExclusiveAlternativeCommandInvokation)2 ExclusiveAlternativeEventProduction (org.contextmapper.dsl.contextMappingDSL.ExclusiveAlternativeEventProduction)2 Flow (org.contextmapper.dsl.contextMappingDSL.Flow)2 FlowStep (org.contextmapper.dsl.contextMappingDSL.FlowStep)2 InclusiveAlternativeCommandInvokation (org.contextmapper.dsl.contextMappingDSL.InclusiveAlternativeCommandInvokation)2 InclusiveAlternativeEventProduction (org.contextmapper.dsl.contextMappingDSL.InclusiveAlternativeEventProduction)2 MultipleEventProduction (org.contextmapper.dsl.contextMappingDSL.MultipleEventProduction)2