Search in sources :

Example 31 with Node

use of org.kie.api.definition.process.Node in project jbpm by kiegroup.

the class CompensationScopeInstance method handleException.

public void handleException(ExceptionHandler handler, String compensationActivityRef, Object dunno) {
    WorkflowProcessInstanceImpl processInstance = (WorkflowProcessInstanceImpl) getProcessInstance();
    NodeInstanceContainer nodeInstanceContainer = (NodeInstanceContainer) getContextInstanceContainer();
    if (handler instanceof CompensationHandler) {
        CompensationHandler compensationHandler = (CompensationHandler) handler;
        try {
            Node handlerNode = compensationHandler.getnode();
            if (handlerNode instanceof BoundaryEventNode) {
                NodeInstance compensationHandlerNodeInstance = nodeInstanceContainer.getNodeInstance(handlerNode);
                compensationInstances.add(compensationHandlerNodeInstance);
                // The BoundaryEventNodeInstance.signalEvent() contains the necessary logic
                // to check whether or not compensation may proceed (? : (not-active + completed))
                EventNodeInstance eventNodeInstance = (EventNodeInstance) compensationHandlerNodeInstance;
                eventNodeInstance.signalEvent("Compensation", compensationActivityRef);
            } else if (handlerNode instanceof EventSubProcessNode) {
                // Check that subprocess parent has completed.
                List<String> completedIds = processInstance.getCompletedNodeIds();
                if (completedIds.contains(((NodeImpl) handlerNode.getNodeContainer()).getMetaData("UniqueId"))) {
                    NodeInstance subProcessNodeInstance = ((NodeInstanceContainer) nodeInstanceContainer).getNodeInstance((Node) handlerNode.getNodeContainer());
                    compensationInstances.add(subProcessNodeInstance);
                    NodeInstance compensationHandlerNodeInstance = ((NodeInstanceContainer) subProcessNodeInstance).getNodeInstance(handlerNode);
                    compensationInstances.add(compensationHandlerNodeInstance);
                    EventSubProcessNodeInstance eventNodeInstance = (EventSubProcessNodeInstance) compensationHandlerNodeInstance;
                    eventNodeInstance.signalEvent("Compensation", compensationActivityRef);
                }
            }
            assert handlerNode instanceof BoundaryEventNode || handlerNode instanceof EventSubProcessNode : "Unexpected compensation handler node type : " + handlerNode.getClass().getSimpleName();
        } catch (Exception e) {
            throwWorkflowRuntimeException(nodeInstanceContainer, processInstance, "Unable to execute compensation.", e);
        }
    } else {
        Exception e = new IllegalArgumentException("Unsupported compensation handler: " + handler);
        throwWorkflowRuntimeException(nodeInstanceContainer, processInstance, e.getMessage(), e);
    }
}
Also used : NodeInstanceContainer(org.jbpm.workflow.instance.NodeInstanceContainer) NodeImpl(org.jbpm.workflow.core.impl.NodeImpl) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) Node(org.kie.api.definition.process.Node) WorkflowProcessInstanceImpl(org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl) CompensationHandler(org.jbpm.process.core.context.exception.CompensationHandler) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) WorkflowRuntimeException(org.jbpm.workflow.instance.WorkflowRuntimeException) EventSubProcessNodeInstance(org.jbpm.workflow.instance.node.EventSubProcessNodeInstance) List(java.util.List) EventSubProcessNodeInstance(org.jbpm.workflow.instance.node.EventSubProcessNodeInstance) NodeInstance(org.jbpm.workflow.instance.NodeInstance) EventNodeInstance(org.jbpm.workflow.instance.node.EventNodeInstance) EventNodeInstance(org.jbpm.workflow.instance.node.EventNodeInstance)

Example 32 with Node

use of org.kie.api.definition.process.Node in project jbpm by kiegroup.

the class JbpmJUnitTestCase method assertNumOfOutgoingConnections.

public void assertNumOfOutgoingConnections(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.getOutgoingConnections().size() != num) {
                fail("Expected outgoing connections: " + num + " - found " + node.getOutgoingConnections().size());
            } else {
                break;
            }
        }
    }
}
Also used : Node(org.kie.api.definition.process.Node) WorkflowProcessInstanceImpl(org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl)

Example 33 with Node

use of org.kie.api.definition.process.Node in project jbpm by kiegroup.

the class DefaultAuditEventBuilderImpl method buildEvent.

