Search in sources :

Example 1 with FamilyEntity

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

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

the class SnapshotServiceImpl method getTopOfIndicators.

@Override
public List<TopOfIndicators> getTopOfIndicators(Long organizationId) {
    List<FamilyEntity> families = familyService.findByOrganizationId(organizationId);
    List<SurveyData> propertiesList = indicatorMapper.entityListToDtoList(economicRepository.findByFamilyIn(families).stream().map(economic -> economic.getSnapshotIndicator()).collect(Collectors.toList()));
    Map<String, TopOfIndicators> topOfIndicatorMap = new HashMap<String, TopOfIndicators>();
    for (SurveyData surveyData : propertiesList) {
        surveyData.forEach((key, value) -> {
            countTopIndicators(topOfIndicatorMap, key, value);
        });
    }
    List<TopOfIndicators> list = topOfIndicatorMap.entrySet().stream().map(e -> new TopOfIndicators(e.getValue())).collect(Collectors.toList());
    return list;
}
Also used : SnapshotEconomicMapper(py.org.fundacionparaguaya.pspserver.surveys.mapper.SnapshotEconomicMapper) UserDetailsDTO(py.org.fundacionparaguaya.pspserver.security.dtos.UserDetailsDTO) LoggerFactory(org.slf4j.LoggerFactory) FamilyService(py.org.fundacionparaguaya.pspserver.families.services.FamilyService) SurveyData(py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyData) I18n(py.org.fundacionparaguaya.pspserver.config.I18n) StringUtils(org.apache.commons.lang3.StringUtils) UserDTO(py.org.fundacionparaguaya.pspserver.security.dtos.UserDTO) SnapshotEconomicSpecification.byApplication(py.org.fundacionparaguaya.pspserver.surveys.specifications.SnapshotEconomicSpecification.byApplication) SnapshotIndicatorPriority(py.org.fundacionparaguaya.pspserver.surveys.dtos.SnapshotIndicatorPriority) PersonMapper(py.org.fundacionparaguaya.pspserver.families.mapper.PersonMapper) Map(java.util.Map) PersonEntity(py.org.fundacionparaguaya.pspserver.families.entities.PersonEntity) NewSnapshot(py.org.fundacionparaguaya.pspserver.surveys.dtos.NewSnapshot) SnapshotService(py.org.fundacionparaguaya.pspserver.surveys.services.SnapshotService) ValidationResults(py.org.fundacionparaguaya.pspserver.surveys.validation.ValidationResults) SnapshotEconomicSpecification.createdAtLess2Months(py.org.fundacionparaguaya.pspserver.surveys.specifications.SnapshotEconomicSpecification.createdAtLess2Months) FamilyFilterDTO(py.org.fundacionparaguaya.pspserver.families.dtos.FamilyFilterDTO) Collectors(java.util.stream.Collectors) OrganizationMapper(py.org.fundacionparaguaya.pspserver.network.mapper.OrganizationMapper) SnapshotIndicatorEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotIndicatorEntity) SurveyDefinition(py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyDefinition) SnapshotEconomicRepository(py.org.fundacionparaguaya.pspserver.surveys.repositories.SnapshotEconomicRepository) List(java.util.List) SnapshotEconomicEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity) TopOfIndicators(py.org.fundacionparaguaya.pspserver.surveys.dtos.TopOfIndicators) TemporalAdjusters(java.time.temporal.TemporalAdjusters) Optional(java.util.Optional) FamilyDTO(py.org.fundacionparaguaya.pspserver.families.dtos.FamilyDTO) OrganizationRepository(py.org.fundacionparaguaya.pspserver.network.repositories.OrganizationRepository) Specifications.where(org.springframework.data.jpa.domain.Specifications.where) HashMap(java.util.HashMap) FamilyEntity(py.org.fundacionparaguaya.pspserver.families.entities.FamilyEntity) ArrayList(java.util.ArrayList) SurveyService(py.org.fundacionparaguaya.pspserver.surveys.services.SurveyService) SnapshotEconomicSpecification(py.org.fundacionparaguaya.pspserver.surveys.specifications.SnapshotEconomicSpecification) Service(org.springframework.stereotype.Service) CustomParameterizedException(py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException) SnapshotIndicatorPriorityService(py.org.fundacionparaguaya.pspserver.surveys.services.SnapshotIndicatorPriorityService) Logger(org.slf4j.Logger) Snapshot(py.org.fundacionparaguaya.pspserver.surveys.dtos.Snapshot) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) SnapshotIndicators(py.org.fundacionparaguaya.pspserver.surveys.dtos.SnapshotIndicators) Role(py.org.fundacionparaguaya.pspserver.security.constants.Role) PropertyTitle(py.org.fundacionparaguaya.pspserver.surveys.dtos.PropertyTitle) SurveyStoplightEnum(py.org.fundacionparaguaya.pspserver.surveys.enums.SurveyStoplightEnum) UnknownResourceException(py.org.fundacionparaguaya.pspserver.common.exceptions.UnknownResourceException) SnapshotTaken(py.org.fundacionparaguaya.pspserver.surveys.dtos.SnapshotTaken) DateTimeFormatter(java.time.format.DateTimeFormatter) SnapshotIndicatorMapper(py.org.fundacionparaguaya.pspserver.surveys.mapper.SnapshotIndicatorMapper) Transactional(org.springframework.transaction.annotation.Transactional) FamilyEntity(py.org.fundacionparaguaya.pspserver.families.entities.FamilyEntity) HashMap(java.util.HashMap) TopOfIndicators(py.org.fundacionparaguaya.pspserver.surveys.dtos.TopOfIndicators) SurveyData(py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyData)

