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 of Customer
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 of CustomerService
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

    Modifier and Type
    Method
    Description
    create(P customer, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
     
    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 CustomerRepository<com.broadleafcommerce.data.tracking.core.Trackable>
     
    protected com.broadleafcommerce.data.tracking.core.filtering.fetch.FilterParser<cz.jirutka.rsql.parser.ast.Node>
     
    protected void
    handleAccountMemberUpdate(P customer, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    Reflect the customer updates to their corresponding AccountMember instances, namely the full name and email updates.
    protected void
    Assign the customer's username to match their email when CustomerConfigurationProperties is configured with email as username.
    protected void
    Adjust the customer update for the username to match their email when CustomerConfigurationProperties is configured with email as username.
    readAllByEmail(Set<String> emails, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Searches for customers in the data store whose Customer.email contains in the given emails.
    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 whose Customer#name matches the given nameQuery.
    readAllUniqueIds(int page, cz.jirutka.rsql.parser.ast.Node filters)
    Retrieves a list of unique customer context IDs no larger than page.
    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.
    readByEmail(String email, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Find a customer by email.
    readCustomersPagingStream(cz.jirutka.rsql.parser.ast.Node filters, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Reads all customers matching the given filters.
    replace(String id, P customer, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
     
    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
     
    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 filters
    update(String id, P customer, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
     
    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

    Methods inherited from interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService

    delete, readAll, readAll, readAll, readAllByContextId, readByContextId, updateSort

    Methods inherited from interface com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityService

    readAll, readAll, readAll, readAll
  • Constructor Details

    • 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 Details

    • 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 interface CustomerService<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 whose Customer#name matches the given nameQuery. Ignores case.
      Specified by:
      readAllByFullName in interface CustomerService<P extends Customer>
      Parameters:
      nameQuery - the name to search for
      filters - An RSQL filter used to narrow query results. May be EmptyNode if no filters should be applied.
      page - the requested page of results from the database
      contextInfo - context information surrounding sandboxing and multitenant state
      Returns:
      the customers in the data store whose Customer#name matches the given nameQuery. 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 whose Customer.email contains in the given emails. Ignores case.
      Specified by:
      readAllByEmail in interface CustomerService<P extends Customer>
      Parameters:
      emails - the set of emails to search for
      contextInfo - context information surrounding sandboxing and multitenant state
      Returns:
      the customers in the data store whose Customer.email contains in the given emails. 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 in filters.
      Specified by:
      readAllUniqueIds in interface CustomerService<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 be EmptyNode 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 interface CustomerService<P extends Customer>
      Parameters:
      filters - An RSQL filter used to narrow query results. May be EmptyNode if no filters should be applied.
      sort - The string containing the structured list of sorts to apply. May be Sort.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 interface CustomerService<P extends Customer>
      Parameters:
      filters - additional filters to apply in the query
      contextInfo - 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, the contextInfo argument is required.
      Specified by:
      readByEmail in interface CustomerService<P extends Customer>
      Parameters:
      email - The email to search for
      contextInfo - 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)
      Specified by:
      update in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends Customer>
      Overrides:
      update in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends Customer>
    • 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)
      Specified by:
      updateAll in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends Customer>
      Overrides:
      updateAll in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends Customer>
    • 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)
      Specified by:
      updateAllAllowingPartialSuccess in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends Customer>
      Overrides:
      updateAllAllowingPartialSuccess in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends Customer>
    • replace

      public P replace(@NonNull String id, @NonNull P customer, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Specified by:
      replace in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends Customer>
      Overrides:
      replace in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends Customer>
    • replaceAll

      public List<P> replaceAll(List<com.broadleafcommerce.data.tracking.core.service.Update<P>> replacements, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Specified by:
      replaceAll in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends Customer>
      Overrides:
      replaceAll in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends Customer>
    • 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)
      Specified by:
      replaceAllAllowingPartialSuccess in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends Customer>
      Overrides:
      replaceAllAllowingPartialSuccess in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends Customer>
    • create

      public P create(@NonNull P customer, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Specified by:
      create in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends Customer>
      Overrides:
      create in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends Customer>
    • createAll

      public List<P> createAll(@NonNull List<P> customers, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Specified by:
      createAll in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends Customer>
      Overrides:
      createAll in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends Customer>
    • createAllAllowingPartialSuccess

      public com.broadleafcommerce.data.tracking.core.service.BulkPersistenceResponse<P> createAllAllowingPartialSuccess(List<P> customers, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Specified by:
      createAllAllowingPartialSuccess in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends Customer>
      Overrides:
      createAllAllowingPartialSuccess in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends Customer>
    • handleEmailAsUsername

      protected void handleEmailAsUsername(P customer)
      Assign the customer's username to match their email when CustomerConfigurationProperties is configured with email as username.
      Parameters:
      customer - the customer for which to handle email as username
    • handleEmailAsUsernameUpdate

      protected void handleEmailAsUsernameUpdate(P customer)
      Adjust the customer update for the username to match their email when CustomerConfigurationProperties 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 the customer updates to their corresponding AccountMember instances, namely the full name and email updates.
      Parameters:
      customer - the customer object containing the updates
      context - 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()