FINERACT-1724: Loan Charge API support for batch APIs and a couple of other batch API enhancements

This commit is contained in:
Arnold Galovics
2022-12-19 22:46:36 +01:00
committed by Arnold Gálovics
parent cb39a23467
commit 8ab206aa4a
56 changed files with 4220 additions and 150 deletions
@@ -37,7 +37,9 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.RandomUtils;
import org.apache.fineract.batch.command.internal.AdjustTransactionCommandStrategy;
import org.apache.fineract.batch.command.internal.CreateTransactionLoanCommandStrategy;
import org.apache.fineract.batch.domain.BatchRequest;
@@ -46,6 +48,7 @@ import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
import org.apache.fineract.integrationtests.common.BatchHelper;
import org.apache.fineract.integrationtests.common.ClientHelper;
import org.apache.fineract.integrationtests.common.CollateralManagementHelper;
import org.apache.fineract.integrationtests.common.GlobalConfigurationHelper;
import org.apache.fineract.integrationtests.common.Utils;
import org.apache.fineract.integrationtests.common.charges.ChargesHelper;
import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder;
@@ -105,6 +108,7 @@ public class BatchApiTest {
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
this.datatableHelper = new DatatableHelper(this.requestSpec, this.responseSpec);
GlobalConfigurationHelper.updateIsAutomaticExternalIdGenerationEnabled(this.requestSpec, this.responseSpec, true);
}
/**
@@ -365,7 +369,7 @@ public class BatchApiTest {
final BatchRequest br3 = BatchHelper.applyLoanRequest(4724L, 4723L, productId, clientCollateralId);
// Create a Collect Charges Request
final BatchRequest br4 = BatchHelper.collectChargesRequest(4725L, 4724L);
final BatchRequest br4 = BatchHelper.collectChargesByLoanIdRequest(4725L, 4724L);
final List<BatchRequest> batchRequests = new ArrayList<>();
@@ -426,9 +430,10 @@ public class BatchApiTest {
final BatchRequest disburseLoanRequest = BatchHelper.disburseLoanRequest(disburseLoanRequestId, approveLoanRequestId);
final BatchRequest createChargeRequest = BatchHelper.createChargeRequest(createChargeRequestId, disburseLoanRequestId, chargeId);
final BatchRequest createChargeRequest = BatchHelper.createChargeByLoanIdRequest(createChargeRequestId, disburseLoanRequestId,
chargeId);
final BatchRequest getChargeByIdRequest = BatchHelper.getChargeByIdCommandStrategy(getChargeByIdRequestId, createChargeRequestId);
final BatchRequest getChargeByIdRequest = BatchHelper.getChargeByLoanIdChargeId(getChargeByIdRequestId, createChargeRequestId);
// Create batch requests list
final List<BatchRequest> batchRequests = Arrays.asList(applyLoanRequest, approveLoanRequest, disburseLoanRequest,
@@ -445,6 +450,183 @@ public class BatchApiTest {
Assertions.assertEquals(HttpStatus.SC_OK, responses.get(4).getStatusCode(), "Verify Status Code 200 for Get Charge By Id");
}
/**
* Test for a successful charge adjustment. A '200' status code is expected on successful responses.
*
* @see AdjustTransactionCommandStrategy
*/
@Test
public void shouldReturnOkStatusOnSuccessfulChargeAdjustment() {
final String loanProductJSON = new LoanProductTestBuilder() //
.withPrincipal("1000.00") //
.withNumberOfRepayments("24") //
.withRepaymentAfterEvery("1") //
.withRepaymentTypeAsMonth() //
.withinterestRatePerPeriod("2") //
.withInterestRateFrequencyTypeAsMonths() //
.withAmortizationTypeAsEqualPrincipalPayment() //
.withInterestTypeAsDecliningBalance() //
.currencyDetails("0", "100").build(null);
final Long applyLoanRequestId = Long.valueOf(RandomStringUtils.randomNumeric(4));
final Long approveLoanRequestId = applyLoanRequestId + 1;
final Long disburseLoanRequestId = approveLoanRequestId + 1;
final Long createChargeRequestId = disburseLoanRequestId + 1;
final Long adjustChargeRequestId = createChargeRequestId + 1;
final Long getTransactionRequestId = adjustChargeRequestId + 1;
// Create product
final Integer productId = new LoanTransactionHelper(this.requestSpec, this.responseSpec).getLoanProductId(loanProductJSON);
// Create client
final Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec);
ClientHelper.verifyClientCreatedOnServer(this.requestSpec, this.responseSpec, clientId);
// Create charge object and get id
final Integer chargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
ChargesHelper.getLoanSpecifiedDueDateJSON());
final BatchRequest applyLoanRequest = BatchHelper.applyLoanRequestWithClientId(applyLoanRequestId, clientId, productId);
final BatchRequest approveLoanRequest = BatchHelper.approveLoanRequest(approveLoanRequestId, applyLoanRequestId);
final BatchRequest disburseLoanRequest = BatchHelper.disburseLoanRequest(disburseLoanRequestId, approveLoanRequestId);
final BatchRequest createChargeRequest = BatchHelper.createChargeByLoanIdRequest(createChargeRequestId, disburseLoanRequestId,
chargeId);
final BatchRequest adjustChargeRequest = BatchHelper.adjustChargeRequest(adjustChargeRequestId, createChargeRequestId);
final BatchRequest getTransactionRequest = BatchHelper.getTransactionByIdRequest(getTransactionRequestId, adjustChargeRequestId,
true);
// Create batch requests list
final List<BatchRequest> batchRequests = Arrays.asList(applyLoanRequest, approveLoanRequest, disburseLoanRequest,
createChargeRequest, adjustChargeRequest, getTransactionRequest);
// Create batch responses list
final List<BatchResponse> responses = BatchHelper.postBatchRequestsWithoutEnclosingTransaction(this.requestSpec, this.responseSpec,
BatchHelper.toJsonString(batchRequests));
Assertions.assertEquals(HttpStatus.SC_OK, responses.get(0).getStatusCode(), "Verify Status Code 200 for Apply Loan");
Assertions.assertEquals(HttpStatus.SC_OK, responses.get(1).getStatusCode(), "Verify Status Code 200 for Approve Loan");
Assertions.assertEquals(HttpStatus.SC_OK, responses.get(2).getStatusCode(), "Verify Status Code 200 for Disburse Loan");
Assertions.assertEquals(HttpStatus.SC_OK, responses.get(3).getStatusCode(), "Verify Status Code 200 for Create Charge");
Assertions.assertEquals(HttpStatus.SC_OK, responses.get(4).getStatusCode(), "Verify Status Code 200 for Adjust Charge");
Assertions.assertEquals(HttpStatus.SC_OK, responses.get(5).getStatusCode(), "Verify Status Code 200 for Get Transaction By Id");
final FromJsonHelper jsonHelper = new FromJsonHelper();
final JsonObject chargeAdjustment = jsonHelper.parse(responses.get(5).getBody()).getAsJsonObject().get("type").getAsJsonObject();
Assertions.assertEquals("Charge Adjustment", chargeAdjustment.get("value").getAsString());
Assertions.assertTrue(chargeAdjustment.get("chargeAdjustment").getAsBoolean());
}
/**
* Tests that a new charge was added to a newly created loan and charges are Collected properly 200(OK) status was
* returned for successful responses. It first creates a new client and apply a loan, then creates a new charge for
* the create loan and then fetches all the applied charges using external id
*
* @see org.apache.fineract.batch.command.internal.CollectChargesCommandStrategy
* @see org.apache.fineract.batch.command.internal.CreateChargeCommandStrategy
*/
@Test
public void shouldReturnOkStatusForCreateAndGetChargeByExternalIdCommand() {
final String loanProductJSON = new LoanProductTestBuilder() //
.withPrincipal("1000.00") //
.withNumberOfRepayments("24") //
.withRepaymentAfterEvery("1") //
.withRepaymentTypeAsMonth() //
.withinterestRatePerPeriod("2") //
.withInterestRateFrequencyTypeAsMonths() //
.withAmortizationTypeAsEqualPrincipalPayment() //
.withInterestTypeAsDecliningBalance() //
.currencyDetails("0", "100").build(null);
final Long applyLoanRequestId = Long.valueOf(RandomStringUtils.randomNumeric(4));
final Long approveLoanRequestId = applyLoanRequestId + 1;
final Long disburseLoanRequestId = approveLoanRequestId + 1;
final Long getLoanRequestId = disburseLoanRequestId + 1;
final Long createChargeRequestId = getLoanRequestId + 1;
final Long collectChargesRequestId = createChargeRequestId + 1;
final Long adjustChargeRequestId = createChargeRequestId + 1;
final Long getTransactionByExternalIdRequestId = adjustChargeRequestId + 1;
final Long getChargeByIdRequestId = getTransactionByExternalIdRequestId + 1;
// Create product
final Integer productId = new LoanTransactionHelper(this.requestSpec, this.responseSpec).getLoanProductId(loanProductJSON);
// Create client
final Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec);
ClientHelper.verifyClientCreatedOnServer(this.requestSpec, this.responseSpec, clientId);
// Create charge object and get id
final Integer chargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
ChargesHelper.getLoanSpecifiedDueDateJSON());
final BatchRequest applyLoanRequest = BatchHelper.applyLoanRequestWithClientId(applyLoanRequestId, clientId, productId);
final BatchRequest approveLoanRequest = BatchHelper.transistionLoanStateByExternalId(approveLoanRequestId, applyLoanRequestId,
LocalDate.now(ZoneId.systemDefault()).minusDays(10), "approve");
final BatchRequest disburseLoanRequest = BatchHelper.transistionLoanStateByExternalId(disburseLoanRequestId, approveLoanRequestId,
LocalDate.now(ZoneId.systemDefault()).minusDays(8), "disburse");
final BatchRequest getLoanRequest = BatchHelper.getLoanByExternalIdRequest(getLoanRequestId, approveLoanRequestId,
"associations=all");
final BatchRequest createChargeRequest = BatchHelper.createChargeByLoanExternalIdRequest(createChargeRequestId, getLoanRequestId,
chargeId);
final BatchRequest collectChargesRequest = BatchHelper.collectChargesByLoanExternalIdRequest(collectChargesRequestId,
getLoanRequestId);
// Create batch requests list
final List<BatchRequest> batchRequests = Arrays.asList(applyLoanRequest, approveLoanRequest, disburseLoanRequest, getLoanRequest,
createChargeRequest, collectChargesRequest);
// Create batch responses list
final List<BatchResponse> responses = BatchHelper.postBatchRequestsWithoutEnclosingTransaction(this.requestSpec, this.responseSpec,
BatchHelper.toJsonString(batchRequests));
Assertions.assertEquals(HttpStatus.SC_OK, responses.get(0).getStatusCode(), "Verify Status Code 200 for Apply Loan");
Assertions.assertEquals(HttpStatus.SC_OK, responses.get(1).getStatusCode(), "Verify Status Code 200 for Approve Loan");
Assertions.assertEquals(HttpStatus.SC_OK, responses.get(2).getStatusCode(), "Verify Status Code 200 for Disburse Loan");
Assertions.assertEquals(HttpStatus.SC_OK, responses.get(3).getStatusCode(), "Verify Status Code 200 for Get Loan");
Assertions.assertEquals(HttpStatus.SC_OK, responses.get(4).getStatusCode(), "Verify Status Code 200 for Create Charge");
Assertions.assertEquals(HttpStatus.SC_OK, responses.get(5).getStatusCode(), "Verify Status Code 200 for Collect charges");
final FromJsonHelper jsonHelper = new FromJsonHelper();
final String loanExternalId = jsonHelper.parse(responses.get(3).getBody()).getAsJsonObject().get("externalId").getAsString();
final String chargeExternalId = jsonHelper.parse(responses.get(4).getBody()).getAsJsonObject().get("resourceExternalId")
.getAsString();
final BatchRequest adjustChargeByExternalId = BatchHelper.adjustChargeByExternalIdRequest(adjustChargeRequestId, null,
loanExternalId, chargeExternalId);
final BatchRequest getTransactionByExternalIdRequest = BatchHelper
.getTransactionByExternalIdRequest(getTransactionByExternalIdRequestId, adjustChargeRequestId, loanExternalId, true);
final BatchRequest getChargeByIdRequest = BatchHelper.getChargeByLoanExternalIdChargeExternalId(getChargeByIdRequestId,
getTransactionByExternalIdRequestId, loanExternalId, chargeExternalId);
// Create batch responses list
final List<BatchResponse> adjustChargeAndGetResponses = BatchHelper.postBatchRequestsWithoutEnclosingTransaction(this.requestSpec,
this.responseSpec,
BatchHelper.toJsonString(Arrays.asList(adjustChargeByExternalId, getTransactionByExternalIdRequest, getChargeByIdRequest)));
Assertions.assertEquals(HttpStatus.SC_OK, adjustChargeAndGetResponses.get(0).getStatusCode(),
"Verify Status Code 200 for Adjust Charge By External Id");
Assertions.assertEquals(HttpStatus.SC_OK, adjustChargeAndGetResponses.get(1).getStatusCode(),
"Verify Status Code 200 for Get Transaction By Id");
Assertions.assertEquals(HttpStatus.SC_OK, adjustChargeAndGetResponses.get(2).getStatusCode(),
"Verify Status Code 200 for Get Charge By Id");
final JsonObject chargeAdjustment = jsonHelper.parse(adjustChargeAndGetResponses.get(1).getBody()).getAsJsonObject().get("type")
.getAsJsonObject();
Assertions.assertEquals("Charge Adjustment", chargeAdjustment.get("value").getAsString());
Assertions.assertTrue(chargeAdjustment.get("chargeAdjustment").getAsBoolean());
}
/**
* Tests that batch repayment for loans is happening properly. Collected properly 200(OK) status was returned for
* successful responses. It first creates a new loan and then makes two repayments for it and then verifies that
@@ -852,7 +1034,7 @@ public class BatchApiTest {
final BatchRequest batchRequest3 = BatchHelper.disburseLoanRequest(disburseLoanRequestId, approveLoanRequestId);
// Create a getTransaction Request
final BatchRequest batchRequest4 = BatchHelper.getTransactionByIdRequest(getTransactionRequestId, disburseLoanRequestId);
final BatchRequest batchRequest4 = BatchHelper.getTransactionByIdRequest(getTransactionRequestId, disburseLoanRequestId, false);
final List<BatchRequest> batchRequests = Arrays.asList(batchRequest1, batchRequest2, batchRequest3, batchRequest4);
@@ -1391,6 +1573,111 @@ public class BatchApiTest {
Assertions.assertEquals(date, reversedOnDate);
}
/**
* Test for the successful repayment reversal transaction using loan external id and transaction external id. A
* '200' status code is expected on successful responses.
*
* @see AdjustTransactionCommandStrategy
*/
@Test
public void shouldReturnOkStatusForBatchRepaymentReversalUsingExternalId() {
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 productId = new LoanTransactionHelper(this.requestSpec, this.responseSpec).getLoanProductId(loanProductJSON);
final LocalDate date = LocalDate.now(Utils.getZoneIdOfTenant());
final Long applyLoanRequestId = Long.valueOf(RandomStringUtils.randomNumeric(4));
final Long approveLoanRequestId = applyLoanRequestId + 1;
final Long disburseLoanRequestId = approveLoanRequestId + 1;
final Long getLoanBeforeTxnRequestId = disburseLoanRequestId + 1;
final Long repayLoanRequestId = getLoanBeforeTxnRequestId + 1;
final Long getLoanAfterTxnRequestId = repayLoanRequestId + 1;
final Long repayReversalRequestId = getLoanAfterTxnRequestId + 1;
final Long getLoanAfterReversal = repayReversalRequestId + 1;
// Create client
final Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec);
ClientHelper.verifyClientCreatedOnServer(this.requestSpec, this.responseSpec, clientId);
final String loanExternalId = UUID.randomUUID().toString();
// Create an apply loan request
final BatchRequest applyLoanRequest = BatchHelper.applyLoanRequestWithClientIdAndExternalId(applyLoanRequestId, clientId, productId,
loanExternalId);
// Create an approve loan request
final BatchRequest approveLoanRequest = BatchHelper.approveLoanRequest(approveLoanRequestId, applyLoanRequestId);
// Create a disburse loan request
final BatchRequest disburseLoanRequest = BatchHelper.disburseLoanRequest(disburseLoanRequestId, approveLoanRequestId);
// Get loan transactions request
final BatchRequest getLoanTransactionsRequestBeforeTxn = BatchHelper.getLoanByIdRequest(getLoanBeforeTxnRequestId,
disburseLoanRequestId, "associations=transactions");
// Create a repayment request by external id
final BatchRequest repaymentRequest = BatchHelper.createTransactionRequestByLoanExternalId(repayLoanRequestId,
getLoanBeforeTxnRequestId, "repayment", "500", LocalDate.now(ZoneId.systemDefault()));
// Get loan transactions request
final BatchRequest getLoanTransactionsRequestAfterTxn = BatchHelper.getLoanByIdRequest(getLoanAfterTxnRequestId, repayLoanRequestId,
"associations=transactions");
final List<BatchRequest> batchRequests = Arrays.asList(applyLoanRequest, approveLoanRequest, disburseLoanRequest,
getLoanTransactionsRequestBeforeTxn, repaymentRequest, getLoanTransactionsRequestAfterTxn);
// Because loanExternalId & transactionExternalId are coming from 2 different responses, there is no easy way to
// use them as reference in 1 batch api call.
// So we are splitting repayment & reversal into 2 different batch api invocations
final List<BatchResponse> responses = BatchHelper.postBatchRequestsWithoutEnclosingTransaction(this.requestSpec, this.responseSpec,
BatchHelper.toJsonString(batchRequests));
final FromJsonHelper jsonHelper = new FromJsonHelper();
final String loanExternalIdDisburseLoanResponse = jsonHelper.parse(responses.get(3).getBody()).getAsJsonObject().get("externalId")
.getAsString();
final Long loanId = jsonHelper.parse(responses.get(3).getBody()).getAsJsonObject().get("id").getAsLong();
final String transactionExternalId = jsonHelper.parse(responses.get(4).getBody()).getAsJsonObject().get("resourceExternalId")
.getAsString();
Assertions.assertNotNull(loanExternalIdDisburseLoanResponse);
Assertions.assertEquals(loanExternalId, loanExternalIdDisburseLoanResponse);
Assertions.assertNotNull(transactionExternalId);
// Create a repayment reversal request by external id
final BatchRequest repaymentReversalRequest = BatchHelper.createAdjustTransactionByExternalIdRequest(repayReversalRequestId, null,
loanExternalIdDisburseLoanResponse, transactionExternalId, "0", date);
final BatchRequest getLoanByIdWithTransactions = BatchHelper.getLoanByIdRequest(loanId, getLoanAfterReversal,
repayReversalRequestId, "associations=transactions");
final List<BatchRequest> reversalAndGetBatchRequest = Arrays.asList(repaymentReversalRequest, getLoanByIdWithTransactions);
final List<BatchResponse> reversalResponses = BatchHelper.postBatchRequestsWithoutEnclosingTransaction(this.requestSpec,
this.responseSpec, BatchHelper.toJsonString(reversalAndGetBatchRequest));
final JsonObject repayment = jsonHelper.parse(reversalResponses.get(1).getBody()).getAsJsonObject().get("transactions")
.getAsJsonArray().get(2).getAsJsonObject();
final JsonArray dateArray = repayment.get("reversedOnDate").getAsJsonArray();
final LocalDate reversedOnDate = LocalDate.of(dateArray.get(0).getAsInt(), dateArray.get(1).getAsInt(),
dateArray.get(2).getAsInt());
Assertions.assertEquals(HttpStatus.SC_OK, (long) reversalResponses.get(0).getStatusCode(),
"Verify Status Code 200 for repayment reversal");
Assertions.assertEquals("Repayment", repayment.get("type").getAsJsonObject().get("value").getAsString());
Assertions.assertTrue(repayment.get("manuallyReversed").getAsBoolean());
Assertions.assertEquals(date, reversedOnDate);
}
/**
* Test for the successful repayment chargeback transaction. A '200' status code is expected on successful
* responses.
@@ -1798,6 +2085,131 @@ public class BatchApiTest {
Assertions.assertEquals(changes.get(columnName2).getAsString(), columnValue2 + "1");
}
/**
* Tests that a loan information was successfully updated through updateLoanCommand. A 'changes' parameter is
* returned as part of response after successful update of loan information. In this test, we are marking an active
* loan account as fraud.
*
* @see org.apache.fineract.batch.command.internal.ModifyLoanApplicationCommandStrategy
*/
@Test
public void shouldReflectChangesOnLoanUpdate() {
final String loanProductJSON = new LoanProductTestBuilder() //
.withPrincipal("1000.00") //
.withNumberOfRepayments("24") //
.withRepaymentAfterEvery("1") //
.withRepaymentTypeAsMonth() //
.withinterestRatePerPeriod("2") //
.withInterestRateFrequencyTypeAsMonths() //
.withAmortizationTypeAsEqualPrincipalPayment() //
.withInterestTypeAsDecliningBalance() //
.currencyDetails("0", "100").build(null);
final Long applyLoanRequestId = RandomUtils.nextLong(100, 1000);
final Long approveLoanRequestId = applyLoanRequestId + 1;
final Long disburseLoanRequestId = approveLoanRequestId + 1;
final Long updateLoanRequestId = disburseLoanRequestId + 1;
// Create product
final Integer productId = new LoanTransactionHelper(this.requestSpec, this.responseSpec).getLoanProductId(loanProductJSON);
// Create client
final Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec);
ClientHelper.verifyClientCreatedOnServer(this.requestSpec, this.responseSpec, clientId);
final BatchRequest applyLoanRequest = BatchHelper.applyLoanRequestWithClientId(applyLoanRequestId, clientId, productId);
final BatchRequest approveLoanRequest = BatchHelper.approveLoanRequest(approveLoanRequestId, applyLoanRequestId);
final BatchRequest disburseLoanRequest = BatchHelper.disburseLoanRequest(disburseLoanRequestId, approveLoanRequestId);
final BatchRequest updateLoanRequest = BatchHelper.createLoanRequestMarkAsFraud(updateLoanRequestId, disburseLoanRequestId);
// Create batch requests list
final List<BatchRequest> batchRequests = Arrays.asList(applyLoanRequest, approveLoanRequest, disburseLoanRequest,
updateLoanRequest);
final String jsonifiedRequest = BatchHelper.toJsonString(batchRequests);
final List<BatchResponse> response = BatchHelper.postBatchRequestsWithoutEnclosingTransaction(this.requestSpec, this.responseSpec,
jsonifiedRequest);
// Get the changes parameter from updateLoan Response
final JsonObject changes = new FromJsonHelper().parse(response.get(3).getBody()).getAsJsonObject().get("changes").getAsJsonObject();
Assertions.assertEquals(HttpStatus.SC_OK, response.get(3).getStatusCode(), "Verify Status Code 200 for update loan application");
Assertions.assertEquals("true", changes.get("fraud").getAsString());
}
/**
* Tests that a loan information was successfully updated through updateLoanCommand using external id. A 'changes'
* parameter is returned as part of response after successful update of loan information. In this test, we are
* marking an active loan account as fraud.
*
* @see org.apache.fineract.batch.command.internal.ModifyLoanApplicationByExternalIdCommandStrategy
*/
@Test
public void shouldReflectChangesOnLoanUpdateByExternalId() {
final String loanProductJSON = new LoanProductTestBuilder() //
.withPrincipal("1000.00") //
.withNumberOfRepayments("24") //
.withRepaymentAfterEvery("1") //
.withRepaymentTypeAsMonth() //
.withinterestRatePerPeriod("2") //
.withInterestRateFrequencyTypeAsMonths() //
.withAmortizationTypeAsEqualPrincipalPayment() //
.withInterestTypeAsDecliningBalance() //
.currencyDetails("0", "100").build(null);
final Long applyLoanRequestId = RandomUtils.nextLong(100, 1000);
final Long approveLoanRequestId = applyLoanRequestId + 1;
final Long disburseLoanRequestId = approveLoanRequestId + 1;
final Long updateLoanRequestId = disburseLoanRequestId + 1;
final Long getLoanRequestId = updateLoanRequestId + 1;
// Create product
final Integer productId = new LoanTransactionHelper(this.requestSpec, this.responseSpec).getLoanProductId(loanProductJSON);
// Create client
final Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec);
ClientHelper.verifyClientCreatedOnServer(this.requestSpec, this.responseSpec, clientId);
final BatchRequest applyLoanRequest = BatchHelper.applyLoanRequestWithClientId(applyLoanRequestId, clientId, productId);
final BatchRequest approveLoanRequest = BatchHelper.transistionLoanStateByExternalId(approveLoanRequestId, applyLoanRequestId,
LocalDate.now(ZoneId.systemDefault()).minusDays(10), "approve");
final BatchRequest disburseLoanRequest = BatchHelper.transistionLoanStateByExternalId(disburseLoanRequestId, approveLoanRequestId,
LocalDate.now(ZoneId.systemDefault()).minusDays(8), "disburse");
final BatchRequest updateLoanRequest = BatchHelper.modifyLoanByExternalIdRequest(updateLoanRequestId, approveLoanRequestId);
final BatchRequest getLoanRequest = BatchHelper.getLoanByExternalIdRequest(getLoanRequestId, approveLoanRequestId,
"associations=all");
// Create batch requests list
final List<BatchRequest> batchRequests = Arrays.asList(applyLoanRequest, approveLoanRequest, disburseLoanRequest, updateLoanRequest,
getLoanRequest);
final String jsonifiedRequest = BatchHelper.toJsonString(batchRequests);
final List<BatchResponse> responses = BatchHelper.postBatchRequestsWithoutEnclosingTransaction(this.requestSpec, this.responseSpec,
jsonifiedRequest);
Assertions.assertEquals(HttpStatus.SC_OK, responses.get(0).getStatusCode(), "Verify Status Code 200 for Apply Loan");
Assertions.assertEquals(HttpStatus.SC_OK, responses.get(1).getStatusCode(), "Verify Status Code 200 for Approve Loan");
Assertions.assertEquals(HttpStatus.SC_OK, responses.get(2).getStatusCode(), "Verify Status Code 200 for Disburse Loan");
Assertions.assertEquals(HttpStatus.SC_OK, responses.get(3).getStatusCode(), "Verify Status Code 200 for update loan application");
Assertions.assertEquals(HttpStatus.SC_OK, responses.get(4).getStatusCode(), "Verify Status Code 200 for Get Loan");
// Get the changes parameter from updateLoan Response
final JsonObject changes = new FromJsonHelper().parse(responses.get(3).getBody()).getAsJsonObject().get("changes")
.getAsJsonObject();
Assertions.assertEquals("true", changes.get("fraud").getAsString());
}
/**
* Delete datatable
*
@@ -28,6 +28,7 @@ import io.restassured.builder.ResponseSpecBuilder;
import io.restassured.http.ContentType;
import io.restassured.specification.RequestSpecification;
import io.restassured.specification.ResponseSpecification;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
@@ -952,17 +953,20 @@ public class ExternalIdSupportIntegrationTest extends IntegrationTest {
String loanExternalIdStr5 = UUID.randomUUID().toString();
applyForLoanApplication(client.getClientId().intValue(), loanProductID, loanExternalIdStr5);
this.loanTransactionHelper.approveLoan(loanExternalIdStr5, new PostLoansLoanIdRequest().approvedOnDate("2 September 2022")
.approvedLoanAmount("1000").expectedDisbursementDate("2 September 2022").locale("en").dateFormat("dd MMMM yyyy"));
result = this.loanTransactionHelper.disburseLoan(loanExternalIdStr5, new PostLoansLoanIdRequest()
.actualDisbursementDate("2 September 2022").transactionAmount("1000").locale("en").dateFormat("dd MMMM yyyy"));
this.loanTransactionHelper.approveLoan(loanExternalIdStr5,
new PostLoansLoanIdRequest().approvedOnDate("2 September 2022").approvedLoanAmount(new BigDecimal("1000"))
.expectedDisbursementDate("2 September 2022").locale("en").dateFormat("dd MMMM yyyy"));
result = this.loanTransactionHelper.disburseLoan(loanExternalIdStr5,
new PostLoansLoanIdRequest().actualDisbursementDate("2 September 2022").transactionAmount(new BigDecimal("1000"))
.locale("en").dateFormat("dd MMMM yyyy"));
// It's commented out for now, till it got fixed to return the loan externalId as well
// assertEquals(loanExternalIdStr5, result.getResourceExternalId());
String loanExternalIdStr6 = UUID.randomUUID().toString();
applyForLoanApplication(client.getClientId().intValue(), loanProductID, loanExternalIdStr6);
this.loanTransactionHelper.approveLoan(loanExternalIdStr6, new PostLoansLoanIdRequest().approvedOnDate("2 September 2022")
.approvedLoanAmount("1000").expectedDisbursementDate("2 September 2022").locale("en").dateFormat("dd MMMM yyyy"));
this.loanTransactionHelper.approveLoan(loanExternalIdStr6,
new PostLoansLoanIdRequest().approvedOnDate("2 September 2022").approvedLoanAmount(new BigDecimal("1000"))
.expectedDisbursementDate("2 September 2022").locale("en").dateFormat("dd MMMM yyyy"));
result = this.loanTransactionHelper.undoApprovalLoan(loanExternalIdStr6, new PostLoansLoanIdRequest());
assertEquals(loanExternalIdStr6, result.getResourceExternalId());
@@ -971,29 +975,36 @@ public class ExternalIdSupportIntegrationTest extends IntegrationTest {
String loanExternalIdStr7 = UUID.randomUUID().toString();
applyForLoanApplication(client.getClientId().intValue(), loanProductID, loanExternalIdStr7, savingsId.toString());
this.loanTransactionHelper.approveLoan(loanExternalIdStr7, new PostLoansLoanIdRequest().approvedOnDate("2 September 2022")
.approvedLoanAmount("1000").expectedDisbursementDate("2 September 2022").locale("en").dateFormat("dd MMMM yyyy"));
result = this.loanTransactionHelper.disburseToSavingsLoan(loanExternalIdStr7, new PostLoansLoanIdRequest()
.actualDisbursementDate("2 September 2022").transactionAmount("1000").locale("en").dateFormat("dd MMMM yyyy"));
this.loanTransactionHelper.approveLoan(loanExternalIdStr7,
new PostLoansLoanIdRequest().approvedOnDate("2 September 2022").approvedLoanAmount(new BigDecimal("1000"))
.expectedDisbursementDate("2 September 2022").locale("en").dateFormat("dd MMMM yyyy"));
result = this.loanTransactionHelper.disburseToSavingsLoan(loanExternalIdStr7,
new PostLoansLoanIdRequest().actualDisbursementDate("2 September 2022").transactionAmount(new BigDecimal("1000"))
.locale("en").dateFormat("dd MMMM yyyy"));
assertEquals(loanExternalIdStr7, result.getResourceExternalId());
String loanExternalIdStr8 = UUID.randomUUID().toString();
applyForLoanApplication(client.getClientId().intValue(), loanProductID, loanExternalIdStr8);
this.loanTransactionHelper.approveLoan(loanExternalIdStr8, new PostLoansLoanIdRequest().approvedOnDate("2 September 2022")
.approvedLoanAmount("1000").expectedDisbursementDate("2 September 2022").locale("en").dateFormat("dd MMMM yyyy"));
this.loanTransactionHelper.disburseLoan(loanExternalIdStr8, new PostLoansLoanIdRequest()
.actualDisbursementDate("2 September 2022").transactionAmount("1000").locale("en").dateFormat("dd MMMM yyyy"));
this.loanTransactionHelper.approveLoan(loanExternalIdStr8,
new PostLoansLoanIdRequest().approvedOnDate("2 September 2022").approvedLoanAmount(new BigDecimal("1000"))
.expectedDisbursementDate("2 September 2022").locale("en").dateFormat("dd MMMM yyyy"));
this.loanTransactionHelper.disburseLoan(loanExternalIdStr8,
new PostLoansLoanIdRequest().actualDisbursementDate("2 September 2022").transactionAmount(new BigDecimal("1000"))
.locale("en").dateFormat("dd MMMM yyyy"));
result = this.loanTransactionHelper.undoDisbursalLoan(loanExternalIdStr8, new PostLoansLoanIdRequest());
assertEquals(loanExternalIdStr8, result.getResourceExternalId());
String loanExternalIdStr9 = UUID.randomUUID().toString();
applyForLoanApplication(client.getClientId().intValue(), loanProductID, loanExternalIdStr9);
this.loanTransactionHelper.approveLoan(loanExternalIdStr9, new PostLoansLoanIdRequest().approvedOnDate("2 September 2022")
.approvedLoanAmount("1000").expectedDisbursementDate("2 September 2022").locale("en").dateFormat("dd MMMM yyyy"));
this.loanTransactionHelper.disburseLoan(loanExternalIdStr9, new PostLoansLoanIdRequest()
.actualDisbursementDate("2 September 2022").transactionAmount("1000").locale("en").dateFormat("dd MMMM yyyy"));
this.loanTransactionHelper.disburseLoan(loanExternalIdStr9, new PostLoansLoanIdRequest()
.actualDisbursementDate("3 September 2022").transactionAmount("1000").locale("en").dateFormat("dd MMMM yyyy"));
this.loanTransactionHelper.approveLoan(loanExternalIdStr9,
new PostLoansLoanIdRequest().approvedOnDate("2 September 2022").approvedLoanAmount(new BigDecimal("1000"))
.expectedDisbursementDate("2 September 2022").locale("en").dateFormat("dd MMMM yyyy"));
this.loanTransactionHelper.disburseLoan(loanExternalIdStr9,
new PostLoansLoanIdRequest().actualDisbursementDate("2 September 2022").transactionAmount(new BigDecimal("1000"))
.locale("en").dateFormat("dd MMMM yyyy"));
this.loanTransactionHelper.disburseLoan(loanExternalIdStr9,
new PostLoansLoanIdRequest().actualDisbursementDate("3 September 2022").transactionAmount(new BigDecimal("1000"))
.locale("en").dateFormat("dd MMMM yyyy"));
result = this.loanTransactionHelper.undoLastDisbursalLoan(loanExternalIdStr9, new PostLoansLoanIdRequest());
assertEquals(loanExternalIdStr9, result.getResourceExternalId());
@@ -1020,7 +1031,7 @@ public class ExternalIdSupportIntegrationTest extends IntegrationTest {
String loanExternalIdStr13 = UUID.randomUUID().toString();
applyForLoanApplication(client.getClientId().intValue(), loanProductID, loanExternalIdStr13);
result = this.loanTransactionHelper.approveLoan(loanExternalIdStr13,
new PostLoansLoanIdRequest().approvedOnDate("2 September 2022").approvedLoanAmount("1000")
new PostLoansLoanIdRequest().approvedOnDate("2 September 2022").approvedLoanAmount(new BigDecimal("1000"))
.expectedDisbursementDate("2 September 2022").locale("en").dateFormat("dd MMMM yyyy"));
assertEquals(loanExternalIdStr13, result.getResourceExternalId());
@@ -1032,11 +1043,12 @@ public class ExternalIdSupportIntegrationTest extends IntegrationTest {
applyForLoanApplication(client.getClientId().intValue(), loanProductID, loanExternalIdStr14);
String transactionExternalId = UUID.randomUUID().toString();
result = this.loanTransactionHelper.approveLoan(loanExternalIdStr14,
new PostLoansLoanIdRequest().approvedOnDate("2 September 2022").approvedLoanAmount("1000")
new PostLoansLoanIdRequest().approvedOnDate("2 September 2022").approvedLoanAmount(new BigDecimal("1000"))
.expectedDisbursementDate("2 September 2022").locale("en").dateFormat("dd MMMM yyyy"));
assertEquals(loanExternalIdStr14, result.getResourceExternalId());
this.loanTransactionHelper.disburseLoan(loanExternalIdStr14, new PostLoansLoanIdRequest()
.actualDisbursementDate("2 September 2022").transactionAmount("1000").locale("en").dateFormat("dd MMMM yyyy"));
this.loanTransactionHelper.disburseLoan(loanExternalIdStr14,
new PostLoansLoanIdRequest().actualDisbursementDate("2 September 2022").transactionAmount(new BigDecimal("1000"))
.locale("en").dateFormat("dd MMMM yyyy"));
PostLoansLoanIdTransactionsResponse closeResult = this.loanTransactionHelper.closeLoan(loanExternalIdStr14,
new PostLoansLoanIdTransactionsRequest().transactionDate("3 September 2022").locale("en").dateFormat("dd MMMM yyyy")
.externalId(transactionExternalId));
@@ -1046,10 +1058,11 @@ public class ExternalIdSupportIntegrationTest extends IntegrationTest {
String transactionExternalId2 = UUID.randomUUID().toString();
applyForLoanApplication(client.getClientId().intValue(), loanProductID, loanExternalIdStr15);
result = this.loanTransactionHelper.approveLoan(loanExternalIdStr15,
new PostLoansLoanIdRequest().approvedOnDate("2 September 2022").approvedLoanAmount("1000")
new PostLoansLoanIdRequest().approvedOnDate("2 September 2022").approvedLoanAmount(new BigDecimal("1000"))
.expectedDisbursementDate("2 September 2022").locale("en").dateFormat("dd MMMM yyyy"));
this.loanTransactionHelper.disburseLoan(loanExternalIdStr15, new PostLoansLoanIdRequest()
.actualDisbursementDate("2 September 2022").transactionAmount("1000").locale("en").dateFormat("dd MMMM yyyy"));
this.loanTransactionHelper.disburseLoan(loanExternalIdStr15,
new PostLoansLoanIdRequest().actualDisbursementDate("2 September 2022").transactionAmount(new BigDecimal("1000"))
.locale("en").dateFormat("dd MMMM yyyy"));
assertEquals(loanExternalIdStr15, result.getResourceExternalId());
PostLoansLoanIdTransactionsResponse forecloseResult = this.loanTransactionHelper.forecloseLoan(loanExternalIdStr15,
new PostLoansLoanIdTransactionsRequest().transactionDate("2 September 2022").locale("en").dateFormat("dd MMMM yyyy")
@@ -30,6 +30,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;
import javax.ws.rs.HttpMethod;
import org.apache.fineract.batch.command.internal.CreateTransactionLoanCommandStrategy;
@@ -302,6 +303,25 @@ public final class BatchHelper {
* @return {@link BatchRequest}
*/
public static BatchRequest applyLoanRequestWithClientId(final Long requestId, final Integer clientId, final Integer productId) {
return applyLoanRequestWithClientIdAndExternalId(requestId, clientId, productId, UUID.randomUUID().toString());
}
/**
* Creates and returns a {@link org.apache.fineract.batch.command.internal.ApplyLoanCommandStrategy} request with
* given clientId, external id and product id.
*
* @param requestId
* the request id
* @param clientId
* the client id
* @param productId
* the product id
* @param externalId
* the external id
* @return {@link BatchRequest}
*/
public static BatchRequest applyLoanRequestWithClientIdAndExternalId(final Long requestId, final Integer clientId,
final Integer productId, final String externalId) {
final BatchRequest br = new BatchRequest();
@@ -315,7 +335,7 @@ public final class BatchHelper {
+ "\"repaymentEvery\": 1, \"repaymentFrequencyType\": 2, \"interestRatePerPeriod\": 10,"
+ "\"amortizationType\": 1, \"interestType\": 0, \"interestCalculationPeriodType\": 1,"
+ "\"transactionProcessingStrategyCode\": \"mifos-standard-strategy\", \"expectedDisbursementDate\": \"10 Jun 2013\","
+ "\"submittedOnDate\": \"10 Jun 2013\"}", clientId, productId);
+ "\"submittedOnDate\": \"10 Jun 2013\", \"externalId\": \"%s\"}", clientId, productId, externalId);
br.setBody(body);
@@ -349,7 +369,7 @@ public final class BatchHelper {
/**
* Creates and returns a {@link org.apache.fineract.batch.command.internal.CreateChargeCommandStrategy} Request with
* given requestId and reference
* given requestId and reference based on loan id
*
* @param requestId
* the batch request id.
@@ -359,11 +379,46 @@ public final class BatchHelper {
* the charge id used for getting charge type.
* @return BatchRequest
*/
public static BatchRequest createChargeRequest(final Long requestId, final Long reference, final Integer chargeId) {
public static BatchRequest createChargeByLoanIdRequest(final Long requestId, final Long reference, final Integer chargeId) {
return createChargeRequest(requestId, reference, "loans/$.loanId/charges", chargeId);
}
/**
* Creates and returns a
* {@link org.apache.fineract.batch.command.internal.CreateChargeByLoanExternalIdCommandStrategy} Request with given
* requestId and reference based on loan external id
*
* @param requestId
* the batch request id.
* @param reference
* the reference id.
* @param chargeId
* the charge id used for getting charge type.
* @return BatchRequest
*/
public static BatchRequest createChargeByLoanExternalIdRequest(final Long requestId, final Long reference, final Integer chargeId) {
return createChargeRequest(requestId, reference, "loans/external-id/$.externalId/charges", chargeId);
}
/**
* Creates and returns a Batch Request with given requestId and reference
*
* @param requestId
* the batch request id.
* @param reference
* the reference id.
* @param relativeUrl
* the relative url reference.
* @param chargeId
* the charge id used for getting charge type.
* @return BatchRequest
*/
private static BatchRequest createChargeRequest(final Long requestId, final Long reference, final String relativeUrl,
final Integer chargeId) {
final BatchRequest br = new BatchRequest();
br.setRequestId(requestId);
br.setRelativeUrl("loans/$.loanId/charges");
br.setRelativeUrl(relativeUrl);
br.setMethod("POST");
br.setReference(reference);
@@ -378,20 +433,103 @@ public final class BatchHelper {
return br;
}
/**
* Creates and returns a {@link org.apache.fineract.batch.command.internal.AdjustChargeCommandStrategy} Request with
* given requestId and reference
*
* @param requestId
* the batch request id.
* @param reference
* the reference id.
* @return BatchRequest
*/
public static BatchRequest adjustChargeRequest(final Long requestId, final Long reference) {
final BatchRequest br = new BatchRequest();
br.setRequestId(requestId);
br.setRelativeUrl("loans/$.loanId/charges/$.resourceId?command=adjustment");
br.setMethod("POST");
br.setReference(reference);
br.setBody("{\"amount\":7.00,\"locale\":\"en\"}");
return br;
}
/**
* Creates and returns a
* {@link org.apache.fineract.batch.command.internal.AdjustChargeByChargeExternalIdCommandStrategy} Request with
* given requestId and reference
*
* @param requestId
* the batch request id.
* @param reference
* the reference id.
* @param loanExternalId
* the loan external id.
* @param chargeExternalId
* the charge external id
* @return BatchRequest
*/
public static BatchRequest adjustChargeByExternalIdRequest(final Long requestId, final Long reference, final String loanExternalId,
final String chargeExternalId) {
final BatchRequest br = new BatchRequest();
br.setRequestId(requestId);
br.setRelativeUrl(
String.format("loans/external-id/%s/charges/external-id/%s?command=adjustment", loanExternalId, chargeExternalId));
br.setMethod("POST");
br.setReference(reference);
br.setBody("{\"amount\":7.00,\"locale\":\"en\"}");
return br;
}
/**
* Creates and returns a {@link org.apache.fineract.batch.command.internal.CollectChargesCommandStrategy} Request
* with given requestId and reference.
*
* @param requestId
* the request id
* @param reference
* the reference id
* @return BatchRequest
*/
public static BatchRequest collectChargesRequest(final Long requestId, final Long reference) {
public static BatchRequest collectChargesByLoanIdRequest(final Long requestId, final Long reference) {
return collectChargesRequest(requestId, reference, "loans/$.loanId/charges");
}
/**
* Creates and returns a
* {@link org.apache.fineract.batch.command.internal.CollectChargesByLoanExternalIdCommandStrategy} Request with
* given requestId and reference.
*
* @param requestId
* the request id
* @param reference
* the reference id
* @return BatchRequest
*/
public static BatchRequest collectChargesByLoanExternalIdRequest(final Long requestId, final Long reference) {
return collectChargesRequest(requestId, reference, "loans/external-id/$.externalId/charges");
}
/**
* Creates and returns a Batch Request with given requestId and reference.
*
* @param requestId
* the request id
* @param reference
* the reference id
* @param relativeUrl
* the relative url
* @return BatchRequest
*/
private static BatchRequest collectChargesRequest(final Long requestId, final Long reference, final String relativeUrl) {
final BatchRequest br = new BatchRequest();
br.setRequestId(requestId);
br.setRelativeUrl("loans/$.loanId/charges");
br.setRelativeUrl(relativeUrl);
br.setReference(reference);
br.setMethod("GET");
br.setBody("{ }");
@@ -399,6 +537,29 @@ public final class BatchHelper {
return br;
}
/**
* Creates and returns a Batch request with given requestId and reference.
*
* @param requestId
* the request id
* @param reference
* the reference
* @param relativeUrl
* the relative url
* @return the {@link BatchRequest}
*/
private static BatchRequest getChargeById(final Long requestId, final Long reference, final String relativeUrl) {
final BatchRequest br = new BatchRequest();
br.setRequestId(requestId);
br.setRelativeUrl(relativeUrl);
br.setMethod(HttpMethod.GET);
br.setReference(reference);
br.setBody("{}");
return br;
}
/**
* Creates and returns a {@link org.apache.fineract.batch.command.internal.GetChargeByIdCommandStrategy} request
* with given requestId and reference.
@@ -409,18 +570,25 @@ public final class BatchHelper {
* the reference
* @return the {@link BatchRequest}
*/
public static BatchRequest getChargeByIdCommandStrategy(final Long requestId, final Long reference) {
public static BatchRequest getChargeByLoanIdChargeId(final Long requestId, final Long reference) {
return getChargeById(requestId, reference, "loans/$.loanId/charges/$.resourceId");
}
final BatchRequest br = new BatchRequest();
String relativeUrl = "loans/$.loanId/charges/$.resourceId";
br.setRequestId(requestId);
br.setRelativeUrl(relativeUrl);
br.setMethod(HttpMethod.GET);
br.setReference(reference);
br.setBody("{}");
return br;
/**
* Creates and returns a
* {@link org.apache.fineract.batch.command.internal.GetChargeByChargeExternalIdCommandStrategy} request with given
* requestId and reference.
*
* @param requestId
* the request id
* @param reference
* the reference
* @return the {@link BatchRequest}
*/
public static BatchRequest getChargeByLoanExternalIdChargeExternalId(final Long requestId, final Long reference,
final String loanExternalId, final String chargeExternalId) {
return getChargeById(requestId, reference,
String.format("loans/external-id/%s/charges/external-id/%s", loanExternalId, chargeExternalId));
}
/**
@@ -528,6 +696,41 @@ public final class BatchHelper {
return br;
}
/**
* Creates and returns a
* {@link org.apache.fineract.batch.command.internal.LoanStateTransistionsByExternalIdCommandStrategy} Request with
* given requestId and reference.
*
*
* @param requestId
* the request ID
* @param reference
* the reference ID
* @param date
* the actual disbursement date
* @param command
* the action to transistion
* @return BatchRequest the batch request
*/
public static BatchRequest transistionLoanStateByExternalId(final Long requestId, final Long reference, final LocalDate date,
final String command) {
final BatchRequest br = new BatchRequest();
br.setRequestId(requestId);
br.setRelativeUrl("loans/external-id/$.resourceExternalId?command=" + command);
br.setReference(reference);
br.setMethod("POST");
String dateString = date.format(DateTimeFormatter.ofPattern("dd MMMM yyyy"));
if ("disburse".equals(command)) {
br.setBody("{\"locale\": \"en\", \"dateFormat\": \"dd MMMM yyyy\", \"actualDisbursementDate\": \"" + dateString + "\"}");
} else if ("approve".equals(command)) {
br.setBody("{\"locale\": \"en\", \"dateFormat\": \"dd MMMM yyyy\", \"approvedOnDate\": \"" + dateString + "\","
+ "\"note\": \"Loan approval note\"}");
}
return br;
}
/**
* Creates and returns a {@link CreateTransactionLoanCommandStrategy} Request with given requestId.
*
@@ -572,6 +775,37 @@ public final class BatchHelper {
return br;
}
/**
* Creates and returns a {@link CreateTransactionLoanCommandStrategy} Request with given requestId.
*
* @param requestId
* the request ID
* @param reference
* the reference ID
* @param transactionCommand
* the transaction command to process
* @param amount
* the amount
* @param date
* the transaction date
* @return BatchRequest the batch request
*/
public static BatchRequest createTransactionRequestByLoanExternalId(final Long requestId, final Long reference,
final String transactionCommand, final String amount, final LocalDate date) {
final BatchRequest br = new BatchRequest();
br.setRequestId(requestId);
br.setReference(reference);
br.setRelativeUrl(String.format("loans/external-id/$.externalId/transactions?command=%s", transactionCommand));
br.setMethod("POST");
String dateString = date.format(DateTimeFormatter.ofPattern("dd MMMM yyyy"));
br.setBody(String.format(
"{\"locale\": \"en\", \"dateFormat\": \"dd MMMM yyyy\", " + "\"transactionDate\": \"%s\", \"transactionAmount\": %s}",
dateString, amount));
return br;
}
/**
* Creates and returns a {@link CreateTransactionLoanCommandStrategy} request with given request ID.
*
@@ -725,12 +959,50 @@ public final class BatchHelper {
* the request id
* @param reference
* the reference
* @param subResourceId
* whether the subResourceId is used
* @return the {@link BatchRequest}
*/
public static BatchRequest getTransactionByIdRequest(final Long requestId, final Long reference) {
public static BatchRequest getTransactionByIdRequest(final Long requestId, final Long reference, final Boolean subResourceId) {
final BatchRequest br = new BatchRequest();
String relativeUrl = "loans/$.loanId/transactions/$.resourceId";
String relativeUrl;
if (subResourceId) {
relativeUrl = "loans/$.loanId/transactions/$.subResourceId";
} else {
relativeUrl = "loans/$.loanId/transactions/$.resourceId";
}
br.setRequestId(requestId);
br.setRelativeUrl(relativeUrl);
br.setMethod(HttpMethod.GET);
br.setReference(reference);
br.setBody("{}");
return br;
}
/**
* Creates and returns a
* {@link org.apache.fineract.batch.command.internal.GetTransactionByExternalIdCommandStrategy} request with given
* requestId and reference.
*
* @param requestId
* the request id
* @param reference
* the reference
* @return the {@link BatchRequest}
*/
public static BatchRequest getTransactionByExternalIdRequest(final Long requestId, final Long reference, final String loanExternalId,
final Boolean subResourceExternalId) {
final BatchRequest br = new BatchRequest();
String relativeUrl;
if (subResourceExternalId) {
relativeUrl = String.format("loans/external-id/%s/transactions/external-id/$.subResourceExternalId", loanExternalId);
} else {
relativeUrl = String.format("loans/external-id/%s/transactions/external-id/$.resourceExternalId", loanExternalId);
}
br.setRequestId(requestId);
br.setRelativeUrl(relativeUrl);
@@ -770,6 +1042,35 @@ public final class BatchHelper {
return br;
}
/**
* Creates and returns a {@link org.apache.fineract.batch.command.internal.GetLoanByExternalIdCommandStrategy}
* request with given requestId and reference.
*
* @param requestId
* the request id
* @param reference
* the reference
* @param queryParameter
* the query parameters
* @return the {@link BatchRequest}
*/
public static BatchRequest getLoanByExternalIdRequest(final Long requestId, final Long reference, final String queryParameter) {
final BatchRequest br = new BatchRequest();
String relativeUrl = "loans/external-id/$.resourceExternalId";
if (queryParameter != null) {
relativeUrl = relativeUrl + "?" + queryParameter;
}
br.setRequestId(requestId);
br.setRelativeUrl(relativeUrl);
br.setMethod(HttpMethod.GET);
br.setReference(reference);
br.setBody("{}");
return br;
}
/**
* Creates and returns a {@link org.apache.fineract.batch.command.internal.GetLoanByIdCommandStrategy} request with
* given loan id and query param.
@@ -781,13 +1082,33 @@ public final class BatchHelper {
* @return the {@link BatchRequest}
*/
public static BatchRequest getLoanByIdRequest(final Long loanId, final String queryParameter) {
return getLoanByIdRequest(loanId, 4567L, null, queryParameter);
}
/**
* Creates and returns a {@link org.apache.fineract.batch.command.internal.GetLoanByIdCommandStrategy} request with
* given loan id and query param.
*
* @param loanId
* the loan id
* @param requestId
* the request id
* @param referenceId
* the reference id
* @param queryParameter
* the query parameters
* @return the {@link BatchRequest}
*/
public static BatchRequest getLoanByIdRequest(final Long loanId, final Long requestId, final Long referenceId,
final String queryParameter) {
final BatchRequest br = new BatchRequest();
String relativeUrl = String.format("loans/%s", loanId);
if (queryParameter != null) {
relativeUrl = relativeUrl + "?" + queryParameter;
}
br.setRequestId(4567L);
br.setRequestId(requestId);
br.setReference(referenceId);
br.setRelativeUrl(relativeUrl);
br.setMethod(HttpMethod.GET);
br.setBody("{}");
@@ -912,6 +1233,39 @@ public final class BatchHelper {
return br;
}
/**
* Creates and returns a batch request to create an adjust transaction request using external id.
*
* @param requestId
* the request ID
* @param reference
* the reference
* @param loanExternalId
* the loan external id
* @param transactionExternalId
* the transaction external id
* @param amount
* the amount
* @param date
* the date
* @return the {@link BatchRequest}
*/
public static BatchRequest createAdjustTransactionByExternalIdRequest(final Long requestId, final Long reference,
final String loanExternalId, final String transactionExternalId, final String amount, final LocalDate date) {
final BatchRequest br = new BatchRequest();
br.setRequestId(requestId);
br.setReference(reference);
br.setRelativeUrl(String.format("loans/external-id/%s/transactions/external-id/%s", loanExternalId, transactionExternalId));
br.setMethod("POST");
String dateString = date.format(DateTimeFormatter.ofPattern("dd MMMM yyyy"));
br.setBody(String.format(
"{\"locale\": \"en\", \"dateFormat\": \"dd MMMM yyyy\", " + "\"transactionDate\": \"%s\", \"transactionAmount\": %s}",
dateString, amount));
return br;
}
/**
* Creates and returns a batch request to create a chargeback transaction request.
*
@@ -937,6 +1291,50 @@ public final class BatchHelper {
}
/**
* Creates and returns a batch request to update a Loan account as fraud.
*
* @param requestId
* the request ID
* @param reference
* the reference
* @return the {@link BatchRequest}
*/
public static BatchRequest createLoanRequestMarkAsFraud(final Long requestId, final Long reference) {
final BatchRequest br = new BatchRequest();
br.setRequestId(requestId);
br.setRelativeUrl("loans/$.loanId?command=markAsFraud");
br.setMethod("PUT");
br.setReference(reference);
br.setBody("{\"fraud\": \"true\"}");
return br;
}
/**
* Creates and returns a batch request to update a Loan account as fraud by loan external id.
*
* @param requestId
* the request ID
* @param reference
* the reference
* @return the {@link BatchRequest}
*/
public static BatchRequest modifyLoanByExternalIdRequest(final Long requestId, final Long reference) {
final BatchRequest br = new BatchRequest();
br.setRequestId(requestId);
br.setRelativeUrl("loans/external-id/$.resourceExternalId?command=markAsFraud");
br.setMethod("PUT");
br.setReference(reference);
br.setBody("{\"fraud\": \"true\"}");
return br;
}
/**
* Creates and returns a batch request to query datatable entry.
*
@@ -629,4 +629,10 @@ public class GlobalConfigurationHelper {
assertEquals(updatedConfiguration.getEnabled(), enabled);
}
public static Integer updateIsAutomaticExternalIdGenerationEnabled(final RequestSpecification requestSpec,
final ResponseSpecification responseSpec, final boolean enabled) {
long configId = 50;
return updateEnabledFlagForGlobalConfiguration(requestSpec, responseSpec, configId, enabled);
}
}