Search in sources :

Example 96 with Any

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

the class EntityQueryProcessor method process.

@Override
public ImmutableCollection<Any> process(Query query) {
    final ImmutableList.Builder<Any> resultBuilder = ImmutableList.builder();
    final Target target = query.getTarget();
    final FieldMask fieldMask = query.getFieldMask();
    final ImmutableCollection<? extends Entity> entities;
    if (target.getIncludeAll() && fieldMask.getPathsList().isEmpty()) {
        entities = repository.loadAll();
    } else {
        final EntityFilters filters = target.getFilters();
        entities = repository.find(filters, fieldMask);
    }
    for (Entity entity : entities) {
        final Message state = entity.getState();
        final Any packedState = AnyPacker.pack(state);
        resultBuilder.add(packedState);
    }
    final ImmutableList<Any> result = resultBuilder.build();
    return result;
}
Also used : Entity(io.spine.server.entity.Entity) Target(io.spine.client.Target) Message(com.google.protobuf.Message) ImmutableList(com.google.common.collect.ImmutableList) EntityFilters(io.spine.client.EntityFilters) Any(com.google.protobuf.Any) FieldMask(com.google.protobuf.FieldMask)

Example 97 with Any

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

the class AggregateQueryProcessor method process.

@Override
public ImmutableCollection<Any> process(Query query) {
    final ImmutableList.Builder<Any> resultBuilder = ImmutableList.builder();
    ImmutableCollection<EntityRecord> stateRecords;
    final Target target = query.getTarget();
    final FieldMask fieldMask = query.getFieldMask();
    final boolean shouldApplyFieldMask = !fieldMask.getPathsList().isEmpty();
    if (target.getIncludeAll()) {
        stateRecords = shouldApplyFieldMask ? standStorage.readAllByType(type, fieldMask) : standStorage.readAllByType(type);
    } else {
        stateRecords = doFetchWithFilters(target, fieldMask);
    }
    for (EntityRecord record : stateRecords) {
        final Any state = record.getState();
        resultBuilder.add(state);
    }
    final ImmutableList<Any> result = resultBuilder.build();
    return result;
}
Also used : EntityRecord(io.spine.server.entity.EntityRecord) Target(io.spine.client.Target) ImmutableList(com.google.common.collect.ImmutableList) Any(com.google.protobuf.Any) FieldMask(com.google.protobuf.FieldMask)

Example 98 with Any

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

the class MultiTenantStandShould method not_trigger_updates_of_aggregate_records_for_another_tenant_subscriptions.

@Test
public void not_trigger_updates_of_aggregate_records_for_another_tenant_subscriptions() {
    final StandStorage standStorage = InMemoryStorageFactory.getInstance(isMultitenant()).createStandStorage();
    final Stand stand = prepareStandWithAggregateRepo(standStorage);
    // --- Default Tenant
    final ActorRequestFactory requestFactory = getRequestFactory();
    final MemoizeEntityUpdateCallback defaultTenantCallback = subscribeToAllOf(stand, requestFactory, Customer.class);
    // --- Another Tenant
    final TenantId anotherTenant = newTenantUuid();
    final ActorRequestFactory anotherFactory = createRequestFactory(anotherTenant);
    final MemoizeEntityUpdateCallback anotherCallback = subscribeToAllOf(stand, anotherFactory, Customer.class);
    // Trigger updates in Default Tenant.
    final Map.Entry<CustomerId, Customer> sampleData = fillSampleCustomers(1).entrySet().iterator().next();
    final CustomerId customerId = sampleData.getKey();
    final Customer customer = sampleData.getValue();
    final Version stateVersion = Tests.newVersionWithNumber(1);
    stand.update(asEnvelope(customerId, customer, stateVersion));
    final Any packedState = AnyPacker.pack(customer);
    // Verify that Default Tenant callback has got the update.
    assertEquals(packedState, defaultTenantCallback.getNewEntityState());
    // And Another Tenant callback has not been called.
    assertEquals(null, anotherCallback.getNewEntityState());
}
Also used : TenantId(io.spine.users.TenantId) Customer(io.spine.test.commandservice.customer.Customer) Version(io.spine.base.Version) StandStorage(io.spine.server.stand.StandStorage) ActorRequestFactory(io.spine.client.ActorRequestFactory) CustomerId(io.spine.test.commandservice.customer.CustomerId) Map(java.util.Map) Any(com.google.protobuf.Any) Test(org.junit.Test)