Example 3 with FamilyEntity

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

the class FamilyServiceImpl method addFamily.

@Override
public FamilyDTO addFamily(FamilyDTO familyDTO) {
    FamilyEntity family = new FamilyEntity();
    BeanUtils.copyProperties(familyDTO, family);
    FamilyEntity newFamily = familyRepository.save(family);
    return familyMapper.entityToDto(newFamily);
}
Also used : FamilyEntity(py.org.fundacionparaguaya.pspserver.families.entities.FamilyEntity)

Example 4 with FamilyEntity

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

the class FamilyServiceImpl method listFamilies.

@Override
public List<FamilyDTO> listFamilies(FamilyFilterDTO filter, UserDetailsDTO userDetails) {
    FamilyFilterDTO newFilter = buildFilterFromFilterAndUser(filter, userDetails);
    List<FamilyEntity> entityList = familyRepository.findAll(where(byFilter(newFilter)));
    return familyMapper.entityListToDtoList(entityList);
}
Also used : FamilyEntity(py.org.fundacionparaguaya.pspserver.families.entities.FamilyEntity) FamilyFilterDTO(py.org.fundacionparaguaya.pspserver.families.dtos.FamilyFilterDTO)

Example 5 with FamilyEntity

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

Aggregations

FamilyEntity (py.org.fundacionparaguaya.pspserver.families.entities.FamilyEntity)9 ArrayList (java.util.ArrayList)4 SnapshotEconomicEntity (py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity)4 SurveyData (py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyData)3 SnapshotIndicatorEntity (py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotIndicatorEntity)3 List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 Specification (org.springframework.data.jpa.domain.Specification)2 Specifications.where (org.springframework.data.jpa.domain.Specifications.where)2 Service (org.springframework.stereotype.Service)2 Transactional (org.springframework.transaction.annotation.Transactional)2 CustomParameterizedException (py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException)2 UnknownResourceException (py.org.fundacionparaguaya.pspserver.common.exceptions.UnknownResourceException)2 FamilyFilterDTO (py.org.fundacionparaguaya.pspserver.families.dtos.FamilyFilterDTO)2 PersonEntity (py.org.fundacionparaguaya.pspserver.families.entities.PersonEntity)2 OrganizationEntity (py.org.fundacionparaguaya.pspserver.network.entities.OrganizationEntity)2 SnapshotIndicators (py.org.fundacionparaguaya.pspserver.surveys.dtos.SnapshotIndicators)2 ValidationResults (py.org.fundacionparaguaya.pspserver.surveys.validation.ValidationResults)2 CityEntity (py.org.fundacionparaguaya.pspserver.system.entities.CityEntity)2