Search in sources :

Example 11 with EventContext

use of io.spine.base.EventContext in project core-java by SpineEventEngine.

the class EventFactory method createEvent.

/**
     * Creates an event for the passed event message.
     *
     * <p>The message passed is validated according to the constraints set in its Protobuf
     * definition. In case the message isn't valid, an {@linkplain ConstraintViolationThrowable
     * exception} is thrown.
     *
     * <p>In the message is an instance of {@code Any}, it is unpacked for validation.
     *
     * <p>It is recommended to use a corresponding {@linkplain io.spine.validate.ValidatingBuilder
     * ValidatingBuilder} implementation to create a message.
     *
     * @param messageOrAny the message of the event or the message packed into {@code Any}
     * @param version      the version of the entity which produces the event
     * @throws ConstraintViolationThrowable if the passed message does not satisfy the constraints
     *                                      set for it in its Protobuf definition
     */
public Event createEvent(Message messageOrAny, @Nullable Version version) throws ConstraintViolationThrowable {
    checkNotNull(messageOrAny);
    // we must validate it now before emitting the next ID.
    validate(messageOrAny);
    final EventId eventId = idSequence.next();
    final EventContext context = createContext(producerId, commandContext, version);
    final Event result = createEvent(eventId, messageOrAny, context);
    return result;
}
Also used : IntegrationEventContext(io.spine.server.integration.IntegrationEventContext) EventContext(io.spine.base.EventContext) EventId(io.spine.base.EventId) IntegrationEvent(io.spine.server.integration.IntegrationEvent) Event(io.spine.base.Event)

Example 12 with EventContext

use of io.spine.base.EventContext in project core-java by SpineEventEngine.

the class EventFactory method toEvent.

/**
     * Creates an event based on the passed integration event.
     */
public static Event toEvent(IntegrationEvent integrationEvent) {
    final IntegrationEventContext sourceContext = integrationEvent.getContext();
    final EventContext context = toEventContext(sourceContext);
    final Event result = createEvent(sourceContext.getEventId(), integrationEvent.getMessage(), context);
    return result;
}
Also used : IntegrationEventContext(io.spine.server.integration.IntegrationEventContext) EventContext(io.spine.base.EventContext) IntegrationEventContext(io.spine.server.integration.IntegrationEventContext) IntegrationEvent(io.spine.server.integration.IntegrationEvent) Event(io.spine.base.Event)

Aggregations

EventContext (io.spine.base.EventContext)12 EventsShould.newEventContext (io.spine.base.EventsShould.newEventContext)5 Test (org.junit.Test)5 Event (io.spine.base.Event)4 IntegrationEventContext (io.spine.server.integration.IntegrationEventContext)3 Message (com.google.protobuf.Message)2 IntegrationEvent (io.spine.server.integration.IntegrationEvent)2 Timestamp (com.google.protobuf.Timestamp)1 EventId (io.spine.base.EventId)1 Transaction (io.spine.server.entity.Transaction)1 IdSetEventFunction (io.spine.server.entity.idfunc.IdSetEventFunction)1 EventOperation (io.spine.server.tenant.EventOperation)1 ProjectId (io.spine.test.projection.ProjectId)1 ProjectCreated (io.spine.test.projection.event.ProjectCreated)1