You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by aw...@apache.org on 2019/09/02 20:43:55 UTC

[fineract-cn-reporting] 10/47: Deposit Listing data rows built, Inactive Account Skeleton: Hopefully completes deposit account listing

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

awasum pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract-cn-reporting.git

commit e75d262a7df98cd866d9bd3e72898b4e7bcbdc89
Author: Awasum Yannick <aw...@skylabase.com>
AuthorDate: Mon Aug 21 16:17:18 2017 +0100

    Deposit Listing data rows built, Inactive Account Skeleton: Hopefully completes deposit account listing
---
 ...InactiveCustomerAccountReportSpecification.java |  24 +++++
 .../SavingListReportSpecification.java             | 100 +++++++++++++++++----
 2 files changed, 107 insertions(+), 17 deletions(-)

diff --git a/service/src/main/java/io/mifos/reporting/service/internal/specification/InactiveCustomerAccountReportSpecification.java b/service/src/main/java/io/mifos/reporting/service/internal/specification/InactiveCustomerAccountReportSpecification.java
new file mode 100644
index 0000000..148743b
--- /dev/null
+++ b/service/src/main/java/io/mifos/reporting/service/internal/specification/InactiveCustomerAccountReportSpecification.java
@@ -0,0 +1,24 @@
+package io.mifos.reporting.service.internal.specification;
+
+import io.mifos.reporting.api.v1.domain.ReportDefinition;
+import io.mifos.reporting.api.v1.domain.ReportPage;
+import io.mifos.reporting.api.v1.domain.ReportRequest;
+import io.mifos.reporting.service.spi.Report;
+import io.mifos.reporting.service.spi.ReportSpecification;
+@Report(category = "Customer", identifier = "Inactive")
+public class InactiveCustomerAccountReportSpecification implements ReportSpecification {
+    @Override
+    public ReportDefinition getReportDefinition() {
+        return null;
+    }
+
+    @Override
+    public ReportPage generateReport(ReportRequest reportRequest, int pageIndex, int size) {
+        return null;
+    }
+
+    @Override
+    public void validate(ReportRequest reportRequest) throws IllegalArgumentException {
+
+    }
+}
diff --git a/service/src/main/java/io/mifos/reporting/service/internal/specification/SavingListReportSpecification.java b/service/src/main/java/io/mifos/reporting/service/internal/specification/SavingListReportSpecification.java
index 8496a04..a5cf74b 100644
--- a/service/src/main/java/io/mifos/reporting/service/internal/specification/SavingListReportSpecification.java
+++ b/service/src/main/java/io/mifos/reporting/service/internal/specification/SavingListReportSpecification.java
@@ -1,5 +1,7 @@
 package io.mifos.reporting.service.internal.specification;
 
+import io.mifos.core.api.util.UserContextHolder;
+import io.mifos.core.lang.DateConverter;
 import io.mifos.reporting.api.v1.domain.*;
 import io.mifos.reporting.service.ServiceConstants;
 import io.mifos.reporting.service.spi.*;
@@ -9,6 +11,8 @@ import org.springframework.beans.factory.annotation.Qualifier;
 
 import javax.persistence.EntityManager;
 import javax.persistence.Query;
+import java.time.Clock;
+import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
@@ -75,11 +79,15 @@ public class SavingListReportSpecification implements ReportSpecification {
         final List<?> depositAccountResultList = depositAccountQuery.getResultList();
         reportPage.setRows(this.buildRows(reportRequest, depositAccountResultList));
 
-        return null;
-    }
 
-    private List<Row> buildRows(ReportRequest reportRequest, List<?> customerResultList) {
-        return null;
+        reportPage.setHasMore(
+                !this.entityManager.createNativeQuery(this.buildAccountQuery(reportRequest, pageIndex + 1, size))
+                        .getResultList().isEmpty()
+        );
+
+        reportPage.setGeneratedBy(UserContextHolder.checkedGetUser());
+        reportPage.setGeneratedOn(DateConverter.toIsoString(LocalDateTime.now(Clock.systemUTC())));
+        return reportPage;
     }
 
     private List<QueryParameter> buildQueryParameters() {
@@ -132,6 +140,77 @@ public class SavingListReportSpecification implements ReportSpecification {
         this.allColumnMapping.putAll(employeeColumnMapping);
         this.allColumnMapping.putAll(accountColumnMapping);
     }
+    private Header createHeader(final List<DisplayableField> displayableFields) {
+        final Header header = new Header();
+        header.setColumnNames(
+                displayableFields
+                        .stream()
+                        .map(DisplayableField::getName)
+                        .collect(Collectors.toList())
+        );
+        return header;
+    }
+
+
+    private List<Row> buildRows(final ReportRequest reportRequest, final List<?> depositAccountResultList) {
+        final ArrayList<Row> rows =new ArrayList<>();
+        depositAccountResultList.forEach(result -> {
+            final Row row = new Row();
+            row.setValues(new ArrayList<>());
+
+            final String customerIdentifier;
+
+            if (result instanceof Object[]) {
+                final Object[] resultValues = (Object[]) result;
+
+                customerIdentifier = resultValues[0].toString();
+
+                for (final Object resultValue : resultValues) {
+                    final Value value = new Value();
+                    if (resultValue != null) {
+                        value.setValues(new String[]{resultValue.toString()});
+                    } else {
+                        value.setValues(new String[]{});
+                    }
+
+                    row.getValues().add(value);
+                }
+            } else {
+
+                customerIdentifier = result.toString();
+                final Value value = new Value();
+                value.setValues(new String[]{result.toString()});
+                row.getValues().add(value);
+            }
+
+            final Query customerQuery = this.entityManager.createNativeQuery(this.buildCustomerQuery(reportRequest, customerIdentifier));
+            final List<?> accountResultList = customerQuery.getResultList();
+            final ArrayList<String> values = new ArrayList<>();
+            accountResultList.forEach(customerResult -> {
+                if (customerResult instanceof Object[]) {
+                    final Object[] customerResultValues = (Object[]) customerResult;
+                    final String customerValue = customerResultValues[0].toString();
+                    values.add(customerValue);
+                }
+            });
+            final Value customerValue = new Value();
+            customerValue.setValues(values.toArray(new String[values.size()]));
+            row.getValues().add(customerValue);
+
+            final String officeQueryString = this.buildOfficeQuery(reportRequest, customerIdentifier);
+            if (officeQueryString != null) {
+                final Query officeQuery = this.entityManager.createNativeQuery(officeQueryString);
+                final List<?> resultList = officeQuery.getResultList();
+                final Value officeValue = new Value();
+                officeValue.setValues(new String[]{resultList.get(0).toString()});
+                row.getValues().add(officeValue);
+            }
+
+            rows.add(row);
+        });
+
+        return rows;
+    }
 
     private String buildAccountQuery(final ReportRequest reportRequest, int pageIndex, int size) {
         final StringBuilder query = new StringBuilder("SELECT ");
@@ -216,19 +295,6 @@ public class SavingListReportSpecification implements ReportSpecification {
                 "ORDER BY cst.identifier";
     }
 
-
-    private Header createHeader(final List<DisplayableField> displayableFields) {
-        final Header header = new Header();
-        header.setColumnNames(
-                displayableFields
-                        .stream()
-                        .map(DisplayableField::getName)
-                        .collect(Collectors.toList())
-        );
-        return header;
-    }
-
-
     private List<DisplayableField> buildDisplayableFields() {
 
         return Arrays.asList(