Search in sources :

Example 6 with ApplicationDTO

use of py.org.fundacionparaguaya.pspserver.network.dtos.ApplicationDTO 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)

Example 7 with ApplicationDTO

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

the class FamilyControllerTest method getApplcationTest.

private ApplicationDTO getApplcationTest() {
    ApplicationDTO dto = new ApplicationDTO();
    dto.setId(new Long(1));
    dto.setName("foo.APPLICATION");
    // ...
    return dto;
}
Also used : ApplicationDTO(py.org.fundacionparaguaya.pspserver.network.dtos.ApplicationDTO)

Example 8 with ApplicationDTO

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

the class ApplicationController method deleteApplication.

@DeleteMapping("/{applicationId}")
public ResponseEntity<ApplicationDTO> deleteApplication(@PathVariable("applicationId") Long applicationId) {
    LOG.debug("REST request to delete Application: {}", applicationId);
    ApplicationDTO dto = applicationService.deleteApplication(applicationId);
    return ResponseEntity.accepted().body(dto);
}
Also used : ApplicationDTO(py.org.fundacionparaguaya.pspserver.network.dtos.ApplicationDTO) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping)

Example 9 with ApplicationDTO

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

the class ApplicationServiceImpl method listApplicationsHubs.

@Override
public PaginableList<ApplicationDTO> listApplicationsHubs(int page, int perPage, String orderBy, String sortBy) {
    PageRequest pageRequest = new PspPageRequest(page, perPage, orderBy, sortBy);
    Page<ApplicationEntity> pageResponse = applicationRepository.findAllByIsHub(true, pageRequest);
    if (pageResponse == null) {
        return new PaginableList<ApplicationDTO>(Collections.emptyList());
    }
    Page<ApplicationDTO> applicationPage = pageResponse.map(new Converter<ApplicationEntity, ApplicationDTO>() {

        public ApplicationDTO convert(ApplicationEntity source) {
            return applicationMapper.entityToDto(source);
        }
    });
    return new PaginableList<ApplicationDTO>(applicationPage, applicationPage.getContent());
}
Also used : ApplicationDTO(py.org.fundacionparaguaya.pspserver.network.dtos.ApplicationDTO) PspPageRequest(py.org.fundacionparaguaya.pspserver.common.pagination.PspPageRequest) PageRequest(org.springframework.data.domain.PageRequest) PaginableList(py.org.fundacionparaguaya.pspserver.common.pagination.PaginableList) PspPageRequest(py.org.fundacionparaguaya.pspserver.common.pagination.PspPageRequest) ApplicationEntity(py.org.fundacionparaguaya.pspserver.network.entities.ApplicationEntity)

Example 10 with ApplicationDTO

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

the class OrganizationServiceImpl method getOrganizationDashboard.

@Override
public OrganizationDTO getOrganizationDashboard(Long organizationId, UserDetailsDTO details) {
    OrganizationDTO dto = new OrganizationDTO();
    if (details.getOrganization() != null && details.getOrganization().getId() != null) {
        dto = getOrganizationById(details.getOrganization().getId());
    } else if (organizationId != null) {
        dto = getOrganizationById(organizationId);
    }
    Long applicationId = Optional.ofNullable(details.getApplication()).orElse(new ApplicationDTO()).getId();
    FamilyFilterDTO filter = FamilyFilterDTO.builder().applicationId(applicationId).organizationId(dto.getId()).build();
    DashboardDTO dashboard = DashboardDTO.of(familyService.countFamiliesByFilter(filter), null, snapshotServiceImpl.getTopOfIndicators(organizationId), countSnapshotIndicators(organizationId), null);
    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)

Aggregations

ApplicationDTO (py.org.fundacionparaguaya.pspserver.network.dtos.ApplicationDTO)10 OrganizationDTO (py.org.fundacionparaguaya.pspserver.network.dtos.OrganizationDTO)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 ApplicationEntity (py.org.fundacionparaguaya.pspserver.network.entities.ApplicationEntity)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