Search in sources :

Example 16 with ColumnFilter

use of io.spine.client.ColumnFilter 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);
}
Also used : CompositeColumnFilter(io.spine.client.CompositeColumnFilter) Message(com.google.protobuf.Message) EntityIdFilter(io.spine.client.EntityIdFilter) EntityFilters(io.spine.client.EntityFilters) BoolValue(com.google.protobuf.BoolValue) ColumnFilter(io.spine.client.ColumnFilter) CompositeColumnFilter(io.spine.client.CompositeColumnFilter) Any(com.google.protobuf.Any) EntityId(io.spine.client.EntityId) Version(io.spine.core.Version) Test(org.junit.Test)

Example 17 with ColumnFilter

use of io.spine.client.ColumnFilter 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 18 with ColumnFilter

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

the class QueryParametersShould method be_serializable.

@Test
public void be_serializable() {
    final String columnName = version.name();
    final EntityColumn column = findColumn(VersionableEntity.class, columnName);
    final ColumnFilter filter = ColumnFilters.eq(columnName, 1);
    final CompositeQueryParameter parameter = aggregatingParameter(column, filter);
    final QueryParameters parameters = QueryParameters.newBuilder().add(parameter).build();
    reserializeAndAssert(parameters);
}
Also used : ColumnFilter(io.spine.client.ColumnFilter) Test(org.junit.Test)

Example 19 with ColumnFilter

use of io.spine.client.ColumnFilter 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 20 with ColumnFilter

use of io.spine.client.ColumnFilter 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)

Aggregations

ColumnFilter (io.spine.client.ColumnFilter)22 Test (org.junit.Test)17 CompositeColumnFilter (io.spine.client.CompositeColumnFilter)12 EntityFilters (io.spine.client.EntityFilters)8 EntityRecord (io.spine.server.entity.EntityRecord)5 EntityRecordWithColumns (io.spine.server.entity.storage.EntityRecordWithColumns)5 Any (com.google.protobuf.Any)4 CompositeQueryParameter (io.spine.server.entity.storage.CompositeQueryParameter)3 EntityColumn (io.spine.server.entity.storage.EntityColumn)3 QueryParameters (io.spine.server.entity.storage.QueryParameters)3 Int32Value (com.google.protobuf.Int32Value)2 Timestamp (com.google.protobuf.Timestamp)2 Version (io.spine.core.Version)2 AbstractVersionableEntity (io.spine.server.entity.AbstractVersionableEntity)2 ERepository.toEntityFilters (io.spine.server.event.ERepository.toEntityFilters)2 Project (io.spine.test.storage.Project)2 EqualsTester (com.google.common.testing.EqualsTester)1 BoolValue (com.google.protobuf.BoolValue)1 FieldMask (com.google.protobuf.FieldMask)1 Message (com.google.protobuf.Message)1