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