use of py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity 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.entities.SnapshotEconomicEntity 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.entities.SnapshotEconomicEntity in project FP-PSP-SERVER by FundacionParaguaya.
the class SnapshotEconomicMapper method newSnapshotToEconomicEntity.
public SnapshotEconomicEntity newSnapshotToEconomicEntity(NewSnapshot snapshot, SnapshotIndicatorEntity indicator) {
UserEntity user = null;
TermCondPolEntity termCond = null;
TermCondPolEntity privPol = null;
if (snapshot.getUserName() != null) {
user = userRepository.findOneByUsername(snapshot.getUserName()).get();
}
if (snapshot.getTermCondId() != null) {
termCond = termCondPolRepository.findOne(snapshot.getTermCondId());
}
if (snapshot.getPrivPolId() != null) {
privPol = termCondPolRepository.findOne(snapshot.getPrivPolId());
}
return new SnapshotEconomicEntity().surveyDefinition(new SurveyEntity(snapshot.getSurveyId())).surveyIndicator(indicator).staticProperties(snapshot.getMappedEconomicSurveyData(propertyAttributeSupport.staticEconomic(), propertyAttributeSupport::propertySchemaToSystemName)).additionalProperties(snapshot.getEconomicSurveyData(propertyAttributeSupport.additional())).user(user).termCond(termCond).privPol(privPol);
}
use of py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity 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;
}
use of py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity in project FP-PSP-SERVER by FundacionParaguaya.
the class SnapshotReportManagerImpl method generateCSVSnapshotByOrganizationAndCreatedDate.
@Override
public String generateCSVSnapshotByOrganizationAndCreatedDate(SnapshotFilterDTO filters) {
List<SnapshotEconomicEntity> snapshots = new ArrayList<>();
Sort sort = new Sort(new Sort.Order(Direction.ASC, "family.organization.name"), new Sort.Order(Direction.ASC, "family.name"), new Sort.Order(Direction.ASC, "createdAt"));
if (filters.getDateFrom() != null && filters.getDateTo() != null) {
Specification<SnapshotEconomicEntity> dateRange = SnapshotEconomicSpecification.createdAtBetween2Dates(filters.getDateFrom(), filters.getDateTo());
snapshots = snapshotRepository.findAll(where(SnapshotEconomicSpecification.byApplication(filters.getApplicationId())).and(dateRange).and(SnapshotEconomicSpecification.byOrganization(filters.getOrganizationId())), sort);
}
ReportDTO report = getOrganizationAndFamilyData(snapshots);
return reportToCsv(report);
}
Aggregations