Search in sources :

Example 6 with LifecycleFlags

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

the class AggregateStorageShould method index_archived_aggregate.

@Test
public void index_archived_aggregate() {
    final LifecycleFlags archivedRecordFlags = LifecycleFlags.newBuilder().setArchived(true).build();
    storage.writeRecord(id, StorageRecord.create(getCurrentTime()));
    storage.writeLifecycleFlags(id, archivedRecordFlags);
    assertTrue(storage.index().hasNext());
}
Also used : LifecycleFlags(io.spine.server.entity.LifecycleFlags) Test(org.junit.Test)

Example 7 with LifecycleFlags

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

the class RecordStorageShould method withLifecycleColumns.

protected static EntityRecordWithColumns withLifecycleColumns(EntityRecord record) {
    final LifecycleFlags flags = record.getLifecycleFlags();
    final Map<String, MemoizedValue> columns = ImmutableMap.of(LifecycleColumns.ARCHIVED.columnName(), booleanColumn(LifecycleColumns.ARCHIVED.column(), flags.getArchived()), LifecycleColumns.DELETED.columnName(), booleanColumn(LifecycleColumns.DELETED.column(), flags.getDeleted()));
    final EntityRecordWithColumns result = createRecord(record, columns);
    return result;
}
Also used : MemoizedValue(io.spine.server.entity.storage.EntityColumn.MemoizedValue) EntityRecordWithColumns(io.spine.server.entity.storage.EntityRecordWithColumns) LifecycleFlags(io.spine.server.entity.LifecycleFlags)

Example 8 with LifecycleFlags

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

the class AggregateMessageEndpoint method deliverNowTo.

@Override
protected void deliverNowTo(I aggregateId) {
    final A aggregate = repository().loadOrCreate(aggregateId);
    final LifecycleFlags flagsBefore = aggregate.getLifecycleFlags();
    final List<? extends Message> eventMessages = doDispatch(aggregate, envelope());
    final AggregateTransaction tx = startTransaction(aggregate);
    aggregate.apply(eventMessages, envelope());
    tx.commit();
    // Update lifecycle flags only if the message was handled successfully and flags changed.
    final LifecycleFlags flagsAfter = aggregate.getLifecycleFlags();
    if (flagsAfter != null && !flagsBefore.equals(flagsAfter)) {
        storage().writeLifecycleFlags(aggregateId, flagsAfter);
    }
    store(aggregate);
}
Also used : LifecycleFlags(io.spine.server.entity.LifecycleFlags)

Example 9 with LifecycleFlags

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

the class AggregateStorageVisibilityHandlingShould method save_whole_status.

@Test
public void save_whole_status() {
    final boolean archived = true;
    final boolean deleted = true;
    final LifecycleFlags expected = LifecycleFlags.newBuilder().setArchived(archived).setDeleted(deleted).build();
    storage.writeLifecycleFlags(id, expected);
    final Optional<LifecycleFlags> optionalActual = storage.readLifecycleFlags(id);
    assertStatus(optionalActual, true, true);
}
Also used : LifecycleFlags(io.spine.server.entity.LifecycleFlags) Test(org.junit.Test)

Example 10 with LifecycleFlags

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

the class AggregateStorageVisibilityHandlingShould method assertStatus.

@SuppressWarnings({ "OptionalUsedAsFieldOrParameterType", "OptionalGetWithoutIsPresent" })
private static void assertStatus(Optional<LifecycleFlags> entityStatus, boolean archived, boolean deleted) {
    assertTrue(entityStatus.isPresent());
    final LifecycleFlags status = entityStatus.get();
    assertEquals(archived, status.getArchived());
    assertEquals(deleted, status.getDeleted());
}
Also used : LifecycleFlags(io.spine.server.entity.LifecycleFlags)

Aggregations

LifecycleFlags (io.spine.server.entity.LifecycleFlags)11 Test (org.junit.Test)8 EntityRecord (io.spine.server.entity.EntityRecord)2 MemoizedValue (io.spine.server.entity.storage.EntityColumn.MemoizedValue)1 EntityRecordWithColumns (io.spine.server.entity.storage.EntityRecordWithColumns)1