Search in sources :

Example 16 with NodeImpl

use of org.jbpm.workflow.core.impl.NodeImpl 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)

Aggregations

NodeImpl (org.jbpm.workflow.core.impl.NodeImpl)16 Node (org.kie.api.definition.process.Node)8 ConnectionImpl (org.jbpm.workflow.core.impl.ConnectionImpl)6 EventSubProcessNode (org.jbpm.workflow.core.node.EventSubProcessNode)6 HumanTaskNode (org.jbpm.workflow.core.node.HumanTaskNode)6 ExtendedNodeImpl (org.jbpm.workflow.core.impl.ExtendedNodeImpl)5 ActionNode (org.jbpm.workflow.core.node.ActionNode)5 BoundaryEventNode (org.jbpm.workflow.core.node.BoundaryEventNode)5 EndNode (org.jbpm.workflow.core.node.EndNode)5 StartNode (org.jbpm.workflow.core.node.StartNode)5 CompositeContextNode (org.jbpm.workflow.core.node.CompositeContextNode)4 CompositeNode (org.jbpm.workflow.core.node.CompositeNode)4 EventNode (org.jbpm.workflow.core.node.EventNode)4 FaultNode (org.jbpm.workflow.core.node.FaultNode)4 RuleSetNode (org.jbpm.workflow.core.node.RuleSetNode)4 StateBasedNode (org.jbpm.workflow.core.node.StateBasedNode)4 List (java.util.List)3 EventFilter (org.jbpm.process.core.event.EventFilter)3 EventTypeFilter (org.jbpm.process.core.event.EventTypeFilter)3 StateNode (org.jbpm.workflow.core.node.StateNode)3