Search in sources :

Example 6 with SnapshotEconomicEntity

use of py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity in project FP-PSP-SERVER by FundacionParaguaya.

the class SnapshotServiceImpl method getSnapshotIndicatorsByFamily.

@Override
public List<SnapshotIndicators> getSnapshotIndicatorsByFamily(Long familyId) {
    List<SnapshotIndicators> toRet = new ArrayList<>();
    List<SnapshotEconomicEntity> originalSnapshots = economicRepository.findByFamilyFamilyId(familyId).stream().collect(Collectors.toList());
    for (SnapshotEconomicEntity os : originalSnapshots) {
        SnapshotIndicators snapshotIndicators = countSnapshotIndicators(os);
        List<SnapshotIndicatorPriority> priorities = priorityService.getSnapshotIndicatorPriorityList(os.getSnapshotIndicator().getId());
        snapshotIndicators.setIndicatorsPriorities(priorities);
        snapshotIndicators.setCreatedAt(os.getCreatedAtAsISOString());
        snapshotIndicators.setSnapshotIndicatorId(os.getSnapshotIndicator().getId());
        snapshotIndicators.setFamilyId(os.getFamily().getFamilyId());
        snapshotIndicators.setSnapshotEconomicId(os.getId());
        snapshotIndicators.setSurveyId(os.getSurveyDefinition().getId());
        FamilyDTO familyDto = familyService.getFamilyById(familyId);
        familyDto.setOrganizationId(organizationMapper.entityToDto(organizationRepository.findOne(familyDto.getOrganization().getId())));
        snapshotIndicators.setFamily(familyDto);
        if (os.getUser() != null) {
            snapshotIndicators.setUser(UserDTO.builder().userId(os.getUser().getId()).username(os.getUser().getUsername()).build());
        }
        snapshotIndicators.setIndicatorsSurveyData(getIndicatorsValue(os, snapshotIndicators));
        toRet.add(snapshotIndicators);
    }
    return toRet;
}
Also used : SnapshotIndicators(py.org.fundacionparaguaya.pspserver.surveys.dtos.SnapshotIndicators) SnapshotIndicatorPriority(py.org.fundacionparaguaya.pspserver.surveys.dtos.SnapshotIndicatorPriority) SnapshotEconomicEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity) ArrayList(java.util.ArrayList) FamilyDTO(py.org.fundacionparaguaya.pspserver.families.dtos.FamilyDTO)

Example 7 with SnapshotEconomicEntity

use of py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity in project FP-PSP-SERVER by FundacionParaguaya.

the class SnapshotServiceImpl method getSnapshotIndicators.

@Override
public SnapshotIndicators getSnapshotIndicators(Long snapshotId) {
    SnapshotIndicators toRet = new SnapshotIndicators();
    SnapshotEconomicEntity originalSnapshot = economicRepository.findOne(snapshotId);
    if (originalSnapshot == null) {
        return toRet;
    }
    List<SnapshotIndicatorPriority> priorities = priorityService.getSnapshotIndicatorPriorityList(originalSnapshot.getSnapshotIndicator().getId());
    toRet.setIndicatorsPriorities(priorities);
    toRet.setIndicatorsSurveyData(getIndicatorsValue(originalSnapshot, toRet));
    toRet.setCreatedAt(originalSnapshot.getCreatedAtAsISOString());
    toRet.setSnapshotIndicatorId(originalSnapshot.getSnapshotIndicator().getId());
    toRet.setSnapshotEconomicId(originalSnapshot.getId());
    toRet.setSurveyId(originalSnapshot.getSurveyDefinition().getId());
    // set family for information purpose
    Long familyId = originalSnapshot.getFamily().getFamilyId();
    toRet.setFamilyId(familyId);
    toRet.setFamily(familyService.getFamilyById(familyId));
    return toRet;
}
Also used : SnapshotIndicators(py.org.fundacionparaguaya.pspserver.surveys.dtos.SnapshotIndicators) SnapshotIndicatorPriority(py.org.fundacionparaguaya.pspserver.surveys.dtos.SnapshotIndicatorPriority) SnapshotEconomicEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity)

Example 8 with SnapshotEconomicEntity

use of py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity in project FP-PSP-SERVER by FundacionParaguaya.

the class SnapshotEconomicMapper method newSnapshotToEconomicEntity.

public SnapshotEconomicEntity newSnapshotToEconomicEntity(NewSnapshot snapshot, SnapshotIndicatorEntity indicator) {
    UserEntity user = null;
    TermCondPolEntity termCond = null;
    TermCondPolEntity privPol = null;
    if (snapshot.getUserName() != null) {
        user = userRepository.findOneByUsername(snapshot.getUserName()).get();
    }
    if (snapshot.getTermCondId() != null) {
        termCond = termCondPolRepository.findOne(snapshot.getTermCondId());
    }
    if (snapshot.getPrivPolId() != null) {
        privPol = termCondPolRepository.findOne(snapshot.getPrivPolId());
    }
    return new SnapshotEconomicEntity().surveyDefinition(new SurveyEntity(snapshot.getSurveyId())).surveyIndicator(indicator).staticProperties(snapshot.getMappedEconomicSurveyData(propertyAttributeSupport.staticEconomic(), propertyAttributeSupport::propertySchemaToSystemName)).additionalProperties(snapshot.getEconomicSurveyData(propertyAttributeSupport.additional())).user(user).termCond(termCond).privPol(privPol);
}
Also used : SnapshotEconomicEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity) SurveyEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SurveyEntity) UserEntity(py.org.fundacionparaguaya.pspserver.security.entities.UserEntity) TermCondPolEntity(py.org.fundacionparaguaya.pspserver.security.entities.TermCondPolEntity)

Example 9 with SnapshotEconomicEntity

use of py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity 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 10 with SnapshotEconomicEntity

use of py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity 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)

Aggregations

SnapshotEconomicEntity (py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity)17 ArrayList (java.util.ArrayList)9 SnapshotIndicators (py.org.fundacionparaguaya.pspserver.surveys.dtos.SnapshotIndicators)6 SurveyData (py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyData)6 FamilyEntity (py.org.fundacionparaguaya.pspserver.families.entities.FamilyEntity)5 SnapshotIndicatorEntity (py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotIndicatorEntity)5 ReportDTO (py.org.fundacionparaguaya.pspserver.reports.dtos.ReportDTO)4 SnapshotIndicatorPriority (py.org.fundacionparaguaya.pspserver.surveys.dtos.SnapshotIndicatorPriority)4 DateTimeFormatter (java.time.format.DateTimeFormatter)3 List (java.util.List)3 Map (java.util.Map)3 Collectors (java.util.stream.Collectors)3 Specifications.where (org.springframework.data.jpa.domain.Specifications.where)3 Service (org.springframework.stereotype.Service)3 Transactional (org.springframework.transaction.annotation.Transactional)3 CustomParameterizedException (py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException)3 FamilyDTO (py.org.fundacionparaguaya.pspserver.families.dtos.FamilyDTO)3 PersonEntity (py.org.fundacionparaguaya.pspserver.families.entities.PersonEntity)3 SnapshotIndicatorMapper (py.org.fundacionparaguaya.pspserver.surveys.mapper.SnapshotIndicatorMapper)3 SnapshotEconomicRepository (py.org.fundacionparaguaya.pspserver.surveys.repositories.SnapshotEconomicRepository)3