Search in sources :

Example 1 with UserApplicationEntity

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();
}
Also used : UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) UserRoleEntity(py.org.fundacionparaguaya.pspserver.security.entities.UserRoleEntity) OrganizationEntity(py.org.fundacionparaguaya.pspserver.network.entities.OrganizationEntity) ApplicationEntity(py.org.fundacionparaguaya.pspserver.network.entities.ApplicationEntity) UserApplicationEntity(py.org.fundacionparaguaya.pspserver.network.entities.UserApplicationEntity) UserApplicationEntity(py.org.fundacionparaguaya.pspserver.network.entities.UserApplicationEntity) UserEntity(py.org.fundacionparaguaya.pspserver.security.entities.UserEntity)

Example 2 with UserApplicationEntity

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);
}
Also used : ApplicationEntity(py.org.fundacionparaguaya.pspserver.network.entities.ApplicationEntity) UserApplicationEntity(py.org.fundacionparaguaya.pspserver.network.entities.UserApplicationEntity) UserApplicationEntity(py.org.fundacionparaguaya.pspserver.network.entities.UserApplicationEntity)

Example 3 with 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);
}
Also used : PspPageRequest(py.org.fundacionparaguaya.pspserver.common.pagination.PspPageRequest) PageRequest(org.springframework.data.domain.PageRequest) PspPageRequest(py.org.fundacionparaguaya.pspserver.common.pagination.PspPageRequest) UserApplicationEntity(py.org.fundacionparaguaya.pspserver.network.entities.UserApplicationEntity)

Example 4 with UserApplicationEntity

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);
}
Also used : UserApplicationEntity(py.org.fundacionparaguaya.pspserver.network.entities.UserApplicationEntity)

Example 5 with UserApplicationEntity

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);
}
Also used : OrganizationEntity(py.org.fundacionparaguaya.pspserver.network.entities.OrganizationEntity) UserApplicationEntity(py.org.fundacionparaguaya.pspserver.network.entities.UserApplicationEntity)

Aggregations

UserApplicationEntity (py.org.fundacionparaguaya.pspserver.network.entities.UserApplicationEntity)5 ApplicationEntity (py.org.fundacionparaguaya.pspserver.network.entities.ApplicationEntity)2 OrganizationEntity (py.org.fundacionparaguaya.pspserver.network.entities.OrganizationEntity)2 PageRequest (org.springframework.data.domain.PageRequest)1 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)1 PspPageRequest (py.org.fundacionparaguaya.pspserver.common.pagination.PspPageRequest)1 UserEntity (py.org.fundacionparaguaya.pspserver.security.entities.UserEntity)1 UserRoleEntity (py.org.fundacionparaguaya.pspserver.security.entities.UserRoleEntity)1