Search in sources :

Example 6 with Any

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

the class AnyPackerShould method pack_spine_message_to_Any.

@Test
public void pack_spine_message_to_Any() {
    final Any actual = AnyPacker.pack(spineMsg);
    final TypeUrl typeUrl = TypeUrl.of(spineMsg);
    assertEquals(Any.pack(spineMsg).getValue(), actual.getValue());
    assertEquals(typeUrl.value(), actual.getTypeUrl());
}
Also used : TypeUrl(io.spine.type.TypeUrl) Any(com.google.protobuf.Any) Test(org.junit.Test)

Example 7 with Any

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

the class AnyPackerShould method pack_google_message_to_Any.

@Test
public void pack_google_message_to_Any() {
    final Any expected = Any.pack(googleMsg);
    final Any actual = AnyPacker.pack(googleMsg);
    assertEquals(expected, actual);
}
Also used : Any(com.google.protobuf.Any) Test(org.junit.Test)

Example 8 with Any

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

the class QueryParameter method eq.

/**
     * Creates new equality {@code QueryParameter}.
     *
     * @param columnName the name of the Entity Column to query by, expressed in a single field
     *                   name with no type info
     * @param value      the requested value of the Entity Column
     * @return new instance of the QueryParameter
     */
public static QueryParameter eq(String columnName, Object value) {
    checkNotNull(columnName);
    checkNotNull(value);
    final Any wrappedValue = toAny(value);
    final QueryParameter parameter = new QueryParameter(columnName, wrappedValue);
    return parameter;
}
Also used : TypeConverter.toAny(io.spine.protobuf.TypeConverter.toAny) Any(com.google.protobuf.Any)

Example 9 with Any

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

the class Identifiers method idToString.

/**
     * Converts the passed ID value into the string representation.
     *
     * @param id  the value to convert
     * @param <I> the type of the ID
     * @return <ul>
     *              <li>for classes implementing {@link Message} &mdash; a Json form;
     *              <li>for {@code String}, {@code Long}, {@code Integer} &mdash;
     *              the result of {@link Object#toString()};
     *              <li>for {@code null} ID &mdash; the {@link #NULL_ID};
     *              <li>if the result is empty or blank string &mdash; the {@link #EMPTY_ID}.
     *         </ul>
     * @throws IllegalArgumentException if the passed type isn't one of the above or
     *                                  the passed {@link Message} instance has no fields
     * @see StringifierRegistry
     */
public static <I> String idToString(@Nullable I id) {
    if (id == null) {
        return NULL_ID;
    }
    final Identifier<?> identifier;
    if (id instanceof Any) {
        final Message unpacked = unpack((Any) id);
        identifier = Identifier.fromMessage(unpacked);
    } else {
        identifier = Identifier.from(id);
    }
    final String result = identifier.toString();
    return result;
}
Also used : Message(com.google.protobuf.Message) TextFormat.shortDebugString(com.google.protobuf.TextFormat.shortDebugString) Any(com.google.protobuf.Any)

Example 10 with Any

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

the class Enrichments method getEnrichment.

/**
     * Return a specific enrichment from the context.
     *
     * @param enrichmentClass a class of the event enrichment
     * @param context         a context to get an enrichment from
     * @param <E>             a type of the event enrichment
     * @return an optional of the enrichment
     */
public static <E extends Message> Optional<E> getEnrichment(Class<E> enrichmentClass, EventContext context) {
    checkNotNull(enrichmentClass);
    checkNotNull(context);
    final Optional<Enrichment.Container> value = getEnrichments(context);
    if (!value.isPresent()) {
        return Optional.absent();
    }
    final Enrichment.Container enrichments = value.get();
    final String typeName = TypeName.of(enrichmentClass).value();
    final Any any = enrichments.getItemsMap().get(typeName);
    if (any == null) {
        return Optional.absent();
    }
    final E result = unpack(any);
    return Optional.fromNullable(result);
}
Also used : Any(com.google.protobuf.Any)

Aggregations

Any (com.google.protobuf.Any)212 Test (org.junit.Test)88 Message (com.google.protobuf.Message)45 TypeConverter.toAny (io.spine.protobuf.TypeConverter.toAny)27 EntityRecord (io.spine.server.entity.EntityRecord)24 TypeUrl (io.spine.type.TypeUrl)15 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)11 Version (io.spine.core.Version)11 Customer (io.spine.test.commandservice.customer.Customer)11 Truth.assertWithMessage (com.google.common.truth.Truth.assertWithMessage)10 CdsUpdate (io.grpc.xds.XdsClient.CdsUpdate)9 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 Query (io.spine.client.Query)7 Project (io.spine.test.storage.Project)7 FieldMask (com.google.protobuf.FieldMask)6 LbEndpoint (io.grpc.xds.Endpoints.LbEndpoint)6 EntityId (io.spine.client.EntityId)6