Search in sources :

Example 11 with TypeUrl

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

the class SubscriptionService method selectBoundedContext.

private BoundedContext selectBoundedContext(Subscription subscription) {
    final TypeName typeName = TypeName.of(subscription.getTopic().getTarget().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 12 with TypeUrl

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

the class Stand method update.

/**
     * Updates the state of an entity inside of the current instance of {@code Stand}.
     *
     * <p>In case the entity update represents the new
     * {@link io.spine.server.aggregate.Aggregate Aggregate} state,
     * store the new value for the {@code Aggregate} to each of the configured instances of
     * {@link StandStorage}.
     *
     * <p>Each {@code Aggregate} state value is stored as one-to-one to its
     * {@link TypeUrl TypeUrl} obtained via {@link Any#getTypeUrl()}.
     *
     * <p>In case {@code Stand} already contains the state for this {@code Aggregate},
     * the value will be replaced.
     *
     * <p>The state updates which are not originated from the {@code Aggregate} are not
     * stored in the {@code Stand}.
     *
     * <p>In any case, the state update is then propagated to the callbacks.
     * The set of matched callbacks is determined by filtering all the registered callbacks
     * by the entity {@code TypeUrl}.
     *
     * <p>The matching callbacks are executed with the {@link #callbackExecutor}.
     *
     * @param envelope the updated entity state,
     *                 packed as {@linkplain EntityStateEnvelope envelope}
     */
void update(final EntityStateEnvelope<?, ?> envelope) {
    final EntityUpdateOperation op = new EntityUpdateOperation(envelope) {

        @Override
        public void run() {
            final Object id = envelope.getEntityId();
            final Message entityState = envelope.getMessage();
            final Any packedState = AnyPacker.pack(entityState);
            final TypeUrl entityTypeUrl = TypeUrl.of(entityState);
            final boolean aggregateUpdate = typeRegistry.hasAggregateType(entityTypeUrl);
            if (aggregateUpdate) {
                final Optional<Version> entityVersion = envelope.getEntityVersion();
                checkState(entityVersion.isPresent(), "The aggregate version must be set in order to update Stand. " + "Actual envelope: {}", envelope);
                // checked above.
                @SuppressWarnings("OptionalGetWithoutIsPresent") final Version versionValue = entityVersion.get();
                final AggregateStateId aggregateStateId = AggregateStateId.of(id, entityTypeUrl);
                final EntityRecord record = EntityRecord.newBuilder().setState(packedState).setVersion(versionValue).build();
                storage.write(aggregateStateId, record);
            }
            notifyMatchingSubscriptions(id, packedState, entityTypeUrl);
        }
    };
    op.execute();
}
Also used : EntityRecord(io.spine.server.entity.EntityRecord) Message(com.google.protobuf.Message) Version(io.spine.base.Version) EntityUpdateOperation(io.spine.server.tenant.EntityUpdateOperation) TypeUrl(io.spine.type.TypeUrl) Any(com.google.protobuf.Any)

Example 13 with TypeUrl

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

the class AbstractTargetValidator method checkTargetSupported.

boolean checkTargetSupported(Target target) {
    final TypeUrl typeUrl = getTypeOf(target);
    final boolean result = typeRegistry.getTypes().contains(typeUrl);
    return result;
}
Also used : TypeUrl(io.spine.type.TypeUrl)

Example 14 with TypeUrl

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

the class AggregateStateIdStringifier method fromString.

@Override
protected AggregateStateId fromString(String s) {
    checkNotNull(s);
    final int typeUrlEndIndex = s.indexOf(DIVIDER);
    checkArgument(typeUrlEndIndex > 0, "Passed string does not contain a type URL.");
    final String typeUrlString = s.substring(0, typeUrlEndIndex);
    final TypeUrl typeUrl = TypeUrl.parse(typeUrlString);
    final int idTypeStartIndex = typeUrlEndIndex + 1;
    final int idTypeEndIndex = s.indexOf(DIVIDER, idTypeStartIndex);
    checkArgument(idTypeEndIndex > 0, "Passed string does not contain the ID type.");
    final String idTypeString = s.substring(idTypeStartIndex, idTypeEndIndex);
    final Class idType = idTypeFromString(idTypeString);
    final String idStringValue = s.substring(idTypeEndIndex + 1);
    final Object genericId = Stringifiers.fromString(idStringValue, idType);
    final AggregateStateId result = AggregateStateId.of(genericId, typeUrl);
    return result;
}
Also used : TypeUrl(io.spine.type.TypeUrl)

Example 15 with TypeUrl

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

the class StandShould method doCheckReadingCustomersById.

@CanIgnoreReturnValue
Stand doCheckReadingCustomersById(int numberOfCustomers) {
    // Define the types and values used as a test data.
    final TypeUrl customerType = TypeUrl.of(Customer.class);
    final Map<CustomerId, Customer> sampleCustomers = fillSampleCustomers(numberOfCustomers);
    // Prepare the stand and its storage to act.
    final StandStorage standStorage = setupStandStorageWithCustomers(sampleCustomers, customerType);
    final Stand stand = prepareStandWithAggregateRepo(standStorage);
    triggerMultipleUpdates(sampleCustomers, stand);
    final Query readMultipleCustomers = requestFactory.query().byIds(Customer.class, sampleCustomers.keySet());
    final MemoizeQueryResponseObserver responseObserver = new MemoizeQueryResponseObserver();
    stand.execute(readMultipleCustomers, responseObserver);
    final List<Any> messageList = checkAndGetMessageList(responseObserver);
    assertEquals(sampleCustomers.size(), messageList.size());
    final Collection<Customer> allCustomers = sampleCustomers.values();
    for (Any singleRecord : messageList) {
        final Customer unpackedSingleResult = AnyPacker.unpack(singleRecord);
        assertTrue(allCustomers.contains(unpackedSingleResult));
    }
    return stand;
}
Also used : Query(io.spine.client.Query) Customer(io.spine.test.commandservice.customer.Customer) StandStorage(io.spine.server.stand.StandStorage) TypeUrl(io.spine.type.TypeUrl) CustomerId(io.spine.test.commandservice.customer.CustomerId) Any(com.google.protobuf.Any) CanIgnoreReturnValue(com.google.errorprone.annotations.CanIgnoreReturnValue)

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