Search in sources :

Example 6 with ProcessInstance

use of org.kie.api.runtime.process.ProcessInstance in project drools by kiegroup.

the class JPAWorkItemManager method abortWorkItem.

public void abortWorkItem(long id) {
    PersistenceContext context = getPersistenceContext();
    WorkItemInfo workItemInfo = null;
    if (this.workItems != null) {
        workItemInfo = this.workItems.get(id);
        if (workItemInfo != null) {
            workItemInfo = (WorkItemInfo) context.merge(workItemInfo);
        }
    }
    if (workItemInfo == null) {
        workItemInfo = (WorkItemInfo) context.findWorkItem(id);
    }
    // work item may have been aborted
    if (workItemInfo != null) {
        WorkItem workItem = (WorkItemImpl) internalGetWorkItem(workItemInfo);
        ProcessInstance processInstance = kruntime.getProcessInstance(workItem.getProcessInstanceId());
        workItem.setState(WorkItem.ABORTED);
        // process instance may have finished already
        if (processInstance != null) {
            processInstance.signalEvent("workItemAborted", workItem);
        }
        context.remove(workItemInfo);
        if (workItems != null) {
            workItems.remove(workItem.getId());
        }
    }
}
Also used : WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) PersistenceContext(org.drools.persistence.api.PersistenceContext) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkItem(org.drools.core.process.instance.WorkItem) WorkItemInfo(org.drools.persistence.info.WorkItemInfo)

Example 7 with ProcessInstance

use of org.kie.api.runtime.process.ProcessInstance in project drools by kiegroup.

the class JPAWorkItemManager method completeWorkItem.

public void completeWorkItem(long id, Map<String, Object> results) {
    PersistenceContext context = getPersistenceContext();
    WorkItemInfo workItemInfo = null;
    if (this.workItems != null) {
        workItemInfo = this.workItems.get(id);
        if (workItemInfo != null) {
            workItemInfo = (WorkItemInfo) context.merge(workItemInfo);
        }
    }
    if (workItemInfo == null) {
        workItemInfo = (WorkItemInfo) context.findWorkItem(id);
    }
    // work item may have been aborted
    if (workItemInfo != null) {
        WorkItem workItem = internalGetWorkItem(workItemInfo);
        workItem.setResults(results);
        ProcessInstance processInstance = kruntime.getProcessInstance(workItem.getProcessInstanceId());
        workItem.setState(WorkItem.COMPLETED);
        // process instance may have finished already
        if (processInstance != null) {
            processInstance.signalEvent("workItemCompleted", workItem);
        }
        context.remove(workItemInfo);
        if (workItems != null) {
            this.workItems.remove(workItem.getId());
        }
    }
}
Also used : PersistenceContext(org.drools.persistence.api.PersistenceContext) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkItem(org.drools.core.process.instance.WorkItem) WorkItemInfo(org.drools.persistence.info.WorkItemInfo)

Example 8 with ProcessInstance

use of org.kie.api.runtime.process.ProcessInstance in project drools by kiegroup.

the class SetProcessInstanceVariablesCommand method execute.

public Void execute(Context context) {
    KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
    ProcessInstance processInstance = ksession.getProcessInstance(processInstanceId);
    if (processInstance != null) {
        if (variables != null) {
            for (Map.Entry<String, Object> entry : variables.entrySet()) {
                ((WorkflowProcessInstance) processInstance).setVariable(entry.getKey(), entry.getValue());
            }
        }
    }
    return null;
}
Also used : KieSession(org.kie.api.runtime.KieSession) RegistryContext(org.drools.core.command.impl.RegistryContext) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) HashMap(java.util.HashMap) Map(java.util.Map) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance)

Example 9 with ProcessInstance

use of org.kie.api.runtime.process.ProcessInstance in project drools by kiegroup.

the class DefaultWorkItemManager method abortWorkItem.

public void abortWorkItem(long id) {
    WorkItemImpl workItem = (WorkItemImpl) workItems.get(new Long(id));
    // work item may have been aborted
    if (workItem != null) {
        ProcessInstance processInstance = kruntime.getProcessInstance(workItem.getProcessInstanceId());
        workItem.setState(WorkItem.ABORTED);
        // process instance may have finished already
        if (processInstance != null) {
            processInstance.signalEvent("workItemAborted", workItem);
        }
        workItems.remove(new Long(id));
    }
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) ProcessInstance(org.kie.api.runtime.process.ProcessInstance)

Example 10 with ProcessInstance

use of org.kie.api.runtime.process.ProcessInstance in project drools by kiegroup.

the class DefaultWorkItemManager method completeWorkItem.

public void completeWorkItem(long id, Map<String, Object> results) {
    WorkItem workItem = workItems.get(new Long(id));
    // work item may have been aborted
    if (workItem != null) {
        (workItem).setResults(results);
        ProcessInstance processInstance = kruntime.getProcessInstance(workItem.getProcessInstanceId());
        (workItem).setState(WorkItem.COMPLETED);
        // process instance may have finished already
        if (processInstance != null) {
            processInstance.signalEvent("workItemCompleted", workItem);
        }
        workItems.remove(new Long(id));
    }
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkItem(org.drools.core.process.instance.WorkItem)

Aggregations

ProcessInstance (org.kie.api.runtime.process.ProcessInstance)12 RegistryContext (org.drools.core.command.impl.RegistryContext)7 KieSession (org.kie.api.runtime.KieSession)7 ExecutionResultImpl (org.drools.core.runtime.impl.ExecutionResultImpl)4 WorkItem (org.drools.core.process.instance.WorkItem)3 Map (java.util.Map)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 PersistenceContext (org.drools.persistence.api.PersistenceContext)2 WorkItemInfo (org.drools.persistence.info.WorkItemInfo)2 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)2 CorrelationAwareProcessRuntime (org.kie.internal.process.CorrelationAwareProcessRuntime)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 WorkingMemoryEntryPoint (org.drools.core.WorkingMemoryEntryPoint)1 InternalRuleFlowGroup (org.drools.core.common.InternalRuleFlowGroup)1 InternalWorkingMemoryEntryPoint (org.drools.core.common.InternalWorkingMemoryEntryPoint)1 NamedEntryPoint (org.drools.core.common.NamedEntryPoint)1 WorkItemImpl (org.drools.core.process.instance.impl.WorkItemImpl)1 NodeInstance (org.kie.api.runtime.process.NodeInstance)1 NodeInstanceContainer (org.kie.api.runtime.process.NodeInstanceContainer)1