Search in sources :

Example 1 with TransactionState

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;
}
Also used : TransactionState(uk.gov.pay.ledger.transaction.state.TransactionState) TransactionEntity(uk.gov.pay.ledger.transaction.entity.TransactionEntity)

Aggregations

TransactionEntity (uk.gov.pay.ledger.transaction.entity.TransactionEntity)1 TransactionState (uk.gov.pay.ledger.transaction.state.TransactionState)1