Example 99 with Any

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

the class StandShould method trigger_subscription_callback_upon_update_of_aggregate.

@Test
public void trigger_subscription_callback_upon_update_of_aggregate() {
    final Stand stand = prepareStandWithAggregateRepo(mock(StandStorage.class));
    final Topic allCustomers = requestFactory.topic().allOf(Customer.class);
    final MemoizeEntityUpdateCallback memoizeCallback = new MemoizeEntityUpdateCallback();
    subscribeAndActivate(stand, allCustomers, memoizeCallback);
    assertNull(memoizeCallback.newEntityState);
    final Map.Entry<CustomerId, Customer> sampleData = fillSampleCustomers(1).entrySet().iterator().next();
    final CustomerId customerId = sampleData.getKey();
    final Customer customer = sampleData.getValue();
    final Version stateVersion = Tests.newVersionWithNumber(1);
    stand.update(asEnvelope(customerId, customer, stateVersion));
    final Any packedState = AnyPacker.pack(customer);
    assertEquals(packedState, memoizeCallback.newEntityState);
}
Also used : Customer(io.spine.test.commandservice.customer.Customer) Version(io.spine.base.Version) StandStorage(io.spine.server.stand.StandStorage) CustomerId(io.spine.test.commandservice.customer.CustomerId) Topic(io.spine.client.Topic) Map(java.util.Map) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) Any(com.google.protobuf.Any) Test(org.junit.Test) TenantAwareTest(io.spine.server.tenant.TenantAwareTest)

Example 100 with Any

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

the class StandShould method checkEmptyResultForTargetOnEmptyStorage.

private void checkEmptyResultForTargetOnEmptyStorage(Query readCustomersQuery) {
    final StandStorage standStorageMock = mock(StandStorage.class);
    // Return an empty collection on {@link StandStorage#readAllByType(TypeUrl)} call.
    final ImmutableList<EntityRecord> emptyResultList = ImmutableList.<EntityRecord>builder().build();
    when(standStorageMock.readAllByType(any(TypeUrl.class))).thenReturn(emptyResultList);
    final Stand stand = prepareStandWithAggregateRepo(standStorageMock);
    final MemoizeQueryResponseObserver responseObserver = new MemoizeQueryResponseObserver();
    stand.execute(readCustomersQuery, responseObserver);
    final List<Any> messageList = checkAndGetMessageList(responseObserver);
    assertTrue("Query returned a non-empty response message list though the target was empty", messageList.isEmpty());
}
Also used : EntityRecord(io.spine.server.entity.EntityRecord) StandStorage(io.spine.server.stand.StandStorage) TypeUrl(io.spine.type.TypeUrl) Any(com.google.protobuf.Any)

Aggregations

Any (com.google.protobuf.Any)117 Test (org.junit.Test)40 Message (com.google.protobuf.Message)25 EntityRecord (io.spine.server.entity.EntityRecord)19 Version (io.spine.base.Version)13 Customer (io.spine.test.commandservice.customer.Customer)13 TypeUrl (io.spine.type.TypeUrl)13 StandStorage (io.spine.server.stand.StandStorage)12 Query (io.spine.client.Query)10 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)10 CustomerId (io.spine.test.commandservice.customer.CustomerId)10 Map (java.util.Map)8 FieldMask (com.google.protobuf.FieldMask)7 EntityFilters (io.spine.client.EntityFilters)7 EntityId (io.spine.client.EntityId)7 Target (io.spine.client.Target)7 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)6 Identifiers.idToAny (io.spine.base.Identifiers.idToAny)6 QueryResponse (io.spine.client.QueryResponse)6 EntityIdFilter (io.spine.client.EntityIdFilter)5