@Override
public AuditEvent buildEvent(ProcessNodeTriggeredEvent pnte) {
    ProcessInstanceImpl pi = (ProcessInstanceImpl) pnte.getProcessInstance();
    NodeInstanceImpl nodeInstance = (NodeInstanceImpl) pnte.getNodeInstance();
    Node node = nodeInstance.getNode();
    String nodeId = null;
    String nodeType = null;
    String nodeContainerId = null;
    if (node != null) {
        nodeId = (String) node.getMetaData().get("UniqueId");
        nodeType = node.getClass().getSimpleName();
        nodeContainerId = getNodeContainerId(node.getNodeContainer());
    } else {
        nodeId = Long.toString(nodeInstance.getNodeId());
        nodeType = (String) nodeInstance.getMetaData("NodeType");
    }
    NodeInstanceLog log = new NodeInstanceLog(NodeInstanceLog.TYPE_ENTER, pi.getId(), pi.getProcessId(), Long.toString(nodeInstance.getId()), nodeId, nodeInstance.getNodeName());
    if (nodeInstance instanceof WorkItemNodeInstance && ((WorkItemNodeInstance) nodeInstance).getWorkItem() != null) {
        log.setWorkItemId(((WorkItemNodeInstance) nodeInstance).getWorkItem().getId());
    }
    if (nodeInstance instanceof SubProcessNodeInstance) {
        log.setReferenceId(((SubProcessNodeInstance) nodeInstance).getProcessInstanceId());
    }
    String connection = (String) nodeInstance.getMetaData().get("IncomingConnection");
    log.setConnection(connection);
    log.setExternalId("" + ((KieSession) pnte.getKieRuntime()).getIdentifier());
    log.setNodeType(nodeType);
    log.setNodeContainerId(nodeContainerId);
    log.setDate(pnte.getEventDate());
    log.setSlaCompliance(nodeInstance.getSlaCompliance());
    log.setSlaDueDate(nodeInstance.getSlaDueDate());
    return log;
}
Also used : NodeInstanceImpl(org.jbpm.workflow.instance.impl.NodeInstanceImpl) SubProcessNodeInstance(org.jbpm.workflow.instance.node.SubProcessNodeInstance) NodeInstanceLog(org.jbpm.process.audit.NodeInstanceLog) ProcessInstanceImpl(org.jbpm.process.instance.impl.ProcessInstanceImpl) Node(org.kie.api.definition.process.Node) KieSession(org.kie.api.runtime.KieSession) WorkItemNodeInstance(org.jbpm.workflow.instance.node.WorkItemNodeInstance)

Example 34 with Node

use of org.kie.api.definition.process.Node in project jbpm by kiegroup.

the class DefaultAuditEventBuilderImpl method buildEvent.

@Override
public AuditEvent buildEvent(ProcessNodeLeftEvent pnle, Object log) {
    ProcessInstanceImpl pi = (ProcessInstanceImpl) pnle.getProcessInstance();
    NodeInstanceImpl nodeInstance = (NodeInstanceImpl) pnle.getNodeInstance();
    Node node = nodeInstance.getNode();
    String nodeId = null;
    String nodeType = null;
    String nodeContainerId = null;
    if (node != null) {
        nodeId = (String) node.getMetaData().get("UniqueId");
        nodeType = node.getClass().getSimpleName();
        nodeContainerId = getNodeContainerId(node.getNodeContainer());
    } else {
        nodeId = Long.toString(nodeInstance.getNodeId());
        nodeType = (String) nodeInstance.getMetaData("NodeType");
    }
    NodeInstanceLog logEvent = null;
    if (log != null) {
        logEvent = (NodeInstanceLog) log;
    } else {
        logEvent = new NodeInstanceLog(NodeInstanceLog.TYPE_EXIT, pi.getId(), pi.getProcessId(), Long.toString(nodeInstance.getId()), nodeId, nodeInstance.getNodeName());
    }
    if (nodeInstance instanceof WorkItemNodeInstance && ((WorkItemNodeInstance) nodeInstance).getWorkItem() != null) {
        logEvent.setWorkItemId(((WorkItemNodeInstance) nodeInstance).getWorkItem().getId());
    }
    if (nodeInstance instanceof SubProcessNodeInstance) {
        logEvent.setReferenceId(((SubProcessNodeInstance) nodeInstance).getProcessInstanceId());
    }
    String connection = (String) nodeInstance.getMetaData().get("OutgoingConnection");
    logEvent.setConnection(connection);
    logEvent.setExternalId("" + ((KieSession) pnle.getKieRuntime()).getIdentifier());
    logEvent.setNodeType(nodeType);
    logEvent.setNodeContainerId(nodeContainerId);
    logEvent.setDate(pnle.getEventDate());
    logEvent.setSlaCompliance(nodeInstance.getSlaCompliance());
    logEvent.setSlaDueDate(nodeInstance.getSlaDueDate());
    return logEvent;
}
Also used : NodeInstanceImpl(org.jbpm.workflow.instance.impl.NodeInstanceImpl) SubProcessNodeInstance(org.jbpm.workflow.instance.node.SubProcessNodeInstance) NodeInstanceLog(org.jbpm.process.audit.NodeInstanceLog) ProcessInstanceImpl(org.jbpm.process.instance.impl.ProcessInstanceImpl) Node(org.kie.api.definition.process.Node) KieSession(org.kie.api.runtime.KieSession) WorkItemNodeInstance(org.jbpm.workflow.instance.node.WorkItemNodeInstance)

Example 35 with Node

use of org.kie.api.definition.process.Node in project drools by kiegroup.

the class WorkingMemoryLogger method createNodeId.

private String createNodeId(NodeInstance nodeInstance) {
    Node node = nodeInstance.getNode();
    if (node == null) {
        return "";
    }
    Object uniqueIdObj = node.getMetaData().get("UniqueId");
    String nodeId;
    if (uniqueIdObj == null) {
        nodeId = "" + node.getId();
    } else {
        nodeId = (String) uniqueIdObj;
    }
    NodeContainer nodeContainer = node.getNodeContainer();
    while (nodeContainer != null) {
        if (nodeContainer instanceof Node) {
            node = (Node) nodeContainer;
            nodeContainer = node.getNodeContainer();
            // TODO fix this filter out hidden compositeNode inside ForEach node
            if (!(nodeContainer.getClass().getName().endsWith("ForEachNode"))) {
                nodeId = node.getId() + ":" + nodeId;
            }
        } else {
            break;
        }
    }
    return nodeId;
}
Also used : Node(org.kie.api.definition.process.Node) NodeContainer(org.kie.api.definition.process.NodeContainer)

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