use of py.org.fundacionparaguaya.pspserver.security.dtos.UserDetailsDTO 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