com.networknt.eventuate.test.domain.AccountSnapshotStrategy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of test-domain Show documentation
Show all versions of test-domain Show documentation
Test banking domain objects.
package com.networknt.eventuate.test.domain;
import com.networknt.eventuate.common.*;
import java.util.List;
import java.util.Optional;
public class AccountSnapshotStrategy implements SnapshotStrategy {
@Override
public Class> getAggregateClass() {
return Account.class;
}
@Override
public Optional possiblySnapshot(Aggregate aggregate, Optional snapshotVersion, List oldEvents, List newEvents) {
Account account = (Account) aggregate;
return Optional.of(new AccountSnapshot(account.getBalance()));
}
@Override
public Aggregate recreateAggregate(Class> clasz, Snapshot snapshot, MissingApplyEventMethodStrategy missingApplyEventMethodStrategy) {
AccountSnapshot accountSnapshot = (AccountSnapshot) snapshot;
Account aggregate = new Account();
List events = aggregate.process(new CreateAccountCommand(accountSnapshot.getBalance()));
Aggregates.applyEventsToMutableAggregate(aggregate, events, missingApplyEventMethodStrategy);
return aggregate;
}
}