Search in sources :

Example 1 with EventProduction

use of org.contextmapper.dsl.contextMappingDSL.EventProduction in project context-mapper-dsl by ContextMapper.

the class MDSLModelCreator method mapFlowStep.

private void mapFlowStep(OrchestrationFlow mdslFlow, FlowStep step) {
    if (step.getClass() == org.contextmapper.dsl.contextMappingDSL.impl.CommandInvokationStepImpl.class) {
        CommandInvokationStep cis = (CommandInvokationStep) step;
        EitherCommandOrOperationInvokation ecooi = cis.getAction();
        EList<DomainEvent> events = cis.getEvents();
        if (ecooi instanceof SingleCommandInvokation) {
            SingleCommandInvokation ci = (SingleCommandInvokation) ecooi;
            boolean first;
            String andEvents = combineEvents(events, " + ");
            String commands = "";
            first = true;
            for (CommandEvent ce : ci.getCommands()) {
                // we can only have one entry, but still checking (could also validate size and go to index 0 directly)
                if (!first) {
                    commands += "-";
                    first = false;
                }
                commands += ce.getName();
            }
            mdslFlow.addCommandInvocationStep(andEvents, commands);
        } else if (ecooi instanceof ConcurrentCommandInvokation) {
            ConcurrentCommandInvokation cci = (ConcurrentCommandInvokation) ecooi;
            EList<CommandEvent> commands = cci.getCommands();
            String andEvents = combineEvents(events, " + ");
            String andCommands = commands.get(0).getName();
            for (int i = 1; i < commands.size(); i++) {
                andCommands += " + " + commands.get(i).getName();
            }
            mdslFlow.addCommandInvocationStep(andEvents, andCommands);
        } else if (ecooi instanceof ExclusiveAlternativeCommandInvokation) {
            ExclusiveAlternativeCommandInvokation eaci = (ExclusiveAlternativeCommandInvokation) ecooi;
            EList<CommandEvent> commands = eaci.getCommands();
            String xorEvents = combineEvents(events, " + ");
            String xorCommands = commands.get(0).getName();
            for (int i = 1; i < commands.size(); i++) {
                xorCommands += " x " + commands.get(i).getName();
            }
            mdslFlow.addCommandInvocationStep(xorEvents, xorCommands);
        } else if (ecooi instanceof InclusiveAlternativeCommandInvokation) {
            InclusiveAlternativeCommandInvokation eaci = (InclusiveAlternativeCommandInvokation) ecooi;
            EList<CommandEvent> commands = eaci.getCommands();
            String orEvents = combineEvents(events, " + ");
            String orCommands = commands.get(0).getName();
            for (int i = 1; i < commands.size(); i++) {
                orCommands += " o " + commands.get(i).getName();
            }
            mdslFlow.addCommandInvocationStep(orEvents, orCommands);
        } else {
            throw new GeneratorInputException("Not yet implemented: support for " + ecooi.getClass());
        }
    } else if (step.getClass() == org.contextmapper.dsl.contextMappingDSL.impl.DomainEventProductionStepImpl.class) {
        DomainEventProductionStep depStep = (DomainEventProductionStep) step;
        EitherCommandOrOperation action = depStep.getAction();
        EventProduction ep = depStep.getEventProduction();
        if (ep instanceof SingleEventProduction) {
            EList<DomainEvent> events = ep.getEvents();
            // we can only have one entry, so just in case:
            if (events.size() != 1)
                throw new InvalidParameterException("Single event production must not list more than one event.");
            mdslFlow.addEventProductionStep(action.getCommand().getName(), events.get(0).getName());
        } else if (ep instanceof MultipleEventProduction) {
            String andEvents = mapEvents(action, ep, " + ");
            mdslFlow.addEventProductionStep(action.getCommand().getName(), andEvents);
        } else if (ep instanceof InclusiveAlternativeEventProduction) {
            String orEvents = mapEvents(action, ep, " o ");
            mdslFlow.addEventProductionStep(action.getCommand().getName(), orEvents);
        } else if (ep instanceof ExclusiveAlternativeEventProduction) {
            String xorEvents = mapEvents(action, ep, " x ");
            mdslFlow.addEventProductionStep(action.getCommand().getName(), xorEvents);
        } else {
            throw new GeneratorInputException("Not yet implemented: support for " + ep.getClass());
        }
    }
}
Also used : SingleEventProduction(org.contextmapper.dsl.contextMappingDSL.SingleEventProduction) InclusiveAlternativeEventProduction(org.contextmapper.dsl.contextMappingDSL.InclusiveAlternativeEventProduction) SingleCommandInvokation(org.contextmapper.dsl.contextMappingDSL.SingleCommandInvokation) GeneratorInputException(org.contextmapper.dsl.generator.exception.GeneratorInputException) MultipleEventProduction(org.contextmapper.dsl.contextMappingDSL.MultipleEventProduction) SingleEventProduction(org.contextmapper.dsl.contextMappingDSL.SingleEventProduction) EventProduction(org.contextmapper.dsl.contextMappingDSL.EventProduction) MultipleEventProduction(org.contextmapper.dsl.contextMappingDSL.MultipleEventProduction) ExclusiveAlternativeEventProduction(org.contextmapper.dsl.contextMappingDSL.ExclusiveAlternativeEventProduction) InclusiveAlternativeEventProduction(org.contextmapper.dsl.contextMappingDSL.InclusiveAlternativeEventProduction) InvalidParameterException(java.security.InvalidParameterException) EitherCommandOrOperationInvokation(org.contextmapper.dsl.contextMappingDSL.EitherCommandOrOperationInvokation) ConcurrentCommandInvokation(org.contextmapper.dsl.contextMappingDSL.ConcurrentCommandInvokation) ExclusiveAlternativeCommandInvokation(org.contextmapper.dsl.contextMappingDSL.ExclusiveAlternativeCommandInvokation) CommandInvokationStep(org.contextmapper.dsl.contextMappingDSL.CommandInvokationStep) CommandEvent(org.contextmapper.tactic.dsl.tacticdsl.CommandEvent) EitherCommandOrOperation(org.contextmapper.dsl.contextMappingDSL.EitherCommandOrOperation) DomainEvent(org.contextmapper.tactic.dsl.tacticdsl.DomainEvent) InclusiveAlternativeCommandInvokation(org.contextmapper.dsl.contextMappingDSL.InclusiveAlternativeCommandInvokation) DomainEventProductionStep(org.contextmapper.dsl.contextMappingDSL.DomainEventProductionStep) ExclusiveAlternativeEventProduction(org.contextmapper.dsl.contextMappingDSL.ExclusiveAlternativeEventProduction) EList(org.eclipse.emf.common.util.EList)

