Search in sources :

Example 11 with NodeNotFoundException

use of de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException in project scylla by bptlab.

the class DataObjectBPMNStartEvent method eventRoutine.

@Override
public void eventRoutine(BPMNStartEvent desmojEvent, ProcessInstance processInstance) throws ScyllaRuntimeException {
    ProcessModel processModel = processInstance.getProcessModel();
    // int processInstanceId = processInstance.getId();
    try {
        if (processModel.getDataObjectsGraph().getNodes().containsKey(desmojEvent.getNodeId())) {
            Set<Integer> refferingObjects = processModel.getDataObjectsGraph().getTargetObjects(desmojEvent.getNodeId());
            Collection<Object> allFields = desmojEvent.getDesmojObjects().getExtensionDistributions().get("dataobject").values();
            for (Object fields : allFields) {
                Integer i = 0;
                while (((Map<String, Map<Integer, DataObjectField>>) fields).values().toArray().length - i != 0) {
                    DataObjectField field = (DataObjectField) ((Map<String, Map<Integer, DataObjectField>>) fields).values().toArray()[i];
                    if (refferingObjects.contains(field.getNodeId())) {
                        // System.out.println(processInstance.getId() + " " + desmojEvent.getDisplayName() + " " + processModel.getDisplayNames().get(field.getNodeId()) + " " + field.getDataDistributionWrapper().getSample());
                        SimulationModel model = (SimulationModel) desmojEvent.getModel();
                        Collection<Map<Integer, java.util.List<ProcessNodeInfo>>> allProcesses = model.getProcessNodeInfos().values();
                        for (Map<Integer, java.util.List<ProcessNodeInfo>> process : allProcesses) {
                            List<ProcessNodeInfo> currentProcess = process.get(processInstance.getId());
                            for (ProcessNodeInfo task : currentProcess) {
                                // System.out.println(processModel.getDisplayNames().get(processModel.getDataObjectsGraph().getSourceObjects(field.getNodeId()).toArray()[0]) + " " + task.getTaskName());
                                for (Integer j = 0; j < processModel.getDataObjectsGraph().getSourceObjects(field.getNodeId()).toArray().length; j++) {
                                    if (task.getId().equals(processModel.getDataObjectsGraph().getSourceObjects(field.getNodeId()).toArray()[j]) && task.getTransition() == ProcessNodeTransitionType.EVENT_TERMINATE) {
                                        // check all tasks and find the ones that may be looged; already logged ones will get ignored next line
                                        if (!task.getDataObjectField().containsKey(processModel.getDisplayNames().get(field.getNodeId()) + "." + field.getFieldName())) {
                                            // don't log if task already has this field logged
                                            Map<String, Object> fieldSample = new HashMap<String, Object>();
                                            Object currentSample = field.getDataDistributionWrapper().getSample();
                                            // log Value at TaskTerminate
                                            fieldSample.put(processModel.getDisplayNames().get(field.getNodeId()) + "." + field.getFieldName(), currentSample);
                                            task.SetDataObjectField(fieldSample);
                                            // set current DataObjectFieldValue
                                            DataObjectField.addDataObjectValue(processInstance.getId(), fieldSample.keySet().toArray()[0].toString(), currentSample);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    i++;
                }
            }
        } else {
        // do nothing and continue with the next task because Node has no dataobejcts
        }
    } catch (ScyllaRuntimeException | ScyllaValidationException | NodeNotFoundException e) {
        e.printStackTrace();
    }
}
Also used : ScyllaRuntimeException(de.hpi.bpt.scylla.exception.ScyllaRuntimeException) ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) ProcessNodeInfo(de.hpi.bpt.scylla.logger.ProcessNodeInfo) ScyllaValidationException(de.hpi.bpt.scylla.exception.ScyllaValidationException) NodeNotFoundException(de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException) java.util(java.util) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel)

Example 12 with NodeNotFoundException

use of de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException in project scylla by bptlab.

the class EventbasedGatewayEventPlugin method eventRoutine.

/**
 * Handles a gateway event, if it is an event based gateway
 * Changes scheduling behavior by already scheduling the next events of the given gateway event (if event based)
 */
@Override
public void eventRoutine(GatewayEvent desmojEvent, ProcessInstance processInstance) throws ScyllaRuntimeException {
    SimulationModel model = (SimulationModel) desmojEvent.getModel();
    ProcessModel processModel = processInstance.getProcessModel();
    int nodeId = desmojEvent.getNodeId();
    GatewayType type = processModel.getGateways().get(nodeId);
    try {
        Set<Integer> idsOfNextNodes = processModel.getIdsOfNextNodes(nodeId);
        if (type == GatewayType.EVENT_BASED && idsOfNextNodes.size() > 1) {
            // Schedule all following events
            List<ScyllaEvent> nextEvents = new ArrayList<ScyllaEvent>(desmojEvent.getNextEventMap().values());
            desmojEvent.scheduleNextEvents();
            // and look which is scheduled first.
            ScyllaEvent first = nextEvents.get(0);
            for (ScyllaEvent e : nextEvents) {
                if (TimeInstant.isBefore(e.scheduledNext(), first.scheduledNext())) {
                    first = e;
                }
            }
            // Cancel all other events except the one that is scheduled first.
            nextEvents.remove(first);
            for (ScyllaEvent e : nextEvents) {
                e.cancel();
            }
        }
    } catch (NodeNotFoundException | ScyllaValidationException | SuspendExecution e) {
        e.printStackTrace();
        // Critical error (following nodes not found or validation error), abort the instance.
        SimulationUtils.abort(model, processInstance, nodeId, desmojEvent.traceIsOn());
    }
}
Also used : ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) SuspendExecution(co.paralleluniverse.fibers.SuspendExecution) ArrayList(java.util.ArrayList) GatewayType(de.hpi.bpt.scylla.model.process.node.GatewayType) ScyllaEvent(de.hpi.bpt.scylla.simulation.event.ScyllaEvent) ScyllaValidationException(de.hpi.bpt.scylla.exception.ScyllaValidationException) NodeNotFoundException(de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel)

Example 13 with NodeNotFoundException

use of de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException in project scylla by bptlab.

the class ExclusiveGatewaySCParserPlugin 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("exclusiveGateway")) {
            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>();
                Double probabilitySum = 0d;
                for (Element elem : outgoingSequenceFlows) {
                    Integer nodeIdOfSequenceFlow = processModel.getIdentifiersToNodeIds().get(elem.getAttributeValue("id"));
                    if (nodeIdOfSequenceFlow != null) {
                        Double branchingProbability = Double.parseDouble(elem.getChildText("branchingProbability", simNamespace));
                        if (branchingProbability < 0 || branchingProbability > 1) {
                            throw new ScyllaValidationException("Exclusive gateway branching probability for " + identifier + " is out of bounds [0,1].");
                        }
                        probabilitySum += branchingProbability;
                        branchingProbabilities.put(nodeIdOfSequenceFlow, branchingProbability);
                    }
                }
                if (probabilitySum <= 0) {
                    throw new ScyllaValidationException("Simulation configuration defines branching probabilities for exclusive gateway " + identifier + ", where the sum of probabilities is negative or zero.");
                }
                if (probabilitySum > 1) {
                    // XXX imprecision by IEEE 754 floating point representation
                    throw new ScyllaValidationException("Simulation configuration defines branching probabilities for exclusive gateway " + identifier + ", exceeding 1 in total.");
                }
                // complete probabilities with the default flow probability
                if (probabilitySum > 0 && probabilitySum <= 1) {
                    Map<String, String> gatewayAttributes = processModel.getNodeAttributes().get(nodeId);
                    String defaultFlowIdentifier = gatewayAttributes.get("default");
                    if (defaultFlowIdentifier != null) {
                        double probabilityOfDefaultFlow = 1 - probabilitySum;
                        int defaultFlowNodeId = processModel.getIdentifiersToNodeIds().get(defaultFlowIdentifier);
                        if (!branchingProbabilities.containsKey(defaultFlowNodeId)) {
                            branchingProbabilities.put(defaultFlowNodeId, probabilityOfDefaultFlow);
                        } else {
                            branchingProbabilities.put(defaultFlowNodeId, branchingProbabilities.get(defaultFlowNodeId) + probabilityOfDefaultFlow);
                        }
                        ;
                    }
                }
                try {
                    if (branchingProbabilities.keySet().size() != processModel.getIdsOfNextNodes(nodeId).size()) {
                        throw new ScyllaValidationException("Number of branching probabilities defined in simulation configuration " + "does not match to number of outgoing flows of exclusive gateway " + identifier + ".");
                    }
                } catch (NodeNotFoundException e) {
                    throw new ScyllaValidationException("Node not found: " + e.getMessage());
                }
                BranchingBehavior branchingBehavior = new BranchingBehavior(branchingProbabilities);
                branchingBehaviors.put(nodeId, branchingBehavior);
            }
        }
    }
    HashMap<String, Object> extensionAttributes = new HashMap<String, Object>();
    extensionAttributes.put("branchingBehaviors", branchingBehaviors);
    return extensionAttributes;
}
Also used : ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) HashMap(java.util.HashMap) BranchingBehavior(de.hpi.bpt.scylla.model.configuration.BranchingBehavior) Element(org.jdom2.Element) Namespace(org.jdom2.Namespace) ScyllaValidationException(de.hpi.bpt.scylla.exception.ScyllaValidationException) NodeNotFoundException(de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException)

