Search in sources :

Example 1 with BPMNEndEvent

use of de.hpi.bpt.scylla.simulation.event.BPMNEndEvent 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;
}
Also used : ScyllaRuntimeException(de.hpi.bpt.scylla.exception.ScyllaRuntimeException) ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) Set(java.util.Set) HashSet(java.util.HashSet) TaskEnableEvent(de.hpi.bpt.scylla.simulation.event.TaskEnableEvent) EventType(de.hpi.bpt.scylla.model.process.node.EventType) ArrayList(java.util.ArrayList) GatewayType(de.hpi.bpt.scylla.model.process.node.GatewayType) BPMNIntermediateEvent(de.hpi.bpt.scylla.simulation.event.BPMNIntermediateEvent) ScyllaEvent(de.hpi.bpt.scylla.simulation.event.ScyllaEvent) GatewayEvent(de.hpi.bpt.scylla.simulation.event.GatewayEvent) BPMNEndEvent(de.hpi.bpt.scylla.simulation.event.BPMNEndEvent) Map(java.util.Map) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel) TimeInstant(desmoj.core.simulator.TimeInstant) HashSet(java.util.HashSet)

Aggregations

ScyllaRuntimeException (de.hpi.bpt.scylla.exception.ScyllaRuntimeException)1 ProcessModel (de.hpi.bpt.scylla.model.process.ProcessModel)1 EventType (de.hpi.bpt.scylla.model.process.node.EventType)1 GatewayType (de.hpi.bpt.scylla.model.process.node.GatewayType)1 SimulationModel (de.hpi.bpt.scylla.simulation.SimulationModel)1 BPMNEndEvent (de.hpi.bpt.scylla.simulation.event.BPMNEndEvent)1 BPMNIntermediateEvent (de.hpi.bpt.scylla.simulation.event.BPMNIntermediateEvent)1 GatewayEvent (de.hpi.bpt.scylla.simulation.event.GatewayEvent)1 ScyllaEvent (de.hpi.bpt.scylla.simulation.event.ScyllaEvent)1 TaskEnableEvent (de.hpi.bpt.scylla.simulation.event.TaskEnableEvent)1 TimeInstant (desmoj.core.simulator.TimeInstant)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1