Skip to content
Permalink
Browse files
Deposit Listing data rows built, Inactive Account Skeleton: Hopefully…
… completes deposit account listing
  • Loading branch information
Awasum Yannick committed Aug 21, 2017
1 parent 8eba0c0 commit e75d262a7df98cd866d9bd3e72898b4e7bcbdc89
Showing 2 changed files with 107 additions and 17 deletions.
@@ -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 {

}
}
@@ -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 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 ReportPage generateReport(ReportRequest reportRequest, int pageIndex, int
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 @@ private void initializeMapping() {
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 @@ private String buildOfficeQuery(final ReportRequest reportRequest, final String
"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(

0 comments on commit e75d262

Please sign in to comment.