@SuppressWarnings("unchecked") @Override public <T> Optional<ChildEntity<T>> createChildDefinition(Field field, EntityModel<T> declaringEntity) { Map<String, Object> attributes = findAnnotationAttributes(field, AggregateMember.class).orElse(null); if (attributes == null || !isFieldTypeSupported(field)) { return Optional.empty(); } EntityModel<Object> childEntityModel = extractChildEntityModel(declaringEntity, attributes, field); ForwardingMode eventForwardingMode = instantiateForwardingMode( field, childEntityModel, (Class<? extends ForwardingMode>) attributes.get("eventForwardingMode") ); return Optional.of(new AnnotatedChildEntity<>( childEntityModel, (Boolean) attributes.get("forwardCommands"), (msg, parent) -> resolveCommandTarget(msg, parent, field, childEntityModel), (msg, parent) -> resolveEventTargets(msg, parent, field, eventForwardingMode) )); }
/** * Retrieves the routing keys of every command handler on the given {@code childEntityModel} to be able to correctly * route commands to Entities. * * @param field a {@link java.lang.reflect.Field} denoting the Child Entity upon which the {@code * childEntityModel} is based. * @param childEntityModel a {@link EntityModel} to retrieve the * routing key properties from. * @return a {@link java.util.Map} of key/value types {@link java.lang.String}/ * {@link org.axonframework.common.property.Property} from Command Message name to routing key. */ @SuppressWarnings("WeakerAccess") protected Map<String, Property<Object>> extractCommandHandlerRoutingKeys(Field field, EntityModel<Object> childEntityModel) { return childEntityModel.commandHandlers() .stream() .map(commandHandler -> commandHandler.unwrap(CommandMessageHandlingMember.class) .orElse(null)) .filter(Objects::nonNull) .collect(Collectors.toMap( CommandMessageHandlingMember::commandName, commandHandler -> extractCommandHandlerRoutingKey(childEntityModel, commandHandler, field ) )); }
@SuppressWarnings("unchecked") @Override public <T> Optional<ChildEntity<T>> createChildDefinition(Field field, EntityModel<T> declaringEntity) { Map<String, Object> attributes = findAnnotationAttributes(field, AggregateMember.class).orElse(null); if (attributes == null || !isFieldTypeSupported(field)) { return Optional.empty(); } EntityModel<Object> childEntityModel = extractChildEntityModel(declaringEntity, attributes, field); ForwardingMode eventForwardingMode = instantiateForwardingMode( field, childEntityModel, (Class<? extends ForwardingMode>) attributes.get("eventForwardingMode") ); return Optional.of(new AnnotatedChildEntity<>( childEntityModel, (Boolean) attributes.get("forwardCommands"), (msg, parent) -> resolveCommandTarget(msg, parent, field, childEntityModel), (msg, parent) -> resolveEventTargets(msg, parent, field, eventForwardingMode) )); }
/** * Retrieves the routing keys of every command handler on the given {@code childEntityModel} to be able to correctly * route commands to Entities. * * @param field a {@link java.lang.reflect.Field} denoting the Child Entity upon which the {@code * childEntityModel} is based. * @param childEntityModel a {@link EntityModel} to retrieve the * routing key properties from. * @return a {@link java.util.Map} of key/value types {@link java.lang.String}/ * {@link org.axonframework.common.property.Property} from Command Message name to routing key. */ @SuppressWarnings("WeakerAccess") protected Map<String, Property<Object>> extractCommandHandlerRoutingKeys(Field field, EntityModel<Object> childEntityModel) { return childEntityModel.commandHandlers() .stream() .map(commandHandler -> commandHandler.unwrap(CommandMessageHandlingMember.class) .orElse(null)) .filter(Objects::nonNull) .collect(Collectors.toMap( CommandMessageHandlingMember::commandName, commandHandler -> extractCommandHandlerRoutingKey(childEntityModel, commandHandler, field ) )); }