public static List<String> toIds(List<? extends AbstractElement> elements) { List<String> result = new ArrayList<>(elements.size()); for (AbstractElement e : elements) { result.add(e.getId()); } return result; }
public ProcessDefinition(String id, Collection<AbstractElement> children, Map<String, String> attributes) { super(id); Map<String, AbstractElement> m = new LinkedHashMap<>(); if (children != null) { for (AbstractElement c : children) { m.put(c.getId(), c); } } this.entities = Collections.unmodifiableMap(m); this.attributes = Collections.unmodifiableMap(new HashMap<>(attributes)); }
ForkImpl(SeqImpl<?, ?> parent, AbstractElement start) { this(parent, start.getId(), start); addElement(start); }
private static List<AbstractElement> link(IdGenerator idGenerator, List<Container> containers) { if (containers.isEmpty()) { return Collections.emptyList(); } List<AbstractElement> l = new ArrayList<>(); Collection<AbstractElement> last = null; for (Container c : containers) { if (last != null) { for (AbstractElement e : last) { l.add(new SequenceFlow(idGenerator.nextId(), e.getId(), c.first.getId())); } } l.add(c.first); if (c.rest != null) { l.addAll(c.rest); } l.addAll(c.last); last = c.last; } return l; }
private static void indexOutgoingFlows0(ProcessDefinition pd, Map<String, List<SequenceFlow>> accumulator) { for (AbstractElement e : pd.getChildren()) { String id = e.getId(); List<SequenceFlow> l = findOutgoingFlows(pd, id); accumulator.put(id, ImmutableList.copyOf(l)); if (e instanceof ProcessDefinition) { indexOutgoingFlows0((ProcessDefinition) e, accumulator); } } }
private static void print(AbstractElement e, int level) { if (e instanceof SequenceFlow) { SequenceFlow f = (SequenceFlow) e; System.out.println(ident(level) + e.getClass() + ": id=" + e.getId() + " // " + f.getFrom() + " -> " + f.getTo() + " // " + f.getExpression()); } else { System.out.println(ident(level) + e.getClass() + ": id=" + e.getId()); } if (e instanceof ProcessDefinition) { ProcessDefinition pd = (ProcessDefinition) e; for (AbstractElement c : pd.getChildren()) { print(c, level + 1); } } }
private static List<AbstractElement> addEntryPoint(IdGenerator idGenerator, List<AbstractElement> elements) throws ParserException { if (elements.size() < 1) { throw new ParserException("Can't add an entry point to a empty block"); } List<AbstractElement> l = new ArrayList<>(elements); AbstractElement first = l.get(0); AbstractElement last = l.get(l.size() - 1); String startId = idGenerator.nextId(); String endId = idGenerator.nextId(); l.add(0, new StartEvent(startId)); l.add(1, new SequenceFlow(idGenerator.nextId(), startId, first.getId())); l.add(new SequenceFlow(idGenerator.nextId(), last.getId(), endId)); l.add(new EndEvent(endId)); return l; }
private static void dump(StringBuilder b, ProcessDefinition pd, Map<String, SourceMap> sourceMaps, int level) { for (AbstractElement e : pd.getChildren()) { pad(b, level).append(e.getClass().getSimpleName()).append(" [").append(e.getId()).append("]"); SourceMap sm = sourceMaps.get(e.getId()); if (sm != null) { pad(b, level + 1).append("source: ").append(sm).append("\n");
/** * Collects all (not just the first ones) downstream parallel gateways' incoming flows */ private static List<FlowSignal> findDownstreamGatewayFlows(IndexedProcessDefinition pd, String from, int count) throws ExecutionException { Set<String> memento = new HashSet<>(); Queue<FlowSignal> processingQueue = new LinkedList<>(); List<FlowSignal> results = new ArrayList<>(); AbstractElement elem = findElement(pd, from); if (elem instanceof SequenceFlow) { processingQueue.add(new FlowSignal((SequenceFlow) elem, count)); } else { fillQueue(processingQueue, pd, elem.getId(), count); } while (!processingQueue.isEmpty()) { FlowSignal fs = processingQueue.poll(); if (!memento.add(fs.flow.getId())) { continue; } AbstractElement target = findElement(pd, fs.flow.getTo()); if (target instanceof EndEvent) { continue; } if (isParallelGateway(target)) { results.add(fs); continue; } fillQueue(processingQueue, pd, target.getId(), fs.count); } return results; }
String toId = es.get(0).getId();
private void connect(Chunk c, Chunk a, Chunk b) { String dst = b.firstElement().getId(); for (String src : a.getOutputs()) { c.addElement(new SequenceFlow(nextId(), src, dst)); } } }
public List<AbstractElement> wrapAsProcess(Chunk c) { List<AbstractElement> l = new ArrayList<>(); String startId = nextId(); l.add(new StartEvent(startId)); if (c.isEmpty()) { String endId = nextId(); l.add(new SequenceFlow(nextId(), startId, endId)); l.add(new EndEvent(endId)); return l; } l.add(new SequenceFlow(nextId(), startId, c.firstElement().getId())); l.addAll(c.getElements()); if (!c.getOutputs().isEmpty()) { String endId = nextId(); for (String src : c.getOutputs()) { l.add(new SequenceFlow(nextId(), src, endId)); } l.add(new EndEvent(endId)); } return l; }
@Override public T add(AbstractElement elem) { String newId = elem.getId(); // perform joining, if needed String loopJoin = loopJoin(); if (joinPoint == null && hasJoins(loopJoin)) { joinPoint(loopJoin); } // save those for the new element since doJoinPoint() might overwrite those String flowName = null; String flowExpr = null; if(flows.primed) { flowName = flows.name; flowExpr = flows.expression; } doJoinPoint(newId); if (lastId != null) { // restore flow data if needed if(flowName != null || flowExpr != null) { flows.prime(flowName, flowExpr); } addFlow(lastId, newId); } addElement(elem); lastId = newId; lastElement = elem; return ret(); }
@SuppressWarnings("unchecked") default void applyErrorBlock(ConverterContext ctx, Chunk c, String attachedRef, Map<String, Object> opts) throws YamlConverterException { if (opts == null) { return; } Seq<YamlStep> errorSteps = (Seq<YamlStep>) opts.get("error"); if (errorSteps == null) { return; } String evId = ctx.nextId(); c.addElement(new BoundaryEvent(evId, attachedRef, null)); Chunk err = ctx.convert(errorSteps); // connect the boundary event to the error block's steps String dst = err.firstElement().getId(); c.addElement(new SequenceFlow(ctx.nextId(), evId, dst)); c.addElements(err.getElements()); c.addOutputs(err.getOutputs()); // keep the source map of the error block's steps c.addSourceMaps(err.getSourceMap()); }
result.addElement(new SequenceFlow(ctx.nextId(), nextItemTaskId, hasNextGwId)); result.addElement(new SequenceFlow(ctx.nextId(), processOutVarsTask, nextItemTaskId)); result.addElement(new SequenceFlow(ctx.nextId(), hasNextGwId, c.firstElement().getId(), "${__withItemsUtils.hasNext(execution)}")); result.addElement(new SequenceFlow(ctx.nextId(), hasNextGwId, cleanupTaskId)); c.getOutputs().forEach(o -> {
private static void applyDefaultBlock(ConverterContext ctx, Chunk c, String gwId, Seq<YamlStep> steps) throws YamlConverterException { Chunk defaultChunk = steps != null ? ctx.convert(steps) : null; if (defaultChunk == null || defaultChunk.isEmpty()) { c.addOutput(gwId); return; } String dst = defaultChunk.firstElement().getId(); c.addElement(new SequenceFlow(ctx.nextId(), gwId, dst)); c.addElements(defaultChunk.getElements()); // output of the "default" case c.addOutputs(defaultChunk.getOutputs()); c.addSourceMaps(defaultChunk.getSourceMap()); } }
private static void applyElseBlock(ConverterContext ctx, Chunk c, String gwId, Seq<YamlStep> steps) throws YamlConverterException { Chunk elseChunk = steps != null ? ctx.convert(steps) : null; if (elseChunk == null || elseChunk.isEmpty()) { c.addOutput(gwId); return; } // connect "else" steps with the gateway String elseDst = elseChunk.firstElement().getId(); c.addElement(new SequenceFlow(ctx.nextId(), gwId, elseDst)); c.addElements(elseChunk.getElements()); // output of the "else" branch c.addOutputs(elseChunk.getOutputs()); c.addSourceMaps(elseChunk.getSourceMap()); } }
.push(new PerformActionsCommand(new ActivateElementAction(a.getDefinitionId(), e.getId(), 1)));
@Override public Chunk convert(ConverterContext ctx, YamlIfExpr s) throws YamlConverterException { Chunk c = new Chunk(); String gwId = ctx.nextId(); c.addElement(new ExclusiveGateway(gwId)); c.addSourceMap(gwId, toSourceMap(s, "Check: " + s.getExpr())); // "then" branch Chunk thenChunk = ctx.convert(s.getThenSteps()); // connect "then" steps with the gateway String thenDst = thenChunk.firstElement().getId(); c.addElement(new SequenceFlow(ctx.nextId(), gwId, thenDst, s.getExpr())); c.addElements(thenChunk.getElements()); c.addOutputs(thenChunk.getOutputs()); c.addSourceMaps(thenChunk.getSourceMap()); // "else" branch applyElseBlock(ctx, c, gwId, s.getElseSteps()); return c; }