diff --git a/config/spotbugs/exclude.xml b/config/spotbugs/exclude.xml
index 251015bb617..44160dfd6a9 100644
--- a/config/spotbugs/exclude.xml
+++ b/config/spotbugs/exclude.xml
@@ -26,6 +26,9 @@
+
+
+
diff --git a/docker-compose-web-app.yml b/docker-compose-web-app.yml
new file mode 100644
index 00000000000..7d1b768ef37
--- /dev/null
+++ b/docker-compose-web-app.yml
@@ -0,0 +1,27 @@
+# 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.
+#
+
+version: "3.8"
+services:
+ # Frontend service
+ community-app:
+ image: openmf/web-app:latest
+ container_name: mifos-web-app
+ restart: always
+ ports:
+ - 4200:80
diff --git a/fineract-core/src/main/java/org/apache/fineract/commands/service/CommandWrapperBuilder.java b/fineract-core/src/main/java/org/apache/fineract/commands/service/CommandWrapperBuilder.java
index 88646406cf6..edbb8f892df 100644
--- a/fineract-core/src/main/java/org/apache/fineract/commands/service/CommandWrapperBuilder.java
+++ b/fineract-core/src/main/java/org/apache/fineract/commands/service/CommandWrapperBuilder.java
@@ -3656,6 +3656,22 @@ public CommandWrapperBuilder downPayment(final Long loanId) {
return this;
}
+ public CommandWrapperBuilder reAge(final Long loanId) {
+ this.actionName = "REAGE";
+ this.entityName = "LOAN";
+ this.loanId = loanId;
+ this.href = "/loans/" + loanId + "/transactions?command=reAge";
+ return this;
+ }
+
+ public CommandWrapperBuilder undoReAge(final Long loanId) {
+ this.actionName = "UNDO_REAGE";
+ this.entityName = "LOAN";
+ this.loanId = loanId;
+ this.href = "/loans/" + loanId + "/transactions?command=undoReAge";
+ return this;
+ }
+
public CommandWrapperBuilder createDelinquencyAction(final Long loanId) {
this.actionName = "CREATE";
this.entityName = "DELINQUENCY_ACTION";
diff --git a/fineract-core/src/main/java/org/apache/fineract/infrastructure/core/api/JsonCommand.java b/fineract-core/src/main/java/org/apache/fineract/infrastructure/core/api/JsonCommand.java
index 9d560ad83d7..d8211598e42 100644
--- a/fineract-core/src/main/java/org/apache/fineract/infrastructure/core/api/JsonCommand.java
+++ b/fineract-core/src/main/java/org/apache/fineract/infrastructure/core/api/JsonCommand.java
@@ -389,6 +389,19 @@ public boolean isChangeInStringParameterNamed(final String parameterName, final
return isChanged;
}
+ public > T enumValueOfParameterNamed(String parameterName, Class enumType) {
+ try {
+ String value = stringValueOfParameterNamedAllowingNull(parameterName);
+ if (value != null) {
+ return Enum.valueOf(enumType, value);
+ } else {
+ return null;
+ }
+ } catch (IllegalArgumentException e) {
+ return null;
+ }
+ }
+
public String stringValueOfParameterNamed(final String parameterName) {
final String value = this.fromApiJsonHelper.extractStringNamed(parameterName, this.parsedCommand);
return StringUtils.defaultIfEmpty(value, "");
diff --git a/fineract-core/src/main/java/org/apache/fineract/infrastructure/event/business/service/BusinessEventNotifierServiceImpl.java b/fineract-core/src/main/java/org/apache/fineract/infrastructure/event/business/service/BusinessEventNotifierServiceImpl.java
index ba1c85a2994..9809f6342f2 100644
--- a/fineract-core/src/main/java/org/apache/fineract/infrastructure/event/business/service/BusinessEventNotifierServiceImpl.java
+++ b/fineract-core/src/main/java/org/apache/fineract/infrastructure/event/business/service/BusinessEventNotifierServiceImpl.java
@@ -62,11 +62,9 @@ public void afterPropertiesSet() throws Exception {
@Override
public void notifyPreBusinessEvent(BusinessEvent> businessEvent) {
throwExceptionIfBulkEvent(businessEvent);
- List businessEventListeners = preListeners.get(businessEvent.getClass());
- if (businessEventListeners != null) {
- for (BusinessEventListener eventListener : businessEventListeners) {
- eventListener.onBusinessEvent(businessEvent);
- }
+ List businessEventListeners = findSuitableListeners(preListeners, businessEvent.getClass());
+ for (BusinessEventListener eventListener : businessEventListeners) {
+ eventListener.onBusinessEvent(businessEvent);
}
}
@@ -84,11 +82,9 @@ public > void addPreBusinessEventListener(Class ev
public void notifyPostBusinessEvent(BusinessEvent> businessEvent) {
throwExceptionIfBulkEvent(businessEvent);
boolean isExternalEvent = !(businessEvent instanceof NoExternalEvent);
- List businessEventListeners = postListeners.get(businessEvent.getClass());
- if (businessEventListeners != null) {
- for (BusinessEventListener eventListener : businessEventListeners) {
- eventListener.onBusinessEvent(businessEvent);
- }
+ List businessEventListeners = findSuitableListeners(postListeners, businessEvent.getClass());
+ for (BusinessEventListener eventListener : businessEventListeners) {
+ eventListener.onBusinessEvent(businessEvent);
}
if (isExternalEvent && isExternalEventPostingEnabled()) {
// we only want to create external events for operations that were successful, hence the post listener
@@ -102,6 +98,17 @@ public void notifyPostBusinessEvent(BusinessEvent> businessEvent) {
}
}
+ private List findSuitableListeners(Map> listeners, Class> eventClazz) {
+ List result = new ArrayList<>();
+ for (Map.Entry> entry : listeners.entrySet()) {
+ Class> registeredClazz = entry.getKey();
+ if (registeredClazz.isAssignableFrom(eventClazz)) {
+ result.addAll(entry.getValue());
+ }
+ }
+ return result;
+ }
+
@Override
public > void addPostBusinessEventListener(Class eventType, BusinessEventListener listener) {
List businessEventListeners = postListeners.get(eventType);
diff --git a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/api/LoanReAgingApiConstants.java b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/api/LoanReAgingApiConstants.java
new file mode 100644
index 00000000000..96411c24b8d
--- /dev/null
+++ b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/api/LoanReAgingApiConstants.java
@@ -0,0 +1,30 @@
+/**
+ * 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.portfolio.loanaccount.api;
+
+public interface LoanReAgingApiConstants {
+
+ String localeParameterName = "locale";
+ String dateFormatParameterName = "dateFormat";
+ String externalIdParameterName = "externalId";
+
+ String frequency = "frequency";
+ String startDate = "startDate";
+ String numberOfInstallments = "numberOfInstallments";
+}
diff --git a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/data/LoanTransactionEnumData.java b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/data/LoanTransactionEnumData.java
index 8d6db7a779a..c3985e4893c 100644
--- a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/data/LoanTransactionEnumData.java
+++ b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/data/LoanTransactionEnumData.java
@@ -19,6 +19,7 @@
package org.apache.fineract.portfolio.loanaccount.data;
import lombok.Getter;
+import org.apache.fineract.portfolio.loanaccount.domain.LoanTransactionType;
/**
* Immutable data object represent loan status enumerations.
@@ -55,6 +56,7 @@ public class LoanTransactionEnumData {
private final boolean chargeback;
private final boolean chargeoff;
private final boolean downPayment;
+ private final boolean reAge;
public LoanTransactionEnumData(final Long id, final String code, final String value) {
this.id = id;
@@ -85,6 +87,7 @@ public LoanTransactionEnumData(final Long id, final String code, final String va
this.chargeAdjustment = Long.valueOf(26).equals(this.id);
this.chargeoff = Long.valueOf(27).equals(this.id);
this.downPayment = Long.valueOf(28).equals(this.id);
+ this.reAge = Long.valueOf(LoanTransactionType.REAGE.getValue()).equals(this.id);
}
public boolean isRepaymentType() {
diff --git a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java
index 9d2dca1a64b..0349de44306 100644
--- a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java
+++ b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java
@@ -4280,6 +4280,13 @@ public Money getTotalRecoveredPayments() {
return cumulativePaid;
}
+ public Money getTotalPrincipalOutstandingUntil(LocalDate date) {
+ return getRepaymentScheduleInstallments().stream()
+ .filter(installment -> installment.getDueDate().isBefore(date) || installment.getDueDate().isEqual(date))
+ .map(installment -> installment.getPrincipalOutstanding(loanCurrency())).reduce(Money.zero(loanCurrency()), Money::add);
+
+ }
+
private Money getTotalInterestOutstandingOnLoan() {
Money cumulativeInterest = Money.zero(loanCurrency());
diff --git a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanTransaction.java b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanTransaction.java
index fd42d7e3db7..811baeeb250 100644
--- a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanTransaction.java
+++ b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanTransaction.java
@@ -316,7 +316,7 @@ public static boolean transactionAmountsMatch(final MonetaryCurrency currency, f
&& loanTransaction.getOverPaymentPortion(currency).isEqualTo(newLoanTransaction.getOverPaymentPortion(currency));
}
- private LoanTransaction(final Loan loan, final Office office, final Integer typeOf, final LocalDate dateOf, final BigDecimal amount,
+ public LoanTransaction(final Loan loan, final Office office, final Integer typeOf, final LocalDate dateOf, final BigDecimal amount,
final BigDecimal principalPortion, final BigDecimal interestPortion, final BigDecimal feeChargesPortion,
final BigDecimal penaltyChargesPortion, final BigDecimal overPaymentPortion, final boolean reversed,
final PaymentDetail paymentDetail, final ExternalId externalId) {
@@ -681,6 +681,10 @@ public boolean isChargeOff() {
return getTypeOf().isChargeOff() && isNotReversed();
}
+ public boolean isReAge() {
+ return getTypeOf().isReAge() && isNotReversed();
+ }
+
public boolean isIdentifiedBy(final Long identifier) {
return getId().equals(identifier);
}
diff --git a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanTransactionType.java b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanTransactionType.java
index ef5bd3f6627..a057300f69b 100644
--- a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanTransactionType.java
+++ b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanTransactionType.java
@@ -60,7 +60,8 @@ public enum LoanTransactionType {
CHARGEBACK(25, "loanTransactionType.chargeback"), //
CHARGE_ADJUSTMENT(26, "loanTransactionType.chargeAdjustment"), //
CHARGE_OFF(27, "loanTransactionType.chargeOff"), //
- DOWN_PAYMENT(28, "loanTransactionType.downPayment");
+ DOWN_PAYMENT(28, "loanTransactionType.downPayment"), //
+ REAGE(29, "loanTransactionType.reAge");
private final Integer value;
private final String code;
@@ -104,6 +105,7 @@ public static LoanTransactionType fromInt(final Integer transactionType) {
case 26 -> LoanTransactionType.CHARGE_ADJUSTMENT;
case 27 -> LoanTransactionType.CHARGE_OFF;
case 28 -> LoanTransactionType.DOWN_PAYMENT;
+ case 29 -> LoanTransactionType.REAGE;
default -> LoanTransactionType.INVALID;
};
}
@@ -192,6 +194,10 @@ public boolean isChargeOff() {
return this.equals(LoanTransactionType.CHARGE_OFF);
}
+ public boolean isReAge() {
+ return this.equals(LoanTransactionType.REAGE);
+ }
+
public boolean isDownPayment() {
return this.equals(LoanTransactionType.DOWN_PAYMENT);
}
diff --git a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/reaging/LoanReAgeParameter.java b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/reaging/LoanReAgeParameter.java
new file mode 100644
index 00000000000..78198ea71c0
--- /dev/null
+++ b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/reaging/LoanReAgeParameter.java
@@ -0,0 +1,54 @@
+/**
+ * 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.portfolio.loanaccount.domain.reaging;
+
+import jakarta.persistence.Column;
+import jakarta.persistence.Entity;
+import jakarta.persistence.EnumType;
+import jakarta.persistence.Enumerated;
+import jakarta.persistence.Table;
+import java.time.LocalDate;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import org.apache.fineract.infrastructure.core.domain.AbstractAuditableWithUTCDateTimeCustom;
+import org.apache.fineract.portfolio.common.domain.PeriodFrequencyType;
+
+@Entity
+@Table(name = "m_loan_reage_parameter")
+@AllArgsConstructor
+@Getter
+public class LoanReAgeParameter extends AbstractAuditableWithUTCDateTimeCustom {
+
+ // intentionally not doing a JPA relationship since it's not necessary
+ @Column(name = "loan_transaction_id", nullable = false)
+ private Long loanTransactionId;
+
+ @Enumerated(EnumType.STRING)
+ @Column(name = "frequency", nullable = false)
+ private PeriodFrequencyType frequency;
+
+ @Column(name = "start_date", nullable = false)
+ private LocalDate startDate;
+
+ @Column(name = "number_of_installments", nullable = false)
+ private Integer numberOfInstallments;
+
+ // for JPA, don't use
+ protected LoanReAgeParameter() {}
+}
diff --git a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/reaging/LoanReAgingParameterRepository.java b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/reaging/LoanReAgingParameterRepository.java
new file mode 100644
index 00000000000..7558afbc0b6
--- /dev/null
+++ b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/reaging/LoanReAgingParameterRepository.java
@@ -0,0 +1,28 @@
+/**
+ * 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.portfolio.loanaccount.domain.reaging;
+
+import java.util.Optional;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.repository.query.Param;
+
+public interface LoanReAgingParameterRepository extends JpaRepository {
+
+ Optional findByLoanTransactionId(@Param("loanTransactionId") Long loanTransactionId);
+}
diff --git a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/service/LoanEnumerations.java b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/service/LoanEnumerations.java
index affa363858d..efcae196d7a 100644
--- a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/service/LoanEnumerations.java
+++ b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/service/LoanEnumerations.java
@@ -313,6 +313,8 @@ public static LoanTransactionEnumData transactionType(final LoanTransactionType
LoanTransactionType.CHARGE_OFF.getCode(), "Charge-off");
case DOWN_PAYMENT -> new LoanTransactionEnumData(LoanTransactionType.DOWN_PAYMENT.getValue().longValue(),
LoanTransactionType.DOWN_PAYMENT.getCode(), "Down Payment");
+ case REAGE -> new LoanTransactionEnumData(LoanTransactionType.REAGE.getValue().longValue(), LoanTransactionType.REAGE.getCode(),
+ "Re-age");
};
}
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/business/domain/loan/transaction/reaging/LoanReAgeTransactionBusinessEvent.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/business/domain/loan/transaction/reaging/LoanReAgeTransactionBusinessEvent.java
new file mode 100644
index 00000000000..fea932aa756
--- /dev/null
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/business/domain/loan/transaction/reaging/LoanReAgeTransactionBusinessEvent.java
@@ -0,0 +1,36 @@
+/**
+ * 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.infrastructure.event.business.domain.loan.transaction.reaging;
+
+import org.apache.fineract.infrastructure.event.business.domain.loan.transaction.LoanTransactionBusinessEvent;
+import org.apache.fineract.portfolio.loanaccount.domain.LoanTransaction;
+
+public class LoanReAgeTransactionBusinessEvent extends LoanTransactionBusinessEvent {
+
+ private static final String TYPE = "LoanReAgeTransactionBusinessEvent";
+
+ public LoanReAgeTransactionBusinessEvent(LoanTransaction value) {
+ super(value);
+ }
+
+ @Override
+ public String getType() {
+ return TYPE;
+ }
+}
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/business/domain/loan/transaction/reaging/LoanUndoReAgeTransactionBusinessEvent.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/business/domain/loan/transaction/reaging/LoanUndoReAgeTransactionBusinessEvent.java
new file mode 100644
index 00000000000..540c2e06e81
--- /dev/null
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/business/domain/loan/transaction/reaging/LoanUndoReAgeTransactionBusinessEvent.java
@@ -0,0 +1,36 @@
+/**
+ * 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.infrastructure.event.business.domain.loan.transaction.reaging;
+
+import org.apache.fineract.infrastructure.event.business.domain.loan.transaction.LoanTransactionBusinessEvent;
+import org.apache.fineract.portfolio.loanaccount.domain.LoanTransaction;
+
+public class LoanUndoReAgeTransactionBusinessEvent extends LoanTransactionBusinessEvent {
+
+ private static final String TYPE = "LoanUndoReAgeTransactionBusinessEvent";
+
+ public LoanUndoReAgeTransactionBusinessEvent(LoanTransaction value) {
+ super(value);
+ }
+
+ @Override
+ public String getType() {
+ return TYPE;
+ }
+}
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/api/LoanTransactionsApiResource.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/api/LoanTransactionsApiResource.java
index c9eb31fb6aa..b479448099f 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/api/LoanTransactionsApiResource.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/api/LoanTransactionsApiResource.java
@@ -81,6 +81,8 @@ public class LoanTransactionsApiResource {
public static final String CHARGE_OFF_COMMAND_VALUE = "charge-off";
public static final String UNDO_CHARGE_OFF_COMMAND_VALUE = "undo-charge-off";
public static final String DOWN_PAYMENT = "downPayment";
+ public static final String UNDO_REAGE = "undoReAge";
+ public static final String REAGE = "reAge";
private final Set responseDataParameters = new HashSet<>(Arrays.asList("id", "type", "date", "currency", "amount", "externalId",
LoanApiConstants.REVERSAL_EXTERNAL_ID_PARAMNAME, LoanApiConstants.REVERSED_ON_DATE_PARAMNAME));
@@ -477,6 +479,10 @@ private String executeTransaction(final Long loanId, final String loanExternalId
commandRequest = builder.undoChargeOff(resolvedLoanId).build();
} else if (CommandParameterUtil.is(commandParam, DOWN_PAYMENT)) {
commandRequest = builder.downPayment(resolvedLoanId).build();
+ } else if (CommandParameterUtil.is(commandParam, REAGE)) {
+ commandRequest = builder.reAge(resolvedLoanId).build();
+ } else if (CommandParameterUtil.is(commandParam, UNDO_REAGE)) {
+ commandRequest = builder.undoReAge(resolvedLoanId).build();
}
if (commandRequest == null) {
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/api/LoanTransactionsApiResourceSwagger.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/api/LoanTransactionsApiResourceSwagger.java
index 33ed6e2b066..e4271435706 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/api/LoanTransactionsApiResourceSwagger.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/api/LoanTransactionsApiResourceSwagger.java
@@ -283,6 +283,15 @@ private PostLoansLoanIdTransactionsRequest() {}
public Long chargeOffReasonId;
@Schema(example = "1")
public Long writeoffReasonId;
+
+ // command=reAge START
+ @Schema(example = "frequency")
+ public String frequency;
+ @Schema(example = "startDate")
+ public String startDate;
+ @Schema(example = "numberOfInstallments")
+ public Integer numberOfInstallments;
+ // command=reAge END
}
@Schema(description = "PostLoansLoanIdTransactionsResponse")
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/loan/reaging/LoanReAgingCommandHandler.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/loan/reaging/LoanReAgingCommandHandler.java
new file mode 100644
index 00000000000..7f3778246d9
--- /dev/null
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/loan/reaging/LoanReAgingCommandHandler.java
@@ -0,0 +1,50 @@
+/**
+ * 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.portfolio.loanaccount.handler.loan.reaging;
+
+import lombok.RequiredArgsConstructor;
+import org.apache.fineract.commands.annotation.CommandType;
+import org.apache.fineract.commands.handler.NewCommandSourceHandler;
+import org.apache.fineract.infrastructure.DataIntegrityErrorHandler;
+import org.apache.fineract.infrastructure.core.api.JsonCommand;
+import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
+import org.apache.fineract.portfolio.loanaccount.service.reaging.LoanReAgingServiceImpl;
+import org.springframework.dao.DataIntegrityViolationException;
+import org.springframework.orm.jpa.JpaSystemException;
+import org.springframework.stereotype.Service;
+
+@Service
+@RequiredArgsConstructor
+@CommandType(entity = "LOAN", action = "REAGE")
+public class LoanReAgingCommandHandler implements NewCommandSourceHandler {
+
+ private final LoanReAgingServiceImpl loanReAgingService;
+ private final DataIntegrityErrorHandler dataIntegrityErrorHandler;
+
+ @Override
+ public CommandProcessingResult processCommand(JsonCommand command) {
+ try {
+ return loanReAgingService.reAge(command.getLoanId(), command);
+ } catch (final JpaSystemException | DataIntegrityViolationException dve) {
+ dataIntegrityErrorHandler.handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve, "loan.reAge",
+ "Error while handling re-aging");
+ return CommandProcessingResult.empty();
+ }
+ }
+}
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/loan/reaging/LoanUndoReAgingCommandHandler.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/loan/reaging/LoanUndoReAgingCommandHandler.java
new file mode 100644
index 00000000000..d66583d2c34
--- /dev/null
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/handler/loan/reaging/LoanUndoReAgingCommandHandler.java
@@ -0,0 +1,50 @@
+/**
+ * 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.portfolio.loanaccount.handler.loan.reaging;
+
+import lombok.RequiredArgsConstructor;
+import org.apache.fineract.commands.annotation.CommandType;
+import org.apache.fineract.commands.handler.NewCommandSourceHandler;
+import org.apache.fineract.infrastructure.DataIntegrityErrorHandler;
+import org.apache.fineract.infrastructure.core.api.JsonCommand;
+import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
+import org.apache.fineract.portfolio.loanaccount.service.reaging.LoanReAgingServiceImpl;
+import org.springframework.dao.DataIntegrityViolationException;
+import org.springframework.orm.jpa.JpaSystemException;
+import org.springframework.stereotype.Service;
+
+@Service
+@RequiredArgsConstructor
+@CommandType(entity = "LOAN", action = "UNDO_REAGE")
+public class LoanUndoReAgingCommandHandler implements NewCommandSourceHandler {
+
+ private final LoanReAgingServiceImpl loanReAgingService;
+ private final DataIntegrityErrorHandler dataIntegrityErrorHandler;
+
+ @Override
+ public CommandProcessingResult processCommand(JsonCommand command) {
+ try {
+ return loanReAgingService.undoReAge(command.getLoanId(), command);
+ } catch (final JpaSystemException | DataIntegrityViolationException dve) {
+ dataIntegrityErrorHandler.handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve, "loan.undoReAge",
+ "Error while handling undo re-age");
+ return CommandProcessingResult.empty();
+ }
+ }
+}
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/listener/LoanTransactionDelinquencyRecalculationListener.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/listener/LoanTransactionDelinquencyRecalculationListener.java
new file mode 100644
index 00000000000..9ee55b142b7
--- /dev/null
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/listener/LoanTransactionDelinquencyRecalculationListener.java
@@ -0,0 +1,60 @@
+/**
+ * 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.portfolio.loanaccount.service.listener;
+
+import java.util.List;
+import lombok.RequiredArgsConstructor;
+import org.apache.fineract.infrastructure.event.business.BusinessEventListener;
+import org.apache.fineract.infrastructure.event.business.domain.loan.transaction.LoanTransactionBusinessEvent;
+import org.apache.fineract.infrastructure.event.business.domain.loan.transaction.reaging.LoanReAgeTransactionBusinessEvent;
+import org.apache.fineract.infrastructure.event.business.domain.loan.transaction.reaging.LoanUndoReAgeTransactionBusinessEvent;
+import org.apache.fineract.infrastructure.event.business.service.BusinessEventNotifierService;
+import org.apache.fineract.portfolio.loanaccount.domain.LoanAccountDomainService;
+import org.apache.fineract.portfolio.loanaccount.domain.LoanTransaction;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.stereotype.Component;
+
+@Component
+@RequiredArgsConstructor
+public class LoanTransactionDelinquencyRecalculationListener
+ implements InitializingBean, BusinessEventListener {
+
+ // Extend this list to support more event types so the hardcoded delinquency recalculation can be removed from the
+ // use-cases
+ private static final List> SUPPORTED_EVENT_TYPES = List.of(//
+ LoanReAgeTransactionBusinessEvent.class, //
+ LoanUndoReAgeTransactionBusinessEvent.class //
+ );//
+
+ private final LoanAccountDomainService loanAccountDomainService;
+ private final BusinessEventNotifierService businessEventNotifierService;
+
+ @Override
+ public void afterPropertiesSet() throws Exception {
+ businessEventNotifierService.addPostBusinessEventListener(LoanTransactionBusinessEvent.class, this);
+ }
+
+ @Override
+ public void onBusinessEvent(LoanTransactionBusinessEvent event) {
+ if (SUPPORTED_EVENT_TYPES.contains(event.getClass())) {
+ LoanTransaction tx = event.get();
+ loanAccountDomainService.setLoanDelinquencyTag(tx.getLoan(), tx.getTransactionDate());
+ }
+ }
+}
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/reaging/LoanReAgingServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/reaging/LoanReAgingServiceImpl.java
new file mode 100644
index 00000000000..f08350527e2
--- /dev/null
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/reaging/LoanReAgingServiceImpl.java
@@ -0,0 +1,155 @@
+/**
+ * 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.portfolio.loanaccount.service.reaging;
+
+import static java.math.BigDecimal.ZERO;
+
+import java.math.BigDecimal;
+import java.time.LocalDate;
+import java.util.Comparator;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import lombok.RequiredArgsConstructor;
+import org.apache.fineract.infrastructure.core.api.JsonCommand;
+import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
+import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
+import org.apache.fineract.infrastructure.core.domain.ExternalId;
+import org.apache.fineract.infrastructure.core.service.DateUtils;
+import org.apache.fineract.infrastructure.core.service.ExternalIdFactory;
+import org.apache.fineract.infrastructure.event.business.domain.loan.transaction.reaging.LoanReAgeTransactionBusinessEvent;
+import org.apache.fineract.infrastructure.event.business.domain.loan.transaction.reaging.LoanUndoReAgeTransactionBusinessEvent;
+import org.apache.fineract.infrastructure.event.business.service.BusinessEventNotifierService;
+import org.apache.fineract.organisation.monetary.domain.Money;
+import org.apache.fineract.portfolio.common.domain.PeriodFrequencyType;
+import org.apache.fineract.portfolio.loanaccount.api.LoanReAgingApiConstants;
+import org.apache.fineract.portfolio.loanaccount.domain.Loan;
+import org.apache.fineract.portfolio.loanaccount.domain.LoanTransaction;
+import org.apache.fineract.portfolio.loanaccount.domain.LoanTransactionRepository;
+import org.apache.fineract.portfolio.loanaccount.domain.LoanTransactionType;
+import org.apache.fineract.portfolio.loanaccount.domain.reaging.LoanReAgeParameter;
+import org.apache.fineract.portfolio.loanaccount.domain.reaging.LoanReAgingParameterRepository;
+import org.apache.fineract.portfolio.loanaccount.service.LoanAssembler;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service
+@RequiredArgsConstructor
+@Transactional
+public class LoanReAgingServiceImpl {
+
+ private final LoanAssembler loanAssembler;
+ private final LoanReAgingValidator reAgingValidator;
+ private final ExternalIdFactory externalIdFactory;
+ private final BusinessEventNotifierService businessEventNotifierService;
+ private final LoanTransactionRepository loanTransactionRepository;
+ private final LoanReAgingParameterRepository reAgingParameterRepository;
+
+ public CommandProcessingResult reAge(Long loanId, JsonCommand command) {
+ Loan loan = loanAssembler.assembleFrom(loanId);
+ reAgingValidator.validateReAge(loan, command);
+
+ Map changes = new LinkedHashMap<>();
+ changes.put(LoanReAgingApiConstants.localeParameterName, command.locale());
+ changes.put(LoanReAgingApiConstants.dateFormatParameterName, command.dateFormat());
+
+ LoanTransaction reAgeTransaction = createReAgeTransaction(loan, command);
+ // important to do a flush before creating the reage parameter since it needs the ID
+ loanTransactionRepository.saveAndFlush(reAgeTransaction);
+
+ LoanReAgeParameter reAgeParameter = createReAgeParameter(reAgeTransaction, command);
+ reAgingParameterRepository.saveAndFlush(reAgeParameter);
+
+ // delinquency recalculation will be triggered by the event in a decoupled way via a listener
+ businessEventNotifierService.notifyPostBusinessEvent(new LoanReAgeTransactionBusinessEvent(reAgeTransaction));
+ return new CommandProcessingResultBuilder() //
+ .withCommandId(command.commandId()) //
+ .withEntityId(reAgeTransaction.getId()) //
+ .withEntityExternalId(reAgeTransaction.getExternalId()) //
+ .withOfficeId(loan.getOfficeId()) //
+ .withClientId(loan.getClientId()) //
+ .withGroupId(loan.getGroupId()) //
+ .withLoanId(command.getLoanId()) //
+ .with(changes).build();
+ }
+
+ private LoanReAgeParameter createReAgeParameter(LoanTransaction reAgeTransaction, JsonCommand command) {
+ // TODO: these parameters should be checked when the validations are implemented
+ PeriodFrequencyType periodFrequencyType = command.enumValueOfParameterNamed(LoanReAgingApiConstants.frequency,
+ PeriodFrequencyType.class);
+ LocalDate startDate = command.dateValueOfParameterNamed(LoanReAgingApiConstants.startDate);
+ Integer numberOfInstallments = command.integerValueOfParameterNamed(LoanReAgingApiConstants.numberOfInstallments);
+ return new LoanReAgeParameter(reAgeTransaction.getId(), periodFrequencyType, startDate, numberOfInstallments);
+ }
+
+ public CommandProcessingResult undoReAge(Long loanId, JsonCommand command) {
+ Loan loan = loanAssembler.assembleFrom(loanId);
+ reAgingValidator.validateUndoReAge(loan, command);
+
+ Map changes = new LinkedHashMap<>();
+ changes.put(LoanReAgingApiConstants.localeParameterName, command.locale());
+ changes.put(LoanReAgingApiConstants.dateFormatParameterName, command.dateFormat());
+
+ LoanTransaction reAgeTransaction = findLatestNonReversedReAgeTransaction(loan);
+ if (reAgeTransaction == null) {
+ // TODO: when validations implemented; throw exception if there isn't a reage transaction available
+ }
+ reverseReAgeTransaction(reAgeTransaction, command);
+ loanTransactionRepository.saveAndFlush(reAgeTransaction);
+
+ // delinquency recalculation will be triggered by the event in a decoupled way via a listener
+ businessEventNotifierService.notifyPostBusinessEvent(new LoanUndoReAgeTransactionBusinessEvent(reAgeTransaction));
+ return new CommandProcessingResultBuilder() //
+ .withCommandId(command.commandId()) //
+ .withEntityId(reAgeTransaction.getId()) //
+ .withEntityExternalId(reAgeTransaction.getExternalId()) //
+ .withOfficeId(loan.getOfficeId()) //
+ .withClientId(loan.getClientId()) //
+ .withGroupId(loan.getGroupId()) //
+ .withLoanId(command.getLoanId()) //
+ .with(changes).build();
+ }
+
+ private void reverseReAgeTransaction(LoanTransaction reAgeTransaction, JsonCommand command) {
+ ExternalId reversalExternalId = externalIdFactory.createFromCommand(command, LoanReAgingApiConstants.externalIdParameterName);
+ reAgeTransaction.reverse(reversalExternalId);
+ reAgeTransaction.manuallyAdjustedOrReversed();
+ }
+
+ private LoanTransaction findLatestNonReversedReAgeTransaction(Loan loan) {
+ return loan.getLoanTransactions().stream() //
+ .filter(LoanTransaction::isNotReversed) //
+ .filter(LoanTransaction::isReAge) //
+ .max(Comparator.comparing(LoanTransaction::getTransactionDate)) //
+ .orElse(null);
+ }
+
+ private LoanTransaction createReAgeTransaction(Loan loan, JsonCommand command) {
+ ExternalId txExternalId = externalIdFactory.createFromCommand(command, LoanReAgingApiConstants.externalIdParameterName);
+
+ // reaging transaction date is always the current business date
+ LocalDate transactionDate = DateUtils.getBusinessLocalDate();
+
+ // in case of a reaging transaction, only the outstanding principal amount until the business date is considered
+ Money txPrincipal = loan.getTotalPrincipalOutstandingUntil(transactionDate);
+ BigDecimal txPrincipalAmount = txPrincipal.getAmount();
+
+ return new LoanTransaction(loan, loan.getOffice(), LoanTransactionType.REAGE.getValue(), transactionDate, txPrincipalAmount,
+ txPrincipalAmount, ZERO, ZERO, ZERO, null, false, null, txExternalId);
+ }
+}
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/reaging/LoanReAgingValidator.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/reaging/LoanReAgingValidator.java
new file mode 100644
index 00000000000..a3dfceb8e6c
--- /dev/null
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/reaging/LoanReAgingValidator.java
@@ -0,0 +1,35 @@
+/**
+ * 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.portfolio.loanaccount.service.reaging;
+
+import org.apache.fineract.infrastructure.core.api.JsonCommand;
+import org.apache.fineract.portfolio.loanaccount.domain.Loan;
+import org.springframework.stereotype.Component;
+
+@Component
+public class LoanReAgingValidator {
+
+ public void validateReAge(Loan loan, JsonCommand command) {
+ // TODO: implement
+ }
+
+ public void validateUndoReAge(Loan loan, JsonCommand command) {
+ // TODO: implement
+ }
+}
diff --git a/fineract-provider/src/main/resources/db/changelog/tenant/changelog-tenant.xml b/fineract-provider/src/main/resources/db/changelog/tenant/changelog-tenant.xml
index 2085cf5fbf4..40e78b8d06e 100644
--- a/fineract-provider/src/main/resources/db/changelog/tenant/changelog-tenant.xml
+++ b/fineract-provider/src/main/resources/db/changelog/tenant/changelog-tenant.xml
@@ -154,4 +154,6 @@
+
+
diff --git a/fineract-provider/src/main/resources/db/changelog/tenant/parts/0135_add_external_event_for_loan_reaging.xml b/fineract-provider/src/main/resources/db/changelog/tenant/parts/0135_add_external_event_for_loan_reaging.xml
new file mode 100644
index 00000000000..b501842a3df
--- /dev/null
+++ b/fineract-provider/src/main/resources/db/changelog/tenant/parts/0135_add_external_event_for_loan_reaging.xml
@@ -0,0 +1,37 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/fineract-provider/src/main/resources/db/changelog/tenant/parts/0136_loan_reaging_parameters.xml b/fineract-provider/src/main/resources/db/changelog/tenant/parts/0136_loan_reaging_parameters.xml
new file mode 100644
index 00000000000..5539fee9448
--- /dev/null
+++ b/fineract-provider/src/main/resources/db/changelog/tenant/parts/0136_loan_reaging_parameters.xml
@@ -0,0 +1,74 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/fineract-provider/src/test/java/org/apache/fineract/infrastructure/event/external/service/ExternalEventConfigurationValidationServiceTest.java b/fineract-provider/src/test/java/org/apache/fineract/infrastructure/event/external/service/ExternalEventConfigurationValidationServiceTest.java
index 69b69d9db52..76e22563240 100644
--- a/fineract-provider/src/test/java/org/apache/fineract/infrastructure/event/external/service/ExternalEventConfigurationValidationServiceTest.java
+++ b/fineract-provider/src/test/java/org/apache/fineract/infrastructure/event/external/service/ExternalEventConfigurationValidationServiceTest.java
@@ -98,7 +98,8 @@ public void givenAllConfigurationWhenValidatedThenValidationSuccessful() throws
"LoanChargeOffPostBusinessEvent", "LoanUndoChargeOffBusinessEvent", "LoanAccrualTransactionCreatedBusinessEvent",
"LoanRescheduledDueAdjustScheduleBusinessEvent", "LoanOwnershipTransferBusinessEvent", "LoanAccountSnapshotBusinessEvent",
"LoanTransactionDownPaymentPostBusinessEvent", "LoanTransactionDownPaymentPreBusinessEvent",
- "LoanAccountDelinquencyPauseChangedBusinessEvent", "LoanAccountCustomSnapshotBusinessEvent");
+ "LoanAccountDelinquencyPauseChangedBusinessEvent", "LoanAccountCustomSnapshotBusinessEvent",
+ "LoanReAgeTransactionBusinessEvent", "LoanUndoReAgeTransactionBusinessEvent");
List tenants = Arrays
.asList(new FineractPlatformTenant(1L, "default", "Default Tenant", "Europe/Budapest", null));
@@ -178,7 +179,8 @@ public void givenMissingEventConfigurationWhenValidatedThenThrowException() thro
"LoanUndoChargeOffBusinessEvent", "LoanAccrualTransactionCreatedBusinessEvent",
"LoanRescheduledDueAdjustScheduleBusinessEvent", "LoanOwnershipTransferBusinessEvent", "LoanAccountSnapshotBusinessEvent",
"LoanTransactionDownPaymentPostBusinessEvent", "LoanTransactionDownPaymentPreBusinessEvent",
- "LoanAccountDelinquencyPauseChangedBusinessEvent", "LoanAccountCustomSnapshotBusinessEvent");
+ "LoanAccountDelinquencyPauseChangedBusinessEvent", "LoanAccountCustomSnapshotBusinessEvent",
+ "LoanReAgeTransactionBusinessEvent", "LoanUndoReAgeTransactionBusinessEvent");
List tenants = Arrays
.asList(new FineractPlatformTenant(1L, "default", "Default Tenant", "Europe/Budapest", null));
diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/BaseLoanIntegrationTest.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/BaseLoanIntegrationTest.java
index 7907515280b..375fdc2c6f1 100644
--- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/BaseLoanIntegrationTest.java
+++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/BaseLoanIntegrationTest.java
@@ -40,6 +40,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Objects;
+import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
@@ -54,6 +55,7 @@
import org.apache.fineract.client.models.GetJournalEntriesTransactionIdResponse;
import org.apache.fineract.client.models.GetLoansLoanIdRepaymentPeriod;
import org.apache.fineract.client.models.GetLoansLoanIdResponse;
+import org.apache.fineract.client.models.GetLoansLoanIdTransactions;
import org.apache.fineract.client.models.PaymentAllocationOrder;
import org.apache.fineract.client.models.PostChargesResponse;
import org.apache.fineract.client.models.PostLoanProductsRequest;
@@ -317,10 +319,18 @@ protected void verifyTransactions(Long loanId, Transaction... transactions) {
} else {
Assertions.assertEquals(transactions.length, loanDetails.getTransactions().size());
Arrays.stream(transactions).forEach(tr -> {
- boolean found = loanDetails.getTransactions().stream()
- .anyMatch(item -> Objects.equals(item.getAmount(), tr.amount) && Objects.equals(item.getType().getValue(), tr.type)
- && Objects.equals(item.getDate(), LocalDate.parse(tr.date, dateTimeFormatter)));
- Assertions.assertTrue(found, "Required transaction not found: " + tr);
+ Optional optTx = loanDetails.getTransactions().stream()
+ .filter(item -> Objects.equals(item.getAmount(), tr.amount) //
+ && Objects.equals(item.getType().getValue(), tr.type) //
+ && Objects.equals(item.getDate(), LocalDate.parse(tr.date, dateTimeFormatter)))
+ .findFirst();
+ Assertions.assertTrue(optTx.isPresent(), "Required transaction not found: " + tr);
+
+ GetLoansLoanIdTransactions tx = optTx.get();
+
+ if (tr.reversed != null) {
+ Assertions.assertEquals(tr.reversed, tx.getManuallyReversed(), "Transaction is not reversed: " + tr);
+ }
});
}
}
@@ -355,6 +365,20 @@ protected void executeInlineCOB(Long loanId) {
inlineLoanCOBHelper.executeInlineCOB(List.of(loanId));
}
+ protected void reAgeLoan(Long loanId, String frequency, String startDate, Integer numberOfInstallments) {
+ PostLoansLoanIdTransactionsRequest request = new PostLoansLoanIdTransactionsRequest();
+ request.setDateFormat(DATETIME_PATTERN);
+ request.setLocale("en");
+ request.setFrequency(frequency);
+ request.setStartDate(startDate);
+ request.setNumberOfInstallments(numberOfInstallments);
+ loanTransactionHelper.reAge(loanId, request);
+ }
+
+ protected void undoReAgeLoan(Long loanId) {
+ loanTransactionHelper.undoReAge(loanId, new PostLoansLoanIdTransactionsRequest());
+ }
+
protected void verifyLastClosedBusinessDate(Long loanId, String lastClosedBusinessDate) {
GetLoansLoanIdResponse loanDetails = loanTransactionHelper.getLoanDetails(loanId);
Assertions.assertNotNull(loanDetails.getLastClosedBusinessDate());
@@ -554,7 +578,11 @@ protected Journal journalEntry(double principalAmount, Account account, String t
}
protected Transaction transaction(double principalAmount, String type, String date) {
- return new Transaction(principalAmount, type, date);
+ return new Transaction(principalAmount, type, date, null);
+ }
+
+ protected Transaction reversedTransaction(double principalAmount, String type, String date) {
+ return new Transaction(principalAmount, type, date, true);
}
protected TransactionExt transaction(double amount, String type, String date, double outstandingAmount, double principalPortion,
@@ -657,6 +685,7 @@ public static class Transaction {
Double amount;
String type;
String date;
+ Boolean reversed;
}
@ToString
@@ -711,6 +740,7 @@ public static class InterestType {
public static class RepaymentFrequencyType {
public static final Integer MONTHS = 2;
+ public static final String MONTHS_STRING = "MONTHS";
}
public static class InterestCalculationPeriodType {
diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/ExternalEventConfigurationHelper.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/ExternalEventConfigurationHelper.java
index 42c5e1dd311..2b8b9e1aa2b 100644
--- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/ExternalEventConfigurationHelper.java
+++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/ExternalEventConfigurationHelper.java
@@ -500,6 +500,16 @@ public static ArrayList