Search in sources :

Example 6 with NodeInstanceImpl

use of org.jbpm.workflow.instance.impl.NodeInstanceImpl in project jbpm by kiegroup.

the class AbstractProtobufProcessInstanceMarshaller method readNodeInstance.

public NodeInstance readNodeInstance(MarshallerReaderContext context, NodeInstanceContainer nodeInstanceContainer, WorkflowProcessInstance processInstance) throws IOException {
    JBPMMessages.ProcessInstance.NodeInstance _node = (JBPMMessages.ProcessInstance.NodeInstance) context.parameterObject;
    NodeInstanceImpl nodeInstance = readNodeInstanceContent(_node, context, processInstance);
    nodeInstance.setNodeId(_node.getNodeId());
    nodeInstance.setId(_node.getId());
    nodeInstance.setNodeInstanceContainer(nodeInstanceContainer);
    nodeInstance.setProcessInstance((org.jbpm.workflow.instance.WorkflowProcessInstance) processInstance);
    nodeInstance.setLevel(_node.getLevel() == 0 ? 1 : _node.getLevel());
    nodeInstance.internalSetSlaCompliance(_node.getSlaCompliance());
    if (_node.getSlaDueDate() > 0) {
        nodeInstance.internalSetSlaDueDate(new Date(_node.getSlaDueDate()));
    }
    nodeInstance.internalSetSlaTimerId(_node.getSlaTimerId());
    switch(_node.getContent().getType()) {
        case COMPOSITE_CONTEXT_NODE:
        case DYNAMIC_NODE:
            if (_node.getContent().getComposite().getVariableCount() > 0) {
                Context variableScope = ((org.jbpm.process.core.Process) ((org.jbpm.process.instance.ProcessInstance) processInstance).getProcess()).getDefaultContext(VariableScope.VARIABLE_SCOPE);
                VariableScopeInstance variableScopeInstance = (VariableScopeInstance) ((CompositeContextNodeInstance) nodeInstance).getContextInstance(variableScope);
                for (JBPMMessages.Variable _variable : _node.getContent().getComposite().getVariableList()) {
                    try {
                        Object _value = ProtobufProcessMarshaller.unmarshallVariableValue(context, _variable);
                        variableScopeInstance.internalSetVariable(_variable.getName(), _value);
                    } catch (ClassNotFoundException e) {
                        throw new IllegalArgumentException("Could not reload variable " + _variable.getName());
                    }
                }
            }
            if (_node.getContent().getComposite().getIterationLevelsCount() > 0) {
                for (JBPMMessages.IterationLevel _level : _node.getContent().getComposite().getIterationLevelsList()) {
                    ((CompositeContextNodeInstance) nodeInstance).getIterationLevels().put(_level.getId(), _level.getLevel());
                }
            }
            for (JBPMMessages.ProcessInstance.NodeInstance _instance : _node.getContent().getComposite().getNodeInstanceList()) {
                context.parameterObject = _instance;
                readNodeInstance(context, (CompositeContextNodeInstance) nodeInstance, processInstance);
            }
            for (JBPMMessages.ProcessInstance.ExclusiveGroupInstance _excl : _node.getContent().getComposite().getExclusiveGroupList()) {
                ExclusiveGroupInstance exclusiveGroupInstance = new ExclusiveGroupInstance();
                ((CompositeContextNodeInstance) nodeInstance).addContextInstance(ExclusiveGroup.EXCLUSIVE_GROUP, exclusiveGroupInstance);
                for (Long nodeInstanceId : _excl.getGroupNodeInstanceIdList()) {
                    NodeInstance groupNodeInstance = ((org.jbpm.workflow.instance.NodeInstanceContainer) processInstance).getNodeInstance(nodeInstanceId, true);
                    if (groupNodeInstance == null) {
                        throw new IllegalArgumentException("Could not find node instance when deserializing exclusive group instance: " + nodeInstanceId);
                    }
                    exclusiveGroupInstance.addNodeInstance(groupNodeInstance);
                }
            }
            break;
        case FOR_EACH_NODE:
            for (JBPMMessages.ProcessInstance.NodeInstance _instance : _node.getContent().getForEach().getNodeInstanceList()) {
                context.parameterObject = _instance;
                readNodeInstance(context, (ForEachNodeInstance) nodeInstance, processInstance);
                VariableScopeInstance variableScopeInstance = (VariableScopeInstance) ((ForEachNodeInstance) nodeInstance).getContextInstance(VariableScope.VARIABLE_SCOPE);
                for (JBPMMessages.Variable _variable : _node.getContent().getForEach().getVariableList()) {
                    try {
                        Object _value = ProtobufProcessMarshaller.unmarshallVariableValue(context, _variable);
                        variableScopeInstance.internalSetVariable(_variable.getName(), _value);
                    } catch (ClassNotFoundException e) {
                        throw new IllegalArgumentException("Could not reload variable " + _variable.getName());
                    }
                }
                if (_node.getContent().getForEach().getIterationLevelsCount() > 0) {
                    for (JBPMMessages.IterationLevel _level : _node.getContent().getForEach().getIterationLevelsList()) {
                        ((ForEachNodeInstance) nodeInstance).getIterationLevels().put(_level.getId(), _level.getLevel());
                    }
                }
            }
            break;
        case EVENT_SUBPROCESS_NODE:
            for (JBPMMessages.ProcessInstance.NodeInstance _instance : _node.getContent().getComposite().getNodeInstanceList()) {
                context.parameterObject = _instance;
                readNodeInstance(context, (EventSubProcessNodeInstance) nodeInstance, processInstance);
                VariableScopeInstance variableScopeInstance = (VariableScopeInstance) ((EventSubProcessNodeInstance) nodeInstance).getContextInstance(VariableScope.VARIABLE_SCOPE);
                for (JBPMMessages.Variable _variable : _node.getContent().getComposite().getVariableList()) {
                    try {
                        Object _value = ProtobufProcessMarshaller.unmarshallVariableValue(context, _variable);
                        variableScopeInstance.internalSetVariable(_variable.getName(), _value);
                    } catch (ClassNotFoundException e) {
                        throw new IllegalArgumentException("Could not reload variable " + _variable.getName());
                    }
                }
            }
            break;
        default:
    }
    return nodeInstance;
}
Also used : NodeInstanceImpl(org.jbpm.workflow.instance.impl.NodeInstanceImpl) MarshallerWriteContext(org.drools.core.marshalling.impl.MarshallerWriteContext) MarshallerReaderContext(org.drools.core.marshalling.impl.MarshallerReaderContext) Context(org.jbpm.process.core.Context) SwimlaneContext(org.jbpm.process.core.context.swimlane.SwimlaneContext) ExclusiveGroupInstance(org.jbpm.process.instance.context.exclusive.ExclusiveGroupInstance) CompositeContextNodeInstance(org.jbpm.workflow.instance.node.CompositeContextNodeInstance) NodeInstanceContainer(org.kie.api.runtime.process.NodeInstanceContainer) Process(org.kie.api.definition.process.Process) Date(java.util.Date) VariableScopeInstance(org.jbpm.process.instance.context.variable.VariableScopeInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) RuleSetNodeInstance(org.jbpm.workflow.instance.node.RuleSetNodeInstance) EventSubProcessNodeInstance(org.jbpm.workflow.instance.node.EventSubProcessNodeInstance) StateNodeInstance(org.jbpm.workflow.instance.node.StateNodeInstance) TimerNodeInstance(org.jbpm.workflow.instance.node.TimerNodeInstance) CompositeContextNodeInstance(org.jbpm.workflow.instance.node.CompositeContextNodeInstance) DynamicNodeInstance(org.jbpm.workflow.instance.node.DynamicNodeInstance) AsyncEventNodeInstance(org.jbpm.workflow.instance.node.AsyncEventNodeInstance) SubProcessNodeInstance(org.jbpm.workflow.instance.node.SubProcessNodeInstance) NodeInstance(org.kie.api.runtime.process.NodeInstance) HumanTaskNodeInstance(org.jbpm.workflow.instance.node.HumanTaskNodeInstance) EventNodeInstance(org.jbpm.workflow.instance.node.EventNodeInstance) ForEachNodeInstance(org.jbpm.workflow.instance.node.ForEachNodeInstance) MilestoneNodeInstance(org.jbpm.workflow.instance.node.MilestoneNodeInstance) WorkItemNodeInstance(org.jbpm.workflow.instance.node.WorkItemNodeInstance)

