Search in sources :

Example 1 with SnapshotIndicatorEntity

use of py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotIndicatorEntity in project FP-PSP-SERVER by FundacionParaguaya.

the class SnapshotServiceImpl method addSurveySnapshot.

@Override
@Transactional
public Snapshot addSurveySnapshot(UserDetailsDTO details, NewSnapshot snapshot) {
    checkNotNull(snapshot);
    ValidationResults results = surveyService.checkSchemaCompliance(snapshot);
    if (!results.isValid()) {
        throw new CustomParameterizedException(i18n.translate("snapshot.invalid"), results.asMap());
    }
    SnapshotIndicatorEntity indicatorEntity = economicMapper.newSnapshotToIndicatorEntity(snapshot);
    PersonEntity personEntity = personMapper.snapshotPersonalToEntity(snapshot);
    FamilyEntity family = familyService.getOrCreateFamilyFromSnapshot(details, snapshot, personEntity);
    SnapshotEconomicEntity snapshotEconomicEntity = saveEconomic(snapshot, indicatorEntity, family);
    familyService.updateFamily(family.getFamilyId());
    return economicMapper.entityToDto(snapshotEconomicEntity);
}
Also used : FamilyEntity(py.org.fundacionparaguaya.pspserver.families.entities.FamilyEntity) ValidationResults(py.org.fundacionparaguaya.pspserver.surveys.validation.ValidationResults) SnapshotEconomicEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity) CustomParameterizedException(py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException) SnapshotIndicatorEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotIndicatorEntity) PersonEntity(py.org.fundacionparaguaya.pspserver.families.entities.PersonEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with SnapshotIndicatorEntity

use of py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotIndicatorEntity in project FP-PSP-SERVER by FundacionParaguaya.

the class SnapshotIndicatorPriorityServiceImpl method addSnapshotIndicatorPriority.

@Override
@Transactional
public SnapshotIndicatorPriority addSnapshotIndicatorPriority(SnapshotIndicatorPriority priority) {
    checkArgument(priority != null, i18n.translate("argument.notNull", priority));
    checkArgument(priority.getSnapshotIndicatorId() > 0, "Argument was %s but expected nonnegative", priority.getSnapshotIndicatorId());
    if (!priority.getIsAttainment() && snapshotPriorityRepository.countAllBySnapshotIndicatorIdAndIsAttainmentFalse(priority.getSnapshotIndicatorId()) >= 5) {
        throw new CustomParameterizedException(i18n.translate("snapshotPriority.onlyFivePriorities"));
    }
    SnapshotIndicatorPriorityEntity entity = new SnapshotIndicatorPriorityEntity();
    entity.setReason(priority.getReason());
    entity.setAction(priority.getAction());
    entity.setIndicator(priority.getIndicator());
    entity.setIsAttainment(priority.getIsAttainment());
    entity.setEstimatedDateAsISOString(priority.getEstimatedDate());
    SnapshotIndicatorEntity indicator = snapshotIndicatorRepository.getOne(priority.getSnapshotIndicatorId());
    entity.setSnapshotIndicator(indicator);
    SnapshotIndicatorPriorityEntity newSnapshotIndicatorPriority = snapshotPriorityRepository.save(entity);
    // We publish this event so that other components can
    // execute some operations on other entities, like an update
    // on the familiy#lastmModifiedAt property:
    // https://github.com/FundacionParaguaya/FP-PSP-SERVER/issues/134
    // In this way we only need one extra dependency in this service.
    publisher.publishEvent(PriorityCreatedEvent.of(indicator));
    return snapshotPriorityMapper.entityToDto(newSnapshotIndicatorPriority);
}
Also used : SnapshotIndicatorPriorityEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotIndicatorPriorityEntity) CustomParameterizedException(py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException) SnapshotIndicatorEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotIndicatorEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with SnapshotIndicatorEntity

use of py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotIndicatorEntity 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;
}
Also used : FamilyEntity(py.org.fundacionparaguaya.pspserver.families.entities.FamilyEntity) SnapshotIndicators(py.org.fundacionparaguaya.pspserver.surveys.dtos.SnapshotIndicators) SnapshotEconomicEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity) ArrayList(java.util.ArrayList) SnapshotIndicatorEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotIndicatorEntity) SurveyData(py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyData)

Example 4 with SnapshotIndicatorEntity

use of py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotIndicatorEntity 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)

Aggregations

SnapshotIndicatorEntity (py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotIndicatorEntity)4 SnapshotEconomicEntity (py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity)3 Transactional (org.springframework.transaction.annotation.Transactional)2 CustomParameterizedException (py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException)2 FamilyEntity (py.org.fundacionparaguaya.pspserver.families.entities.FamilyEntity)2 ArrayList (java.util.ArrayList)1 PersonEntity (py.org.fundacionparaguaya.pspserver.families.entities.PersonEntity)1 SnapshotIndicators (py.org.fundacionparaguaya.pspserver.surveys.dtos.SnapshotIndicators)1 SurveyData (py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyData)1 SnapshotIndicatorPriorityEntity (py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotIndicatorPriorityEntity)1 ValidationResults (py.org.fundacionparaguaya.pspserver.surveys.validation.ValidationResults)1