/** * Returns a {@link Predicate} for a {@link ConflictResolver} that responds affirmative if the payload type of any * event in a list of unseen events is assignable to given {@code payloadType}. If the returned predicate matches an * unseen event the ConflictResolver will throw an exception. * * @param payloadType the type of event payload to filter for * @return a Predicate to detect conflicts in unseen aggregate events */ public static <T> Predicate<List<DomainEventMessage<?>>> payloadTypeOf(Class<T> payloadType) { return eventMatching(event -> payloadType.isAssignableFrom(event.getPayloadType())); }
/** * Returns a {@link Predicate} for a {@link ConflictResolver} that responds affirmative if the payload of any event * in a list of unseen events is of given {@code payloadType} and matches the given {@code messageFilter}. If the * returned predicate matches an unseen event the ConflictResolver will throw an exception. * * @param payloadType the type of event payload to filter for * @param payloadFilter predicate for the payload of a single event * @return a Predicate to detect conflicts in unseen aggregate events */ @SuppressWarnings("unchecked") public static <T> Predicate<List<DomainEventMessage<?>>> payloadMatching(Class<T> payloadType, Predicate<? super T> payloadFilter) { return events -> events.stream().filter(event -> payloadType.isAssignableFrom(event.getPayloadType())) .map(event -> (T) event.getPayload()).anyMatch(payloadFilter::test); }
@SuppressWarnings("unchecked") @Override public final T createAggregateRoot(String aggregateIdentifier, DomainEventMessage<?> firstEvent) { T aggregate; if (aggregateBaseType.isAssignableFrom(firstEvent.getPayloadType())) { aggregate = (T) firstEvent.getPayload(); } else { aggregate = doCreateAggregate(aggregateIdentifier, firstEvent); } return postProcessInstance(aggregate); }
/** * Returns a {@link Predicate} for a {@link ConflictResolver} that responds affirmative if the payload type of any * event in a list of unseen events is assignable to given {@code payloadType}. If the returned predicate matches an * unseen event the ConflictResolver will throw an exception. * * @param payloadType the type of event payload to filter for * @return a Predicate to detect conflicts in unseen aggregate events */ public static <T> Predicate<List<DomainEventMessage<?>>> payloadTypeOf(Class<T> payloadType) { return eventMatching(event -> payloadType.isAssignableFrom(event.getPayloadType())); }
/** * Returns a {@link Predicate} for a {@link ConflictResolver} that responds affirmative if the payload of any event * in a list of unseen events is of given {@code payloadType} and matches the given {@code messageFilter}. If the * returned predicate matches an unseen event the ConflictResolver will throw an exception. * * @param payloadType the type of event payload to filter for * @param payloadFilter predicate for the payload of a single event * @return a Predicate to detect conflicts in unseen aggregate events */ @SuppressWarnings("unchecked") public static <T> Predicate<List<DomainEventMessage<?>>> payloadMatching(Class<T> payloadType, Predicate<? super T> payloadFilter) { return events -> events.stream().filter(event -> payloadType.isAssignableFrom(event.getPayloadType())) .map(event -> (T) event.getPayload()).anyMatch(payloadFilter::test); }
@SuppressWarnings("unchecked") @Override public final T createAggregateRoot(String aggregateIdentifier, DomainEventMessage<?> firstEvent) { T aggregate; if (aggregateBaseType.isAssignableFrom(firstEvent.getPayloadType())) { aggregate = (T) firstEvent.getPayload(); } else { aggregate = doCreateAggregate(aggregateIdentifier, firstEvent); } return postProcessInstance(aggregate); }