Search in sources :

Example 1 with PluginWrapper

use of de.hpi.bpt.scylla.plugin_loader.PluginLoader.PluginWrapper in project scylla by bptlab.

the class ExclusiveGatewayEventPlugin 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);
    ProcessSimulationComponents desmojObjects = desmojEvent.getDesmojObjects();
    try {
        Set<Integer> idsOfNextNodes = processModel.getIdsOfNextNodes(nodeId);
        if (idsOfNextNodes.size() > 1) {
            // split
            if (type == GatewayType.DEFAULT || type == GatewayType.EXCLUSIVE) {
                Map<Integer, Object> branchingDistributions = desmojObjects.getExtensionDistributions().get(getName());
                DiscreteDistEmpirical<Integer> distribution = (DiscreteDistEmpirical<Integer>) branchingDistributions.get(nodeId);
                // decide on next node
                if (distribution != null) {
                    // if a distribution is given take this
                    Integer nextFlowId = distribution.sample().intValue();
                    if (!processModel.getIdentifiers().keySet().contains(nextFlowId)) {
                        throw new ScyllaValidationException("Flow with id " + nextFlowId + " does not exist.");
                    }
                    scheduleNextEvent(desmojEvent, processInstance, processModel, nextFlowId);
                } else {
                    // otherwise try to get information out of the describing branches and branch on the basis of this
                    Map<Class<?>, ArrayList<PluginWrapper>> a = PluginLoader.getDefaultPluginLoader().getExtensions();
                    Collection<ArrayList<PluginWrapper>> plugins = a.values();
                    Boolean dataObjectPluginOn = false;
                    for (ArrayList<PluginWrapper> plugin : plugins) {
                        for (PluginWrapper p : plugin) {
                            if (p.toString().equals("DataObjectSCParserPlugin")) {
                                dataObjectPluginOn = true;
                            }
                        }
                    }
                    if (dataObjectPluginOn) {
                        Object[] outgoingRefs = processModel.getGraph().getTargetObjects(nodeId).toArray();
                        Integer DefaultPath = null;
                        Boolean foundAWay = false;
                        for (Object or : outgoingRefs) {
                            // go through all outgoing references
                            if (or.equals(getKeyByValue(processModel.getIdentifiers(), processModel.getNodeAttributes().get(desmojEvent.getNodeId()).get("default")))) {
                                // if it's the default path jump it
                                DefaultPath = (Integer) or;
                                continue;
                            }
                            String[] conditions = processModel.getDisplayNames().get(or).split("&&");
                            Integer nextFlowId = (Integer) or;
                            List<Boolean> test = new ArrayList<>();
                            for (String condition : conditions) {
                                condition = condition.trim();
                                String field = null;
                                String value = null;
                                String comparison = null;
                                if (condition.contains("==")) {
                                    field = condition.split("==")[0];
                                    value = condition.split("==")[1];
                                    // value = processModel.getDisplayNames().get(or).substring(2, processModel.getDisplayNames().get(or).length());
                                    comparison = "equal";
                                } else if (condition.contains(">=")) {
                                    field = condition.split(">=")[0];
                                    value = condition.split(">=")[1];
                                    comparison = "greaterOrEqual";
                                } else if (condition.contains("<=")) {
                                    field = condition.split("<=")[0];
                                    value = condition.split("<=")[1];
                                    comparison = "lessOrEqual";
                                } else if (condition.contains("!=")) {
                                    field = condition.split("!=")[0];
                                    value = condition.split("!=")[1];
                                    comparison = "notEqual";
                                } else if (condition.contains("=")) {
                                    field = condition.split("=")[0];
                                    value = condition.split("=")[1];
                                    comparison = "equal";
                                } else if (condition.contains("<")) {
                                    field = condition.split("<")[0];
                                    value = condition.split("<")[1];
                                    comparison = "less";
                                } else if (condition.contains(">")) {
                                    field = condition.split(">")[0];
                                    value = condition.split(">")[1];
                                    comparison = "greater";
                                } else {
                                    throw new ScyllaValidationException("Condition " + condition + " does not have a comparison-operator");
                                }
                                value = value.trim();
                                field = field.trim();
                                Object fieldValue = DataObjectField.getDataObjectValue(processInstance.getId(), field);
                                if (!isParsableAsLong(value) || !isParsableAsLong((String.valueOf(fieldValue)))) {
                                    // try a long comparison
                                    Integer comparisonResult = (String.valueOf(fieldValue)).trim().compareTo(String.valueOf(value));
                                    if (comparison.equals("equal") && comparisonResult == 0) {
                                        break;
                                    } else if (comparison.equals("notEqual") && comparisonResult != 0) {
                                        break;
                                    } else {
                                        test.add(false);
                                    }
                                } else {
                                    // otherwise do a string compare
                                    Long LongValue = Long.valueOf(value);
                                    Long dOValue = Long.valueOf((String.valueOf(fieldValue)));
                                    Integer comparisonResult = (dOValue.compareTo(LongValue));
                                    if (comparison.equals("equal") && comparisonResult == 0) {
                                    } else if (comparison.equals("less") && comparisonResult < 0) {
                                    } else if (comparison.equals("greater") && comparisonResult > 0) {
                                    } else if (comparison.equals("greaterOrEqual") && comparisonResult >= 0) {
                                    } else if (comparison.equals("lessOrEqual") && comparisonResult <= 0) {
                                    } else {
                                        test.add(false);
                                    }
                                }
                            }
                            if (test.size() == 0) {
                                scheduleNextEvent(desmojEvent, processInstance, processModel, nextFlowId);
                                foundAWay = true;
                            }
                        }
                        if (!foundAWay && DefaultPath != null) {
                            scheduleNextEvent(desmojEvent, processInstance, processModel, DefaultPath);
                        } else if (!foundAWay && DefaultPath == null) {
                            // everything will be killed, logical error
                            throw new ScyllaValidationException("No Default Path for " + desmojEvent.getDisplayName() + " given and outgoing branches not complete. No branch matches, abort.");
                        }
                    } else {
                        Object[] outgoingRefs = processModel.getGraph().getTargetObjects(nodeId).toArray();
                        Integer DefaultPath = null;
                        for (Object or : outgoingRefs) {
                            // try to find default path
                            if (or.equals(getKeyByValue(processModel.getIdentifiers(), processModel.getNodeAttributes().get(desmojEvent.getNodeId()).get("default")))) {
                                DefaultPath = (Integer) or;
                                break;
                            }
                        }
                        if (DefaultPath != null) {
                            scheduleNextEvent(desmojEvent, processInstance, processModel, DefaultPath);
                        } else {
                            throw new ScyllaValidationException("No Distribution for " + desmojEvent.getDisplayName() + " given, no DefaultPath given and DataObject PlugIn not activated.");
                        }
                    }
                }
            }
        }
    } 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) ArrayList(java.util.ArrayList) GatewayType(de.hpi.bpt.scylla.model.process.node.GatewayType) ScyllaValidationException(de.hpi.bpt.scylla.exception.ScyllaValidationException) ProcessSimulationComponents(de.hpi.bpt.scylla.simulation.ProcessSimulationComponents) PluginWrapper(de.hpi.bpt.scylla.plugin_loader.PluginLoader.PluginWrapper) DiscreteDistEmpirical(desmoj.core.dist.DiscreteDistEmpirical) NodeNotFoundException(de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel)

Aggregations

ScyllaValidationException (de.hpi.bpt.scylla.exception.ScyllaValidationException)1 ProcessModel (de.hpi.bpt.scylla.model.process.ProcessModel)1 NodeNotFoundException (de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException)1 GatewayType (de.hpi.bpt.scylla.model.process.node.GatewayType)1 PluginWrapper (de.hpi.bpt.scylla.plugin_loader.PluginLoader.PluginWrapper)1 ProcessSimulationComponents (de.hpi.bpt.scylla.simulation.ProcessSimulationComponents)1 SimulationModel (de.hpi.bpt.scylla.simulation.SimulationModel)1 DiscreteDistEmpirical (desmoj.core.dist.DiscreteDistEmpirical)1 ArrayList (java.util.ArrayList)1