Example 7 with NodeInstanceImpl

use of org.jbpm.workflow.instance.impl.NodeInstanceImpl in project jbpm by kiegroup.

the class MigrateProcessInstanceCommand method updateNodeInstances.

private void updateNodeInstances(NodeInstanceContainer nodeInstanceContainer, Map<String, Long> nodeMapping) {
    for (NodeInstance nodeInstance : nodeInstanceContainer.getNodeInstances()) {
        String oldNodeId = ((NodeImpl) ((org.jbpm.workflow.instance.NodeInstance) nodeInstance).getNode()).getUniqueId();
        Long newNodeId = nodeMapping.get(oldNodeId);
        if (newNodeId == null) {
            newNodeId = nodeInstance.getNodeId();
        }
        ((NodeInstanceImpl) nodeInstance).setNodeId(newNodeId);
        if (nodeInstance instanceof NodeInstanceContainer) {
            updateNodeInstances((NodeInstanceContainer) nodeInstance, nodeMapping);
        }
    }
}
Also used : NodeInstanceImpl(org.jbpm.workflow.instance.impl.NodeInstanceImpl) NodeInstanceContainer(org.jbpm.workflow.instance.NodeInstanceContainer) NodeImpl(org.jbpm.workflow.core.impl.NodeImpl) NodeInstance(org.kie.api.runtime.process.NodeInstance)

