Search in sources :

Example 66 with Node

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);
    }
}
Also used : Node(org.kie.api.definition.process.Node) WorkflowProcessInstanceImpl(org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl) ArrayList(java.util.ArrayList)

Example 67 with Node

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);
    }
}
Also used : Node(org.kie.api.definition.process.Node) WorkflowProcessInstanceImpl(org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl) ArrayList(java.util.ArrayList)

Example 68 with Node

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;
}
Also used : RuleFlowProcessInstance(org.jbpm.ruleflow.instance.RuleFlowProcessInstance) NodeNotFoundException(org.jbpm.services.api.NodeNotFoundException) Node(org.kie.api.definition.process.Node) KieSession(org.kie.api.runtime.KieSession) RegistryContext(org.drools.core.command.impl.RegistryContext) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException)

Example 69 with Node

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);
        }
    }
}
Also used : NodeInstanceImpl(org.jbpm.workflow.instance.impl.NodeInstanceImpl) NodeInstanceContainer(org.jbpm.workflow.instance.NodeInstanceContainer) NodeImpl(org.jbpm.workflow.core.impl.NodeImpl) Query(javax.persistence.Query) HumanTaskNode(org.jbpm.workflow.core.node.HumanTaskNode) Node(org.kie.api.definition.process.Node) HumanTaskNodeInstance(org.jbpm.workflow.instance.node.HumanTaskNodeInstance) TimerNodeInstance(org.jbpm.workflow.instance.node.TimerNodeInstance) StateBasedNodeInstance(org.jbpm.workflow.instance.node.StateBasedNodeInstance) NodeInstance(org.kie.api.runtime.process.NodeInstance) HumanTaskNodeInstance(org.jbpm.workflow.instance.node.HumanTaskNodeInstance) HumanTaskNode(org.jbpm.workflow.core.node.HumanTaskNode)

Example 70 with Node

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;
            }
        }
    }
}
Also used : Node(org.kie.api.definition.process.Node) WorkflowProcessInstanceImpl(org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl)

Aggregations

Node (org.kie.api.definition.process.Node)70 StartNode (org.jbpm.workflow.core.node.StartNode)27 EventNode (org.jbpm.workflow.core.node.EventNode)26 ActionNode (org.jbpm.workflow.core.node.ActionNode)25 EndNode (org.jbpm.workflow.core.node.EndNode)25 CompositeNode (org.jbpm.workflow.core.node.CompositeNode)22 ArrayList (java.util.ArrayList)20 EventSubProcessNode (org.jbpm.workflow.core.node.EventSubProcessNode)20 WorkItemNode (org.jbpm.workflow.core.node.WorkItemNode)19 FaultNode (org.jbpm.workflow.core.node.FaultNode)17 HumanTaskNode (org.jbpm.workflow.core.node.HumanTaskNode)17 StateBasedNode (org.jbpm.workflow.core.node.StateBasedNode)15 BoundaryEventNode (org.jbpm.workflow.core.node.BoundaryEventNode)13 NodeContainer (org.kie.api.definition.process.NodeContainer)13 DynamicNode (org.jbpm.workflow.core.node.DynamicNode)11 ForEachNode (org.jbpm.workflow.core.node.ForEachNode)11 StateNode (org.jbpm.workflow.core.node.StateNode)11 RuleSetNode (org.jbpm.workflow.core.node.RuleSetNode)10 SubProcessNode (org.jbpm.workflow.core.node.SubProcessNode)10 WorkflowProcessInstanceImpl (org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl)10