use of de.hpi.bpt.scylla.exception.ScyllaValidationException in project scylla by bptlab.
the class InclusiveGatewayEventPlugin method eventRoutine.
// @SuppressWarnings("unchecked")
@Override
public void eventRoutine(GatewayEvent desmojEvent, ProcessInstance processInstance) throws ScyllaRuntimeException {
SimulationModel model = (SimulationModel) desmojEvent.getModel();
ProcessModel processModel = processInstance.getProcessModel();
int nodeId = desmojEvent.getNodeId();
boolean showInTrace = desmojEvent.traceIsOn();
GatewayType type = processModel.getGateways().get(nodeId);
try {
Set<Integer> idsOfNextNodes = processModel.getIdsOfNextNodes(nodeId);
if (idsOfNextNodes.size() > 1) {
// split
if (type == GatewayType.INCLUSIVE) {
// TODO this is incomplete, must find corresponding join gateway and define behavior for it
// Map<Integer, Object> branchingDistributions = desmojObjects.getDistributionsExtensional()
// .get(getName());
// Map<Integer, BoolDistBernoulli> distributions = (Map<Integer, BoolDistBernoulli>)
// branchingDistributions
// .get(nodeId);
// Set<Integer> idsOfNodesToBeActivated = new HashSet<Integer>();
// for (Integer nextFlowId : distributions.keySet()) {
// BoolDistBernoulli distribution = distributions.get(nextFlowId);
// if (!processModel.getIdentifiers().keySet().contains(nextFlowId)) {
// throw new ScyllaValidationException("Flow with id " + nextFlowId + " does not exist.");
// }
// boolean activateOutgoingFlow = distribution.sample();
// if (activateOutgoingFlow) {
// Set<Integer> nodeIds = processModel.getTargetObjectIds(nextFlowId);
// if (nodeIds.size() != 1) {
// throw new ScyllaValidationException("Flow " + nextFlowId
// + " does not connect to 1 node, but" + nodeIds.size() + " .");
// }
// int nextNodeId = nodeIds.iterator().next();
//
// idsOfNodesToBeActivated.add(nextNodeId);
// }
// // TODO default flow
// }
//
// Map<Integer, ScyllaEvent> nextEventMap = desmojEvent.getNextEventMap();
// List<Integer> indicesOfEventsToKeep = new ArrayList<Integer>();
// for (int index : nextEventMap.keySet()) {
// ScyllaEvent eventCandidate = nextEventMap.get(index);
// int nodeIdOfCandidate = eventCandidate.getNodeId();
// if (idsOfNodesToBeActivated.contains(nodeIdOfCandidate)) {
// indicesOfEventsToKeep.add(index);
// }
// }
// Map<Integer, TimeSpan> timeSpanToNextEventMap = desmojEvent.getTimeSpanToNextEventMap();
// nextEventMap.keySet().retainAll(indicesOfEventsToKeep);
// timeSpanToNextEventMap.keySet().retainAll(indicesOfEventsToKeep);
}
}
} catch (NodeNotFoundException | ScyllaValidationException e) {
System.err.println(e.getMessage());
e.printStackTrace();
SimulationUtils.abort(model, processInstance, nodeId, showInTrace);
return;
}
}
use of de.hpi.bpt.scylla.exception.ScyllaValidationException in project scylla by bptlab.
the class InclusiveGatewaySCParserPlugin method parse.
@Override
public Map<String, Object> parse(SimulationConfiguration simulationInput, Element sim) throws ScyllaValidationException {
Map<Integer, BranchingBehavior> branchingBehaviors = new HashMap<Integer, BranchingBehavior>();
Namespace simNamespace = sim.getNamespace();
ProcessModel processModel = simulationInput.getProcessModel();
for (Element el : sim.getChildren()) {
String elementName = el.getName();
if (elementName.equals("inclusiveGateway")) {
String identifier = el.getAttributeValue("id");
if (identifier == null) {
DebugLogger.log("Warning: Simulation configuration definition element '" + elementName + "' does not have an identifier, skip.");
// no matching element in process, so skip definition
continue;
}
Integer nodeId = processModel.getIdentifiersToNodeIds().get(identifier);
if (nodeId == null) {
DebugLogger.log("Simulation configuration definition for process element '" + identifier + "', but not available in process, skip.");
// no matching element in process, so skip definition
continue;
}
List<Element> outgoingSequenceFlows = el.getChildren("outgoingSequenceFlow", simNamespace);
if (outgoingSequenceFlows.size() > 0) {
Map<Integer, Double> branchingProbabilities = new HashMap<Integer, Double>();
for (Element elem : outgoingSequenceFlows) {
Integer nodeIdOfSequenceFlow = processModel.getIdentifiersToNodeIds().get(elem.getAttributeValue("id"));
if (nodeIdOfSequenceFlow != null) {
Double branchingProbability = Double.valueOf(elem.getChildText("branchingProbability", simNamespace));
if (branchingProbability < 0 || branchingProbability > 1) {
throw new ScyllaValidationException("Inclusive gateway branching probability for " + identifier + " is out of bounds [0,1].");
}
branchingProbabilities.put(nodeIdOfSequenceFlow, branchingProbability);
}
}
BranchingBehavior branchingBehavior = new BranchingBehavior(branchingProbabilities);
branchingBehaviors.put(nodeId, branchingBehavior);
}
}
}
HashMap<String, Object> extensionAttributes = new HashMap<String, Object>();
extensionAttributes.put("branchingBehaviors", branchingBehaviors);
return extensionAttributes;
}
use of de.hpi.bpt.scylla.exception.ScyllaValidationException in project scylla by bptlab.
the class SubprocessBPMNEEPlugin method eventRoutine.
@Override
public void eventRoutine(BPMNEndEvent desmojEvent, ProcessInstance processInstance) throws ScyllaRuntimeException {
ProcessModel processModel = processInstance.getProcessModel();
if (processModel.getParent() != null && processInstanceIsCompleted(processInstance)) {
// works
try {
ProcessSimulationComponents desmojObjects = desmojEvent.getDesmojObjects();
ProcessSimulationComponents parentDesmojObjects = desmojObjects.getParent();
ProcessModel parentModel = processModel.getParent();
int nodeIdInParent = processModel.getNodeIdInParent();
ProcessInstance parentProcessInstance = processInstance.getParent();
// behavior when sub-process sends events:
// none -> back to normal flow
// message -> "send it"
// error -> to parent
// escalation -> to parent
// cancel -> nonono!
// compensation -> ... not now
// signal -> ... not now
// terminate -> terminate sub-process (kill all events of sub-process instance (MI sub-process
// not affected))
// ...
// timer -> special treatment
Set<Integer> idsOfNextNodes = parentModel.getIdsOfNextNodes(nodeIdInParent);
// normal flow: must not have more than one successor
if (idsOfNextNodes.size() != 1) {
int nodeId = desmojEvent.getNodeId();
throw new ScyllaValidationException("Subprocess " + nodeId + " does not have 1 successor, but " + idsOfNextNodes.size() + ".");
}
Integer nextNodeId = idsOfNextNodes.iterator().next();
// TODO let the parent create the next node, so remove the lines below
List<ScyllaEvent> events = SimulationUtils.createEventsForNextNode(desmojEvent, parentDesmojObjects, parentProcessInstance, nextNodeId);
// next event occurs immediately after start event
TimeSpan timeSpan = new TimeSpan(0);
String parentProcessInstanceName = parentProcessInstance.getName();
SubprocessPluginUtils pluginInstance = SubprocessPluginUtils.getInstance();
TaskTerminateEvent eventOfParent = pluginInstance.getEventsOnHold().get(parentProcessInstanceName).get(nodeIdInParent);
if (eventOfParent != null) {
events.add(eventOfParent);
pluginInstance.getEventsOnHold().get(parentProcessInstanceName).remove(nodeIdInParent);
pluginInstance.getNameOfEventsThatWereOnHold().add(eventOfParent.getName());
}
for (ScyllaEvent event : events) {
int index = desmojEvent.getNewEventIndex();
desmojEvent.getNextEventMap().put(index, event);
desmojEvent.getTimeSpanToNextEventMap().put(index, timeSpan);
}
} catch (NodeNotFoundException | ScyllaValidationException | ScyllaRuntimeException e) {
SimulationModel model = (SimulationModel) desmojEvent.getModel();
int nodeId = desmojEvent.getNodeId();
boolean showInTrace = model.traceIsOn();
DebugLogger.error(e.getMessage());
e.printStackTrace();
SimulationUtils.abort(model, processInstance, nodeId, showInTrace);
}
}
}
use of de.hpi.bpt.scylla.exception.ScyllaValidationException in project scylla by bptlab.
the class BPMNIntermediateEvent method eventRoutine.
@Override
public void eventRoutine(ProcessInstance processInstance) throws SuspendExecution {
super.eventRoutine(processInstance);
SimulationModel model = (SimulationModel) getModel();
ProcessModel processModel = processInstance.getProcessModel();
try {
EventType type = processModel.getEventTypes().get(nodeId);
// Long duration = null;
// TimeUnit timeUnit = null;
Map<EventDefinitionType, Map<String, String>> definitions = processModel.getEventDefinitions().get(nodeId);
Set<String> messages = new HashSet<String>();
for (EventDefinitionType definition : definitions.keySet()) {
// TODO what about implicit throw events?
if (definition == EventDefinitionType.CANCEL) {
// TODO: cancel event only in transaction sub-process
// isInterrupting?
boolean cancelActivity = processModel.getCancelActivities().get(nodeId);
if (type == EventType.BOUNDARY && cancelActivity) {
String message = "Boundary Cancel Event: " + displayName;
messages.add(message);
} else {
SimulationUtils.sendElementNotSupportedTraceNote(model, processModel, displayName, nodeId);
SimulationUtils.abort(model, processInstance, nodeId, traceIsOn());
return;
}
} else if (definition == EventDefinitionType.COMPENSATION) {
// isInterrupting?
boolean cancelActivity = processModel.getCancelActivities().get(nodeId);
if (type == EventType.BOUNDARY && cancelActivity) {
String message = "Boundary Compensation Event: " + displayName;
messages.add(message);
} else {
SimulationUtils.sendElementNotSupportedTraceNote(model, processModel, displayName, nodeId);
SimulationUtils.abort(model, processInstance, nodeId, traceIsOn());
return;
}
} else if (definition == EventDefinitionType.CONDITIONAL) {
if (type == EventType.BOUNDARY) {
// isInterrupting?
boolean cancelActivity = processModel.getCancelActivities().get(nodeId);
if (cancelActivity) {
String message = "Boundary Conditional Event (Interrupting): " + displayName;
messages.add(message);
} else {
String message = "Boundary Conditional Event (Non-Interrupting): " + displayName;
messages.add(message);
}
} else if (type == EventType.INTERMEDIATE_CATCH) {
String message = "Intermediate Conditional Event (Catching): " + displayName;
messages.add(message);
} else {
SimulationUtils.sendElementNotSupportedTraceNote(model, processModel, displayName, nodeId);
SimulationUtils.abort(model, processInstance, nodeId, traceIsOn());
return;
}
} else if (definition == EventDefinitionType.ERROR) {
// isInterrupting?
boolean cancelActivity = processModel.getCancelActivities().get(nodeId);
if (type == EventType.BOUNDARY && cancelActivity) {
String message = "Boundary Error Event: " + displayName;
messages.add(message);
} else {
SimulationUtils.sendElementNotSupportedTraceNote(model, processModel, displayName, nodeId);
SimulationUtils.abort(model, processInstance, nodeId, traceIsOn());
return;
}
} else if (definition == EventDefinitionType.ESCALATION) {
if (type == EventType.BOUNDARY) {
// isInterrupting?
boolean cancelActivity = processModel.getCancelActivities().get(nodeId);
if (cancelActivity) {
String message = "Boundary Escalation Event (Interrupting): " + displayName;
messages.add(message);
} else {
String message = "Boundary Escalation Event (Non-Interrupting): " + displayName;
messages.add(message);
}
} else if (type == EventType.INTERMEDIATE_THROW) {
String message = "Intermediate Escalation Event (Throwing): " + displayName;
messages.add(message);
} else {
SimulationUtils.sendElementNotSupportedTraceNote(model, processModel, displayName, nodeId);
SimulationUtils.abort(model, processInstance, nodeId, traceIsOn());
return;
}
} else if (definition == EventDefinitionType.LINK) {
if (type == EventType.INTERMEDIATE_CATCH) {
String message = "Intermediate Link Event (Catching): " + displayName;
messages.add(message);
} else if (type == EventType.INTERMEDIATE_THROW) {
String message = "Intermediate Link Event (Throwing): " + displayName;
messages.add(message);
} else {
SimulationUtils.sendElementNotSupportedTraceNote(model, processModel, displayName, nodeId);
SimulationUtils.abort(model, processInstance, nodeId, traceIsOn());
return;
}
} else if (definition == EventDefinitionType.MESSAGE) {
if (type == EventType.BOUNDARY) {
// isInterrupting?
boolean cancelActivity = processModel.getCancelActivities().get(nodeId);
if (cancelActivity) {
String message = "Boundary Message Event (Interrupting): " + displayName;
messages.add(message);
} else {
String message = "Boundary Message Event (Non-Interrupting): " + displayName;
messages.add(message);
}
} else if (type == EventType.INTERMEDIATE_CATCH) {
String message = "Intermediate Message Event (Catching): " + displayName;
messages.add(message);
} else if (type == EventType.INTERMEDIATE_THROW) {
String message = "Intermediate Message Event (Throwing): " + displayName;
messages.add(message);
} else {
SimulationUtils.sendElementNotSupportedTraceNote(model, processModel, displayName, nodeId);
SimulationUtils.abort(model, processInstance, nodeId, traceIsOn());
return;
}
} else if (definition == EventDefinitionType.SIGNAL) {
if (type == EventType.BOUNDARY) {
// isInterrupting?
boolean cancelActivity = processModel.getCancelActivities().get(nodeId);
if (cancelActivity) {
String message = "Boundary Signal Event (Interrupting): " + displayName;
messages.add(message);
} else {
String message = "Boundary Signal Event (Non-Interrupting): " + displayName;
messages.add(message);
}
} else if (type == EventType.INTERMEDIATE_CATCH) {
String message = "Intermediate Signal Event (Catching): " + displayName;
messages.add(message);
} else if (type == EventType.INTERMEDIATE_THROW) {
String message = "Intermediate Signal Event (Throwing): " + displayName;
messages.add(message);
} else {
SimulationUtils.sendElementNotSupportedTraceNote(model, processModel, displayName, nodeId);
SimulationUtils.abort(model, processInstance, nodeId, traceIsOn());
return;
}
} else if (definition == EventDefinitionType.TIMER) {
if (type == EventType.BOUNDARY) {
// isInterrupting?
boolean cancelActivity = processModel.getCancelActivities().get(nodeId);
if (cancelActivity) {
String message = "Boundary Timer Event (Interrupting): " + displayName;
messages.add(message);
} else {
String message = "Boundary Timer Event (Non-Interrupting): " + displayName;
messages.add(message);
}
} else if (type == EventType.INTERMEDIATE_CATCH) {
String message = "Intermediate Timer Event (Catching): " + displayName;
messages.add(message);
} else {
SimulationUtils.sendElementNotSupportedTraceNote(model, processModel, displayName, nodeId);
SimulationUtils.abort(model, processInstance, nodeId, traceIsOn());
return;
}
} else {
// None Event
if (messages.isEmpty()) {
if (type == EventType.INTERMEDIATE_THROW) {
String message = "Intermediate None Event (Throwing): " + displayName;
messages.add(message);
} else {
SimulationUtils.sendElementNotSupportedTraceNote(model, processModel, displayName, nodeId);
SimulationUtils.abort(model, processInstance, nodeId, traceIsOn());
}
}
}
}
for (String message : messages) {
sendTraceNote(message);
}
// get next node(s)
Set<Integer> idsOfNextNodes = processModel.getIdsOfNextNodes(nodeId);
// BPMN intermediate event must not have more than successor
if (idsOfNextNodes.size() != 1) {
throw new ScyllaValidationException("Event " + nodeId + " does not have 1 successor, but " + idsOfNextNodes.size() + ".");
}
Integer nextNodeId = idsOfNextNodes.iterator().next();
// schedule event for next node
List<ScyllaEvent> events = SimulationUtils.createEventsForNextNode(this, pSimComponents, processInstance, nextNodeId);
// next event occurs immediately after start event
TimeSpan timeSpan = new TimeSpan(0);
for (ScyllaEvent event : events) {
int index = getNewEventIndex();
nextEventMap.put(index, event);
timeSpanToNextEventMap.put(index, timeSpan);
}
// unless current one is BPMN timer event with timerDuration
BPMNIntermediateEventPluggable.runPlugins(this, processInstance);
scheduleNextEvents();
} catch (NodeNotFoundException | ScyllaValidationException | ScyllaRuntimeException e) {
System.err.println(e.getMessage());
e.printStackTrace();
SimulationUtils.abort(model, processInstance, nodeId, traceIsOn());
return;
}
}
use of de.hpi.bpt.scylla.exception.ScyllaValidationException in project scylla by bptlab.
the class BPMNStartEvent method eventRoutine.
@Override
public void eventRoutine(ProcessInstance processInstance) throws SuspendExecution {
super.eventRoutine(processInstance);
SimulationModel model = (SimulationModel) getModel();
ProcessModel processModel = processInstance.getProcessModel();
Map<EventDefinitionType, Map<String, String>> definitions = processModel.getEventDefinitions().get(nodeId);
Set<String> messages = new HashSet<String>();
for (EventDefinitionType definition : definitions.keySet()) {
if (definition == EventDefinitionType.MESSAGE) {
String message = "Message Start Event: " + displayName;
messages.add(message);
} else if (definition == EventDefinitionType.TIMER) {
String message = "Timer Start Event: " + displayName;
messages.add(message);
} else if (definition == EventDefinitionType.CONDITIONAL) {
String message = "Conditional Start Event: " + displayName;
messages.add(message);
} else if (definition == EventDefinitionType.SIGNAL) {
String message = "Signal Start Event: " + displayName;
messages.add(message);
}
}
if (messages.isEmpty()) {
String message = "None Start Event: " + displayName;
messages.add(message);
}
for (String message : messages) {
sendTraceNote(message);
}
try {
// get next node(s)
Set<Integer> idsOfNextNodes = processModel.getIdsOfNextNodes(nodeId);
// BPMN start event must not have more than successor
if (idsOfNextNodes.size() != 1) {
throw new ScyllaValidationException("Start event " + nodeId + " does not have 1 successor, but " + idsOfNextNodes.size() + ".");
}
Integer nextNodeId = idsOfNextNodes.iterator().next();
List<ScyllaEvent> events = SimulationUtils.createEventsForNextNode(this, pSimComponents, processInstance, nextNodeId);
// next event occurs immediately after start event
TimeSpan timeSpan = new TimeSpan(0);
for (ScyllaEvent event : events) {
int index = getNewEventIndex();
nextEventMap.put(index, event);
timeSpanToNextEventMap.put(index, timeSpan);
}
// unless current one is BPMN timer event with timerDuration
BPMNStartEventPluggable.runPlugins(this, processInstance);
scheduleNextEvents();
} catch (NodeNotFoundException | ScyllaValidationException | ScyllaRuntimeException e) {
DebugLogger.error(e.getMessage());
e.printStackTrace();
SimulationUtils.abort(model, processInstance, nodeId, traceIsOn());
return;
}
}
Aggregations