Search in sources :

Example 6 with WorkItemInfo

use of org.drools.persistence.info.WorkItemInfo in project drools by kiegroup.

the class JPAWorkItemManager method internalAbortWorkItem.

public void internalAbortWorkItem(long id) {
    PersistenceContext context = getPersistenceContext();
    WorkItemInfo workItemInfo = (WorkItemInfo) context.findWorkItem(id);
    // work item may have been aborted
    if (workItemInfo != null) {
        WorkItemImpl workItem = (WorkItemImpl) internalGetWorkItem(workItemInfo);
        WorkItemHandler handler = (WorkItemHandler) this.workItemHandlers.get(workItem.getName());
        if (handler != null) {
            handler.abortWorkItem(workItem, this);
        } else {
            if (workItems != null) {
                workItems.remove(id);
                throwWorkItemNotFoundException(workItem);
            }
        }
        if (workItems != null) {
            workItems.remove(id);
        }
        context.remove(workItemInfo);
    }
}
Also used : WorkItemHandler(org.kie.api.runtime.process.WorkItemHandler) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) PersistenceContext(org.drools.persistence.api.PersistenceContext) WorkItemInfo(org.drools.persistence.info.WorkItemInfo)

Example 7 with WorkItemInfo

use of org.drools.persistence.info.WorkItemInfo 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 WorkItemInfo

use of org.drools.persistence.info.WorkItemInfo 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)

Aggregations

WorkItemInfo (org.drools.persistence.info.WorkItemInfo)8 PersistenceContext (org.drools.persistence.api.PersistenceContext)6 WorkItem (org.drools.core.process.instance.WorkItem)3 WorkItemImpl (org.drools.core.process.instance.impl.WorkItemImpl)3 Environment (org.kie.api.runtime.Environment)2 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)2 WorkItemHandler (org.kie.api.runtime.process.WorkItemHandler)2 Field (java.lang.reflect.Field)1