This is an automated email from the ASF dual-hosted git repository.

adamsaghy pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract.git


The following commit(s) were added to refs/heads/develop by this push:
     new e5a23406ca FINERACT-2080: Extract accountNumberRequiresAutoGeneration 
from loan entity
e5a23406ca is described below

commit e5a23406ca5e79c6efa3c1810567a932de11530f
Author: Oleksii Novikov <[email protected]>
AuthorDate: Wed Apr 23 12:32:23 2025 +0300

    FINERACT-2080: Extract accountNumberRequiresAutoGeneration from loan entity
---
 .../portfolio/loanaccount/domain/Loan.java         |  10 --
 ...ationWritePlatformServiceJpaRepositoryImpl.java |   1 -
 .../loanaccount/service/LoanAssemblerImpl.java     | 124 +++++++++++----------
 3 files changed, 64 insertions(+), 71 deletions(-)

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 fe77571ca0..b7c31293e0 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
@@ -35,7 +35,6 @@ import jakarta.persistence.OneToMany;
 import jakarta.persistence.OneToOne;
 import jakarta.persistence.OrderBy;
 import jakarta.persistence.Table;
-import jakarta.persistence.Transient;
 import jakarta.persistence.UniqueConstraint;
 import jakarta.persistence.Version;
 import jakarta.validation.constraints.NotNull;
