Search in sources :

Example 6 with WorkItem

use of org.drools.core.process.instance.WorkItem in project drools by kiegroup.

the class JPAWorkItemManager method retryWorkItem.

public void retryWorkItem(long workItemId) {
    WorkItem workItem = getWorkItem(workItemId);
    retryWorkItem(workItem);
}
Also used : WorkItem(org.drools.core.process.instance.WorkItem)

Example 7 with WorkItem

use of org.drools.core.process.instance.WorkItem 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 WorkItem

use of org.drools.core.process.instance.WorkItem in project drools by kiegroup.

the class JPAWorkItemManager method retryWorkItemWithParams.

public void retryWorkItemWithParams(long workItemId, Map<String, Object> map) {
    Environment env = this.kruntime.getEnvironment();
    WorkItem workItem = getWorkItem(workItemId);
    if (workItem != null) {
        workItem.setParameters(map);
        WorkItemInfo workItemInfo = new WorkItemInfo(workItem, env);
        PersistenceContext context = getPersistenceContext();
        context.merge(workItemInfo);
        retryWorkItem(workItem);
    }
}
Also used : Environment(org.kie.api.runtime.Environment) PersistenceContext(org.drools.persistence.api.PersistenceContext) WorkItem(org.drools.core.process.instance.WorkItem) WorkItemInfo(org.drools.persistence.info.WorkItemInfo)

Example 9 with WorkItem

use of org.drools.core.process.instance.WorkItem 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)

Example 10 with WorkItem

use of org.drools.core.process.instance.WorkItem in project drools by kiegroup.

the class GetWorkItemIdsCommand method execute.

public List<Long> execute(Context context) {
    KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
    Set<WorkItem> workItems = ((WorkItemManager) ksession.getWorkItemManager()).getWorkItems();
    List<Long> workItemIds = new ArrayList<Long>(workItems.size());
    for (WorkItem workItem : workItems) {
        workItemIds.add(workItem.getId());
    }
    return workItemIds;
}
Also used : ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) RegistryContext(org.drools.core.command.impl.RegistryContext) WorkItem(org.drools.core.process.instance.WorkItem) WorkItemManager(org.drools.core.process.instance.WorkItemManager)

Aggregations

WorkItem (org.drools.core.process.instance.WorkItem)10 PersistenceContext (org.drools.persistence.api.PersistenceContext)3 WorkItemInfo (org.drools.persistence.info.WorkItemInfo)3 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)3 WorkItemImpl (org.drools.core.process.instance.impl.WorkItemImpl)2 Environment (org.kie.api.runtime.Environment)2 ArrayList (java.util.ArrayList)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 RegistryContext (org.drools.core.command.impl.RegistryContext)1 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)1 WorkItemManager (org.drools.core.process.instance.WorkItemManager)1 DefaultWorkItemManager (org.drools.core.process.instance.impl.DefaultWorkItemManager)1 Test (org.junit.Test)1 KieSession (org.kie.api.runtime.KieSession)1 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)1 WorkItemHandler (org.kie.api.runtime.process.WorkItemHandler)1 WorkItemManager (org.kie.api.runtime.process.WorkItemManager)1 KnowledgeBuilder (org.kie.internal.builder.KnowledgeBuilder)1