Search in sources :

Example 11 with CompositeColumnFilter

use of io.spine.client.CompositeColumnFilter in project core-java by SpineEventEngine.

the class EntityQueriesShould method not_create_query_for_non_existing_column.

@Test(expected = IllegalArgumentException.class)
public void not_create_query_for_non_existing_column() {
    final ColumnFilter filter = ColumnFilters.eq("nonExistingColumn", 42);
    final CompositeColumnFilter compositeFilter = ColumnFilters.all(filter);
    final EntityFilters filters = EntityFilters.newBuilder().addFilter(compositeFilter).build();
    createEntityQuery(filters, AbstractVersionableEntity.class);
}
Also used : CompositeColumnFilter(io.spine.client.CompositeColumnFilter) EntityFilters(io.spine.client.EntityFilters) ColumnFilter(io.spine.client.ColumnFilter) CompositeColumnFilter(io.spine.client.CompositeColumnFilter) Test(org.junit.Test)

Example 12 with CompositeColumnFilter

use of io.spine.client.CompositeColumnFilter in project core-java by SpineEventEngine.

the class ERepositoryShould method convert_time_query_to_EntityFilters.

@Test
public void convert_time_query_to_EntityFilters() {
    final EventStreamQuery query = EventStreamQuery.newBuilder().setAfter(Timestamps.MIN_VALUE).setBefore(Timestamps.MAX_VALUE).build();
    final EntityFilters entityFilters = toEntityFilters(query);
    assertEquals(1, entityFilters.getFilterCount());
    final CompositeColumnFilter compositeFilter = entityFilters.getFilter(0);
    final List<ColumnFilter> columnFilters = compositeFilter.getFilterList();
    assertEquals(CompositeOperator.ALL, compositeFilter.getOperator());
    assertEquals(2, columnFilters.size());
}
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) Test(org.junit.Test)

Example 13 with CompositeColumnFilter

use of io.spine.client.CompositeColumnFilter in project core-java by SpineEventEngine.

the class ERepository method typeFilter.

private static Optional<CompositeColumnFilter> typeFilter(EventStreamQuery query) {
    final CompositeColumnFilter.Builder typeFilter = CompositeColumnFilter.newBuilder().setOperator(EITHER);
    for (EventFilter eventFilter : query.getFilterList()) {
        final String type = eventFilter.getEventType();
        if (!type.trim().isEmpty()) {
            final ColumnFilter filter = eq(TYPE_COLUMN, type);
            typeFilter.addFilter(filter);
        }
    }
    return buildFilter(typeFilter);
}
Also used : CompositeColumnFilter(io.spine.client.CompositeColumnFilter) ColumnFilter(io.spine.client.ColumnFilter) CompositeColumnFilter(io.spine.client.CompositeColumnFilter)

Example 14 with CompositeColumnFilter

use of io.spine.client.CompositeColumnFilter in project core-java by SpineEventEngine.

the class RecordStorageShould method update_entity_column_values.

@Test
public void update_entity_column_values() {
    final Project.Status initialStatus = DONE;
    // is used for documentation purposes.
    @SuppressWarnings("UnnecessaryLocalVariable") final Project.Status statusAfterUpdate = CANCELLED;
    final Int32Value initialStatusValue = Int32Value.newBuilder().setValue(initialStatus.getNumber()).build();
    final ColumnFilter status = eq("projectStatusValue", initialStatusValue);
    final CompositeColumnFilter aggregatingFilter = CompositeColumnFilter.newBuilder().setOperator(ALL).addFilter(status).build();
    final EntityFilters filters = EntityFilters.newBuilder().addFilter(aggregatingFilter).build();
    final RecordStorage<I> storage = getStorage();
    final EntityQuery<I> query = EntityQueries.from(filters, storage);
    final I id = newId();
    final TestCounterEntity<I> entity = new TestCounterEntity<>(id);
    entity.setStatus(initialStatus);
    final EntityRecord record = newStorageRecord(id, newState(id));
    final EntityRecordWithColumns recordWithColumns = create(record, entity, storage);
    final FieldMask fieldMask = FieldMask.getDefaultInstance();
    // Create the record.
    storage.write(id, recordWithColumns);
    final Iterator<EntityRecord> recordsBefore = storage.readAll(query, fieldMask);
    assertSingleRecord(record, recordsBefore);
    // Update the entity columns of the record.
    entity.setStatus(statusAfterUpdate);
    final EntityRecordWithColumns updatedRecordWithColumns = create(record, entity, storage);
    storage.write(id, updatedRecordWithColumns);
    final Iterator<EntityRecord> recordsAfter = storage.readAll(query, fieldMask);
    assertFalse(recordsAfter.hasNext());
}
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) Int32Value(com.google.protobuf.Int32Value) FieldMask(com.google.protobuf.FieldMask) Test(org.junit.Test)

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