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