Search in sources :

Example 1 with MultipleEventProduction

use of org.contextmapper.dsl.contextMappingDSL.MultipleEventProduction 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)

Example 2 with MultipleEventProduction

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

the class Flow2SketchMinerConverter method convert.

private SimplifiedFlowStep convert(FlowStep step) {
    Set<Task> froms = Sets.newLinkedHashSet();
    Set<Task> tos = Sets.newLinkedHashSet();
    ToType toType = ToType.XOR;
    if (step instanceof CommandInvokationStep) {
        froms.addAll(((CommandInvokationStep) step).getEvents().stream().map(e -> getOrCreateTask(e.getName(), TaskType.EVENT)).collect(Collectors.toList()));
        if (((CommandInvokationStep) step).getAction() instanceof CommandInvokation) {
            CommandInvokation commandInvokation = (CommandInvokation) ((CommandInvokationStep) step).getAction();
            tos.addAll(commandInvokation.getCommands().stream().map(c -> getOrCreateTask(c.getName(), TaskType.COMMAND)).collect(Collectors.toList()));
            if (commandInvokation instanceof ConcurrentCommandInvokation)
                toType = ToType.AND;
            if (commandInvokation instanceof InclusiveAlternativeCommandInvokation)
                toType = ToType.OR;
        } else if (((CommandInvokationStep) step).getAction() instanceof OperationInvokation) {
            OperationInvokation operationInvokation = (OperationInvokation) ((CommandInvokationStep) step).getAction();
            tos.addAll(operationInvokation.getOperations().stream().map(o -> getOrCreateTask(o.getName(), TaskType.COMMAND)).collect(Collectors.toList()));
            if (operationInvokation instanceof ConcurrentOperationInvokation)
                toType = ToType.AND;
            if (operationInvokation instanceof InclusiveAlternativeOperationInvokation)
                toType = ToType.OR;
        }
    } else if (step instanceof DomainEventProductionStep) {
        DomainEventProductionStep eventStep = (DomainEventProductionStep) step;
        froms.add(createTask4EventProduction(eventStep));
        tos.addAll(eventStep.getEventProduction().getEvents().stream().map(e -> getOrCreateTask(e.getName(), TaskType.EVENT)).collect(Collectors.toList()));
        if (eventStep.getEventProduction() instanceof MultipleEventProduction)
            toType = ToType.AND;
        if (eventStep.getEventProduction() instanceof InclusiveAlternativeEventProduction)
            toType = ToType.OR;
    }
    return new SimplifiedFlowStep(froms, tos, toType);
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) TaskSequence(org.contextmapper.dsl.generator.sketchminer.model.TaskSequence) StateTransition(org.contextmapper.tactic.dsl.tacticdsl.StateTransition) StringUtils(org.apache.commons.lang3.StringUtils) EitherCommandOrOperation(org.contextmapper.dsl.contextMappingDSL.EitherCommandOrOperation) CommandInvokation(org.contextmapper.dsl.contextMappingDSL.CommandInvokation) Lists(com.google.common.collect.Lists) InclusiveAlternativeOperationInvokation(org.contextmapper.dsl.contextMappingDSL.InclusiveAlternativeOperationInvokation) EcoreUtil2(org.eclipse.xtext.EcoreUtil2) Map(java.util.Map) TaskType(org.contextmapper.dsl.generator.sketchminer.model.TaskType) CommandInvokationStep(org.contextmapper.dsl.contextMappingDSL.CommandInvokationStep) Task(org.contextmapper.dsl.generator.sketchminer.model.Task) ConcurrentCommandInvokation(org.contextmapper.dsl.contextMappingDSL.ConcurrentCommandInvokation) ConcurrentOperationInvokation(org.contextmapper.dsl.contextMappingDSL.ConcurrentOperationInvokation) Application(org.contextmapper.dsl.contextMappingDSL.Application) Iterator(java.util.Iterator) Collection(java.util.Collection) Set(java.util.Set) MultipleEventProduction(org.contextmapper.dsl.contextMappingDSL.MultipleEventProduction) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) Sets(com.google.common.collect.Sets) FlowStep(org.contextmapper.dsl.contextMappingDSL.FlowStep) CMLModelObjectsResolvingHelper(org.contextmapper.dsl.cml.CMLModelObjectsResolvingHelper) List(java.util.List) InclusiveAlternativeEventProduction(org.contextmapper.dsl.contextMappingDSL.InclusiveAlternativeEventProduction) OperationInvokation(org.contextmapper.dsl.contextMappingDSL.OperationInvokation) SketchMinerModel(org.contextmapper.dsl.generator.sketchminer.model.SketchMinerModel) DomainEventProductionStep(org.contextmapper.dsl.contextMappingDSL.DomainEventProductionStep) ToType(org.contextmapper.dsl.generator.sketchminer.converter.SimplifiedFlowStep.ToType) Flow(org.contextmapper.dsl.contextMappingDSL.Flow) InclusiveAlternativeCommandInvokation(org.contextmapper.dsl.contextMappingDSL.InclusiveAlternativeCommandInvokation) Task(org.contextmapper.dsl.generator.sketchminer.model.Task) InclusiveAlternativeEventProduction(org.contextmapper.dsl.contextMappingDSL.InclusiveAlternativeEventProduction) InclusiveAlternativeCommandInvokation(org.contextmapper.dsl.contextMappingDSL.InclusiveAlternativeCommandInvokation) MultipleEventProduction(org.contextmapper.dsl.contextMappingDSL.MultipleEventProduction) DomainEventProductionStep(org.contextmapper.dsl.contextMappingDSL.DomainEventProductionStep) ConcurrentOperationInvokation(org.contextmapper.dsl.contextMappingDSL.ConcurrentOperationInvokation) InclusiveAlternativeOperationInvokation(org.contextmapper.dsl.contextMappingDSL.InclusiveAlternativeOperationInvokation) ConcurrentOperationInvokation(org.contextmapper.dsl.contextMappingDSL.ConcurrentOperationInvokation) OperationInvokation(org.contextmapper.dsl.contextMappingDSL.OperationInvokation) CommandInvokation(org.contextmapper.dsl.contextMappingDSL.CommandInvokation) ConcurrentCommandInvokation(org.contextmapper.dsl.contextMappingDSL.ConcurrentCommandInvokation) InclusiveAlternativeCommandInvokation(org.contextmapper.dsl.contextMappingDSL.InclusiveAlternativeCommandInvokation) ToType(org.contextmapper.dsl.generator.sketchminer.converter.SimplifiedFlowStep.ToType) ConcurrentCommandInvokation(org.contextmapper.dsl.contextMappingDSL.ConcurrentCommandInvokation) CommandInvokationStep(org.contextmapper.dsl.contextMappingDSL.CommandInvokationStep) InclusiveAlternativeOperationInvokation(org.contextmapper.dsl.contextMappingDSL.InclusiveAlternativeOperationInvokation)

Aggregations

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 InclusiveAlternativeCommandInvokation (org.contextmapper.dsl.contextMappingDSL.InclusiveAlternativeCommandInvokation)2 InclusiveAlternativeEventProduction (org.contextmapper.dsl.contextMappingDSL.InclusiveAlternativeEventProduction)2 MultipleEventProduction (org.contextmapper.dsl.contextMappingDSL.MultipleEventProduction)2 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Sets (com.google.common.collect.Sets)1 InvalidParameterException (java.security.InvalidParameterException)1 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 StringUtils (org.apache.commons.lang3.StringUtils)1 CMLModelObjectsResolvingHelper (org.contextmapper.dsl.cml.CMLModelObjectsResolvingHelper)1 Application (org.contextmapper.dsl.contextMappingDSL.Application)1