use of de.hpi.bpt.scylla.simulation.event.TaskEnableEvent in project scylla by bptlab.
the class SimulationUtils method createEventsForNextNode.
/**
* Gets type of next node and prepare respective event.
*
* @param model
* the simulation model
* @param processModel
* the process model
* @param processInstanceId
* the identifier of the process instance
* @param nextNodeId
* the identifier of the next node
* @return the DesmoJ representing the next node plus DesmoJ events from plug-ins
* @throws ScyllaRuntimeException
* @throws NodeNotFoundException
* @throws ScyllaValidationException
*/
public static List<ScyllaEvent> createEventsForNextNode(ScyllaEvent currentEvent, ProcessSimulationComponents desmojObjects, ProcessInstance processInstance, int nextNodeId) throws ScyllaRuntimeException, NodeNotFoundException, ScyllaValidationException {
SimulationModel model = (SimulationModel) processInstance.getModel();
TimeInstant currentSimulationTime = model.presentTime();
ProcessModel processModel = processInstance.getProcessModel();
String source = currentEvent.getSource();
List<ScyllaEvent> events = new ArrayList<ScyllaEvent>();
if (processModel.getTasks().containsKey(nextNodeId) || processModel.getSubProcesses().containsKey(nextNodeId)) {
// TaskType tType = processModel.getTasks().get(nextNodeId);
ScyllaEvent event = new TaskEnableEvent(model, source, currentSimulationTime, desmojObjects, processInstance, nextNodeId);
events.add(event);
} else if (processModel.getGateways().containsKey(nextNodeId)) {
GatewayType gType = processModel.getGateways().get(nextNodeId);
Set<Integer> idsOfNodesBeforeGateway = processModel.getIdsOfPreviousNodes(nextNodeId);
if (gType == GatewayType.PARALLEL && idsOfNodesBeforeGateway.size() > 1) {
Map<Integer, Set<Integer>> referenceToEventsOnHold = processInstance.getNodesAndTriggers();
if (!referenceToEventsOnHold.containsKey(nextNodeId)) {
referenceToEventsOnHold.put(nextNodeId, new HashSet<Integer>());
}
Set<Integer> nodesTriggeredFrom = referenceToEventsOnHold.get(nextNodeId);
int currentNodeId = currentEvent.getNodeId();
nodesTriggeredFrom.add(currentNodeId);
if (idsOfNodesBeforeGateway.equals(nodesTriggeredFrom)) {
ScyllaEvent event = new GatewayEvent(model, source, currentSimulationTime, desmojObjects, processInstance, nextNodeId);
events.add(event);
// clear list of fired incoming flows
referenceToEventsOnHold.remove(nextNodeId);
}
} else {
ScyllaEvent event = new GatewayEvent(model, source, currentSimulationTime, desmojObjects, processInstance, nextNodeId);
events.add(event);
}
} else if (processModel.getEventTypes().containsKey(nextNodeId)) {
EventType eType = processModel.getEventTypes().get(nextNodeId);
if (eType == EventType.START) {
throw new ScyllaRuntimeException("Start event " + nextNodeId + " must be at the beginning of the process.");
} else if (eType == EventType.END) {
ScyllaEvent event = new BPMNEndEvent(model, source, currentSimulationTime, desmojObjects, processInstance, nextNodeId);
events.add(event);
} else {
ScyllaEvent event = new BPMNIntermediateEvent(model, source, currentSimulationTime, desmojObjects, processInstance, nextNodeId);
events.add(event);
}
} else {
throw new ScyllaRuntimeException("Next node " + nextNodeId + " not found or not supported.");
}
List<ScyllaEvent> eventsFromPlugins = EventCreationPluggable.runPlugins(currentEvent, desmojObjects, processInstance, nextNodeId);
events.addAll(eventsFromPlugins);
return events;
}
Aggregations