Skip to content

Commit

Permalink
move dryTransition to validation
Browse files Browse the repository at this point in the history
  • Loading branch information
kjozsa committed Jun 19, 2024
1 parent e75da79 commit 37ddc6c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@
import org.apache.fineract.portfolio.loanaccount.domain.LoanOfficerAssignmentHistory;
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepaymentScheduleInstallment;
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepositoryWrapper;
import org.apache.fineract.portfolio.loanaccount.domain.LoanStatus;
import org.apache.fineract.portfolio.loanaccount.domain.LoanTermVariationType;
import org.apache.fineract.portfolio.loanaccount.domain.LoanTermVariations;
import org.apache.fineract.portfolio.loanaccount.domain.transactionprocessor.LoanRepaymentScheduleTransactionProcessor;
Expand Down Expand Up @@ -1386,11 +1385,6 @@ public Pair<Loan, Map<String, Object>> assembleLoanApproval(AppUser currentUser,
final JsonArray disbursementDataArray = command.arrayOfParameterNamed(LoanApiConstants.disbursementDataParameterName);
final Loan loan = this.loanRepositoryWrapper.findOneWithNotFoundDetection(loanId, true);

final LoanStatus newStatus = defaultLoanLifecycleStateMachine.dryTransition(LoanEvent.LOAN_APPROVED, loan);
if (newStatus.hasStateOf(loan.getStatus())) {
return Pair.of(loan, Map.of()); // no status change happened
}

final Map<String, Object> actualChanges = new HashMap<>();
defaultLoanLifecycleStateMachine.transition(LoanEvent.LOAN_APPROVED, loan);
actualChanges.put(PARAM_STATUS, LoanEnumerations.status(loan.getStatus()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
import org.apache.fineract.portfolio.loanaccount.api.LoanApiConstants;
import org.apache.fineract.portfolio.loanaccount.domain.Loan;
import org.apache.fineract.portfolio.loanaccount.domain.LoanCollateralManagement;
import org.apache.fineract.portfolio.loanaccount.domain.LoanEvent;
import org.apache.fineract.portfolio.loanaccount.domain.LoanLifecycleStateMachine;
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepaymentScheduleTransactionProcessorFactory;
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepositoryWrapper;
Expand Down Expand Up @@ -2047,6 +2048,13 @@ public void validateApproval(JsonCommand command, Long loanId) {
throw new InvalidLoanStateTransitionException("approval", "cannot.be.a.future.date", errorMessage, approvedOnDate);
}

final LoanStatus newStatus = defaultLoanLifecycleStateMachine.dryTransition(LoanEvent.LOAN_APPROVED, loan);
if (newStatus.hasStateOf(loan.getStatus())) {
final String defaultUserMessage = "Loan is already approved.";
final ApiParameterError error = ApiParameterError
.generalError("error.msg.loan.approve.account.is.not.submitted.and.pending.state", defaultUserMessage);
baseDataValidator.getDataValidationErrors().add(error);
}
}); // end validation
}

Expand Down

0 comments on commit 37ddc6c

Please sign in to comment.