Package africa.absa.inception.security
Interface GroupRepository
- All Superinterfaces:
org.springframework.data.repository.CrudRepository<Group,,UUID> org.springframework.data.jpa.repository.JpaRepository<Group,,UUID> org.springframework.data.repository.PagingAndSortingRepository<Group,,UUID> org.springframework.data.repository.query.QueryByExampleExecutor<Group>,org.springframework.data.repository.Repository<Group,UUID>
public interface GroupRepository
extends org.springframework.data.jpa.repository.JpaRepository<Group,UUID>
The GroupRepository interface declares the repository for the Group domain type.
- Author:
- Marcus Portmann
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddRoleToGroup(UUID groupId, String roleCode) Add the role to the group.voidaddUserToGroup(UUID groupId, UUID userId) Add the user to the group.voiddeleteById(UUID groupId) Delete the group.booleanexistsByUserDirectoryIdAndNameIgnoreCase(UUID userDirectoryId, String name) Check whether the group exists.findByUserDirectoryId(UUID userDirectoryId) Retrieve the groups for the user directory.org.springframework.data.domain.Page<Group>findByUserDirectoryId(UUID userDirectoryId, org.springframework.data.domain.Pageable pageable) Retrieve the groups for the user directory.findByUserDirectoryIdAndNameIgnoreCase(UUID userDirectoryId, String name) Retrieve the group.org.springframework.data.domain.Page<Group>findFiltered(UUID userDirectoryId, String filter, org.springframework.data.domain.Pageable pageable) Retrieve the filtered groups for the user directory.org.springframework.data.domain.Page<String>getFilteredUsernamesForGroup(UUID userDirectoryId, UUID groupId, String filter, org.springframework.data.domain.Pageable pageable) Retrieve the filtered usernames for the group.getFunctionCodesByUserDirectoryIdAndGroupNames(UUID userDirectoryId, List<String> groupNames) Retrieve the codes for the functions associated with the groups for the user directory.getIdByUserDirectoryIdAndNameIgnoreCase(UUID userDirectoryId, String name) Retrieve the ID for the group with the specified name for the user directory.getNamesByUserDirectoryId(UUID userDirectoryId) Retrieve the group names for the user directory.longgetNumberOfUsersForGroup(UUID groupId) Retrieve the number of users for the group.getRoleCodesByGroupId(UUID groupId) Retrieve the role codes for the group.getRoleCodesByUserDirectoryIdAndGroupNames(UUID userDirectoryId, List<String> groupNames) Retrieve the codes for the roles associated with the groups for the user directory.getUsernamesForGroup(UUID userDirectoryId, UUID groupId) Retrieve the usernames for the group.org.springframework.data.domain.Page<String>getUsernamesForGroup(UUID userDirectoryId, UUID groupId, org.springframework.data.domain.Pageable pageable) Retrieve the usernames for the group.intremoveRoleFromGroup(UUID groupId, String roleCode) Remove the role from the group.voidremoveUserFromGroup(UUID groupId, UUID userId) Remove the user from the group.booleanroleToGroupMappingExists(UUID groupId, String roleCode) Check whether the role to group mapping exists.Methods inherited from interface org.springframework.data.repository.CrudRepository
count, delete, deleteAll, deleteAll, deleteAllById, existsById, findById, saveMethods inherited from interface org.springframework.data.jpa.repository.JpaRepository
deleteAllByIdInBatch, deleteAllInBatch, deleteAllInBatch, deleteInBatch, findAll, findAll, findAll, findAll, findAllById, flush, getById, getOne, saveAll, saveAllAndFlush, saveAndFlushMethods inherited from interface org.springframework.data.repository.PagingAndSortingRepository
findAllMethods inherited from interface org.springframework.data.repository.query.QueryByExampleExecutor
count, exists, findAll, findOne
-
Method Details
-
addRoleToGroup
@Modifying @Query(value="insert into security.role_to_group_map(role_code, group_id) values (:roleCode, :groupId)", nativeQuery=true) void addRoleToGroup(@Param("groupId") UUID groupId, @Param("roleCode") String roleCode) Add the role to the group.- Parameters:
groupId- the ID for the grouproleCode- the code for the role
-
addUserToGroup
@Modifying @Query(value="insert into security.user_to_group_map(user_id, group_id) values (:userId, :groupId)", nativeQuery=true) void addUserToGroup(@Param("groupId") UUID groupId, @Param("userId") UUID userId) Add the user to the group.- Parameters:
groupId- the ID for the groupuserId- the ID for the user
-
deleteById
@Modifying @Query("delete from Group g where g.id = :groupId") void deleteById(@Param("groupId") UUID groupId) Delete the group. -
existsByUserDirectoryIdAndNameIgnoreCase
Check whether the group exists.- Parameters:
userDirectoryId- the ID for the user directoryname- the name of the group- Returns:
- true if the group exists or false otherwise
-
findByUserDirectoryId
Retrieve the groups for the user directory.- Parameters:
userDirectoryId- the ID for the user directory- Returns:
- the groups for the user directory
-
findByUserDirectoryId
org.springframework.data.domain.Page<Group> findByUserDirectoryId(UUID userDirectoryId, org.springframework.data.domain.Pageable pageable) Retrieve the groups for the user directory.- Parameters:
userDirectoryId- the ID for the user directorypageable- the pagination information- Returns:
- the groups for the user directory
-
findByUserDirectoryIdAndNameIgnoreCase
Retrieve the group.- Parameters:
userDirectoryId- the ID for the user directoryname- the name of the group- Returns:
- an Optional containing the group or an empty Optional if the group could not be found
-
findFiltered
@Query("select g from Group g where (lower(g.name) like lower(:filter)) and g.userDirectoryId = :userDirectoryId") org.springframework.data.domain.Page<Group> findFiltered(@Param("userDirectoryId") UUID userDirectoryId, @Param("filter") String filter, org.springframework.data.domain.Pageable pageable) Retrieve the filtered groups for the user directory.- Parameters:
userDirectoryId- the ID for the user directoryfilter- the filter to apply to the groupspageable- the pagination information- Returns:
- the filtered groups for the user directory
-
getFilteredUsernamesForGroup
@Query("select u.username from Group g join g.users as u where g.userDirectoryId = :userDirectoryId and g.id = :groupId and (lower(u.username) like lower(:filter))") org.springframework.data.domain.Page<String> getFilteredUsernamesForGroup(@Param("userDirectoryId") UUID userDirectoryId, @Param("groupId") UUID groupId, @Param("filter") String filter, org.springframework.data.domain.Pageable pageable) Retrieve the filtered usernames for the group.- Parameters:
userDirectoryId- the ID for the user directorygroupId- the ID for the groupfilter- the filter to apply to the usernamespageable- the pagination information- Returns:
- the filtered usernames for the group
-
getFunctionCodesByUserDirectoryIdAndGroupNames
@Query("select distinct f.code from Group g join g.roles as r join r.functions as f where g.userDirectoryId = :userDirectoryId and lower(g.name) in :groupNames") List<String> getFunctionCodesByUserDirectoryIdAndGroupNames(@Param("userDirectoryId") UUID userDirectoryId, @Param("groupNames") List<String> groupNames) Retrieve the codes for the functions associated with the groups for the user directory.- Parameters:
userDirectoryId- the ID for the user directorygroupNames- the group names- Returns:
- the function codes
-
getIdByUserDirectoryIdAndNameIgnoreCase
@Query("select g.id from Group g where g.userDirectoryId = :userDirectoryId and lower(g.name) like lower(:name)") Optional<UUID> getIdByUserDirectoryIdAndNameIgnoreCase(@Param("userDirectoryId") UUID userDirectoryId, @Param("name") String name) Retrieve the ID for the group with the specified name for the user directory.- Parameters:
userDirectoryId- the ID for the user directoryname- the group name- Returns:
- an Optional containing the ID for the group with the specified name for the user directory or an empty Optional if the group could not be found
-
getNamesByUserDirectoryId
@Query("select g.name from Group g where g.userDirectoryId = :userDirectoryId") List<String> getNamesByUserDirectoryId(@Param("userDirectoryId") UUID userDirectoryId) Retrieve the group names for the user directory.- Parameters:
userDirectoryId- the ID for the user directory- Returns:
- the group names for the user directory
-
getNumberOfUsersForGroup
@Query("select count(u.id) from Group g join g.users as u where g.id = :groupId") long getNumberOfUsersForGroup(@Param("groupId") UUID groupId) Retrieve the number of users for the group.- Parameters:
groupId- the ID for the group- Returns:
- the number of users for the group
-
getRoleCodesByGroupId
@Query("select r.code from Group g join g.roles as r where g.id = :groupId") List<String> getRoleCodesByGroupId(@Param("groupId") UUID groupId) Retrieve the role codes for the group.- Parameters:
groupId- the ID for the group- Returns:
- the role codes for the group
-
getRoleCodesByUserDirectoryIdAndGroupNames
@Query("select distinct r.code from Group g join g.roles as r where g.userDirectoryId = :userDirectoryId and lower(g.name) in :groupNames") List<String> getRoleCodesByUserDirectoryIdAndGroupNames(@Param("userDirectoryId") UUID userDirectoryId, @Param("groupNames") List<String> groupNames) Retrieve the codes for the roles associated with the groups for the user directory.- Parameters:
userDirectoryId- the ID for the groupgroupNames- the group names- Returns:
- the role codes
-
getUsernamesForGroup
@Query("select u.username from Group g join g.users as u where g.userDirectoryId = :userDirectoryId and g.id = :groupId") List<String> getUsernamesForGroup(@Param("userDirectoryId") UUID userDirectoryId, @Param("groupId") UUID groupId) Retrieve the usernames for the group.- Parameters:
userDirectoryId- the ID for the user directorygroupId- the ID for the group- Returns:
- the usernames for the group
-
getUsernamesForGroup
@Query("select u.username from Group g join g.users as u where g.userDirectoryId = :userDirectoryId and g.id = :groupId") org.springframework.data.domain.Page<String> getUsernamesForGroup(@Param("userDirectoryId") UUID userDirectoryId, @Param("groupId") UUID groupId, org.springframework.data.domain.Pageable pageable) Retrieve the usernames for the group.- Parameters:
userDirectoryId- the ID for the user directorygroupId- the ID for the grouppageable- the pagination information- Returns:
- the usernames for the group
-
removeRoleFromGroup
@Modifying @Query(value="delete from security.role_to_group_map where group_id=:groupId and role_code = :roleCode", nativeQuery=true) int removeRoleFromGroup(@Param("groupId") UUID groupId, @Param("roleCode") String roleCode) Remove the role from the group.- Parameters:
groupId- the ID for the grouproleCode- the code for the role- Returns:
- the number of impacted role to group mappings
-
removeUserFromGroup
@Modifying @Query(value="delete from security.user_to_group_map where group_id=:groupId and user_id = :userId", nativeQuery=true) void removeUserFromGroup(@Param("groupId") UUID groupId, @Param("userId") UUID userId) Remove the user from the group.- Parameters:
groupId- the ID for the groupuserId- the ID for the user
-
roleToGroupMappingExists
@Query(value="select (count(role_code) > 0) from security.role_to_group_map where role_code = :roleCode and group_id = :groupId", nativeQuery=true) boolean roleToGroupMappingExists(@Param("groupId") UUID groupId, @Param("roleCode") String roleCode) Check whether the role to group mapping exists.- Parameters:
groupId- the ID for the grouproleCode- the code for the role- Returns:
- true if the role to group mapping exists or false otherwise
-