Search in sources :

Example 1 with RoleNotFoundException

use of org.codenergic.theskeleton.role.RoleNotFoundException in project theskeleton by codenergic.

the class PrivilegeServiceImpl method addPrivilegeToRole.

@Override
@Transactional
public RoleEntity addPrivilegeToRole(String code, String privilegeName) {
    RoleEntity role = roleRepository.findByCode(code).orElseThrow(() -> new RoleNotFoundException(code));
    PrivilegeEntity privilege = privilegeRepository.findByName(privilegeName).orElseThrow(() -> new PrivilegeNotFoundException(privilegeName));
    return rolePrivilegeRepository.save(new RolePrivilegeEntity(role, privilege)).getRole();
}
Also used : RoleEntity(org.codenergic.theskeleton.role.RoleEntity) UserRoleEntity(org.codenergic.theskeleton.role.UserRoleEntity) RoleNotFoundException(org.codenergic.theskeleton.role.RoleNotFoundException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

RoleEntity (org.codenergic.theskeleton.role.RoleEntity)1 RoleNotFoundException (org.codenergic.theskeleton.role.RoleNotFoundException)1 UserRoleEntity (org.codenergic.theskeleton.role.UserRoleEntity)1 Transactional (org.springframework.transaction.annotation.Transactional)1