use of py.org.fundacionparaguaya.pspserver.network.dtos.OrganizationDTO 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());
}
use of py.org.fundacionparaguaya.pspserver.network.dtos.OrganizationDTO in project FP-PSP-SERVER by FundacionParaguaya.
the class OrganizationController method getAllOrganizations.
@GetMapping()
public ResponseEntity<PaginableList<OrganizationDTO>> getAllOrganizations(@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<OrganizationDTO> pageProperties = organizationService.listOrganizations(userDetails, filter, pageRequest);
PaginableList<OrganizationDTO> response = new PaginableList<>(pageProperties, pageProperties.getContent());
return ResponseEntity.ok(response);
}
use of py.org.fundacionparaguaya.pspserver.network.dtos.OrganizationDTO in project FP-PSP-SERVER by FundacionParaguaya.
the class OrganizationController method deleteOrganization.
@DeleteMapping("/{organizationId}")
public ResponseEntity<OrganizationDTO> deleteOrganization(@PathVariable("organizationId") Long organizationId) {
LOG.debug("REST request to delete Organization: {}", organizationId);
OrganizationDTO dto = organizationService.deleteOrganization(organizationId);
return ResponseEntity.accepted().body(dto);
}
use of py.org.fundacionparaguaya.pspserver.network.dtos.OrganizationDTO 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;
}
Aggregations