Search in sources :

Example 1 with OrganizationDTO

use of py.org.fundacionparaguaya.pspserver.network.dtos.OrganizationDTO in project FP-PSP-SERVER by FundacionParaguaya.

the class ApplicationServiceImpl method getApplicationDashboard.

@Override
public ApplicationDTO getApplicationDashboard(Long applicationId, UserDetailsDTO details) {
    ApplicationDTO dto = getUserApplication(details, applicationId);
    Long organizationId = Optional.ofNullable(details.getOrganization()).orElse(new OrganizationDTO()).getId();
    FamilyFilterDTO filter = FamilyFilterDTO.builder().applicationId(dto.getId()).organizationId(organizationId).build();
    DashboardDTO dashboard = DashboardDTO.of(familyService.countFamiliesByFilter(filter), null, null, null, snapshotService.countSnapshotTaken(filter));
    dto.setDashboard(dashboard);
    return dto;
}
Also used : ApplicationDTO(py.org.fundacionparaguaya.pspserver.network.dtos.ApplicationDTO) FamilyFilterDTO(py.org.fundacionparaguaya.pspserver.families.dtos.FamilyFilterDTO) OrganizationDTO(py.org.fundacionparaguaya.pspserver.network.dtos.OrganizationDTO) DashboardDTO(py.org.fundacionparaguaya.pspserver.network.dtos.DashboardDTO)

Example 2 with OrganizationDTO

use of py.org.fundacionparaguaya.pspserver.network.dtos.OrganizationDTO in project FP-PSP-SERVER by FundacionParaguaya.

the class SurveyOrganizationServiceImpl method crudSurveyOrganization.

@Override
public void crudSurveyOrganization(UserDetailsDTO details, Long surveyId, SurveyDefinition surveyDefinition, SurveyEntity surveyEntity) {
    ApplicationEntity applicationEntity;
    SurveyOrganizationEntity surveyOrganizationEntity;
    List<SurveyOrganizationEntity> surveyOrganizationEntityList = new ArrayList<SurveyOrganizationEntity>();
    List<SurveyOrganizationEntity> tempSurveyOrganizationEntityList;
    ApplicationDTO applicationDTOCheck = details.getApplication();
    // is hub_admin
    if (applicationDTOCheck != null) {
        // deletes former organizations assigned to a survey
        repo.deleteBySurveyIdAndApplicationIdAndOrganizationIsNotNull(surveyId, applicationDTOCheck.getId());
        for (OrganizationDTO organizationDTO : surveyDefinition.getOrganizations()) {
            surveyOrganizationEntity = new SurveyOrganizationEntity();
            surveyOrganizationEntity.setOrganization(organizationRepo.findById(organizationDTO.getId()));
            surveyOrganizationEntity.setApplication(applicationRepo.findById(applicationDTOCheck.getId()));
            surveyOrganizationEntity.setSurvey(surveyEntity);
            surveyOrganizationEntityList.add(surveyOrganizationEntity);
        }
        // saves the new list of organizations assigned to a survey
        repo.save(surveyOrganizationEntityList);
    }
    // is root
    if (applicationDTOCheck == null) {
        for (ApplicationDTO applicationDTO : surveyDefinition.getApplications()) {
            // brings all associated surveys with the corresponding applications and organizations
            tempSurveyOrganizationEntityList = repo.findBySurveyIdAndApplicationId(surveyId, applicationDTO.getId());
            if (tempSurveyOrganizationEntityList != null && tempSurveyOrganizationEntityList.size() > 0) {
                surveyOrganizationEntityList.addAll(tempSurveyOrganizationEntityList);
            } else {
                applicationEntity = applicationRepo.findById(applicationDTO.getId());
                surveyOrganizationEntity = new SurveyOrganizationEntity();
                surveyOrganizationEntity.setApplication(applicationEntity);
                surveyOrganizationEntity.setSurvey(surveyEntity);
                surveyOrganizationEntityList.add(surveyOrganizationEntity);
            }
        }
        // deletes old application list
        repo.deleteBySurveyId(surveyId);
        repo.flush();
        // saves new application list
        repo.save(surveyOrganizationEntityList);
    }
}
Also used : ApplicationDTO(py.org.fundacionparaguaya.pspserver.network.dtos.ApplicationDTO) ApplicationEntity(py.org.fundacionparaguaya.pspserver.network.entities.ApplicationEntity) ArrayList(java.util.ArrayList) OrganizationDTO(py.org.fundacionparaguaya.pspserver.network.dtos.OrganizationDTO) SurveyOrganizationDTO(py.org.fundacionparaguaya.pspserver.network.dtos.SurveyOrganizationDTO) SurveyOrganizationEntity(py.org.fundacionparaguaya.pspserver.network.entities.SurveyOrganizationEntity)

Example 3 with OrganizationDTO

use of py.org.fundacionparaguaya.pspserver.network.dtos.OrganizationDTO in project FP-PSP-SERVER by FundacionParaguaya.

