use of org.contextmapper.dsl.contextMappingDSL.InclusiveAlternativeCommandInvokation 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());
}
}
}
use of org.contextmapper.dsl.contextMappingDSL.InclusiveAlternativeCommandInvokation 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);
}
Aggregations