use of eu.bcvsolutions.idm.core.api.event.EntityEvent in project CzechIdMng by bcvsolutions.
the class DefaultEntityEventManager method putToQueue.
@SuppressWarnings({ "unchecked", "rawtypes" })
private void putToQueue(IdmEntityEventDto entityEvent) {
if (entityEvent.getPriority() == PriorityType.IMMEDIATE) {
LOG.trace("Event type [{}] for owner with id [{}] will be executed synchronously.", entityEvent.getEventType(), entityEvent.getOwnerId());
executeEvent(entityEvent);
return;
}
if (!eventConfiguration.isAsynchronous()) {
LOG.trace("Event type [{}] for owner with id [{}] will be executed synchronously, asynchronous event processing [{}] is disabled.", entityEvent.getEventType(), entityEvent.getOwnerId(), EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED);
executeEvent(entityEvent);
return;
}
//
// get enabled processors
final EntityEvent<Identifiable> event = toEvent(entityEvent);
List<EntityEventProcessor> registeredProcessors = context.getBeansOfType(EntityEventProcessor.class).values().stream().filter(enabledEvaluator::isEnabled).filter(processor -> !processor.isDisabled()).filter(processor -> processor.supports(event)).filter(processor -> processor.conditional(event)).sorted(new AnnotationAwareOrderComparator()).collect(Collectors.toList());
if (registeredProcessors.isEmpty()) {
LOG.debug("Event type [{}] for owner with id [{}] will not be executed, no enabled processor is registered.", entityEvent.getEventType(), entityEvent.getOwnerId());
return;
}
//
// evaluate event priority by registered processors
PriorityType priority = evaluatePriority(event, registeredProcessors);
if (priority != null && priority.getPriority() < entityEvent.getPriority().getPriority()) {
entityEvent.setPriority(priority);
}
// registered processors voted about event will be processed synchronously
if (entityEvent.getPriority() == PriorityType.IMMEDIATE) {
LOG.trace("Event type [{}] for owner with id [{}] will be executed synchronously.", entityEvent.getEventType(), entityEvent.getOwnerId());
executeEvent(entityEvent);
return;
}
//
// notification - info about registered (asynchronous) processors
Map<String, Object> parameters = new LinkedHashMap<>();
parameters.put("eventType", entityEvent.getEventType());
parameters.put("ownerId", entityEvent.getOwnerId());
parameters.put("instanceId", entityEvent.getInstanceId());
parameters.put("processors", registeredProcessors.stream().map(DefaultEntityEventManager.this::toDto).collect(Collectors.toList()));
notificationManager.send(CoreModuleDescriptor.TOPIC_EVENT, new IdmMessageDto.Builder().setLevel(NotificationLevel.INFO).setModel(new DefaultResultModel(CoreResultCode.EVENT_ACCEPTED, parameters)).build());
//
// persist event - asynchronous processing
entityEventService.save(entityEvent);
}
Aggregations