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));
}
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));
}
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;
}
Aggregations