FINERACT-1760-Link-Transaction-Reverse-Replay
This commit is contained in:
committed by
Arnold Gálovics
parent
b7f88d1196
commit
53b474b461
+3
-1
@@ -22,7 +22,8 @@ public enum LoanTransactionRelationTypeEnum {
|
||||
|
||||
INVALID(0, "loanTransactionType.invalid"), //
|
||||
CHARGEBACK(1, "loanTransactionRelationType.chargeback"), //
|
||||
CHARGE_ADJUSTMENT(2, "loanTransactionRelationType.chargeAdjustment");
|
||||
CHARGE_ADJUSTMENT(2, "loanTransactionRelationType.chargeAdjustment"), //
|
||||
REPLAYED(3, "loanTransactionRelationType.replayed");
|
||||
|
||||
private final Integer value;
|
||||
private final String code;
|
||||
@@ -49,6 +50,7 @@ public enum LoanTransactionRelationTypeEnum {
|
||||
return switch (transactionType) {
|
||||
case 1 -> LoanTransactionRelationTypeEnum.CHARGEBACK;
|
||||
case 2 -> LoanTransactionRelationTypeEnum.CHARGE_ADJUSTMENT;
|
||||
case 3 -> LoanTransactionRelationTypeEnum.REPLAYED;
|
||||
default -> LoanTransactionRelationTypeEnum.INVALID;
|
||||
};
|
||||
}
|
||||
|
||||
+5
@@ -38,6 +38,8 @@ import org.apache.fineract.portfolio.loanaccount.domain.LoanInterestRecalcualtio
|
||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepaymentScheduleInstallment;
|
||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepaymentScheduleProcessingWrapper;
|
||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanTransaction;
|
||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanTransactionRelation;
|
||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanTransactionRelationTypeEnum;
|
||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanTransactionToRepaymentScheduleMapping;
|
||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanTransactionType;
|
||||
import org.apache.fineract.portfolio.loanaccount.domain.transactionprocessor.impl.CreocoreLoanRepaymentScheduleTransactionProcessor;
|
||||
@@ -186,6 +188,9 @@ public abstract class AbstractLoanRepaymentScheduleTransactionProcessor implemen
|
||||
loanTransaction.reverse(loanTransaction.getExternalId());
|
||||
loanTransaction.updateExternalId(null);
|
||||
newLoanTransaction.copyLoanTransactionRelations(loanTransaction.getLoanTransactionRelations());
|
||||
// Adding Replayed relation from newly created transaction to reversed transaction
|
||||
newLoanTransaction.getLoanTransactionRelations().add(LoanTransactionRelation.linkToTransaction(newLoanTransaction,
|
||||
loanTransaction, LoanTransactionRelationTypeEnum.REPLAYED));
|
||||
changedTransactionDetail.getNewTransactionMappings().put(loanTransaction.getId(), newLoanTransaction);
|
||||
}
|
||||
}
|
||||
|
||||
+9
-4
@@ -47,6 +47,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import org.apache.fineract.accounting.glaccount.domain.GLAccountType;
|
||||
import org.apache.fineract.client.models.BusinessDateRequest;
|
||||
@@ -6221,10 +6222,14 @@ public class ClientLoanIntegrationTest {
|
||||
assertEquals(5.0, chargeAdjustmentTransaction.getPrincipalPortion());
|
||||
assertEquals("loanTransactionType.chargeAdjustment", chargeAdjustmentTransaction.getType().getCode());
|
||||
assertEquals(externalId, chargeAdjustmentTransaction.getExternalId());
|
||||
transactionRelation = chargeAdjustmentTransaction.getTransactionRelations().iterator().next();
|
||||
assertEquals(chargeAdjustmentTxnId, transactionRelation.getFromLoanTransaction());
|
||||
assertEquals((long) penalty1LoanChargeId, transactionRelation.getToLoanCharge());
|
||||
assertEquals("CHARGE_ADJUSTMENT", transactionRelation.getRelationType());
|
||||
|
||||
Set<GetLoanTransactionRelation> transactionRelations = chargeAdjustmentTransaction.getTransactionRelations();
|
||||
for (GetLoanTransactionRelation loanTransactionRelation : transactionRelations) {
|
||||
if (loanTransactionRelation.getRelationType().equals("CHARGE_ADJUSTMENT")) {
|
||||
assertEquals(chargeAdjustmentTxnId, loanTransactionRelation.getFromLoanTransaction());
|
||||
assertEquals((long) penalty1LoanChargeId, loanTransactionRelation.getToLoanCharge());
|
||||
}
|
||||
}
|
||||
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
this.loanTransactionHelper.reverseLoanTransaction((long) loanID, chargeAdjustmentTxnId,
|
||||
|
||||
+153
@@ -0,0 +1,153 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeFormatterBuilder;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
import org.apache.fineract.client.models.GetDelinquencyBucketsResponse;
|
||||
import org.apache.fineract.client.models.GetLoanProductsProductIdResponse;
|
||||
import org.apache.fineract.client.models.GetLoanTransactionRelation;
|
||||
import org.apache.fineract.client.models.GetLoansLoanIdTransactionsTransactionIdResponse;
|
||||
import org.apache.fineract.client.models.PostLoansLoanIdTransactionsRequest;
|
||||
import org.apache.fineract.client.models.PostLoansLoanIdTransactionsResponse;
|
||||
import org.apache.fineract.integrationtests.common.ClientHelper;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.fineract.integrationtests.common.charges.ChargesHelper;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanApplicationTestBuilder;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
|
||||
import org.apache.fineract.integrationtests.common.products.DelinquencyBucketsHelper;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class LoanTransactionReverseReplayRelationTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private ResponseSpecification responseSpecErr400;
|
||||
private ResponseSpecification responseSpecErr503;
|
||||
private RequestSpecification requestSpec;
|
||||
private ClientHelper clientHelper;
|
||||
private LoanTransactionHelper loanTransactionHelper;
|
||||
private DateTimeFormatter dateFormatter = new DateTimeFormatterBuilder().appendPattern("dd MMMM yyyy").toFormatter();
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
Utils.initializeRESTAssured();
|
||||
this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
|
||||
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
|
||||
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
|
||||
this.responseSpecErr400 = new ResponseSpecBuilder().expectStatusCode(400).build();
|
||||
this.responseSpecErr503 = new ResponseSpecBuilder().expectStatusCode(503).build();
|
||||
this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
|
||||
this.clientHelper = new ClientHelper(this.requestSpec, this.responseSpec);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loanTransactionReverseReplayRelationTest() {
|
||||
// Loan ExternalId
|
||||
String loanExternalIdStr = UUID.randomUUID().toString();
|
||||
|
||||
// Delinquency Bucket
|
||||
final Integer delinquencyBucketId = DelinquencyBucketsHelper.createDelinquencyBucket(requestSpec, responseSpec);
|
||||
final GetDelinquencyBucketsResponse delinquencyBucket = DelinquencyBucketsHelper.getDelinquencyBucket(requestSpec, responseSpec,
|
||||
delinquencyBucketId);
|
||||
|
||||
// Client and Loan account creation
|
||||
|
||||
final Integer clientId = clientHelper.createClient(ClientHelper.defaultClientCreationRequest()).getClientId().intValue();
|
||||
final GetLoanProductsProductIdResponse getLoanProductsProductResponse = createLoanProduct(loanTransactionHelper,
|
||||
delinquencyBucketId);
|
||||
assertNotNull(getLoanProductsProductResponse);
|
||||
|
||||
final Integer loanId = createLoanAccount(clientId, getLoanProductsProductResponse.getId(), loanExternalIdStr);
|
||||
|
||||
// Add Charge
|
||||
Integer penalty = ChargesHelper.createCharges(requestSpec, responseSpec,
|
||||
ChargesHelper.getLoanSpecifiedDueDateJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_FLAT, "10", true));
|
||||
|
||||
LocalDate targetDate = LocalDate.of(2022, 9, 7);
|
||||
final String penaltyCharge1AddedDate = dateFormatter.format(targetDate);
|
||||
|
||||
Integer penalty1LoanChargeId = this.loanTransactionHelper.addChargesForLoan(loanId,
|
||||
LoanTransactionHelper.getSpecifiedDueDateChargesForLoanAsJSON(String.valueOf(penalty), penaltyCharge1AddedDate, "10"));
|
||||
|
||||
// make repayment
|
||||
|
||||
// Set Loan transaction externalId for transaction getting reversed and replayed
|
||||
String loanTransactionExternalIdStr = UUID.randomUUID().toString();
|
||||
|
||||
final PostLoansLoanIdTransactionsResponse repaymentTransaction = loanTransactionHelper.makeLoanRepayment(loanExternalIdStr,
|
||||
new PostLoansLoanIdTransactionsRequest().dateFormat("dd MMMM yyyy").transactionDate("15 September 2022").locale("en")
|
||||
.transactionAmount(11.0).externalId(loanTransactionExternalIdStr));
|
||||
|
||||
// make backdated repayment for reverse replay
|
||||
final PostLoansLoanIdTransactionsResponse backDatedRepaymentTransaction = loanTransactionHelper.makeLoanRepayment(loanExternalIdStr,
|
||||
new PostLoansLoanIdTransactionsRequest().dateFormat("dd MMMM yyyy").transactionDate("10 September 2022").locale("en")
|
||||
.transactionAmount(5.0));
|
||||
|
||||
// get transaction relationship for new transaction using externalId of reversed loan transaction
|
||||
|
||||
Long reversedAndReplayedTransactionId = repaymentTransaction.getResourceId();
|
||||
Long backDatedRepaymentTransactionId = backDatedRepaymentTransaction.getResourceId();
|
||||
|
||||
GetLoansLoanIdTransactionsTransactionIdResponse getLoansTransactionResponse = loanTransactionHelper
|
||||
.getLoanTransactionDetails((long) loanId, loanTransactionExternalIdStr);
|
||||
assertNotNull(getLoansTransactionResponse);
|
||||
assertNotNull(getLoansTransactionResponse.getTransactionRelations());
|
||||
|
||||
// test replayed relationship
|
||||
GetLoanTransactionRelation transactionRelation = getLoansTransactionResponse.getTransactionRelations().iterator().next();
|
||||
assertEquals(reversedAndReplayedTransactionId, transactionRelation.getToLoanTransaction());
|
||||
assertEquals("REPLAYED", transactionRelation.getRelationType());
|
||||
}
|
||||
|
||||
private GetLoanProductsProductIdResponse createLoanProduct(final LoanTransactionHelper loanTransactionHelper,
|
||||
final Integer delinquencyBucketId) {
|
||||
final HashMap<String, Object> loanProductMap = new LoanProductTestBuilder().build(null, delinquencyBucketId);
|
||||
final Integer loanProductId = loanTransactionHelper.getLoanProductId(Utils.convertToJson(loanProductMap));
|
||||
return loanTransactionHelper.getLoanProduct(loanProductId);
|
||||
}
|
||||
|
||||
private Integer createLoanAccount(final Integer clientID, final Long loanProductID, final String externalId) {
|
||||
|
||||
String loanApplicationJSON = new LoanApplicationTestBuilder().withPrincipal("1000").withLoanTermFrequency("1")
|
||||
.withLoanTermFrequencyAsMonths().withNumberOfRepayments("1").withRepaymentEveryAfter("1")
|
||||
.withRepaymentFrequencyTypeAsMonths().withInterestRatePerPeriod("0").withInterestTypeAsFlatBalance()
|
||||
.withAmortizationTypeAsEqualPrincipalPayments().withInterestCalculationPeriodTypeSameAsRepaymentPeriod()
|
||||
.withExpectedDisbursementDate("03 September 2022").withSubmittedOnDate("01 September 2022").withLoanType("individual")
|
||||
.withExternalId(externalId).build(clientID.toString(), loanProductID.toString(), null);
|
||||
|
||||
final Integer loanId = loanTransactionHelper.getLoanId(loanApplicationJSON);
|
||||
loanTransactionHelper.approveLoan("02 September 2022", "1000", loanId, null);
|
||||
loanTransactionHelper.disburseLoanWithNetDisbursalAmount("03 September 2022", loanId, "1000");
|
||||
return loanId;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user