Skip to content

Commit

Permalink
FINERACT-1971: Added reamortization foundational work
Browse files Browse the repository at this point in the history
  • Loading branch information
galovics committed Feb 22, 2024
1 parent 051b37c commit 564c983
Show file tree
Hide file tree
Showing 21 changed files with 669 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3672,6 +3672,22 @@ public CommandWrapperBuilder undoReAge(final Long loanId) {
return this;
}

public CommandWrapperBuilder reAmortize(final Long loanId) {
this.actionName = "REAMORTIZE";
this.entityName = "LOAN";
this.loanId = loanId;
this.href = "/loans/" + loanId + "/transactions?command=reAmortize";
return this;
}

public CommandWrapperBuilder undoReAmortize(final Long loanId) {
this.actionName = "UNDO_REAMORTIZE";
this.entityName = "LOAN";
this.loanId = loanId;
this.href = "/loans/" + loanId + "/transactions?command=undoReAmortize";
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
@@ -0,0 +1,26 @@
/**
* 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 LoanReAmortizationApiConstants {

String localeParameterName = "locale";
String dateFormatParameterName = "dateFormat";
String externalIdParameterName = "externalId";
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class LoanTransactionEnumData {
private final boolean chargeoff;
private final boolean downPayment;
private final boolean reAge;
private final boolean reAmortize;

public LoanTransactionEnumData(final Long id, final String code, final String value) {
this.id = id;
Expand Down Expand Up @@ -88,6 +89,7 @@ public LoanTransactionEnumData(final Long id, final String code, final String va
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);
this.reAmortize = Long.valueOf(LoanTransactionType.REAMORTIZE.getValue()).equals(this.id);
}

public boolean isRepaymentType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,10 @@ public boolean isReAge() {
return getTypeOf().isReAge() && isNotReversed();
}

public boolean isReAmortize() {
return getTypeOf().isReAmortize() && 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 @@ -61,7 +61,7 @@ public enum LoanTransactionType {
CHARGE_ADJUSTMENT(26, "loanTransactionType.chargeAdjustment"), //
CHARGE_OFF(27, "loanTransactionType.chargeOff"), //
DOWN_PAYMENT(28, "loanTransactionType.downPayment"), //
REAGE(29, "loanTransactionType.reAge");
REAGE(29, "loanTransactionType.reAge"), REAMORTIZE(30, "loanTransactionType.reAmortize");

private final Integer value;
private final String code;
Expand Down Expand Up @@ -106,6 +106,7 @@ public static LoanTransactionType fromInt(final Integer transactionType) {
case 27 -> LoanTransactionType.CHARGE_OFF;
case 28 -> LoanTransactionType.DOWN_PAYMENT;
case 29 -> LoanTransactionType.REAGE;
case 30 -> LoanTransactionType.REAMORTIZE;
default -> LoanTransactionType.INVALID;
};
}
Expand Down Expand Up @@ -198,6 +199,10 @@ public boolean isReAge() {
return this.equals(LoanTransactionType.REAGE);
}

public boolean isReAmortize() {
return this.equals(LoanTransactionType.REAMORTIZE);
}

public boolean isDownPayment() {
return this.equals(LoanTransactionType.DOWN_PAYMENT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ public static LoanTransactionEnumData transactionType(final LoanTransactionType
LoanTransactionType.DOWN_PAYMENT.getCode(), "Down Payment");
case REAGE -> new LoanTransactionEnumData(LoanTransactionType.REAGE.getValue().longValue(), LoanTransactionType.REAGE.getCode(),
"Re-age");
case REAMORTIZE -> new LoanTransactionEnumData(LoanTransactionType.REAMORTIZE.getValue().longValue(),
LoanTransactionType.REAMORTIZE.getCode(), "Re-amortize");
};
}

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.reamortization;

import org.apache.fineract.infrastructure.event.business.domain.loan.transaction.LoanTransactionBusinessEvent;
import org.apache.fineract.portfolio.loanaccount.domain.LoanTransaction;

public class LoanReAmortizeTransactionBusinessEvent extends LoanTransactionBusinessEvent {

private static final String TYPE = "LoanReAmortizeTransactionBusinessEvent";

public LoanReAmortizeTransactionBusinessEvent(LoanTransaction value) {
super(value);
}

@Override
public String getType() {
return TYPE;
}
}
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.reamortization;

import org.apache.fineract.infrastructure.event.business.domain.loan.transaction.LoanTransactionBusinessEvent;
import org.apache.fineract.portfolio.loanaccount.domain.LoanTransaction;

public class LoanUndoReAmortizeTransactionBusinessEvent extends LoanTransactionBusinessEvent {

private static final String TYPE = "LoanUndoReAmortizeTransactionBusinessEvent";

public LoanUndoReAmortizeTransactionBusinessEvent(LoanTransaction value) {
super(value);
}

@Override
public String getType() {
return TYPE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ public class LoanTransactionsApiResource {
public static final String DOWN_PAYMENT = "downPayment";
public static final String UNDO_REAGE = "undoReAge";
public static final String REAGE = "reAge";
public static final String REAMORTIZE = "reAmortize";
public static final String UNDO_REAMORTIZE = "undoReAmortize";
private final Set<String> responseDataParameters = new HashSet<>(Arrays.asList("id", "type", "date", "currency", "amount", "externalId",
LoanApiConstants.REVERSAL_EXTERNAL_ID_PARAMNAME, LoanApiConstants.REVERSED_ON_DATE_PARAMNAME));

Expand Down Expand Up @@ -483,6 +485,10 @@ private String executeTransaction(final Long loanId, final String loanExternalId
commandRequest = builder.reAge(resolvedLoanId).build();
} else if (CommandParameterUtil.is(commandParam, UNDO_REAGE)) {
commandRequest = builder.undoReAge(resolvedLoanId).build();
} else if (CommandParameterUtil.is(commandParam, REAMORTIZE)) {
commandRequest = builder.reAmortize(resolvedLoanId).build();
} else if (CommandParameterUtil.is(commandParam, UNDO_REAMORTIZE)) {
commandRequest = builder.undoReAmortize(resolvedLoanId).build();
}

if (commandRequest == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.reamortization;

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.reamortization.LoanReAmortizationServiceImpl;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.orm.jpa.JpaSystemException;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
@CommandType(entity = "LOAN", action = "REAMORTIZE")
public class LoanReAmortizationCommandHandler implements NewCommandSourceHandler {

private final LoanReAmortizationServiceImpl loanReAmortizationService;
private final DataIntegrityErrorHandler dataIntegrityErrorHandler;

@Override
public CommandProcessingResult processCommand(JsonCommand command) {
try {
return loanReAmortizationService.reAmortize(command.getLoanId(), command);
} catch (final JpaSystemException | DataIntegrityViolationException dve) {
dataIntegrityErrorHandler.handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve, "loan.reAmortize",
"Error while handling re-amortizing");
return CommandProcessingResult.empty();
}
}
}
Original file line number Diff line number Diff line change
@@ -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.reamortization;

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.reamortization.LoanReAmortizationServiceImpl;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.orm.jpa.JpaSystemException;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
@CommandType(entity = "LOAN", action = "UNDO_REAMORTIZE")
public class LoanUndoReAmortizationCommandHandler implements NewCommandSourceHandler {

private final LoanReAmortizationServiceImpl loanReAmortizationService;
private final DataIntegrityErrorHandler dataIntegrityErrorHandler;

@Override
public CommandProcessingResult processCommand(JsonCommand command) {
try {
return loanReAmortizationService.undoReAmortize(command.getLoanId(), command);
} catch (final JpaSystemException | DataIntegrityViolationException dve) {
dataIntegrityErrorHandler.handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve, "loan.undoReAmortize",
"Error while handling undo re-amortizing");
return CommandProcessingResult.empty();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
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.domain.loan.transaction.reamortization.LoanReAmortizeTransactionBusinessEvent;
import org.apache.fineract.infrastructure.event.business.domain.loan.transaction.reamortization.LoanUndoReAmortizeTransactionBusinessEvent;
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;
Expand All @@ -39,7 +41,9 @@ public class LoanTransactionDelinquencyRecalculationListener
// use-cases
private static final List<Class<? extends LoanTransactionBusinessEvent>> SUPPORTED_EVENT_TYPES = List.of(//
LoanReAgeTransactionBusinessEvent.class, //
LoanUndoReAgeTransactionBusinessEvent.class //
LoanUndoReAgeTransactionBusinessEvent.class, //
LoanReAmortizeTransactionBusinessEvent.class, //
LoanUndoReAmortizeTransactionBusinessEvent.class //
);//

private final LoanAccountDomainService loanAccountDomainService;
Expand Down
Loading

0 comments on commit 564c983

Please sign in to comment.