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());
}
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);
}
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;
}
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} — a Json form;
* <li>for {@code String}, {@code Long}, {@code Integer} —
* the result of {@link Object#toString()};
* <li>for {@code null} ID — the {@link #NULL_ID};
* <li>if the result is empty or blank string — 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;
}
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);
}
Aggregations