You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by GitBox <gi...@apache.org> on 2020/09/29 03:31:11 UTC

[GitHub] [fineract] ptuomola commented on a change in pull request #1251: FINERACT-1095 Added status parameter in Loans API

ptuomola commented on a change in pull request #1251:
URL: https://github.com/apache/fineract/pull/1251#discussion_r496357195



##########
File path: fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanStatus.java
##########
@@ -80,6 +82,42 @@ public static LoanStatus fromInt(final Integer statusValue) {
         return enumeration;
     }
 
+    public static LoanStatus fromString(final String statusString) {
+
+        LoanStatus enumeration = LoanStatus.INVALID;
+
+        if (StringUtils.isEmpty(statusString)) {
+            return enumeration;
+        }
+
+        if (statusString.equalsIgnoreCase(LoanStatus.SUBMITTED_AND_PENDING_APPROVAL.toString())) {

Review comment:
       Just another point: given this validation seems to be a common pattern in the enums, I've added a method in the DataValidatorBuilder (isOneOfEnumValues()) to check if the value provided is valid for a specific enum (and report back with correct PlatformApiDataException if it isn't).
   
   So one way to handle these is in the validation phase check the values using that, after which it should be safe to use valueOf() without getting an exception. 
   
   So as far as I can see there are three ways to do the same thing:
   
   - custom valueOf method with error handling to avoid an exception (as currently in many places in the code), and then check for invalid status afterwards - i.e. the current logic in this PR
   
   - call valueOf and catch the exception if the value is invalid, and rethrow as PlatformApiDataException
   
   - call DataValidatorBuilder.isOneOfEnumValues() to validate and then valueOf to convert
   
   Not sure there's a significant advantage of one way over another...
   
   
   
   




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org