Class DefaultAccountMemberService<M extends AccountMember>
java.lang.Object
com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P>
com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService<M>
com.broadleafcommerce.customer.service.DefaultAccountMemberService<M>
- All Implemented Interfaces:
AccountMemberService<M>
,com.broadleafcommerce.data.tracking.core.service.CrudEntityService<M>
,com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityService<M>
public class DefaultAccountMemberService<M extends AccountMember>
extends com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService<M>
implements AccountMemberService<M>
Default implementation of the
AccountMemberService
.- Author:
- Chris Kittrell (ckittrell)
-
Field Summary
-
Constructor Summary
ConstructorDescriptionDefaultAccountMemberService
(AccountMemberRepository<com.broadleafcommerce.data.tracking.core.Trackable> repository, AccountService<Account> accountService, CustomerService<Customer> customerService, com.broadleafcommerce.common.extension.TypeFactory typeFactory, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper helper, AccountMemberRoleChangeProducer accountMemberRoleChangeProducer) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
checkExistingAccount
(String accountId, @NonNull RegisterAccountMemberRequest registerRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected M
createAccountMember
(@NonNull RegisterAccountMemberRequest registerRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Create anAccountMember
based on theRegisterAccountMemberRequest
protected AccountRef
createAccountRefFromAccount
(@NonNull Account account) createActiveFromInviteAndCustomer
(@NonNull Customer customer, String accountId, @NonNull AccountInviteRequest accountInviteRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Creates an activeAccountMember
from the given invite request and customer.protected CustomerRef
createCustomerRefFromCustomer
(@NonNull Customer customer) createInactiveFromAccountInvite
(@NonNull AccountInvite accountInvite, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) createInactiveFromAccountInviteAndCustomer
(@NonNull AccountInvite accountInvite, @NonNull Customer customer, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Create an account member from an account invitation and customer.void
protected AccountMemberRoleChangeProducer
protected AccountService<Account>
protected Account
getAccountWithId
(@NonNull AccountRef accountRef) protected Customer
getCustomer
(@NonNull RegisterAccountMemberRequest registerRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Returns the customer to associate with the account.protected CustomerService<Customer>
protected Customer
getCustomerWithId
(@NonNull CustomerRef customerRef) protected AccountMemberRepository<com.broadleafcommerce.data.tracking.core.Trackable>
protected com.broadleafcommerce.common.extension.TypeFactory
protected boolean
hasUpdatedRole
(@NonNull UpdateAccountMemberRequest updateRequest, M accountMember) void
Hydrates the relationships onto theAccountMember
.Hydrates the relationships onto theAccountMember
.protected M
hydrateAccount
(M accountMember, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Hydrates theAccount
onto theAccountMember
.org.springframework.data.domain.Page<M>
hydrateAll
(@NonNull org.springframework.data.domain.Page<M> accountMembers, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Hydrates the relationships onto theAccountMembers
.protected M
hydrateCustomer
(M accountMember, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Hydrates theCustomer
onto theAccountMember
.protected void
notifyAccountMemberRoleChange
(M accountMember, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) protected void
notifyAccountMemberRoleChange
(M accountMember, com.broadleafcommerce.data.tracking.core.context.ContextInfo context, boolean isDelete) Send anAccountMemberRoleChangeRequest
with theAccountMemberRoleChangeProducer
.readActiveByCustomerId
(String customerId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Read account memberships for a customer where the membership is active.org.springframework.data.domain.Page<M>
readActiveByCustomerId
(String customerId, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Read account memberships for a customer where the membership is active.org.springframework.data.domain.Page<M>
readAllByAccountId
(String accountId, cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Reads all of the AccountMember relationships in the database associated with the given account context ID.org.springframework.data.domain.Page<M>
readAllByAccountIdAndActiveTrue
(@NonNull String accountId, cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) org.springframework.data.domain.Page<M>
readByCustomerId
(String customerId, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Read account memberships for a customer.readByCustomerIdAndAccountId
(String customerId, String accountId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Read an account member by customer and account IDreadByEmailAndAccountId
(String email, String accountId, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) readByIdAndAccountId
(String id, String accountId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Finds theAccountMember
which has the given ID and parent account ID.registerAccountMember
(String accountId, @NonNull RegisterAccountMemberRequest registerRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) protected void
resetCustomerDefaultAccountIfNeeded
(M member, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) ResetsCustomer.getDefaultAccountId()
if needed.updateAccountMember
(String accountId, @NonNull String accountMemberId, @NonNull UpdateAccountMemberRequest updateRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) updateAfterInviteAccepted
(String email, String accountId, @NonNull Customer customer, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Handles updating the account member after accepting a pending invite.updateAfterInviteAccepted
(M accountMember, @NonNull Customer customer, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Handles updating the account member after accepting a pending invite.Methods inherited from class com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService
getRsqlHelper, readAll, readAll, readAll, readAll
Methods inherited from class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService
convertFromPersistentDomain, convertToPersistentDomain, create, createAll, createAllAllowingPartialSuccess, getHelper, getSortPositionStrategy, readAll, readAll, readAll, readAllByContextId, readByContextId, replace, replaceAll, replaceAllAllowingPartialSuccess, setSortPositionStrategy, update, updateAll, updateAllAllowingPartialSuccess, updateSort
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService
create, createAll, createAllAllowingPartialSuccess, readAll, readAll, readAll, readAllByContextId, readByContextId, replace, replaceAll, replaceAllAllowingPartialSuccess, update, updateAll, updateAllAllowingPartialSuccess, updateSort
Methods inherited from interface com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityService
readAll, readAll, readAll, readAll
-
Field Details
-
USER_ID_ATTRIBUTE
- See Also:
-
-
Constructor Details
-
DefaultAccountMemberService
public DefaultAccountMemberService(AccountMemberRepository<com.broadleafcommerce.data.tracking.core.Trackable> repository, AccountService<Account> accountService, CustomerService<Customer> customerService, com.broadleafcommerce.common.extension.TypeFactory typeFactory, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper helper, @Nullable AccountMemberRoleChangeProducer accountMemberRoleChangeProducer)
-
-
Method Details
-
createActiveFromInviteAndCustomer
public M createActiveFromInviteAndCustomer(@NonNull @NonNull Customer customer, String accountId, @NonNull @NonNull AccountInviteRequest accountInviteRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:AccountMemberService
Creates an activeAccountMember
from the given invite request and customer. This is used when an invitation is auto-accepted due to the customer already being registered.- Specified by:
createActiveFromInviteAndCustomer
in interfaceAccountMemberService<M extends AccountMember>
- Parameters:
customer
- The registered customer invitedaccountId
- The account invited toaccountInviteRequest
- The invite requestcontextInfo
- Additional multitenant and sandbox info- Returns:
- The new account member.
-
readAllByAccountId
public org.springframework.data.domain.Page<M> readAllByAccountId(String accountId, @Nullable cz.jirutka.rsql.parser.ast.Node filters, @Nullable org.springframework.data.domain.Pageable page, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:AccountMemberService
Reads all of the AccountMember relationships in the database associated with the given account context ID.- Specified by:
readAllByAccountId
in interfaceAccountMemberService<M extends AccountMember>
- Parameters:
accountId
- the account context ID to find the relationships forfilters
- additional filters to apply in the query. Should beEmptyNode
if no additional filters should be applied.page
- the requested page of results from the databasecontextInfo
- the context to query within- Returns:
- the AccountMember relationships in the database that match the given account context ID
-
updateAfterInviteAccepted
public M updateAfterInviteAccepted(String email, String accountId, @NonNull @NonNull Customer customer, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:AccountMemberService
Handles updating the account member after accepting a pending invite. This usually happens after a user registers after receiving an invite as oppposed to an existing user accepting an invite.- Specified by:
updateAfterInviteAccepted
in interfaceAccountMemberService<M extends AccountMember>
- Parameters:
email
- The email of the invited memberaccountId
- The id of the inviting accountcustomer
- The newly registered customer user that accepted the invitecontextInfo
- Additional sandbox and multitenant info- Returns:
- The updated account member.
-
updateAfterInviteAccepted
public M updateAfterInviteAccepted(@NonNull M accountMember, @NonNull @NonNull Customer customer, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:AccountMemberService
Handles updating the account member after accepting a pending invite. This usually happens after a user registers after receiving an invite as oppposed to an existing user accepting an invite.- Specified by:
updateAfterInviteAccepted
in interfaceAccountMemberService<M extends AccountMember>
- Parameters:
accountMember
- The member who accepted the invitecustomer
- The newly registered customer user that accepted the invitecontextInfo
- Additional sandbox and multitenant info- Returns:
- The updated account member.
-
readAllByAccountIdAndActiveTrue
public org.springframework.data.domain.Page<M> readAllByAccountIdAndActiveTrue(@NonNull @NonNull String accountId, @Nullable cz.jirutka.rsql.parser.ast.Node filters, @Nullable org.springframework.data.domain.Pageable page, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) - Specified by:
readAllByAccountIdAndActiveTrue
in interfaceAccountMemberService<M extends AccountMember>
-
hydrateAll
public org.springframework.data.domain.Page<M> hydrateAll(@NonNull @NonNull org.springframework.data.domain.Page<M> accountMembers, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:AccountMemberService
Hydrates the relationships onto theAccountMembers
.- Specified by:
hydrateAll
in interfaceAccountMemberService<M extends AccountMember>
- Parameters:
accountMembers
- The members to hydratecontextInfo
- Additional sandbox and multitenant info- Returns:
- They hydrated
accountMembers
.
-
readByEmailAndAccountId
public Optional<M> readByEmailAndAccountId(String email, String accountId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) - Specified by:
readByEmailAndAccountId
in interfaceAccountMemberService<M extends AccountMember>
-
registerAccountMember
public M registerAccountMember(String accountId, @NonNull @NonNull RegisterAccountMemberRequest registerRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:AccountMemberService
Relates aCustomer
with theAccount
identified by theaccountId
. If the customer cannot be found, then one is created.- Specified by:
registerAccountMember
in interfaceAccountMemberService<M extends AccountMember>
- Parameters:
accountId
- Id of theAccount
that theRegisterAccountMemberRequest.getCustomer()
should be related toregisterRequest
- The payload that describes the requested relationship between the customer & the accountcontext
- The context of the user's request- Returns:
- The registered AccountMember
-
checkExistingAccount
protected void checkExistingAccount(String accountId, @NonNull @NonNull RegisterAccountMemberRequest registerRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
updateAccountMember
public M updateAccountMember(String accountId, @NonNull @NonNull String accountMemberId, @NonNull @NonNull UpdateAccountMemberRequest updateRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:AccountMemberService
- Specified by:
updateAccountMember
in interfaceAccountMemberService<M extends AccountMember>
- Parameters:
accountId
- Id of theAccount
in the relationshipaccountMemberId
- Id of theAccountMember
that is to be updatedupdateRequest
- The payload that describes the requested changescontext
- The context of the user's request- Returns:
- The updated
AccountMember
.
-
createInactiveFromAccountInviteAndCustomer
public M createInactiveFromAccountInviteAndCustomer(@NonNull @NonNull AccountInvite accountInvite, @NonNull @NonNull Customer customer, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:AccountMemberService
Create an account member from an account invitation and customer. This account member will not be active yet and must accept the invitation.This method performs no validation so it is assumed the invitation has been pre-validated before being passed to this method. See
DefaultAccountInviteService.acceptInvite(String, String, ContextInfo)
.- Specified by:
createInactiveFromAccountInviteAndCustomer
in interfaceAccountMemberService<M extends AccountMember>
- Parameters:
accountInvite
- The account invite to create the account member forcustomer
- The customercontextInfo
- The context of the user's request- Returns:
- The created account member
-
createInactiveFromAccountInvite
public M createInactiveFromAccountInvite(@NonNull @NonNull AccountInvite accountInvite, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) - Specified by:
createInactiveFromAccountInvite
in interfaceAccountMemberService<M extends AccountMember>
-
readByCustomerIdAndAccountId
public Optional<M> readByCustomerIdAndAccountId(String customerId, String accountId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:AccountMemberService
Read an account member by customer and account ID- Specified by:
readByCustomerIdAndAccountId
in interfaceAccountMemberService<M extends AccountMember>
- Parameters:
customerId
- The customer IDaccountId
- The account IDcontextInfo
- The context of the user's request- Returns:
- The account member, if they're a member of the account.
-
readByCustomerId
public org.springframework.data.domain.Page<M> readByCustomerId(String customerId, @Nullable org.springframework.data.domain.Pageable page, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:AccountMemberService
Read account memberships for a customer.- Specified by:
readByCustomerId
in interfaceAccountMemberService<M extends AccountMember>
- Parameters:
customerId
- The customer IDpage
- The pagecontextInfo
- The context of the user's request- Returns:
- The
AccountMember
-
readActiveByCustomerId
public org.springframework.data.domain.Page<M> readActiveByCustomerId(String customerId, @Nullable org.springframework.data.domain.Pageable page, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:AccountMemberService
Read account memberships for a customer where the membership is active.- Specified by:
readActiveByCustomerId
in interfaceAccountMemberService<M extends AccountMember>
- Parameters:
customerId
- The customer IDpage
- The pagecontextInfo
- The context of the user's request- Returns:
- The
AccountMember
-
readActiveByCustomerId
public List<M> readActiveByCustomerId(String customerId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:AccountMemberService
Read account memberships for a customer where the membership is active.- Specified by:
readActiveByCustomerId
in interfaceAccountMemberService<M extends AccountMember>
- Parameters:
customerId
- The customer IDcontextInfo
- The context of the user's request- Returns:
- The
AccountMember
-
delete
public void delete(String id, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) - Specified by:
delete
in interfacecom.broadleafcommerce.data.tracking.core.service.CrudEntityService<M extends AccountMember>
- Overrides:
delete
in classcom.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<M extends AccountMember>
-
resetCustomerDefaultAccountIfNeeded
protected void resetCustomerDefaultAccountIfNeeded(@NonNull M member, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) ResetsCustomer.getDefaultAccountId()
if needed.Note that
Customer
may not exist for the givenAccountMember
if the member was invited but not registered.- Parameters:
member
- theAccountMember
to reset the correspondingCustomer.getDefaultAccountId()
forcontext
- context information surrounding sandboxing and multitenant state
-
readByIdAndAccountId
public M readByIdAndAccountId(String id, String accountId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:AccountMemberService
Finds theAccountMember
which has the given ID and parent account ID.- Specified by:
readByIdAndAccountId
in interfaceAccountMemberService<M extends AccountMember>
- Parameters:
id
- the context ID of theAccountMember
accountId
- the context ID of the owningAccount
contextInfo
- context surrounding customer and multitenant state- Returns:
- the account member that has the given ID and owning account ID
-
hydrate
public void hydrate(@NonNull M accountMember, @NonNull @NonNull List<Customer> customers, @NonNull @NonNull List<Account> accounts) Hydrates the relationships onto theAccountMember
.- Specified by:
hydrate
in interfaceAccountMemberService<M extends AccountMember>
- Parameters:
accountMember
- the member to hydratecustomers
- list of customers retrieved by context IDaccounts
- list of accounts retrieved by context ID
-
hydrate
public M hydrate(@NonNull M accountMember, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Hydrates the relationships onto theAccountMember
.- Specified by:
hydrate
in interfaceAccountMemberService<M extends AccountMember>
- Parameters:
accountMember
- The member to hydratecontext
- Additional sandbox and multitenant info- Returns:
- They hydrated
accountMember
.
-
hydrateCustomer
protected M hydrateCustomer(@NonNull M accountMember, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Hydrates theCustomer
onto theAccountMember
.- Parameters:
accountMember
- The member to hydratecontext
- Additional sandbox and multitenant info- Returns:
- They hydrated
accountMember
.
-
hydrateAccount
protected M hydrateAccount(@NonNull M accountMember, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Hydrates theAccount
onto theAccountMember
.- Parameters:
accountMember
- The member to hydratecontext
- Additional sandbox and multitenant info- Returns:
- They hydrated
accountMember
.
-
getCustomer
protected Customer getCustomer(@NonNull @NonNull RegisterAccountMemberRequest registerRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Returns the customer to associate with the account.- Parameters:
registerRequest
- the request used to identify or describe the customercontext
- the context within which the request has been made- Returns:
- the customer that is to be added to the account
-
createAccountMember
protected M createAccountMember(@NonNull @NonNull RegisterAccountMemberRequest registerRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Create anAccountMember
based on theRegisterAccountMemberRequest
- Parameters:
registerRequest
- the request data used to build the AccountMembercontext
- the context in which the AccountMember should be created- Returns:
- The persisted AccountMember
-
getCustomerWithId
-
getAccountWithId
-
hasUpdatedRole
protected boolean hasUpdatedRole(@NonNull @NonNull UpdateAccountMemberRequest updateRequest, @NonNull M accountMember) -
createAccountRefFromAccount
-
createCustomerRefFromCustomer
-
notifyAccountMemberRoleChange
protected void notifyAccountMemberRoleChange(@NonNull M accountMember, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) -
notifyAccountMemberRoleChange
protected void notifyAccountMemberRoleChange(@NonNull M accountMember, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context, boolean isDelete) Send anAccountMemberRoleChangeRequest
with theAccountMemberRoleChangeProducer
.- Parameters:
accountMember
- TheAccountMember
being updated.context
- The security context of the operation.isDelete
- Indicates if thisAccountMember
has been deleted.
-
getRepository
protected AccountMemberRepository<com.broadleafcommerce.data.tracking.core.Trackable> getRepository()- Overrides:
getRepository
in classcom.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<M extends AccountMember>
-
getAccountService
-
getCustomerService
-
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory() -
getAccountMemberRoleChangeProducer
-