Search in sources :

Example 6 with SurveyData

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

the class PersonMapper method snapshotPersonalToEntity.

public PersonEntity snapshotPersonalToEntity(NewSnapshot snapshot) {
    SurveyData personalInformation = snapshot.getMappedPersonalSurveyData(propertyAttributeSupport.staticPersonal(), propertyAttributeSupport::propertySchemaToSystemName);
    if (personalInformation.get("birthdate") != null) {
        personalInformation.put("birthdate", LocalDate.parse(personalInformation.getAsString("birthdate"), DateTimeFormatter.ofPattern("yyyy-MM-dd")));
    }
    if (personalInformation.get("gender") != null) {
        personalInformation.put("gender", Gender.valueOf(personalInformation.getAsString("gender")));
    }
    if (personalInformation.get("countryOfBirth") != null) {
        Optional<CountryEntity> country = countryRepository.findByAlfa2Code(personalInformation.getAsString("countryOfBirth"));
        personalInformation.put("countryOfBirth", country.orElse(null));
    }
    PersonEntity pe = new PersonEntity().staticProperties(personalInformation);
    return pe;
}
Also used : SurveyData(py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyData) CountryEntity(py.org.fundacionparaguaya.pspserver.system.entities.CountryEntity) PersonEntity(py.org.fundacionparaguaya.pspserver.families.entities.PersonEntity)

Example 7 with SurveyData

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

the class SnapshotServiceImpl method countSnapshotIndicators.

private SnapshotIndicators countSnapshotIndicators(SnapshotEconomicEntity snapshot) {
    SnapshotIndicators indicators = new SnapshotIndicators();
    try {
        SurveyData properties = indicatorMapper.entityToDto(snapshot.getSnapshotIndicator());
        properties.forEach((k, v) -> {
            countIndicators(indicators, v);
        });
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
        throw new UnknownResourceException(i18n.translate("snapshot.invalid", snapshot.getId()));
    }
    return indicators;
}
Also used : SnapshotIndicators(py.org.fundacionparaguaya.pspserver.surveys.dtos.SnapshotIndicators) SurveyData(py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyData) UnknownResourceException(py.org.fundacionparaguaya.pspserver.common.exceptions.UnknownResourceException) CustomParameterizedException(py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException) UnknownResourceException(py.org.fundacionparaguaya.pspserver.common.exceptions.UnknownResourceException)

Example 8 with SurveyData

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

the class SnapshotServiceImpl method getIndicatorsValue.

@Override
public List<SurveyData> getIndicatorsValue(SurveyData indicators) {
    List<SurveyData> toRet = new ArrayList<>();
    indicators.forEach((k, v) -> {
        SurveyData indicator = new SurveyData();
        indicator.put(INDICATOR_NAME, getNameFromCamelCase(k));
        indicator.put(INDICATOR_VALUE, v != null ? StringUtils.lowerCase(v.toString()) : "none");
        toRet.add(indicator);
    });
    return toRet;
}
Also used : ArrayList(java.util.ArrayList) SurveyData(py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyData)

Example 9 with SurveyData

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

the class OrganizationServiceImpl method countSnapshotIndicators.

private SnapshotIndicators countSnapshotIndicators(Long organizationId) {
    List<FamilyEntity> families = familyService.findByOrganizationId(organizationId);
    List<SnapshotEconomicEntity> snapshotEconomics = snapshotEconomicRepo.findByFamilyIn(families);
    List<SnapshotIndicatorEntity> entityList = new ArrayList<SnapshotIndicatorEntity>();
    for (SnapshotEconomicEntity economics : snapshotEconomics) {
        entityList.add(economics.getSnapshotIndicator());
    }
    SnapshotIndicators indicators = new SnapshotIndicators();
    List<SurveyData> listProperties = indicatorMapper.entityListToDtoList(entityList);
    for (SurveyData properties : listProperties) {
        properties.forEach((k, v) -> {
            countIndicators(indicators, v);
        });
    }
    return indicators;
}
Also used : FamilyEntity(py.org.fundacionparaguaya.pspserver.families.entities.FamilyEntity) SnapshotIndicators(py.org.fundacionparaguaya.pspserver.surveys.dtos.SnapshotIndicators) SnapshotEconomicEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity) ArrayList(java.util.ArrayList) SnapshotIndicatorEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotIndicatorEntity) SurveyData(py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyData)

Example 10 with SurveyData

use of py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyData 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

SurveyData (py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyData)10 ArrayList (java.util.ArrayList)7 SnapshotEconomicEntity (py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity)5 SnapshotIndicators (py.org.fundacionparaguaya.pspserver.surveys.dtos.SnapshotIndicators)4 List (java.util.List)3 CustomParameterizedException (py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException)3 UnknownResourceException (py.org.fundacionparaguaya.pspserver.common.exceptions.UnknownResourceException)3 FamilyEntity (py.org.fundacionparaguaya.pspserver.families.entities.FamilyEntity)3 PersonEntity (py.org.fundacionparaguaya.pspserver.families.entities.PersonEntity)3 SnapshotIndicatorEntity (py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotIndicatorEntity)3 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)2 DateTimeFormatter (java.time.format.DateTimeFormatter)2 TemporalAdjusters (java.time.temporal.TemporalAdjusters)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 StringUtils (org.apache.commons.lang3.StringUtils)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2