Search in sources :

Example 11 with PathContext

use of org.jbpm.simulation.PathContext in project droolsjbpm-integration by kiegroup.

the class ThrowEventElementHandler method handle.

@Override
public boolean handle(FlowElement element, PathContextManager manager) {
    List<EventDefinition> throwDefinitions = getEventDefinitions(element);
    if (throwDefinitions != null && !throwDefinitions.isEmpty()) {
        for (EventDefinition def : throwDefinitions) {
            String key = "";
            if (def instanceof SignalEventDefinition) {
                key = ((SignalEventDefinition) def).getSignalRef();
            } else if (def instanceof MessageEventDefinition) {
                key = ((MessageEventDefinition) def).getMessageRef().getId();
            } else if (def instanceof LinkEventDefinition) {
                key = ((LinkEventDefinition) def).getName();
            } else if (def instanceof CompensateEventDefinition) {
                key = ((CompensateEventDefinition) def).getActivityRef().getId();
            } else if (def instanceof ErrorEventDefinition) {
                key = ((ErrorEventDefinition) def).getErrorRef().getId();
            }
            FlowElement catchEvent = manager.getCatchingEvents().get(key);
            if (catchEvent != null && hasPathToCatchEvent(catchEvent)) {
                PathContext context = manager.getContextFromStack();
                boolean canBeFinished = context.isCanBeFinished();
                context.setCanBeFinishedNoIncrement(false);
                super.handle(catchEvent, manager);
                context.setCanBeFinishedNoIncrement(canBeFinished);
            }
        }
    }
    return super.handle(element, manager);
}
Also used : LinkEventDefinition(org.eclipse.bpmn2.LinkEventDefinition) PathContext(org.jbpm.simulation.PathContext) FlowElement(org.eclipse.bpmn2.FlowElement) ErrorEventDefinition(org.eclipse.bpmn2.ErrorEventDefinition) SignalEventDefinition(org.eclipse.bpmn2.SignalEventDefinition) MessageEventDefinition(org.eclipse.bpmn2.MessageEventDefinition) EventDefinition(org.eclipse.bpmn2.EventDefinition) CompensateEventDefinition(org.eclipse.bpmn2.CompensateEventDefinition) ErrorEventDefinition(org.eclipse.bpmn2.ErrorEventDefinition) LinkEventDefinition(org.eclipse.bpmn2.LinkEventDefinition) SignalEventDefinition(org.eclipse.bpmn2.SignalEventDefinition) MessageEventDefinition(org.eclipse.bpmn2.MessageEventDefinition) CompensateEventDefinition(org.eclipse.bpmn2.CompensateEventDefinition)

Example 12 with PathContext

use of org.jbpm.simulation.PathContext in project droolsjbpm-integration by kiegroup.

the class SimulationFilterPathFormatConverter method convert.

