use of py.org.fundacionparaguaya.pspserver.network.dtos.ApplicationDTO in project FP-PSP-SERVER by FundacionParaguaya.
the class ApplicationController method getPaginatedApplications.
@GetMapping()
public ResponseEntity<PaginableList<ApplicationDTO>> getPaginatedApplications(@RequestParam(value = "page", required = false, defaultValue = "1") int page, @RequestParam(value = "per_page", required = false, defaultValue = "12") int perPage, @RequestParam(value = "sort_by", required = false, defaultValue = "name") String sortBy, @RequestParam(value = "order", required = false, defaultValue = "asc") String orderBy, @RequestParam(value = "filter", required = false, defaultValue = "") String filter, @AuthenticationPrincipal UserDetailsDTO userDetails) {
PageRequest pageRequest = new PspPageRequest(page, perPage, orderBy, sortBy);
Page<ApplicationDTO> pageProperties = applicationService.getPaginatedApplications(userDetails, filter, pageRequest);
PaginableList<ApplicationDTO> response = new PaginableList<>(pageProperties, pageProperties.getContent());
return ResponseEntity.ok(response);
}
use of py.org.fundacionparaguaya.pspserver.network.dtos.ApplicationDTO 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;
}
use of py.org.fundacionparaguaya.pspserver.network.dtos.ApplicationDTO 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);
}
}
use of py.org.fundacionparaguaya.pspserver.network.dtos.ApplicationDTO in project FP-PSP-SERVER by FundacionParaguaya.
the class OrganizationControllerITest method getApplicationTest.
private ApplicationDTO getApplicationTest() {
ApplicationDTO dto = new ApplicationDTO();
dto.setId(new Long(1));
dto.setDescription("foo.APPLICATION");
return dto;
}
use of py.org.fundacionparaguaya.pspserver.network.dtos.ApplicationDTO 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;
}
Aggregations