use of eu.bcvsolutions.idm.core.api.event.EntityEventProcessor in project CzechIdMng by bcvsolutions.
the class DefaultEntityEventManager method evaluatePriority.
/**
* Evaluate event priority by registered processors
*
* @param event
* @param registeredProcessors
* @return
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
protected PriorityType evaluatePriority(EntityEvent<Identifiable> event, List<EntityEventProcessor> registeredProcessors) {
PriorityType priority = null;
for (EntityEventProcessor processor : registeredProcessors) {
if (!(processor instanceof AsyncEntityEventProcessor)) {
continue;
}
AsyncEntityEventProcessor asyncProcessor = (AsyncEntityEventProcessor) processor;
PriorityType processorPriority = asyncProcessor.getPriority(event);
if (processorPriority == null) {
// processor doesn't vote about priority - preserve original event priority.
continue;
}
if (priority == null || processorPriority.getPriority() < priority.getPriority()) {
priority = processorPriority;
}
if (priority == PriorityType.IMMEDIATE) {
// nothing is higher
break;
}
}
//
return priority;
}
use of eu.bcvsolutions.idm.core.api.event.EntityEventProcessor 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);
}
use of eu.bcvsolutions.idm.core.api.event.EntityEventProcessor in project CzechIdMng by bcvsolutions.
the class DefaultEntityEventManager method find.
@Override
@SuppressWarnings({ "rawtypes" })
public List<EntityEventProcessorDto> find(EntityEventProcessorFilter filter) {
List<EntityEventProcessorDto> dtos = new ArrayList<>();
Map<String, EntityEventProcessor> processors = context.getBeansOfType(EntityEventProcessor.class);
for (Entry<String, EntityEventProcessor> entry : processors.entrySet()) {
EntityEventProcessor<?> processor = entry.getValue();
// entity event processor depends on module - we could not call any processor method
if (!enabledEvaluator.isEnabled(processor)) {
continue;
}
EntityEventProcessorDto dto = toDto(processor);
//
if (passFilter(dto, filter)) {
dtos.add(dto);
}
}
LOG.debug("Returning [{}] registered entity event processors", dtos.size());
return dtos;
}
Aggregations