Search in sources :

Example 1 with CompositeColumnFilter

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);
}
Also used : CompositeColumnFilter(io.spine.client.CompositeColumnFilter) EntityFilters(io.spine.client.EntityFilters) TenantAwareTest(io.spine.server.tenant.TenantAwareTest) Test(org.junit.Test)

Example 2 with CompositeColumnFilter

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));
}
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 3 with CompositeColumnFilter

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);
}
Also used : CompositeColumnFilter(io.spine.client.CompositeColumnFilter) EntityFilters(io.spine.client.EntityFilters) CompositeColumnFilter(io.spine.client.CompositeColumnFilter) ColumnFilter(io.spine.client.ColumnFilter) EntityRecordWithColumns(io.spine.server.entity.storage.EntityRecordWithColumns) EntityRecord(io.spine.server.entity.EntityRecord) Project(io.spine.test.storage.Project) GivenVersion(io.spine.core.given.GivenVersion) Version(io.spine.core.Version) Int32Value(com.google.protobuf.Int32Value) Test(org.junit.Test)

Example 4 with CompositeColumnFilter

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()));
}
Also used : CompositeColumnFilter(io.spine.client.CompositeColumnFilter) EntityRecord(io.spine.server.entity.EntityRecord) EntityIdFilter(io.spine.client.EntityIdFilter) EntityFilters(io.spine.client.EntityFilters) Test(org.junit.Test)

Example 5 with CompositeColumnFilter

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;
}
Also used : CompositeColumnFilter(io.spine.client.CompositeColumnFilter) ColumnFilter(io.spine.client.ColumnFilter)

Aggregations

CompositeColumnFilter (io.spine.client.CompositeColumnFilter)14 ColumnFilter (io.spine.client.ColumnFilter)12 EntityFilters (io.spine.client.EntityFilters)10 Test (org.junit.Test)10 EntityRecord (io.spine.server.entity.EntityRecord)3 Any (com.google.protobuf.Any)2 Int32Value (com.google.protobuf.Int32Value)2 EntityIdFilter (io.spine.client.EntityIdFilter)2 Version (io.spine.core.Version)2 EntityRecordWithColumns (io.spine.server.entity.storage.EntityRecordWithColumns)2 ERepository.toEntityFilters (io.spine.server.event.ERepository.toEntityFilters)2 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)2 Project (io.spine.test.storage.Project)2 BoolValue (com.google.protobuf.BoolValue)1 FieldMask (com.google.protobuf.FieldMask)1 Message (com.google.protobuf.Message)1 StringValue (com.google.protobuf.StringValue)1 Timestamp (com.google.protobuf.Timestamp)1 CompositeOperator (io.spine.client.CompositeColumnFilter.CompositeOperator)1 EntityId (io.spine.client.EntityId)1