@@ -322,9 +321,6 @@ public class Loan extends 
AbstractAuditableWithUTCDateTimeCustom<Long> {
     @Embedded
     private LoanSummary summary;
 
-    @Transient
-    private boolean accountNumberRequiresAutoGeneration;
-
     @Setter()
     @Column(name = "principal_amount_proposed", scale = 6, precision = 19, 
nullable = false)
     private BigDecimal proposedPrincipal;
@@ -506,7 +502,6 @@ public class Loan extends 
AbstractAuditableWithUTCDateTimeCustom<Long> {
 
         if (StringUtils.isBlank(accountNo)) {
             this.accountNumber = new RandomPasswordGenerator(19).generate();
-            this.accountNumberRequiresAutoGeneration = true;
         } else {
             this.accountNumber = accountNo;
         }
@@ -841,11 +836,6 @@ public class Loan extends 
AbstractAuditableWithUTCDateTimeCustom<Long> {
         this.loanProduct = loanProduct;
     }
 
-    public void updateAccountNo(final String newAccountNo) {
-        this.accountNumber = newAccountNo;
-        this.accountNumberRequiresAutoGeneration = false;
-    }
-
     public void updateFund(final Fund fund) {
         this.fund = fund;
     }
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanApplicationWritePlatformServiceJpaRepositoryImpl.java
 
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanApplicationWritePlatformServiceJpaRepositoryImpl.java
index e902b10fea..cbd6c829c5 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanApplicationWritePlatformServiceJpaRepositoryImpl.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanApplicationWritePlatformServiceJpaRepositoryImpl.java
@@ -131,7 +131,6 @@ public class 
LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa
     @Transactional
     @Override
     public CommandProcessingResult submitApplication(final JsonCommand 
command) {
-
         try {
             // Validations (prior assembling)
             this.loanApplicationValidator.validateForCreate(command);
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanAssemblerImpl.java
 
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanAssemblerImpl.java
index 73ad304f5a..6ef88ae977 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanAssemblerImpl.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanAssemblerImpl.java
@@ -292,76 +292,80 @@ public class LoanAssemblerImpl implements LoanAssembler {
     // TODO: Review... it might be better somewhere else and rethink due to 
the account number generation logic is
     // intertwined with GLIM logic
     @Override
-    public void accountNumberGeneration(JsonCommand command, Loan loan) {
-        if (loan.isAccountNumberRequiresAutoGeneration()) {
-            JsonElement element = command.parsedJson();
-            final AccountNumberFormat accountNumberFormat = 
this.accountNumberFormatRepository.findByAccountType(EntityAccountType.LOAN);
-            // TODO: It is really weird to set GLIM info only if account 
number was not provided
-            // if application is of GLIM type
-            if (loan.getLoanType().isGLIMAccount()) {
-                Group group = loan.getGroup();
-                String accountNumber = "";
-                BigDecimal applicationId = BigDecimal.ZERO;
-                Boolean isLastChildApplication = false;
-                // GLIM specific parameters
-                final Locale locale = 
this.fromApiJsonHelper.extractLocaleParameter(element.getAsJsonObject());
-                BigDecimal applicationIdFromParam = 
this.fromApiJsonHelper.extractBigDecimalNamed("applicationId", element, locale);
-                BigDecimal totalLoan = 
this.fromApiJsonHelper.extractBigDecimalNamed("totalLoan", element, locale);
-                if (applicationIdFromParam != null) {
-                    applicationId = applicationIdFromParam;
-                }
+    public void accountNumberGeneration(final JsonCommand command, final Loan 
loan) {
+        final JsonElement element = command.parsedJson();
 
-                Boolean isLastChildApplicationFromParam = 
this.fromApiJsonHelper.extractBooleanNamed("lastApplication", element);
-                if (isLastChildApplicationFromParam != null) {
-                    isLastChildApplication = isLastChildApplicationFromParam;
-                }
+        final String accountNo = 
this.fromApiJsonHelper.extractStringNamed("accountNo", element);
+        final boolean isAccountNumberRequiresAutoGeneration = 
StringUtils.isBlank(accountNo);
+        if (!isAccountNumberRequiresAutoGeneration) {
+            return;
+        }
+
+        final AccountNumberFormat accountNumberFormat = 
this.accountNumberFormatRepository.findByAccountType(EntityAccountType.LOAN);
+        // TODO: It is really weird to set GLIM info only if account number 
was not provided
+        // if application is of GLIM type
+        if (loan.getLoanType().isGLIMAccount()) {
+            Group group = loan.getGroup();
+            String accountNumber;
+            BigDecimal applicationId = BigDecimal.ZERO;
+            // GLIM specific parameters
+            final Locale locale = 
this.fromApiJsonHelper.extractLocaleParameter(element.getAsJsonObject());
+            BigDecimal applicationIdFromParam = 
this.fromApiJsonHelper.extractBigDecimalNamed("applicationId", element, locale);
+            BigDecimal totalLoan = 
this.fromApiJsonHelper.extractBigDecimalNamed("totalLoan", element, locale);
+            if (applicationIdFromParam != null) {
+                applicationId = applicationIdFromParam;
+            }
 
-                if 
(this.fromApiJsonHelper.extractBooleanNamed("isParentAccount", element) != 
null) {
-                    // empty table check
-                    // TODO: This count here is weird... and seems 
parent-empty and parent not empty looks the same
-                    if (glimRepository.count() != 0) {
-                        // **************Parent-Not an empty
-                        // table********************
-                        createAndSetGLIMAccount(totalLoan, loan, 
accountNumberFormat, group, applicationId);
-                    } else {
-                        // ************** Parent-empty
-                        // table********************
-                        createAndSetGLIMAccount(totalLoan, loan, 
accountNumberFormat, group, applicationId);
-                    }
+            Boolean isLastChildApplicationFromParam = 
this.fromApiJsonHelper.extractBooleanNamed("lastApplication", element);
+            boolean isLastChildApplication = false;
+            if (isLastChildApplicationFromParam != null) {
+                isLastChildApplication = isLastChildApplicationFromParam;
+            }
+
+            if (this.fromApiJsonHelper.extractBooleanNamed("isParentAccount", 
element) != null) {
+                // empty table check
+                // TODO: This count here is weird... and seems parent-empty 
and parent not empty looks the same
+                if (glimRepository.count() != 0) {
+                    // **************Parent-Not an empty
+                    // table********************
+                    createAndSetGLIMAccount(totalLoan, loan, 
accountNumberFormat, group, applicationId);
                 } else {
-                    // TODO: This count here is weird...
-                    if (glimRepository.count() != 0) {
-                        // Child-Not an empty table
-                        GroupLoanIndividualMonitoringAccount glimAccount = 
glimRepository.findOneByIsAcceptingChildAndApplicationId(true,
-                                applicationId);
-                        accountNumber = glimAccount.getAccountNumber() + 
(glimAccount.getChildAccountsCount() + 1);
-                        loan.updateAccountNo(accountNumber);
-                        
this.glimAccountInfoWritePlatformService.incrementChildAccountCount(glimAccount);
-                        loan.setGlim(glimAccount);
-                    } else {
-                        // **************Child-empty
-                        // table********************
-                        // if the glim info is empty set the current account
-                        // as parent
-                        createAndSetGLIMAccount(totalLoan, loan, 
accountNumberFormat, group, applicationId);
-                    }
-                    // reset in cases of last child application of glim
-                    if (isLastChildApplication) {
-                        this.glimAccountInfoWritePlatformService
-                                
.resetIsAcceptingChild(glimRepository.findOneByIsAcceptingChildAndApplicationId(true,
 applicationId));
-                    }
+                    // ************** Parent-empty
+                    // table********************
+                    createAndSetGLIMAccount(totalLoan, loan, 
accountNumberFormat, group, applicationId);
+                }
+            } else {
+                // TODO: This count here is weird...
+                if (glimRepository.count() != 0) {
+                    // Child-Not an empty table
+                    GroupLoanIndividualMonitoringAccount glimAccount = 
glimRepository.findOneByIsAcceptingChildAndApplicationId(true,
+                            applicationId);
+                    accountNumber = glimAccount.getAccountNumber() + 
(glimAccount.getChildAccountsCount() + 1);
+                    loan.setAccountNumber(accountNumber);
+                    
this.glimAccountInfoWritePlatformService.incrementChildAccountCount(glimAccount);
+                    loan.setGlim(glimAccount);
+                } else {
+                    // **************Child-empty
+                    // table********************
+                    // if the glim info is empty set the current account
+                    // as parent
+                    createAndSetGLIMAccount(totalLoan, loan, 
accountNumberFormat, group, applicationId);
+                }
+                // reset in cases of last child application of glim
+                if (isLastChildApplication) {
+                    this.glimAccountInfoWritePlatformService
+                            
.resetIsAcceptingChild(glimRepository.findOneByIsAcceptingChildAndApplicationId(true,
 applicationId));
                 }
-            } else { // for applications other than GLIM
-                
loan.updateAccountNo(this.accountNumberGenerator.generate(loan, 
accountNumberFormat));
             }
+        } else { // for applications other than GLIM
+            loan.setAccountNumber(this.accountNumberGenerator.generate(loan, 
accountNumberFormat));
         }
     }
 
     private void createAndSetGLIMAccount(BigDecimal totalLoan, Loan loan, 
AccountNumberFormat accountNumberFormat, Group group,
             BigDecimal applicationId) {
-        String accountNumber;
-        accountNumber = this.accountNumberGenerator.generate(loan, 
accountNumberFormat);
-        loan.updateAccountNo(accountNumber + "1");
+        final String accountNumber = 
this.accountNumberGenerator.generate(loan, accountNumberFormat);
+        loan.setAccountNumber(accountNumber + "1");
         GroupLoanIndividualMonitoringAccount glimAccount = 
glimAccountInfoWritePlatformService.createGLIMAccount(accountNumber, group,
                 totalLoan, 1L, true, 
LoanStatus.SUBMITTED_AND_PENDING_APPROVAL.getValue(), applicationId);
         loan.setGlim(glimAccount);

Reply via email to