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;
}
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);
}
}
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;
}
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;
}
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;
}
Aggregations