Search in sources :

Example 1 with SurveyData

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

the class SnapshotServiceImpl method getIndicatorsValue.

private List<SurveyData> getIndicatorsValue(SnapshotEconomicEntity snapshotEconomic, SnapshotIndicators toRet) {
    SurveyDefinition survey = surveyService.getSurveyDefinition(snapshotEconomic.getSurveyDefinition().getId());
    List<String> indicatorGroup = survey.getSurveyUISchema().getGroupIndicators();
    List<String> order = survey.getSurveyUISchema().getUiOrder().stream().filter(field -> indicatorGroup.contains(field)).collect(Collectors.toList());
    SurveyData indicators = indicatorMapper.entityToDto(snapshotEconomic.getSnapshotIndicator());
    List<SurveyData> indicatorsToRet = new ArrayList<>();
    if (indicatorGroup != null && !indicatorGroup.isEmpty() && order != null && !order.isEmpty()) {
        order.forEach(indicator -> {
            if (indicators.containsKey(indicator)) {
                SurveyData sd = new SurveyData();
                sd.put(INDICATOR_NAME, getDescriptionOpt(survey, indicator).map(e -> e.get("es")).orElse(getNameFromCamelCase(indicator)));
                sd.put(INDICATOR_VALUE, indicators.get(indicator));
                countIndicators(toRet, sd.get(INDICATOR_VALUE));
                indicatorsToRet.add(sd);
            }
        });
    }
    return indicatorsToRet;
}
Also used : SnapshotEconomicMapper(py.org.fundacionparaguaya.pspserver.surveys.mapper.SnapshotEconomicMapper) UserDetailsDTO(py.org.fundacionparaguaya.pspserver.security.dtos.UserDetailsDTO) LoggerFactory(org.slf4j.LoggerFactory) FamilyService(py.org.fundacionparaguaya.pspserver.families.services.FamilyService) SurveyData(py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyData) I18n(py.org.fundacionparaguaya.pspserver.config.I18n) StringUtils(org.apache.commons.lang3.StringUtils) UserDTO(py.org.fundacionparaguaya.pspserver.security.dtos.UserDTO) SnapshotEconomicSpecification.byApplication(py.org.fundacionparaguaya.pspserver.surveys.specifications.SnapshotEconomicSpecification.byApplication) SnapshotIndicatorPriority(py.org.fundacionparaguaya.pspserver.surveys.dtos.SnapshotIndicatorPriority) PersonMapper(py.org.fundacionparaguaya.pspserver.families.mapper.PersonMapper) Map(java.util.Map) PersonEntity(py.org.fundacionparaguaya.pspserver.families.entities.PersonEntity) NewSnapshot(py.org.fundacionparaguaya.pspserver.surveys.dtos.NewSnapshot) SnapshotService(py.org.fundacionparaguaya.pspserver.surveys.services.SnapshotService) ValidationResults(py.org.fundacionparaguaya.pspserver.surveys.validation.ValidationResults) SnapshotEconomicSpecification.createdAtLess2Months(py.org.fundacionparaguaya.pspserver.surveys.specifications.SnapshotEconomicSpecification.createdAtLess2Months) FamilyFilterDTO(py.org.fundacionparaguaya.pspserver.families.dtos.FamilyFilterDTO) Collectors(java.util.stream.Collectors) OrganizationMapper(py.org.fundacionparaguaya.pspserver.network.mapper.OrganizationMapper) SnapshotIndicatorEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotIndicatorEntity) SurveyDefinition(py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyDefinition) SnapshotEconomicRepository(py.org.fundacionparaguaya.pspserver.surveys.repositories.SnapshotEconomicRepository) List(java.util.List) SnapshotEconomicEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity) TopOfIndicators(py.org.fundacionparaguaya.pspserver.surveys.dtos.TopOfIndicators) TemporalAdjusters(java.time.temporal.TemporalAdjusters) Optional(java.util.Optional) FamilyDTO(py.org.fundacionparaguaya.pspserver.families.dtos.FamilyDTO) OrganizationRepository(py.org.fundacionparaguaya.pspserver.network.repositories.OrganizationRepository) Specifications.where(org.springframework.data.jpa.domain.Specifications.where) HashMap(java.util.HashMap) FamilyEntity(py.org.fundacionparaguaya.pspserver.families.entities.FamilyEntity) ArrayList(java.util.ArrayList) SurveyService(py.org.fundacionparaguaya.pspserver.surveys.services.SurveyService) SnapshotEconomicSpecification(py.org.fundacionparaguaya.pspserver.surveys.specifications.SnapshotEconomicSpecification) Service(org.springframework.stereotype.Service) CustomParameterizedException(py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException) SnapshotIndicatorPriorityService(py.org.fundacionparaguaya.pspserver.surveys.services.SnapshotIndicatorPriorityService) Logger(org.slf4j.Logger) Snapshot(py.org.fundacionparaguaya.pspserver.surveys.dtos.Snapshot) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) SnapshotIndicators(py.org.fundacionparaguaya.pspserver.surveys.dtos.SnapshotIndicators) Role(py.org.fundacionparaguaya.pspserver.security.constants.Role) PropertyTitle(py.org.fundacionparaguaya.pspserver.surveys.dtos.PropertyTitle) SurveyStoplightEnum(py.org.fundacionparaguaya.pspserver.surveys.enums.SurveyStoplightEnum) UnknownResourceException(py.org.fundacionparaguaya.pspserver.common.exceptions.UnknownResourceException) SnapshotTaken(py.org.fundacionparaguaya.pspserver.surveys.dtos.SnapshotTaken) DateTimeFormatter(java.time.format.DateTimeFormatter) SnapshotIndicatorMapper(py.org.fundacionparaguaya.pspserver.surveys.mapper.SnapshotIndicatorMapper) Transactional(org.springframework.transaction.annotation.Transactional) SurveyDefinition(py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyDefinition) ArrayList(java.util.ArrayList) SurveyData(py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyData)

