use of org.jbpm.workflow.instance.NodeInstanceContainer in project jbpm by kiegroup.
the class WorkflowReuseContextInstanceFactory method getContextInstance.
public ContextInstance getContextInstance(Context context, ContextInstanceContainer contextInstanceContainer, ProcessInstance processInstance) {
ContextInstance result = contextInstanceContainer.getContextInstance(context.getType(), context.getId());
if (result != null) {
return result;
}
try {
AbstractContextInstance contextInstance = (AbstractContextInstance) cls.newInstance();
contextInstance.setContextId(context.getId());
contextInstance.setContextInstanceContainer(contextInstanceContainer);
contextInstance.setProcessInstance(processInstance);
contextInstanceContainer.addContextInstance(context.getType(), contextInstance);
NodeInstanceContainer nodeInstanceContainer = null;
if (contextInstanceContainer instanceof NodeInstanceContainer) {
nodeInstanceContainer = (NodeInstanceContainer) contextInstanceContainer;
} else if (contextInstanceContainer instanceof ContextInstance) {
ContextInstanceContainer parent = ((ContextInstance) contextInstanceContainer).getContextInstanceContainer();
while (parent != null) {
if (parent instanceof NodeInstanceContainer) {
nodeInstanceContainer = (NodeInstanceContainer) parent;
} else if (contextInstanceContainer instanceof ContextInstance) {
parent = ((ContextInstance) contextInstanceContainer).getContextInstanceContainer();
} else {
parent = null;
}
}
}
((WorkflowContextInstance) contextInstance).setNodeInstanceContainer(nodeInstanceContainer);
return contextInstance;
} catch (Exception e) {
throw new RuntimeException("Unable to instantiate context '" + this.cls.getName() + "': " + e.getMessage());
}
}
use of org.jbpm.workflow.instance.NodeInstanceContainer 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.jbpm.workflow.instance.NodeInstanceContainer in project jbpm by kiegroup.
the class ListTimersCommand method processNodeInstance.
protected void processNodeInstance(TimerManager tm, NodeInstanceContainer container, List<TimerInstance> timers) {
for (NodeInstance nodeInstance : container.getNodeInstances()) {
if (nodeInstance instanceof TimerNodeInstance) {
TimerNodeInstance tni = (TimerNodeInstance) nodeInstance;
org.jbpm.process.instance.timer.TimerInstance timer = tm.getTimerMap().get(tni.getTimerId());
TimerInstanceImpl details = buildTimer(timer);
details.setTimerName(resolveVariable(tni.getNodeName(), tni));
timers.add(details);
} else if (nodeInstance instanceof StateBasedNodeInstance) {
StateBasedNodeInstance sbni = (StateBasedNodeInstance) nodeInstance;
List<Long> timerList = sbni.getTimerInstances();
if (timerList != null) {
for (Long timerId : timerList) {
org.jbpm.process.instance.timer.TimerInstance timer = tm.getTimerMap().get(timerId);
TimerInstanceImpl details = buildTimer(timer);
details.setTimerName(resolveVariable(sbni.getNodeName(), sbni));
timers.add(details);
}
}
}
if (nodeInstance instanceof NodeInstanceContainer) {
processNodeInstance(tm, (NodeInstanceContainer) nodeInstance, timers);
}
}
}
use of org.jbpm.workflow.instance.NodeInstanceContainer in project jbpm by kiegroup.
the class MigrationManager method updateNodeInstances.
@SuppressWarnings("unchecked")
private void updateNodeInstances(NodeInstanceContainer nodeInstanceContainer, Map<String, String> nodeMapping, NodeContainer nodeContainer, EntityManager em) {
for (NodeInstance nodeInstance : nodeInstanceContainer.getNodeInstances()) {
Long upgradedNodeId = null;
String oldNodeId = (String) ((NodeImpl) ((org.jbpm.workflow.instance.NodeInstance) nodeInstance).getNode()).getMetaData().get("UniqueId");
String newNodeId = nodeMapping.get(oldNodeId);
if (newNodeId == null) {
newNodeId = oldNodeId;
}
Node upgradedNode = findNodeByUniqueId(newNodeId, nodeContainer);
if (upgradedNode == null) {
try {
upgradedNodeId = Long.parseLong(newNodeId);
} catch (NumberFormatException e) {
continue;
}
} else {
upgradedNodeId = upgradedNode.getId();
}
((NodeInstanceImpl) nodeInstance).setNodeId(upgradedNodeId);
if (upgradedNode != null) {
// update log information for new node information
Query nodeInstanceIdQuery = em.createQuery("select nodeInstanceId from NodeInstanceLog nil" + " where nil.nodeId = :oldNodeId and processInstanceId = :processInstanceId " + " GROUP BY nil.nodeInstanceId" + " HAVING sum(nil.type) = 0");
nodeInstanceIdQuery.setParameter("oldNodeId", oldNodeId).setParameter("processInstanceId", nodeInstance.getProcessInstance().getId());
List<Long> nodeInstanceIds = nodeInstanceIdQuery.getResultList();
report.addEntry(Type.INFO, "Mapping: Node instance logs to be updated = " + nodeInstanceIds);
Query nodeLogQuery = em.createQuery("update NodeInstanceLog set nodeId = :nodeId, nodeName = :nodeName, nodeType = :nodeType " + "where nodeInstanceId in (:ids) and processInstanceId = :processInstanceId");
nodeLogQuery.setParameter("nodeId", (String) upgradedNode.getMetaData().get("UniqueId")).setParameter("nodeName", upgradedNode.getName()).setParameter("nodeType", upgradedNode.getClass().getSimpleName()).setParameter("ids", nodeInstanceIds).setParameter("processInstanceId", nodeInstance.getProcessInstance().getId());
int nodesUpdated = nodeLogQuery.executeUpdate();
report.addEntry(Type.INFO, "Mapping: Node instance logs updated = " + nodesUpdated + " for node instance id " + nodeInstance.getId());
if (upgradedNode instanceof HumanTaskNode && nodeInstance instanceof HumanTaskNodeInstance) {
Long taskId = (Long) em.createQuery("select id from TaskImpl where workItemId = :workItemId").setParameter("workItemId", ((HumanTaskNodeInstance) nodeInstance).getWorkItemId()).getSingleResult();
String name = ((HumanTaskNode) upgradedNode).getName();
String description = (String) ((HumanTaskNode) upgradedNode).getWork().getParameter("Description");
// update task audit instance log with new deployment and process id
Query auditTaskLogQuery = em.createQuery("update AuditTaskImpl set name = :name, description = :description where taskId = :taskId");
auditTaskLogQuery.setParameter("name", name).setParameter("description", description).setParameter("taskId", taskId);
int auditTaskUpdated = auditTaskLogQuery.executeUpdate();
report.addEntry(Type.INFO, "Mapping: Task audit updated = " + auditTaskUpdated + " for task id " + taskId);
// update task instance log with new deployment and process id
Query taskLogQuery = em.createQuery("update TaskImpl set name = :name, description = :description where id = :taskId");
taskLogQuery.setParameter("name", name).setParameter("description", description).setParameter("taskId", taskId);
int taskUpdated = taskLogQuery.executeUpdate();
report.addEntry(Type.INFO, "Mapping: Task updated = " + taskUpdated + " for task id " + taskId);
}
}
if (nodeInstance instanceof NodeInstanceContainer) {
updateNodeInstances((NodeInstanceContainer) nodeInstance, nodeMapping, nodeContainer, em);
}
}
}
Aggregations