Class DefaultAccountService<P extends Account>

  • Type Parameters:
    P - A subtype of Account
    All Implemented Interfaces:
    AccountService<P>, com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P>, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityService<P>

    public class DefaultAccountService<P extends Account>
    extends com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService<P>
    implements AccountService<P>
    Default implementation of AccountService
    Author:
    Chris Kittrell (ckittrell)
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void checkForCircularAccountReferences​(String ancestorAccountId, @NonNull String childAccountId, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Check for circular account references and throw a CircularParentAccountException if found.
      P create​(P businessInstance, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)  
      void delete​(String id, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)  
      protected boolean filterParentAccounts​(com.broadleafcommerce.data.tracking.core.Trackable account, cz.jirutka.rsql.parser.ast.Node filters, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Apply the given filters to all parents of the given account.
      protected AccountRepository<com.broadleafcommerce.data.tracking.core.Trackable> getAccountRepository()  
      protected AccountUpdateEventProducer getAccountUpdateEventProducer()  
      protected String getParentAccountId​(P account)
      Get the parent id of the given account.
      protected boolean isActive​(P account)
      Determine if the given account has status DefaultAccountStatuses.ACTIVE.
      protected boolean isInactive​(P account)
      Determine if the given account has status DefaultAccountStatuses.INACTIVE.
      protected void notifyAccountChange​(String accountId, String parentAccountId, String status, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      protected Set<com.broadleafcommerce.data.tracking.core.Trackable> readAccountChildren​(List<com.broadleafcommerce.data.tracking.core.Trackable> parentAccounts, int childAccountDepth, cz.jirutka.rsql.parser.ast.Node filters, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Reads all of the Accounts by ids and optionally include child accounts.
      List<P> readAllByIdWithChildren​(@NonNull Collection<String> ids, int childAccountDepth, boolean filterParents, cz.jirutka.rsql.parser.ast.Node filters, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Reads all of the Accounts by ids and optionally include child accounts.
      protected List<com.broadleafcommerce.data.tracking.core.Trackable> readAllByIdWithFilters​(Collection<String> ids, cz.jirutka.rsql.parser.ast.Node filters, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Read by id with filters included.
      P replace​(String id, P accountUpdateRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)  
      • 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, createAll, createAllAllowingPartialSuccess, getHelper, getRepository, getSortPositionStrategy, readAll, readAll, readAll, readAllByContextId, readByContextId, replaceAll, replaceAllAllowingPartialSuccess, setSortPositionStrategy, update, updateAll, updateAllAllowingPartialSuccess, updateSort
      • Methods inherited from interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService

        createAll, createAllAllowingPartialSuccess, readAll, readAll, readAll, readAllByContextId, readByContextId, replaceAll, replaceAllAllowingPartialSuccess, update, updateAll, updateAllAllowingPartialSuccess, updateSort
      • Methods inherited from interface com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityService

        readAll, readAll, readAll, readAll
    • Constructor Detail

      • DefaultAccountService

        public DefaultAccountService​(AccountRepository<com.broadleafcommerce.data.tracking.core.Trackable> accountRepository,
                                     com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper helper,
                                     @Nullable
                                     AccountUpdateEventProducer accountUpdateEventProducer)
    • Method Detail

      • create

        public P create​(P businessInstance,
                        @Nullable
                        com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
        Specified by:
        create in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends Account>
        Overrides:
        create in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends Account>
      • replace

        public P replace​(String id,
                         P accountUpdateRequest,
                         @Nullable
                         com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
        Specified by:
        replace in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends Account>
        Overrides:
        replace in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends Account>
      • 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<P extends Account>
        Overrides:
        delete in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends Account>
      • readAllByIdWithChildren

        public List<P> readAllByIdWithChildren​(@NonNull
                                               @NonNull Collection<String> ids,
                                               int childAccountDepth,
                                               boolean filterParents,
                                               cz.jirutka.rsql.parser.ast.Node filters,
                                               @Nullable
                                               com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
        Description copied from interface: AccountService
        Reads all of the Accounts by ids and optionally include child accounts. Set excludeAccountsWithInactiveParent to true to filter out accounts that have a disabled parent account.
        Specified by:
        readAllByIdWithChildren in interface AccountService<P extends Account>
        Parameters:
        ids - The Ids of the accounts to match
        childAccountDepth - How many levels deep of the account hierarchy of the accounts matching ids to include in the results, e.g., how many levels of child accounts to include. -1 indicates no limit. 0 indicates no child accounts.

        Default is 0.

        filterParents - If true, the returned list will include only accounts with active parent accounts.
        filters - An RSQL filter used to narrow query results. May be EmptyNode if no filters should be applied.
        contextInfo - Additional multitenant and sandbox info
        Returns:
        All of the Accounts by ids and optionally child accounts.
      • readAllByIdWithFilters

        protected List<com.broadleafcommerce.data.tracking.core.Trackable> readAllByIdWithFilters​(Collection<String> ids,
                                                                                                  cz.jirutka.rsql.parser.ast.Node filters,
                                                                                                  @Nullable
                                                                                                  com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
        Read by id with filters included. This is an alternative to #readAllByContextId() that will apply the given filters.
        Parameters:
        ids - The list of account ids to lookup.
        filters - An RSQL filter used to narrow query results. May be EmptyNode if no filters should be applied.
        contextInfo - Context information for data tracking.
        Returns:
        A list of Trackable that matches the given ids and filters.
      • filterParentAccounts

        protected boolean filterParentAccounts​(com.broadleafcommerce.data.tracking.core.Trackable account,
                                               cz.jirutka.rsql.parser.ast.Node filters,
                                               @Nullable
                                               com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
        Apply the given filters to all parents of the given account. Return true if all parents of the given account match the filter.
        Parameters:
        account - The account whose parents should be checked.
        filters - An RSQL filter used to narrow query results. May be EmptyNode if no filters should be applied.
        contextInfo - Context information for data tracking.
        Returns:
        True if all parents of the given account match the filter. False otherwise.
      • readAccountChildren

        protected Set<com.broadleafcommerce.data.tracking.core.Trackable> readAccountChildren​(List<com.broadleafcommerce.data.tracking.core.Trackable> parentAccounts,
                                                                                              int childAccountDepth,
                                                                                              cz.jirutka.rsql.parser.ast.Node filters,
                                                                                              @Nullable
                                                                                              com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
        Reads all of the Accounts by ids and optionally include child accounts. Set excludeAccountsWithInactiveParent to true to filter out accounts that have a disabled parent account.
        Parameters:
        parentAccounts - The ids of the parent accounts for which to find children.
        childAccountDepth - How many levels deep of the account hierarchy of the accounts matching ids to include in the results, e.g., how many levels of child accounts to include. -1 indicates no limit. 0 indicates no child accounts. Providing 0 results in a no-op.
        filters - An RSQL filter used to narrow query results. May be EmptyNode if no filters should be applied.
        contextInfo - Context information for data tracking.
        Returns:
        A Set of all children of the given accounts, down to the given childAccountDepth.
      • getParentAccountId

        @Nullable
        protected String getParentAccountId​(P account)
        Get the parent id of the given account.
        Parameters:
        account - The account whose parent is being checked
        Returns:
        The id of the parent to the given account, or null if the given account has no parent.
      • checkForCircularAccountReferences

        protected void checkForCircularAccountReferences​(@Nullable
                                                         String ancestorAccountId,
                                                         @NonNull
                                                         @NonNull String childAccountId,
                                                         @Nullable
                                                         com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
        Check for circular account references and throw a CircularParentAccountException if found. This recursively reads parent accounts and validates that the parent account id does not match the account id being saved.
        Parameters:
        ancestorAccountId - The id of an ancestor of the account being saved.
        childAccountId - The id of the account being saved.
        context - The security context of the operation
      • notifyAccountChange

        protected void notifyAccountChange​(String accountId,
                                           @Nullable
                                           String parentAccountId,
                                           String status,
                                           @Nullable
                                           com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
        Parameters:
        accountId - The id of the account being updated.
        parentAccountId - The id of the parent account.
        status - The status of the updated account
        context - The security context of the operation.
      • getAccountRepository

        protected AccountRepository<com.broadleafcommerce.data.tracking.core.Trackable> getAccountRepository()