use of io.spine.client.EntityIdFilter in project core-java by SpineEventEngine.
the class EntityQueriesShould method construct_non_empty_queries.
@Test
public void construct_non_empty_queries() {
final Message someGenericId = Sample.messageOfType(ProjectId.class);
final Any someId = AnyPacker.pack(someGenericId);
final EntityId entityId = EntityId.newBuilder().setId(someId).build();
final EntityIdFilter idFilter = EntityIdFilter.newBuilder().addIds(entityId).build();
final Version versionValue = Version.newBuilder().setNumber(1).build();
final BoolValue archivedValue = BoolValue.newBuilder().setValue(true).build();
final ColumnFilter versionFilter = ColumnFilters.eq(version.name(), versionValue);
final ColumnFilter archivedFilter = ColumnFilters.eq(archived.name(), archivedValue);
final CompositeColumnFilter aggregatingFilter = CompositeColumnFilter.newBuilder().addFilter(versionFilter).addFilter(archivedFilter).setOperator(EITHER).build();
final EntityFilters filters = EntityFilters.newBuilder().setIdFilter(idFilter).addFilter(aggregatingFilter).build();
final EntityQuery<?> query = createEntityQuery(filters, AbstractVersionableEntity.class);
assertNotNull(query);
final Collection<?> ids = query.getIds();
assertFalse(ids.isEmpty());
assertSize(1, ids);
final Object singleId = ids.iterator().next();
assertEquals(someGenericId, singleId);
final List<CompositeQueryParameter> values = newArrayList(query.getParameters());
assertSize(1, values);
final CompositeQueryParameter singleParam = values.get(0);
final Collection<ColumnFilter> columnFilters = singleParam.getFilters().values();
assertEquals(EITHER, singleParam.getOperator());
assertContains(versionFilter, columnFilters);
assertContains(archivedFilter, columnFilters);
}
use of io.spine.client.EntityIdFilter in project core-java by SpineEventEngine.
the class EntityQueries method toGenericIdValues.
private static <I> Collection<I> toGenericIdValues(EntityFilters entityFilters) {
final EntityIdFilter idFilter = entityFilters.getIdFilter();
final Collection<I> ids = new LinkedList<>();
for (EntityId entityId : idFilter.getIdsList()) {
final Any wrappedMessageId = entityId.getId();
final I genericId = Identifier.unpack(wrappedMessageId);
ids.add(genericId);
}
return ids;
}
use of io.spine.client.EntityIdFilter in project core-java by SpineEventEngine.
the class RecordStorageShould method filter_archived_or_deleted_records_on_by_ID_bulk_read.
@Test
public void filter_archived_or_deleted_records_on_by_ID_bulk_read() {
final I activeId = newId();
final I archivedId = newId();
final I deletedId = newId();
final TestCounterEntity<I> activeEntity = new TestCounterEntity<>(activeId);
final TestCounterEntity<I> archivedEntity = new TestCounterEntity<>(archivedId);
archivedEntity.archive();
final TestCounterEntity<I> deletedEntity = new TestCounterEntity<>(deletedId);
deletedEntity.delete();
final EntityRecord activeRecord = newStorageRecord(activeId, activeEntity.getState());
final EntityRecord archivedRecord = newStorageRecord(archivedId, archivedEntity.getState());
final EntityRecord deletedRecord = newStorageRecord(deletedId, deletedEntity.getState());
final RecordStorage<I> storage = getStorage();
storage.write(deletedId, create(deletedRecord, deletedEntity, storage));
storage.write(activeId, create(activeRecord, activeEntity, storage));
storage.write(archivedId, create(archivedRecord, archivedEntity, storage));
final EntityIdFilter idFilter = EntityIdFilter.newBuilder().addIds(toEntityId(activeId)).addIds(toEntityId(archivedId)).addIds(toEntityId(deletedId)).build();
final EntityFilters filters = EntityFilters.newBuilder().setIdFilter(idFilter).build();
final EntityQuery<I> query = EntityQueries.<I>from(filters, storage).withLifecycleFlags(storage);
final Iterator<EntityRecord> read = storage.readAll(query, FieldMask.getDefaultInstance());
assertSingleRecord(activeRecord, read);
}
use of io.spine.client.EntityIdFilter in project core-java by SpineEventEngine.
the class RecordStorageShould method allow_by_single_id_queries_with_no_columns.
@Test
public void allow_by_single_id_queries_with_no_columns() {
// Create the test data
final I idMatching = newId();
final I idWrong1 = newId();
final I idWrong2 = newId();
final TestCounterEntity<I> matchingEntity = new TestCounterEntity<>(idMatching);
final TestCounterEntity<I> wrongEntity1 = new TestCounterEntity<>(idWrong1);
final TestCounterEntity<I> wrongEntity2 = new TestCounterEntity<>(idWrong2);
final EntityRecord fineRecord = newStorageRecord(idMatching, newState(idMatching));
final EntityRecord notFineRecord1 = newStorageRecord(idWrong1, newState(idWrong1));
final EntityRecord notFineRecord2 = newStorageRecord(idWrong2, newState(idWrong2));
final RecordStorage<I> storage = getStorage();
final EntityRecordWithColumns recordRight = create(fineRecord, matchingEntity, storage);
final EntityRecordWithColumns recordWrong1 = create(notFineRecord1, wrongEntity1, storage);
final EntityRecordWithColumns recordWrong2 = create(notFineRecord2, wrongEntity2, storage);
// Fill the storage
storage.write(idWrong1, recordWrong1);
storage.write(idMatching, recordRight);
storage.write(idWrong2, recordWrong2);
// Prepare the query
final Any matchingIdPacked = TypeConverter.toAny(idMatching);
final EntityId entityId = EntityId.newBuilder().setId(matchingIdPacked).build();
final EntityIdFilter idFilter = EntityIdFilter.newBuilder().addIds(entityId).build();
final EntityFilters filters = EntityFilters.newBuilder().setIdFilter(idFilter).build();
final EntityQuery<I> query = EntityQueries.from(filters, storage);
// Perform the query
final Iterator<EntityRecord> readRecords = storage.readAll(query, FieldMask.getDefaultInstance());
// Check results
assertSingleRecord(fineRecord, readRecords);
}
Aggregations