Search in sources :

Example 1 with SnapshotFilterDTO

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

the class SnapshotReportManagerImpl method listSnapshotByFamily.

@Override
public List<FamilySnapshotDTO> listSnapshotByFamily(SnapshotFilterDTO filters) {
    List<FamilySnapshotDTO> toRet = new ArrayList<>();
    Sort sort = new Sort(new Sort.Order(Direction.ASC, "createdAt"));
    if (filters.getDateFrom() != null && filters.getDateTo() != null && filters.getFamilyId() != null) {
        List<SnapshotEconomicEntity> snapshots = snapshotRepository.findAll(where(forFamily(filters.getFamilyId())).and(SnapshotEconomicSpecification.createdAtBetween2Dates(filters.getDateFrom(), filters.getDateTo())), sort);
        Map<SurveyEntity, List<SnapshotEconomicEntity>> groupBySurvey = snapshots.stream().collect(Collectors.groupingBy(s -> s.getSurveyDefinition()));
        groupBySurvey.forEach((k, v) -> {
            FamilySnapshotDTO familySnapshots = new FamilySnapshotDTO(filters.getFamilyId(), k.getTitle());
            familySnapshots.setSnapshots(getSnasphots(v));
            toRet.add(familySnapshots);
        });
    }
    return toRet;
}
Also used : Specifications.where(org.springframework.data.jpa.domain.Specifications.where) Arrays(java.util.Arrays) FamilyRepository(py.org.fundacionparaguaya.pspserver.families.repositories.FamilyRepository) SurveyEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SurveyEntity) SnapshotFilterDTO(py.org.fundacionparaguaya.pspserver.reports.dtos.SnapshotFilterDTO) FamilySpecification.byOrganization(py.org.fundacionparaguaya.pspserver.families.specifications.FamilySpecification.byOrganization) SurveyData(py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyData) OrganizationFamilyDTO(py.org.fundacionparaguaya.pspserver.reports.dtos.OrganizationFamilyDTO) FamilyEntity(py.org.fundacionparaguaya.pspserver.families.entities.FamilyEntity) ArrayList(java.util.ArrayList) SnapshotEconomicSpecification(py.org.fundacionparaguaya.pspserver.surveys.specifications.SnapshotEconomicSpecification) Service(org.springframework.stereotype.Service) Map(java.util.Map) Sort(org.springframework.data.domain.Sort) Direction(org.springframework.data.domain.Sort.Direction) SnapshotReportManager(py.org.fundacionparaguaya.pspserver.reports.services.SnapshotReportManager) OrganizationEntity(py.org.fundacionparaguaya.pspserver.network.entities.OrganizationEntity) ReportDTO(py.org.fundacionparaguaya.pspserver.reports.dtos.ReportDTO) StringConverter(py.org.fundacionparaguaya.pspserver.common.utils.StringConverter) FamilySnapshotDTO(py.org.fundacionparaguaya.pspserver.reports.dtos.FamilySnapshotDTO) Collectors(java.util.stream.Collectors) FamilyDTOMapper(py.org.fundacionparaguaya.pspserver.reports.mapper.FamilyDTOMapper) SnapshotEconomicRepository(py.org.fundacionparaguaya.pspserver.surveys.repositories.SnapshotEconomicRepository) List(java.util.List) SnapshotEconomicEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity) FamilySpecification(py.org.fundacionparaguaya.pspserver.families.specifications.FamilySpecification) Specification(org.springframework.data.jpa.domain.Specification) FamilySpecification.byApplication(py.org.fundacionparaguaya.pspserver.families.specifications.FamilySpecification.byApplication) SnapshotIndicatorMapper(py.org.fundacionparaguaya.pspserver.surveys.mapper.SnapshotIndicatorMapper) SnapshotEconomicSpecification.forFamily(py.org.fundacionparaguaya.pspserver.surveys.specifications.SnapshotEconomicSpecification.forFamily) FamilySnapshotDTO(py.org.fundacionparaguaya.pspserver.reports.dtos.FamilySnapshotDTO) SnapshotEconomicEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity) SurveyEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SurveyEntity) ArrayList(java.util.ArrayList) Sort(org.springframework.data.domain.Sort) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with SnapshotFilterDTO

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

the class SnapshotReportController method getFamiliesByOrganization.