Aggregations

InvalidParameterException (java.security.InvalidParameterException)1 CommandInvokationStep (org.contextmapper.dsl.contextMappingDSL.CommandInvokationStep)1 ConcurrentCommandInvokation (org.contextmapper.dsl.contextMappingDSL.ConcurrentCommandInvokation)1 DomainEventProductionStep (org.contextmapper.dsl.contextMappingDSL.DomainEventProductionStep)1 EitherCommandOrOperation (org.contextmapper.dsl.contextMappingDSL.EitherCommandOrOperation)1 EitherCommandOrOperationInvokation (org.contextmapper.dsl.contextMappingDSL.EitherCommandOrOperationInvokation)1 EventProduction (org.contextmapper.dsl.contextMappingDSL.EventProduction)1 ExclusiveAlternativeCommandInvokation (org.contextmapper.dsl.contextMappingDSL.ExclusiveAlternativeCommandInvokation)1 ExclusiveAlternativeEventProduction (org.contextmapper.dsl.contextMappingDSL.ExclusiveAlternativeEventProduction)1 InclusiveAlternativeCommandInvokation (org.contextmapper.dsl.contextMappingDSL.InclusiveAlternativeCommandInvokation)1 InclusiveAlternativeEventProduction (org.contextmapper.dsl.contextMappingDSL.InclusiveAlternativeEventProduction)1 MultipleEventProduction (org.contextmapper.dsl.contextMappingDSL.MultipleEventProduction)1 SingleCommandInvokation (org.contextmapper.dsl.contextMappingDSL.SingleCommandInvokation)1 SingleEventProduction (org.contextmapper.dsl.contextMappingDSL.SingleEventProduction)1 GeneratorInputException (org.contextmapper.dsl.generator.exception.GeneratorInputException)1 CommandEvent (org.contextmapper.tactic.dsl.tacticdsl.CommandEvent)1 DomainEvent (org.contextmapper.tactic.dsl.tacticdsl.DomainEvent)1 EList (org.eclipse.emf.common.util.EList)1