public List<SimulationPath> convert(List<PathContext> paths) {
    List<SimulationPath> allPaths = new ArrayList<SimulationPath>();
    for (PathContext context : paths) {
        SimulationPath simPath = new SimulationPath();
        simPath.setPathId(context.getPathId());
        for (FlowElement fe : context.getPathElements()) {
            if (fe instanceof SequenceFlow) {
                simPath.addSequenceFlow(fe.getId());
                simPath.addSequenceFlowSource(fe.getId(), ((SequenceFlow) fe).getSourceRef().getId());
            } else if (isGatewaySplit(fe)) {
                if (provider != null) {
                    double probability = 0;
                    for (SequenceFlow sq : ((Gateway) fe).getOutgoing()) {
                        if (provider instanceof BPMN2SimulationDataProvider) {
                            probability += (Double) ((BPMN2SimulationDataProvider) provider).getSimulationDataForNode(sq.getId()).get(SimulationConstants.PROBABILITY);
                        }
                    }
                    BigDecimal bd = new BigDecimal(probability);
                    bd = bd.setScale(5, RoundingMode.HALF_UP);
                    probability = bd.doubleValue();
                    if (probability != 100) {
                        throw new IllegalArgumentException("Process is not valid for simulation - use validation to find errors");
                    }
                }
            } else if (fe instanceof BoundaryEvent) {
                simPath.addBoundaryEventId(fe.getId());
            } else if (fe instanceof CatchEvent) {
                CatchEvent act = (CatchEvent) fe;
                if (act.getIncoming() == null || act.getIncoming().isEmpty() && !isParentEventSubprocess(fe)) {
                    String ref = processEventDefinitions(((CatchEvent) fe).getEventDefinitions());
                    simPath.setSignalName(ref);
                }
            } else {
                simPath.addActivity(fe.getId());
                if (fe instanceof ThrowEvent) {
                    String ref = processEventDefinitions(((ThrowEvent) fe).getEventDefinitions());
                    if (ref != null) {
                        simPath.addThrowEvent(fe.getId(), ref);
                    }
                }
            }
            // ensure that only processes that have start nodes will be considered
            if (fe instanceof StartEvent && !isParentEventSubprocess(fe)) {
                simPath.setStartable(true);
            }
        }
        allPaths.add(simPath);
        // calcluate path probability if required
        if (provider != null) {
            provider.calculatePathProbability(simPath);
        }
    }
    Collections.sort(allPaths, new Comparator<SimulationPath>() {

        public int compare(SimulationPath o1, SimulationPath o2) {
            double difference = o1.getProbability() - o2.getProbability();
            if (difference > 0) {
                return -1;
            } else if (difference < 0) {
                return 1;
            }
            return 0;
        }
    });
    return allPaths;
}
Also used : ThrowEvent(org.eclipse.bpmn2.ThrowEvent) SimulationPath(org.jbpm.simulation.impl.SimulationPath) BoundaryEvent(org.eclipse.bpmn2.BoundaryEvent) SequenceFlow(org.eclipse.bpmn2.SequenceFlow) BPMN2SimulationDataProvider(org.jbpm.simulation.impl.BPMN2SimulationDataProvider) ArrayList(java.util.ArrayList) CatchEvent(org.eclipse.bpmn2.CatchEvent) BigDecimal(java.math.BigDecimal) PathContext(org.jbpm.simulation.PathContext) FlowElement(org.eclipse.bpmn2.FlowElement) StartEvent(org.eclipse.bpmn2.StartEvent)

Example 13 with PathContext

use of org.jbpm.simulation.PathContext in project droolsjbpm-integration by kiegroup.

the class ActivityElementHandler method handle.

public boolean handle(FlowElement element, PathContextManager manager) {
    List<SequenceFlow> outgoing = new ArrayList<SequenceFlow>(getOutgoing(element));
    if (outgoing.isEmpty()) {
        return false;
    }
    PathContext context = manager.getContextFromStack();
    List<BoundaryEvent> bEvents = ((Activity) element).getBoundaryEventRefs();
    if (bEvents != null && !bEvents.isEmpty()) {
        boolean cancelActivity = false;
        for (BoundaryEvent bEvent : bEvents) {
            if (!context.getPathElements().contains(bEvent)) {
                manager.addToPath(bEvent, context);
                List<SequenceFlow> bOut = bEvent.getOutgoing();
                outgoing.addAll(bOut);
                cancelActivity = bEvent.isCancelActivity();
                handleSeparatePaths(outgoing, manager, bEvent);
                handleCombinedPaths(outgoing, manager);
                if (!cancelActivity) {
                    handleAllPaths(outgoing, manager);
                }
            } else {
                HandlerRegistry.getHandler().handle(element, manager);
            }
        }
        return true;
    } else {
        HandlerRegistry.getHandler().handle(element, manager);
        return false;
    }
}
Also used : PathContext(org.jbpm.simulation.PathContext) BoundaryEvent(org.eclipse.bpmn2.BoundaryEvent) WrappedBoundaryEvent(org.jbpm.simulation.util.WrappedBoundaryEvent) SequenceFlow(org.eclipse.bpmn2.SequenceFlow) ArrayList(java.util.ArrayList) Activity(org.eclipse.bpmn2.Activity)

Example 14 with PathContext

use of org.jbpm.simulation.PathContext in project droolsjbpm-integration by kiegroup.

the class ConvergingGatewayElementHandler method handleParallelGateway.

