use of uk.gov.pay.ledger.transaction.state.TransactionState in project pay-ledger by alphagov.
the class TransactionEntityFactory method create.
public TransactionEntity create(EventDigest eventDigest) {
TransactionState digestTransactionState = eventDigest.getMostRecentSalientEventType().map(TransactionState::fromEventType).orElse(TransactionState.UNDEFINED);
var eventAggregate = eventDigest.getEventAggregate();
String transactionDetail = convertToTransactionDetails(eventAggregate);
TransactionEntity entity = objectMapper.convertValue(eventAggregate, TransactionEntity.class);
entity.setServiceId(eventDigest.getServiceId());
entity.setLive(Optional.ofNullable(eventDigest.isLive()).orElse(entity.isLive()));
entity.setTransactionDetails(transactionDetail);
entity.setEventCount(eventDigest.getEventCount());
entity.setState(digestTransactionState);
entity.setCreatedDate(eventDigest.getEventCreatedDate());
entity.setExternalId(eventDigest.getResourceExternalId());
entity.setParentExternalId(eventDigest.getParentResourceExternalId());
entity.setTransactionType(eventDigest.getResourceType().toString());
return entity;
}
Aggregations