Class DefaultAccountMemberService<M extends AccountMember>

  • 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)
    • 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: AccountMemberService
        Creates an active AccountMember 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 interface AccountMemberService<M extends AccountMember>
        Parameters:
        customer - The registered customer invited
        accountId - The account invited to
        accountInviteRequest - The invite request
        contextInfo - 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 interface AccountMemberService<M extends AccountMember>
        Parameters:
        accountId - the account context ID to find the relationships for
        filters - additional filters to apply in the query. Should be EmptyNode if no additional filters should be applied.
        page - the requested page of results from the database
        contextInfo - 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 interface AccountMemberService<M extends AccountMember>
        Parameters:
        email - The email of the invited member
        accountId - The id of the inviting account
        customer - The newly registered customer user that accepted the invite
        contextInfo - 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 interface AccountMemberService<M extends AccountMember>
        Parameters:
        accountMember - The member who accepted the invite
        customer - The newly registered customer user that accepted the invite
        contextInfo - 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 interface AccountMemberService<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 the AccountMembers.
        Specified by:
        hydrateAll in interface AccountMemberService<M extends AccountMember>
        Parameters:
        accountMembers - The members to hydrate
        contextInfo - Additional sandbox and multitenant info
        Returns:
        They hydrated accountMembers.
      • checkExistingAccount

        protected void checkExistingAccount​(String accountId,
                                            @NonNull
                                            @NonNull RegisterAccountMemberRequest registerRequest,
                                            @Nullable
                                            com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      • 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 interface AccountMemberService<M extends AccountMember>
        Parameters:
        accountInvite - The account invite to create the account member for
        customer - The customer
        contextInfo - The context of the user's request
        Returns:
        The created account member
      • 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 interface AccountMemberService<M extends AccountMember>
        Parameters:
        customerId - The customer ID
        accountId - The account ID
        contextInfo - 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 interface AccountMemberService<M extends AccountMember>
        Parameters:
        customerId - The customer ID
        page - The page
        contextInfo - 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 interface AccountMemberService<M extends AccountMember>
        Parameters:
        customerId - The customer ID
        page - The page
        contextInfo - 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 interface AccountMemberService<M extends AccountMember>
        Parameters:
        customerId - The customer ID
        contextInfo - 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 interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<M extends AccountMember>
        Overrides:
        delete in class com.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)
        Resets Customer.getDefaultAccountId() if needed.

        Note that Customer may not exist for the given AccountMember if the member was invited but not registered.

        Parameters:
        member - the AccountMember to reset the corresponding Customer.getDefaultAccountId() for
        context - 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 the AccountMember which has the given ID and parent account ID.
        Specified by:
        readByIdAndAccountId in interface AccountMemberService<M extends AccountMember>
        Parameters:
        id - the context ID of the AccountMember
        accountId - the context ID of the owning Account
        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 the AccountMember.
        Specified by:
        hydrate in interface AccountMemberService<M extends AccountMember>
        Parameters:
        accountMember - the member to hydrate
        customers - list of customers retrieved by context ID
        accounts - 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 the AccountMember.
        Specified by:
        hydrate in interface AccountMemberService<M extends AccountMember>
        Parameters:
        accountMember - The member to hydrate
        context - 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 the Customer onto the AccountMember.
        Parameters:
        accountMember - The member to hydrate
        context - 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 the Account onto the AccountMember.
        Parameters:
        accountMember - The member to hydrate
        context - 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 customer
        context - 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)
        Parameters:
        registerRequest - the request data used to build the AccountMember
        context - 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)
        Parameters:
        accountMember - The AccountMember being updated.
        context - The security context of the operation.
        isDelete - Indicates if this AccountMember has been deleted.
      • getRepository

        protected AccountMemberRepository<com.broadleafcommerce.data.tracking.core.Trackable> getRepository()
        Overrides:
        getRepository in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<M extends AccountMember>
      • getTypeFactory

        protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()