All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.networknt.eventuate.test.domain.AccountSnapshotStrategy Maven / Gradle / Ivy

There is a newer version: 1.5.1
Show newest version
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;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy