Search in sources :

Example 1 with PersonEntity

use of py.org.fundacionparaguaya.pspserver.families.entities.PersonEntity 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 PersonEntity

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

the class PersonServiceImpl method addPerson.

@Override
public PersonDTO addPerson(PersonDTO personDTO) {
    PersonEntity person = new PersonEntity();
    BeanUtils.copyProperties(personDTO, person);
    PersonEntity newPerson = personRepository.save(person);
    return personMapper.entityToDto(newPerson);
}
Also used : PersonEntity(py.org.fundacionparaguaya.pspserver.families.entities.PersonEntity)

Example 3 with PersonEntity

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

the class PersonMapper method snapshotPersonalToEntity.

public PersonEntity snapshotPersonalToEntity(NewSnapshot snapshot) {
    SurveyData personalInformation = snapshot.getMappedPersonalSurveyData(propertyAttributeSupport.staticPersonal(), propertyAttributeSupport::propertySchemaToSystemName);
    if (personalInformation.get("birthdate") != null) {
        personalInformation.put("birthdate", LocalDate.parse(personalInformation.getAsString("birthdate"), DateTimeFormatter.ofPattern("yyyy-MM-dd")));
    }
    if (personalInformation.get("gender") != null) {
        personalInformation.put("gender", Gender.valueOf(personalInformation.getAsString("gender")));
    }
    if (personalInformation.get("countryOfBirth") != null) {
        Optional<CountryEntity> country = countryRepository.findByAlfa2Code(personalInformation.getAsString("countryOfBirth"));
        personalInformation.put("countryOfBirth", country.orElse(null));
    }
    PersonEntity pe = new PersonEntity().staticProperties(personalInformation);
    return pe;
}
Also used : SurveyData(py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyData) CountryEntity(py.org.fundacionparaguaya.pspserver.system.entities.CountryEntity) PersonEntity(py.org.fundacionparaguaya.pspserver.families.entities.PersonEntity)

Aggregations

PersonEntity (py.org.fundacionparaguaya.pspserver.families.entities.PersonEntity)3 Transactional (org.springframework.transaction.annotation.Transactional)1 CustomParameterizedException (py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException)1 FamilyEntity (py.org.fundacionparaguaya.pspserver.families.entities.FamilyEntity)1 SurveyData (py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyData)1 SnapshotEconomicEntity (py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity)1 SnapshotIndicatorEntity (py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotIndicatorEntity)1 ValidationResults (py.org.fundacionparaguaya.pspserver.surveys.validation.ValidationResults)1 CountryEntity (py.org.fundacionparaguaya.pspserver.system.entities.CountryEntity)1