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;
}
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;
}
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;
}
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);
}
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);
}
Aggregations