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);
}
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();
}
}
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;
}
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);
}
}
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);
}
}
Aggregations