Class DefaultUserRoleAncestryHydrationService

    • Constructor Detail

      • DefaultUserRoleAncestryHydrationService

        public DefaultUserRoleAncestryHydrationService​(UserRoleService<UserRole> userRoleService)
    • Method Detail

      • getWithAllAncestors

        public Map<String,​UserRoleAncestryHydrationResponse> getWithAllAncestors​(Collection<UserRole> roles)
        Description copied from interface: UserRoleAncestryHydrationService
        Fetches all of the given roles' ancestors from the data store and returns a result containing them and the given roles themselves.

        If a role does not have any ancestors, it will be returned by itself.

        If any broken references or cycles are found in the ancestry of a role, its response will not be UserRoleAncestryHydrationResponse.successful.

        Specified by:
        getWithAllAncestors in interface UserRoleAncestryHydrationService
        Parameters:
        roles - the roles whose ancestors should be fetched. These should be instances with their fields already fully populated (as they would be from the data store). Roles provided here are considered to be already-found and will re-appear in the result.
        Returns:
        a map from each given role's id to the hydration response for it. There is guaranteed to be an entry in this map for each given role. The response for a particular role will have it along with all of its ancestors if successful, or a description of any error that was encountered. Do note that if multiple roles share the same ancestor, each of their ancestry lists will contain the same instance of that ancestor.
      • markComplete

        protected void markComplete​(String roleIdToMarkComplete,
                                    UserRoleAncestryHydrationResponse completionResultForRole,
                                    Set<String> roleIdsToRemoveFromInProgress,
                                    Map<String,​UserRoleAncestryHydrationResponse> completed)
        Parameters:
        roleIdToMarkComplete - the id of the role which should be marked complete
        completionResultForRole - the result that the role should be completed with
        roleIdsToRemoveFromInProgress - a set containing ids of roles that should no longer be considered in-progress. The given roleIdToMarkComplete will be added to this set.
        completed - a map of completed role ids to their results. The given roleIdToMarkComplete will be put into this map with the value of completionResultForRole.
      • findInDataStoreAndReturnMissingIds

        protected Set<String> findInDataStoreAndReturnMissingIds​(Set<String> roleIdsToFind,
                                                                 Map<String,​UserRole> cacheToAddFoundTo)
        Searches the data store for roles matching the given roleIdsToFind. Roles that are found will be added to the cacheToAddFoundTo. Any ids for which roles were not found will be returned.
        Parameters:
        roleIdsToFind - the set of role ids to find in the data store
        cacheToAddFoundTo - a map of role id to role, which all found roles will be added to
        Returns:
        a set containing any ids for which roles were not found in the data store
      • attemptHydrationOfNextAncestor

        protected void attemptHydrationOfNextAncestor​(String inProgressRoleToHydrate,
                                                      UserRole highestAncestorThusFar,
                                                      List<String> ancestorIdsSeenThusFar,
                                                      Set<String> failedToFindRoleIds,
                                                      Map<String,​UserRole> foundRolesCache,
                                                      Set<String> roleIdsToRemoveFromInProgress,
                                                      Set<String> roleIdsToFindInDataStore,
                                                      Map<String,​UserRoleAncestryHydrationResponse> completed)
        Parameters:
        inProgressRoleToHydrate - the id of a role whose ancestor hydration was originally requested
        highestAncestorThusFar - the highest-level ancestor that has been successfully found for the inProgressRoleToHydrate thus far. Guaranteed to have a non-empty UserRole.parentRoleId representing the next ancestor to find.
        ancestorIdsSeenThusFar - the list (in order of lowest to highest-level) of ids of ancestors that have been successfully found for the inProgressRoleToHydrate thus far. The very last id in this list will belong to highestAncestorThusFar. If the next ancestor is found, it should be appended to this list.
        failedToFindRoleIds - the ids of roles for which a query to the data store has already been attempted, but no corresponding record was found
        foundRolesCache - all roles that have already been successfully found in the data store, mapped by their id
        roleIdsToRemoveFromInProgress - a set of role ids that will be removed from the group of roles for which ancestor hydration is considered unfinished. The inProgressRoleToHydrate is currently a member of that group, so if this method determines that it should be marked completed, it should be added to this set (in addition to being added to completed).
        roleIdsToFindInDataStore - a set of role ids that will be queried for in the data store. If a role id needs to be found in the data store, it should be added to this set. The query will be performed and the results will be reflected in failedToFindRoleIds and foundRolesCache on the next invocation of this method for inProgressRoleToHydrate.
        completed - the final map of role ids for which ancestor hydration is finished, to the result of performing that hydration. If this method determines that inProgressRoleToHydrate should be marked completed, it should be added to this map (in addition to being added to roleIdsToRemoveFromInProgress)
      • getFlattenedWithAllAncestors

        public Collection<UserRole> getFlattenedWithAllAncestors​(Collection<UserRole> roles)
        Description copied from interface: UserRoleAncestryHydrationService
        A convenience method to enable fetching a flattened collection consisting of all of the given roles along with their ancestors.

        This method should internally delegate to UserRoleAncestryHydrationService.getWithAllAncestors(Collection) to perform the actual ancestor hydration. Each role whose ancestry was not successfully hydrated will be omitted from the result, and an error will be logged for it.

        The result will be filtered for duplicates (can occur for example if an ancestor is shared by multiple roles) and thus each element should only appear once in the results.

        Specified by:
        getFlattenedWithAllAncestors in interface UserRoleAncestryHydrationService
        Parameters:
        roles - the roles whose ancestors should be fetched. These should be instances with their fields already fully populated (as they would be from the data store). Roles provided here are considered to be already-found and will re-appear in the result.
        Returns:
        a flattened collection consisting of all of the given roles along with their ancestors, excluding any roles for which ancestry hydration failed