the class OrganizationServiceImpl method listOrganizations.

@Override
public PaginableList<OrganizationDTO> listOrganizations(Long applicationId, Long organizationId, int page, int perPage, String orderBy, String sortBy) {
    PaginableList<OrganizationDTO> response;
    PageRequest pageRequest = new PspPageRequest(page, perPage, orderBy, sortBy);
    Page<OrganizationEntity> pageResponse = organizationRepository.findAll(where(byFilter(applicationId, organizationId)), pageRequest);
    if (pageResponse == null) {
        return new PaginableList<>(Collections.emptyList());
    } else {
        Page<OrganizationDTO> organizationPage = pageResponse.map(new Converter<OrganizationEntity, OrganizationDTO>() {

            @Override
            public OrganizationDTO convert(OrganizationEntity source) {
                return organizationMapper.entityToDto(source);
            }
        });
        response = new PaginableList<OrganizationDTO>(organizationPage, organizationPage.getContent());
    }
    return response;
}
Also used : PspPageRequest(py.org.fundacionparaguaya.pspserver.common.pagination.PspPageRequest) PageRequest(org.springframework.data.domain.PageRequest) PaginableList(py.org.fundacionparaguaya.pspserver.common.pagination.PaginableList) OrganizationEntity(py.org.fundacionparaguaya.pspserver.network.entities.OrganizationEntity) PspPageRequest(py.org.fundacionparaguaya.pspserver.common.pagination.PspPageRequest) OrganizationDTO(py.org.fundacionparaguaya.pspserver.network.dtos.OrganizationDTO)

Example 4 with OrganizationDTO

use of py.org.fundacionparaguaya.pspserver.network.dtos.OrganizationDTO in project FP-PSP-SERVER by FundacionParaguaya.

the class FamilyControllerTest method getOrganizationTest.

private OrganizationDTO getOrganizationTest() {
    OrganizationDTO dto = new OrganizationDTO();
    dto.setId(new Long(1));
    dto.setName("foo.ORGANIZATION");
    return dto;
}
Also used : OrganizationDTO(py.org.fundacionparaguaya.pspserver.network.dtos.OrganizationDTO)

Example 5 with OrganizationDTO

use of py.org.fundacionparaguaya.pspserver.network.dtos.OrganizationDTO in project FP-PSP-SERVER by FundacionParaguaya.

the class SurveyServiceImpl method listSurveys.