@GetMapping(path = "/family/organizations", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<List<OrganizationFamilyDTO>> getFamiliesByOrganization(@RequestParam(value = "application_id", required = false) Long applicationId, @RequestParam(value = "organization_id", required = false) Long organizationId, @RequestParam(value = "family_id", required = false) Long familyId, @RequestParam(value = "date_from", required = true) String dateFrom, @RequestParam(value = "date_to", required = true) String dateTo) {
    SnapshotFilterDTO filters = new SnapshotFilterDTO(applicationId, organizationId, familyId, dateFrom, dateTo);
    List<OrganizationFamilyDTO> families = familyReportService.listFamilyByOrganizationAndCreatedDate(filters);
    return ResponseEntity.ok(families);
}
Also used : OrganizationFamilyDTO(py.org.fundacionparaguaya.pspserver.reports.dtos.OrganizationFamilyDTO) SnapshotFilterDTO(py.org.fundacionparaguaya.pspserver.reports.dtos.SnapshotFilterDTO) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 3 with SnapshotFilterDTO

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

the class SnapshotReportController method getSnapshotsIndicatorsByFamily.

@GetMapping(path = "/family/indicators", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<List<FamilySnapshotDTO>> getSnapshotsIndicatorsByFamily(@RequestParam(value = "application_id", required = false) Long applicationId, @RequestParam(value = "organization_id", required = false) Long organizationId, @RequestParam(value = "family_id", required = true) Long familyId, @RequestParam(value = "date_from", required = true) String dateFrom, @RequestParam(value = "date_to", required = true) String dateTo) {
    SnapshotFilterDTO filters = new SnapshotFilterDTO(applicationId, organizationId, familyId, dateFrom, dateTo);
    List<FamilySnapshotDTO> snapshots = familyReportService.listSnapshotByFamily(filters);
    return ResponseEntity.ok(snapshots);
}
Also used : FamilySnapshotDTO(py.org.fundacionparaguaya.pspserver.reports.dtos.FamilySnapshotDTO) SnapshotFilterDTO(py.org.fundacionparaguaya.pspserver.reports.dtos.SnapshotFilterDTO) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 4 with SnapshotFilterDTO

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

the class SnapshotReportController method generateCSVSnapshotByOrganizationAndCreatedDate.

@GetMapping(path = "/family/indicators/csv", produces = "application/octet-stream")
public void generateCSVSnapshotByOrganizationAndCreatedDate(@RequestParam(value = "application_id", required = false) Long applicationId, @RequestParam(value = "organization_id", required = false) Long organizationId, @RequestParam(value = "family_id", required = true) Long familyId, @RequestParam(value = "date_from", required = true) String dateFrom, @RequestParam(value = "date_to", required = true) String dateTo, HttpServletResponse response) throws IOException {
    SnapshotFilterDTO filters = new SnapshotFilterDTO(applicationId, organizationId, familyId, dateFrom, dateTo);
    String csv = familyReportService.generateCSVSnapshotByOrganizationAndCreatedDate(filters);
    response.setContentType("application/octet-stream");
    response.setHeader("Content-Disposition", "attachment; filename=\"snapshots.csv\"");
    response.getWriter().write(csv);
    response.getWriter().close();
}
Also used : SnapshotFilterDTO(py.org.fundacionparaguaya.pspserver.reports.dtos.SnapshotFilterDTO) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 5 with SnapshotFilterDTO

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

the class SnapshotReportManagerImpl method listFamilyByOrganizationAndCreatedDate.

@Override
public List<OrganizationFamilyDTO> listFamilyByOrganizationAndCreatedDate(SnapshotFilterDTO filters) {
    List<FamilyEntity> families = new ArrayList<>();
    Sort sort = new Sort(new Sort.Order(Direction.ASC, "organization.name"), new Sort.Order(Direction.ASC, "name"));
    Specification<FamilyEntity> dateRange = FamilySpecification.createdAtBetween2Dates(filters.getDateFrom(), filters.getDateTo());
    families = familyRepository.findAll(where(byOrganization(filters.getOrganizationId())).and(dateRange).and(byApplication(filters.getApplicationId())).and(dateRange), sort);
    Map<OrganizationEntity, List<FamilyEntity>> groupByOrganization = families.stream().collect(Collectors.groupingBy(f -> f.getOrganization()));
    List<OrganizationFamilyDTO> toRet = new ArrayList<>();
    groupByOrganization.forEach((k, v) -> {
        OrganizationFamilyDTO fa = new OrganizationFamilyDTO(k.getName(), k.getCode(), k.getDescription(), k.isActive());
        fa.setFamilies(familyReportMapper.entityListToDtoList(v));
        toRet.add(fa);
    });
    return toRet;
}
Also used : Specifications.where(org.springframework.data.jpa.domain.Specifications.where) Arrays(java.util.Arrays) FamilyRepository(py.org.fundacionparaguaya.pspserver.families.repositories.FamilyRepository) SurveyEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SurveyEntity) SnapshotFilterDTO(py.org.fundacionparaguaya.pspserver.reports.dtos.SnapshotFilterDTO) FamilySpecification.byOrganization(py.org.fundacionparaguaya.pspserver.families.specifications.FamilySpecification.byOrganization) SurveyData(py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyData) OrganizationFamilyDTO(py.org.fundacionparaguaya.pspserver.reports.dtos.OrganizationFamilyDTO) FamilyEntity(py.org.fundacionparaguaya.pspserver.families.entities.FamilyEntity) ArrayList(java.util.ArrayList) SnapshotEconomicSpecification(py.org.fundacionparaguaya.pspserver.surveys.specifications.SnapshotEconomicSpecification) Service(org.springframework.stereotype.Service) Map(java.util.Map) Sort(org.springframework.data.domain.Sort) Direction(org.springframework.data.domain.Sort.Direction) SnapshotReportManager(py.org.fundacionparaguaya.pspserver.reports.services.SnapshotReportManager) OrganizationEntity(py.org.fundacionparaguaya.pspserver.network.entities.OrganizationEntity) ReportDTO(py.org.fundacionparaguaya.pspserver.reports.dtos.ReportDTO) StringConverter(py.org.fundacionparaguaya.pspserver.common.utils.StringConverter) FamilySnapshotDTO(py.org.fundacionparaguaya.pspserver.reports.dtos.FamilySnapshotDTO) Collectors(java.util.stream.Collectors) FamilyDTOMapper(py.org.fundacionparaguaya.pspserver.reports.mapper.FamilyDTOMapper) SnapshotEconomicRepository(py.org.fundacionparaguaya.pspserver.surveys.repositories.SnapshotEconomicRepository) List(java.util.List) SnapshotEconomicEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity) FamilySpecification(py.org.fundacionparaguaya.pspserver.families.specifications.FamilySpecification) Specification(org.springframework.data.jpa.domain.Specification) FamilySpecification.byApplication(py.org.fundacionparaguaya.pspserver.families.specifications.FamilySpecification.byApplication) SnapshotIndicatorMapper(py.org.fundacionparaguaya.pspserver.surveys.mapper.SnapshotIndicatorMapper) SnapshotEconomicSpecification.forFamily(py.org.fundacionparaguaya.pspserver.surveys.specifications.SnapshotEconomicSpecification.forFamily) FamilyEntity(py.org.fundacionparaguaya.pspserver.families.entities.FamilyEntity) OrganizationEntity(py.org.fundacionparaguaya.pspserver.network.entities.OrganizationEntity) OrganizationFamilyDTO(py.org.fundacionparaguaya.pspserver.reports.dtos.OrganizationFamilyDTO) ArrayList(java.util.ArrayList) Sort(org.springframework.data.domain.Sort) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

