Search in sources :

Example 1 with PathContext

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

the class GatewayElementHandler method handleInclusiveGateway.

protected void handleInclusiveGateway(List<SequenceFlow> outgoing) {
    // firstly cover simple xor based - number of paths is equal to number
    // of outgoing
    handleExclusiveGateway(outgoing);
    Type currentType = manager.getContextFromStack().getType();
    manager.getContextFromStack().setType(Type.ROOT);
    // next cover all combinations of paths
    if (outgoing.size() > 2) {
        List<SequenceFlow> copy = new ArrayList<SequenceFlow>(outgoing);
        List<SequenceFlow> andCombination = null;
        for (SequenceFlow flow : outgoing) {
            // first remove one that we currently processing as that is not
            // a combination
            copy.remove(flow);
            PathContext contextAtThisNode = manager.cloneGivenWithoutPush(manager.getContextFromStack());
            for (SequenceFlow copyFlow : copy) {
                manager.cloneGiven(contextAtThisNode);
                andCombination = new ArrayList<SequenceFlow>();
                andCombination.add(flow);
                andCombination.add(copyFlow);
                handleParallelGateway(andCombination);
            }
        }
    }
    manager.getContextFromStack().setType(Type.ROOT);
    // lastly cover and based - is single path that goes through all at the
    // same time
    handleParallelGateway(outgoing);
    manager.getContextFromStack().setType(currentType);
}
Also used : Type(org.jbpm.simulation.PathContext.Type) PathContext(org.jbpm.simulation.PathContext) SequenceFlow(org.eclipse.bpmn2.SequenceFlow) ArrayList(java.util.ArrayList)

Example 2 with PathContext

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

the class GatewayElementHandler method handleParallelGateway.

protected void handleParallelGateway(List<SequenceFlow> outgoing) {
    PathContext context = manager.getContextFromStack();
    boolean canBeFinished = context.isCanBeFinished();
    context.setCanBeFinished(false);
    manager.addAllToPath(outgoing, context);
    int counter = 0;
    for (SequenceFlow seqFlow : outgoing) {
        counter++;
        FlowElement target = seqFlow.getTargetRef();
        if (counter == outgoing.size()) {
            if (manager.getPaths().size() == 1) {
                context.setCanBeFinished(canBeFinished);
            } else {
                Iterator<PathContext> it = manager.getPaths().iterator();
                while (it.hasNext()) {
                    PathContext pathContext = (PathContext) it.next();
                    if (pathContext.getType() == Type.ACTIVE) {
                        pathContext.setCanBeFinished(canBeFinished);
                    }
                }
            }
        }
        super.handle(target, manager);
    }
    // finalize paths if there are any to cover scenario when there was not converging parallel gateway
    if (canBeFinished) {
        for (SequenceFlow seqFlow : outgoing) {
            manager.addToPath(seqFlow, context);
            manager.addToPath(seqFlow.getTargetRef(), context);
        }
        manager.finalizePathOnLeave();
    }
}
Also used : PathContext(org.jbpm.simulation.PathContext) SequenceFlow(org.eclipse.bpmn2.SequenceFlow) FlowElement(org.eclipse.bpmn2.FlowElement)

Example 3 with PathContext

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

the class JSONPathFormatConverter method convert.

public JSONObject convert(List<PathContext> completePaths) {
    JSONObject parent = new JSONObject();
    JSONObject paths = new JSONObject();
    try {
        if (completePaths != null && !completePaths.isEmpty()) {
            for (PathContext pc : completePaths) {
                paths.put(pc.getPathId(), getPathFlowElementsAsString(pc.getPathElements()));
            }
        }
        parent.put("paths", paths);
    } catch (JSONException e) {
        // TODO need logging
        e.printStackTrace();
    }
    return parent;
}
Also used : PathContext(org.jbpm.simulation.PathContext) JSONObject(org.json.JSONObject) JSONException(org.json.JSONException)

Example 4 with PathContext

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

the class ActivityElementHandler method handleAllPaths.

protected void handleAllPaths(List<SequenceFlow> outgoing, PathContextManager manager) {
    PathContext context = manager.getContextFromStack();
    context.setCanBeFinished(false);
    int counter = 0;
    for (SequenceFlow seqFlow : outgoing) {
        counter++;
        FlowElement target = seqFlow.getTargetRef();
        if (counter == outgoing.size()) {
            context.setCanBeFinished(true);
        }
        manager.addToPath(seqFlow, context);
        super.handle(target, manager);
    }
}
Also used : PathContext(org.jbpm.simulation.PathContext) SequenceFlow(org.eclipse.bpmn2.SequenceFlow) FlowElement(org.eclipse.bpmn2.FlowElement)

Example 5 with PathContext

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

the class ActivityElementHandler method handleSeparatePaths.

protected void handleSeparatePaths(List<SequenceFlow> outgoing, PathContextManager manager, BoundaryEvent bEvent) {
    List<PathContext> locked = new ArrayList<PathContext>();
    PathContext context = manager.getContextFromStack();
    for (SequenceFlow seqFlow : outgoing) {
        FlowElement target = seqFlow.getTargetRef();
        PathContext separatePath = manager.cloneGiven(context);
        // replace boundary event with a wrapper if sequence flow does not go out if it
        if (!seqFlow.getSourceRef().equals(bEvent)) {
            separatePath.removePathElement(bEvent);
            separatePath.addPathElement(new WrappedBoundaryEvent(bEvent));
        }
        manager.addToPath(seqFlow, separatePath);
        super.handle(target, manager);
        separatePath.setLocked(true);
        locked.add(separatePath);
    }
    // unlock
    for (PathContext ctx : locked) {
        ctx.setLocked(false);
    }
}
Also used : PathContext(org.jbpm.simulation.PathContext) SequenceFlow(org.eclipse.bpmn2.SequenceFlow) FlowElement(org.eclipse.bpmn2.FlowElement) ArrayList(java.util.ArrayList) WrappedBoundaryEvent(org.jbpm.simulation.util.WrappedBoundaryEvent)

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