Search in sources :

Example 1 with SnapshotIndicators

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

the class SnapshotServiceImpl method getLastSnapshotIndicatorsByFamily.

@Override
public SnapshotIndicators getLastSnapshotIndicatorsByFamily(Long familyId) {
    SnapshotIndicators toRet = new SnapshotIndicators();
    Optional<SnapshotEconomicEntity> snapshot = economicRepository.findFirstByFamilyFamilyIdOrderByCreatedAtDesc(familyId);
    if (snapshot.isPresent()) {
        toRet = getSnapshotIndicators(snapshot.get().getId());
    }
    return toRet;
}
Also used : SnapshotIndicators(py.org.fundacionparaguaya.pspserver.surveys.dtos.SnapshotIndicators) SnapshotEconomicEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity)

Example 2 with SnapshotIndicators

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

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

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

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

the class ApplicationControllerTest method getDashboardTest.

private DashboardDTO getDashboardTest() {
    DashboardDTO dto = new DashboardDTO();
    dto.setNumberOfFamilies(new Long(1));
    dto.setActivityFeed(new ArrayList<>());
    dto.setSnapshotIndicators(new SnapshotIndicators());
    dto.setSnapshotTaken(new SnapshotTaken());
    dto.setTopOfIndicators(new ArrayList<>());
    return dto;
}
Also used : SnapshotIndicators(py.org.fundacionparaguaya.pspserver.surveys.dtos.SnapshotIndicators) SnapshotTaken(py.org.fundacionparaguaya.pspserver.surveys.dtos.SnapshotTaken) DashboardDTO(py.org.fundacionparaguaya.pspserver.network.dtos.DashboardDTO)

Aggregations

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