Search in sources :

Example 1 with DomainEventProductionStep

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

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

the class PlantUMLStateDiagramCreator4Flow method printDiagramContent.

@Override
protected void printDiagramContent(Flow flow) {
    List<DomainEventProductionStep> eventProductionStepsWithStateTransitions = flow.getSteps().stream().filter(s -> s instanceof DomainEventProductionStep).map(s -> (DomainEventProductionStep) s).filter(s -> s.getStateTransition() != null).collect(Collectors.toList());
    List<StateTransition> allStateTransitions = eventProductionStepsWithStateTransitions.stream().map(s -> s.getStateTransition()).collect(Collectors.toList());
    for (String state : collectStates(allStateTransitions)) {
        printState(state);
    }
    for (DomainEventProductionStep step : eventProductionStepsWithStateTransitions) printTransition(step.getStateTransition(), step.getAction().getCommand() != null ? step.getAction().getCommand().getName() : step.getAction().getOperation().getName());
    linebreak(2);
    sb.append("legend top center");
    linebreak();
    sb.append("  " + flow.getName() + " State Transitions");
    linebreak();
    sb.append("endlegend");
}
Also used : List(java.util.List) DomainEventProductionStep(org.contextmapper.dsl.contextMappingDSL.DomainEventProductionStep) StateTransition(org.contextmapper.tactic.dsl.tacticdsl.StateTransition) Flow(org.contextmapper.dsl.contextMappingDSL.Flow) Collectors(java.util.stream.Collectors) DomainEventProductionStep(org.contextmapper.dsl.contextMappingDSL.DomainEventProductionStep) StateTransition(org.contextmapper.tactic.dsl.tacticdsl.StateTransition)

Example 3 with DomainEventProductionStep

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

Example 4 with DomainEventProductionStep

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

the class ApplicationFlowSemanticsValidator method checkThatStateTransitionStatesBelongToAggregate.

@Check
public void checkThatStateTransitionStatesBelongToAggregate(final DomainEventProductionStep step) {
    if (step.getAggregate() == null)
        return;
    if (step.getStateTransition() == null)
        return;
    CMLModelObjectsResolvingHelper helper = new CMLModelObjectsResolvingHelper((ContextMappingModel) EcoreUtil2.getRootContainer(step));
    Set<String> aggregateStates = helper.resolveAggregateStates(step.getAggregate());
    for (EnumValue value : step.getStateTransition().getFrom()) {
        if (!aggregateStates.contains(value.getName()))
            error(String.format(STATE_VALUE_DOES_NOT_BELONG_TO_AGGREGATE, value.getName(), step.getAggregate().getName()), step.getStateTransition(), TacticdslPackage.Literals.STATE_TRANSITION__FROM, step.getStateTransition().getFrom().indexOf(value));
    }
    for (EnumValue value : step.getStateTransition().getTarget().getTo().stream().map(s -> s.getValue()).collect(Collectors.toList())) {
        if (!aggregateStates.contains(value.getName()))
            error(String.format(STATE_VALUE_DOES_NOT_BELONG_TO_AGGREGATE, value.getName(), step.getAggregate().getName()), step.getStateTransition().getTarget(), TacticdslPackage.Literals.STATE_TRANSITION_TARGET__TO, step.getStateTransition().getTarget().getTo().indexOf(value));
    }
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) VISUALIZE_FLOW_WITH_SKETCH_MINER(org.contextmapper.dsl.validation.ValidationMessages.VISUALIZE_FLOW_WITH_SKETCH_MINER) TacticdslPackage(org.contextmapper.tactic.dsl.tacticdsl.TacticdslPackage) Set(java.util.Set) EnumValue(org.contextmapper.tactic.dsl.tacticdsl.EnumValue) EObject(org.eclipse.emf.ecore.EObject) COMMAND_OR_OPERATION_IS_NOT_PART_OF_BOUNDED_CONTEXT(org.contextmapper.dsl.validation.ValidationMessages.COMMAND_OR_OPERATION_IS_NOT_PART_OF_BOUNDED_CONTEXT) Collectors(java.util.stream.Collectors) EitherCommandOrOperation(org.contextmapper.dsl.contextMappingDSL.EitherCommandOrOperation) STATE_VALUE_DOES_NOT_BELONG_TO_AGGREGATE(org.contextmapper.dsl.validation.ValidationMessages.STATE_VALUE_DOES_NOT_BELONG_TO_AGGREGATE) CommandEvent(org.contextmapper.tactic.dsl.tacticdsl.CommandEvent) CMLModelObjectsResolvingHelper(org.contextmapper.dsl.cml.CMLModelObjectsResolvingHelper) CommandInvokation(org.contextmapper.dsl.contextMappingDSL.CommandInvokation) ServiceOperation(org.contextmapper.tactic.dsl.tacticdsl.ServiceOperation) OperationInvokation(org.contextmapper.dsl.contextMappingDSL.OperationInvokation) EcoreUtil2(org.eclipse.xtext.EcoreUtil2) DomainEventProductionStep(org.contextmapper.dsl.contextMappingDSL.DomainEventProductionStep) ContextMappingDSLPackage(org.contextmapper.dsl.contextMappingDSL.ContextMappingDSLPackage) Flow(org.contextmapper.dsl.contextMappingDSL.Flow) Check(org.eclipse.xtext.validation.Check) EValidatorRegistrar(org.eclipse.xtext.validation.EValidatorRegistrar) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) AbstractDeclarativeValidator(org.eclipse.xtext.validation.AbstractDeclarativeValidator) CMLModelObjectsResolvingHelper(org.contextmapper.dsl.cml.CMLModelObjectsResolvingHelper) EnumValue(org.contextmapper.tactic.dsl.tacticdsl.EnumValue) Check(org.eclipse.xtext.validation.Check)

Aggregations

DomainEventProductionStep (org.contextmapper.dsl.contextMappingDSL.DomainEventProductionStep)4 Collectors (java.util.stream.Collectors)3 EitherCommandOrOperation (org.contextmapper.dsl.contextMappingDSL.EitherCommandOrOperation)3 Flow (org.contextmapper.dsl.contextMappingDSL.Flow)3 List (java.util.List)2 Set (java.util.Set)2 CMLModelObjectsResolvingHelper (org.contextmapper.dsl.cml.CMLModelObjectsResolvingHelper)2 CommandInvokation (org.contextmapper.dsl.contextMappingDSL.CommandInvokation)2 CommandInvokationStep (org.contextmapper.dsl.contextMappingDSL.CommandInvokationStep)2 ConcurrentCommandInvokation (org.contextmapper.dsl.contextMappingDSL.ConcurrentCommandInvokation)2 ContextMappingModel (org.contextmapper.dsl.contextMappingDSL.ContextMappingModel)2 InclusiveAlternativeCommandInvokation (org.contextmapper.dsl.contextMappingDSL.InclusiveAlternativeCommandInvokation)2 InclusiveAlternativeEventProduction (org.contextmapper.dsl.contextMappingDSL.InclusiveAlternativeEventProduction)2 MultipleEventProduction (org.contextmapper.dsl.contextMappingDSL.MultipleEventProduction)2 OperationInvokation (org.contextmapper.dsl.contextMappingDSL.OperationInvokation)2 CommandEvent (org.contextmapper.tactic.dsl.tacticdsl.CommandEvent)2 StateTransition (org.contextmapper.tactic.dsl.tacticdsl.StateTransition)2 EcoreUtil2 (org.eclipse.xtext.EcoreUtil2)2 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1