galovics commented on code in PR #2394:
URL: https://github.com/apache/fineract/pull/2394#discussion_r911685115


##########
fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanRepository.java:
##########
@@ -161,4 +163,7 @@ List<Loan> 
findByGroupOfficeIdsAndLoanStatus(@Param("officeIds") Collection<Long
     @Query(FIND_BY_ACCOUNT_NUMBER)
     Loan findLoanAccountByAccountNumber(@Param("accountNumber") String 
accountNumber);
 
+    @Query(DOES_EXISTS_LOAN_WITH_EXTERNAL_ID)
+    boolean validateIfExistLoanWithExternalId(@Param("externalId") String 
externalId);

Review Comment:
   1. validate is not really a good choice of name because the method is not 
validating anything, rather it decides whether a loan exists with externalId.
   2. No need for a custom query. Spring Data JPA supports the `exists` keyword 
so you can simply name the method like `existsByExternalId` and magically it 
should work.



##########
fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanRepositoryWrapper.java:
##########
@@ -240,6 +240,10 @@ public Loan 
findNonClosedLoanByAccountNumber(@Param("accountNumber") String acco
         return this.repository.findNonClosedLoanByAccountNumber(accountNumber);
     }
 
+    public boolean validateIfExistLoanWithExternalId(@Param("externalId") 
String externalId) {

Review Comment:
   Same, method naming is a tiny bit confusing.
   Bonus: why do we have the `@Param` annotation here? It just doesn't make any 
sense to me. Could you explain?



##########
fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanApplicationWritePlatformServiceJpaRepositoryImpl.java:
##########
@@ -303,6 +303,13 @@ public CommandProcessingResult submitApplication(final 
JsonCommand command) {
 
             this.fromApiJsonDeserializer.validateForCreate(command.json(), 
isMeetingMandatoryForJLGLoans, loanProduct);
 
+            // Validate If the externalId is already registered
+            final String externalId = 
this.fromJsonHelper.extractStringNamed("externalId", command.parsedJson());
+            if (StringUtils.isNotBlank(externalId) && 
this.loanRepositoryWrapper.validateIfExistLoanWithExternalId(externalId)) {

Review Comment:
   Let's not call a repository method within an if condition, it's just really 
hard to do debugging on it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to