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;
}
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;
}
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;
}
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();
}
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);
}
Aggregations