Search in sources :

Example 1 with SubProcessNodeInstance

use of org.jbpm.workflow.instance.node.SubProcessNodeInstance in project jbpm by kiegroup.

the class SingleSessionCommandServiceTest method testPersistenceSubProcess.

@Test
public void testPersistenceSubProcess() {
    setUp();
    Properties properties = new Properties();
    properties.setProperty("drools.commandService", PersistableRunner.class.getName());
    properties.setProperty("drools.processInstanceManagerFactory", JPAProcessInstanceManagerFactory.class.getName());
    properties.setProperty("drools.workItemManagerFactory", JPAWorkItemManagerFactory.class.getName());
    properties.setProperty("drools.processSignalManagerFactory", JPASignalManagerFactory.class.getName());
    properties.setProperty("drools.timerService", JpaJDKTimerService.class.getName());
    SessionConfiguration config = SessionConfiguration.newInstance(properties);
    InternalKnowledgeBase ruleBase = KnowledgeBaseFactory.newKnowledgeBase();
    KiePackage pkg = getProcessSubProcess();
    ruleBase.addPackages((Collection) Arrays.asList(pkg));
    PersistableRunner service = new PersistableRunner(ruleBase, config, env);
    Long sessionId = service.getSessionId();
    StartProcessCommand startProcessCommand = new StartProcessCommand();
    startProcessCommand.setProcessId("org.drools.test.TestProcess");
    RuleFlowProcessInstance processInstance = (RuleFlowProcessInstance) service.execute(startProcessCommand);
    logger.info("Started process instance {}", processInstance.getId());
    long processInstanceId = processInstance.getId();
    TestWorkItemHandler handler = TestWorkItemHandler.getInstance();
    WorkItem workItem = handler.getWorkItem();
    assertNotNull(workItem);
    service.dispose();
    service = new PersistableRunner(sessionId, ruleBase, config, env);
    GetProcessInstanceCommand getProcessInstanceCommand = new GetProcessInstanceCommand();
    getProcessInstanceCommand.setProcessInstanceId(processInstanceId);
    processInstance = (RuleFlowProcessInstance) service.execute(getProcessInstanceCommand);
    assertNotNull(processInstance);
    Collection<NodeInstance> nodeInstances = processInstance.getNodeInstances();
    assertEquals(1, nodeInstances.size());
    SubProcessNodeInstance subProcessNodeInstance = (SubProcessNodeInstance) nodeInstances.iterator().next();
    long subProcessInstanceId = subProcessNodeInstance.getProcessInstanceId();
    getProcessInstanceCommand = new GetProcessInstanceCommand();
    getProcessInstanceCommand.setProcessInstanceId(subProcessInstanceId);
    RuleFlowProcessInstance subProcessInstance = (RuleFlowProcessInstance) service.execute(getProcessInstanceCommand);
    assertNotNull(subProcessInstance);
    service.dispose();
    service = new PersistableRunner(sessionId, ruleBase, config, env);
    CompleteWorkItemCommand completeWorkItemCommand = new CompleteWorkItemCommand();
    completeWorkItemCommand.setWorkItemId(workItem.getId());
    service.execute(completeWorkItemCommand);
    service.dispose();
    service = new PersistableRunner(sessionId, ruleBase, config, env);
    getProcessInstanceCommand = new GetProcessInstanceCommand();
    getProcessInstanceCommand.setProcessInstanceId(subProcessInstanceId);
    subProcessInstance = (RuleFlowProcessInstance) service.execute(getProcessInstanceCommand);
    assertNull(subProcessInstance);
    getProcessInstanceCommand = new GetProcessInstanceCommand();
    getProcessInstanceCommand.setProcessInstanceId(processInstanceId);
    processInstance = (RuleFlowProcessInstance) service.execute(getProcessInstanceCommand);
    assertNull(processInstance);
    service.dispose();
}
Also used : TestWorkItemHandler(org.jbpm.persistence.session.objects.TestWorkItemHandler) RuleFlowProcessInstance(org.jbpm.ruleflow.instance.RuleFlowProcessInstance) JPASignalManagerFactory(org.jbpm.persistence.processinstance.JPASignalManagerFactory) CompleteWorkItemCommand(org.drools.core.command.runtime.process.CompleteWorkItemCommand) Properties(java.util.Properties) JPAWorkItemManagerFactory(org.drools.persistence.jpa.processinstance.JPAWorkItemManagerFactory) StartProcessCommand(org.drools.core.command.runtime.process.StartProcessCommand) WorkItem(org.kie.api.runtime.process.WorkItem) PersistableRunner(org.drools.persistence.PersistableRunner) GetProcessInstanceCommand(org.drools.core.command.runtime.process.GetProcessInstanceCommand) SubProcessNodeInstance(org.jbpm.workflow.instance.node.SubProcessNodeInstance) KiePackage(org.kie.api.definition.KiePackage) JPAProcessInstanceManagerFactory(org.jbpm.persistence.processinstance.JPAProcessInstanceManagerFactory) SubProcessNodeInstance(org.jbpm.workflow.instance.node.SubProcessNodeInstance) NodeInstance(org.kie.api.runtime.process.NodeInstance) SessionConfiguration(org.drools.core.SessionConfiguration) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) JpaJDKTimerService(org.drools.persistence.jpa.JpaJDKTimerService) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest) Test(org.junit.Test)

