Search in sources :

Example 1 with CaseEventListener

use of org.jbpm.casemgmt.api.event.CaseEventListener in project jbpm by kiegroup.

the class CaseConfigurationDeploymentListener method getEventListenerFromDescriptor.

protected List<CaseEventListener> getEventListenerFromDescriptor(InternalRuntimeManager runtimeManager) {
    List<CaseEventListener> listeners = new ArrayList<CaseEventListener>();
    DeploymentDescriptor descriptor = runtimeManager.getDeploymentDescriptor();
    if (descriptor != null) {
        Map<String, Object> params = getParametersMap(runtimeManager);
        for (ObjectModel model : descriptor.getEventListeners()) {
            ObjectModelResolver resolver = ObjectModelResolverProvider.get(model.getResolver());
            if (resolver == null) {
                logger.warn("Unable to find ObjectModelResolver for {}", model.getResolver());
                continue;
            }
            try {
                Object listenerInstance = resolver.getInstance(model, runtimeManager.getEnvironment().getClassLoader(), params);
                if (listenerInstance != null && CaseEventListener.class.isAssignableFrom(listenerInstance.getClass())) {
                    listeners.add((CaseEventListener) listenerInstance);
                } else {
                    // close/cleanup instance as it is not going to be used at the moment, except these that are cacheable
                    if (listenerInstance instanceof Closeable && !(listenerInstance instanceof Cacheable)) {
                        ((Closeable) listenerInstance).close();
                    }
                }
            } catch (Exception e) {
                logger.debug("Unable to build listener {}", model);
            }
        }
    }
    return listeners;
}
Also used : ObjectModel(org.kie.internal.runtime.conf.ObjectModel) Cacheable(org.kie.internal.runtime.Cacheable) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) Closeable(org.kie.internal.runtime.Closeable) ArrayList(java.util.ArrayList) ObjectModelResolver(org.kie.internal.runtime.conf.ObjectModelResolver) CaseEventListener(org.jbpm.casemgmt.api.event.CaseEventListener) NotifyParentCaseEventListener(org.jbpm.casemgmt.impl.wih.NotifyParentCaseEventListener)

Example 2 with CaseEventListener

use of org.jbpm.casemgmt.api.event.CaseEventListener in project jbpm by kiegroup.

the class CaseConfigurationDeploymentListener method onDeploy.

@Override
public void onDeploy(DeploymentEvent event) {
    InternalRuntimeManager runtimeManager = (InternalRuntimeManager) event.getDeployedUnit().getRuntimeManager();
    if (runtimeManager instanceof PerCaseRuntimeManager) {
        List<CaseEventListener> caseEventListeners = getEventListenerFromDescriptor(runtimeManager);
        logger.debug("Adding following case event listeners {} for deployment {}", caseEventListeners, event.getDeploymentId());
        TransactionalCommandService commandService = transactionalCommandService;
        if (commandService == null) {
            commandService = new TransactionalCommandService(((SimpleRuntimeEnvironment) runtimeManager.getEnvironment()).getEmf());
        }
        CaseInstanceAuditEventListener auditEventListener = new CaseInstanceAuditEventListener(commandService);
        caseEventListeners.add(auditEventListener);
        caseEventListeners.add(new NotifyParentCaseEventListener(identityProvider));
        CaseEventSupport caseEventSupport = new CaseEventSupport(identityProvider, caseEventListeners);
        ((PerCaseRuntimeManager) runtimeManager).setCaseEventSupport(caseEventSupport);
        logger.debug("CaseEventSupport configured for deployment {}", event.getDeploymentId());
    }
}
Also used : SimpleRuntimeEnvironment(org.jbpm.runtime.manager.impl.SimpleRuntimeEnvironment) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) PerCaseRuntimeManager(org.jbpm.runtime.manager.impl.PerCaseRuntimeManager) CaseInstanceAuditEventListener(org.jbpm.casemgmt.impl.audit.CaseInstanceAuditEventListener) TransactionalCommandService(org.jbpm.shared.services.impl.TransactionalCommandService) NotifyParentCaseEventListener(org.jbpm.casemgmt.impl.wih.NotifyParentCaseEventListener) CaseEventListener(org.jbpm.casemgmt.api.event.CaseEventListener) NotifyParentCaseEventListener(org.jbpm.casemgmt.impl.wih.NotifyParentCaseEventListener)

Aggregations

CaseEventListener (org.jbpm.casemgmt.api.event.CaseEventListener)2 NotifyParentCaseEventListener (org.jbpm.casemgmt.impl.wih.NotifyParentCaseEventListener)2 ArrayList (java.util.ArrayList)1 CaseInstanceAuditEventListener (org.jbpm.casemgmt.impl.audit.CaseInstanceAuditEventListener)1 PerCaseRuntimeManager (org.jbpm.runtime.manager.impl.PerCaseRuntimeManager)1 SimpleRuntimeEnvironment (org.jbpm.runtime.manager.impl.SimpleRuntimeEnvironment)1 TransactionalCommandService (org.jbpm.shared.services.impl.TransactionalCommandService)1 Cacheable (org.kie.internal.runtime.Cacheable)1 Closeable (org.kie.internal.runtime.Closeable)1 DeploymentDescriptor (org.kie.internal.runtime.conf.DeploymentDescriptor)1 ObjectModel (org.kie.internal.runtime.conf.ObjectModel)1 ObjectModelResolver (org.kie.internal.runtime.conf.ObjectModelResolver)1 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)1