protected void handleParallelGateway(FlowElement element, List<SequenceFlow> outgoing) {
    PathContext context = manager.getContextFromStack();
    boolean canBeFinished = context.isCanBeFinished();
    if (canBeFinished && context.getType() != Type.ROOT) {
        for (SequenceFlow seqFlow : outgoing) {
            manager.addToPath(seqFlow, context);
            manager.addToPath(seqFlow.getTargetRef(), context);
        }
        Iterator<PathContext> it = manager.getPaths().iterator();
        while (it.hasNext()) {
            PathContext pathContext = (PathContext) it.next();
            if (pathContext.getType() == Type.ACTIVE) {
                pathContext.setCanBeFinishedNoIncrement(canBeFinished);
                manager.finalizePath(pathContext);
                it.remove();
            }
        }
    } else {
        super.handle(element, manager);
    }
}
Also used : PathContext(org.jbpm.simulation.PathContext) SequenceFlow(org.eclipse.bpmn2.SequenceFlow)

Example 15 with PathContext

use of org.jbpm.simulation.PathContext in project droolsjbpm-integration by kiegroup.

the class EmbeddedSubprocessHandler method handle.

public boolean handle(FlowElement element, PathContextManager manager) {
    SubProcess subProcess = ((SubProcess) element);
    // process internal nodes of the sub process
    List<FlowElement> sbElements = subProcess.getFlowElements();
    StartEvent start = null;
    for (FlowElement sbElement : sbElements) {
        if (sbElement instanceof StartEvent) {
            start = (StartEvent) sbElement;
            break;
        }
    }
    boolean canBeFinsihed = manager.getContextFromStack().isCanBeFinished();
    manager.getContextFromStack().setCanBeFinishedNoIncrement(false);
    super.handle(start, manager);
    manager.getContextFromStack().setCanBeFinishedNoIncrement(canBeFinsihed);
    List<SequenceFlow> out = getOutgoing(element);
    for (SequenceFlow flow : out) {
        manager.addToPath(flow, manager.getContextFromStack());
        super.handle(flow.getTargetRef(), manager);
    }
    if (canBeFinsihed) {
        boolean goOn = true;
        while (goOn) {
            PathContext context = manager.getContextFromStack();
            if (context.getType() == Type.ACTIVE) {
                context.setCanBeFinishedNoIncrement(canBeFinsihed);
                manager.finalizePath();
            } else {
                break;
            }
        }
    }
    return true;
}
Also used : SubProcess(org.eclipse.bpmn2.SubProcess) PathContext(org.jbpm.simulation.PathContext) FlowElement(org.eclipse.bpmn2.FlowElement) SequenceFlow(org.eclipse.bpmn2.SequenceFlow) StartEvent(org.eclipse.bpmn2.StartEvent)

Aggregations

PathContext (org.jbpm.simulation.PathContext)15 FlowElement (org.eclipse.bpmn2.FlowElement)10 SequenceFlow (org.eclipse.bpmn2.SequenceFlow)10 ArrayList (java.util.ArrayList)5 Activity (org.eclipse.bpmn2.Activity)2 BoundaryEvent (org.eclipse.bpmn2.BoundaryEvent)2 StartEvent (org.eclipse.bpmn2.StartEvent)2 SubProcess (org.eclipse.bpmn2.SubProcess)2 WrappedBoundaryEvent (org.jbpm.simulation.util.WrappedBoundaryEvent)2 BigDecimal (java.math.BigDecimal)1 CatchEvent (org.eclipse.bpmn2.CatchEvent)1 CompensateEventDefinition (org.eclipse.bpmn2.CompensateEventDefinition)1 ErrorEventDefinition (org.eclipse.bpmn2.ErrorEventDefinition)1 EventDefinition (org.eclipse.bpmn2.EventDefinition)1 Gateway (org.eclipse.bpmn2.Gateway)1 IntermediateThrowEvent (org.eclipse.bpmn2.IntermediateThrowEvent)1 LinkEventDefinition (org.eclipse.bpmn2.LinkEventDefinition)1 MessageEventDefinition (org.eclipse.bpmn2.MessageEventDefinition)1 ParallelGateway (org.eclipse.bpmn2.ParallelGateway)1 SignalEventDefinition (org.eclipse.bpmn2.SignalEventDefinition)1