use of org.kie.api.definition.process.Node in project jbpm by kiegroup.
the class JbpmJUnitBaseTestCase method assertNodeExists.
public void assertNodeExists(ProcessInstance process, String... nodeNames) {
WorkflowProcessInstanceImpl instance = (WorkflowProcessInstanceImpl) process;
List<String> names = new ArrayList<String>();
for (String nodeName : nodeNames) {
names.add(nodeName);
}
for (Node node : instance.getNodeContainer().getNodes()) {
if (names.contains(node.getName())) {
names.remove(node.getName());
}
}
if (!names.isEmpty()) {
String s = names.get(0);
for (int i = 1; i < names.size(); i++) {
s += ", " + names.get(i);
}
fail("Node(s) do not exist: " + s);
}
}
use of org.kie.api.definition.process.Node in project jbpm by kiegroup.
the class JbpmJUnitTestCase method assertNodeExists.
public void assertNodeExists(ProcessInstance process, String... nodeNames) {
WorkflowProcessInstanceImpl instance = (WorkflowProcessInstanceImpl) process;
List<String> names = new ArrayList<String>();
for (String nodeName : nodeNames) {
names.add(nodeName);
}
for (Node node : instance.getNodeContainer().getNodes()) {
if (names.contains(node.getName())) {
names.remove(node.getName());
}
}
if (!names.isEmpty()) {
String s = names.get(0);
for (int i = 1; i < names.size(); i++) {
s += ", " + names.get(i);
}
fail("Node(s) do not exist: " + s);
}
}
use of org.kie.api.definition.process.Node in project jbpm by kiegroup.
the class TriggerNodeCommand method execute.
public Void execute(Context context) {
KieSession kieSession = ((RegistryContext) context).lookup(KieSession.class);
logger.debug("About to trigger (create) node instance for node {} in process instance {}", nodeId, processInstanceId);
RuleFlowProcessInstance wfp = (RuleFlowProcessInstance) kieSession.getProcessInstance(processInstanceId, false);
if (wfp == null) {
throw new ProcessInstanceNotFoundException("Process instance with id " + processInstanceId + " not found");
}
Node node = wfp.getRuleFlowProcess().getNodesRecursively().stream().filter(ni -> ni.getId() == nodeId).findFirst().orElse(null);
if (node == null) {
throw new NodeNotFoundException("Node instance with id " + nodeId + " not found");
}
logger.debug("Triggering node {} on process instance {}", node, wfp);
wfp.getNodeInstance(node).trigger(null, org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE);
logger.debug("Node {} successfully triggered", node);
return null;
}
use of org.kie.api.definition.process.Node 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);
}
}
}
use of org.kie.api.definition.process.Node in project jbpm by kiegroup.
the class JbpmJUnitTestCase method assertNumOfIncommingConnections.
public void assertNumOfIncommingConnections(ProcessInstance process, String nodeName, int num) {
assertNodeExists(process, nodeName);
WorkflowProcessInstanceImpl instance = (WorkflowProcessInstanceImpl) process;
for (Node node : instance.getNodeContainer().getNodes()) {
if (node.getName().equals(nodeName)) {
if (node.getIncomingConnections().size() != num) {
fail("Expected incomming connections: " + num + " - found " + node.getIncomingConnections().size());
} else {
break;
}
}
}
}
Aggregations