use of py.org.fundacionparaguaya.pspserver.network.entities.UserApplicationEntity in project FP-PSP-SERVER by FundacionParaguaya.
the class UserDetailsServiceImpl method loadUserByUsername.
@Override
public UserDetailsDTO loadUserByUsername(String username) throws UsernameNotFoundException {
LOG.info("Loading user details: {}", username);
UserEntity user = userRepository.findOneByUsername(username).orElseThrow(() -> new UsernameNotFoundException("Username not found " + username));
List<UserRoleEntity> roles = userRoleRepo.findByUser(user);
UserApplicationEntity userApp = userApplicationRepo.findByUser(user).orElseGet(UserApplicationEntity::new);
Optional<OrganizationEntity> organization = userApp.getOrganizationOpt();
Optional<ApplicationEntity> application = userApp.getApplicationOpt();
return UserDetailsDTO.builder().username(user.getUsername()).password(user.getPass()).enabled(user.isActive()).application(application.map(applicationMapper::entityToDto).orElse(null)).organization(organization.map(organizationMapper::entityToDto).orElse(null)).grantedAuthorities(this.getGrantedAuthorities(roles)).build();
}
use of py.org.fundacionparaguaya.pspserver.network.entities.UserApplicationEntity in project FP-PSP-SERVER by FundacionParaguaya.
the class UserServiceImpl method createUserApplication.
private UserApplicationEntity createUserApplication(UserEntity user, UserRoleApplicationDTO userRoleApplicationDTO) {
UserApplicationEntity userApplicationEntity = new UserApplicationEntity();
userApplicationEntity.setUser(user);
ApplicationEntity application = applicationRepository.findById(userRoleApplicationDTO.getApplicationId());
userApplicationEntity.setApplication(application);
return userApplicationRepository.save(userApplicationEntity);
}
use of py.org.fundacionparaguaya.pspserver.network.entities.UserApplicationEntity in project FP-PSP-SERVER by FundacionParaguaya.
the class UserServiceImpl method listUsers.
@Override
public Page<UserDTO> listUsers(int page, int perPage, String orderBy, String sortBy, UserDetailsDTO userDetails) {
PageRequest pageRequest = new PspPageRequest(page, perPage, orderBy, "user." + sortBy);
Page<UserApplicationEntity> userApplicationPage = userApplicationRepository.findAll(Specifications.where(hasApplication(userDetails.getApplication())).and(hasOrganization(userDetails.getOrganization())).and(userIsActive()), pageRequest);
return userApplicationPage.map(userApplicationMapper::entityToUserDto);
}
use of py.org.fundacionparaguaya.pspserver.network.entities.UserApplicationEntity in project FP-PSP-SERVER by FundacionParaguaya.
the class UserApplicationServiceImpl method addUserApplication.
@Override
public UserApplicationDTO addUserApplication(UserApplicationDTO userApplicationDTO) {
UserApplicationEntity userApplication = new UserApplicationEntity();
BeanUtils.copyProperties(userApplicationDTO, userApplication);
UserApplicationEntity newUserApplication = userApplicationRepository.save(userApplication);
return userApplicationMapper.entityToDto(newUserApplication);
}
use of py.org.fundacionparaguaya.pspserver.network.entities.UserApplicationEntity in project FP-PSP-SERVER by FundacionParaguaya.
the class UserServiceImpl method createUserOrganization.
private UserApplicationEntity createUserOrganization(UserEntity user, UserRoleApplicationDTO userRoleApplicationDTO) {
UserApplicationEntity userApplicationEntity = new UserApplicationEntity();
userApplicationEntity.setUser(user);
OrganizationEntity organization = organizationRepository.findById(userRoleApplicationDTO.getOrganizationId());
userApplicationEntity.setOrganization(organization);
userApplicationEntity.setApplication(organization.getApplication());
return userApplicationRepository.save(userApplicationEntity);
}
Aggregations