Example 2 with SurveyData

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

the class SnapshotServiceImpl method getTopOfIndicators.

@Override
public List<TopOfIndicators> getTopOfIndicators(Long organizationId) {
    List<FamilyEntity> families = familyService.findByOrganizationId(organizationId);
    List<SurveyData> propertiesList = indicatorMapper.entityListToDtoList(economicRepository.findByFamilyIn(families).stream().map(economic -> economic.getSnapshotIndicator()).collect(Collectors.toList()));
    Map<String, TopOfIndicators> topOfIndicatorMap = new HashMap<String, TopOfIndicators>();
    for (SurveyData surveyData : propertiesList) {
        surveyData.forEach((key, value) -> {
            countTopIndicators(topOfIndicatorMap, key, value);
        });
    }
    List<TopOfIndicators> list = topOfIndicatorMap.entrySet().stream().map(e -> new TopOfIndicators(e.getValue())).collect(Collectors.toList());
    return list;
}
Also used : SnapshotEconomicMapper(py.org.fundacionparaguaya.pspserver.surveys.mapper.SnapshotEconomicMapper) UserDetailsDTO(py.org.fundacionparaguaya.pspserver.security.dtos.UserDetailsDTO) LoggerFactory(org.slf4j.LoggerFactory) FamilyService(py.org.fundacionparaguaya.pspserver.families.services.FamilyService) SurveyData(py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyData) I18n(py.org.fundacionparaguaya.pspserver.config.I18n) StringUtils(org.apache.commons.lang3.StringUtils) UserDTO(py.org.fundacionparaguaya.pspserver.security.dtos.UserDTO) SnapshotEconomicSpecification.byApplication(py.org.fundacionparaguaya.pspserver.surveys.specifications.SnapshotEconomicSpecification.byApplication) SnapshotIndicatorPriority(py.org.fundacionparaguaya.pspserver.surveys.dtos.SnapshotIndicatorPriority) PersonMapper(py.org.fundacionparaguaya.pspserver.families.mapper.PersonMapper) Map(java.util.Map) PersonEntity(py.org.fundacionparaguaya.pspserver.families.entities.PersonEntity) NewSnapshot(py.org.fundacionparaguaya.pspserver.surveys.dtos.NewSnapshot) SnapshotService(py.org.fundacionparaguaya.pspserver.surveys.services.SnapshotService) ValidationResults(py.org.fundacionparaguaya.pspserver.surveys.validation.ValidationResults) SnapshotEconomicSpecification.createdAtLess2Months(py.org.fundacionparaguaya.pspserver.surveys.specifications.SnapshotEconomicSpecification.createdAtLess2Months) FamilyFilterDTO(py.org.fundacionparaguaya.pspserver.families.dtos.FamilyFilterDTO) Collectors(java.util.stream.Collectors) OrganizationMapper(py.org.fundacionparaguaya.pspserver.network.mapper.OrganizationMapper) SnapshotIndicatorEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotIndicatorEntity) SurveyDefinition(py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyDefinition) SnapshotEconomicRepository(py.org.fundacionparaguaya.pspserver.surveys.repositories.SnapshotEconomicRepository) List(java.util.List) SnapshotEconomicEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity) TopOfIndicators(py.org.fundacionparaguaya.pspserver.surveys.dtos.TopOfIndicators) TemporalAdjusters(java.time.temporal.TemporalAdjusters) Optional(java.util.Optional) FamilyDTO(py.org.fundacionparaguaya.pspserver.families.dtos.FamilyDTO) OrganizationRepository(py.org.fundacionparaguaya.pspserver.network.repositories.OrganizationRepository) Specifications.where(org.springframework.data.jpa.domain.Specifications.where) HashMap(java.util.HashMap) FamilyEntity(py.org.fundacionparaguaya.pspserver.families.entities.FamilyEntity) ArrayList(java.util.ArrayList) SurveyService(py.org.fundacionparaguaya.pspserver.surveys.services.SurveyService) SnapshotEconomicSpecification(py.org.fundacionparaguaya.pspserver.surveys.specifications.SnapshotEconomicSpecification) Service(org.springframework.stereotype.Service) CustomParameterizedException(py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException) SnapshotIndicatorPriorityService(py.org.fundacionparaguaya.pspserver.surveys.services.SnapshotIndicatorPriorityService) Logger(org.slf4j.Logger) Snapshot(py.org.fundacionparaguaya.pspserver.surveys.dtos.Snapshot) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) SnapshotIndicators(py.org.fundacionparaguaya.pspserver.surveys.dtos.SnapshotIndicators) Role(py.org.fundacionparaguaya.pspserver.security.constants.Role) PropertyTitle(py.org.fundacionparaguaya.pspserver.surveys.dtos.PropertyTitle) SurveyStoplightEnum(py.org.fundacionparaguaya.pspserver.surveys.enums.SurveyStoplightEnum) UnknownResourceException(py.org.fundacionparaguaya.pspserver.common.exceptions.UnknownResourceException) SnapshotTaken(py.org.fundacionparaguaya.pspserver.surveys.dtos.SnapshotTaken) DateTimeFormatter(java.time.format.DateTimeFormatter) SnapshotIndicatorMapper(py.org.fundacionparaguaya.pspserver.surveys.mapper.SnapshotIndicatorMapper) Transactional(org.springframework.transaction.annotation.Transactional) FamilyEntity(py.org.fundacionparaguaya.pspserver.families.entities.FamilyEntity) HashMap(java.util.HashMap) TopOfIndicators(py.org.fundacionparaguaya.pspserver.surveys.dtos.TopOfIndicators) SurveyData(py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyData)

Example 3 with SurveyData

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

the class SnapshotEconomicMapper method getAllProperties.

public SurveyData getAllProperties(StoreableSnapshot bean, List<PropertyAttributeEntity> attributes) {
    SurveyData data = new SurveyData();
    attributes.stream().forEach(makeSurveyDataWriter(bean, data));
    bean.getAdditionalProperties().entrySet().stream().forEach(a -> data.put(a.getKey(), a.getValue()));
    return data;
}
Also used : SurveyData(py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyData)

Example 4 with SurveyData

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

the class SnapshotReportManagerImpl method generateRows.

private List<List<String>> generateRows(List<SurveyData> rowsValue, List<String> headers) {
    List<List<String>> rows = new ArrayList<>();
    for (SurveyData data : rowsValue) {
        List<String> row = new ArrayList<>();
        for (String header : headers) {
            String key = StringConverter.getCamelCaseFromName(header);
            if (data.containsKey(key)) {
                if (data.getAsString(key) == null) {
                    row.add("");
                } else {
                    row.add(data.getAsString(key));
                }
            } else {
                row.add("");
            }
        }
        rows.add(row);
    }
    return rows;
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) SurveyData(py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyData)

Example 5 with SurveyData

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

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