use of py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity in project FP-PSP-SERVER by FundacionParaguaya.
the class SnapshotReportManagerImpl method listSnapshotByFamily.
@Override
public List<FamilySnapshotDTO> listSnapshotByFamily(SnapshotFilterDTO filters) {
List<FamilySnapshotDTO> toRet = new ArrayList<>();
Sort sort = new Sort(new Sort.Order(Direction.ASC, "createdAt"));
if (filters.getDateFrom() != null && filters.getDateTo() != null && filters.getFamilyId() != null) {
List<SnapshotEconomicEntity> snapshots = snapshotRepository.findAll(where(forFamily(filters.getFamilyId())).and(SnapshotEconomicSpecification.createdAtBetween2Dates(filters.getDateFrom(), filters.getDateTo())), sort);
Map<SurveyEntity, List<SnapshotEconomicEntity>> groupBySurvey = snapshots.stream().collect(Collectors.groupingBy(s -> s.getSurveyDefinition()));
groupBySurvey.forEach((k, v) -> {
FamilySnapshotDTO familySnapshots = new FamilySnapshotDTO(filters.getFamilyId(), k.getTitle());
familySnapshots.setSnapshots(getSnasphots(v));
toRet.add(familySnapshots);
});
}
return toRet;
}
use of py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity in project FP-PSP-SERVER by FundacionParaguaya.
the class FamilySpecification method createdAtBetween2Dates.
public static Specification<FamilyEntity> createdAtBetween2Dates(String dateFrom, String dateTo) {
return new Specification<FamilyEntity>() {
@Override
public Predicate toPredicate(Root<FamilyEntity> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
List<Predicate> predicates = new ArrayList<>();
if (dateFrom != null && dateTo != null) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(SHORT_DATE_FORMAT);
Subquery<SnapshotEconomicEntity> subquery = query.subquery(SnapshotEconomicEntity.class);
Root<SnapshotEconomicEntity> fromSnapshot = subquery.from(SnapshotEconomicEntity.class);
subquery.select(fromSnapshot.get(SnapshotEconomicEntity_.getFamily()).get(ID_FAMILY));
predicates.add(cb.greaterThanOrEqualTo(fromSnapshot.get(SnapshotEconomicEntity_.getCreatedAt()), LocalDate.parse(dateFrom, formatter).atStartOfDay()));
predicates.add(cb.lessThan(fromSnapshot.get(SnapshotEconomicEntity_.getCreatedAt()), LocalDate.parse(dateTo, formatter).plusDays(1).atStartOfDay()));
subquery.where(cb.and(predicates.toArray(new Predicate[predicates.size()])));
return cb.in(root.get(ID_FAMILY)).value(subquery);
}
return cb.and(predicates.toArray(new Predicate[predicates.size()]));
}
};
}
use of py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity in project FP-PSP-SERVER by FundacionParaguaya.
the class SnapshotServiceImpl method deleteSnapshotById.
@Override
public void deleteSnapshotById(Long snapshotEconomicId) {
SnapshotEconomicEntity snapshotEconomicEntity = economicRepository.findOne(snapshotEconomicId);
if (snapshotEconomicEntity == null) {
return;
}
Long familyId = null;
if (snapshotEconomicEntity.getFamily() != null) {
familyId = snapshotEconomicEntity.getFamily().getFamilyId();
}
priorityService.deletePrioritiesByIndicator(snapshotEconomicEntity.getSnapshotIndicator().getId());
economicRepository.delete(snapshotEconomicEntity);
if (familyId != null && economicRepository.findByFamilyFamilyId(familyId).size() == 0) {
familyService.deleteFamily(familyId);
}
}
use of py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity in project FP-PSP-SERVER by FundacionParaguaya.
the class OrganizationServiceImpl method countSnapshotIndicators.
private SnapshotIndicators countSnapshotIndicators(Long organizationId) {
List<FamilyEntity> families = familyService.findByOrganizationId(organizationId);
List<SnapshotEconomicEntity> snapshotEconomics = snapshotEconomicRepo.findByFamilyIn(families);
List<SnapshotIndicatorEntity> entityList = new ArrayList<SnapshotIndicatorEntity>();
for (SnapshotEconomicEntity economics : snapshotEconomics) {
entityList.add(economics.getSnapshotIndicator());
}
SnapshotIndicators indicators = new SnapshotIndicators();
List<SurveyData> listProperties = indicatorMapper.entityListToDtoList(entityList);
for (SurveyData properties : listProperties) {
properties.forEach((k, v) -> {
countIndicators(indicators, v);
});
}
return indicators;
}
use of py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity in project FP-PSP-SERVER by FundacionParaguaya.
the class SnapshotReportManagerImpl method getOrganizationAndFamilyData.
private ReportDTO getOrganizationAndFamilyData(List<SnapshotEconomicEntity> snapshots) {
ReportDTO report = new ReportDTO();
report.getHeaders().addAll(DEFAULT_HEADRES);
List<SurveyData> rows = new ArrayList<>();
report.getHeaders().addAll(snapshotMapper.getStaticPropertiesNames());
for (SnapshotEconomicEntity s : snapshots) {
s.getSnapshotIndicator().getAdditionalProperties().forEach((k, v) -> {
if (!report.getHeaders().contains(k)) {
report.getHeaders().add(StringConverter.getNameFromCamelCase(k));
}
});
SurveyData data = snapshotMapper.entityToDto(s.getSnapshotIndicator());
data.put("organizationCode", s.getFamily().getOrganization().getCode());
data.put("organizationName", s.getFamily().getOrganization().getName());
data.put("organizationStatus", s.getFamily().getOrganization().getStatus().toString());
data.put("familyCode", s.getFamily().getCode());
data.put("familyName", s.getFamily().getName());
data.put("familyStatus", s.getFamily().getStatus().toString());
data.put("snapshotCreatedAt", s.getCreatedAtLocalDateString());
rows.add(data);
}
report.setRows(generateRows(rows, report.getHeaders()));
return report;
}
Aggregations