use of io.spine.client.EntityIdFilter in project core-java by SpineEventEngine.
the class QueryBuilderShould method create_queries_with_ids.
@Test
public void create_queries_with_ids() {
final int id1 = 314;
final int id2 = 271;
final Query query = factory().query().select(TestEntity.class).byId(id1, id2).build();
assertNotNull(query);
assertFalse(query.hasFieldMask());
final Target target = query.getTarget();
assertFalse(target.getIncludeAll());
final EntityFilters entityFilters = target.getFilters();
final EntityIdFilter idFilter = entityFilters.getIdFilter();
final Collection<EntityId> idValues = idFilter.getIdsList();
final Function<EntityId, Integer> transformer = new EntityIdUnpacker<>(int.class);
final Collection<Integer> intIdValues = transform(idValues, transformer);
assertSize(2, idValues);
assertThat(intIdValues, containsInAnyOrder(id1, id2));
}
use of io.spine.client.EntityIdFilter in project core-java by SpineEventEngine.
the class AggregateQueryProcessor method doFetchWithFilters.
private Iterator<EntityRecord> doFetchWithFilters(Target target, FieldMask fieldMask) {
final EntityFilters filters = target.getFilters();
final boolean idsAreDefined = !filters.getIdFilter().getIdsList().isEmpty();
if (!idsAreDefined) {
return ImmutableList.<EntityRecord>of().iterator();
}
final EntityIdFilter idFilter = filters.getIdFilter();
final Collection<AggregateStateId> stateIds = Collections2.transform(idFilter.getIdsList(), stateIdTransformer);
final Iterator<EntityRecord> result = stateIds.size() == 1 ? readOne(stateIds.iterator().next(), fieldMask) : readMany(stateIds, fieldMask);
return result;
}
use of io.spine.client.EntityIdFilter in project core-java by SpineEventEngine.
the class SubscriptionRecord method matchByFilters.
private static boolean matchByFilters(Object id, EntityFilters filters) {
final boolean result;
final EntityIdFilter givenIdFilter = filters.getIdFilter();
final boolean idFilterSet = !EntityIdFilter.getDefaultInstance().equals(givenIdFilter);
if (idFilterSet) {
final Any idAsAny = Identifier.pack(id);
final EntityId givenEntityId = EntityId.newBuilder().setId(idAsAny).build();
final List<EntityId> idsList = givenIdFilter.getIdsList();
result = idsList.contains(givenEntityId);
} else {
result = false;
}
return result;
}
use of io.spine.client.EntityIdFilter in project core-java by SpineEventEngine.
the class RecordStorageShould method read_both_by_columns_and_IDs.
@Test
public void read_both_by_columns_and_IDs() {
final I targetId = newId();
final TestCounterEntity<I> targetEntity = new TestCounterEntity<>(targetId);
final TestCounterEntity<I> noMatchEntity = new TestCounterEntity<>(newId());
final TestCounterEntity<I> noMatchIdEntity = new TestCounterEntity<>(newId());
final TestCounterEntity<I> deletedEntity = new TestCounterEntity<>(newId());
targetEntity.setStatus(CANCELLED);
deletedEntity.setStatus(CANCELLED);
deletedEntity.delete();
noMatchIdEntity.setStatus(CANCELLED);
noMatchEntity.setStatus(DONE);
write(targetEntity);
write(noMatchEntity);
write(noMatchIdEntity);
write(deletedEntity);
final EntityIdFilter idFilter = EntityIdFilter.newBuilder().addIds(toEntityId(targetId)).build();
final CompositeColumnFilter columnFilter = all(eq("projectStatusValue", CANCELLED.getNumber()));
final EntityFilters filters = EntityFilters.newBuilder().setIdFilter(idFilter).addFilter(columnFilter).build();
final RecordStorage<I> storage = getStorage();
final EntityQuery<I> query = EntityQueries.<I>from(filters, storage).withLifecycleFlags(storage);
final Iterator<EntityRecord> read = storage.readAll(query, FieldMask.getDefaultInstance());
final List<EntityRecord> readRecords = newArrayList(read);
assertEquals(1, readRecords.size());
final EntityRecord readRecord = readRecords.get(0);
assertEquals(targetEntity.getState(), unpack(readRecord.getState()));
assertEquals(targetId, Identifier.unpack(readRecord.getEntityId()));
}
use of io.spine.client.EntityIdFilter in project core-java by SpineEventEngine.
the class RecordBasedRepositoryShould method retrieve_all_records_with_entity_filters_and_field_mask_applied.
@SuppressWarnings("MethodWithMultipleLoops")
@Test
public void retrieve_all_records_with_entity_filters_and_field_mask_applied() {
final int count = 10;
final List<E> entities = createAndStoreEntities(repository, count);
final List<EntityId> ids = Lists.newLinkedList();
// Find some of the records (half of them in this case)
for (int i = 0; i < count / 2; i++) {
final Message entityId = (Message) entities.get(i).getId();
final EntityId id = EntityId.newBuilder().setId(pack(entityId)).build();
ids.add(id);
}
final EntityIdFilter filter = EntityIdFilter.newBuilder().addAllIds(ids).build();
final EntityFilters filters = EntityFilters.newBuilder().setIdFilter(filter).build();
final Descriptors.Descriptor entityDescriptor = entities.get(0).getState().getDescriptorForType();
final FieldMask firstFieldOnly = FieldMasks.maskOf(entityDescriptor, 1);
final Iterator<E> readEntities = find(filters, firstFieldOnly);
final Collection<E> foundList = newArrayList(readEntities);
assertSize(ids.size(), foundList);
for (E entity : foundList) {
assertMatches(entity, firstFieldOnly);
}
}
Aggregations