Search in sources :

Example 1 with EntityRecord

use of io.spine.server.entity.EntityRecord in project core-java by SpineEventEngine.

the class EventStorage method iterator.

Iterator<Event> iterator(EventStreamQuery query) {
    final EventRecordStorage storage = recordStorage();
    final Map<EventId, EntityRecord> records = storage.readAll(query);
    final Collection<EventEntity> entities = transform(records.entrySet(), storageRecordToEntity());
    // TODO:2017-05-19:dmytro.dashenkov: Remove after the Entity Column approach is implemented.
    final Collection<EventEntity> filtered = filter(entities, createEntityFilter(query));
    final List<EventEntity> entityList = newArrayList(filtered);
    Collections.sort(entityList, EventEntity.comparator());
    final Iterator<Event> result = Iterators.transform(entityList.iterator(), getEventFunc());
    return result;
}
Also used : EntityRecord(io.spine.server.entity.EntityRecord) EventRecordStorage(io.spine.server.storage.EventRecordStorage) EventId(io.spine.base.EventId) Event(io.spine.base.Event)

Example 2 with EntityRecord

use of io.spine.server.entity.EntityRecord in project core-java by SpineEventEngine.

the class ProjectionStorageShould method retrieve_empty_map_if_storage_is_empty.

// because the behaviour to test is different
@SuppressWarnings("MethodDoesntCallSuperMethod")
@Override
@Test
public void retrieve_empty_map_if_storage_is_empty() {
    final Map<I, EntityRecord> noMaskEntiries = storage.readAll();
    final FieldMask nonEmptyMask = FieldMask.newBuilder().addPaths("invalid_path").build();
    final Map<I, EntityRecord> maskedEntries = storage.readAll(nonEmptyMask);
    assertEmpty(noMaskEntiries);
    assertEmpty(maskedEntries);
    // Same type
    assertEquals(noMaskEntiries, maskedEntries);
}
Also used : EntityRecord(io.spine.server.entity.EntityRecord) FieldMask(com.google.protobuf.FieldMask) Test(org.junit.Test)

Example 3 with EntityRecord

use of io.spine.server.entity.EntityRecord in project core-java by SpineEventEngine.

the class EntityQueryMatcherShould method match_columns.

// Mocks <-> reflection issues
@SuppressWarnings("unchecked")
@Test
public void match_columns() {
    final String targetName = "feature";
    final Column<?> target = mock(Column.class);
    when(target.isNullable()).thenReturn(true);
    when(target.getName()).thenReturn(targetName);
    when(target.getType()).thenReturn((Class) Boolean.class);
    final Object acceptedValue = true;
    final Collection<Object> ids = Collections.emptyList();
    final Map<Column<?>, Object> params = ImmutableMap.<Column<?>, Object>of(target, acceptedValue);
    final EntityQuery<?> query = EntityQuery.of(ids, params);
    final Any matchingId = AnyPacker.pack(Sample.messageOfType(TaskId.class));
    final Any nonMatchingId = AnyPacker.pack(Sample.messageOfType(TaskId.class));
    final EntityQueryMatcher<?> matcher = new EntityQueryMatcher<>(query);
    final EntityRecord matching = EntityRecord.newBuilder().setEntityId(matchingId).build();
    final EntityRecord nonMatching = EntityRecord.newBuilder().setEntityId(nonMatchingId).build();
    final Column.MemoizedValue storedValue = mock(Column.MemoizedValue.class);
    when(storedValue.getSourceColumn()).thenReturn(target);
    when(storedValue.getValue()).thenReturn(acceptedValue);
    final Map<String, Column.MemoizedValue<?>> matchingColumns = ImmutableMap.<String, Column.MemoizedValue<?>>of(targetName, storedValue);
    final EntityRecordWithColumns nonMatchingRecord = of(nonMatching);
    final EntityRecordWithColumns matchingRecord = io.spine.server.entity.storage.EntityRecordWithColumns.of(matching, matchingColumns);
    assertTrue(matcher.apply(matchingRecord));
    assertFalse(matcher.apply(nonMatchingRecord));
}
Also used : TaskId(io.spine.test.entity.TaskId) Any(com.google.protobuf.Any) EntityRecord(io.spine.server.entity.EntityRecord) Test(org.junit.Test)

Example 4 with EntityRecord

use of io.spine.server.entity.EntityRecord in project core-java by SpineEventEngine.

the class StandStorageShould method checkIds.

protected void checkIds(List<AggregateStateId> ids, Collection<EntityRecord> records) {
    assertSize(ids.size(), records);
    final Collection<ProjectId> projectIds = Collections2.transform(ids, new Function<AggregateStateId, ProjectId>() {

        @Nullable
        @Override
        public ProjectId apply(@Nullable AggregateStateId input) {
            if (input == null) {
                return null;
            }
            return (ProjectId) input.getAggregateId();
        }
    });
    for (EntityRecord record : records) {
        final Any packedState = record.getState();
        final Project state = AnyPacker.unpack(packedState);
        final ProjectId id = state.getId();
        assertContains(id, projectIds);
    }
}
Also used : EntityRecord(io.spine.server.entity.EntityRecord) Project(io.spine.test.storage.Project) ProjectId(io.spine.test.storage.ProjectId) Any(com.google.protobuf.Any) Nullable(javax.annotation.Nullable)

Example 5 with EntityRecord

use of io.spine.server.entity.EntityRecord in project core-java by SpineEventEngine.

the class StandStorageShould method retrieve_records_by_ids.

@Test
public void retrieve_records_by_ids() {
    final StandStorage storage = getStorage();
    // Use a subset of IDs
    final List<AggregateStateId> ids = fill(storage, 10, DEFAULT_ID_SUPPLIER).subList(0, 5);
    final Collection<EntityRecord> records = (Collection<EntityRecord>) storage.readMultiple(ids);
    checkIds(ids, records);
}
Also used : EntityRecord(io.spine.server.entity.EntityRecord) StandStorage(io.spine.server.stand.StandStorage) ImmutableCollection(com.google.common.collect.ImmutableCollection) Collection(java.util.Collection) Test(org.junit.Test)

Aggregations

EntityRecord (io.spine.server.entity.EntityRecord)55 Test (org.junit.Test)34 Any (com.google.protobuf.Any)24 EntityRecordWithColumns (io.spine.server.entity.storage.EntityRecordWithColumns)15 Message (com.google.protobuf.Message)10 Project (io.spine.test.storage.Project)10 TypeUrl (io.spine.type.TypeUrl)9 FieldMask (com.google.protobuf.FieldMask)7 EntityFilters (io.spine.client.EntityFilters)7 ProjectId (io.spine.test.storage.ProjectId)7 ColumnFilter (io.spine.client.ColumnFilter)5 EntityIdFilter (io.spine.client.EntityIdFilter)4 LinkedList (java.util.LinkedList)4 CompositeColumnFilter (io.spine.client.CompositeColumnFilter)3 Version (io.spine.core.Version)3 CompositeQueryParameter (io.spine.server.entity.storage.CompositeQueryParameter)3 EntityColumn (io.spine.server.entity.storage.EntityColumn)3 QueryParameters (io.spine.server.entity.storage.QueryParameters)3 StandStorage (io.spine.server.stand.StandStorage)3 ImmutableList (com.google.common.collect.ImmutableList)2