Search in sources :

Example 26 with TypeUrl

use of io.spine.type.TypeUrl in project core-java by SpineEventEngine.

the class SubscriptionService method selectBoundedContext.

private BoundedContext selectBoundedContext(Target target) {
    final TypeName typeName = TypeName.of(target.getType());
    final TypeUrl type = typeName.toUrl();
    final BoundedContext result = typeToContextMap.get(type);
    return result;
}
Also used : TypeName(io.spine.type.TypeName) TypeUrl(io.spine.type.TypeUrl)

Example 27 with TypeUrl

use of io.spine.type.TypeUrl in project core-java by SpineEventEngine.

the class DefaultEntityStorageConverter method doBackward.

@Override
@SuppressWarnings("unchecked")
protected E doBackward(EntityRecord entityRecord) {
    final Message unpacked = unpack(entityRecord.getState());
    final TypeUrl entityStateType = repository.getEntityStateType();
    final S state = (S) FieldMasks.applyMask(fieldMask, unpacked, entityStateType);
    final I id = (I) idFromAny(entityRecord.getEntityId());
    final E entity = repository.create(id);
    if (entity != null) {
        if (entity instanceof AbstractVersionableEntity) {
            final AbstractVersionableEntity versionable = (AbstractVersionableEntity) entity;
            if (versionable instanceof EventPlayingEntity) {
                final EventPlayingEntity playingEntity = (EventPlayingEntity) versionable;
                playingEntity.injectState(state, entityRecord.getVersion());
            } else {
                versionable.updateState(state, entityRecord.getVersion());
            }
            versionable.setLifecycleFlags(entityRecord.getLifecycleFlags());
        } else {
            entity.injectState(state);
        }
    }
    return entity;
}
Also used : Message(com.google.protobuf.Message) TypeUrl(io.spine.type.TypeUrl)

Example 28 with TypeUrl

use of io.spine.type.TypeUrl in project core-java by SpineEventEngine.

the class Queries method typeOf.

/**
     * Extract the type of {@link Target} for the given {@link Query}.
     *
     * <p>Returns null if the {@code Target} type is unknown to the application.
     *
     * @param query the query of interest.
     * @return the URL of the type of the query {@linkplain Query#getTarget() target}
     */
public static TypeUrl typeOf(Query query) {
    checkNotNull(query);
    final Target target = query.getTarget();
    final TypeName typeName = TypeName.of(target.getType());
    final TypeUrl type = typeName.toUrl();
    return type;
}
Also used : Targets.composeTarget(io.spine.client.Targets.composeTarget) TypeName(io.spine.type.TypeName) TypeUrl(io.spine.type.TypeUrl)

Example 29 with TypeUrl

use of io.spine.type.TypeUrl in project core-java by SpineEventEngine.

the class Json method buildForKnownTypes.

/**
     * Builds the registry of types known in the application.
     */
private static JsonFormat.TypeRegistry buildForKnownTypes() {
    final JsonFormat.TypeRegistry.Builder builder = JsonFormat.TypeRegistry.newBuilder();
    for (TypeUrl typeUrl : KnownTypes.getAllUrls()) {
        final Descriptors.GenericDescriptor genericDescriptor = typeUrl.getDescriptor();
        if (genericDescriptor instanceof Descriptor) {
            final Descriptor descriptor = (Descriptor) genericDescriptor;
            builder.add(descriptor);
        }
    }
    return builder.build();
}
Also used : Descriptor(com.google.protobuf.Descriptors.Descriptor) TypeUrl(io.spine.type.TypeUrl) Descriptors(com.google.protobuf.Descriptors)

Example 30 with TypeUrl

use of io.spine.type.TypeUrl in project core-java by SpineEventEngine.

the class AnyPacker method unpack.

/**
     * Unwraps {@code Any} value into an instance of type specified by value
     * returned by {@link Any#getTypeUrl()}.
     *
     *
     * @param any instance of {@link Any} that should be unwrapped
     * @param <T> the type enclosed into {@code Any}
     * @return unwrapped message instance
     */
public static <T extends Message> T unpack(Any any) {
    checkNotNull(any);
    final TypeUrl typeUrl = TypeUrl.ofEnclosed(any);
    final Class<T> messageClass = typeUrl.getJavaClass();
    return unpack(any, messageClass);
}
Also used : TypeUrl(io.spine.type.TypeUrl)

Aggregations

TypeUrl (io.spine.type.TypeUrl)37 Any (com.google.protobuf.Any)12 Test (org.junit.Test)11 EntityRecord (io.spine.server.entity.EntityRecord)7 Message (com.google.protobuf.Message)6 StandStorage (io.spine.server.stand.StandStorage)4 EntityRecordWithColumns (io.spine.server.entity.storage.EntityRecordWithColumns)3 ClassName (io.spine.type.ClassName)3 TypeName (io.spine.type.TypeName)3 Descriptors (com.google.protobuf.Descriptors)2 Version (io.spine.base.Version)2 Query (io.spine.client.Query)2 BoundedContext (io.spine.server.BoundedContext)2 StandTestProjectionRepository (io.spine.server.stand.Given.StandTestProjectionRepository)2 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)2 Customer (io.spine.test.commandservice.customer.Customer)2 CustomerId (io.spine.test.commandservice.customer.CustomerId)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)1 CanIgnoreReturnValue (com.google.errorprone.annotations.CanIgnoreReturnValue)1