public class DefaultUserRoleAncestryHydrationService extends Object implements UserRoleAncestryHydrationService
Constructor and Description |
---|
DefaultUserRoleAncestryHydrationService(UserRoleService<UserRole> userRoleService) |
Modifier and Type | Method and Description |
---|---|
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) |
protected Set<String> |
findInDataStoreAndReturnMissingIds(Set<String> roleIdsToFind,
Map<String,UserRole> cacheToAddFoundTo)
Searches the data store for roles matching the given
roleIdsToFind . |
Collection<UserRole> |
getFlattenedWithAllAncestors(Collection<UserRole> roles)
A convenience method to enable fetching a flattened collection consisting of all of the given
roles along with their ancestors.
|
Collection<UserRole> |
getFlattenedWithAllAncestorsAndThrowIfAnyFailed(Collection<UserRole> roles)
Same logic as documented for
UserRoleAncestryHydrationService.getFlattenedWithAllAncestors(Collection) except this
method throws an exception when there's one or more UserRoleAncestryHydrationResponse
not successful. |
protected List<UserRoleAncestryHydrationResponse> |
getSuccessfulAndLogErrors(@NonNull Map<String,UserRoleAncestryHydrationResponse> responses)
A convenient method to process the response from
getWithAllAncestors(Collection) by
logging errors on all roles which failed hydration and returning only the successful
responses. |
protected UserRoleService<UserRole> |
getUserRoleService() |
Map<String,UserRoleAncestryHydrationResponse> |
getWithAllAncestors(Collection<UserRole> roles)
Fetches all of the given roles' ancestors from the data store and returns a result containing
them and the given roles themselves.
|
Map<String,Collection<UserRole>> |
getWithAllAncestorsByRoleIdAndThrowIfAnyFailed(Collection<UserRole> roles)
Same logic as documented for
UserRoleAncestryHydrationService.getWithAllAncestors(Collection) except this method
throws an exception when there's one or more UserRoleAncestryHydrationResponse not
successful, and the value of the map is a collection of the given roles along with their
ancestors mapped by the given role id. |
protected void |
markComplete(String roleIdToMarkComplete,
UserRoleAncestryHydrationResponse completionResultForRole,
Set<String> roleIdsToRemoveFromInProgress,
Map<String,UserRoleAncestryHydrationResponse> completed) |
public DefaultUserRoleAncestryHydrationService(UserRoleService<UserRole> userRoleService)
public Map<String,UserRoleAncestryHydrationResponse> getWithAllAncestors(Collection<UserRole> roles)
UserRoleAncestryHydrationService
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
.
getWithAllAncestors
in interface UserRoleAncestryHydrationService
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.protected void markComplete(String roleIdToMarkComplete, UserRoleAncestryHydrationResponse completionResultForRole, Set<String> roleIdsToRemoveFromInProgress, Map<String,UserRoleAncestryHydrationResponse> completed)
roleIdToMarkComplete
- the id of the role which should be marked completecompletionResultForRole
- the result that the role should be completed withroleIdsToRemoveFromInProgress
- 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
.protected Set<String> findInDataStoreAndReturnMissingIds(Set<String> roleIdsToFind, Map<String,UserRole> cacheToAddFoundTo)
roleIdsToFind
. Roles that are
found will be added to the cacheToAddFoundTo
. Any ids for which roles were not found
will be returned.roleIdsToFind
- the set of role ids to find in the data storecacheToAddFoundTo
- a map of role id to role, which all found roles will be added toprotected 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)
inProgressRoleToHydrate
- the id of a role whose ancestor hydration was originally
requestedhighestAncestorThusFar
- 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 foundfoundRolesCache
- all roles that have already been successfully found in the data store,
mapped by their idroleIdsToRemoveFromInProgress
- 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
)public Map<String,Collection<UserRole>> getWithAllAncestorsByRoleIdAndThrowIfAnyFailed(Collection<UserRole> roles)
UserRoleAncestryHydrationService
UserRoleAncestryHydrationService.getWithAllAncestors(Collection)
except this method
throws an exception when there's one or more UserRoleAncestryHydrationResponse
not
successful, and the value of the map is a collection of the given roles along with their
ancestors mapped by the given role id.getWithAllAncestorsByRoleIdAndThrowIfAnyFailed
in interface UserRoleAncestryHydrationService
roles
- a collection of roles to get along with its ancestorspublic Collection<UserRole> getFlattenedWithAllAncestors(Collection<UserRole> roles)
UserRoleAncestryHydrationService
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.
getFlattenedWithAllAncestors
in interface UserRoleAncestryHydrationService
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.public Collection<UserRole> getFlattenedWithAllAncestorsAndThrowIfAnyFailed(Collection<UserRole> roles)
UserRoleAncestryHydrationService
UserRoleAncestryHydrationService.getFlattenedWithAllAncestors(Collection)
except this
method throws an exception when there's one or more UserRoleAncestryHydrationResponse
not successful.getFlattenedWithAllAncestorsAndThrowIfAnyFailed
in interface UserRoleAncestryHydrationService
roles
- a collection of roles to get along with its ancestorsprotected List<UserRoleAncestryHydrationResponse> getSuccessfulAndLogErrors(@NonNull @NonNull Map<String,UserRoleAncestryHydrationResponse> responses)
getWithAllAncestors(Collection)
by
logging errors on all roles which failed hydration and returning only the successful
responses.responses
- the responses returned by getWithAllAncestors(Collection)
UserRoleAncestryHydrationResponse.successful
protected UserRoleService<UserRole> getUserRoleService()
Copyright © 2021. All rights reserved.