Search in sources :

Example 6 with WorkflowProcessInstanceImpl

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

the class NotifyParentCaseEventListener method afterProcessCompleted.

@Override
public void afterProcessCompleted(ProcessCompletedEvent event) {
    CaseFileInstance caseFile = getCaseFile((KieSession) event.getKieRuntime());
    if (caseFile != null) {
        String caseId = ((WorkflowProcessInstanceImpl) event.getProcessInstance()).getCorrelationKey();
        if (caseFile.getCaseId().equals(caseId)) {
            logger.debug("Process instance {} that represents main case instance {} has completed/was aborted, notify parent if exists", event.getProcessInstance().getId(), caseId);
            CaseEvent caseEvent = null;
            if (event.getProcessInstance().getState() == ProcessInstance.STATE_COMPLETED) {
                caseEvent = new CaseCloseEvent(identityProvider.getName(), caseId, caseFile, "");
            } else {
                caseEvent = new CaseCancelEvent(identityProvider.getName(), caseId, caseFile, Arrays.asList(event.getProcessInstance().getId()));
            }
            notifyParentOnCompletion(caseEvent);
        }
    }
}
Also used : CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseCancelEvent(org.jbpm.casemgmt.api.event.CaseCancelEvent) WorkflowProcessInstanceImpl(org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl) CaseEvent(org.jbpm.casemgmt.api.event.CaseEvent) CaseCloseEvent(org.jbpm.casemgmt.api.event.CaseCloseEvent)

Example 7 with WorkflowProcessInstanceImpl

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

the class ProcessInstanceInfo method transform.

public void transform() {
    // if (processInstance == null) {
    // return;
    // }
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    boolean variablesChanged = false;
    try {
        ProcessMarshallerWriteContext context = new ProcessMarshallerWriteContext(baos, null, null, null, null, this.env);
        context.setProcessInstanceId(processInstance.getId());
        context.setState(processInstance.getState() == ProcessInstance.STATE_ACTIVE ? ProcessMarshallerWriteContext.STATE_ACTIVE : ProcessMarshallerWriteContext.STATE_COMPLETED);
        String processType = ((ProcessInstanceImpl) processInstance).getProcess().getType();
        saveProcessInstanceType(context, processInstance, processType);
        ProcessInstanceMarshaller marshaller = ProcessMarshallerRegistry.INSTANCE.getMarshaller(processType);
        Object result = marshaller.writeProcessInstance(context, processInstance);
        if (marshaller instanceof ProtobufRuleFlowProcessInstanceMarshaller && result != null) {
            JBPMMessages.ProcessInstance _instance = (JBPMMessages.ProcessInstance) result;
            PersisterHelper.writeToStreamWithHeader(context, _instance);
        }
        context.close();
    } catch (IOException e) {
        throw new IllegalArgumentException("IOException while storing process instance " + processInstance.getId() + ": " + e.getMessage(), e);
    }
    byte[] newByteArray = baos.toByteArray();
    if (variablesChanged || !Arrays.equals(newByteArray, processInstanceByteArray)) {
        this.state = processInstance.getState();
        this.lastModificationDate = new Date();
        this.processInstanceByteArray = newByteArray;
        this.eventTypes.clear();
        for (String type : processInstance.getEventTypes()) {
            eventTypes.add(type);
        }
    }
    if (!processInstance.getProcessId().equals(this.processId)) {
        this.processId = processInstance.getProcessId();
    }
    ((WorkflowProcessInstanceImpl) processInstance).setPersisted(true);
}
Also used : ProtobufRuleFlowProcessInstanceMarshaller(org.jbpm.marshalling.impl.ProtobufRuleFlowProcessInstanceMarshaller) ProcessInstanceMarshaller(org.jbpm.marshalling.impl.ProcessInstanceMarshaller) WorkflowProcessInstanceImpl(org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl) JBPMMessages(org.jbpm.marshalling.impl.JBPMMessages) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Date(java.util.Date) ProtobufRuleFlowProcessInstanceMarshaller(org.jbpm.marshalling.impl.ProtobufRuleFlowProcessInstanceMarshaller) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) PersistentProcessInstance(org.jbpm.persistence.api.PersistentProcessInstance) ProcessMarshallerWriteContext(org.drools.core.marshalling.impl.ProcessMarshallerWriteContext)

