use of py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity in project FP-PSP-SERVER by FundacionParaguaya.
the class PriorityCreatedEventListener method getFamilyFromEvent.
private Optional<FamilyEntity> getFamilyFromEvent(PriorityCreatedEvent event) {
SnapshotIndicatorEntity indicator = event.getSnapshotIndicatorEntity();
SnapshotEconomicEntity economic = economicRepo.findBySnapshotIndicator(indicator);
return Optional.ofNullable(economic.getFamily());
}
use of py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity in project FP-PSP-SERVER by FundacionParaguaya.
the class FamilySnapshotsManagerImpl method deleteSnapshotByFamily.
@Override
public void deleteSnapshotByFamily(Long familyId) {
checkArgument(familyId > 0, i18n.translate("argument.nonNegative", familyId));
Optional.ofNullable(familyRepository.findOne(familyId)).ifPresent(family -> {
Optional.ofNullable(economicRepository.findTopByFamilyFamilyIdOrderByIdDesc(familyId)).ifPresent(snapshotEconomicEntity -> {
LocalDateTime now = LocalDateTime.now();
LocalDateTime dateOfSnapshot = snapshotEconomicEntity.getCreatedAt();
Period intervalPeriod = Period.between(dateOfSnapshot.toLocalDate(), now.toLocalDate());
if (intervalPeriod.getDays() < MAX_DAYS_DELETE_SNAPSHOT) {
SnapshotEconomicEntity snapshotEconomicEntityAux = snapshotEconomicEntity;
snapshotIndicatorPriorityRepository.delete(snapshotIndicatorPriorityRepository.findBySnapshotIndicatorId(snapshotEconomicEntity.getSnapshotIndicator().getId()));
economicRepository.delete(snapshotEconomicEntity);
snapshotIndicatorRepository.delete(snapshotEconomicEntityAux.getSnapshotIndicator());
}
});
family.setActive(false);
familyRepository.save(family);
});
}
Aggregations