Search in sources :

Example 6 with CompositeColumnFilter

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

the class EntityQueries method toQueryParams.

private static QueryParameters toQueryParams(EntityFilters entityFilters, Collection<EntityColumn> entityColumns) {
    final QueryParameters.Builder builder = QueryParameters.newBuilder();
    for (CompositeColumnFilter filter : entityFilters.getFilterList()) {
        final Multimap<EntityColumn, ColumnFilter> columnFilters = splitFilters(filter, entityColumns);
        final CompositeOperator operator = filter.getOperator();
        final CompositeQueryParameter parameter = CompositeQueryParameter.from(columnFilters, operator);
        builder.add(parameter);
    }
    return builder.build();
}
Also used : CompositeColumnFilter(io.spine.client.CompositeColumnFilter) CompositeOperator(io.spine.client.CompositeColumnFilter.CompositeOperator) CompositeColumnFilter(io.spine.client.CompositeColumnFilter) ColumnFilter(io.spine.client.ColumnFilter)

Example 7 with CompositeColumnFilter

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

the class ERepository method timeFilter.

private static Optional<CompositeColumnFilter> timeFilter(EventStreamQuery query) {
    final CompositeColumnFilter.Builder timeFilter = CompositeColumnFilter.newBuilder().setOperator(ALL);
    if (query.hasAfter()) {
        final Timestamp timestamp = query.getAfter();
        final ColumnFilter filter = gt(CREATED_TIME_COLUMN, timestamp);
        timeFilter.addFilter(filter);
    }
    if (query.hasBefore()) {
        final Timestamp timestamp = query.getBefore();
        final ColumnFilter filter = lt(CREATED_TIME_COLUMN, timestamp);
        timeFilter.addFilter(filter);
    }
    return buildFilter(timeFilter);
}
Also used : CompositeColumnFilter(io.spine.client.CompositeColumnFilter) ColumnFilter(io.spine.client.ColumnFilter) CompositeColumnFilter(io.spine.client.CompositeColumnFilter) Timestamp(com.google.protobuf.Timestamp)

Example 8 with CompositeColumnFilter

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

the class RecordBasedRepositoryShould method find_entities_by_query.

@Test
public void find_entities_by_query() {
    final I id1 = createId(271);
    final I id2 = createId(314);
    final Class<E> entityClass = repository.getEntityClass();
    final E entity1 = Given.entityOfClass(entityClass).withId(id1).build();
    final E entity2 = Given.entityOfClass(entityClass).withId(id2).build();
    repository.store(entity1);
    repository.store(entity2);
    final String fieldPath = "idString";
    final StringValue fieldValue = StringValue.newBuilder().setValue(id1.toString()).build();
    final ColumnFilter filter = eq(fieldPath, fieldValue);
    final CompositeColumnFilter aggregatingFilter = CompositeColumnFilter.newBuilder().addFilter(filter).setOperator(ALL).build();
    final EntityFilters filters = EntityFilters.newBuilder().addFilter(aggregatingFilter).build();
    final Collection<E> found = newArrayList(repository.find(filters, FieldMask.getDefaultInstance()));
    assertSize(1, found);
    assertContains(entity1, found);
    assertNotContains(entity2, found);
}
Also used : CompositeColumnFilter(io.spine.client.CompositeColumnFilter) EntityFilters(io.spine.client.EntityFilters) ColumnFilter(io.spine.client.ColumnFilter) CompositeColumnFilter(io.spine.client.CompositeColumnFilter) StringValue(com.google.protobuf.StringValue) TenantAwareTest(io.spine.server.tenant.TenantAwareTest) Test(org.junit.Test)

Example 9 with CompositeColumnFilter

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

the class EntityQueriesShould method check_filter_type.

@Test(expected = IllegalArgumentException.class)
public void check_filter_type() {
    // Boolean EntityColumn queried for for an Integer value
    final ColumnFilter filter = ColumnFilters.gt(archived.name(), 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 10 with CompositeColumnFilter

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

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