use of com.kloia.eventapis.api.EventRepository in project eventapis by kloiasoft.
the class CommandExecutionInterceptor method recordCommand.
private CommandRecord recordCommand(JoinPoint jp, CommandHandler commandHandler, Command command) throws ConcurrentEventException, EventStoreException {
EventRepository eventRepository;
CommandDto commandDto = null;
CommandRecord commandRecord = new CommandRecord();
commandRecord.setEventName(commandHandler.getClass().getSimpleName());
for (int i = 0; i < jp.getArgs().length; i++) {
Object arg = jp.getArgs()[i];
commandRecord.getParameters().put(i, arg);
}
// }
try {
Field declaredField = commandHandler.getClass().getDeclaredField(command.eventRepository());
if (!declaredField.isAccessible())
declaredField.setAccessible(true);
eventRepository = (EventRepository) declaredField.get(commandHandler);
} catch (IllegalAccessException | NoSuchFieldException e) {
log.error("Error while accessing EventRecorder(" + command.eventRepository() + ") of Command:" + commandHandler.getClass().getSimpleName() + " message: " + e.getMessage(), e);
return null;
}
if (eventRepository != null) {
eventRepository.getEventRecorder().recordEntityEvent(commandRecord, System.currentTimeMillis(), Optional.empty(), entityEvent -> new DefaultConcurrencyResolver());
} else
log.error("Error while accessing EventRecorder(" + command.eventRepository() + " is null ) of Command:" + commandHandler.getClass().getSimpleName());
return commandRecord;
}
Aggregations