Skip to content
Permalink
Browse files
Complete Teller Listing Report Spec
  • Loading branch information
Awasum Yannick committed Aug 28, 2017
1 parent 3b8eb87 commit e01fd9f7fdc6398a0861f22bb8bf053544250b1d
Showing 1 changed file with 96 additions and 47 deletions.
@@ -4,9 +4,7 @@
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.CriteriaBuilder;
import io.mifos.reporting.service.spi.Report;
import io.mifos.reporting.service.spi.ReportSpecification;
import io.mifos.reporting.service.spi.*;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
@@ -16,23 +14,20 @@
import java.time.Clock;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;

@Report(category = "Teller" , identifier = "Listing")
public class TellerListReportSpecification implements ReportSpecification {

// private static final String TOTAL_CASH_ON_HAND = "Cash on hand";
// private static final String TOTAL_CASH_RECEIVED = "Cash received";
// private static final String TOTAL_CASH_DISBURSED = "Cash Disbursed";
// private static final String TOTAL_NEGOTIABLE_INSTRUMENT_RECEIVED = "Negotiable instrument received";
// private static final String TOTAL_CHEQUES_RECEIVED = "Total cheques received";
private static final String TELLER = "Teller";
private static final String EMPLOYEE = "Employee";
private static final String OFFICE = "Office";
private static final String CASHDRAW_LIMIT = "Cashdraw limit";
private static final String STATE = "State";
private static final String DATE_RANGE = "Date";

private final Logger logger;

@@ -51,16 +46,6 @@ public TellerListReportSpecification(@Qualifier(ServiceConstants.LOGGER_NAME) fi
this.initializeMapping();
}

private void initializeMapping() {
this.tellerColumnMapping.put(TELLER, "tl.identifier");
this.tellerColumnMapping.put(OFFICE, "tl.office_identifier");
this.tellerColumnMapping.put(CASHDRAW_LIMIT, "tl.cashdraw_limit");
this.tellerColumnMapping.put(EMPLOYEE, "tl.assigned_employee_identifier");
this.tellerColumnMapping.put(STATE, "tl.a_state");

this.allColumnMapping.putAll(tellerColumnMapping);
}

@Override
public ReportDefinition getReportDefinition() {
final ReportDefinition reportDefinition = new ReportDefinition();
@@ -72,14 +57,6 @@ public ReportDefinition getReportDefinition() {
return reportDefinition;
}

private List<DisplayableField> buildDisplayableFields() {
return null;
}

private List<QueryParameter> buildQueryParameters() {
return null;
}

@Override
public ReportPage generateReport(ReportRequest reportRequest, int pageIndex, int size) {
final ReportDefinition reportDefinition = this.getReportDefinition();
@@ -104,6 +81,99 @@ public ReportPage generateReport(ReportRequest reportRequest, int pageIndex, int
return reportPage;
}

@Override
public void validate(final ReportRequest reportRequest) throws IllegalArgumentException {
final ArrayList<String> unknownFields = new ArrayList<>();
reportRequest.getQueryParameters().forEach(queryParameter -> {
if (!this.allColumnMapping.keySet().contains(queryParameter.getName())) {
unknownFields.add(queryParameter.getName());
}
});

reportRequest.getDisplayableFields().forEach(displayableField -> {
if (!this.allColumnMapping.keySet().contains(displayableField.getName())) {
unknownFields.add(displayableField.getName());
}
});

if (!unknownFields.isEmpty()) {
throw new IllegalArgumentException(
"Unspecified fields requested: " + unknownFields.stream().collect(Collectors.joining(", "))
);
}
}

private void initializeMapping() {
this.tellerColumnMapping.put(TELLER, "tl.identifier");
this.tellerColumnMapping.put(OFFICE, "tl.office_identifier");
this.tellerColumnMapping.put(CASHDRAW_LIMIT, "tl.cashdraw_limit");
this.tellerColumnMapping.put(EMPLOYEE, "tl.assigned_employee_identifier");
this.tellerColumnMapping.put(STATE, "tl.a_state");
this.tellerColumnMapping.put(DATE_RANGE, "tl.created_on");

this.allColumnMapping.putAll(tellerColumnMapping);
}

private Header createHeader(List<DisplayableField> displayableFields) {
final Header header = new Header();
header.setColumnNames(
displayableFields
.stream()
.map(DisplayableField::getName)
.collect(Collectors.toList())
);
return header;
}

private List<Row> buildRows(ReportRequest reportRequest, List<?> tellerResultList) {
final ArrayList<Row> rows = new ArrayList<>();
tellerResultList.forEach(result -> {
final Row row = new Row();
row.setValues(new ArrayList<>());

if (result instanceof Object[]) {
final Object[] resultValues = (Object[]) result;

for(final Object resultVal : resultValues) {
final Value val;
val = new Value();

if (resultVal != null) {
val.setValues(new String[]{resultVal.toString()});
} else {
val.setValues(new String[]{});
}

row.getValues().add(val);
}
} else {
final Value value = new Value();
value.setValues(new String[]{result.toString()});
row.getValues().add(value);
}
rows.add(row);
});

return rows;
}

private List<QueryParameter> buildQueryParameters() {
return Arrays.asList(
QueryParameterBuilder.create(DATE_RANGE, Type.DATE).operator(QueryParameter.Operator.BETWEEN).build(),
QueryParameterBuilder.create(STATE, Type.TEXT).operator(QueryParameter.Operator.IN).build()
);
}

private List<DisplayableField> buildDisplayableFields() {
return Arrays.asList(
DisplayableFieldBuilder.create(TELLER, Type.TEXT).mandatory().build(),
DisplayableFieldBuilder.create(OFFICE, Type.TEXT).build(),
DisplayableFieldBuilder.create(EMPLOYEE, Type.TEXT).build(),
DisplayableFieldBuilder.create(CASHDRAW_LIMIT, Type.TEXT).build(),
DisplayableFieldBuilder.create(STATE, Type.TEXT).build()
);
}

private String buildTellerQuery(ReportRequest reportRequest, int pageIndex, int size) {
final StringBuilder query = new StringBuilder("SELECT ");

@@ -148,25 +218,4 @@ private String buildTellerQuery(ReportRequest reportRequest, int pageIndex, int

return query.toString();
}

private List<Row> buildRows(ReportRequest reportRequest, List<?> tellerResultList) {
return null;
}

private Header createHeader(List<DisplayableField> displayableFields) {
final Header header = new Header();
header.setColumnNames(
displayableFields
.stream()
.map(DisplayableField::getName)
.collect(Collectors.toList())
);
return header;
}

@Override
public void validate(ReportRequest reportRequest) throws IllegalArgumentException {

}

}

0 comments on commit e01fd9f

Please sign in to comment.