use of io.automatiko.engine.workflow.bpmn2.core.IntermediateLink in project automatiko-engine by automatiko-io.
the class IntermediateCatchEventHandler method handleLinkNode.
protected void handleLinkNode(Element element, Node node, org.w3c.dom.Node xmlLinkNode, ExtensibleXmlParser parser) {
NodeContainer nodeContainer = (NodeContainer) parser.getParent();
node.setName(element.getAttribute("name"));
NamedNodeMap linkAttr = xmlLinkNode.getAttributes();
String name = linkAttr.getNamedItem("name").getNodeValue();
String id = element.getAttribute("id");
node.setMetaData("UniqueId", id);
node.setMetaData(LINK_NAME, name);
org.w3c.dom.Node xmlNode = xmlLinkNode.getFirstChild();
IntermediateLink aLink = new IntermediateLink();
aLink.setName(name);
aLink.setUniqueId(id);
while (null != xmlNode) {
String nodeName = xmlNode.getNodeName();
if ("target".equals(nodeName)) {
String target = xmlNode.getTextContent();
node.setMetaData("target", target);
aLink.setTarget(target);
}
if ("source".equals(nodeName)) {
String source = xmlNode.getTextContent();
node.setMetaData("source", source);
aLink.addSource(source);
}
xmlNode = xmlNode.getNextSibling();
}
if (nodeContainer instanceof ExecutableProcess) {
ExecutableProcess process = (ExecutableProcess) nodeContainer;
List<IntermediateLink> links = (List<IntermediateLink>) process.getMetaData().get(ProcessHandler.LINKS);
if (null == links) {
links = new ArrayList<IntermediateLink>();
}
links.add(aLink);
process.setMetaData(ProcessHandler.LINKS, links);
} else if (nodeContainer instanceof CompositeNode) {
CompositeNode subprocess = (CompositeNode) nodeContainer;
List<IntermediateLink> links = (List<IntermediateLink>) subprocess.getMetaData().get(ProcessHandler.LINKS);
if (null == links) {
links = new ArrayList<IntermediateLink>();
}
links.add(aLink);
subprocess.setMetaData(ProcessHandler.LINKS, links);
}
}
use of io.automatiko.engine.workflow.bpmn2.core.IntermediateLink in project automatiko-engine by automatiko-io.
the class ProcessHandler method end.
@SuppressWarnings("unchecked")
public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
parser.endElementBuilder();
ExecutableProcess process = (ExecutableProcess) parser.getCurrent();
List<IntermediateLink> throwLinks = (List<IntermediateLink>) process.getMetaData(LINKS);
linkIntermediateLinks(process, throwLinks);
List<SequenceFlow> connections = (List<SequenceFlow>) process.getMetaData(CONNECTIONS);
linkConnections(process, connections);
linkBoundaryEvents(process);
// This must be done *after* linkConnections(process, connections)
// because it adds hidden connections for compensations
List<Association> associations = (List<Association>) process.getMetaData(ASSOCIATIONS);
linkAssociations((Definitions) process.getMetaData("Definitions"), process, associations);
List<Lane> lanes = (List<Lane>) process.getMetaData(LaneHandler.LANES);
assignLanes(process, lanes);
postProcessNodes(process, process);
// process tags if any defined
processTags(process);
return process;
}
use of io.automatiko.engine.workflow.bpmn2.core.IntermediateLink in project jbpm by kiegroup.
the class ProcessHandler method linkIntermediateLinks.
public static void linkIntermediateLinks(NodeContainer process, List<IntermediateLink> links) {
if (links == null) {
return;
}
Map<String, IntermediateLink> catchLinks = new HashMap<>();
Map<String, Collection<IntermediateLink>> throwLinks = new HashMap<>();
Collection<IntermediateLink> noNameLinks = new ArrayList<>();
Collection<IntermediateLink> duplicatedTarget = new LinkedHashSet<>();
Collection<IntermediateLink> unconnectedTarget = new ArrayList<>();
// collect errors and nodes in first loop
for (IntermediateLink link : links) {
if (link.getName() == null || link.getName().isEmpty()) {
noNameLinks.add(link);
} else if (link.isThrowLink()) {
throwLinks.computeIfAbsent(link.getName(), s -> new ArrayList<>()).add(link);
} else {
IntermediateLink duplicateLink = catchLinks.putIfAbsent(link.getName(), link);
if (duplicateLink != null) {
duplicatedTarget.add(duplicateLink);
duplicatedTarget.add(link);
}
}
}
// second loop for connection
for (IntermediateLink catchLink : catchLinks.values()) {
Collection<IntermediateLink> associatedLinks = throwLinks.remove(catchLink.getName());
if (associatedLinks != null) {
// connect throw to catch
Node catchNode = findNodeByIdOrUniqueIdInMetadata(process, catchLink.getUniqueId());
if (catchNode != null) {
for (IntermediateLink throwLink : associatedLinks) {
Node throwNode = findNodeByIdOrUniqueIdInMetadata(process, throwLink.getUniqueId());
if (throwNode != null) {
Connection result = new ConnectionImpl(throwNode, NodeImpl.CONNECTION_DEFAULT_TYPE, catchNode, NodeImpl.CONNECTION_DEFAULT_TYPE);
result.setMetaData("linkNodeHidden", "yes");
}
}
}
} else {
unconnectedTarget.add(catchLink);
}
}
// throw exception if any error (this is done at the end of the process to show the user as much errors as possible)
StringBuilder errors = new StringBuilder();
if (!noNameLinks.isEmpty()) {
formatError(errors, "These nodes do not have a name ", noNameLinks.stream(), process);
}
if (!duplicatedTarget.isEmpty()) {
formatError(errors, "\nThere are multiple catch nodes with the same name ", duplicatedTarget.stream(), process);
}
if (!unconnectedTarget.isEmpty()) {
formatError(errors, "\nThere is not connection from any throw link to these catch links ", unconnectedTarget.stream(), process);
}
if (!throwLinks.isEmpty()) {
formatError(errors, "\nThere is not connection from any catch link to these throw links ", throwLinks.values().stream().flatMap(Collection::stream), process);
}
if (errors.length() > 0) {
throw new IllegalArgumentException(errors.toString());
}
}
use of io.automatiko.engine.workflow.bpmn2.core.IntermediateLink in project jbpm by kiegroup.
the class ProcessHandler method end.
@SuppressWarnings("unchecked")
public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
parser.endElementBuilder();
RuleFlowProcess process = (RuleFlowProcess) parser.getCurrent();
List<IntermediateLink> throwLinks = (List<IntermediateLink>) process.getMetaData(LINKS);
linkIntermediateLinks(process, throwLinks);
List<SequenceFlow> connections = (List<SequenceFlow>) process.getMetaData(CONNECTIONS);
linkConnections(process, connections);
linkBoundaryEvents(process);
// This must be done *after* linkConnections(process, connections)
// because it adds hidden connections for compensations
List<Association> associations = (List<Association>) process.getMetaData(ASSOCIATIONS);
linkAssociations((Definitions) process.getMetaData("Definitions"), process, associations);
List<Lane> lanes = (List<Lane>) process.getMetaData(LaneHandler.LANES);
assignLanes(process, lanes);
postProcessNodes(process, process);
postProcessCollaborations(process, parser);
return process;
}
use of io.automatiko.engine.workflow.bpmn2.core.IntermediateLink in project jbpm by kiegroup.
the class IntermediateThrowEventHandler method handleLinkNode.
protected void handleLinkNode(Element element, Node node, org.w3c.dom.Node xmlLinkNode, ExtensibleXmlParser parser) {
node.setName(element.getAttribute("name"));
NamedNodeMap linkAttr = xmlLinkNode.getAttributes();
String name = linkAttr.getNamedItem("name").getNodeValue();
String id = element.getAttribute("id");
node.setMetaData("UniqueId", id);
node.setMetaData(LINK_NAME, name);
org.w3c.dom.Node xmlNode = xmlLinkNode.getFirstChild();
NodeContainer nodeContainer = (NodeContainer) parser.getParent();
IntermediateLink aLink = new IntermediateLink();
aLink.setName(name);
aLink.setUniqueId(id);
while (null != xmlNode) {
String nodeName = xmlNode.getNodeName();
if (LINK_TARGET.equals(nodeName)) {
String target = xmlNode.getTextContent();
node.setMetaData(LINK_TARGET, target);
}
if (LINK_SOURCE.equals(nodeName)) {
String source = xmlNode.getTextContent();
ArrayList<String> sources = (ArrayList<String>) node.getMetaData().get(LINK_SOURCE);
// if there is no list, create one
if (null == sources) {
sources = new ArrayList<String>();
}
// to connect nodes.
aLink.addSource(source);
// to do the xml dump
sources.add(source);
node.setMetaData(LINK_SOURCE, sources);
}
xmlNode = xmlNode.getNextSibling();
}
aLink.configureThrow();
if (nodeContainer instanceof RuleFlowProcess) {
RuleFlowProcess process = (RuleFlowProcess) nodeContainer;
List<IntermediateLink> links = (List<IntermediateLink>) process.getMetaData().get(ProcessHandler.LINKS);
if (null == links) {
links = new ArrayList<IntermediateLink>();
}
links.add(aLink);
process.setMetaData(ProcessHandler.LINKS, links);
} else if (nodeContainer instanceof CompositeNode) {
CompositeNode subprocess = (CompositeNode) nodeContainer;
List<IntermediateLink> links = (List<IntermediateLink>) subprocess.getMetaData().get(ProcessHandler.LINKS);
if (null == links) {
links = new ArrayList<IntermediateLink>();
}
links.add(aLink);
subprocess.setMetaData(ProcessHandler.LINKS, links);
}
}
Aggregations