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;
}
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());
}
}
Aggregations