Search in sources :

Example 1 with SnapshotEconomicEntity

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

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

the class SnapshotServiceImpl method countSnapshotTaken.

@Override
public SnapshotTaken countSnapshotTaken(FamilyFilterDTO filter) {
    List<SnapshotEconomicEntity> snapshots = getSnapshotsLess2MonthsByFamilies(filter);
    Map<String, Long> result = snapshots.stream().collect(Collectors.groupingBy(item -> item.getCreatedAt().toLocalDate().with(TemporalAdjusters.firstDayOfMonth()).format(DateTimeFormatter.ISO_DATE), Collectors.counting()));
    SnapshotTaken t = new SnapshotTaken();
    t.setByMonth(result);
    return t;
}
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) SnapshotEconomicEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity) SnapshotTaken(py.org.fundacionparaguaya.pspserver.surveys.dtos.SnapshotTaken)

Example 3 with SnapshotEconomicEntity

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

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

the class SnapshotServiceImpl method addSurveySnapshot.

@Override
@Transactional
public Snapshot addSurveySnapshot(UserDetailsDTO details, NewSnapshot snapshot) {
    checkNotNull(snapshot);
    ValidationResults results = surveyService.checkSchemaCompliance(snapshot);
    if (!results.isValid()) {
        throw new CustomParameterizedException(i18n.translate("snapshot.invalid"), results.asMap());
    }
    SnapshotIndicatorEntity indicatorEntity = economicMapper.newSnapshotToIndicatorEntity(snapshot);
    PersonEntity personEntity = personMapper.snapshotPersonalToEntity(snapshot);
    FamilyEntity family = familyService.getOrCreateFamilyFromSnapshot(details, snapshot, personEntity);
    SnapshotEconomicEntity snapshotEconomicEntity = saveEconomic(snapshot, indicatorEntity, family);
    familyService.updateFamily(family.getFamilyId());
    return economicMapper.entityToDto(snapshotEconomicEntity);
}
Also used : FamilyEntity(py.org.fundacionparaguaya.pspserver.families.entities.FamilyEntity) ValidationResults(py.org.fundacionparaguaya.pspserver.surveys.validation.ValidationResults) SnapshotEconomicEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity) CustomParameterizedException(py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException) SnapshotIndicatorEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotIndicatorEntity) PersonEntity(py.org.fundacionparaguaya.pspserver.families.entities.PersonEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with SnapshotEconomicEntity

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

the class SnapshotServiceImpl method saveEconomic.

private SnapshotEconomicEntity saveEconomic(NewSnapshot snapshot, SnapshotIndicatorEntity indicator, FamilyEntity family) {
    SnapshotEconomicEntity entity = economicMapper.newSnapshotToEconomicEntity(snapshot, indicator);
    entity.setFamily(family);
    entity.setPersonalInformation(snapshot.getPersonalSurveyData());
    return this.economicRepository.save(entity);
}
Also used : SnapshotEconomicEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity)

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