Class DefaultCustomerService<P extends Customer>
- java.lang.Object
-
- com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P>
-
- com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService<P>
-
- com.broadleafcommerce.customer.service.DefaultCustomerService<P>
-
- Type Parameters:
P
- A subtype ofCustomer
- All Implemented Interfaces:
CustomerService<P>
,com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P>
,com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityService<P>
public class DefaultCustomerService<P extends Customer> extends com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService<P> implements CustomerService<P>
Default implementation ofCustomerService
- Author:
- Samarth Dhruva (samarthd)
-
-
Constructor Summary
Constructors Constructor Description DefaultCustomerService(CustomerRepository<com.broadleafcommerce.data.tracking.core.Trackable> customerRepository, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper helper, CustomerConfigurationProperties customerProperties, com.broadleafcommerce.data.tracking.core.filtering.fetch.FilterParser<cz.jirutka.rsql.parser.ast.Node> parser)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description P
create(P customer, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
List<P>
createAll(List<P> customers, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
com.broadleafcommerce.data.tracking.core.service.BulkPersistenceResponse<P>
createAllAllowingPartialSuccess(List<P> customers, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
protected AccountMemberService<AccountMember>
getAccountMemberService()
protected CustomerConfigurationProperties
getCustomerProperties()
protected CustomerRepository<com.broadleafcommerce.data.tracking.core.Trackable>
getCustomerRepository()
protected com.broadleafcommerce.data.tracking.core.filtering.fetch.FilterParser<cz.jirutka.rsql.parser.ast.Node>
getParser()
protected void
handleAccountMemberUpdate(P customer, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
Reflect thecustomer
updates to their correspondingAccountMember
instances, namely the full name and email updates.protected void
handleEmailAsUsername(P customer)
Assign thecustomer
's username to match their email whenCustomerConfigurationProperties
is configured with email as username.protected void
handleEmailAsUsernameUpdate(P customer)
Adjust thecustomer
update for the username to match their email whenCustomerConfigurationProperties
is configured with email as username.List<P>
readAllByEmail(Set<String> emails, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Searches for customers in the data store whoseCustomer.email
contains in the givenemails
.org.springframework.data.domain.Page<P>
readAllByFullName(String nameQuery, cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Searches for customers in the data store whoseCustomer#name
matches the givennameQuery
.List<String>
readAllUniqueIds(int page, cz.jirutka.rsql.parser.ast.Node filters)
Retrieves a list of unique customer context IDs no larger than page.Optional<P>
readByContextIdOpt(String id, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
Read a single instance of an entity in the form of a business domain.Optional<P>
readByEmail(String email, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Find a customer by email.Stream<P>
readCustomersPagingStream(cz.jirutka.rsql.parser.ast.Node filters, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Reads all customers matching the given filters.P
replace(String id, P customer, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
List<P>
replaceAll(List<com.broadleafcommerce.data.tracking.core.service.Update<P>> replacements, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
com.broadleafcommerce.data.tracking.core.service.BulkPersistenceResponse<P>
replaceAllAllowingPartialSuccess(List<com.broadleafcommerce.data.tracking.core.service.Update<P>> replacements, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
void
setAccountMemberService(AccountMemberService<AccountMember> accountMemberService)
Stream<P>
streamAll(cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Sort sort, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Stream a list of customers matching the provided filtersP
update(String id, P customer, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
List<P>
updateAll(List<com.broadleafcommerce.data.tracking.core.service.Update<P>> updates, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
com.broadleafcommerce.data.tracking.core.service.BulkPersistenceResponse<P>
updateAllAllowingPartialSuccess(List<com.broadleafcommerce.data.tracking.core.service.Update<P>> updates, 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, delete, getHelper, getRepository, getSortPositionStrategy, readAll, readAll, readAll, readAllByContextId, readByContextId, setSortPositionStrategy, updateSort
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
-
-
Constructor Detail
-
DefaultCustomerService
public DefaultCustomerService(CustomerRepository<com.broadleafcommerce.data.tracking.core.Trackable> customerRepository, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper helper, CustomerConfigurationProperties customerProperties, com.broadleafcommerce.data.tracking.core.filtering.fetch.FilterParser<cz.jirutka.rsql.parser.ast.Node> parser)
-
-
Method Detail
-
readByContextIdOpt
public Optional<P> readByContextIdOpt(@NonNull String id, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
Description copied from interface:CustomerService
Read a single instance of an entity in the form of a business domain.- Specified by:
readByContextIdOpt
in interfaceCustomerService<P extends Customer>
- Parameters:
id
- The context id for the entity. This is the id by which the business recognizes the item.context
- Context information used to discriminate the correct version of an entity by context id when multiple verions may be available across sandboxes, catalogs and applications.- Returns:
- an
Optional
containing the narrowed entity instance in the form of a business instance if found,Optional.empty()
otherwise
-
readAllByFullName
@NonNull public org.springframework.data.domain.Page<P> readAllByFullName(@NonNull String nameQuery, @NonNull cz.jirutka.rsql.parser.ast.Node filters, @NonNull org.springframework.data.domain.Pageable page, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Description copied from interface:CustomerService
Searches for customers in the data store whoseCustomer#name
matches the givennameQuery
. Ignores case.- Specified by:
readAllByFullName
in interfaceCustomerService<P extends Customer>
- Parameters:
nameQuery
- the name to search forfilters
- An RSQL filter used to narrow query results. May beEmptyNode
if no filters should be applied.page
- the requested page of results from the databasecontextInfo
- context information surrounding sandboxing and multitenant state- Returns:
- the customers in the data store whose
Customer#name
matches the givennameQuery
. Ignores case.
-
readAllByEmail
@NonNull public List<P> readAllByEmail(@NonNull Set<String> emails, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Description copied from interface:CustomerService
Searches for customers in the data store whoseCustomer.email
contains in the givenemails
. Ignores case.- Specified by:
readAllByEmail
in interfaceCustomerService<P extends Customer>
- Parameters:
emails
- the set of emails to search forcontextInfo
- context information surrounding sandboxing and multitenant state- Returns:
- the customers in the data store whose
Customer.email
contains in the givenemails
. Ignores case.
-
readAllUniqueIds
@NonNull public List<String> readAllUniqueIds(int page, @NonNull cz.jirutka.rsql.parser.ast.Node filters)
Description copied from interface:CustomerService
Retrieves a list of unique customer context IDs no larger than page. It is expected that any appropriate offset is achieved through criteria designated infilters
.- Specified by:
readAllUniqueIds
in interfaceCustomerService<P extends Customer>
- Parameters:
page
- the requested page of results from the database. -1 indicates no limit.filters
- An RSQL filter used to narrow query results. May beEmptyNode
if no filters should be applied.- Returns:
- unique customer IDs
-
streamAll
public Stream<P> streamAll(@NonNull cz.jirutka.rsql.parser.ast.Node filters, @NonNull org.springframework.data.domain.Sort sort, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Description copied from interface:CustomerService
Stream a list of customers matching the provided filters- Specified by:
streamAll
in interfaceCustomerService<P extends Customer>
- Parameters:
filters
- An RSQL filter used to narrow query results. May beEmptyNode
if no filters should be applied.sort
- The string containing the structured list of sorts to apply. May beSort.unsorted()
contextInfo
- context information surrounding sandboxing and multitenant state- Returns:
- A stream of customers matching the filters.
-
readCustomersPagingStream
public Stream<P> readCustomersPagingStream(@Nullable cz.jirutka.rsql.parser.ast.Node filters, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Description copied from interface:CustomerService
Reads all customers matching the given filters. In case filters are empty, all customers are returned.- Specified by:
readCustomersPagingStream
in interfaceCustomerService<P extends Customer>
- Parameters:
filters
- additional filters to apply in the querycontextInfo
- Request context information around sandbox and multitenant state- Returns:
- the customers matching the given filters
-
readByEmail
public Optional<P> readByEmail(@NonNull String email, @NonNull com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Description copied from interface:CustomerService
Find a customer by email. Note: While e-mail is guaranteed to be unique per customer context, this is not guaranteed across multiple customer contexts. Therefore, thecontextInfo
argument is required.- Specified by:
readByEmail
in interfaceCustomerService<P extends Customer>
- Parameters:
email
- The email to search forcontextInfo
- The current context- Returns:
- The customer associated with the supplied email address.
-
update
public P update(@NonNull String id, @NonNull P customer, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
-
updateAll
public List<P> updateAll(@NonNull List<com.broadleafcommerce.data.tracking.core.service.Update<P>> updates, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
-
updateAllAllowingPartialSuccess
public com.broadleafcommerce.data.tracking.core.service.BulkPersistenceResponse<P> updateAllAllowingPartialSuccess(List<com.broadleafcommerce.data.tracking.core.service.Update<P>> updates, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
-
replace
public P replace(@NonNull String id, @NonNull P customer, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
-
replaceAll
public List<P> replaceAll(List<com.broadleafcommerce.data.tracking.core.service.Update<P>> replacements, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
-
replaceAllAllowingPartialSuccess
public com.broadleafcommerce.data.tracking.core.service.BulkPersistenceResponse<P> replaceAllAllowingPartialSuccess(List<com.broadleafcommerce.data.tracking.core.service.Update<P>> replacements, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
-
create
public P create(@NonNull P customer, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
-
createAll
public List<P> createAll(@NonNull List<P> customers, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
-
createAllAllowingPartialSuccess
public com.broadleafcommerce.data.tracking.core.service.BulkPersistenceResponse<P> createAllAllowingPartialSuccess(List<P> customers, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
-
handleEmailAsUsername
protected void handleEmailAsUsername(P customer)
Assign thecustomer
's username to match their email whenCustomerConfigurationProperties
is configured with email as username.- Parameters:
customer
- the customer for which to handle email as username
-
handleEmailAsUsernameUpdate
protected void handleEmailAsUsernameUpdate(P customer)
Adjust thecustomer
update for the username to match their email whenCustomerConfigurationProperties
is configured with email as username.- Parameters:
customer
- the customer update for which to handle email as username
-
handleAccountMemberUpdate
protected void handleAccountMemberUpdate(@NonNull P customer, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
Reflect thecustomer
updates to their correspondingAccountMember
instances, namely the full name and email updates.- Parameters:
customer
- the customer object containing the updatescontext
- context information surrounding sandboxing and multitenant state
-
getCustomerRepository
protected CustomerRepository<com.broadleafcommerce.data.tracking.core.Trackable> getCustomerRepository()
-
getCustomerProperties
protected CustomerConfigurationProperties getCustomerProperties()
-
getParser
protected com.broadleafcommerce.data.tracking.core.filtering.fetch.FilterParser<cz.jirutka.rsql.parser.ast.Node> getParser()
-
setAccountMemberService
@Autowired @Lazy public void setAccountMemberService(AccountMemberService<AccountMember> accountMemberService)
-
getAccountMemberService
protected AccountMemberService<AccountMember> getAccountMemberService()
-
-