Search in sources :

Example 6 with WorkItemHandler

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

the class CustomWorkItemHandlerTest method testRegisterHandlerWithKsessionUsingConfiguration.

@Test
public void testRegisterHandlerWithKsessionUsingConfiguration() {
    KieBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    Properties props = new Properties();
    props.setProperty("drools.workItemHandlers", "CustomWorkItemHandlers.conf");
    KieSessionConfiguration config = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(props);
    KieSession ksession = kbase.newKieSession(config, EnvironmentFactory.newEnvironment());
    assertNotNull(ksession);
    // this test would fail on creation of the work item manager if injecting session is not supported
    WorkItemManager manager = ksession.getWorkItemManager();
    assertNotNull(manager);
    Map<String, WorkItemHandler> handlers = ((SessionConfiguration) config).getWorkItemHandlers();
    assertNotNull(handlers);
    assertEquals(1, handlers.size());
    assertTrue(handlers.containsKey("Custom"));
}
Also used : WorkItemHandler(org.kie.api.runtime.process.WorkItemHandler) KieBase(org.kie.api.KieBase) KieSession(org.kie.api.runtime.KieSession) Properties(java.util.Properties) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) KieSessionConfiguration(org.kie.api.runtime.KieSessionConfiguration) KieSessionConfiguration(org.kie.api.runtime.KieSessionConfiguration) SessionConfiguration(org.drools.core.SessionConfiguration) Test(org.junit.Test)

Example 7 with WorkItemHandler

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

the class DefaultWorkItemManager method internalExecuteWorkItem.

public void internalExecuteWorkItem(WorkItem workItem) {
    ((WorkItemImpl) workItem).setId(workItemCounter.incrementAndGet());
    internalAddWorkItem(workItem);
    WorkItemHandler handler = this.workItemHandlers.get(workItem.getName());
    if (handler != null) {
        handler.executeWorkItem(workItem, this);
    } else
        throw new WorkItemHandlerNotFoundException("Could not find work item handler for " + workItem.getName(), workItem.getName());
}
Also used : WorkItemHandler(org.kie.api.runtime.process.WorkItemHandler) WorkItemHandlerNotFoundException(org.drools.core.WorkItemHandlerNotFoundException)

Aggregations

WorkItemHandler (org.kie.api.runtime.process.WorkItemHandler)7 WorkItemImpl (org.drools.core.process.instance.impl.WorkItemImpl)3 WorkItemHandlerNotFoundException (org.drools.core.WorkItemHandlerNotFoundException)2 PersistenceContext (org.drools.persistence.api.PersistenceContext)2 WorkItemInfo (org.drools.persistence.info.WorkItemInfo)2 Test (org.junit.Test)2 WorkItemManager (org.kie.api.runtime.process.WorkItemManager)2 Properties (java.util.Properties)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 SessionConfiguration (org.drools.core.SessionConfiguration)1 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)1 WorkItem (org.drools.core.process.instance.WorkItem)1 DefaultWorkItemManager (org.drools.core.process.instance.impl.DefaultWorkItemManager)1 KieBase (org.kie.api.KieBase)1 WorkItemHandlerModel (org.kie.api.builder.model.WorkItemHandlerModel)1 Environment (org.kie.api.runtime.Environment)1 KieSession (org.kie.api.runtime.KieSession)1 KieSessionConfiguration (org.kie.api.runtime.KieSessionConfiguration)1 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)1 KnowledgeBuilder (org.kie.internal.builder.KnowledgeBuilder)1