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 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 group
      roleCode - 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 group
      userId - 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.
      Specified by:
      deleteById in interface org.springframework.data.repository.CrudRepository<Group,UUID>
      Parameters:
      groupId - the ID for the group
    • existsByUserDirectoryIdAndNameIgnoreCase

      @Transactional boolean existsByUserDirectoryIdAndNameIgnoreCase(UUID userDirectoryId, String name)
      Check whether the group exists.
      Parameters:
      userDirectoryId - the ID for the user directory
      name - the name of the group
      Returns:
      true if the group exists or false otherwise
    • findByUserDirectoryId

      List<Group> findByUserDirectoryId(UUID userDirectoryId)
      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 directory
      pageable - the pagination information
      Returns:
      the groups for the user directory
    • findByUserDirectoryIdAndNameIgnoreCase

      Optional<Group> findByUserDirectoryIdAndNameIgnoreCase(UUID userDirectoryId, String name)
      Retrieve the group.
      Parameters:
      userDirectoryId - the ID for the user directory
      name - 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 directory
      filter - the filter to apply to the groups
      pageable - 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 directory
      groupId - the ID for the group
      filter - the filter to apply to the usernames
      pageable - 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 directory
      groupNames - 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 directory
      name - 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 group
      groupNames - 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 directory
      groupId - 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 directory
      groupId - the ID for the group
      pageable - 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 group
      roleCode - 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 group
      userId - 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 group
      roleCode - the code for the role
      Returns:
      true if the role to group mapping exists or false otherwise