Search in sources :

Example 1 with ProcessInstanceView

use of org.jbpm.persistence.api.integration.model.ProcessInstanceView in project jbpm by kiegroup.

the class JPAProcessInstanceManager method addProcessInstance.

public void addProcessInstance(ProcessInstance processInstance, CorrelationKey correlationKey) {
    ProcessInstanceInfo processInstanceInfo = new ProcessInstanceInfo(processInstance, this.kruntime.getEnvironment());
    ProcessPersistenceContext context = ((ProcessPersistenceContextManager) this.kruntime.getEnvironment().get(EnvironmentName.PERSISTENCE_CONTEXT_MANAGER)).getProcessPersistenceContext();
    processInstanceInfo = (ProcessInstanceInfo) context.persist(processInstanceInfo);
    ((org.jbpm.process.instance.ProcessInstance) processInstance).setId(processInstanceInfo.getId());
    processInstanceInfo.updateLastReadDate();
    // generate correlation key if not given which is same as process instance id to keep uniqueness
    if (correlationKey == null) {
        correlationKey = new CorrelationKeyInfo();
        ((CorrelationKeyInfo) correlationKey).addProperty(new CorrelationPropertyInfo(null, processInstanceInfo.getId().toString()));
        ((org.jbpm.process.instance.ProcessInstance) processInstance).getMetaData().put("CorrelationKey", correlationKey);
    }
    CorrelationKeyInfo correlationKeyInfo = (CorrelationKeyInfo) correlationKey;
    correlationKeyInfo.setProcessInstanceId(processInstanceInfo.getId());
    context.persist(correlationKeyInfo);
    internalAddProcessInstance(processInstance);
    EventManagerProvider.getInstance().get().create(new ProcessInstanceView(processInstance));
}
Also used : CorrelationPropertyInfo(org.jbpm.persistence.correlation.CorrelationPropertyInfo) CorrelationKeyInfo(org.jbpm.persistence.correlation.CorrelationKeyInfo) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) ProcessPersistenceContextManager(org.jbpm.persistence.api.ProcessPersistenceContextManager) ProcessPersistenceContext(org.jbpm.persistence.api.ProcessPersistenceContext) ProcessInstanceView(org.jbpm.persistence.api.integration.model.ProcessInstanceView)

Example 2 with ProcessInstanceView

use of org.jbpm.persistence.api.integration.model.ProcessInstanceView in project jbpm by kiegroup.

the class JPAProcessInstanceManager method removeProcessInstance.

public void removeProcessInstance(ProcessInstance processInstance) {
    ProcessPersistenceContext context = ((ProcessPersistenceContextManager) this.kruntime.getEnvironment().get(EnvironmentName.PERSISTENCE_CONTEXT_MANAGER)).getProcessPersistenceContext();
    ProcessInstanceInfo processInstanceInfo = (ProcessInstanceInfo) context.findProcessInstanceInfo(processInstance.getId());
    if (processInstanceInfo != null) {
        context.remove(processInstanceInfo);
    }
    internalRemoveProcessInstance(processInstance);
    EventManagerProvider.getInstance().get().delete(new ProcessInstanceView(processInstance));
}
Also used : ProcessPersistenceContextManager(org.jbpm.persistence.api.ProcessPersistenceContextManager) ProcessPersistenceContext(org.jbpm.persistence.api.ProcessPersistenceContext) ProcessInstanceView(org.jbpm.persistence.api.integration.model.ProcessInstanceView)

Example 3 with ProcessInstanceView

use of org.jbpm.persistence.api.integration.model.ProcessInstanceView in project jbpm by kiegroup.

the class JPAProcessInstanceManager method getProcessInstance.

