Search in sources :

Example 16 with SnapshotEconomicEntity

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());
}
Also used : SnapshotEconomicEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity) SnapshotIndicatorEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotIndicatorEntity)

Example 17 with SnapshotEconomicEntity

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);
    });
}
Also used : LocalDateTime(java.time.LocalDateTime) SnapshotEconomicEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity) Period(java.time.Period)

Aggregations

SnapshotEconomicEntity (py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity)17 ArrayList (java.util.ArrayList)9 SnapshotIndicators (py.org.fundacionparaguaya.pspserver.surveys.dtos.SnapshotIndicators)6 SurveyData (py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyData)6 FamilyEntity (py.org.fundacionparaguaya.pspserver.families.entities.FamilyEntity)5 SnapshotIndicatorEntity (py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotIndicatorEntity)5 ReportDTO (py.org.fundacionparaguaya.pspserver.reports.dtos.ReportDTO)4 SnapshotIndicatorPriority (py.org.fundacionparaguaya.pspserver.surveys.dtos.SnapshotIndicatorPriority)4 DateTimeFormatter (java.time.format.DateTimeFormatter)3 List (java.util.List)3 Map (java.util.Map)3 Collectors (java.util.stream.Collectors)3 Specifications.where (org.springframework.data.jpa.domain.Specifications.where)3 Service (org.springframework.stereotype.Service)3 Transactional (org.springframework.transaction.annotation.Transactional)3 CustomParameterizedException (py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException)3 FamilyDTO (py.org.fundacionparaguaya.pspserver.families.dtos.FamilyDTO)3 PersonEntity (py.org.fundacionparaguaya.pspserver.families.entities.PersonEntity)3 SnapshotIndicatorMapper (py.org.fundacionparaguaya.pspserver.surveys.mapper.SnapshotIndicatorMapper)3 SnapshotEconomicRepository (py.org.fundacionparaguaya.pspserver.surveys.repositories.SnapshotEconomicRepository)3