Search in sources :

Example 26 with Any

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

the class ProjectionStorageShould method checkProjectIdIsInList.

@SuppressWarnings("BreakStatement")
private static Project checkProjectIdIsInList(EntityRecord project, List<ProjectId> ids) {
    final Any packedState = project.getState();
    final Project state = AnyPacker.unpack(packedState);
    final ProjectId id = state.getId();
    boolean isIdPresent = false;
    for (ProjectId genericId : ids) {
        isIdPresent = genericId.equals(id);
        if (isIdPresent) {
            break;
        }
    }
    assertTrue(isIdPresent);
    return state;
}
Also used : Project(io.spine.test.storage.Project) ProjectId(io.spine.test.storage.ProjectId) Any(com.google.protobuf.Any)

Example 27 with Any

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

the class ProjectionStorageShould method fillStorage.

// Converter nullability issues
@SuppressWarnings("ConstantConditions")
private List<ProjectId> fillStorage(int count) {
    final List<ProjectId> ids = new LinkedList<>();
    for (int i = 0; i < count; i++) {
        final ProjectId id = newId();
        final Project state = Given.project(id, format("project-%d", i));
        final Any packedState = AnyPacker.pack(state);
        final EntityRecord rawRecord = EntityRecord.newBuilder().setState(packedState).setVersion(GivenVersion.withNumber(1)).build();
        final EntityRecordWithColumns record = withLifecycleColumns(rawRecord);
        storage.write(id, record);
        ids.add(id);
    }
    return ids;
}
Also used : EntityRecord(io.spine.server.entity.EntityRecord) Project(io.spine.test.storage.Project) ProjectId(io.spine.test.storage.ProjectId) Any(com.google.protobuf.Any) LinkedList(java.util.LinkedList) EntityRecordWithColumns(io.spine.server.entity.storage.EntityRecordWithColumns)

Example 28 with Any

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

the class ERepositoryShould method convert_type_query_to_EntityFilters.

@Test
public void convert_type_query_to_EntityFilters() {
    final String typeName = " com.example.EventType ";
    final EventFilter validFilter = filterForType(typeName);
    final EventFilter invalidFilter = filterForType("   ");
    final EventStreamQuery query = EventStreamQuery.newBuilder().addFilter(validFilter).addFilter(invalidFilter).build();
    final EntityFilters entityFilters = toEntityFilters(query);
    assertEquals(1, entityFilters.getFilterCount());
    final CompositeColumnFilter compositeFilter = entityFilters.getFilter(0);
    final List<ColumnFilter> columnFilters = compositeFilter.getFilterList();
    assertEquals(CompositeOperator.EITHER, compositeFilter.getOperator());
    assertEquals(1, columnFilters.size());
    final Any typeNameAsAny = columnFilters.get(0).getValue();
    assertEquals(typeName, toObject(typeNameAsAny, String.class));
}
Also used : CompositeColumnFilter(io.spine.client.CompositeColumnFilter) ERepository.toEntityFilters(io.spine.server.event.ERepository.toEntityFilters) EntityFilters(io.spine.client.EntityFilters) ColumnFilter(io.spine.client.ColumnFilter) CompositeColumnFilter(io.spine.client.CompositeColumnFilter) Any(com.google.protobuf.Any) Test(org.junit.Test)

Example 29 with Any

use of com.google.protobuf.Any 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();
                getStorage().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.core.Version) EntityUpdateOperation(io.spine.server.tenant.EntityUpdateOperation) TypeUrl(io.spine.type.TypeUrl) TypeConverter.toAny(io.spine.protobuf.TypeConverter.toAny) Any(com.google.protobuf.Any)

Example 30 with Any

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

the class SubscriptionRecord method matchByFilters.

private static boolean matchByFilters(Object id, EntityFilters filters) {
    final boolean result;
    final EntityIdFilter givenIdFilter = filters.getIdFilter();
    final boolean idFilterSet = !EntityIdFilter.getDefaultInstance().equals(givenIdFilter);
    if (idFilterSet) {
        final Any idAsAny = Identifier.pack(id);
        final EntityId givenEntityId = EntityId.newBuilder().setId(idAsAny).build();
        final List<EntityId> idsList = givenIdFilter.getIdsList();
        result = idsList.contains(givenEntityId);
    } else {
        result = false;
    }
    return result;
}
Also used : EntityId(io.spine.client.EntityId) EntityIdFilter(io.spine.client.EntityIdFilter) 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