Search in sources :

Example 1 with SurveyEntity

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

the class SnapshotEconomicMapper method newSnapshotToEconomicEntity.

public SnapshotEconomicEntity newSnapshotToEconomicEntity(NewSnapshot snapshot, SnapshotIndicatorEntity indicator) {
    UserEntity user = null;
    TermCondPolEntity termCond = null;
    TermCondPolEntity privPol = null;
    if (snapshot.getUserName() != null) {
        user = userRepository.findOneByUsername(snapshot.getUserName()).get();
    }
    if (snapshot.getTermCondId() != null) {
        termCond = termCondPolRepository.findOne(snapshot.getTermCondId());
    }
    if (snapshot.getPrivPolId() != null) {
        privPol = termCondPolRepository.findOne(snapshot.getPrivPolId());
    }
    return new SnapshotEconomicEntity().surveyDefinition(new SurveyEntity(snapshot.getSurveyId())).surveyIndicator(indicator).staticProperties(snapshot.getMappedEconomicSurveyData(propertyAttributeSupport.staticEconomic(), propertyAttributeSupport::propertySchemaToSystemName)).additionalProperties(snapshot.getEconomicSurveyData(propertyAttributeSupport.additional())).user(user).termCond(termCond).privPol(privPol);
}
Also used : SnapshotEconomicEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity) SurveyEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SurveyEntity) UserEntity(py.org.fundacionparaguaya.pspserver.security.entities.UserEntity) TermCondPolEntity(py.org.fundacionparaguaya.pspserver.security.entities.TermCondPolEntity)

Example 2 with SurveyEntity

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

the class SnapshotReportManagerImpl method listSnapshotByFamily.

@Override
public List<FamilySnapshotDTO> listSnapshotByFamily(SnapshotFilterDTO filters) {
    List<FamilySnapshotDTO> toRet = new ArrayList<>();
    Sort sort = new Sort(new Sort.Order(Direction.ASC, "createdAt"));
    if (filters.getDateFrom() != null && filters.getDateTo() != null && filters.getFamilyId() != null) {
        List<SnapshotEconomicEntity> snapshots = snapshotRepository.findAll(where(forFamily(filters.getFamilyId())).and(SnapshotEconomicSpecification.createdAtBetween2Dates(filters.getDateFrom(), filters.getDateTo())), sort);
        Map<SurveyEntity, List<SnapshotEconomicEntity>> groupBySurvey = snapshots.stream().collect(Collectors.groupingBy(s -> s.getSurveyDefinition()));
        groupBySurvey.forEach((k, v) -> {
            FamilySnapshotDTO familySnapshots = new FamilySnapshotDTO(filters.getFamilyId(), k.getTitle());
            familySnapshots.setSnapshots(getSnasphots(v));
            toRet.add(familySnapshots);
        });
    }
    return toRet;
}
Also used : Specifications.where(org.springframework.data.jpa.domain.Specifications.where) Arrays(java.util.Arrays) FamilyRepository(py.org.fundacionparaguaya.pspserver.families.repositories.FamilyRepository) SurveyEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SurveyEntity) SnapshotFilterDTO(py.org.fundacionparaguaya.pspserver.reports.dtos.SnapshotFilterDTO) FamilySpecification.byOrganization(py.org.fundacionparaguaya.pspserver.families.specifications.FamilySpecification.byOrganization) SurveyData(py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyData) OrganizationFamilyDTO(py.org.fundacionparaguaya.pspserver.reports.dtos.OrganizationFamilyDTO) FamilyEntity(py.org.fundacionparaguaya.pspserver.families.entities.FamilyEntity) ArrayList(java.util.ArrayList) SnapshotEconomicSpecification(py.org.fundacionparaguaya.pspserver.surveys.specifications.SnapshotEconomicSpecification) Service(org.springframework.stereotype.Service) Map(java.util.Map) Sort(org.springframework.data.domain.Sort) Direction(org.springframework.data.domain.Sort.Direction) SnapshotReportManager(py.org.fundacionparaguaya.pspserver.reports.services.SnapshotReportManager) OrganizationEntity(py.org.fundacionparaguaya.pspserver.network.entities.OrganizationEntity) ReportDTO(py.org.fundacionparaguaya.pspserver.reports.dtos.ReportDTO) StringConverter(py.org.fundacionparaguaya.pspserver.common.utils.StringConverter) FamilySnapshotDTO(py.org.fundacionparaguaya.pspserver.reports.dtos.FamilySnapshotDTO) Collectors(java.util.stream.Collectors) FamilyDTOMapper(py.org.fundacionparaguaya.pspserver.reports.mapper.FamilyDTOMapper) SnapshotEconomicRepository(py.org.fundacionparaguaya.pspserver.surveys.repositories.SnapshotEconomicRepository) List(java.util.List) SnapshotEconomicEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity) FamilySpecification(py.org.fundacionparaguaya.pspserver.families.specifications.FamilySpecification) Specification(org.springframework.data.jpa.domain.Specification) FamilySpecification.byApplication(py.org.fundacionparaguaya.pspserver.families.specifications.FamilySpecification.byApplication) SnapshotIndicatorMapper(py.org.fundacionparaguaya.pspserver.surveys.mapper.SnapshotIndicatorMapper) SnapshotEconomicSpecification.forFamily(py.org.fundacionparaguaya.pspserver.surveys.specifications.SnapshotEconomicSpecification.forFamily) FamilySnapshotDTO(py.org.fundacionparaguaya.pspserver.reports.dtos.FamilySnapshotDTO) SnapshotEconomicEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity) SurveyEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SurveyEntity) ArrayList(java.util.ArrayList) Sort(org.springframework.data.domain.Sort) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with SurveyEntity

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

