use of io.spine.type.TypeUrl in project core-java by SpineEventEngine.
the class KnownTypesShould method assertHasClassNameByTypeUrlOf.
private static void assertHasClassNameByTypeUrlOf(Class<? extends Message> msgClass) {
final TypeUrl typeUrl = TypeUrl.of(msgClass);
final ClassName className = KnownTypes.getClassName(typeUrl);
assertEquals(ClassName.of(msgClass), className);
}
use of io.spine.type.TypeUrl in project core-java by SpineEventEngine.
the class RecordStorage method read.
/**
* Reads a single item from the storage and applies a {@link FieldMask} to it.
*
* @param id ID of the item to read.
* @param fieldMask fields to read.
* @return the item with the given ID and with the {@code FieldMask} applied.
* @see #read(Object)
*/
public Optional<EntityRecord> read(I id, FieldMask fieldMask) {
final Optional<EntityRecord> rawResult = read(id);
if (!rawResult.isPresent()) {
return Optional.absent();
}
final EntityRecord.Builder builder = EntityRecord.newBuilder(rawResult.get());
final Any state = builder.getState();
final TypeUrl type = TypeUrl.parse(state.getTypeUrl());
final Message stateAsMessage = AnyPacker.unpack(state);
final Message maskedState = FieldMasks.applyMask(fieldMask, stateAsMessage, type);
final Any packedState = AnyPacker.pack(maskedState);
builder.setState(packedState);
return Optional.of(builder.build());
}
use of io.spine.type.TypeUrl in project core-java by SpineEventEngine.
the class InMemoryStandStorage method writeRecord.
@Override
protected void writeRecord(AggregateStateId id, EntityRecordWithColumns record) {
final TypeUrl recordType = TypeUrl.parse(record.getRecord().getState().getTypeUrl());
final TypeUrl recordTypeFromId = id.getStateType();
checkState(recordTypeFromId.equals(recordType), TYPE_URL_MISMATCH_MESSAGE_PATTERN, recordType, recordTypeFromId);
recordStorage.write(id, record);
}
use of io.spine.type.TypeUrl 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.type.TypeUrl 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;
}
Aggregations