use of org.kie.api.definition.process.NodeContainer in project drools by kiegroup.
the class WorkingMemoryLogger method createNodeId.
private String createNodeId(NodeInstance nodeInstance) {
Node node = nodeInstance.getNode();
if (node == null) {
return "";
}
Object uniqueIdObj = node.getMetaData().get("UniqueId");
String nodeId;
if (uniqueIdObj == null) {
nodeId = "" + node.getId();
} else {
nodeId = (String) uniqueIdObj;
}
NodeContainer nodeContainer = node.getNodeContainer();
while (nodeContainer != null) {
if (nodeContainer instanceof Node) {
node = (Node) nodeContainer;
nodeContainer = node.getNodeContainer();
// TODO fix this filter out hidden compositeNode inside ForEach node
if (!(nodeContainer.getClass().getName().endsWith("ForEachNode"))) {
nodeId = node.getId() + ":" + nodeId;
}
} else {
break;
}
}
return nodeId;
}
use of org.kie.api.definition.process.NodeContainer in project jbpm by kiegroup.
the class ChecklistItemFactory method getRelevantNodes.
private static void getRelevantNodes(NodeContainer container, Map<String, String> result) {
for (Node node : container.getNodes()) {
if (node instanceof NodeContainer) {
getRelevantNodes((NodeContainer) node, result);
}
String docs = (String) node.getMetaData().get("Documentation");
if (docs != null) {
int position = docs.indexOf("OrderingNb=");
if (position >= 0) {
int end = docs.indexOf(";", position + 1);
String orderingNumber = docs.substring(position + 11, end);
String nodeId = (String) node.getMetaData().get("UniqueId");
if (nodeId == null) {
nodeId = ((NodeImpl) node).getUniqueId();
}
result.put(nodeId, orderingNumber);
}
}
}
}
use of org.kie.api.definition.process.NodeContainer in project jbpm by kiegroup.
the class XmlBPMNProcessDumper method getUniqueNodeId.
public static String getUniqueNodeId(Node node) {
String result = (String) node.getMetaData().get("UniqueId");
if (result != null) {
return result;
}
result = node.getId() + "";
NodeContainer nodeContainer = node.getNodeContainer();
while (nodeContainer instanceof CompositeNode) {
CompositeNode composite = (CompositeNode) nodeContainer;
result = composite.getId() + "-" + result;
nodeContainer = composite.getNodeContainer();
}
return "_" + result;
}
use of org.kie.api.definition.process.NodeContainer in project jbpm by kiegroup.
the class BPMNPlaneHandler method processNodeInfo.
private boolean processNodeInfo(NodeInfo nodeInfo, Node[] nodes) {
if (nodeInfo == null || nodeInfo.getNodeRef() == null) {
return false;
}
for (Node node : nodes) {
String id = (String) node.getMetaData().get("UniqueId");
if (nodeInfo.getNodeRef().equals(id)) {
((org.jbpm.workflow.core.Node) node).setMetaData("x", nodeInfo.getX());
((org.jbpm.workflow.core.Node) node).setMetaData("y", nodeInfo.getY());
((org.jbpm.workflow.core.Node) node).setMetaData("width", nodeInfo.getWidth());
((org.jbpm.workflow.core.Node) node).setMetaData("height", nodeInfo.getHeight());
return true;
}
if (node instanceof NodeContainer) {
boolean found = processNodeInfo(nodeInfo, ((NodeContainer) node).getNodes());
if (found) {
return true;
}
}
}
return false;
}
use of org.kie.api.definition.process.NodeContainer in project jbpm by kiegroup.
the class ProcessHandler method linkAssociations.
public static void linkAssociations(Definitions definitions, NodeContainer nodeContainer, List<Association> associations) {
if (associations != null) {
for (Association association : associations) {
String sourceRef = association.getSourceRef();
Object source = null;
try {
source = findNodeOrDataStoreByUniqueId(definitions, nodeContainer, sourceRef, "Could not find source [" + sourceRef + "] for association " + association.getId() + "]");
} catch (IllegalArgumentException e) {
// source not found
}
String targetRef = association.getTargetRef();
Object target = null;
try {
target = findNodeOrDataStoreByUniqueId(definitions, nodeContainer, targetRef, "Could not find target [" + targetRef + "] for association [" + association.getId() + "]");
} catch (IllegalArgumentException e) {
// target not found
}
if (source == null || target == null) {
// TODO: ignoring this association for now
} else if (target instanceof DataStore || source instanceof DataStore) {
// TODO: ignoring data store associations for now
} else if (source instanceof EventNode) {
EventNode sourceNode = (EventNode) source;
Node targetNode = (Node) target;
checkBoundaryEventCompensationHandler(association, sourceNode, targetNode);
// make sure IsForCompensation is set to true on target
NodeImpl targetNodeImpl = (NodeImpl) target;
String isForCompensation = "isForCompensation";
Object compensationObject = targetNodeImpl.getMetaData(isForCompensation);
if (compensationObject == null) {
targetNodeImpl.setMetaData(isForCompensation, true);
logger.warn("Setting {} attribute to true for node {}", isForCompensation, targetRef);
} else if (!Boolean.parseBoolean(compensationObject.toString())) {
throw new IllegalArgumentException(isForCompensation + " attribute [" + compensationObject + "] should be true for Compensation Activity [" + targetRef + "]");
}
// put Compensation Handler in CompensationHandlerNode
NodeContainer sourceParent = sourceNode.getNodeContainer();
NodeContainer targetParent = targetNode.getNodeContainer();
if (!sourceParent.equals(targetParent)) {
throw new IllegalArgumentException("Compensation Associations may not cross (sub-)process boundaries,");
}
// connect boundary event to compensation activity
ConnectionImpl connection = new ConnectionImpl(sourceNode, NodeImpl.CONNECTION_DEFAULT_TYPE, targetNode, NodeImpl.CONNECTION_DEFAULT_TYPE);
connection.setMetaData("UniqueId", null);
connection.setMetaData("hidden", true);
connection.setMetaData("association", true);
// Compensation use cases:
// - boundary event --associated-> activity
// - implicit sub process compensation handler + recursive?
/**
* BPMN2 spec, p.442:
* "A Compensation Event Sub-process becomes enabled when its parent Activity transitions into state
* Completed. At that time, a snapshot of the data associated with the parent Acitivity is taken and kept for
* later usage by the Compensation Event Sub-Process."
*/
}
}
}
}
Aggregations