public ProcessInstance getProcessInstance(long id, boolean readOnly) {
    InternalRuntimeManager manager = (InternalRuntimeManager) kruntime.getEnvironment().get(EnvironmentName.RUNTIME_MANAGER);
    if (manager != null) {
        manager.validate((KieSession) kruntime, ProcessInstanceIdContext.get(id));
    }
    TransactionManager txm = (TransactionManager) this.kruntime.getEnvironment().get(EnvironmentName.TRANSACTION_MANAGER);
    org.jbpm.process.instance.ProcessInstance processInstance = null;
    processInstance = (org.jbpm.process.instance.ProcessInstance) this.processInstances.get(id);
    if (processInstance != null) {
        if (((WorkflowProcessInstanceImpl) processInstance).isPersisted() && !readOnly) {
            ProcessPersistenceContextManager ppcm = (ProcessPersistenceContextManager) this.kruntime.getEnvironment().get(EnvironmentName.PERSISTENCE_CONTEXT_MANAGER);
            ppcm.beginCommandScopedEntityManager();
            ProcessPersistenceContext context = ppcm.getProcessPersistenceContext();
            ProcessInstanceInfo processInstanceInfo = (ProcessInstanceInfo) context.findProcessInstanceInfo(id);
            if (processInstanceInfo == null) {
                return null;
            }
            TransactionManagerHelper.addToUpdatableSet(txm, processInstanceInfo);
            processInstanceInfo.updateLastReadDate();
            EventManagerProvider.getInstance().get().update(new ProcessInstanceView(processInstance));
        }
        return processInstance;
    }
    // Make sure that the cmd scoped entity manager has started
    ProcessPersistenceContextManager ppcm = (ProcessPersistenceContextManager) this.kruntime.getEnvironment().get(EnvironmentName.PERSISTENCE_CONTEXT_MANAGER);
    ppcm.beginCommandScopedEntityManager();
    ProcessPersistenceContext context = ppcm.getProcessPersistenceContext();
    ProcessInstanceInfo processInstanceInfo = (ProcessInstanceInfo) context.findProcessInstanceInfo(id);
    if (processInstanceInfo == null) {
        return null;
    }
    processInstance = (org.jbpm.process.instance.ProcessInstance) processInstanceInfo.getProcessInstance(kruntime, this.kruntime.getEnvironment(), readOnly);
    if (!readOnly) {
        processInstanceInfo.updateLastReadDate();
        TransactionManagerHelper.addToUpdatableSet(txm, processInstanceInfo);
        EventManagerProvider.getInstance().get().update(new ProcessInstanceView(processInstance));
    }
    if (((ProcessInstanceImpl) processInstance).getProcessXml() == null) {
        Process process = kruntime.getKieBase().getProcess(processInstance.getProcessId());
        if (process == null) {
            throw new IllegalArgumentException("Could not find process " + processInstance.getProcessId());
        }
        processInstance.setProcess(process);
    }
    if (processInstance.getKnowledgeRuntime() == null) {
        Long parentProcessInstanceId = (Long) ((ProcessInstanceImpl) processInstance).getMetaData().get("ParentProcessInstanceId");
        if (parentProcessInstanceId != null) {
            kruntime.getProcessInstance(parentProcessInstanceId);
        }
        processInstance.setKnowledgeRuntime(kruntime);
        ((ProcessInstanceImpl) processInstance).reconnect();
        if (readOnly) {
            internalRemoveProcessInstance(processInstance);
        }
    }
    return processInstance;
}
Also used : InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) WorkflowProcessInstanceImpl(org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl) ProcessInstanceImpl(org.jbpm.process.instance.impl.ProcessInstanceImpl) Process(org.kie.api.definition.process.Process) ProcessPersistenceContext(org.jbpm.persistence.api.ProcessPersistenceContext) ProcessInstanceView(org.jbpm.persistence.api.integration.model.ProcessInstanceView) TransactionManager(org.drools.persistence.api.TransactionManager) ProcessPersistenceContextManager(org.jbpm.persistence.api.ProcessPersistenceContextManager)

Aggregations

ProcessPersistenceContext (org.jbpm.persistence.api.ProcessPersistenceContext)3 ProcessPersistenceContextManager (org.jbpm.persistence.api.ProcessPersistenceContextManager)3 ProcessInstanceView (org.jbpm.persistence.api.integration.model.ProcessInstanceView)3 TransactionManager (org.drools.persistence.api.TransactionManager)1 CorrelationKeyInfo (org.jbpm.persistence.correlation.CorrelationKeyInfo)1 CorrelationPropertyInfo (org.jbpm.persistence.correlation.CorrelationPropertyInfo)1 ProcessInstanceImpl (org.jbpm.process.instance.impl.ProcessInstanceImpl)1 WorkflowProcessInstanceImpl (org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl)1 Process (org.kie.api.definition.process.Process)1 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)1 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)1 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)1