Example 2 with SubProcessNodeInstance

use of org.jbpm.workflow.instance.node.SubProcessNodeInstance 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 3 with SubProcessNodeInstance

use of org.jbpm.workflow.instance.node.SubProcessNodeInstance 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 4 with SubProcessNodeInstance

use of org.jbpm.workflow.instance.node.SubProcessNodeInstance 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 5 with SubProcessNodeInstance

use of org.jbpm.workflow.instance.node.SubProcessNodeInstance in project jbpm by kiegroup.

the class AbstractProtobufProcessInstanceMarshaller method readNodeInstanceContent.

protected NodeInstanceImpl readNodeInstanceContent(JBPMMessages.ProcessInstance.NodeInstance _node, MarshallerReaderContext context, WorkflowProcessInstance processInstance) throws IOException {
    NodeInstanceImpl nodeInstance = null;
    NodeInstanceContent _content = _node.getContent();
    switch(_content.getType()) {
        case RULE_SET_NODE:
            nodeInstance = new RuleSetNodeInstance();
            ((RuleSetNodeInstance) nodeInstance).setRuleFlowGroup(_content.getRuleSet().getRuleFlowGroup());
            if (_content.getRuleSet().getTimerInstanceIdCount() > 0) {
                List<Long> timerInstances = new ArrayList<Long>();
                for (Long _timerId : _content.getRuleSet().getTimerInstanceIdList()) {
                    timerInstances.add(_timerId);
                }
                ((RuleSetNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
            }
            if (_content.getRuleSet().getMapEntryCount() > 0) {
                Map<String, FactHandle> factInfo = new HashMap<String, FactHandle>();
                for (TextMapEntry entry : _content.getRuleSet().getMapEntryList()) {
                    factInfo.put(entry.getName(), DefaultFactHandle.createFromExternalFormat(entry.getValue()));
                }
                ((RuleSetNodeInstance) nodeInstance).setFactHandles(factInfo);
            }
            break;
        case HUMAN_TASK_NODE:
            nodeInstance = new HumanTaskNodeInstance();
            ((HumanTaskNodeInstance) nodeInstance).internalSetWorkItemId(_content.getHumanTask().getWorkItemId());
            if (_content.getHumanTask().getTimerInstanceIdCount() > 0) {
                List<Long> timerInstances = new ArrayList<Long>();
                for (Long _timerId : _content.getHumanTask().getTimerInstanceIdList()) {
                    timerInstances.add(_timerId);
                }
                ((HumanTaskNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
            }
            break;
        case WORK_ITEM_NODE:
            nodeInstance = new WorkItemNodeInstance();
            ((WorkItemNodeInstance) nodeInstance).internalSetWorkItemId(_content.getWorkItem().getWorkItemId());
            if (_content.getWorkItem().getTimerInstanceIdCount() > 0) {
                List<Long> timerInstances = new ArrayList<Long>();
                for (Long _timerId : _content.getWorkItem().getTimerInstanceIdList()) {
                    timerInstances.add(_timerId);
                }
                ((WorkItemNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
            }
            break;
        case SUBPROCESS_NODE:
            nodeInstance = new SubProcessNodeInstance();
            ((SubProcessNodeInstance) nodeInstance).internalSetProcessInstanceId(_content.getSubProcess().getProcessInstanceId());
            if (_content.getSubProcess().getTimerInstanceIdCount() > 0) {
                List<Long> timerInstances = new ArrayList<Long>();
                for (Long _timerId : _content.getSubProcess().getTimerInstanceIdList()) {
                    timerInstances.add(_timerId);
                }
                ((SubProcessNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
            }
            break;
        case MILESTONE_NODE:
            nodeInstance = new MilestoneNodeInstance();
            if (_content.getMilestone().getTimerInstanceIdCount() > 0) {
                List<Long> timerInstances = new ArrayList<Long>();
                for (Long _timerId : _content.getMilestone().getTimerInstanceIdList()) {
                    timerInstances.add(_timerId);
                }
                ((MilestoneNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
            }
            break;
        case TIMER_NODE:
            nodeInstance = new TimerNodeInstance();
            ((TimerNodeInstance) nodeInstance).internalSetTimerId(_content.getTimer().getTimerId());
            break;
        case ASYNC_EVENT_NODE:
            nodeInstance = new AsyncEventNodeInstance();
            ((AsyncEventNodeInstance) nodeInstance).setEventType(_content.getAsyncEvent().getEventType());
            break;
        case EVENT_NODE:
            nodeInstance = new EventNodeInstance();
            break;
        case JOIN_NODE:
            nodeInstance = new JoinInstance();
            if (_content.getJoin().getTriggerCount() > 0) {
                Map<Long, Integer> triggers = new HashMap<Long, Integer>();
                for (JBPMMessages.ProcessInstance.NodeInstanceContent.JoinNode.JoinTrigger _join : _content.getJoin().getTriggerList()) {
                    triggers.put(_join.getNodeId(), _join.getCounter());
                }
                ((JoinInstance) nodeInstance).internalSetTriggers(triggers);
            }
            break;
        case FOR_EACH_NODE:
            nodeInstance = new ForEachNodeInstance();
            break;
        case COMPOSITE_CONTEXT_NODE:
            nodeInstance = new CompositeContextNodeInstance();
            if (_content.getComposite().getTimerInstanceIdCount() > 0) {
                List<Long> timerInstances = new ArrayList<Long>();
                for (Long _timerId : _content.getComposite().getTimerInstanceIdList()) {
                    timerInstances.add(_timerId);
                }
                ((CompositeContextNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
            }
            break;
        case DYNAMIC_NODE:
            nodeInstance = new DynamicNodeInstance();
            if (_content.getComposite().getTimerInstanceIdCount() > 0) {
                List<Long> timerInstances = new ArrayList<Long>();
                for (Long _timerId : _content.getComposite().getTimerInstanceIdList()) {
                    timerInstances.add(_timerId);
                }
                ((CompositeContextNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
            }
            break;
        case STATE_NODE:
            nodeInstance = new StateNodeInstance();
            if (_content.getState().getTimerInstanceIdCount() > 0) {
                List<Long> timerInstances = new ArrayList<Long>();
                for (Long _timerId : _content.getState().getTimerInstanceIdList()) {
                    timerInstances.add(_timerId);
                }
                ((CompositeContextNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
            }
            break;
        case EVENT_SUBPROCESS_NODE:
            nodeInstance = new EventSubProcessNodeInstance();
            if (_content.getComposite().getTimerInstanceIdCount() > 0) {
                List<Long> timerInstances = new ArrayList<Long>();
                for (Long _timerId : _content.getComposite().getTimerInstanceIdList()) {
                    timerInstances.add(_timerId);
                }
                ((CompositeContextNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
            }
            break;
        default:
            throw new IllegalArgumentException("Unknown node type: " + _content.getType());
    }
    return nodeInstance;
}
Also used : AsyncEventNodeInstance(org.jbpm.workflow.instance.node.AsyncEventNodeInstance) JoinInstance(org.jbpm.workflow.instance.node.JoinInstance) DynamicNodeInstance(org.jbpm.workflow.instance.node.DynamicNodeInstance) FactHandle(org.kie.api.runtime.rule.FactHandle) DefaultFactHandle(org.drools.core.common.DefaultFactHandle) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HumanTaskNodeInstance(org.jbpm.workflow.instance.node.HumanTaskNodeInstance) NodeInstanceContent(org.jbpm.marshalling.impl.JBPMMessages.ProcessInstance.NodeInstanceContent) RuleSetNodeInstance(org.jbpm.workflow.instance.node.RuleSetNodeInstance) NodeInstanceImpl(org.jbpm.workflow.instance.impl.NodeInstanceImpl) MilestoneNodeInstance(org.jbpm.workflow.instance.node.MilestoneNodeInstance) StateNodeInstance(org.jbpm.workflow.instance.node.StateNodeInstance) CompositeContextNodeInstance(org.jbpm.workflow.instance.node.CompositeContextNodeInstance) TextMapEntry(org.jbpm.marshalling.impl.JBPMMessages.ProcessInstance.NodeInstanceContent.RuleSetNode.TextMapEntry) WorkItemNodeInstance(org.jbpm.workflow.instance.node.WorkItemNodeInstance) EventSubProcessNodeInstance(org.jbpm.workflow.instance.node.EventSubProcessNodeInstance) EventSubProcessNodeInstance(org.jbpm.workflow.instance.node.EventSubProcessNodeInstance) SubProcessNodeInstance(org.jbpm.workflow.instance.node.SubProcessNodeInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) ForEachNodeInstance(org.jbpm.workflow.instance.node.ForEachNodeInstance) TimerNodeInstance(org.jbpm.workflow.instance.node.TimerNodeInstance) AsyncEventNodeInstance(org.jbpm.workflow.instance.node.AsyncEventNodeInstance) EventNodeInstance(org.jbpm.workflow.instance.node.EventNodeInstance)

Aggregations

SubProcessNodeInstance (org.jbpm.workflow.instance.node.SubProcessNodeInstance)6 WorkItemNodeInstance (org.jbpm.workflow.instance.node.WorkItemNodeInstance)5 NodeInstanceImpl (org.jbpm.workflow.instance.impl.NodeInstanceImpl)4 NodeInstanceLog (org.jbpm.process.audit.NodeInstanceLog)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 DefaultFactHandle (org.drools.core.common.DefaultFactHandle)2 NodeInstanceContent (org.jbpm.marshalling.impl.JBPMMessages.ProcessInstance.NodeInstanceContent)2 TextMapEntry (org.jbpm.marshalling.impl.JBPMMessages.ProcessInstance.NodeInstanceContent.RuleSetNode.TextMapEntry)2 ProcessInstanceImpl (org.jbpm.process.instance.impl.ProcessInstanceImpl)2 AsyncEventNodeInstance (org.jbpm.workflow.instance.node.AsyncEventNodeInstance)2 CompositeContextNodeInstance (org.jbpm.workflow.instance.node.CompositeContextNodeInstance)2 DynamicNodeInstance (org.jbpm.workflow.instance.node.DynamicNodeInstance)2 EventNodeInstance (org.jbpm.workflow.instance.node.EventNodeInstance)2 EventSubProcessNodeInstance (org.jbpm.workflow.instance.node.EventSubProcessNodeInstance)2 ForEachNodeInstance (org.jbpm.workflow.instance.node.ForEachNodeInstance)2 HumanTaskNodeInstance (org.jbpm.workflow.instance.node.HumanTaskNodeInstance)2 JoinInstance (org.jbpm.workflow.instance.node.JoinInstance)2 MilestoneNodeInstance (org.jbpm.workflow.instance.node.MilestoneNodeInstance)2 RuleSetNodeInstance (org.jbpm.workflow.instance.node.RuleSetNodeInstance)2