Example 8 with NodeInstanceImpl

use of org.jbpm.workflow.instance.impl.NodeInstanceImpl in project jbpm by kiegroup.

the class DefaultAuditEventBuilderImpl method buildEvent.

@Override
public AuditEvent buildEvent(ProcessNodeTriggeredEvent pnte, Object log) {
    NodeInstanceImpl nodeInstance = (NodeInstanceImpl) pnte.getNodeInstance();
    NodeInstanceLog logEvent = null;
    if (log != null) {
        logEvent = (NodeInstanceLog) log;
        if (nodeInstance instanceof WorkItemNodeInstance && ((WorkItemNodeInstance) nodeInstance).getWorkItem() != null) {
            logEvent.setWorkItemId(((WorkItemNodeInstance) nodeInstance).getWorkItem().getId());
        }
        if (nodeInstance instanceof SubProcessNodeInstance) {
            logEvent.setReferenceId(((SubProcessNodeInstance) nodeInstance).getProcessInstanceId());
        }
        return logEvent;
    }
    return null;
}
Also used : NodeInstanceImpl(org.jbpm.workflow.instance.impl.NodeInstanceImpl) SubProcessNodeInstance(org.jbpm.workflow.instance.node.SubProcessNodeInstance) NodeInstanceLog(org.jbpm.process.audit.NodeInstanceLog) WorkItemNodeInstance(org.jbpm.workflow.instance.node.WorkItemNodeInstance)

Example 9 with NodeInstanceImpl

use of org.jbpm.workflow.instance.impl.NodeInstanceImpl 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 10 with NodeInstanceImpl

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

Aggregations

NodeInstanceImpl (org.jbpm.workflow.instance.impl.NodeInstanceImpl)20 NodeInstance (org.kie.api.runtime.process.NodeInstance)9 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)7 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)7 HashMap (java.util.HashMap)6 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)4 NodeInstanceLog (org.jbpm.process.audit.NodeInstanceLog)4 SubProcessNodeInstance (org.jbpm.workflow.instance.node.SubProcessNodeInstance)4 WorkItemNodeInstance (org.jbpm.workflow.instance.node.WorkItemNodeInstance)4 Test (org.junit.Test)4 KieBase (org.kie.api.KieBase)4 Node (org.kie.api.definition.process.Node)4 NodeImpl (org.jbpm.workflow.core.impl.NodeImpl)3 CompositeContextNodeInstance (org.jbpm.workflow.instance.node.CompositeContextNodeInstance)3 ForEachNodeInstance (org.jbpm.workflow.instance.node.ForEachNodeInstance)3 HumanTaskNodeInstance (org.jbpm.workflow.instance.node.HumanTaskNodeInstance)3 TimerNodeInstance (org.jbpm.workflow.instance.node.TimerNodeInstance)3 DefaultProcessEventListener (org.kie.api.event.process.DefaultProcessEventListener)3 ProcessNodeTriggeredEvent (org.kie.api.event.process.ProcessNodeTriggeredEvent)3 KieSession (org.kie.api.runtime.KieSession)3