public IndexedProcessDefinition(ProcessDefinition pd) { super(pd.getId(), pd.getChildren(), pd.getAttributes() != null ? pd.getAttributes() : Collections.emptyMap()); setName(pd.getName()); this.outgoingFlows = indexOutgoingFlows(); this.boundaryEvents = indexBoundaryEvents(); }
private static ProcessDefinition mergeAttrs(ProcessDefinition source, Map<String, String> attrs) { Map<String, String> m = new HashMap<>(source.getAttributes()); m.putAll(attrs); return new ProcessDefinition(source, m); } }
/** * Finds an element of (sub)process by its ID; * * @param pd * @param id * @throws ExecutionException if the element is not found. */ public static AbstractElement findElement(ProcessDefinition pd, String id) throws ExecutionException { ProcessDefinition sub = findElementProcess(pd, id); return sub.getChild(id); }
public ProcessDefinition(ProcessDefinition source, Map<String, String> attributes) { this(source.getId(), source.getChildren(), attributes); }
private static ProcessDefinition findElementProcess0(ProcessDefinition pd, String id) { if (pd.hasChild(id)) { return pd; } for (AbstractElement e : pd.getChildren()) { if (e instanceof ProcessDefinition) { ProcessDefinition sub = findElementProcess0((ProcessDefinition) e, id); if (sub != null) { return sub; } } } return null; }
public void add(ProcessDefinition d) { m.put(d.getId(), d); }
private static List<SequenceFlow> findOutgoingFlows(ProcessDefinition pd, String from) { List<SequenceFlow> result = new ArrayList<>(); for (AbstractElement e : pd.getChildren()) { if (e instanceof SequenceFlow) { SequenceFlow f = (SequenceFlow) e; if (from.equals(f.getFrom())) { result.add(f); } } } return result; }
process = new ProcessDefinition(processId, children, Collections.singletonMap(ProcessDefinition.SOURCE_TYPE_ATTRIBUTE, TYPE)); process.setName(processName);
public SourceAwareProcessDefinition(ProcessDefinition source, Map<String, SourceMap> sourceMaps) { super(source, source.getAttributes()); this.sourceMaps = sourceMaps; }
@Override public Collection<ProcessDefinition> parse(InputStream in) throws ParserException { YAMLMapper m = new YAMLMapper(); Map<String, Object> data; try { data = m.readValue(in, Map.class); } catch (IOException e) { throw new ParserException("Error while parsing the data", e); } log.debug("parse -> got: {}", data); Collection<ProcessDefinition> result = new ArrayList<>(); for (Map.Entry<String, Object> entry : data.entrySet()) { String id = entry.getKey(); Object v = entry.getValue(); if (!(v instanceof List)) { throw new ParserException("Unsupported element type in the process '" + id + "': " + v); } List<Object> l = (List<Object>) v; IdGenerator idGenerator = new IdGenerator(); ProcessDefinition pd = new ProcessDefinition(id, addEntryPoint(idGenerator, toElements(idGenerator, l)), Collections.singletonMap(ProcessDefinition.SOURCE_TYPE_ATTRIBUTE, TYPE)); if (log.isDebugEnabled()) { print(pd, 0); } result.add(pd); } return result; }
/** * Finds a (first) start event of the process. * * @param pd * @throws ExecutionException if process has no start events. */ public static StartEvent findStartEvent(ProcessDefinition pd) throws ExecutionException { for (AbstractElement e : pd.getChildren()) { if (e instanceof StartEvent) { return (StartEvent) e; } } throw new ExecutionException("Invalid process definition '%s': no start event defined", pd.getId()); }
private static void parseAndStore(MultipleDefinitionParser parser, Map<String, String> attrs, Map<String, ProcessDefinition> m, File f) throws IOException { try (InputStream in = new BufferedInputStream(new FileInputStream(f))) { Collection<ProcessDefinition> pds = parser.parse(in); for (ProcessDefinition pd : pds) { m.put(pd.getId(), mergeAttrs(pd, attrs)); log.info("parseAndStore ['{}'] -> got '{}'", f.getAbsolutePath(), pd.getId()); } } catch (ParserException e) { log.warn("parseAndStore ['{}'] -> skipping, {}", f.getAbsolutePath(), e.getMessage()); } }
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); } } }
/** * Finds all incoming flows for the specified element. * * @param pd * @param to * @throws ExecutionException if the element has no incoming flows.. */ public static List<SequenceFlow> findIncomingFlows(ProcessDefinition pd, String to) throws ExecutionException { List<SequenceFlow> result = new ArrayList<>(); ProcessDefinition sub = findElementProcess(pd, to); for (AbstractElement e : sub.getChildren()) { if (e instanceof SequenceFlow) { SequenceFlow f = (SequenceFlow) e; if (to.equals(f.getTo())) { result.add(f); } } } if (result.isEmpty()) { throw new ExecutionException("Invalid process definition '%s': no flows to '%s'", pd.getId(), to); } return result; }
public static String dump(ProcessDefinition pd) { Map<String, SourceMap> sms = Collections.emptyMap(); if (pd instanceof SourceAwareProcessDefinition) { sms = ((SourceAwareProcessDefinition) pd).getSourceMaps(); } StringBuilder b = new StringBuilder(); b.append("===================================\n").append("\tID: ").append(pd.getId()).append("\n"); dump(b, pd, sms, 2); return b.toString(); }
private static void indexBoundaryEvents0(ProcessDefinition pd, Map<String, List<BoundaryEvent>> accumulator) { for (AbstractElement e : pd.getChildren()) { if (e instanceof ProcessDefinition) { indexBoundaryEvents0((ProcessDefinition) e, accumulator); } if (!(e instanceof BoundaryEvent)) { continue; } BoundaryEvent ev = (BoundaryEvent) e; if (ev.getAttachedToRef() == null) { continue; } List<BoundaryEvent> l = accumulator.computeIfAbsent(ev.getAttachedToRef(), k -> new ArrayList<>()); l.add(ev); } } }
/** * Finds a subprocess by its ID. * * @param pd * @param id * @throws ExecutionException if the subprocess is not found. */ public static SubProcess findSubProcess(ProcessDefinition pd, String id) throws ExecutionException { AbstractElement e = findElement(pd, id); if (e instanceof SubProcess) { return (SubProcess) e; } else { throw new ExecutionException("Invalid process definition '%s': element '%s' is not a subprocess element", pd.getId(), id); } }
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("]");
/** * Finds a (sub)process definition by its element ID. * * @param pd a parent process definition. * @param id a (sub)process element ID. * @return the process definition, which contains an element with the * specified ID. * @throws ExecutionException if the element is not found in the parent * process or any of its subprocesses. */ public static ProcessDefinition findElementProcess(ProcessDefinition pd, String id) throws ExecutionException { ProcessDefinition sub = findElementProcess0(pd, id); if (sub == null) { throw new ExecutionException("Invalid process definition '%s': unknown element '%s'", pd.getId(), id); } return sub; }
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); } } }