the class SurveyServiceImpl method addSurveyDefinition.

@Override
public SurveyDefinition addSurveyDefinition(NewSurveyDefinition surveyDefinition) {
    ValidationResults results = validateSchemas(surveyDefinition);
    if (!results.isValid()) {
        throw new CustomParameterizedException("Invalid Survey Schema", results.asMap());
    }
    SurveyEntity entity = this.repo.save(SurveyEntity.of(surveyDefinition.getTitle(), surveyDefinition.getDescription(), new SurveyDefinition().surveySchema(surveyDefinition.getSurveySchema()).surveyUISchema(surveyDefinition.getSurveyUISchema())));
    if (surveyDefinition.getOrganizations() != null && surveyDefinition.getOrganizations().size() > 0) {
        for (OrganizationDTO organization : surveyDefinition.getOrganizations()) {
            if (surveyOrganizationRepo.findBySurveyIdAndApplicationIdAndOrganizationId(entity.getId(), organization.getApplication().getId(), organization.getId()) == null) {
                SurveyOrganizationEntity surveyOrganization = new SurveyOrganizationEntity();
                surveyOrganization.setSurvey(entity);
                surveyOrganization.setApplication(applicationRepo.findById(organization.getApplication().getId()));
                surveyOrganization.setOrganization(organizationRepo.findById(organization.getId()));
                surveyOrganizationRepo.save(surveyOrganization);
            }
        }
    }
    if (surveyDefinition.getApplications() != null) {
        for (ApplicationDTO application : surveyDefinition.getApplications()) {
            SurveyOrganizationEntity surveyOrganization = new SurveyOrganizationEntity();
            surveyOrganization.setSurvey(entity);
            surveyOrganization.setApplication(applicationRepo.findById(application.getId()));
            surveyOrganizationRepo.save(surveyOrganization);
        }
    }
    return new SurveyDefinition().id(entity.getId()).title(entity.getTitle()).description(entity.getDescription()).surveySchema(entity.getSurveyDefinition().getSurveySchema()).surveyUISchema(entity.getSurveyDefinition().getSurveyUISchema()).organizations(surveyDefinition.getOrganizations());
}
Also used : ApplicationDTO(py.org.fundacionparaguaya.pspserver.network.dtos.ApplicationDTO) ValidationResults(py.org.fundacionparaguaya.pspserver.surveys.validation.ValidationResults) SurveyEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SurveyEntity) CustomParameterizedException(py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException) NewSurveyDefinition(py.org.fundacionparaguaya.pspserver.surveys.dtos.NewSurveyDefinition) SurveyDefinition(py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyDefinition) OrganizationDTO(py.org.fundacionparaguaya.pspserver.network.dtos.OrganizationDTO) SurveyOrganizationEntity(py.org.fundacionparaguaya.pspserver.network.entities.SurveyOrganizationEntity)

Aggregations

SurveyEntity (py.org.fundacionparaguaya.pspserver.surveys.entities.SurveyEntity)3 SnapshotEconomicEntity (py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Sort (org.springframework.data.domain.Sort)1 Direction (org.springframework.data.domain.Sort.Direction)1 Specification (org.springframework.data.jpa.domain.Specification)1 Specifications.where (org.springframework.data.jpa.domain.Specifications.where)1 Service (org.springframework.stereotype.Service)1 CustomParameterizedException (py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException)1 StringConverter (py.org.fundacionparaguaya.pspserver.common.utils.StringConverter)1 FamilyEntity (py.org.fundacionparaguaya.pspserver.families.entities.FamilyEntity)1 FamilyRepository (py.org.fundacionparaguaya.pspserver.families.repositories.FamilyRepository)1 FamilySpecification (py.org.fundacionparaguaya.pspserver.families.specifications.FamilySpecification)1 FamilySpecification.byApplication (py.org.fundacionparaguaya.pspserver.families.specifications.FamilySpecification.byApplication)1 FamilySpecification.byOrganization (py.org.fundacionparaguaya.pspserver.families.specifications.FamilySpecification.byOrganization)1 ApplicationDTO (py.org.fundacionparaguaya.pspserver.network.dtos.ApplicationDTO)1