Skip to content

Commit

Permalink
FINERACT-2081: Allow loan charge-off via batch api
Browse files Browse the repository at this point in the history
  • Loading branch information
magyari-adam authored and adamsaghy committed Feb 13, 2025
1 parent 2ce1ece commit e215750
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class CommandStrategyProvider {
/**
* Regex pattern for specifying a mandatory query param that has key = 'command'.
*/
private static final String MANDATORY_COMMAND_PARAM_REGEX = "\\?command=[\\w]+";
private static final String MANDATORY_COMMAND_PARAM_REGEX = "\\?command=[\\w\\-]+";

/**
* Regex pattern for specifying a UUID param.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public BatchResponse execute(BatchRequest request, @SuppressWarnings("unused") U
final List<String> pathParameters = Splitter.on('/').splitToList(relativeUrlWithoutVersion(request));
final String loanExternalId = pathParameters.get(2);

final Pattern commandPattern = Pattern.compile("^?command=[a-zA-Z]+");
final Pattern commandPattern = Pattern.compile("^?command=[a-zA-Z\\-]+");
final Matcher commandMatcher = commandPattern.matcher(pathParameters.get(3));

if (!commandMatcher.find()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public BatchResponse execute(BatchRequest request, @SuppressWarnings("unused") U
final List<String> pathParameters = Splitter.on('/').splitToList(relativeUrlWithoutVersion(request));
final Long loanId = Long.parseLong(pathParameters.get(1));

final Pattern commandPattern = Pattern.compile("^?command=[a-zA-Z]+");
final Pattern commandPattern = Pattern.compile("^?command=[a-zA-Z\\-]+");
final Matcher commandMatcher = commandPattern.matcher(pathParameters.get(2));

if (!commandMatcher.find()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ private static Stream<Arguments> provideCommandStrategies() {
mock(CreateTransactionLoanCommandStrategy.class)),
Arguments.of("loans/123/transactions?command=chargeRefund", HttpMethod.POST, "createTransactionLoanCommandStrategy",
mock(CreateTransactionLoanCommandStrategy.class)),
Arguments.of("loans/123/transactions?command=charge-off", HttpMethod.POST, "createTransactionLoanCommandStrategy",
mock(CreateTransactionLoanCommandStrategy.class)),
Arguments.of("loans/123/transactions/123", HttpMethod.POST, "adjustLoanTransactionCommandStrategy",
mock(AdjustLoanTransactionCommandStrategy.class)),
Arguments.of("loans/123/transactions/123?command=chargeback", HttpMethod.POST, "adjustLoanTransactionCommandStrategy",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2612,6 +2612,73 @@ public void verifyCalculatingRunningBalanceAfterBatchWithReleaseAmount() {
transactionWithdrawal2.get("runningBalance"), "Verify running balance after second withdrawal");
}

@Test
public void shouldReturnOkStatusForBatchChargeOff() {

final String loanProductJSON = new LoanProductTestBuilder() //
.withPrincipal("10000000.00") //
.withNumberOfRepayments("24") //
.withRepaymentAfterEvery("1") //
.withRepaymentTypeAsMonth() //
.withinterestRatePerPeriod("2") //
.withInterestRateFrequencyTypeAsMonths() //
.withAmortizationTypeAsEqualPrincipalPayment() //
.withInterestTypeAsDecliningBalance() //
.currencyDetails("0", "100").build(null);

final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
ClientHelper.verifyClientCreatedOnServer(this.requestSpec, this.responseSpec, clientID);

final Integer collateralId = CollateralManagementHelper.createCollateralProduct(this.requestSpec, this.responseSpec);
Assertions.assertNotNull(collateralId);
final Integer clientCollateralId = CollateralManagementHelper.createClientCollateral(this.requestSpec, this.responseSpec,
clientID.toString(), collateralId);
Assertions.assertNotNull(clientCollateralId);

final Integer productId = new LoanTransactionHelper(this.requestSpec, this.responseSpec).getLoanProductId(loanProductJSON);

// Create a createClient Request
final BatchRequest br1 = BatchHelper.createClientRequest(4730L, "");

// Create a activateClient Request
final BatchRequest br2 = BatchHelper.activateClientRequest(4731L, 4730L);

// Create a ApplyLoan Request
final BatchRequest br3 = BatchHelper.applyLoanRequest(4732L, 4731L, productId, clientCollateralId);

// Create a approveLoan Request
final BatchRequest br4 = BatchHelper.approveLoanRequest(4733L, 4732L);

// Create a disburseLoan Request
final BatchRequest br5 = BatchHelper.disburseLoanRequest(4734L, 4733L);

// Create a loanRepay Request
final BatchRequest br6 = BatchHelper.repayLoanRequest(4735L, 4734L, "500");

// Create a loanRepay Request
final BatchRequest br7 = BatchHelper.repayLoanRequest(4736L, 4734L, "500");

final BatchRequest br8 = BatchHelper.chargeOffRequest(4737L, 4736L);

final List<BatchRequest> batchRequests = new ArrayList<>();

batchRequests.add(br1);
batchRequests.add(br2);
batchRequests.add(br3);
batchRequests.add(br4);
batchRequests.add(br5);
batchRequests.add(br6);
batchRequests.add(br7);
batchRequests.add(br8);

final String jsonifiedRequest = BatchHelper.toJsonString(batchRequests);

final List<BatchResponse> response = BatchHelper.postBatchRequestsWithoutEnclosingTransaction(this.requestSpec, this.responseSpec,
jsonifiedRequest);

Assertions.assertEquals(HttpStatus.SC_OK, (long) response.get(7).getStatusCode(), "Verify Status Code 200 for ChargeOff");
}

/**
* Delete datatable
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,24 @@ public static BatchRequest payoutRefundRequest(final Long requestId, final Long
return createTransactionRequest(requestId, reference, "payoutRefund", amount, LocalDate.now(Utils.getZoneIdOfTenant()));
}

public static BatchRequest chargeOffRequest(final Long requestId, final Long referenceId) {
return chargeOffRequest(requestId, referenceId, LocalDate.now(Utils.getZoneIdOfTenant()));
}

public static BatchRequest chargeOffRequest(final Long requestId, final Long referenceId, LocalDate date) {
final BatchRequest br = new BatchRequest();

br.setRequestId(requestId);
br.setReference(referenceId);
br.setRelativeUrl(String.format("v1/loans/$.loanId/transactions?command=%s", "charge-off"));
br.setMethod("POST");
String dateString = date.format(DateTimeFormatter.ofPattern("dd MMMM yyyy"));
br.setBody(String.format("{\"locale\": \"en\", \"dateFormat\": \"dd MMMM yyyy\", " + "\"transactionDate\": \"%s\", \"note\":null}",
dateString));

return br;
}

/**
* Creates and returns a
* {@link org.apache.fineract.batch.command.internal.CreateLoanRescheduleRequestCommandStrategy} request with given
Expand Down

0 comments on commit e215750

Please sign in to comment.