@Override
public List<SurveyDefinition> listSurveys(UserDetailsDTO userDetails, String lastModifiedGt) {
    Long organizationId = Optional.ofNullable(userDetails.getOrganization()).orElse(new OrganizationDTO()).getId();
    Long applicationId = Optional.ofNullable(userDetails.getApplication()).orElse(new ApplicationDTO()).getId();
    if (userHasRole(userDetails, Role.ROLE_ROOT)) {
        return mapper.entityListToDtoList(repo.findAll());
    }
    List<SurveyDefinition> lista = mapper.entityListToDtoList(surveyOrganizationRepo.findAll(where(byApplication(applicationId)).and(byOrganization(organizationId)).and(lastModifiedGt(lastModifiedGt))).stream().map(e -> e.getSurvey()).collect(Collectors.toList()));
    List<SurveyDefinition> toRet = new ArrayList<>();
    for (SurveyDefinition survey : lista.stream().distinct().collect(Collectors.toList())) {
        survey.setOrganizations(organizationMapper.entityListToDtoList(surveyOrganizationRepo.findBySurveyId(survey.getId()).stream().map(o -> o.getOrganization()).collect(Collectors.toList())));
        toRet.add(survey);
    }
    return toRet;
}
Also used : OrganizationRepository(py.org.fundacionparaguaya.pspserver.network.repositories.OrganizationRepository) Specifications.where(org.springframework.data.jpa.domain.Specifications.where) UserDetailsDTO(py.org.fundacionparaguaya.pspserver.security.dtos.UserDetailsDTO) SurveyEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SurveyEntity) SurveyMapper(py.org.fundacionparaguaya.pspserver.surveys.mapper.SurveyMapper) LocalDateTime(java.time.LocalDateTime) SchemaValidator.requiredValue(py.org.fundacionparaguaya.pspserver.surveys.validation.SchemaValidator.requiredValue) ArrayList(java.util.ArrayList) SurveySchema(py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveySchema) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ApplicationDTO(py.org.fundacionparaguaya.pspserver.network.dtos.ApplicationDTO) SurveyService(py.org.fundacionparaguaya.pspserver.surveys.services.SurveyService) MultipleSchemaValidator(py.org.fundacionparaguaya.pspserver.surveys.validation.MultipleSchemaValidator) ApplicationRepository(py.org.fundacionparaguaya.pspserver.network.repositories.ApplicationRepository) Service(org.springframework.stereotype.Service) SurveyOrganizationEntity(py.org.fundacionparaguaya.pspserver.network.entities.SurveyOrganizationEntity) SurveyOrganizationService(py.org.fundacionparaguaya.pspserver.network.services.SurveyOrganizationService) PropertyValidator.validType(py.org.fundacionparaguaya.pspserver.surveys.validation.PropertyValidator.validType) CustomParameterizedException(py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException) NewSnapshot(py.org.fundacionparaguaya.pspserver.surveys.dtos.NewSnapshot) OrganizationDTO(py.org.fundacionparaguaya.pspserver.network.dtos.OrganizationDTO) Property(py.org.fundacionparaguaya.pspserver.surveys.dtos.Property) PropertyAttributeSupport(py.org.fundacionparaguaya.pspserver.surveys.mapper.PropertyAttributeSupport) ValidationResults(py.org.fundacionparaguaya.pspserver.surveys.validation.ValidationResults) SurveyOrganizationSpecification.lastModifiedGt(py.org.fundacionparaguaya.pspserver.network.specifications.SurveyOrganizationSpecification.lastModifiedGt) NewSurveyDefinition(py.org.fundacionparaguaya.pspserver.surveys.dtos.NewSurveyDefinition) MultipleSchemaValidator.all(py.org.fundacionparaguaya.pspserver.surveys.validation.MultipleSchemaValidator.all) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) SurveyRepository(py.org.fundacionparaguaya.pspserver.surveys.repositories.SurveyRepository) ValidationResult(py.org.fundacionparaguaya.pspserver.surveys.validation.ValidationResult) Role(py.org.fundacionparaguaya.pspserver.security.constants.Role) Collectors(java.util.stream.Collectors) OrganizationMapper(py.org.fundacionparaguaya.pspserver.network.mapper.OrganizationMapper) SurveyOrganizationRepository(py.org.fundacionparaguaya.pspserver.network.repositories.SurveyOrganizationRepository) SurveyDefinition(py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyDefinition) UnknownResourceException(py.org.fundacionparaguaya.pspserver.common.exceptions.UnknownResourceException) ApplicationMapper(py.org.fundacionparaguaya.pspserver.network.mapper.ApplicationMapper) List(java.util.List) StopLightType(py.org.fundacionparaguaya.pspserver.surveys.entities.StopLightType) ValidationSupport(py.org.fundacionparaguaya.pspserver.surveys.validation.ValidationSupport) SurveyOrganizationSpecification.byOrganization(py.org.fundacionparaguaya.pspserver.network.specifications.SurveyOrganizationSpecification.byOrganization) SchemaValidator.presentInSchema(py.org.fundacionparaguaya.pspserver.surveys.validation.SchemaValidator.presentInSchema) Optional(java.util.Optional) SurveyOrganizationSpecification.byApplication(py.org.fundacionparaguaya.pspserver.network.specifications.SurveyOrganizationSpecification.byApplication) SchemaValidator.markedAsRequired(py.org.fundacionparaguaya.pspserver.surveys.validation.SchemaValidator.markedAsRequired) Transactional(org.springframework.transaction.annotation.Transactional) ApplicationDTO(py.org.fundacionparaguaya.pspserver.network.dtos.ApplicationDTO) NewSurveyDefinition(py.org.fundacionparaguaya.pspserver.surveys.dtos.NewSurveyDefinition) SurveyDefinition(py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyDefinition) ArrayList(java.util.ArrayList) OrganizationDTO(py.org.fundacionparaguaya.pspserver.network.dtos.OrganizationDTO)

Aggregations

OrganizationDTO (py.org.fundacionparaguaya.pspserver.network.dtos.OrganizationDTO)9 ApplicationDTO (py.org.fundacionparaguaya.pspserver.network.dtos.ApplicationDTO)5 SurveyOrganizationEntity (py.org.fundacionparaguaya.pspserver.network.entities.SurveyOrganizationEntity)3 ArrayList (java.util.ArrayList)2 PageRequest (org.springframework.data.domain.PageRequest)2 CustomParameterizedException (py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException)2 PaginableList (py.org.fundacionparaguaya.pspserver.common.pagination.PaginableList)2 PspPageRequest (py.org.fundacionparaguaya.pspserver.common.pagination.PspPageRequest)2 FamilyFilterDTO (py.org.fundacionparaguaya.pspserver.families.dtos.FamilyFilterDTO)2 DashboardDTO (py.org.fundacionparaguaya.pspserver.network.dtos.DashboardDTO)2 NewSurveyDefinition (py.org.fundacionparaguaya.pspserver.surveys.dtos.NewSurveyDefinition)2 SurveyDefinition (py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyDefinition)2 SurveyEntity (py.org.fundacionparaguaya.pspserver.surveys.entities.SurveyEntity)2 ValidationResults (py.org.fundacionparaguaya.pspserver.surveys.validation.ValidationResults)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 LocalDateTime (java.time.LocalDateTime)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1