Search in sources :

Example 21 with TypeUrl

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);
}
Also used : ClassName(io.spine.type.ClassName) TypeUrl(io.spine.type.TypeUrl)

Example 22 with TypeUrl

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());
}
Also used : EntityRecord(io.spine.server.entity.EntityRecord) Message(com.google.protobuf.Message) TypeUrl(io.spine.type.TypeUrl) Any(com.google.protobuf.Any)

Example 23 with TypeUrl

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);
}
Also used : TypeUrl(io.spine.type.TypeUrl)

Example 24 with TypeUrl

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();
}
Also used : EntityRecord(io.spine.server.entity.EntityRecord) Message(com.google.protobuf.Message) TypeUrl(io.spine.type.TypeUrl) ImmutableMap(com.google.common.collect.ImmutableMap) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) Map(java.util.Map) Any(com.google.protobuf.Any) ImmutableMap(com.google.common.collect.ImmutableMap) EntityRecordWithColumns(io.spine.server.entity.storage.EntityRecordWithColumns)

Example 25 with TypeUrl

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;
}
Also used : EntityRecord(io.spine.server.entity.EntityRecord) Message(com.google.protobuf.Message) TypeUrl(io.spine.type.TypeUrl) Any(com.google.protobuf.Any) EntityRecordWithColumns(io.spine.server.entity.storage.EntityRecordWithColumns)

Aggregations

TypeUrl (io.spine.type.TypeUrl)37 Any (com.google.protobuf.Any)12 Test (org.junit.Test)11 EntityRecord (io.spine.server.entity.EntityRecord)7 Message (com.google.protobuf.Message)6 StandStorage (io.spine.server.stand.StandStorage)4 EntityRecordWithColumns (io.spine.server.entity.storage.EntityRecordWithColumns)3 ClassName (io.spine.type.ClassName)3 TypeName (io.spine.type.TypeName)3 Descriptors (com.google.protobuf.Descriptors)2 Version (io.spine.base.Version)2 Query (io.spine.client.Query)2 BoundedContext (io.spine.server.BoundedContext)2 StandTestProjectionRepository (io.spine.server.stand.Given.StandTestProjectionRepository)2 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)2 Customer (io.spine.test.commandservice.customer.Customer)2 CustomerId (io.spine.test.commandservice.customer.CustomerId)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)1 CanIgnoreReturnValue (com.google.errorprone.annotations.CanIgnoreReturnValue)1