SnapshotFilterDTO (py.org.fundacionparaguaya.pspserver.reports.dtos.SnapshotFilterDTO)5 GetMapping (org.springframework.web.bind.annotation.GetMapping)3 FamilySnapshotDTO (py.org.fundacionparaguaya.pspserver.reports.dtos.FamilySnapshotDTO)3 OrganizationFamilyDTO (py.org.fundacionparaguaya.pspserver.reports.dtos.OrganizationFamilyDTO)3 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 Sort (org.springframework.data.domain.Sort)2 Direction (org.springframework.data.domain.Sort.Direction)2 Specification (org.springframework.data.jpa.domain.Specification)2 Specifications.where (org.springframework.data.jpa.domain.Specifications.where)2 Service (org.springframework.stereotype.Service)2 StringConverter (py.org.fundacionparaguaya.pspserver.common.utils.StringConverter)2 FamilyEntity (py.org.fundacionparaguaya.pspserver.families.entities.FamilyEntity)2 FamilyRepository (py.org.fundacionparaguaya.pspserver.families.repositories.FamilyRepository)2 FamilySpecification (py.org.fundacionparaguaya.pspserver.families.specifications.FamilySpecification)2 FamilySpecification.byApplication (py.org.fundacionparaguaya.pspserver.families.specifications.FamilySpecification.byApplication)2 FamilySpecification.byOrganization (py.org.fundacionparaguaya.pspserver.families.specifications.FamilySpecification.byOrganization)2