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