use of io.spine.client.CompositeColumnFilter in project core-java by SpineEventEngine.
the class RecordBasedRepositoryShould method allow_any_lifecycle_if_column_involved.
@Test
public void allow_any_lifecycle_if_column_involved() {
final I archivedId = createId(42);
final I deletedId = createId(314);
final I activeId = createId(271);
final E activeEntity = repository.create(activeId);
final E archivedEntity = repository.create(archivedId);
final E deletedEntity = repository.create(deletedId);
delete((EventPlayingEntity) deletedEntity);
archive((EventPlayingEntity) archivedEntity);
// Fill the storage
repository.store(activeEntity);
repository.store(archivedEntity);
repository.store(deletedEntity);
final CompositeColumnFilter columnFilter = all(eq(archived.name(), false));
final EntityFilters filters = EntityFilters.newBuilder().addFilter(columnFilter).build();
final Iterator<E> found = repository.find(filters, FieldMask.getDefaultInstance());
final Collection<E> foundList = newArrayList(found);
// Check result
assertSize(2, foundList);
assertContainsAll(foundList, activeEntity, deletedEntity);
}
use of io.spine.client.CompositeColumnFilter 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));
}
use of io.spine.client.CompositeColumnFilter in project core-java by SpineEventEngine.
the class RecordStorageShould method filter_records_by_columns.
// Complex test case (still tests a single operation)
@SuppressWarnings("OverlyLongMethod")
@Test
public void filter_records_by_columns() {
final Project.Status requiredValue = DONE;
final Int32Value wrappedValue = Int32Value.newBuilder().setValue(requiredValue.getNumber()).build();
final Version versionValue = Version.newBuilder().setNumber(// Value of the counter after one columns
2).build();
final ColumnFilter status = eq("projectStatusValue", wrappedValue);
final ColumnFilter version = eq("counterVersion", versionValue);
final CompositeColumnFilter aggregatingFilter = CompositeColumnFilter.newBuilder().setOperator(ALL).addFilter(status).addFilter(version).build();
final EntityFilters filters = EntityFilters.newBuilder().addFilter(aggregatingFilter).build();
final RecordStorage<I> storage = getStorage();
final EntityQuery<I> query = EntityQueries.from(filters, storage);
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);
// 2 of 3 have required values
matchingEntity.setStatus(requiredValue);
wrongEntity1.setStatus(requiredValue);
wrongEntity2.setStatus(CANCELLED);
// Change internal Entity state
wrongEntity1.getCounter();
// After the mutation above the single matching record is the one under the `idMatching` ID
final EntityRecord fineRecord = newStorageRecord(idMatching, newState(idMatching));
final EntityRecord notFineRecord1 = newStorageRecord(idWrong1, newState(idWrong1));
final EntityRecord notFineRecord2 = newStorageRecord(idWrong2, newState(idWrong2));
final EntityRecordWithColumns recordRight = create(fineRecord, matchingEntity, storage);
final EntityRecordWithColumns recordWrong1 = create(notFineRecord1, wrongEntity1, storage);
final EntityRecordWithColumns recordWrong2 = create(notFineRecord2, wrongEntity2, storage);
storage.write(idMatching, recordRight);
storage.write(idWrong1, recordWrong1);
storage.write(idWrong2, recordWrong2);
final Iterator<EntityRecord> readRecords = storage.readAll(query, FieldMask.getDefaultInstance());
assertSingleRecord(fineRecord, readRecords);
}
use of io.spine.client.CompositeColumnFilter in project core-java by SpineEventEngine.
the class RecordStorageShould method read_both_by_columns_and_IDs.
@Test
public void read_both_by_columns_and_IDs() {
final I targetId = newId();
final TestCounterEntity<I> targetEntity = new TestCounterEntity<>(targetId);
final TestCounterEntity<I> noMatchEntity = new TestCounterEntity<>(newId());
final TestCounterEntity<I> noMatchIdEntity = new TestCounterEntity<>(newId());
final TestCounterEntity<I> deletedEntity = new TestCounterEntity<>(newId());
targetEntity.setStatus(CANCELLED);
deletedEntity.setStatus(CANCELLED);
deletedEntity.delete();
noMatchIdEntity.setStatus(CANCELLED);
noMatchEntity.setStatus(DONE);
write(targetEntity);
write(noMatchEntity);
write(noMatchIdEntity);
write(deletedEntity);
final EntityIdFilter idFilter = EntityIdFilter.newBuilder().addIds(toEntityId(targetId)).build();
final CompositeColumnFilter columnFilter = all(eq("projectStatusValue", CANCELLED.getNumber()));
final EntityFilters filters = EntityFilters.newBuilder().setIdFilter(idFilter).addFilter(columnFilter).build();
final RecordStorage<I> storage = getStorage();
final EntityQuery<I> query = EntityQueries.<I>from(filters, storage).withLifecycleFlags(storage);
final Iterator<EntityRecord> read = storage.readAll(query, FieldMask.getDefaultInstance());
final List<EntityRecord> readRecords = newArrayList(read);
assertEquals(1, readRecords.size());
final EntityRecord readRecord = readRecords.get(0);
assertEquals(targetEntity.getState(), unpack(readRecord.getState()));
assertEquals(targetId, Identifier.unpack(readRecord.getEntityId()));
}
use of io.spine.client.CompositeColumnFilter in project core-java by SpineEventEngine.
the class EntityQueries method splitFilters.
private static Multimap<EntityColumn, ColumnFilter> splitFilters(CompositeColumnFilter filter, Collection<EntityColumn> entityColumns) {
final Multimap<EntityColumn, ColumnFilter> columnFilters = create(filter.getFilterCount(), 1);
for (ColumnFilter columnFilter : filter.getFilterList()) {
final EntityColumn column = findMatchingColumn(columnFilter, entityColumns);
checkFilterType(column, columnFilter);
columnFilters.put(column, columnFilter);
}
return columnFilters;
}
Aggregations