Batch API extensions and a couple of OpenAPI fixes + minor datatable fixes

This commit is contained in:
Arnold Galovics
2022-07-13 21:50:42 +02:00
committed by Arnold Gálovics
parent 4f832f9481
commit 8c023e74a8
30 changed files with 1084 additions and 529 deletions
@@ -18,6 +18,8 @@
*/
package org.apache.fineract.integrationtests;
import static org.junit.jupiter.api.Assertions.assertEquals;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import io.restassured.builder.RequestSpecBuilder;
@@ -28,6 +30,7 @@ import io.restassured.specification.ResponseSpecification;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.fineract.batch.command.internal.CreateTransactionLoanCommandStrategy;
import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
@@ -38,6 +41,7 @@ import org.apache.fineract.integrationtests.common.Utils;
import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder;
import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
import org.apache.fineract.integrationtests.common.savings.SavingsProductHelper;
import org.apache.fineract.integrationtests.common.system.DatatableHelper;
import org.apache.fineract.portfolio.loanaccount.domain.LoanStatus;
import org.apache.http.HttpStatus;
import org.junit.jupiter.api.Assertions;
@@ -55,9 +59,26 @@ import org.junit.jupiter.api.Test;
*/
public class BatchApiTest {
/**
* The response specification
*/
private ResponseSpecification responseSpec;
/**
* The request specification
*/
private RequestSpecification requestSpec;
/**
* The datatable helper
*/
private DatatableHelper datatableHelper;
/**
* Loan app datatable
*/
private static final String LOAN_APP_TABLE_NAME = "m_loan";
/**
* Sets up the essential settings for the TEST like contentType, expectedStatusCode. It uses the '@BeforeEach'
* annotation provided by jUnit.
@@ -68,6 +89,7 @@ public class BatchApiTest {
this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
this.datatableHelper = new DatatableHelper(this.requestSpec, this.responseSpec);
}
/**
@@ -240,7 +262,8 @@ public class BatchApiTest {
// Get the clientId parameter from createClient Response
final JsonElement clientId = new FromJsonHelper().parse(response.get(0).getBody()).getAsJsonObject().get("clientId");
Assertions.assertEquals(200L, (long) response.get(1).getStatusCode(), "Verify Status Code 200" + clientId.getAsString());
Assertions.assertEquals(HttpStatus.SC_OK, (long) response.get(1).getStatusCode(),
"Verify Status Code 200" + clientId.getAsString());
}
/**
@@ -281,7 +304,7 @@ public class BatchApiTest {
final List<BatchResponse> response = BatchHelper.postBatchRequestsWithoutEnclosingTransaction(this.requestSpec, this.responseSpec,
jsonifiedRequest);
Assertions.assertEquals(200L, (long) response.get(1).getStatusCode(), "Verify Status Code 200");
Assertions.assertEquals(HttpStatus.SC_OK, (long) response.get(1).getStatusCode(), "Verify Status Code 200");
}
/**
@@ -341,7 +364,7 @@ public class BatchApiTest {
final List<BatchResponse> response = BatchHelper.postBatchRequestsWithoutEnclosingTransaction(this.requestSpec, this.responseSpec,
jsonifiedRequest);
Assertions.assertEquals(200L, (long) response.get(3).getStatusCode(), "Verify Status Code 200 for Create Loan Charge");
Assertions.assertEquals(HttpStatus.SC_OK, (long) response.get(3).getStatusCode(), "Verify Status Code 200 for Create Loan Charge");
}
/**
@@ -349,7 +372,7 @@ public class BatchApiTest {
* successful responses. It first creates a new loan and then makes two repayments for it and then verifies that
* 200(OK) is returned for the repayment requests.
*
* @see org.apache.fineract.batch.command.internal.RepayLoanCommandStrategy
* @see CreateTransactionLoanCommandStrategy
*/
@Test
public void shouldReturnOkStatusForBatchRepayment() {
@@ -392,10 +415,10 @@ public class BatchApiTest {
final BatchRequest br5 = BatchHelper.disburseLoanRequest(4734L, 4733L);
// Create a loanRepay Request
final BatchRequest br6 = BatchHelper.repayLoanRequest(4735L, 4734L);
final BatchRequest br6 = BatchHelper.repayLoanRequest(4735L, 4734L, "500");
// Create a loanRepay Request
final BatchRequest br7 = BatchHelper.repayLoanRequest(4736L, 4734L);
final BatchRequest br7 = BatchHelper.repayLoanRequest(4736L, 4734L, "500");
final List<BatchRequest> batchRequests = new ArrayList<>();
@@ -412,8 +435,85 @@ public class BatchApiTest {
final List<BatchResponse> response = BatchHelper.postBatchRequestsWithoutEnclosingTransaction(this.requestSpec, this.responseSpec,
jsonifiedRequest);
Assertions.assertEquals(200L, (long) response.get(5).getStatusCode(), "Verify Status Code 200 for Repayment");
Assertions.assertEquals(200L, (long) response.get(6).getStatusCode(), "Verify Status Code 200 for Repayment");
Assertions.assertEquals(HttpStatus.SC_OK, (long) response.get(5).getStatusCode(), "Verify Status Code 200 for Repayment");
Assertions.assertEquals(HttpStatus.SC_OK, (long) response.get(6).getStatusCode(), "Verify Status Code 200 for Repayment");
}
/**
* Tests that batch credit balance refund for loans is happening properly. Collected properly 200(OK) status was
* returned for successful responses. It first creates a new loan and then makes an overpayment, before creating a
* credit balance refund to refund a portion of the over-payment.
*
* @see CreateTransactionLoanCommandStrategy
*/
@Test
public void shouldReturnOkStatusForBatchCreditBalanceRefund() {
final String loanProductJSON = new LoanProductTestBuilder() //
.withPrincipal("1000.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);
final Long createActiveClientRequestId = 4730L;
final Long applyLoanRequestId = createActiveClientRequestId + 1;
final Long approveLoanRequestId = applyLoanRequestId + 1;
final Long disburseLoanRequestId = approveLoanRequestId + 1;
final Long repayLoanRequestId = disburseLoanRequestId + 1;
final Long creditBalanceRefundRequestId = repayLoanRequestId + 1;
// Create a createClient Request
final BatchRequest br1 = BatchHelper.createActiveClientRequest(createActiveClientRequestId, "");
// Create a ApplyLoan Request
final BatchRequest br2 = BatchHelper.applyLoanRequest(applyLoanRequestId, createActiveClientRequestId, productId,
clientCollateralId);
// Create a approveLoan Request
final BatchRequest br3 = BatchHelper.approveLoanRequest(approveLoanRequestId, applyLoanRequestId);
// Create a disburseLoan Request
final BatchRequest br4 = BatchHelper.disburseLoanRequest(disburseLoanRequestId, approveLoanRequestId);
// Create a loanRepay Request which will result in an overpay.
final BatchRequest br5 = BatchHelper.repayLoanRequest(repayLoanRequestId, disburseLoanRequestId, "20000");
// Create a credit balance refund request
final BatchRequest br6 = BatchHelper.creditBalanceRefundRequest(creditBalanceRefundRequestId, repayLoanRequestId, "500");
final List<BatchRequest> batchRequests = new ArrayList<>();
batchRequests.add(br1);
batchRequests.add(br2);
batchRequests.add(br3);
batchRequests.add(br4);
batchRequests.add(br5);
batchRequests.add(br6);
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(4).getStatusCode(), "Verify Status Code 200 for Repayment");
Assertions.assertEquals(HttpStatus.SC_OK, (long) response.get(5).getStatusCode(),
"Verify Status Code 200 for Credit Balance Refund");
}
/**
@@ -441,8 +541,8 @@ public class BatchApiTest {
final List<BatchResponse> response = BatchHelper.postBatchRequestsWithoutEnclosingTransaction(this.requestSpec, this.responseSpec,
jsonifiedRequest);
Assertions.assertEquals(200L, (long) response.get(0).getStatusCode(), "Verify Status Code 200 for Create Client");
Assertions.assertEquals(200L, (long) response.get(1).getStatusCode(), "Verify Status Code 200 for Activate Client");
Assertions.assertEquals(HttpStatus.SC_OK, (long) response.get(0).getStatusCode(), "Verify Status Code 200 for Create Client");
Assertions.assertEquals(HttpStatus.SC_OK, (long) response.get(1).getStatusCode(), "Verify Status Code 200 for Activate Client");
}
/**
@@ -504,8 +604,8 @@ public class BatchApiTest {
final List<BatchResponse> response = BatchHelper.postBatchRequestsWithoutEnclosingTransaction(this.requestSpec, this.responseSpec,
jsonifiedRequest);
Assertions.assertEquals(200L, (long) response.get(3).getStatusCode(), "Verify Status Code 200 for Approve Loan");
Assertions.assertEquals(200L, (long) response.get(4).getStatusCode(), "Verify Status Code 200 for Disburse Loan");
Assertions.assertEquals(HttpStatus.SC_OK, (long) response.get(3).getStatusCode(), "Verify Status Code 200 for Approve Loan");
Assertions.assertEquals(HttpStatus.SC_OK, (long) response.get(4).getStatusCode(), "Verify Status Code 200 for Disburse Loan");
}
/**
@@ -558,10 +658,10 @@ public class BatchApiTest {
final List<BatchResponse> response = BatchHelper.postBatchRequestsWithEnclosingTransaction(this.requestSpec, this.responseSpec,
jsonifiedRequest);
Assertions.assertEquals(200L, (long) response.get(0).getStatusCode(), "Verify Status Code 200 for create client");
Assertions.assertEquals(200L, (long) response.get(1).getStatusCode(), "Verify Status Code 200 for apply Loan");
Assertions.assertEquals(200L, (long) response.get(2).getStatusCode(), "Verify Status Code 200 for approve Loan");
Assertions.assertEquals(200L, (long) response.get(3).getStatusCode(), "Verify Status Code 200 for disburse Loan");
Assertions.assertEquals(HttpStatus.SC_OK, (long) response.get(0).getStatusCode(), "Verify Status Code 200 for create client");
Assertions.assertEquals(HttpStatus.SC_OK, (long) response.get(1).getStatusCode(), "Verify Status Code 200 for apply Loan");
Assertions.assertEquals(HttpStatus.SC_OK, (long) response.get(2).getStatusCode(), "Verify Status Code 200 for approve Loan");
Assertions.assertEquals(HttpStatus.SC_OK, (long) response.get(3).getStatusCode(), "Verify Status Code 200 for disburse Loan");
}
/**
@@ -754,4 +854,164 @@ public class BatchApiTest {
// Repayment schedule information will be available in the response based on the query parameter
Assertions.assertTrue(responses.get(3).getBody().contains("repaymentSchedule"));
}
/**
* Test for the successful get loan and get datatable entry. A '200' status code is expected on successful
* responses.
*
* @see org.apache.fineract.batch.command.internal.ApplyLoanCommandStrategy
* @see org.apache.fineract.batch.command.internal.ApproveLoanCommandStrategy
* @see org.apache.fineract.batch.command.internal.GetLoanByIdCommandStrategy
*/
@Test
public void shouldReturnOkStatusOnSuccessfulGetDataTableEntry() {
final FromJsonHelper jsonHelper = new FromJsonHelper();
final Long loanId = jsonHelper.extractLongNamed("loanId", jsonHelper.parse(setupAccount()).getAsJsonObject());
final String datatableName = this.datatableHelper.createDatatable(LOAN_APP_TABLE_NAME, false);
try {
// Get loan by id Request with query param
final BatchRequest getLoanBatchRequest = BatchHelper.getLoanByIdRequest(loanId, "associations=repaymentSchedule,transactions");
// Get datatable batch request
final BatchRequest getDatatableBatchRequest = BatchHelper.getDatatableByIdRequest(loanId, datatableName,
"genericResultSet=true");
final List<BatchRequest> batchRequestsGetLoan = Arrays.asList(getLoanBatchRequest, getDatatableBatchRequest);
final List<BatchResponse> responsesGetLoan = BatchHelper.postBatchRequestsWithEnclosingTransaction(this.requestSpec,
this.responseSpec, BatchHelper.toJsonString(batchRequestsGetLoan));
final String getLoanResponse = responsesGetLoan.get(0).getBody();
final String getDatatableResponse = responsesGetLoan.get(1).getBody();
Assertions.assertEquals(HttpStatus.SC_OK, responsesGetLoan.get(0).getStatusCode(), "Verify Status Code 200 for get loan");
Assertions.assertEquals(HttpStatus.SC_OK, responsesGetLoan.get(1).getStatusCode(), "Verify Status Code 200 for datatable");
final Long loanIdInGetResponse = jsonHelper.extractLongNamed("id", jsonHelper.parse(getLoanResponse).getAsJsonObject());
Assertions.assertEquals(loanId, loanIdInGetResponse);
// Repayment schedule information will be available in the response based on the query parameter
Assertions.assertTrue(getLoanResponse.contains("repaymentSchedule"));
// Transaction will be available in the response based on the query parameter
Assertions.assertTrue(getLoanResponse.contains("transactions"));
// datatable info will be available in the response based on the query parameter
Assertions.assertTrue(getDatatableResponse.contains("columnHeaders"));
// datatable info will be available in the response based on the query parameter
Assertions.assertTrue(getDatatableResponse.contains("data"));
} finally {
deleteDatatable(datatableName);
}
}
/**
* Test for the successful get loan and get datatable entry where get datatable request have no query param. A '200'
* status code is expected on successful responses.
*
* @see org.apache.fineract.batch.command.internal.ApplyLoanCommandStrategy
* @see org.apache.fineract.batch.command.internal.ApproveLoanCommandStrategy
* @see org.apache.fineract.batch.command.internal.GetLoanByIdCommandStrategy
*/
@Test
public void shouldReturnOkStatusOnSuccessfulGetDatatableEntryWithNoQueryParam() {
final FromJsonHelper jsonHelper = new FromJsonHelper();
final Long loanId = jsonHelper.extractLongNamed("loanId", jsonHelper.parse(setupAccount()).getAsJsonObject());
final String datatableName = this.datatableHelper.createDatatable(LOAN_APP_TABLE_NAME, false);
try {
// Get loan by id Request with query param
final BatchRequest getLoanBatchRequest = BatchHelper.getLoanByIdRequest(loanId, "associations=repaymentSchedule,transactions");
// Get datatable batch request
final BatchRequest getDatatableBatchRequest = BatchHelper.getDatatableByIdRequest(loanId, datatableName, null);
final List<BatchRequest> batchRequestsGetLoan = Arrays.asList(getLoanBatchRequest, getDatatableBatchRequest);
final List<BatchResponse> responsesGetLoan = BatchHelper.postBatchRequestsWithEnclosingTransaction(this.requestSpec,
this.responseSpec, BatchHelper.toJsonString(batchRequestsGetLoan));
final String getLoanResponse = responsesGetLoan.get(0).getBody();
Assertions.assertEquals(HttpStatus.SC_OK, responsesGetLoan.get(0).getStatusCode(), "Verify Status Code 200 for Get Loan");
Assertions.assertEquals(HttpStatus.SC_OK, responsesGetLoan.get(1).getStatusCode(), "Verify Status Code 200 for Get Datatable");
final Long loanIdInGetResponse = jsonHelper.extractLongNamed("id", jsonHelper.parse(getLoanResponse).getAsJsonObject());
Assertions.assertEquals(loanId, loanIdInGetResponse);
Assertions.assertTrue(getLoanResponse.contains("repaymentSchedule"));
Assertions.assertTrue(getLoanResponse.contains("transactions"));
} finally {
deleteDatatable(datatableName);
}
}
/**
* Delete datatable
*
* @param datatableName
* the datatable name
*/
private void deleteDatatable(final String datatableName) {
String deletedDatatableName = this.datatableHelper.deleteDatatable(datatableName);
assertEquals(datatableName, deletedDatatableName, "Fail to delete the datatable");
}
/**
* Setup account to test get loan and get datatable batch call
*
* @return the response body
*/
private String setupAccount() {
final String loanProductJSON = new LoanProductTestBuilder() //
.withPrincipal("10000000.00") //
.withNumberOfRepayments("24") //
.withRepaymentAfterEvery("1") //
.withRepaymentTypeAsMonth() //
.withinterestRatePerPeriod("2") //
.withInterestRateFrequencyTypeAsMonths() //
.withAmortizationTypeAsEqualPrincipalPayment() //
.withInterestTypeAsDecliningBalance() //
.currencyDetails("0", "100").build(null);
final Long applyLoanRequestId = 5730L;
final Long approveLoanRequestId = 5731L;
final Long disburseLoanRequestId = 5734L;
final Long repayLoanRequestId = 5735L;
// 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 an ApplyLoan Request
final BatchRequest applyLoanBatchRequest = BatchHelper.applyLoanRequestWithClientId(applyLoanRequestId, clientId, productId);
// Create an approveLoan Request
final BatchRequest approveLoanBatchRequest = BatchHelper.approveLoanRequest(approveLoanRequestId, applyLoanRequestId);
// Create a disburseLoan Request
final BatchRequest disburseLoanBatchRequest = BatchHelper.disburseLoanRequest(disburseLoanRequestId, applyLoanRequestId);
// Create a repayment Request
final BatchRequest repaymentBatchRequest = BatchHelper.repayLoanRequest(repayLoanRequestId, applyLoanRequestId, "500");
final List<BatchRequest> batchRequests = Arrays.asList(applyLoanBatchRequest, approveLoanBatchRequest, disburseLoanBatchRequest,
repaymentBatchRequest);
final List<BatchResponse> responses = BatchHelper.postBatchRequestsWithEnclosingTransaction(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 Repay Loan");
return responses.get(0).getBody();
}
}
@@ -23,10 +23,14 @@ import com.google.gson.reflect.TypeToken;
import io.restassured.specification.RequestSpecification;
import io.restassured.specification.ResponseSpecification;
import java.security.SecureRandom;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.ws.rs.HttpMethod;
import org.apache.fineract.batch.command.internal.CreateTransactionLoanCommandStrategy;
import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse;
import org.junit.jupiter.api.Assertions;
@@ -223,12 +227,37 @@ public final class BatchHelper {
* given requestId and reference.
*
* @param requestId
* the request ID
* @param reference
* the reference ID
* @param productId
* @return BatchRequest
* the product ID
* @return BatchRequest the batch request
*/
public static BatchRequest applyLoanRequest(final Long requestId, final Long reference, final Integer productId,
final Integer clientCollateralId) {
return applyLoanRequest(requestId, reference, productId, clientCollateralId, LocalDate.now(ZoneId.systemDefault()).minusDays(10),
"10,000.00");
}
/**
* Creates and returns a {@link org.apache.fineract.batch.command.internal.ApplyLoanCommandStrategy} Request with
* given requestId and reference.
*
* @param requestId
* the request ID
* @param reference
* the reference ID
* @param productId
* the product ID
* @param date
* the loan submitted on date
* @param loanAmount
* the loan amount
* @return BatchRequest the batch request
*/
public static BatchRequest applyLoanRequest(final Long requestId, final Long reference, final Integer productId,
final Integer clientCollateralId, final LocalDate date, final String loanAmount) {
final BatchRequest br = new BatchRequest();
@@ -236,19 +265,20 @@ public final class BatchHelper {
br.setRelativeUrl("loans");
br.setMethod("POST");
br.setReference(reference);
String dateString = date.format(DateTimeFormatter.ofPattern("dd MMMM yyyy"));
String body = "{\"dateFormat\": \"dd MMMM yyyy\", \"locale\": \"en_GB\", \"clientId\": \"$.clientId\"," + "\"productId\": "
+ productId + ", \"principal\": \"10,000.00\", \"loanTermFrequency\": 10,"
+ productId + ", \"principal\": \"" + loanAmount + "\", \"loanTermFrequency\": 10,"
+ "\"loanTermFrequencyType\": 2, \"loanType\": \"individual\", \"numberOfRepayments\": 10,"
+ "\"repaymentEvery\": 1, \"repaymentFrequencyType\": 2, \"interestRatePerPeriod\": 10,"
+ "\"amortizationType\": 1, \"interestType\": 0, \"interestCalculationPeriodType\": 1,"
+ "\"transactionProcessingStrategyId\": 1, \"expectedDisbursementDate\": \"10 Jun 2013\",";
+ "\"transactionProcessingStrategyId\": 1, \"expectedDisbursementDate\": \"" + dateString + "\",";
if (clientCollateralId != null) {
body = body + "\"collateral\": [{\"clientCollateralId\": \"" + clientCollateralId.toString() + "\", \"quantity\": \"1\"}],";
body = body + "\"collateral\": [{\"clientCollateralId\": \"" + clientCollateralId + "\", \"quantity\": \"1\"}],";
}
body = body + "\"submittedOnDate\": \"10 Jun 2013\"}";
body = body + "\"submittedOnDate\": \"" + dateString + "\"}";
br.setBody(body);
@@ -385,17 +415,37 @@ public final class BatchHelper {
*
*
* @param requestId
* the request ID
* @param reference
* @return BatchRequest
* the reference ID
* @return BatchRequest the batch request
*/
public static BatchRequest approveLoanRequest(final Long requestId, final Long reference) {
return approveLoanRequest(requestId, reference, LocalDate.now(ZoneId.systemDefault()).minusDays(10));
}
/**
* Creates and returns a {@link org.apache.fineract.batch.command.internal.ApproveLoanCommandStrategy} Request with
* given requestId and reference.
*
*
* @param requestId
* the request ID
* @param reference
* the reference ID
* @param date
* the approved on date
* @return BatchRequest the batch request
*/
public static BatchRequest approveLoanRequest(final Long requestId, final Long reference, LocalDate date) {
final BatchRequest br = new BatchRequest();
br.setRequestId(requestId);
br.setRelativeUrl("loans/$.loanId?command=approve");
br.setReference(reference);
br.setMethod("POST");
br.setBody("{\"locale\": \"en\", \"dateFormat\": \"dd MMMM yyyy\", \"approvedOnDate\": \"12 September 2013\","
String dateString = date.format(DateTimeFormatter.ofPattern("dd MMMM yyyy"));
br.setBody("{\"locale\": \"en\", \"dateFormat\": \"dd MMMM yyyy\", \"approvedOnDate\": \"" + dateString + "\","
+ "\"note\": \"Loan approval note\"}");
return br;
@@ -407,39 +457,123 @@ public final class BatchHelper {
*
*
* @param requestId
* the request ID
* @param reference
* @return BatchRequest
* the reference ID
* @return BatchRequest the batch request
*/
public static BatchRequest disburseLoanRequest(final Long requestId, final Long reference) {
return disburseLoanRequest(requestId, reference, LocalDate.now(ZoneId.systemDefault()).minusDays(8));
}
/**
* Creates and returns a {@link org.apache.fineract.batch.command.internal.DisburseLoanCommandStrategy} Request with
* given requestId and reference.
*
*
* @param requestId
* the request ID
* @param reference
* the reference ID
* @param date
* the actual disbursement date
* @return BatchRequest the batch request
*/
public static BatchRequest disburseLoanRequest(final Long requestId, final Long reference, final LocalDate date) {
final BatchRequest br = new BatchRequest();
br.setRequestId(requestId);
br.setRelativeUrl("loans/$.loanId?command=disburse");
br.setReference(reference);
br.setMethod("POST");
br.setBody("{\"locale\": \"en\", \"dateFormat\": \"dd MMMM yyyy\", \"actualDisbursementDate\": \"15 September 2013\"}");
String dateString = date.format(DateTimeFormatter.ofPattern("dd MMMM yyyy"));
br.setBody("{\"locale\": \"en\", \"dateFormat\": \"dd MMMM yyyy\", \"actualDisbursementDate\": \"" + dateString + "\"}");
return br;
}
/**
* Creates and returns a {@link org.apache.fineract.batch.command.internal.RepayLoanCommandStrategy} Request with
* given requestId.
*
* Creates and returns a {@link CreateTransactionLoanCommandStrategy} Request with given requestId.
*
* @param requestId
* the request ID
* @param reference
* @return BatchRequest
* the reference ID
* @param amount
* the amount
* @param date
* the transaction date
* @return BatchRequest the batch request
*/
public static BatchRequest repayLoanRequest(final Long requestId, final Long reference) {
public static BatchRequest repayLoanRequest(final Long requestId, final Long reference, final String amount) {
return repayLoanRequest(requestId, reference, amount, LocalDate.now(ZoneId.systemDefault()));
}
/**
* Creates and returns a {@link CreateTransactionLoanCommandStrategy} Request with given requestId.
*
* @param requestId
* the request ID
* @param reference
* the reference ID
* @param amount
* the amount
* @param date
* the transaction date
* @return BatchRequest the batch request
*/
public static BatchRequest repayLoanRequest(final Long requestId, final Long reference, final String amount, final LocalDate date) {
final BatchRequest br = new BatchRequest();
br.setRequestId(requestId);
br.setReference(reference);
br.setRelativeUrl("loans/$.loanId/transactions?command=repayment");
br.setMethod("POST");
br.setBody("{\"locale\": \"en\", \"dateFormat\": \"dd MMMM yyyy\", "
+ "\"transactionDate\": \"15 September 2013\", \"transactionAmount\": 500}");
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.
*
*
* @param requestId
* the request ID
* @param reference
* teh reference
* @return BatchRequest the created {@link BatchRequest}
*/
public static BatchRequest creditBalanceRefundRequest(final Long requestId, final Long reference, final String amount) {
return creditBalanceRefundRequest(requestId, reference, amount, LocalDate.now(ZoneId.systemDefault()));
}
/**
* Creates and returns a {@link CreateTransactionLoanCommandStrategy} request with given request ID.
*
*
* @param requestId
* the request ID
* @param reference
* teh reference
* @param date
* the transaction date
* @return BatchRequest the created {@link BatchRequest}
*/
public static BatchRequest creditBalanceRefundRequest(final Long requestId, final Long reference, final String amount, LocalDate date) {
final BatchRequest br = new BatchRequest();
br.setRequestId(requestId);
br.setReference(reference);
br.setRelativeUrl("loans/$.loanId/transactions?command=creditBalanceRefund");
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;
}
@@ -511,4 +645,55 @@ public final class BatchHelper {
return br;
}
/**
* 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 queryParameter
* the query parameters
* @return the {@link BatchRequest}
*/
public static BatchRequest getLoanByIdRequest(final Long loanId, 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.setRelativeUrl(relativeUrl);
br.setMethod(HttpMethod.GET);
br.setBody("{}");
return br;
}
/**
* Creates and returns a batch request to get datatable entry.
*
* @param loanId
* the loan id
* @param datatableName
* the name of datatable
* @param queryParameter
* the query parameters
* @return the {@link BatchRequest}
*/
public static BatchRequest getDatatableByIdRequest(final Long loanId, final String datatableName, final String queryParameter) {
final BatchRequest br = new BatchRequest();
String relativeUrl = String.format("datatables/%s/%s", datatableName, loanId);
if (queryParameter != null) {
relativeUrl = relativeUrl + "?" + queryParameter;
}
br.setRequestId(4568L);
br.setRelativeUrl(relativeUrl);
br.setMethod(HttpMethod.GET);
br.setBody("{}");
return br;
}
}