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 2022/03/30 20:42:54 UTC

[GitHub] [fineract] josehernandezfintecheandomx opened a new pull request #2224: Enhancement for new fields in APIs

josehernandezfintecheandomx opened a new pull request #2224:
URL: https://github.com/apache/fineract/pull/2224


   ## Description
   
   PERF-226
   PERF-227
   PERF-228
   
   Ignore if these details are present on the associated [Apache Fineract JIRA ticket](https://github.com/apache/fineract/pull/1284).
   
   ## Checklist
   
   Please make sure these boxes are checked before submitting your pull request - thanks!
   
   - [ ] Write the commit message as per https://github.com/apache/fineract/#pull-requests
   
   - [ ] Acknowledge that we will not review PRs that are not passing the build _("green")_ - it is your responsibility to get a proposed PR to pass the build, not primarily the project's maintainers.
   
   - [ ] Create/update unit or integration tests for verifying the changes made.
   
   - [ ] Follow coding conventions at https://cwiki.apache.org/confluence/display/FINERACT/Coding+Conventions.
   
   - [ ] Add required Swagger annotation and update API documentation at fineract-provider/src/main/resources/static/api-docs/apiLive.htm with details of any API changes
   
   - [ ] Submission is not a "code dump".  (Large changes can be made "in repository" via a branch.  Ask on the developer mailing list for guidance, if required.)
   
   FYI our guidelines for code reviews are at https://cwiki.apache.org/confluence/display/FINERACT/Code+Review+Guide.
   


-- 
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: commits-unsubscribe@fineract.apache.org

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



[GitHub] [fineract] vidakovic commented on a change in pull request #2224: Enhancement for new fields in APIs

Posted by GitBox <gi...@apache.org>.
vidakovic commented on a change in pull request #2224:
URL: https://github.com/apache/fineract/pull/2224#discussion_r839038633



##########
File path: fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/data/CollectionData.java
##########
@@ -0,0 +1,90 @@
+/**
+ * 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.data;
+
+import java.math.BigDecimal;
+import java.time.LocalDate;
+
+public class CollectionData {

Review comment:
       Please declare this class "final" to make Checkstyle happy. After that I think it's good to go.




-- 
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: commits-unsubscribe@fineract.apache.org

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



[GitHub] [fineract] josehernandezfintecheandomx closed pull request #2224: Enhancement for new fields in APIs

Posted by GitBox <gi...@apache.org>.
josehernandezfintecheandomx closed pull request #2224:
URL: https://github.com/apache/fineract/pull/2224


   


-- 
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: commits-unsubscribe@fineract.apache.org

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



[GitHub] [fineract] galovics commented on a change in pull request #2224: Enhancement for new fields in APIs

Posted by GitBox <gi...@apache.org>.
galovics commented on a change in pull request #2224:
URL: https://github.com/apache/fineract/pull/2224#discussion_r839263063



##########
File path: fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/service/ReadWriteNonCoreDataServiceImpl.java
##########
@@ -340,6 +340,17 @@ private boolean isSurveyCategory(final Integer category) {
         return category.equals(DataTableApiConstant.CATEGORY_PPI);
     }
 
+    private JsonElement addColumn(final String name, final String dataType, final boolean isMandatory, final Integer length) {

Review comment:
       Do you think we could call this method "newColumn" or something instead since it's not really adding a new column anywhere but returns just part of a JsonObject?
   
   I feel it's a little weird when I read the code below
   `columns.add(addColumn("created_at", "DateTime", false, null));`

##########
File path: fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanReadPlatformServiceImpl.java
##########
@@ -2358,4 +2359,56 @@ public Integer retrieveNumberOfActiveLoans() {
         final String sql = "select count(*) from m_loan";
         return this.jdbcTemplate.queryForObject(sql, Integer.class);
     }
+
+    @Override
+    public CollectionData retrieveLoanCollectionData(Long loanId) {
+        final CollectionDataMapper mapper = new CollectionDataMapper(sqlGenerator);
+        String sql = "select " + mapper.schema();
+        CollectionData collectionData = this.jdbcTemplate.queryForObject(sql, mapper, new Object[] { loanId });
+        return collectionData;
+    }
+
+    private static final class CollectionDataMapper implements RowMapper<CollectionData> {
+
+        private final DatabaseSpecificSQLGenerator sqlGenerator;
+
+        CollectionDataMapper(DatabaseSpecificSQLGenerator sqlGenerator) {
+            this.sqlGenerator = sqlGenerator;
+        }
+
+        public String schema() {
+            StringBuilder sqlBuilder = new StringBuilder();
+
+            sqlBuilder.append(
+                    "l.id as loanId, coalesce((l.approved_principal - l.principal_disbursed_derived), 0) as availableDisbursementAmount, ");
+            sqlBuilder.append("datediff(" + sqlGenerator.currentDate() + ", laa.overdue_since_date_derived) as pastDueDays, ");

Review comment:
       datediff is going to fail here on PostgreSQL. Please check the DatabaseSpecificSQLGenerator class, there's a corresponding method there which generates the proper statements for both MySQL and PG.

##########
File path: fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanReadPlatformServiceImpl.java
##########
@@ -2358,4 +2359,56 @@ public Integer retrieveNumberOfActiveLoans() {
         final String sql = "select count(*) from m_loan";
         return this.jdbcTemplate.queryForObject(sql, Integer.class);
     }
+
+    @Override
+    public CollectionData retrieveLoanCollectionData(Long loanId) {
+        final CollectionDataMapper mapper = new CollectionDataMapper(sqlGenerator);
+        String sql = "select " + mapper.schema();
+        CollectionData collectionData = this.jdbcTemplate.queryForObject(sql, mapper, new Object[] { loanId });
+        return collectionData;
+    }
+
+    private static final class CollectionDataMapper implements RowMapper<CollectionData> {
+
+        private final DatabaseSpecificSQLGenerator sqlGenerator;
+
+        CollectionDataMapper(DatabaseSpecificSQLGenerator sqlGenerator) {
+            this.sqlGenerator = sqlGenerator;
+        }
+
+        public String schema() {
+            StringBuilder sqlBuilder = new StringBuilder();
+
+            sqlBuilder.append(
+                    "l.id as loanId, coalesce((l.approved_principal - l.principal_disbursed_derived), 0) as availableDisbursementAmount, ");
+            sqlBuilder.append("datediff(" + sqlGenerator.currentDate() + ", laa.overdue_since_date_derived) as pastDueDays, ");
+            sqlBuilder.append(
+                    "(select coalesce(min(lrs.duedate), null) as duedate from m_loan_repayment_schedule lrs where lrs.loan_id=1 and lrs.completed_derived is false and lrs.duedate >= "

Review comment:
       you sure about the `lrs.loan_id=1` condition? I'm not sure it's intentional to fix a single loan_id in the query.

##########
File path: fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanReadPlatformServiceImpl.java
##########
@@ -2358,4 +2359,56 @@ public Integer retrieveNumberOfActiveLoans() {
         final String sql = "select count(*) from m_loan";
         return this.jdbcTemplate.queryForObject(sql, Integer.class);
     }
+
+    @Override
+    public CollectionData retrieveLoanCollectionData(Long loanId) {
+        final CollectionDataMapper mapper = new CollectionDataMapper(sqlGenerator);
+        String sql = "select " + mapper.schema();
+        CollectionData collectionData = this.jdbcTemplate.queryForObject(sql, mapper, new Object[] { loanId });
+        return collectionData;
+    }
+
+    private static final class CollectionDataMapper implements RowMapper<CollectionData> {
+
+        private final DatabaseSpecificSQLGenerator sqlGenerator;
+
+        CollectionDataMapper(DatabaseSpecificSQLGenerator sqlGenerator) {
+            this.sqlGenerator = sqlGenerator;
+        }
+
+        public String schema() {
+            StringBuilder sqlBuilder = new StringBuilder();
+
+            sqlBuilder.append(
+                    "l.id as loanId, coalesce((l.approved_principal - l.principal_disbursed_derived), 0) as availableDisbursementAmount, ");
+            sqlBuilder.append("datediff(" + sqlGenerator.currentDate() + ", laa.overdue_since_date_derived) as pastDueDays, ");
+            sqlBuilder.append(
+                    "(select coalesce(min(lrs.duedate), null) as duedate from m_loan_repayment_schedule lrs where lrs.loan_id=1 and lrs.completed_derived is false and lrs.duedate >= "
+                            + sqlGenerator.currentDate() + ") as nextPaymentDueDate, ");
+            sqlBuilder.append("datediff(" + sqlGenerator.currentDate() + ", laa.overdue_since_date_derived) as delinquentDays, ");

Review comment:
       Same datediff problem here.

##########
File path: fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/api/LoansApiResource.java
##########
@@ -639,6 +640,12 @@ public String retrieveLoan(@PathParam("loanId") @Parameter(description = "loanId
                 linkedAccount = this.accountAssociationsReadPlatformService.retriveLoanLinkedAssociation(loanId);
             }
 
+            if (associationParameters.contains("collection")) {

Review comment:
       I know the existing codebase doesn't really use constants but rather hardcoded values; can we make sure to extract the "collection" magic string to somewhere and just reference it? 
   Would be a shame if in the future some functionality breaks because we change it here but not the other place(s).

##########
File path: fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanReadPlatformServiceImpl.java
##########
@@ -2358,4 +2359,56 @@ public Integer retrieveNumberOfActiveLoans() {
         final String sql = "select count(*) from m_loan";
         return this.jdbcTemplate.queryForObject(sql, Integer.class);
     }
+
+    @Override
+    public CollectionData retrieveLoanCollectionData(Long loanId) {
+        final CollectionDataMapper mapper = new CollectionDataMapper(sqlGenerator);
+        String sql = "select " + mapper.schema();
+        CollectionData collectionData = this.jdbcTemplate.queryForObject(sql, mapper, new Object[] { loanId });
+        return collectionData;
+    }
+
+    private static final class CollectionDataMapper implements RowMapper<CollectionData> {
+
+        private final DatabaseSpecificSQLGenerator sqlGenerator;
+
+        CollectionDataMapper(DatabaseSpecificSQLGenerator sqlGenerator) {
+            this.sqlGenerator = sqlGenerator;
+        }
+
+        public String schema() {
+            StringBuilder sqlBuilder = new StringBuilder();
+
+            sqlBuilder.append(
+                    "l.id as loanId, coalesce((l.approved_principal - l.principal_disbursed_derived), 0) as availableDisbursementAmount, ");
+            sqlBuilder.append("datediff(" + sqlGenerator.currentDate() + ", laa.overdue_since_date_derived) as pastDueDays, ");
+            sqlBuilder.append(
+                    "(select coalesce(min(lrs.duedate), null) as duedate from m_loan_repayment_schedule lrs where lrs.loan_id=1 and lrs.completed_derived is false and lrs.duedate >= "
+                            + sqlGenerator.currentDate() + ") as nextPaymentDueDate, ");
+            sqlBuilder.append("datediff(" + sqlGenerator.currentDate() + ", laa.overdue_since_date_derived) as delinquentDays, ");
+            sqlBuilder.append(
+                    sqlGenerator.currentDate() + " as delinquentDate, coalesce(laa.total_overdue_derived, 0) as delinquentAmount, ");
+            sqlBuilder.append("lre.transactionDate as lastPaymentDate, coalesce(lre.amount, 0) as lastPaymentAmount ");
+            sqlBuilder.append("from m_loan l inner join m_loan_arrears_aging laa on laa.loan_id = l.id ");
+            sqlBuilder.append(
+                    "left join (select lt.loan_id, lt.transaction_date as transactionDate, lt.amount as amount from m_loan_transaction lt where lt.is_reversed = 0 and lt.transaction_type_enum=2 order by lt.transaction_date desc limit 1) lre on lre.loan_id = l.id ");

Review comment:
       `lt.is_reversed = 0` should be `lt.is_reversed = false` if the mapping is a boolean column. PG won't accept the 0 right-hand side comparison value without explicit casting.




-- 
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: commits-unsubscribe@fineract.apache.org

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