use of io.spine.base.Version in project core-java by SpineEventEngine.
the class EventsShould method setUp.
@Before
public void setUp() {
final TestActorRequestFactory requestFactory = TestActorRequestFactory.newInstance(getClass());
final Command cmd = requestFactory.command().create(Time.getCurrentTime());
final StringValue producerId = Wrapper.forString(getClass().getSimpleName());
EventFactory eventFactory = EventFactory.newBuilder().setCommandId(Commands.generateId()).setProducerId(producerId).setCommandContext(cmd.getContext()).build();
event = eventFactory.createEvent(Time.getCurrentTime(), Tests.<Version>nullRef());
context = event.getContext();
}
use of io.spine.base.Version in project core-java by SpineEventEngine.
the class Aggregate method applyMessages.
/**
* Applies the passed event message or {@code Event} to the aggregate.
*
* @param eventMessages the event messages or events to apply
* @param envelope the envelope of the command which generated the events
* @see #ensureEventMessage(Message)
*/
private void applyMessages(Iterable<? extends Message> eventMessages, CommandEnvelope envelope) {
final List<? extends Message> messages = newArrayList(eventMessages);
final EventFactory eventFactory = createEventFactory(envelope, messages.size());
final List<Event> events = newArrayListWithCapacity(messages.size());
Version projectedEventVersion = getVersion();
for (Message eventOrMessage : messages) {
// Applying each message would increment the entity version.
// Therefore we should simulate this behaviour.
projectedEventVersion = Versions.increment(projectedEventVersion);
final Message eventMessage = ensureEventMessage(eventOrMessage);
final Event event;
if (eventOrMessage instanceof Event) {
event = importEvent((Event) eventOrMessage, envelope.getCommandContext(), projectedEventVersion);
} else {
event = eventFactory.createEvent(eventMessage, projectedEventVersion);
}
events.add(event);
}
play(events);
uncommittedEvents.addAll(events);
}
Aggregations