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 theAccountMemberService.- Author:
- Chris Kittrell (ckittrell)
-
-
Field Summary
Fields Modifier and Type Field Description static StringUSER_ID_ATTRIBUTE
-
Constructor Summary
Constructors Constructor Description 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, AccountMemberRoleChangeProducer accountMemberRoleChangeProducer)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcheckExistingAccount(String accountId, @NonNull RegisterAccountMemberRequest registerRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)protected McreateAccountMember(@NonNull RegisterAccountMemberRequest registerRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)Create anAccountMemberbased on theRegisterAccountMemberRequestprotected AccountRefcreateAccountRefFromAccount(@NonNull Account account)McreateActiveFromInviteAndCustomer(@NonNull Customer customer, String accountId, @NonNull AccountInviteRequest accountInviteRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)Creates an activeAccountMemberfrom the given invite request and customer.protected CustomerRefcreateCustomerRefFromCustomer(@NonNull Customer customer)McreateInactiveFromAccountInvite(@NonNull AccountInvite accountInvite, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)McreateInactiveFromAccountInviteAndCustomer(@NonNull AccountInvite accountInvite, @NonNull Customer customer, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)Create an account member from an account invitation and customer.voiddelete(String id, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)protected AccountMemberRoleChangeProducergetAccountMemberRoleChangeProducer()protected AccountService<Account>getAccountService()protected AccountgetAccountWithId(@NonNull AccountRef accountRef)protected CustomergetCustomer(@NonNull RegisterAccountMemberRequest registerRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)Returns the customer to associate with the account.protected CustomerService<Customer>getCustomerService()protected CustomergetCustomerWithId(@NonNull CustomerRef customerRef)protected AccountMemberRepository<com.broadleafcommerce.data.tracking.core.Trackable>getRepository()protected com.broadleafcommerce.common.extension.TypeFactorygetTypeFactory()protected booleanhasUpdatedRole(@NonNull UpdateAccountMemberRequest updateRequest, M accountMember)voidhydrate(M accountMember, @NonNull List<Customer> customers, @NonNull List<Account> accounts)Hydrates the relationships onto theAccountMember.Mhydrate(M accountMember, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)Hydrates the relationships onto theAccountMember.protected MhydrateAccount(M accountMember, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)Hydrates theAccountonto 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 MhydrateCustomer(M accountMember, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)Hydrates theCustomeronto theAccountMember.protected voidnotifyAccountMemberRoleChange(M accountMember, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)protected voidnotifyAccountMemberRoleChange(M accountMember, com.broadleafcommerce.data.tracking.core.context.ContextInfo context, boolean isDelete)Send anAccountMemberRoleChangeRequestwith theAccountMemberRoleChangeProducer.List<M>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.Optional<M>readByCustomerIdAndAccountId(String customerId, String accountId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)Read an account member by customer and account IDOptional<M>readByEmailAndAccountId(String email, String accountId, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)MreadByIdAndAccountId(String id, String accountId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)Finds theAccountMemberwhich has the given ID and parent account ID.MregisterAccountMember(String accountId, @NonNull RegisterAccountMemberRequest registerRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)protected voidresetCustomerDefaultAccountIfNeeded(M member, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)ResetsCustomer.getDefaultAccountId()if needed.MupdateAccountMember(String accountId, @NonNull String accountMemberId, @NonNull UpdateAccountMemberRequest updateRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)MupdateAfterInviteAccepted(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.MupdateAfterInviteAccepted(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
-
-
-
-
Field Detail
-
USER_ID_ATTRIBUTE
public static final String USER_ID_ATTRIBUTE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
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 Detail
-
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:AccountMemberServiceCreates an activeAccountMemberfrom the given invite request and customer. This is used when an invitation is auto-accepted due to the customer already being registered.- Specified by:
createActiveFromInviteAndCustomerin 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:AccountMemberServiceReads all of the AccountMember relationships in the database associated with the given account context ID.- Specified by:
readAllByAccountIdin interfaceAccountMemberService<M extends AccountMember>- Parameters:
accountId- the account context ID to find the relationships forfilters- additional filters to apply in the query. Should beEmptyNodeif 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:AccountMemberServiceHandles 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:
updateAfterInviteAcceptedin 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:AccountMemberServiceHandles 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:
updateAfterInviteAcceptedin 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:
readAllByAccountIdAndActiveTruein 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:AccountMemberServiceHydrates the relationships onto theAccountMembers.- Specified by:
hydrateAllin 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:
readByEmailAndAccountIdin 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:AccountMemberServiceRelates aCustomerwith theAccountidentified by theaccountId. If the customer cannot be found, then one is created.- Specified by:
registerAccountMemberin interfaceAccountMemberService<M extends AccountMember>- Parameters:
accountId- Id of theAccountthat 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:
updateAccountMemberin interfaceAccountMemberService<M extends AccountMember>- Parameters:
accountId- Id of theAccountin the relationshipaccountMemberId- Id of theAccountMemberthat 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:AccountMemberServiceCreate 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:
createInactiveFromAccountInviteAndCustomerin 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:
createInactiveFromAccountInvitein 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:AccountMemberServiceRead an account member by customer and account ID- Specified by:
readByCustomerIdAndAccountIdin 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:AccountMemberServiceRead account memberships for a customer.- Specified by:
readByCustomerIdin 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:AccountMemberServiceRead account memberships for a customer where the membership is active.- Specified by:
readActiveByCustomerIdin 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:AccountMemberServiceRead account memberships for a customer where the membership is active.- Specified by:
readActiveByCustomerIdin 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:
deletein interfacecom.broadleafcommerce.data.tracking.core.service.CrudEntityService<M extends AccountMember>- Overrides:
deletein 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
Customermay not exist for the givenAccountMemberif the member was invited but not registered.- Parameters:
member- theAccountMemberto 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:AccountMemberServiceFinds theAccountMemberwhich has the given ID and parent account ID.- Specified by:
readByIdAndAccountIdin interfaceAccountMemberService<M extends AccountMember>- Parameters:
id- the context ID of theAccountMemberaccountId- the context ID of the owningAccountcontextInfo- 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:
hydratein 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:
hydratein 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 theCustomeronto 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 theAccountonto 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 anAccountMemberbased 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
protected Customer getCustomerWithId(@NonNull @NonNull CustomerRef customerRef)
-
getAccountWithId
protected Account getAccountWithId(@NonNull @NonNull AccountRef accountRef)
-
hasUpdatedRole
protected boolean hasUpdatedRole(@NonNull @NonNull UpdateAccountMemberRequest updateRequest, @NonNull M accountMember)
-
createAccountRefFromAccount
protected AccountRef createAccountRefFromAccount(@NonNull @NonNull Account account)
-
createCustomerRefFromCustomer
protected CustomerRef createCustomerRefFromCustomer(@NonNull @NonNull Customer customer)
-
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 anAccountMemberRoleChangeRequestwith theAccountMemberRoleChangeProducer.- Parameters:
accountMember- TheAccountMemberbeing updated.context- The security context of the operation.isDelete- Indicates if thisAccountMemberhas been deleted.
-
getRepository
protected AccountMemberRepository<com.broadleafcommerce.data.tracking.core.Trackable> getRepository()
- Overrides:
getRepositoryin classcom.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<M extends AccountMember>
-
getAccountService
protected AccountService<Account> getAccountService()
-
getCustomerService
protected CustomerService<Customer> getCustomerService()
-
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
-
getAccountMemberRoleChangeProducer
@Nullable protected AccountMemberRoleChangeProducer getAccountMemberRoleChangeProducer()
-
-