FINERACT-2081: Allow loan charge-off via batch api
This commit is contained in:
+1
-1
@@ -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.
|
||||
|
||||
+1
-1
@@ -65,7 +65,7 @@ public class CreateTransactionByLoanExternalIdCommandStrategy implements Command
|
||||
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()) {
|
||||
|
||||
+1
-1
@@ -64,7 +64,7 @@ public class CreateTransactionLoanCommandStrategy implements CommandStrategy {
|
||||
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()) {
|
||||
|
||||
+2
@@ -140,6 +140,8 @@ public class CommandStrategyProviderTest {
|
||||
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",
|
||||
|
||||
+67
@@ -2612,6 +2612,73 @@ public class BatchApiTest extends BaseLoanIntegrationTest {
|
||||
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
|
||||
*
|
||||
|
||||
+18
@@ -996,6 +996,24 @@ public final class BatchHelper {
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user