@SuppressWarnings("unchecked") @Override public Object handle(Message<?> message, P target) throws Exception { C childEntity = childEntityResolver.apply((CommandMessage<?>) message, target); if (childEntity == null) { throw new AggregateEntityNotFoundException( "Aggregate cannot handle this command, as there is no entity instance to forward it to." ); } List<AnnotatedCommandHandlerInterceptor<? super C>> interceptors = childHandlingInterceptors.stream() .filter(chi -> chi.canHandle(message)) .sorted((chi1, chi2) -> Integer.compare(chi2.priority(), chi1.priority())) .map(chi -> new AnnotatedCommandHandlerInterceptor<>(chi, childEntity)) .collect(Collectors.toList()); Object result; if (interceptors.isEmpty()) { result = childHandler.handle(message, childEntity); } else { result = new DefaultInterceptorChain<>((UnitOfWork<CommandMessage<?>>) CurrentUnitOfWork.get(), interceptors, m -> childHandler.handle(message, childEntity)).proceed(); } return result; }
@SuppressWarnings("unchecked") private Object handle(CommandMessage<?> commandMessage) throws Exception { List<AnnotatedCommandHandlerInterceptor<? super T>> interceptors = inspector.commandHandlerInterceptors() .stream() .filter(chi -> chi.canHandle(commandMessage)) .sorted((chi1, chi2) -> Integer.compare(chi2.priority(), chi1.priority())) .map(chi -> new AnnotatedCommandHandlerInterceptor<>(chi, aggregateRoot)) .collect(Collectors.toList()); MessageHandlingMember<? super T> handler = inspector.commandHandlers() .stream() .filter(mh -> mh.canHandle(commandMessage)) .findFirst() .orElseThrow(() -> new NoHandlerForCommandException(format("No handler available to handle command [%s]", commandMessage.getCommandName()))); Object result; if (interceptors.isEmpty()) { result = handler.handle(commandMessage, aggregateRoot); } else { result = new DefaultInterceptorChain<>( (UnitOfWork<CommandMessage<?>>) CurrentUnitOfWork.get(), interceptors, m -> handler.handle(commandMessage, aggregateRoot) ).proceed(); } if (aggregateRoot == null) { aggregateRoot = (T) result; return identifierAsString(); } return result; }
@SuppressWarnings("unchecked") @Override public Object handle(Message<?> message, P target) throws Exception { C childEntity = childEntityResolver.apply((CommandMessage<?>) message, target); if (childEntity == null) { throw new AggregateEntityNotFoundException( "Aggregate cannot handle this command, as there is no entity instance to forward it to." ); } List<AnnotatedCommandHandlerInterceptor<? super C>> interceptors = childHandlingInterceptors.stream() .filter(chi -> chi.canHandle(message)) .sorted((chi1, chi2) -> Integer.compare(chi2.priority(), chi1.priority())) .map(chi -> new AnnotatedCommandHandlerInterceptor<>(chi, childEntity)) .collect(Collectors.toList()); Object result; if (interceptors.isEmpty()) { result = childHandler.handle(message, childEntity); } else { result = new DefaultInterceptorChain<>((UnitOfWork<CommandMessage<?>>) CurrentUnitOfWork.get(), interceptors, m -> childHandler.handle(message, childEntity)).proceed(); } return result; }
@SuppressWarnings("unchecked") private Object handle(CommandMessage<?> commandMessage) throws Exception { List<AnnotatedCommandHandlerInterceptor<? super T>> interceptors = inspector.commandHandlerInterceptors() .stream() .filter(chi -> chi.canHandle(commandMessage)) .sorted((chi1, chi2) -> Integer.compare(chi2.priority(), chi1.priority())) .map(chi -> new AnnotatedCommandHandlerInterceptor<>(chi, aggregateRoot)) .collect(Collectors.toList()); MessageHandlingMember<? super T> handler = inspector.commandHandlers() .stream() .filter(mh -> mh.canHandle(commandMessage)) .findFirst() .orElseThrow(() -> new NoHandlerForCommandException(format("No handler available to handle command [%s]", commandMessage.getCommandName()))); Object result; if (interceptors.isEmpty()) { result = handler.handle(commandMessage, aggregateRoot); } else { result = new DefaultInterceptorChain<>( (UnitOfWork<CommandMessage<?>>) CurrentUnitOfWork.get(), interceptors, m -> handler.handle(commandMessage, aggregateRoot) ).proceed(); } if (aggregateRoot == null) { aggregateRoot = (T) result; return identifierAsString(); } return result; }