Example 8 with WorkflowProcessInstanceImpl

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

the class ProcessInstanceInfo method getProcessInstance.

public ProcessInstance getProcessInstance(InternalKnowledgeRuntime kruntime, Environment env, boolean readOnly) {
    this.env = env;
    if (processInstance == null) {
        try {
            ByteArrayInputStream bais = new ByteArrayInputStream(processInstanceByteArray);
            MarshallerReaderContext context = new MarshallerReaderContext(bais, (InternalKnowledgeBase) kruntime.getKieBase(), null, null, ProtobufMarshaller.TIMER_READERS, this.env);
            ProcessInstanceMarshaller marshaller = getMarshallerFromContext(context);
            context.wm = ((StatefulKnowledgeSessionImpl) kruntime).getInternalWorkingMemory();
            processInstance = marshaller.readProcessInstance(context);
            ((WorkflowProcessInstanceImpl) processInstance).setPersisted(false);
            if (readOnly) {
                ((WorkflowProcessInstanceImpl) processInstance).disconnect();
            }
            context.close();
        } catch (IOException e) {
            e.printStackTrace();
            throw new IllegalArgumentException("IOException while loading process instance: " + e.getMessage(), e);
        }
    }
    ((WorkflowProcessInstanceImpl) processInstance).internalSetStartDate(this.startDate);
    return processInstance;
}
Also used : ProtobufRuleFlowProcessInstanceMarshaller(org.jbpm.marshalling.impl.ProtobufRuleFlowProcessInstanceMarshaller) ProcessInstanceMarshaller(org.jbpm.marshalling.impl.ProcessInstanceMarshaller) ByteArrayInputStream(java.io.ByteArrayInputStream) MarshallerReaderContext(org.drools.core.marshalling.impl.MarshallerReaderContext) WorkflowProcessInstanceImpl(org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl) IOException(java.io.IOException)

Example 9 with WorkflowProcessInstanceImpl

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

the class JbpmBpmn2TestCase 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 10 with WorkflowProcessInstanceImpl

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

the class JbpmBpmn2TestCase method assertProcessVarExists.

public void assertProcessVarExists(ProcessInstance process, String... processVarNames) {
    WorkflowProcessInstanceImpl instance = (WorkflowProcessInstanceImpl) process;
    List<String> names = new ArrayList<String>();
    for (String nodeName : processVarNames) {
        names.add(nodeName);
    }
    for (String pvar : instance.getVariables().keySet()) {
        if (names.contains(pvar)) {
            names.remove(pvar);
        }
    }
    if (!names.isEmpty()) {
        String s = names.get(0);
        for (int i = 1; i < names.size(); i++) {
            s += ", " + names.get(i);
        }
        fail("Process Variable(s) do not exist: " + s);
    }
}
Also used : WorkflowProcessInstanceImpl(org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl) ArrayList(java.util.ArrayList)

Aggregations

WorkflowProcessInstanceImpl (org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl)53 NodeInstance (org.kie.api.runtime.process.NodeInstance)17 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)16 ArrayList (java.util.ArrayList)14 HashMap (java.util.HashMap)11 WorkItemNodeInstance (org.jbpm.workflow.instance.node.WorkItemNodeInstance)11 Test (org.junit.Test)10 Node (org.kie.api.definition.process.Node)10 KieSession (org.kie.api.runtime.KieSession)9 Map (java.util.Map)7 RegistryContext (org.drools.core.command.impl.RegistryContext)6 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)6 Process (org.kie.api.definition.process.Process)6 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)5 VariableScopeInstance (org.jbpm.process.instance.context.variable.VariableScopeInstance)5 DynamicNodeInstance (org.jbpm.workflow.instance.node.DynamicNodeInstance)5 Person (com.salaboy.model.Person)4 KnowledgeBase (org.drools.KnowledgeBase)4 KnowledgeBuilder (org.drools.builder.KnowledgeBuilder)4 KnowledgeBuilderError (org.drools.builder.KnowledgeBuilderError)4