use of io.spine.server.entity.EntityRecord in project core-java by SpineEventEngine.
the class InMemoryRecordStorage method readMultipleRecords.
@Override
protected Iterable<EntityRecord> readMultipleRecords(final Iterable<I> givenIds, FieldMask fieldMask) {
final TenantRecords<I> storage = getStorage();
// It is not possible to return an immutable collection,
// since null may be present in it.
final Collection<EntityRecord> result = new LinkedList<>();
for (I givenId : givenIds) {
final EntityRecord matchingResult = storage.findAndApplyFieldMask(givenId, fieldMask);
result.add(matchingResult);
}
return result;
}
use of io.spine.server.entity.EntityRecord in project core-java by SpineEventEngine.
the class TenantRecords method readAllRecords.
Map<I, EntityRecord> readAllRecords(FieldMask fieldMask) {
if (fieldMask.getPathsList().isEmpty()) {
return readAllRecords();
}
if (isEmpty()) {
return ImmutableMap.of();
}
final ImmutableMap.Builder<I, EntityRecord> result = ImmutableMap.builder();
for (Map.Entry<I, EntityRecordWithColumns> storageEntry : filtered.entrySet()) {
final I id = storageEntry.getKey();
final EntityRecord rawRecord = storageEntry.getValue().getRecord();
final TypeUrl type = TypeUrl.parse(rawRecord.getState().getTypeUrl());
final Any recordState = rawRecord.getState();
final Message stateAsMessage = unpack(recordState);
final Message processedState = applyMask(fieldMask, stateAsMessage, type);
final Any packedState = pack(processedState);
final EntityRecord resultingRecord = EntityRecord.newBuilder().setState(packedState).build();
result.put(id, resultingRecord);
}
return result.build();
}
use of io.spine.server.entity.EntityRecord in project core-java by SpineEventEngine.
the class TenantRecords method findAndApplyFieldMask.
EntityRecord findAndApplyFieldMask(I givenId, FieldMask fieldMask) {
EntityRecord matchingResult = null;
for (I recordId : filtered.keySet()) {
if (recordId.equals(givenId)) {
final Optional<EntityRecordWithColumns> record = get(recordId);
if (!record.isPresent()) {
continue;
}
EntityRecord.Builder matchingRecord = record.get().getRecord().toBuilder();
final Any state = matchingRecord.getState();
final TypeUrl typeUrl = TypeUrl.parse(state.getTypeUrl());
final Message wholeState = unpack(state);
final Message maskedState = applyMask(fieldMask, wholeState, typeUrl);
final Any processed = pack(maskedState);
matchingRecord.setState(processed);
matchingResult = matchingRecord.build();
}
}
return matchingResult;
}
use of io.spine.server.entity.EntityRecord in project core-java by SpineEventEngine.
the class ProjectionStorageShould method read_all_messages_with_field_mask.
@SuppressWarnings("MethodWithMultipleLoops")
@Test
public void read_all_messages_with_field_mask() {
final List<I> ids = fillStorage(5);
final String projectDescriptor = Project.getDescriptor().getFullName();
// clashes with non-related tests.
@SuppressWarnings("DuplicateStringLiteralInspection") final FieldMask fieldMask = maskForPaths(projectDescriptor + ".id", projectDescriptor + ".name");
final Map<I, EntityRecord> read = storage.readAll(fieldMask);
assertSize(ids.size(), read);
for (Map.Entry<I, EntityRecord> record : read.entrySet()) {
assertContains(record.getKey(), ids);
final Any packedState = record.getValue().getState();
final Project state = AnyPacker.unpack(packedState);
assertMatchesMask(state, fieldMask);
}
}
use of io.spine.server.entity.EntityRecord in project core-java by SpineEventEngine.
the class AggregateQueryProcessor method process.
@Override
public ImmutableCollection<Any> process(Query query) {
final ImmutableList.Builder<Any> resultBuilder = ImmutableList.builder();
ImmutableCollection<EntityRecord> stateRecords;
final Target target = query.getTarget();
final FieldMask fieldMask = query.getFieldMask();
final boolean shouldApplyFieldMask = !fieldMask.getPathsList().isEmpty();
if (target.getIncludeAll()) {
stateRecords = shouldApplyFieldMask ? standStorage.readAllByType(type, fieldMask) : standStorage.readAllByType(type);
} else {
stateRecords = doFetchWithFilters(target, fieldMask);
}
for (EntityRecord record : stateRecords) {
final Any state = record.getState();
resultBuilder.add(state);
}
final ImmutableList<Any> result = resultBuilder.build();
return result;
}
Aggregations