Precommit

Overview

The Precommit plugin affords the opportunity to manipulate an entity immediately prior to validation. The precommit plugin is tethered to the validation plugin, with the two always executed in order: precommit, then validation.

The following entities can be updated via the Precommit plugin:

  • Accounts

  • Quotes

  • Transactions

  • Payments

  • Disbursements

  • Delinquencies

Plugin Execution

Assuming the appropriate override method for each supported entity has been implemented, upon a validation API request, the Precommit plugin will be executed and passed the following context:

  • PreCommitTrigger

  • Entity-specific Customer Object

The expected return value from each entity method will be a mutated version of that same entity.

Note

For now, the PreCommitTrigger will always be validate. A future release may introduce other trigger points, such as “on entity creation request” or an ad-hoc API trigger.

Account

input: Account ( Customer Object ) + PreCommitTrigger <validate>

return: mutated Account

// Conditionally setting a value for the lastname of an account

@Override
public ConsumerAccount preCommit(ConsumerAccountRequest var1) {
ConsumerAccount original = var1.account();
    if ((original.data().lastName() == null || original.data().lastName().isBlank())
        && "Bruce".equals(var1.account().data().firstName())) {
      log.info("filling lastname for special account");
      return original.toBuilder()
          .data(original.data().toBuilder().lastName("Wayne").build())
          .build();
    }
    return original;
}

Quote

input: QuoteResponse ( Customer Object ) + PreCommitTrigger <validate>

return: mutated Quote

// Setting the coverage limit to a specific value based on the vehicle's usage
// type and year

@Override
public PersonalAutoQuote preCommit(PersonalAutoQuoteRequest var1) {
return var1.quote().toBuilder()
    .personalVehicles(
        var1.quote().personalVehicles().stream()
            .map(
                vehicleQuote -> {
                  if ("Work".equals(vehicleQuote.data().usage())
                      && vehicleQuote.data().year() < 2002) {
                    log.info(
                        "switching PAIncidentLimit to PA500_1000_200 for q {}",
                        vehicleQuote.locator());
                    return vehicleQuote.toBuilder()
                        .PAIncidentLimit(PAIncidentLimit.PA500_1000_200)
                        .build();
                  }
                  return vehicleQuote;
                })
            .toList())
    .build();
}

Transaction

input: PolicyResponse, TransactionResponse, List<ChangeInstructionHolder> and PreCommitTrigger <validate>

return: mutated List<ChangeInstructionHolder>

// Updating the transaction's change instructions

@Override
public PreCommitTransactionResponse preCommit(PersonalAutoTransactionRequest var1) {
  PreCommitTransactionResponseBuilder builder = PreCommitTransactionResponse.builder();
  if (var1.changeInstructions() != null) {
    builder.addChangeInstructions(var1.changeInstructions());
  }
  return builder.build();
}

Payment

input: Payment ( Customer Object, including ExternalCashTransaction details ) + PreCommitTrigger <validate>

return: mutated Payment ( including ExternalCashTransaction details )

// Updating the value of a payment field based on some condition

@Override
public StandardPayment Payment(StandardPaymentRequest req) {
  if ("to change".equals(req.payment().data().note())) {
    StandardPayment payment = req.payment();
    return payment.toBuilder()
        .data(payment.data().toBuilder().note("changed in pre-commit").build())
        .build();
  }
  return req.payment();
}

Disbursement

input: Disbursement ( Customer Object, including ExternalCashTransaction details ) + PreCommitTrigger <validate>

return: mutated Disbursement ( including ExternalCashTransaction details )

// Updating the value of a Disbursement field based on some condition

@Override
public StandardDisbursement preCommit(StandardDisbursementRequest req) {
  log.info("inside pre-commit for payment {} action {}", req.disbursement(), req.trigger());
  if ("to change".equals(req.disbursement().data().note())) {
    StandardDisbursement disbursement = req.disbursement();
    return disbursement.toBuilder()
        .data(disbursement.data().toBuilder().note("changed in pre-commit").build())
        .build();
  }
  return req.disbursement();
}

Delinquency

input: Delinquency - no trigger, because preCommit is always called when moving to inGrace state

return: mutated DelinquencySettings