use of py.org.fundacionparaguaya.pspserver.system.entities.CountryEntity 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;
}
use of py.org.fundacionparaguaya.pspserver.system.entities.CountryEntity in project FP-PSP-SERVER by FundacionParaguaya.
the class FamilyServiceImpl method createOrReturnFamilyFromSnapshot.
@Override
public FamilyEntity createOrReturnFamilyFromSnapshot(UserDetailsDTO details, NewSnapshot snapshot, String code, PersonEntity person) {
if (familyRepository.findByCode(code).isPresent()) {
return familyRepository.findByCode(code).get();
}
FamilyEntity newFamily = new FamilyEntity();
newFamily.setPerson(person);
newFamily.setCode(code);
newFamily.setName(person.getFirstName().concat(SPACE).concat(person.getLastName()));
newFamily.setLocationPositionGps(snapshot.getEconomicSurveyData().getAsString("familyUbication"));
if (details.getApplication() != null) {
newFamily.setApplication(applicationMapper.dtoToEntity(details.getApplication()));
}
newFamily.setActive(true);
Optional<CountryEntity> country = countryRepository.findByCountry(snapshot.getEconomicSurveyData().getAsString("familyCountry"));
newFamily.setCountry(country.orElse(null));
Optional<CityEntity> city = cityRepository.findByCity(snapshot.getEconomicSurveyData().getAsString("familyCity"));
newFamily.setCity(city.orElse(null));
if (snapshot.getOrganizationId() != null) {
OrganizationEntity organization = organizationRepository.findOne(snapshot.getOrganizationId());
newFamily.setOrganization(organization);
newFamily.setApplication(organization.getApplication());
}
newFamily = familyRepository.save(newFamily);
return newFamily;
}
use of py.org.fundacionparaguaya.pspserver.system.entities.CountryEntity in project FP-PSP-SERVER by FundacionParaguaya.
the class FamilySpecification method byFilter.
public static Specification<FamilyEntity> byFilter(FamilyFilterDTO filter) {
return new Specification<FamilyEntity>() {
@Override
public Predicate toPredicate(Root<FamilyEntity> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
List<Predicate> predicates = new ArrayList<>();
if (filter.getApplicationId() != null) {
Join<FamilyEntity, ApplicationEntity> joinApplication = root.join(FamilyEntity_.getApplication());
Expression<Long> byApplicationId = joinApplication.<Long>get(ID_ATTRIBUTE);
predicates.add(cb.equal(byApplicationId, filter.getApplicationId()));
}
if (filter.getOrganizationId() != null) {
Expression<Long> byOrganizationId = root.join(FamilyEntity_.getOrganization()).<Long>get(ID_ATTRIBUTE);
predicates.add(cb.equal(byOrganizationId, filter.getOrganizationId()));
}
if (filter.getCountryId() != null) {
Join<FamilyEntity, CountryEntity> joinCountry = root.join(FamilyEntity_.getCountry());
Expression<Long> byCountryId = joinCountry.<Long>get(ID_ATTRIBUTE);
predicates.add(cb.equal(byCountryId, filter.getCountryId()));
}
if (filter.getCityId() != null) {
Join<FamilyEntity, CityEntity> joinCity = root.join(FamilyEntity_.getCity());
Expression<Long> byCityId = joinCity.<Long>get(ID_ATTRIBUTE);
predicates.add(cb.equal(byCityId, filter.getCityId()));
}
if (StringUtils.isNotEmpty(filter.getName())) {
String nameParamQuery = "%" + filter.getName().toLowerCase().replaceAll("\\s", "%") + "%";
Expression<String> likeName = cb.lower(root.get(FamilyEntity_.getName()));
predicates.add(cb.like(likeName, nameParamQuery));
}
if (filter.getLastModifiedGt() != null) {
LocalDateTime dateTimeParam = LocalDateTime.parse(filter.getLastModifiedGt());
Predicate predicate = cb.greaterThan(root.get(FamilyEntity_.getLastModifiedAt()), dateTimeParam);
predicates.add(predicate);
}
predicates.add(cb.isTrue(root.get(FamilyEntity_.getIsActive())));
return cb.and(predicates.toArray(new Predicate[predicates.size()]));
}
};
}
Aggregations