Search in sources :

Example 1 with WorkItem

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

the class DefaultWorkItemManager method retryWorkItem.

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

Example 2 with WorkItem

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

the class DefaultWorkItemManager method retryWorkItemWithParams.

public void retryWorkItemWithParams(long workItemId, Map<String, Object> map) {
    WorkItem workItem = workItems.get(workItemId);
    if (workItem != null) {
        workItem.setParameters(map);
        retryWorkItem(workItem);
    }
}
Also used : WorkItem(org.drools.core.process.instance.WorkItem)

Example 3 with WorkItem

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

the class RegisterWorkItemHandlerTest method testRegisterWorkItemHandlerWithStatelessSession.

@Test
public void testRegisterWorkItemHandlerWithStatelessSession() {
    String str = "package org.kie.workitem.test \n" + "import " + DefaultWorkItemManager.class.getCanonicalName() + "\n" + "import " + WorkItem.class.getCanonicalName() + "\n" + "import " + WorkItemImpl.class.getCanonicalName() + "\n" + "rule r1 when \n" + "then \n" + "  WorkItem wi = new WorkItemImpl(); \n" + "  wi.setName( \"wihandler\" ); \n" + "  DefaultWorkItemManager wim = ( DefaultWorkItemManager ) kcontext.getKieRuntime().getWorkItemManager(); \n" + "  wim.internalExecuteWorkItem(wi); \n" + "end \n";
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newByteArrayResource(str.getBytes()), ResourceType.DRL);
    if (kbuilder.hasErrors()) {
        fail(kbuilder.getErrors().toString());
    }
    InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addPackages(kbuilder.getKnowledgePackages());
    final boolean[] answer = new boolean[] { false };
    StatelessKieSession ks = kbase.newStatelessKieSession();
    ks.execute(CommandFactory.newRegisterWorkItemHandlerCommand(new WorkItemHandler() {

        public void executeWorkItem(org.kie.api.runtime.process.WorkItem workItem, WorkItemManager manager) {
            answer[0] = true;
        }

        public void abortWorkItem(org.kie.api.runtime.process.WorkItem workItem, WorkItemManager manager) {
        // TODO Auto-generated method stub
        }
    }, "wihandler"));
    assertTrue(answer[0]);
}
Also used : WorkItemHandler(org.kie.api.runtime.process.WorkItemHandler) DefaultWorkItemManager(org.drools.core.process.instance.impl.DefaultWorkItemManager) KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) WorkItem(org.drools.core.process.instance.WorkItem) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) DefaultWorkItemManager(org.drools.core.process.instance.impl.DefaultWorkItemManager) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) Test(org.junit.Test)

Example 4 with WorkItem

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

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

the class JPAWorkItemManager method internalGetWorkItem.

private WorkItem internalGetWorkItem(WorkItemInfo workItemInfo) {
    Environment env = kruntime.getEnvironment();
    WorkItem workItem = workItemInfo.getWorkItem(env, (InternalKnowledgeBase) kruntime.getKieBase());
    return workItem;
}
Also used : Environment(org.kie.api.runtime.Environment) WorkItem(org.drools.core.process.instance.WorkItem)

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