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