Search in sources :

Example 1 with ReportDTO

use of py.org.fundacionparaguaya.pspserver.reports.dtos.ReportDTO in project FP-PSP-SERVER by FundacionParaguaya.

the class SnapshotReportManagerImpl method getSnasphots.

private ReportDTO getSnasphots(List<SnapshotEconomicEntity> snapshots) {
    ReportDTO report = new ReportDTO();
    report.getHeaders().add("Created At");
    List<SurveyData> rows = new ArrayList<>();
    report.getHeaders().addAll(snapshotMapper.getStaticPropertiesNames());
    for (SnapshotEconomicEntity s : snapshots) {
        s.getSnapshotIndicator().getAdditionalProperties().forEach((k, v) -> {
            if (!report.getHeaders().contains(StringConverter.getNameFromCamelCase(k))) {
                report.getHeaders().add(StringConverter.getNameFromCamelCase(k));
            }
        });
        SurveyData data = snapshotMapper.entityToDto(s.getSnapshotIndicator());
        data.put("createdAt", s.getCreatedAtLocalDateString());
        rows.add(data);
    }
    report.setRows(generateRows(rows, report.getHeaders()));
    return report;
}
Also used : SnapshotEconomicEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity) ArrayList(java.util.ArrayList) ReportDTO(py.org.fundacionparaguaya.pspserver.reports.dtos.ReportDTO) SurveyData(py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyData)

Example 2 with ReportDTO

use of py.org.fundacionparaguaya.pspserver.reports.dtos.ReportDTO in project FP-PSP-SERVER by FundacionParaguaya.

the class SnapshotReportManagerImpl method generateCSVSnapshotByOrganizationAndCreatedDate.

@Override
public String generateCSVSnapshotByOrganizationAndCreatedDate(SnapshotFilterDTO filters) {
    List<SnapshotEconomicEntity> snapshots = new ArrayList<>();
    Sort sort = new Sort(new Sort.Order(Direction.ASC, "family.organization.name"), new Sort.Order(Direction.ASC, "family.name"), new Sort.Order(Direction.ASC, "createdAt"));
    if (filters.getDateFrom() != null && filters.getDateTo() != null) {
        Specification<SnapshotEconomicEntity> dateRange = SnapshotEconomicSpecification.createdAtBetween2Dates(filters.getDateFrom(), filters.getDateTo());
        snapshots = snapshotRepository.findAll(where(SnapshotEconomicSpecification.byApplication(filters.getApplicationId())).and(dateRange).and(SnapshotEconomicSpecification.byOrganization(filters.getOrganizationId())), sort);
    }
    ReportDTO report = getOrganizationAndFamilyData(snapshots);
    return reportToCsv(report);
}
Also used : SnapshotEconomicEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity) ArrayList(java.util.ArrayList) Sort(org.springframework.data.domain.Sort) ReportDTO(py.org.fundacionparaguaya.pspserver.reports.dtos.ReportDTO)

Example 3 with ReportDTO

use of py.org.fundacionparaguaya.pspserver.reports.dtos.ReportDTO in project FP-PSP-SERVER by FundacionParaguaya.

the class SnapshotReportManagerImpl method getOrganizationAndFamilyData.

private ReportDTO getOrganizationAndFamilyData(List<SnapshotEconomicEntity> snapshots) {
    ReportDTO report = new ReportDTO();
    report.getHeaders().addAll(DEFAULT_HEADRES);
    List<SurveyData> rows = new ArrayList<>();
    report.getHeaders().addAll(snapshotMapper.getStaticPropertiesNames());
    for (SnapshotEconomicEntity s : snapshots) {
        s.getSnapshotIndicator().getAdditionalProperties().forEach((k, v) -> {
            if (!report.getHeaders().contains(k)) {
                report.getHeaders().add(StringConverter.getNameFromCamelCase(k));
            }
        });
        SurveyData data = snapshotMapper.entityToDto(s.getSnapshotIndicator());
        data.put("organizationCode", s.getFamily().getOrganization().getCode());
        data.put("organizationName", s.getFamily().getOrganization().getName());
        data.put("organizationStatus", s.getFamily().getOrganization().getStatus().toString());
        data.put("familyCode", s.getFamily().getCode());
        data.put("familyName", s.getFamily().getName());
        data.put("familyStatus", s.getFamily().getStatus().toString());
        data.put("snapshotCreatedAt", s.getCreatedAtLocalDateString());
        rows.add(data);
    }
    report.setRows(generateRows(rows, report.getHeaders()));
    return report;
}
Also used : SnapshotEconomicEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity) ArrayList(java.util.ArrayList) ReportDTO(py.org.fundacionparaguaya.pspserver.reports.dtos.ReportDTO) SurveyData(py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyData)

Aggregations

ArrayList (java.util.ArrayList)3 ReportDTO (py.org.fundacionparaguaya.pspserver.reports.dtos.ReportDTO)3 SnapshotEconomicEntity (py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity)3 SurveyData (py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyData)2 Sort (org.springframework.data.domain.Sort)1