Class DefaultAccountService<P extends Account>
- java.lang.Object
-
- com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P>
-
- com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService<P>
-
- com.broadleafcommerce.customer.service.DefaultAccountService<P>
-
- Type Parameters:
P
- A subtype ofAccount
- 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 ofAccountService
- Author:
- Chris Kittrell (ckittrell)
-
-
Field Summary
Fields Modifier and Type Field Description static String
ACCOUNT_STATUS_DELETED
-
Constructor Summary
Constructors Constructor Description DefaultAccountService(AccountRepository<com.broadleafcommerce.data.tracking.core.Trackable> accountRepository, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper helper, AccountUpdateEventProducer accountUpdateEventProducer)
-
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 aCircularParentAccountException
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 statusDefaultAccountStatuses.ACTIVE
.protected boolean
isInactive(P account)
Determine if the given account has statusDefaultAccountStatuses.INACTIVE
.protected void
notifyAccountChange(String accountId, String parentAccountId, String status, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
Send anAccountUpdateRequest
with theAccountUpdateEventProducer
.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 theAccounts
byids
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 theAccounts
byids
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 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
createAll, createAllAllowingPartialSuccess, readAll, readAll, readAll, readAllByContextId, readByContextId, replaceAll, replaceAllAllowingPartialSuccess, update, updateAll, updateAllAllowingPartialSuccess, updateSort
-
-
-
-
Field Detail
-
ACCOUNT_STATUS_DELETED
public static final String ACCOUNT_STATUS_DELETED
- See Also:
- Constant Field Values
-
-
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)
-
replace
public P replace(String id, P accountUpdateRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
-
delete
public void delete(String id, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
-
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 theAccounts
byids
and optionally include child accounts. SetexcludeAccountsWithInactiveParent
totrue
to filter out accounts that have a disabled parent account.- Specified by:
readAllByIdWithChildren
in interfaceAccountService<P extends Account>
- Parameters:
ids
- The Ids of the accounts to matchchildAccountDepth
- How many levels deep of the account hierarchy of the accounts matchingids
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 beEmptyNode
if no filters should be applied.contextInfo
- Additional multitenant and sandbox info- Returns:
- All of the
Accounts
byids
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 beEmptyNode
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 beEmptyNode
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 theAccounts
byids
and optionally include child accounts. SetexcludeAccountsWithInactiveParent
totrue
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 matchingids
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 beEmptyNode
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.
-
isActive
protected boolean isActive(P account)
Determine if the given account has statusDefaultAccountStatuses.ACTIVE
.- Parameters:
account
- The account whose status is being checked- Returns:
- True if the given account's status is
DefaultAccountStatuses.ACTIVE
.
-
isInactive
protected boolean isInactive(P account)
Determine if the given account has statusDefaultAccountStatuses.INACTIVE
.- Parameters:
account
- The account whose status is being checked- Returns:
- True if the given account's status is
DefaultAccountStatuses.INACTIVE
.
-
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 aCircularParentAccountException
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)
Send anAccountUpdateRequest
with theAccountUpdateEventProducer
.- Parameters:
accountId
- The id of the account being updated.parentAccountId
- The id of the parent account.status
- The status of the updated accountcontext
- The security context of the operation.
-
getAccountRepository
protected AccountRepository<com.broadleafcommerce.data.tracking.core.Trackable> getAccountRepository()
-
getAccountUpdateEventProducer
@Nullable protected AccountUpdateEventProducer getAccountUpdateEventProducer()
-
-