Class DefaultAccountMemberRoleChangeRequestHandler
java.lang.Object
com.broadleafcommerce.auth.user.service.DefaultAccountMemberRoleChangeRequestHandler
- All Implemented Interfaces:
AccountMemberRoleChangeRequestHandler
public class DefaultAccountMemberRoleChangeRequestHandler
extends Object
implements AccountMemberRoleChangeRequestHandler
Respond to
AccountMemberRoleChangeRequest
to update User roles when an Account Member's
roles are updated.- Author:
- Cade Rea (cade-rea)
-
Field Summary
-
Constructor Summary
ConstructorDescriptionDefaultAccountMemberRoleChangeRequestHandler
(UserService<User> userService, UserRoleService<UserRole> userRoleService) -
Method Summary
Modifier and TypeMethodDescriptionprotected AccountRole
buildAccountRole
(String accountId, String userId, UserRole role, boolean active) Build anAccountRole
from account id, user, and role.protected List<AccountRole>
buildAccountRolesList
(String accountId, String userId, Set<String> newRoleIdsForAccount, boolean accountIsActive) Transforms role IDs intoAccount Roles
.Get a list of role ids that all account members should receive.protected List<AccountRole>
Build the list of AccountRoles from the updated AccountMember.protected List<AccountRole>
getRolesForAccount
(List<AccountRole> accountRoles, String accountId) Get all of a user'sAccountRoles
for a particular account.protected UserRoleService<UserRole>
protected UserService<User>
void
handle
(AccountMemberRoleChangeRequest request) When an AccountMember record is updated, update the account roles on the User.protected boolean
shouldUpdateRoles
(List<AccountRole> existingRolesForAccount, List<AccountRole> newRolesForAccount) Sort the lists ofAccountRoles
by role id and then compare.
-
Field Details
-
ACCOUNT_STATUS_ACTIVE
- See Also:
-
-
Constructor Details
-
DefaultAccountMemberRoleChangeRequestHandler
public DefaultAccountMemberRoleChangeRequestHandler(UserService<User> userService, UserRoleService<UserRole> userRoleService)
-
-
Method Details
-
handle
When an AccountMember record is updated, update the account roles on the User. If an AccountMember is deleted, remove all roles the user has for that account.- Specified by:
handle
in interfaceAccountMemberRoleChangeRequestHandler
- Parameters:
request
- The AccountMemberRoleChangeRequest message.
-
getRolesForAccount
Get all of a user'sAccountRoles
for a particular account.- Parameters:
accountRoles
- The list of all of a user'sAccountRoles
.accountId
- The id of the account whose roles are being collected.- Returns:
- A filtered list of
AccountRoles
for the given account id.
-
getNewRolesForAccount
Build the list of AccountRoles from the updated AccountMember. If an AccountMember is deleted, return an empty list. If the account is not active, all AccountRoles returned will be inactive. The returned list will include the default account member roles.- Parameters:
request
- The AccountMemberRoleChangeRequest message.- Returns:
- The list of
AccountRoles
that should be assigned to theUser
.
-
shouldUpdateRoles
protected boolean shouldUpdateRoles(List<AccountRole> existingRolesForAccount, List<AccountRole> newRolesForAccount) Sort the lists ofAccountRoles
by role id and then compare.- Parameters:
existingRolesForAccount
- The list ofAccountRoles
that are already assigned to theUser
.newRolesForAccount
- The list ofAccountRoles
that theUser
should have.- Returns:
- true if the two lists do not contain the same roles.
-
getDefaultMemberRoles
Get a list of role ids that all account members should receive.- Returns:
- a list of role ids that all account members should receive.
-
buildAccountRolesList
protected List<AccountRole> buildAccountRolesList(String accountId, String userId, Set<String> newRoleIdsForAccount, boolean accountIsActive) Transforms role IDs intoAccount Roles
. This will validate that a given role id is a valid account role. This also ensures that the default account member role is present.- Parameters:
accountId
- The id of the account of which the user is getting roles.userId
- The id of theUser
that corresponds to the AccountMember that was updated.newRoleIdsForAccount
- List of role ids to assign to the user for the account.accountIsActive
- Indicates if the account is active and controls the status of new roles.- Returns:
- A list of valid
Account Roles
from the given list of role IDs.
-
buildAccountRole
protected AccountRole buildAccountRole(String accountId, String userId, UserRole role, boolean active) Build anAccountRole
from account id, user, and role.- Parameters:
accountId
- The id of the account to which the role will apply.userId
- The id of the user receiving the role.role
- The role to be assigned.active
- If the role should be created as active. This is usually true, but here just in case roles are added to a member of a deactivated account.- Returns:
- An new, non-persisted,
AccountRole
.
-
getUserService
-
getUserRoleService
-