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