Skip to content

Commit

Permalink
FINERACT-1971: Loan re-aging foundational implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
galovics committed Feb 15, 2024
1 parent 1d2fc73 commit 8d34b19
Show file tree
Hide file tree
Showing 30 changed files with 1,003 additions and 19 deletions.
3 changes: 3 additions & 0 deletions config/spotbugs/exclude.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
<Match>
<Package name="~.*\.domain"/>
</Match>
<Match>
<Package name="~.*\.domain\..*"/>
</Match>
<Match>
<Package name="~.*\.data"/>
</Match>
Expand Down
27 changes: 27 additions & 0 deletions docker-compose-web-app.yml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,19 @@ public boolean isChangeInStringParameterNamed(final String parameterName, final
return isChanged;
}

public <T extends Enum<T>> T enumValueOfParameterNamed(String parameterName, Class<T> 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, "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,9 @@ public void afterPropertiesSet() throws Exception {
@Override
public void notifyPreBusinessEvent(BusinessEvent<?> businessEvent) {
throwExceptionIfBulkEvent(businessEvent);
List<BusinessEventListener> businessEventListeners = preListeners.get(businessEvent.getClass());
if (businessEventListeners != null) {
for (BusinessEventListener eventListener : businessEventListeners) {
eventListener.onBusinessEvent(businessEvent);
}
List<BusinessEventListener> businessEventListeners = findSuitableListeners(preListeners, businessEvent.getClass());
for (BusinessEventListener eventListener : businessEventListeners) {
eventListener.onBusinessEvent(businessEvent);
}
}

Expand All @@ -84,11 +82,9 @@ public <T extends BusinessEvent<?>> void addPreBusinessEventListener(Class<T> ev
public void notifyPostBusinessEvent(BusinessEvent<?> businessEvent) {
throwExceptionIfBulkEvent(businessEvent);
boolean isExternalEvent = !(businessEvent instanceof NoExternalEvent);
List<BusinessEventListener> businessEventListeners = postListeners.get(businessEvent.getClass());
if (businessEventListeners != null) {
for (BusinessEventListener eventListener : businessEventListeners) {
eventListener.onBusinessEvent(businessEvent);
}
List<BusinessEventListener> 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
Expand All @@ -102,6 +98,17 @@ public void notifyPostBusinessEvent(BusinessEvent<?> businessEvent) {
}
}

private List<BusinessEventListener> findSuitableListeners(Map<Class, List<BusinessEventListener>> listeners, Class<?> eventClazz) {
List<BusinessEventListener> result = new ArrayList<>();
for (Map.Entry<Class, List<BusinessEventListener>> entry : listeners.entrySet()) {
Class<?> registeredClazz = entry.getKey();
if (registeredClazz.isAssignableFrom(eventClazz)) {
result.addAll(entry.getValue());
}
}
return result;
}

@Override
public <T extends BusinessEvent<?>> void addPostBusinessEventListener(Class<T> eventType, BusinessEventListener<T> listener) {
List<BusinessEventListener> businessEventListeners = postListeners.get(eventType);
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
};
}
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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() {}
}
Original file line number Diff line number Diff line change
@@ -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<LoanReAgeParameter, Long> {

Optional<LoanReAgeParameter> findByLoanTransactionId(@Param("loanTransactionId") Long loanTransactionId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Loading

0 comments on commit 8d34b19

Please sign in to comment.