use of org.kie.api.definition.process.NodeContainer in project jbpm by kiegroup.
the class CompensationEventListener method createNodeInstanceContainers.
private Stack<NodeInstance> createNodeInstanceContainers(Node toCompensateNode, boolean generalCompensation) {
Stack<NodeContainer> nestedNodes = new Stack<NodeContainer>();
Stack<NodeInstance> generatedInstances = new Stack<NodeInstance>();
NodeContainer parentContainer = toCompensateNode.getNodeContainer();
while (!(parentContainer instanceof RuleFlowProcess)) {
nestedNodes.add(parentContainer);
parentContainer = ((Node) parentContainer).getNodeContainer();
}
NodeInstanceContainer parentInstance;
if (nestedNodes.isEmpty()) {
// nestedNodes is empty
parentInstance = (NodeInstanceContainer) getProcessInstance();
} else {
parentInstance = (NodeInstanceContainer) ((WorkflowProcessInstanceImpl) getProcessInstance()).getNodeInstance((Node) nestedNodes.pop());
generatedInstances.add((NodeInstance) parentInstance);
}
NodeInstanceContainer childInstance = parentInstance;
while (!nestedNodes.isEmpty()) {
// generate
childInstance = (NodeInstanceContainer) parentInstance.getNodeInstance((Node) nestedNodes.pop());
assert childInstance instanceof CompositeNodeInstance : "A node with child nodes should end up creating a CompositeNodeInstance type.";
// track and modify
generatedInstances.add((NodeInstance) childInstance);
// loop
parentInstance = (CompositeContextNodeInstance) childInstance;
}
if (generalCompensation) {
childInstance = (NodeInstanceContainer) parentInstance.getNodeInstance(toCompensateNode);
generatedInstances.add((NodeInstance) childInstance);
}
return generatedInstances;
}
use of org.kie.api.definition.process.NodeContainer in project jbpm by kiegroup.
the class WorkflowProcessInstanceUpgrader method getNodeId.
private static String getNodeId(Node[] nodes, String nodeName, boolean unique) {
Stack<Node> nodeStack = new Stack<Node>();
for (Node node : nodes) {
nodeStack.push(node);
}
Node match = null;
while (!nodeStack.isEmpty()) {
Node topNode = nodeStack.pop();
if (topNode.getName().compareTo(nodeName) == 0) {
match = topNode;
break;
}
if (topNode instanceof NodeContainer) {
for (Node node : ((NodeContainer) topNode).getNodes()) {
nodeStack.push(node);
}
}
}
if (match == null) {
throw new IllegalArgumentException("No node with name " + nodeName);
}
String id = "";
if (unique) {
while (!(match.getNodeContainer() instanceof Process)) {
id = ":" + match.getId() + id;
match = (Node) match.getNodeContainer();
}
}
id = match.getId() + id;
return id;
}
use of org.kie.api.definition.process.NodeContainer in project jbpm by kiegroup.
the class NodeImpl method getUniqueId.
public String getUniqueId() {
String result = id + "";
NodeContainer nodeContainer = 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 ProcessBuilderImpl method generateRules.
private void generateRules(Node[] nodes, Process process, StringBuffer builder) {
for (int i = 0; i < nodes.length; i++) {
if (nodes[i] instanceof Split) {
Split split = (Split) nodes[i];
if (split.getType() == Split.TYPE_XOR || split.getType() == Split.TYPE_OR) {
for (Connection connection : split.getDefaultOutgoingConnections()) {
Constraint constraint = split.getConstraint(connection);
if (constraint != null && "rule".equals(constraint.getType())) {
builder.append(createSplitRule(process, connection, split.getConstraint(connection).getConstraint()));
}
}
}
} else if (nodes[i] instanceof MilestoneNode) {
MilestoneNode milestone = (MilestoneNode) nodes[i];
builder.append(createMilestoneRule(process, milestone));
} else if (nodes[i] instanceof StateNode) {
StateNode state = (StateNode) nodes[i];
builder.append(createStateRules(process, state));
} else if (nodes[i] instanceof StartNode) {
StartNode startNode = (StartNode) nodes[i];
List<Trigger> triggers = startNode.getTriggers();
if (triggers != null) {
for (Trigger trigger : triggers) {
if (trigger instanceof ConstraintTrigger) {
builder.append(createStartConstraintRule(process, startNode.getNodeContainer(), (ConstraintTrigger) trigger));
}
}
}
} else if (nodes[i] instanceof NodeContainer) {
generateRules(((NodeContainer) nodes[i]).getNodes(), process, builder);
if (nodes[i] instanceof DynamicNode && "rule".equals(((DynamicNode) nodes[i]).getLanguage())) {
DynamicNode dynamicNode = (DynamicNode) nodes[i];
if (dynamicNode.getCompletionExpression() != null) {
builder.append(createAdHocCompletionRule(process, dynamicNode));
}
if (dynamicNode.getActivationExpression() != null && !dynamicNode.getActivationExpression().isEmpty()) {
builder.append(createAdHocActivationRule(process, dynamicNode));
}
}
} else if (nodes[i] instanceof EventNode) {
EventNode state = (EventNode) nodes[i];
builder.append(createEventStateRule(process, state));
}
}
}
use of org.kie.api.definition.process.NodeContainer in project jbpm by kiegroup.
the class ChecklistItemFactory method getPendingChecklistItems.
private static void getPendingChecklistItems(NodeContainer container, List<ChecklistItem> result, String processId) {
for (Node node : container.getNodes()) {
if (node instanceof HumanTaskNode) {
Work workItem = ((HumanTaskNode) node).getWork();
int priority = 0;
String priorityString = (String) workItem.getParameter("Priority");
if (priorityString != null) {
try {
priority = new Integer(priorityString);
} catch (NumberFormatException e) {
// Do nothing
}
}
String actorId = (String) workItem.getParameter("ActorId");
if (actorId != null && actorId.trim().length() == 0) {
actorId = null;
}
String groupId = (String) workItem.getParameter("GroupId");
if (groupId != null && groupId.trim().length() == 0) {
groupId = null;
}
String actors = null;
if (actorId == null) {
if (groupId == null) {
actors = "";
} else {
actors = groupId;
}
} else {
if (groupId == null) {
actors = actorId;
} else {
actors = actorId + "," + groupId;
}
}
Status status = Status.Pending;
if (((HumanTaskNode) node).getDefaultIncomingConnections().size() == 0) {
status = Status.Optional;
}
result.add(createChecklistItem((String) workItem.getParameter("TaskName"), "HumanTaskNode", actors, (String) workItem.getParameter("Comment"), priority, processId, status));
} else if (node instanceof NodeContainer) {
getPendingChecklistItems((NodeContainer) node, result, processId);
} else {
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);
Status status = Status.Pending;
if (((NodeImpl) node).getDefaultIncomingConnections().size() == 0 && !(node instanceof StartNode)) {
status = Status.Optional;
}
result.add(createChecklistItem(node.getName(), node.getClass().getSimpleName(), "", orderingNumber, 0, processId, status));
}
}
}
}
}
Aggregations