Example 14 with NodeNotFoundException

use of de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException 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;
    }
}
Also used : ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) ScyllaValidationException(de.hpi.bpt.scylla.exception.ScyllaValidationException) NodeNotFoundException(de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException) GatewayType(de.hpi.bpt.scylla.model.process.node.GatewayType) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel)

Example 15 with NodeNotFoundException

use of de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException 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);
        }
    }
}
Also used : ScyllaRuntimeException(de.hpi.bpt.scylla.exception.ScyllaRuntimeException) ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) ScyllaEvent(de.hpi.bpt.scylla.simulation.event.ScyllaEvent) TaskTerminateEvent(de.hpi.bpt.scylla.simulation.event.TaskTerminateEvent) TimeSpan(desmoj.core.simulator.TimeSpan) ScyllaValidationException(de.hpi.bpt.scylla.exception.ScyllaValidationException) NodeNotFoundException(de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException) ProcessSimulationComponents(de.hpi.bpt.scylla.simulation.ProcessSimulationComponents) ProcessInstance(de.hpi.bpt.scylla.simulation.ProcessInstance) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel)

Aggregations

NodeNotFoundException (de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException)20 ProcessModel (de.hpi.bpt.scylla.model.process.ProcessModel)19 SimulationModel (de.hpi.bpt.scylla.simulation.SimulationModel)17 ScyllaValidationException (de.hpi.bpt.scylla.exception.ScyllaValidationException)16 TimeSpan (desmoj.core.simulator.TimeSpan)11 ScyllaRuntimeException (de.hpi.bpt.scylla.exception.ScyllaRuntimeException)10 ProcessSimulationComponents (de.hpi.bpt.scylla.simulation.ProcessSimulationComponents)8 ScyllaEvent (de.hpi.bpt.scylla.simulation.event.ScyllaEvent)7 ProcessInstance (de.hpi.bpt.scylla.simulation.ProcessInstance)6 Map (java.util.Map)6 MultipleStartNodesException (de.hpi.bpt.scylla.model.process.graph.exception.MultipleStartNodesException)5 NoStartNodeException (de.hpi.bpt.scylla.model.process.graph.exception.NoStartNodeException)5 EventDefinitionType (de.hpi.bpt.scylla.model.process.node.EventDefinitionType)5 GatewayType (de.hpi.bpt.scylla.model.process.node.GatewayType)4 ProcessNodeInfo (de.hpi.bpt.scylla.logger.ProcessNodeInfo)3 TimeInstant (desmoj.core.simulator.TimeInstant)3 ArrayList (java.util.ArrayList)3 BPMNStartEvent (de.hpi.bpt.scylla.simulation.event.BPMNStartEvent)2 TaskTerminateEvent (de.hpi.bpt.scylla.simulation.event.TaskTerminateEvent)2 java.util (java.util)2