Search in sources :

Example 91 with Any

use of com.google.protobuf.Any in project core-java by SpineEventEngine.

the class EventFactory method createEvent.

/**
     * Creates a new {@code Event} instance.
     *
     * @param id           the ID of the event
     * @param messageOrAny the event message or {@code Any} containing the message
     * @param context      the event context
     * @return created event instance
     */
private static Event createEvent(EventId id, Message messageOrAny, EventContext context) {
    checkNotNull(messageOrAny);
    checkNotNull(context);
    final Any packed = toAny(messageOrAny);
    final Event result = Event.newBuilder().setId(id).setMessage(packed).setContext(context).build();
    return result;
}
Also used : IntegrationEvent(io.spine.server.integration.IntegrationEvent) Event(io.spine.base.Event) Any(com.google.protobuf.Any) Messages.toAny(io.spine.protobuf.Messages.toAny)

Example 92 with Any

use of com.google.protobuf.Any in project core-java by SpineEventEngine.

the class Identifiers method idToAny.

/**
     * Wraps the passed ID value into an instance of {@link Any}.
     *
     * <p>The passed value must be of one of the supported types listed below.
     * The type of the value wrapped into the returned instance is defined by the type
     * of the passed value:
     * <ul>
     *      <li>For classes implementing {@link com.google.protobuf.Message Message} — the value
     *      of the message itself
     *      <li>For {@code String} — {@link com.google.protobuf.StringValue StringValue}
     *      <li>For {@code Long} — {@link com.google.protobuf.UInt64Value UInt64Value}
     *      <li>For {@code Integer} — {@link com.google.protobuf.UInt32Value UInt32Value}
     * </ul>
     *
     * @param id  the value to wrap
     * @param <I> the type of the value
     * @return instance of {@link Any} with the passed value
     * @throws IllegalArgumentException if the passed value is not of the supported type
     */
public static <I> Any idToAny(I id) {
    checkNotNull(id);
    final Identifier<I> identifier = Identifier.from(id);
    final Any anyId = identifier.pack();
    return anyId;
}
Also used : Any(com.google.protobuf.Any)

Example 93 with Any

use of com.google.protobuf.Any in project core-java by SpineEventEngine.

the class FailureThrowable method toFailure.

/**
     * Converts this {@code FailureThrowable} into {@link Failure}.
     *
     * @param command the command which caused the failure
     */
@Internal
public Failure toFailure(Command command) {
    final Any packedMessage = pack(failureMessage);
    final FailureContext context = createContext(command);
    final FailureId id = Failures.generateId(command.getId());
    return Failure.newBuilder().setId(id).setMessage(packedMessage).setContext(context).build();
}
Also used : Any(com.google.protobuf.Any) Internal(io.spine.annotation.Internal)

Example 94 with Any

use of com.google.protobuf.Any in project core-java by SpineEventEngine.

the class PackingIteratorShould method implement_next.

@Test
public void implement_next() throws Exception {
    while (packer.hasNext()) {
        final Any packed = packer.next();
        assertNotNull(packed);
        assertFalse(isDefault(unpack(packed)));
    }
}
Also used : Any(com.google.protobuf.Any) Test(org.junit.Test)

Example 95 with Any

use of com.google.protobuf.Any in project core-java by SpineEventEngine.

the class AnyPackerShould method return_Any_if_it_is_passed_to_pack.

@Test
public void return_Any_if_it_is_passed_to_pack() {
    final Any any = Any.pack(googleMsg);
    assertSame(any, AnyPacker.pack(any));
}
Also used : Any(com.google.protobuf.Any) Test(org.junit.Test)

Aggregations

Any (com.google.protobuf.Any)155 Test (org.junit.Test)44 Message (com.google.protobuf.Message)30 TypeConverter.toAny (io.spine.protobuf.TypeConverter.toAny)27 EntityRecord (io.spine.server.entity.EntityRecord)24 TypeUrl (io.spine.type.TypeUrl)15 Version (io.spine.core.Version)11 Customer (io.spine.test.commandservice.customer.Customer)11 GivenVersion (io.spine.core.given.GivenVersion)9 EntityRecordWithColumns (io.spine.server.entity.storage.EntityRecordWithColumns)8 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)8 CustomerId (io.spine.test.commandservice.customer.CustomerId)8 FieldMask (com.google.protobuf.FieldMask)7 Query (io.spine.client.Query)7 Project (io.spine.test.storage.Project)7 EntityId (io.spine.client.EntityId)6 QueryResponse (io.spine.client.QueryResponse)6 Ack (io.spine.core.Ack)6 Command (io.spine.core.Command)6 EntityFilters (io.spine.client.EntityFilters)5