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, BigDecimal.ROUND_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().size() == 0) {
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) {
simPath.setStartable(true);
}
}
allPaths.add(simPath);
// calcluate path probability if required