Search in sources :

Example 1 with ColumnFilter

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

Example 2 with ColumnFilter

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

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

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

the class EntityQueryShould method paramsFromValues.

private static QueryParameters paramsFromValues(Map<EntityColumn, Object> values) {
    final QueryParameters.Builder builder = QueryParameters.newBuilder();
    final Multimap<EntityColumn, ColumnFilter> filters = HashMultimap.create(values.size(), 1);
    for (Map.Entry<EntityColumn, Object> param : values.entrySet()) {
        final EntityColumn column = param.getKey();
        final ColumnFilter filter = ColumnFilter.newBuilder().setOperator(EQUAL).setValue(toAny(param.getValue())).setColumnName(column.getName()).build();
        filters.put(column, filter);
    }
    return builder.add(CompositeQueryParameter.from(filters, ALL)).build();
}
Also used : ColumnFilter(io.spine.client.ColumnFilter) HashMap(java.util.HashMap) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap)

Example 5 with ColumnFilter

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

the class EntityQueryShould method be_serializable.

@Test
public void be_serializable() {
    final String columnName = deleted.name();
    final EntityColumn column = findColumn(EntityWithLifecycle.class, columnName);
    final ColumnFilter filter = ColumnFilters.eq(columnName, false);
    final Multimap<EntityColumn, ColumnFilter> filters = of(column, filter);
    final CompositeQueryParameter parameter = CompositeQueryParameter.from(filters, ALL);
    final QueryParameters parameters = QueryParameters.newBuilder().add(parameter).build();
    final Set<String> ids = singleton("my-awesome-id");
    final EntityQuery<String> query = EntityQuery.of(ids, parameters);
    reserializeAndAssert(query);
}
Also used : ColumnFilter(io.spine.client.ColumnFilter) Test(org.junit.Test)

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