Search in sources :

Example 1 with WorkItemHandlerProducer

use of org.kie.internal.runtime.manager.WorkItemHandlerProducer in project jbpm by kiegroup.

the class InjectableRegisterableItemsFactory method getWorkItemHandlers.

@Override
public Map<String, WorkItemHandler> getWorkItemHandlers(RuntimeEngine runtime) {
    Map<String, WorkItemHandler> handler = new HashMap<String, WorkItemHandler>();
    handler.put("Human Task", getHTWorkItemHandler(runtime));
    RuntimeManager manager = ((RuntimeEngineImpl) runtime).getManager();
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("ksession", runtime.getKieSession());
    parameters.put("taskService", runtime.getTaskService());
    parameters.put("runtimeManager", manager);
    parameters.put("kieContainer", getRuntimeManager().getKieContainer());
    try {
        parameters.put("executorService", executorService.get());
    } catch (Exception e) {
        logger.debug("Executor service not available due to {}", e.getMessage());
    }
    if (kieContainer != null) {
        // add classloader as one of the parameters so it can be easily referenced
        parameters.put("classLoader", kieContainer.getClassLoader());
        KieSessionModel ksessionModel = null;
        if (StringUtils.isEmpty(ksessionName)) {
            ksessionModel = ((KieContainerImpl) kieContainer).getKieProject().getDefaultKieSession();
            if (ksessionModel == null) {
                ksessionModel = ((KieContainerImpl) kieContainer).getKieSessionModel(DEFAULT_KIE_SESSION);
            }
        } else {
            ksessionModel = ((KieContainerImpl) kieContainer).getKieSessionModel(ksessionName);
        }
        if (ksessionModel == null) {
            throw new IllegalStateException("Cannot find ksession, either it does not exist or there are multiple default ksession in kmodule.xml");
        }
        try {
            InjectionHelper.wireSessionComponents(ksessionModel, runtime.getKieSession(), parameters);
        } catch (Throwable e) {
            // use fallback mechanism
            InjectionHelper.wireSessionComponents(ksessionModel, runtime.getKieSession());
        }
    }
    try {
        for (WorkItemHandlerProducer producer : workItemHandlerProducer) {
            handler.putAll(producer.getWorkItemHandlers(manager.getIdentifier(), parameters));
        }
    } catch (Exception e) {
        // do nothing as work item handler is considered optional
        logger.warn("Exception while evalutating work item handler prodcuers {}", e.getMessage());
    }
    // add handlers from descriptor
    handler.putAll(getWorkItemHandlersFromDescriptor(runtime));
    return handler;
}
Also used : HashMap(java.util.HashMap) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) KieContainerImpl(org.drools.compiler.kie.builder.impl.KieContainerImpl) RuntimeEngineImpl(org.jbpm.runtime.manager.impl.RuntimeEngineImpl) UnsatisfiedResolutionException(javax.enterprise.inject.UnsatisfiedResolutionException) IOException(java.io.IOException) KieSessionModel(org.kie.api.builder.model.KieSessionModel) WorkItemHandler(org.kie.api.runtime.process.WorkItemHandler) WorkItemHandlerProducer(org.kie.internal.runtime.manager.WorkItemHandlerProducer)

Aggregations

IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 UnsatisfiedResolutionException (javax.enterprise.inject.UnsatisfiedResolutionException)1 KieContainerImpl (org.drools.compiler.kie.builder.impl.KieContainerImpl)1 RuntimeEngineImpl (org.jbpm.runtime.manager.impl.RuntimeEngineImpl)1 KieSessionModel (org.kie.api.builder.model.KieSessionModel)1 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)1 WorkItemHandler (org.kie.api.runtime.process.WorkItemHandler)1 WorkItemHandlerProducer (org.kie.internal.runtime.manager.WorkItemHandlerProducer)1