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();
}
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);
}
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);
}
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);
}
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);
}
Aggregations