Refactor Loan Transaction to support auditable fields
This commit is contained in:
committed by
Arnold Gálovics
parent
176c5700d0
commit
35cc1fc0d6
+6
@@ -20,6 +20,7 @@ package org.apache.fineract.infrastructure.core.service;
|
|||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
@@ -73,6 +74,11 @@ public final class DateUtils {
|
|||||||
return LocalDateTime.now(zone).truncatedTo(ChronoUnit.SECONDS);
|
return LocalDateTime.now(zone).truncatedTo(ChronoUnit.SECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static OffsetDateTime getOffsetDateTimeOfTenant() {
|
||||||
|
final ZoneId zone = getDateTimeZoneOfTenant();
|
||||||
|
return OffsetDateTime.now(zone).truncatedTo(ChronoUnit.SECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
public static LocalDateTime getLocalDateTimeOfSystem() {
|
public static LocalDateTime getLocalDateTimeOfSystem() {
|
||||||
return LocalDateTime.now(ZoneId.systemDefault()).truncatedTo(ChronoUnit.SECONDS);
|
return LocalDateTime.now(ZoneId.systemDefault()).truncatedTo(ChronoUnit.SECONDS);
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -19,7 +19,7 @@
|
|||||||
package org.apache.fineract.portfolio.collateralmanagement.data;
|
package org.apache.fineract.portfolio.collateralmanagement.data;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.time.LocalDateTime;
|
import java.time.OffsetDateTime;
|
||||||
|
|
||||||
public final class LoanTransactionData {
|
public final class LoanTransactionData {
|
||||||
|
|
||||||
@@ -29,9 +29,9 @@ public final class LoanTransactionData {
|
|||||||
|
|
||||||
private final Long loanId;
|
private final Long loanId;
|
||||||
|
|
||||||
private final LocalDateTime lastRepaymentDate;
|
private final OffsetDateTime lastRepaymentDate;
|
||||||
|
|
||||||
private LoanTransactionData(final Long loanId, final LocalDateTime lastRepaymentDate, final BigDecimal remainingAmount,
|
private LoanTransactionData(final Long loanId, final OffsetDateTime lastRepaymentDate, final BigDecimal remainingAmount,
|
||||||
final BigDecimal lastRepayment) {
|
final BigDecimal lastRepayment) {
|
||||||
this.lastRepayment = lastRepayment;
|
this.lastRepayment = lastRepayment;
|
||||||
this.lastRepaymentDate = lastRepaymentDate;
|
this.lastRepaymentDate = lastRepaymentDate;
|
||||||
@@ -39,7 +39,7 @@ public final class LoanTransactionData {
|
|||||||
this.loanId = loanId;
|
this.loanId = loanId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LoanTransactionData instance(final Long loanId, final LocalDateTime lastRepaymentDate, final BigDecimal remainingAmount,
|
public static LoanTransactionData instance(final Long loanId, final OffsetDateTime lastRepaymentDate, final BigDecimal remainingAmount,
|
||||||
final BigDecimal lastRepayment) {
|
final BigDecimal lastRepayment) {
|
||||||
return new LoanTransactionData(loanId, lastRepaymentDate, remainingAmount, lastRepayment);
|
return new LoanTransactionData(loanId, lastRepaymentDate, remainingAmount, lastRepayment);
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-5
@@ -20,7 +20,7 @@ package org.apache.fineract.portfolio.loanaccount.domain;
|
|||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.OffsetDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@@ -37,7 +37,7 @@ import javax.persistence.ManyToOne;
|
|||||||
import javax.persistence.OneToMany;
|
import javax.persistence.OneToMany;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
import javax.persistence.UniqueConstraint;
|
import javax.persistence.UniqueConstraint;
|
||||||
import org.apache.fineract.infrastructure.core.domain.AbstractAuditableCustom;
|
import org.apache.fineract.infrastructure.core.domain.AbstractAuditableWithUTCDateTimeCustom;
|
||||||
import org.apache.fineract.infrastructure.core.service.DateUtils;
|
import org.apache.fineract.infrastructure.core.service.DateUtils;
|
||||||
import org.apache.fineract.organisation.monetary.data.CurrencyData;
|
import org.apache.fineract.organisation.monetary.data.CurrencyData;
|
||||||
import org.apache.fineract.organisation.monetary.domain.MonetaryCurrency;
|
import org.apache.fineract.organisation.monetary.domain.MonetaryCurrency;
|
||||||
@@ -56,7 +56,7 @@ import org.apache.fineract.portfolio.paymentdetail.domain.PaymentDetail;
|
|||||||
*/
|
*/
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "m_loan_transaction", uniqueConstraints = { @UniqueConstraint(columnNames = { "external_id" }, name = "external_id_UNIQUE") })
|
@Table(name = "m_loan_transaction", uniqueConstraints = { @UniqueConstraint(columnNames = { "external_id" }, name = "external_id_UNIQUE") })
|
||||||
public class LoanTransaction extends AbstractAuditableCustom {
|
public class LoanTransaction extends AbstractAuditableWithUTCDateTimeCustom {
|
||||||
|
|
||||||
@ManyToOne(optional = false)
|
@ManyToOne(optional = false)
|
||||||
@JoinColumn(name = "loan_id", nullable = false)
|
@JoinColumn(name = "loan_id", nullable = false)
|
||||||
@@ -726,8 +726,8 @@ public class LoanTransaction extends AbstractAuditableCustom {
|
|||||||
this.manuallyAdjustedOrReversed = true;
|
this.manuallyAdjustedOrReversed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LocalDateTime getCreatedDateTime() {
|
public OffsetDateTime getCreatedDateTime() {
|
||||||
return (this.getCreatedDate().isPresent() ? this.getCreatedDate().get() : DateUtils.getLocalDateTimeOfTenant());
|
return (this.getCreatedDate().isPresent() ? this.getCreatedDate().get() : DateUtils.getOffsetDateTimeOfTenant());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isLastTransaction(final LoanTransaction loanTransaction) {
|
public boolean isLastTransaction(final LoanTransaction loanTransaction) {
|
||||||
@@ -808,6 +808,10 @@ public class LoanTransaction extends AbstractAuditableCustom {
|
|||||||
return this.loanCollateralManagementSet;
|
return this.loanCollateralManagementSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LocalDate getSubmittedOnDate() {
|
||||||
|
return submittedOnDate;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO missing hashCode(), equals(Object obj), but probably OK as long as
|
// TODO missing hashCode(), equals(Object obj), but probably OK as long as
|
||||||
// this is never stored in a Collection.
|
// this is never stored in a Collection.
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-2
@@ -676,8 +676,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
|
|||||||
+ " left join m_loan_arrears_aging la on la.loan_id = l.id" //
|
+ " left join m_loan_arrears_aging la on la.loan_id = l.id" //
|
||||||
+ " left join m_fund f on f.id = l.fund_id" //
|
+ " left join m_fund f on f.id = l.fund_id" //
|
||||||
+ " left join m_staff s on s.id = l.loan_officer_id" //
|
+ " left join m_staff s on s.id = l.loan_officer_id" //
|
||||||
+ " left join m_appuser sbu on sbu.id = l.submittedon_userid"
|
+ " left join m_appuser sbu on sbu.id = l.created_by" + " left join m_appuser rbu on rbu.id = l.rejectedon_userid"
|
||||||
+ " left join m_appuser rbu on rbu.id = l.rejectedon_userid"
|
|
||||||
+ " left join m_appuser wbu on wbu.id = l.withdrawnon_userid"
|
+ " left join m_appuser wbu on wbu.id = l.withdrawnon_userid"
|
||||||
+ " left join m_appuser abu on abu.id = l.approvedon_userid"
|
+ " left join m_appuser abu on abu.id = l.approvedon_userid"
|
||||||
+ " left join m_appuser dbu on dbu.id = l.disbursedon_userid" + " left join m_appuser cbu on cbu.id = l.closedon_userid"
|
+ " left join m_appuser dbu on dbu.id = l.disbursedon_userid" + " left join m_appuser cbu on cbu.id = l.closedon_userid"
|
||||||
|
|||||||
+1
-3
@@ -23,7 +23,6 @@ import com.google.gson.JsonElement;
|
|||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.ZoneId;
|
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -3302,8 +3301,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
|
|||||||
private void validateTransactionsForTransfer(final Loan loan, final LocalDate transferDate) {
|
private void validateTransactionsForTransfer(final Loan loan, final LocalDate transferDate) {
|
||||||
|
|
||||||
for (LoanTransaction transaction : loan.getLoanTransactions()) {
|
for (LoanTransaction transaction : loan.getLoanTransactions()) {
|
||||||
if ((transaction.getTransactionDate().isEqual(transferDate)
|
if ((transaction.getTransactionDate().isEqual(transferDate) && transaction.getSubmittedOnDate().isEqual(transferDate))
|
||||||
&& transaction.getCreatedDateTime().isEqual(transferDate.atStartOfDay(ZoneId.systemDefault()).toLocalDateTime()))
|
|
||||||
|| transaction.getTransactionDate().isAfter(transferDate)) {
|
|| transaction.getTransactionDate().isAfter(transferDate)) {
|
||||||
throw new GeneralPlatformDomainRuleException(TransferApiConstants.transferClientLoanException,
|
throw new GeneralPlatformDomainRuleException(TransferApiConstants.transferClientLoanException,
|
||||||
TransferApiConstants.transferClientLoanExceptionMessage, transaction.getCreatedDateTime().toLocalDate(),
|
TransferApiConstants.transferClientLoanExceptionMessage, transaction.getCreatedDateTime().toLocalDate(),
|
||||||
|
|||||||
+6
-6
@@ -38,10 +38,10 @@ public final class TransferApiConstants {
|
|||||||
public static final String destinationOfficeIdParamName = "destinationOfficeId";
|
public static final String destinationOfficeIdParamName = "destinationOfficeId";
|
||||||
public static final String note = "note";
|
public static final String note = "note";
|
||||||
public static final String transferDate = "transferDate";
|
public static final String transferDate = "transferDate";
|
||||||
public static final String transferClientLoanException = "error.msg.caanot.transfer.client.as.loan.transaction.present.on.or.after.transfer.date";
|
public static final String transferClientLoanException = "error.msg.cannot.transfer.client.as.loan.transaction.present.on.or.after.transfer.date";
|
||||||
public static final String transferClientLoanExceptionMessage = "error msg caanot transfer client as loan transaction present on or after transfer date";
|
public static final String transferClientLoanExceptionMessage = "error msg cannot transfer client as loan transaction present on or after transfer date";
|
||||||
public static final String transferClientSavingsException = "error.msg.caanot.transfer.client.as.savings.transaction.present.on.or.after.transfer.date";
|
public static final String transferClientSavingsException = "error.msg.cannot.transfer.client.as.savings.transaction.present.on.or.after.transfer.date";
|
||||||
public static final String transferClientSavingsExceptionMessage = "error msg caanot transfer client as savings transaction present on or after transfer date";
|
public static final String transferClientSavingsExceptionMessage = "error msg cannot transfer client as savings transaction present on or after transfer date";
|
||||||
public static final String transferClientToSameOfficeException = "error.msg.cannot.transfer.clinet.as.selected.office.and.current.office.are.same";
|
public static final String transferClientToSameOfficeException = "error.msg.cannot.transfer.client.as.selected.office.and.current.office.are.same";
|
||||||
public static final String transferClientToSameOfficeExceptionMessage = "error.msg.cannot.transfer.clinet.as.selected.office.and.current.office.are.same";
|
public static final String transferClientToSameOfficeExceptionMessage = "error.msg.cannot.transfer.client.as.selected.office.and.current.office.are.same";
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -22,11 +22,11 @@
|
|||||||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.1.xsd">
|
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.1.xsd">
|
||||||
<changeSet author="fineract" id="1" onValidationFail="MARK_RAN">
|
<changeSet author="fineract" id="1">
|
||||||
|
<validCheckSum>8:4500ffb68c695d72caba498deff75643</validCheckSum>
|
||||||
<addColumn tableName="m_loan_transaction">
|
<addColumn tableName="m_loan_transaction">
|
||||||
<column name="createdby_id" type="BIGINT" valueComputed="appuser_id"/>
|
<column name="createdby_id" type="BIGINT" valueComputed="appuser_id"/>
|
||||||
<column name="lastmodifiedby_id" type="BIGINT"/>
|
<column name="lastmodifiedby_id" type="BIGINT"/>
|
||||||
<column name="lastmodified_date" type="DATETIME"/>
|
|
||||||
</addColumn>
|
</addColumn>
|
||||||
</changeSet>
|
</changeSet>
|
||||||
<changeSet id="2" author="fineract">
|
<changeSet id="2" author="fineract">
|
||||||
|
|||||||
+211
@@ -0,0 +1,211 @@
|
|||||||
|
/**
|
||||||
|
* 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.apache.fineract.infrastructure.core.domain.AuditableFieldsConstants.CREATED_BY;
|
||||||
|
import static org.apache.fineract.infrastructure.core.domain.AuditableFieldsConstants.CREATED_DATE;
|
||||||
|
import static org.apache.fineract.infrastructure.core.domain.AuditableFieldsConstants.LAST_MODIFIED_BY;
|
||||||
|
import static org.apache.fineract.infrastructure.core.domain.AuditableFieldsConstants.LAST_MODIFIED_DATE;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
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.OffsetDateTime;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import org.apache.fineract.integrationtests.common.ClientHelper;
|
||||||
|
import org.apache.fineract.integrationtests.common.Utils;
|
||||||
|
import org.apache.fineract.integrationtests.common.accounting.Account;
|
||||||
|
import org.apache.fineract.integrationtests.common.accounting.AccountHelper;
|
||||||
|
import org.apache.fineract.integrationtests.common.loans.LoanApplicationTestBuilder;
|
||||||
|
import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder;
|
||||||
|
import org.apache.fineract.integrationtests.common.loans.LoanStatusChecker;
|
||||||
|
import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
|
||||||
|
import org.apache.fineract.integrationtests.common.organisation.StaffHelper;
|
||||||
|
import org.apache.fineract.integrationtests.useradministration.users.UserHelper;
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public class LoanTransactionAuditingIntegrationTest {
|
||||||
|
|
||||||
|
private static final Logger LOG = LoggerFactory.getLogger(LoanTransactionAuditingIntegrationTest.class);
|
||||||
|
private ResponseSpecification responseSpec;
|
||||||
|
private RequestSpecification requestSpec;
|
||||||
|
private LoanTransactionHelper loanTransactionHelper;
|
||||||
|
private AccountHelper accountHelper;
|
||||||
|
|
||||||
|
@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.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
|
||||||
|
this.accountHelper = new AccountHelper(this.requestSpec, this.responseSpec);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void checkAuditDates() throws InterruptedException {
|
||||||
|
final Integer staffId = StaffHelper.createStaff(this.requestSpec, this.responseSpec);
|
||||||
|
String username = Utils.randomNameGenerator("user", 8);
|
||||||
|
final Integer userId = (Integer) UserHelper.createUser(this.requestSpec, this.responseSpec, 1, staffId, username, "resourceId");
|
||||||
|
|
||||||
|
LOG.info("-------------------------Creating Client---------------------------");
|
||||||
|
|
||||||
|
final Integer clientID = ClientHelper.createClient(requestSpec, responseSpec);
|
||||||
|
ClientHelper.verifyClientCreatedOnServer(requestSpec, responseSpec, clientID);
|
||||||
|
LOG.info("-------------------------Creating Loan---------------------------");
|
||||||
|
final Account assetAccount = this.accountHelper.createAssetAccount();
|
||||||
|
final Account incomeAccount = this.accountHelper.createIncomeAccount();
|
||||||
|
final Account expenseAccount = this.accountHelper.createExpenseAccount();
|
||||||
|
final Account overpaymentAccount = this.accountHelper.createLiabilityAccount();
|
||||||
|
|
||||||
|
final Integer loanProductID = createLoanProduct("0", "0", LoanProductTestBuilder.DEFAULT_STRATEGY, "2", assetAccount, incomeAccount,
|
||||||
|
expenseAccount, overpaymentAccount);
|
||||||
|
|
||||||
|
final Integer loanID = applyForLoanApplicationWithPaymentStrategyAndPastMonth(clientID, loanProductID, Collections.emptyList(),
|
||||||
|
null, "10000", LoanApplicationTestBuilder.DEFAULT_STRATEGY, "10 July 2022");
|
||||||
|
Assertions.assertNotNull(loanID);
|
||||||
|
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
|
||||||
|
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
|
||||||
|
|
||||||
|
LOG.info("-----------------------------------APPROVE LOAN-----------------------------------------");
|
||||||
|
loanStatusHashMap = this.loanTransactionHelper.approveLoan("11 July 2022", loanID);
|
||||||
|
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
|
||||||
|
loanStatusHashMap = this.loanTransactionHelper.disburseLoan("11 July 2022", loanID, "10000");
|
||||||
|
LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
|
||||||
|
|
||||||
|
OffsetDateTime now = OffsetDateTime.now(ZoneId.of("Asia/Kolkata"));
|
||||||
|
// Testing in minutes precision, but still need to take care around the end of the actual minute
|
||||||
|
if (now.getSecond() > 56) {
|
||||||
|
Thread.sleep(5000);
|
||||||
|
now = OffsetDateTime.now(ZoneId.of("Asia/Kolkata"));
|
||||||
|
}
|
||||||
|
HashMap repaymentDetails = this.loanTransactionHelper.makeRepayment("11 July 2022", 100.0f, loanID);
|
||||||
|
Integer transactionId = (Integer) repaymentDetails.get("resourceId");
|
||||||
|
HashMap auditFieldsResponse = LoanTransactionHelper.getLoanTransactionAuditFields(requestSpec, responseSpec, loanID, transactionId,
|
||||||
|
"");
|
||||||
|
|
||||||
|
OffsetDateTime createdDate = OffsetDateTime.parse((String) auditFieldsResponse.get(CREATED_DATE),
|
||||||
|
DateTimeFormatter.ISO_OFFSET_DATE_TIME);
|
||||||
|
|
||||||
|
OffsetDateTime lastModifiedDate = OffsetDateTime.parse((String) auditFieldsResponse.get(LAST_MODIFIED_DATE),
|
||||||
|
DateTimeFormatter.ISO_OFFSET_DATE_TIME);
|
||||||
|
|
||||||
|
LOG.info("-------------------------Check Audit dates---------------------------");
|
||||||
|
assertEquals(1, auditFieldsResponse.get(CREATED_BY));
|
||||||
|
assertEquals(now.getYear(), createdDate.getYear());
|
||||||
|
assertEquals(now.getMonth(), createdDate.getMonth());
|
||||||
|
assertEquals(now.getDayOfMonth(), createdDate.getDayOfMonth());
|
||||||
|
assertEquals(now.getHour(), createdDate.getHour());
|
||||||
|
assertEquals(now.getMinute(), createdDate.getMinute());
|
||||||
|
|
||||||
|
assertEquals(1, auditFieldsResponse.get(LAST_MODIFIED_BY));
|
||||||
|
assertEquals(now.getYear(), lastModifiedDate.getYear());
|
||||||
|
assertEquals(now.getMonth(), lastModifiedDate.getMonth());
|
||||||
|
assertEquals(now.getDayOfMonth(), lastModifiedDate.getDayOfMonth());
|
||||||
|
assertEquals(now.getHour(), lastModifiedDate.getHour());
|
||||||
|
assertEquals(now.getMinute(), lastModifiedDate.getMinute());
|
||||||
|
|
||||||
|
Thread.sleep(2000);
|
||||||
|
|
||||||
|
this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
|
||||||
|
this.requestSpec.header("Authorization",
|
||||||
|
"Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey(username, "password"));
|
||||||
|
|
||||||
|
this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
|
||||||
|
this.loanTransactionHelper.reverseRepayment(loanID, transactionId, "11 July 2022");
|
||||||
|
|
||||||
|
now = OffsetDateTime.now(ZoneId.of("Asia/Kolkata"));
|
||||||
|
|
||||||
|
auditFieldsResponse = LoanTransactionHelper.getLoanTransactionAuditFields(requestSpec, responseSpec, loanID, transactionId, "");
|
||||||
|
|
||||||
|
createdDate = OffsetDateTime.parse((String) auditFieldsResponse.get(CREATED_DATE), DateTimeFormatter.ISO_OFFSET_DATE_TIME);
|
||||||
|
|
||||||
|
lastModifiedDate = OffsetDateTime.parse((String) auditFieldsResponse.get(LAST_MODIFIED_DATE),
|
||||||
|
DateTimeFormatter.ISO_OFFSET_DATE_TIME);
|
||||||
|
|
||||||
|
LOG.info("-------------------------Check Audit dates---------------------------");
|
||||||
|
assertEquals(1, auditFieldsResponse.get(CREATED_BY));
|
||||||
|
assertEquals(now.getYear(), createdDate.getYear());
|
||||||
|
assertEquals(now.getMonth(), createdDate.getMonth());
|
||||||
|
assertEquals(now.getDayOfMonth(), createdDate.getDayOfMonth());
|
||||||
|
assertEquals(now.getHour(), createdDate.getHour());
|
||||||
|
assertEquals(now.getMinute(), createdDate.getMinute());
|
||||||
|
|
||||||
|
now = OffsetDateTime.now(ZoneId.of("Asia/Kolkata"));
|
||||||
|
|
||||||
|
assertEquals(userId, auditFieldsResponse.get(LAST_MODIFIED_BY));
|
||||||
|
assertEquals(now.getYear(), lastModifiedDate.getYear());
|
||||||
|
assertEquals(now.getMonth(), lastModifiedDate.getMonth());
|
||||||
|
assertEquals(now.getDayOfMonth(), lastModifiedDate.getDayOfMonth());
|
||||||
|
assertEquals(now.getHour(), lastModifiedDate.getHour());
|
||||||
|
assertEquals(now.getMinute(), lastModifiedDate.getMinute());
|
||||||
|
}
|
||||||
|
|
||||||
|
private Integer applyForLoanApplicationWithPaymentStrategyAndPastMonth(final Integer clientID, final Integer loanProductID,
|
||||||
|
List<HashMap> charges, final String savingsId, String principal, final String repaymentStrategy, final String submittedOnDate) {
|
||||||
|
LOG.info("--------------------------------APPLYING FOR LOAN APPLICATION--------------------------------");
|
||||||
|
|
||||||
|
final String loanApplicationJSON = new LoanApplicationTestBuilder() //
|
||||||
|
.withPrincipal(principal) //
|
||||||
|
.withLoanTermFrequency("6") //
|
||||||
|
.withLoanTermFrequencyAsMonths() //
|
||||||
|
.withNumberOfRepayments("6") //
|
||||||
|
.withRepaymentEveryAfter("1") //
|
||||||
|
.withRepaymentFrequencyTypeAsMonths() //
|
||||||
|
.withInterestRatePerPeriod("2") //
|
||||||
|
.withAmortizationTypeAsEqualInstallments() //
|
||||||
|
.withInterestTypeAsFlatBalance() //
|
||||||
|
.withInterestCalculationPeriodTypeSameAsRepaymentPeriod() //
|
||||||
|
.withExpectedDisbursementDate(submittedOnDate) //
|
||||||
|
.withSubmittedOnDate(submittedOnDate) //
|
||||||
|
.withwithRepaymentStrategy(repaymentStrategy) //
|
||||||
|
.withCharges(charges).build(clientID.toString(), loanProductID.toString(), savingsId);
|
||||||
|
return this.loanTransactionHelper.getLoanId(loanApplicationJSON);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Integer createLoanProduct(final String inMultiplesOf, final String digitsAfterDecimal, final String repaymentStrategy,
|
||||||
|
final String accountingRule, final Account... accounts) {
|
||||||
|
LOG.info("------------------------------CREATING NEW LOAN PRODUCT ---------------------------------------");
|
||||||
|
final String loanProductJSON = new LoanProductTestBuilder() //
|
||||||
|
.withPrincipal("10000000.00") //
|
||||||
|
.withNumberOfRepayments("24") //
|
||||||
|
.withRepaymentAfterEvery("1") //
|
||||||
|
.withRepaymentTypeAsMonth() //
|
||||||
|
.withinterestRatePerPeriod("2") //
|
||||||
|
.withInterestRateFrequencyTypeAsMonths() //
|
||||||
|
.withRepaymentStrategy(repaymentStrategy) //
|
||||||
|
.withAmortizationTypeAsEqualPrincipalPayment() //
|
||||||
|
.withInterestTypeAsDecliningBalance() //
|
||||||
|
.currencyDetails(digitsAfterDecimal, inMultiplesOf).withAccounting(accountingRule, accounts).build(null);
|
||||||
|
return this.loanTransactionHelper.getLoanProductId(loanProductJSON);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+35
@@ -63,6 +63,7 @@ public class LoanTransactionHelper {
|
|||||||
private static final String WRITE_OFF_LOAN_COMMAND = "writeoff";
|
private static final String WRITE_OFF_LOAN_COMMAND = "writeoff";
|
||||||
private static final String WAIVE_INTEREST_COMMAND = "waiveinterest";
|
private static final String WAIVE_INTEREST_COMMAND = "waiveinterest";
|
||||||
private static final String MAKE_REPAYMENT_COMMAND = "repayment";
|
private static final String MAKE_REPAYMENT_COMMAND = "repayment";
|
||||||
|
private static final String UNDO = "undo";
|
||||||
private static final String CREDIT_BALANCE_REFUND_COMMAND = "creditBalanceRefund";
|
private static final String CREDIT_BALANCE_REFUND_COMMAND = "creditBalanceRefund";
|
||||||
private static final String WITHDRAW_LOAN_APPLICATION_COMMAND = "withdrawnByApplicant";
|
private static final String WITHDRAW_LOAN_APPLICATION_COMMAND = "withdrawnByApplicant";
|
||||||
private static final String RECOVER_FROM_GUARANTORS_COMMAND = "recoverGuarantees";
|
private static final String RECOVER_FROM_GUARANTORS_COMMAND = "recoverGuarantees";
|
||||||
@@ -360,6 +361,10 @@ public class LoanTransactionHelper {
|
|||||||
getRepaymentBodyAsJSON(date, amountToBePaid), "");
|
getRepaymentBodyAsJSON(date, amountToBePaid), "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public HashMap reverseRepayment(final Integer loanId, final Integer transactionId, String date) {
|
||||||
|
return (HashMap) performLoanTransaction(createLoanTransactionURL(UNDO, loanId, transactionId), getUndoJsonBody(date), "");
|
||||||
|
}
|
||||||
|
|
||||||
public HashMap makeRepaymentWithPDC(final String date, final Float amountToBePaid, final Integer loanID, final Integer paymentType) {
|
public HashMap makeRepaymentWithPDC(final String date, final Float amountToBePaid, final Integer loanID, final Integer paymentType) {
|
||||||
return (HashMap) performLoanTransaction(createLoanTransactionURL(MAKE_REPAYMENT_COMMAND, loanID),
|
return (HashMap) performLoanTransaction(createLoanTransactionURL(MAKE_REPAYMENT_COMMAND, loanID),
|
||||||
getRepaymentWithPDCBodyAsJSON(date, amountToBePaid, paymentType), "");
|
getRepaymentWithPDCBodyAsJSON(date, amountToBePaid, paymentType), "");
|
||||||
@@ -554,6 +559,15 @@ public class LoanTransactionHelper {
|
|||||||
return new Gson().toJson(map);
|
return new Gson().toJson(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getUndoJsonBody(String date) {
|
||||||
|
final HashMap<String, String> map = new HashMap<>();
|
||||||
|
map.put("transactionDate", date);
|
||||||
|
map.put("transactionAmount", "0");
|
||||||
|
map.put("dateFormat", "dd MMMM yyyy");
|
||||||
|
map.put("locale", "en");
|
||||||
|
return new Gson().toJson(map);
|
||||||
|
}
|
||||||
|
|
||||||
private String getRepaymentWithPDCBodyAsJSON(final String transactionDate, final Float transactionAmount, final Integer paymentTypeId) {
|
private String getRepaymentWithPDCBodyAsJSON(final String transactionDate, final Float transactionAmount, final Integer paymentTypeId) {
|
||||||
final HashMap<String, String> map = new HashMap<>();
|
final HashMap<String, String> map = new HashMap<>();
|
||||||
map.put("locale", "en");
|
map.put("locale", "en");
|
||||||
@@ -708,6 +722,11 @@ public class LoanTransactionHelper {
|
|||||||
return "/fineract-provider/api/v1/loans/" + loanID + "/transactions?command=" + command + "&" + Utils.TENANT_IDENTIFIER;
|
return "/fineract-provider/api/v1/loans/" + loanID + "/transactions?command=" + command + "&" + Utils.TENANT_IDENTIFIER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String createLoanTransactionURL(final String command, final Integer loanID, final Integer transactionId) {
|
||||||
|
return "/fineract-provider/api/v1/loans/" + loanID + "/transactions/" + transactionId + "?command=" + command + "&"
|
||||||
|
+ Utils.TENANT_IDENTIFIER;
|
||||||
|
}
|
||||||
|
|
||||||
private String createGlimAccountURL(final String command, final Integer glimID) {
|
private String createGlimAccountURL(final String command, final Integer glimID) {
|
||||||
return "/fineract-provider/api/v1/loans/glimAccount/" + glimID + "?command=" + command + "&" + Utils.TENANT_IDENTIFIER;
|
return "/fineract-provider/api/v1/loans/glimAccount/" + glimID + "?command=" + command + "&" + Utils.TENANT_IDENTIFIER;
|
||||||
}
|
}
|
||||||
@@ -950,4 +969,20 @@ public class LoanTransactionHelper {
|
|||||||
return Utils.performServerOutputTemplateLocationGet(requestSpec, responseSpec,
|
return Utils.performServerOutputTemplateLocationGet(requestSpec, responseSpec,
|
||||||
"/fineract-provider/api/v1/imports/getOutputTemplateLocation" + "?" + Utils.TENANT_IDENTIFIER, importDocumentId);
|
"/fineract-provider/api/v1/imports/getOutputTemplateLocation" + "?" + Utils.TENANT_IDENTIFIER, importDocumentId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static HashMap<String, Object> getLoanAuditFields(final RequestSpecification requestSpec,
|
||||||
|
final ResponseSpecification responseSpec, final Integer loanId, final String jsonReturn) {
|
||||||
|
final String GET_LOAN_URL = "/fineract-provider/api/v1/internal/loan/" + loanId + "/audit?" + Utils.TENANT_IDENTIFIER;
|
||||||
|
LOG.info("---------------------------------GET A LOAN ENTITY AUDIT FIELDS---------------------------------------------");
|
||||||
|
return Utils.performServerGet(requestSpec, responseSpec, GET_LOAN_URL, jsonReturn);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HashMap<String, Object> getLoanTransactionAuditFields(final RequestSpecification requestSpec,
|
||||||
|
final ResponseSpecification responseSpec, final Integer loanId, final Integer transactionId, final String jsonReturn) {
|
||||||
|
final String GET_LOAN_TRANSACTION_URL = "/fineract-provider/api/v1/internal/loan/" + loanId + "/transaction/" + transactionId
|
||||||
|
+ "/audit?" + Utils.TENANT_IDENTIFIER;
|
||||||
|
LOG.info(
|
||||||
|
"---------------------------------GET A LOAN TRANSACTION ENTITY AUDIT FIELDS---------------------------------------------");
|
||||||
|
return Utils.performServerGet(requestSpec, responseSpec, GET_LOAN_TRANSACTION_URL, jsonReturn);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user