com.elasticpath.service.customer.impl
Class CustomerServiceImpl

java.lang.Object
  extended by com.elasticpath.service.impl.AbstractEpServiceImpl
      extended by com.elasticpath.service.impl.AbstractEpPersistenceServiceImpl
          extended by com.elasticpath.service.customer.impl.CustomerServiceImpl
All Implemented Interfaces:
CustomerService, EpPersistenceService, EpService

public class CustomerServiceImpl
extends AbstractEpPersistenceServiceImpl
implements CustomerService

The default implementation of CustomerService.


Constructor Summary
CustomerServiceImpl()
           
 
Method Summary
 Customer add(Customer customer)
          Adds the given customer.
 Customer addCustomerAddress(Customer customer, CustomerAddress address)
          Adds an address to a customer.
 Customer addCustomerCreditCard(Customer customer, CustomerCreditCard creditCard)
          Adds a credit card to a customer.
 Customer deleteCustomerAddresses(Customer customer)
          This is a workaround for deleteing address(s) since Hibernate can not cascade delete entity object in a collection if it not removed from the collection loaded in the same session.
 Customer deleteCustomerCreditCards(Customer customer)
          This is a workaround for deleteing credit card(s) since Hibernate can not cascade delete entity object in a collection if it not removed from the collection loaded in the same session.
 boolean emailExists(Customer customer)
          Check the given customer's email exists or not.
 java.util.List findAllUids()
          Returns all customer uids as a list.
 java.util.List findByEmail(java.lang.String email)
          Find the customer with the given email address.
 Customer findByGuid(java.lang.String guid)
          Retrieve the customer with the given guid.
 java.util.List findByUids(java.util.Collection customerUids)
          Returns a list of Customer based on the given uids.
 java.util.List findByUserId(java.lang.String userId)
          Find the customer with the given userId address.
 java.util.List findCustomerByCriteria(CustomerSearchCriteria customerSearchCriteria)
          Retrieve the list of customers, whose specified property contain the given criteria value.
 java.util.List findCustomerLike(java.lang.String propertyName, java.lang.String criteriaValue)
          Retrieve the list of customers, whose specified property contain the given criteria value.
 Customer findNonAnonymousByEmail(java.lang.String email)
          Find the non-anonymous customer with the given email address.
 Customer findNonAnonymousByUserId(java.lang.String userId)
          Find the non-anonymous customer with the given userId address.
 java.util.List findUidsByDeletedDate(java.util.Date date)
          Retrieves list of customer uids where the deleted date is later than the specified date.
 java.util.List findUidsByModifiedDate(java.util.Date date)
          Retrieves list of Customer uids where the last modified date is later than the specified date.
 Customer get(long customerUid)
          Get the customer with the given UID.
 java.lang.Object getObject(long uid)
          Generic load method for all persistable domain models.
 boolean isEmailExists(java.lang.String email)
          Checks the given email exists or not.
 boolean isUserIdExists(java.lang.String userId)
          Checks the given user Id exists or not.
 java.util.List list()
          Lists all customers stored in the database.
 Customer load(long customerUid)
          Load the customer with the given UID.
 void remove(Customer customer)
          Deletes the customer.
 void resetPassword(java.lang.String userId)
          Resets the customer's password for the specified email.
 void setCustomerDefaultGroup(Customer customer)
          Adds a customer to the default customer group (ensuring that they have the default role).
 void setCustomerGroupService(CustomerGroupService customerGroupService)
          Set the customerGroupService instance.
 void setCustomerSessionService(CustomerSessionService customerSessionService)
          Set the customerSessionService instance.
 void setEmailService(EmailService emailService)
          Set the emailService.
 void setIndexSearchService(IndexSearchService indexSearchService)
          Set the indexSearchService instance.
 void setPassword(Customer customer, java.lang.String newPassword)
          Changes the password for the specified customer.
 void setUserIdentityService(UserIdentityService userIdentityService)
          Set the userIdentityService instance.
 void setUtility(Utility utility)
          Sets the utility.
 Customer update(Customer customer)
          Updates the given customer.
 boolean userIdExists(Customer customer)
          Check the given customer's user Id exists or not.
 void validateNewCustomer(Customer customer)
          Validate the new customer has the valid email address (not used by any existing non-anonymous customer).
 
Methods inherited from class com.elasticpath.service.impl.AbstractEpPersistenceServiceImpl
getPersistenceEngine, setPersistenceEngine
 
Methods inherited from class com.elasticpath.service.impl.AbstractEpServiceImpl
getElasticPath, setElasticPath
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.elasticpath.service.EpPersistenceService
getPersistenceEngine, setPersistenceEngine
 
Methods inherited from interface com.elasticpath.service.EpService
getElasticPath, setElasticPath
 

Constructor Detail

CustomerServiceImpl

public CustomerServiceImpl()
Method Detail

add

public Customer add(Customer customer)
             throws UserIdExistException
Adds the given customer.

Specified by:
add in interface CustomerService
Parameters:
customer - the customer to add
Returns:
the persisted instance of customer
Throws:
UserIdExistException - - if trying to add an customer using an user Id.

addCustomerAddress

public Customer addCustomerAddress(Customer customer,
                                   CustomerAddress address)
Adds an address to a customer.

Specified by:
addCustomerAddress in interface CustomerService
Parameters:
customer - The customer who is adding an address
address - The address to be added to the customer
Returns:
the updated Customer

addCustomerCreditCard

public Customer addCustomerCreditCard(Customer customer,
                                      CustomerCreditCard creditCard)
Adds a credit card to a customer.

Specified by:
addCustomerCreditCard in interface CustomerService
Parameters:
customer - The customer who is adding a credit card
creditCard - The credit card to be added to the customer
Returns:
the updated Customer

deleteCustomerAddresses

public Customer deleteCustomerAddresses(Customer customer)
This is a workaround for deleteing address(s) since Hibernate can not cascade delete entity object in a collection if it not removed from the collection loaded in the same session.

Specified by:
deleteCustomerAddresses in interface CustomerService
Parameters:
customer - The customer whose address list has been updated
Returns:
the updated Customer

deleteCustomerCreditCards

public Customer deleteCustomerCreditCards(Customer customer)
This is a workaround for deleteing credit card(s) since Hibernate can not cascade delete entity object in a collection if it not removed from the collection loaded in the same session.

Specified by:
deleteCustomerCreditCards in interface CustomerService
Parameters:
customer - The customer whose credit card list has been updated
Returns:
the updated Customer

emailExists

public boolean emailExists(Customer customer)
                    throws EpServiceException
Check the given customer's email exists or not.

Specified by:
emailExists in interface CustomerService
Parameters:
customer - the customer to check
Returns:
true if the given email exists
Throws:
EpServiceException - - in case of any errors

findAllUids

public java.util.List findAllUids()
Returns all customer uids as a list.

Specified by:
findAllUids in interface CustomerService
Returns:
all customer uids as a list

findByEmail

public java.util.List findByEmail(java.lang.String email)
                           throws EpServiceException
Find the customer with the given email address.

Specified by:
findByEmail in interface CustomerService
Parameters:
email - the customer email address
Returns:
the customers with the given email address.
Throws:
EpServiceException - - in case of any errors

findByGuid

public Customer findByGuid(java.lang.String guid)
                    throws EpServiceException
Retrieve the customer with the given guid.

Specified by:
findByGuid in interface CustomerService
Parameters:
guid - the guid of the customer
Returns:
the customer with the given guid
Throws:
EpServiceException - in case of any error

findByUids

public java.util.List findByUids(java.util.Collection customerUids)
Returns a list of Customer based on the given uids. The returned customers will be populated based on the given load tuner.

Specified by:
findByUids in interface CustomerService
Parameters:
customerUids - a collection of customer uids
Returns:
a list of Customers

findByUserId

public java.util.List findByUserId(java.lang.String userId)
                            throws EpServiceException
Find the customer with the given userId address.

Specified by:
findByUserId in interface CustomerService
Parameters:
userId - the customer userId address
Returns:
the customers with the given userId address.
Throws:
EpServiceException - - in case of any errors

findCustomerByCriteria

public java.util.List findCustomerByCriteria(CustomerSearchCriteria customerSearchCriteria)
Retrieve the list of customers, whose specified property contain the given criteria value.

Specified by:
findCustomerByCriteria in interface CustomerService
Parameters:
customerSearchCriteria - criteria for customer search.
Returns:
list of customers matching the given criteria.

findCustomerLike

public java.util.List findCustomerLike(java.lang.String propertyName,
                                       java.lang.String criteriaValue)
Retrieve the list of customers, whose specified property contain the given criteria value. TODO: check the performance of this versus using direct query.

Specified by:
findCustomerLike in interface CustomerService
Parameters:
propertyName - customer property to search on.
criteriaValue - criteria value to be used for searching.
Returns:
list of customers matching the given criteria.

findNonAnonymousByEmail

public Customer findNonAnonymousByEmail(java.lang.String email)
                                 throws EpServiceException
Find the non-anonymous customer with the given email address.

Specified by:
findNonAnonymousByEmail in interface CustomerService
Parameters:
email - the customer email address
Returns:
the non-anonymous customer with the given email address if exists, otherwise null
Throws:
EpServiceException - - in case of any errors

findNonAnonymousByUserId

public Customer findNonAnonymousByUserId(java.lang.String userId)
                                  throws EpServiceException
Find the non-anonymous customer with the given userId address.

Specified by:
findNonAnonymousByUserId in interface CustomerService
Parameters:
userId - the customer userId address
Returns:
the non-anonymous customer with the given userId address if exists, otherwise null
Throws:
EpServiceException - - in case of any errors

findUidsByDeletedDate

public java.util.List findUidsByDeletedDate(java.util.Date date)
Retrieves list of customer uids where the deleted date is later than the specified date.

Specified by:
findUidsByDeletedDate in interface CustomerService
Parameters:
date - date to compare with the deleted date
Returns:
list of customer uids whose deleted date is later than the specified date

findUidsByModifiedDate

public java.util.List findUidsByModifiedDate(java.util.Date date)
Retrieves list of Customer uids where the last modified date is later than the specified date.

Specified by:
findUidsByModifiedDate in interface CustomerService
Parameters:
date - date to compare with the last modified date
Returns:
list of Customer whose last modified date is later than the specified date

get

public Customer get(long customerUid)
             throws EpServiceException
Get the customer with the given UID. Return null if no matching record exists.

Specified by:
get in interface CustomerService
Parameters:
customerUid - the customer UID
Returns:
the customer if UID exists, otherwise null
Throws:
EpServiceException - - in case of any errors

getObject

public java.lang.Object getObject(long uid)
                           throws EpServiceException
Generic load method for all persistable domain models.

Specified by:
getObject in interface EpPersistenceService
Parameters:
uid - the persisted instance uid
Returns:
the persisted instance if exists, otherwise null
Throws:
EpServiceException - - in case of any errors

isEmailExists

public boolean isEmailExists(java.lang.String email)
                      throws EpServiceException
Checks the given email exists or not.

Specified by:
isEmailExists in interface CustomerService
Parameters:
email - the user Id
Returns:
true if the given user Id exists
Throws:
EpServiceException - - in case of any errors

isUserIdExists

public boolean isUserIdExists(java.lang.String userId)
                       throws EpServiceException
Checks the given user Id exists or not.

Specified by:
isUserIdExists in interface CustomerService
Parameters:
userId - the user Id
Returns:
true if the given user Id exists
Throws:
EpServiceException - - in case of any errors

list

public java.util.List list()
                    throws EpServiceException
Lists all customers stored in the database.

Specified by:
list in interface CustomerService
Returns:
a list of customers
Throws:
EpServiceException - - in case of any errors

load

public Customer load(long customerUid)
              throws EpServiceException
Load the customer with the given UID. Throw an unrecoverable exception if there is no matching database row.

Specified by:
load in interface CustomerService
Parameters:
customerUid - the customer UID
Returns:
the customer if UID exists, otherwise null
Throws:
EpServiceException - - in case of any errors

remove

public void remove(Customer customer)
            throws EpServiceException
Deletes the customer.

Specified by:
remove in interface CustomerService
Parameters:
customer - the customer to remove
Throws:
EpServiceException - - in case of any errors

resetPassword

public void resetPassword(java.lang.String userId)
                   throws UserIdNonExistException
Resets the customer's password for the specified email.

Specified by:
resetPassword in interface CustomerService
Parameters:
userId - The user Id of the customer whose password is to be reset
Throws:
UserIdNonExistException - if the user Id isn't found

setCustomerDefaultGroup

public void setCustomerDefaultGroup(Customer customer)
                             throws EpServiceException
Adds a customer to the default customer group (ensuring that they have the default role).

Specified by:
setCustomerDefaultGroup in interface CustomerService
Parameters:
customer - the customer upon which to set the default group
Throws:
EpServiceException - in case of any errors.

setCustomerGroupService

public void setCustomerGroupService(CustomerGroupService customerGroupService)
Set the customerGroupService instance.

Parameters:
customerGroupService - the customerGroupService instance.

setCustomerSessionService

public void setCustomerSessionService(CustomerSessionService customerSessionService)
Set the customerSessionService instance.

Specified by:
setCustomerSessionService in interface CustomerService
Parameters:
customerSessionService - the customerSessionService instance.

setEmailService

public void setEmailService(EmailService emailService)
Set the emailService.

Parameters:
emailService - the emailService

setIndexSearchService

public void setIndexSearchService(IndexSearchService indexSearchService)
Set the indexSearchService instance.

Parameters:
indexSearchService - the indexSearchService instance.

setPassword

public void setPassword(Customer customer,
                        java.lang.String newPassword)
Changes the password for the specified customer.

Specified by:
setPassword in interface CustomerService
Parameters:
customer - the customer whose password is to be changed
newPassword - the new password (clear text)

setUserIdentityService

public void setUserIdentityService(UserIdentityService userIdentityService)
Set the userIdentityService instance.

Specified by:
setUserIdentityService in interface CustomerService
Parameters:
userIdentityService - the userIdentityService instance.

setUtility

public void setUtility(Utility utility)
Sets the utility.

Parameters:
utility - the utility to set

update

public Customer update(Customer customer)
                throws UserIdExistException
Updates the given customer.

Specified by:
update in interface CustomerService
Parameters:
customer - the customer to update
Returns:
the persisted instance of customer
Throws:
UserIdExistException - - if the customer's new user Id is already in use by another existing customer.

userIdExists

public boolean userIdExists(Customer customer)
                     throws EpServiceException
Check the given customer's user Id exists or not.

Specified by:
userIdExists in interface CustomerService
Parameters:
customer - the customer to check
Returns:
true if the given user Id exists
Throws:
EpServiceException - - in case of any errors

validateNewCustomer

public void validateNewCustomer(Customer customer)
                         throws EmailExistException
Validate the new customer has the valid email address (not used by any existing non-anonymous customer).

Specified by:
validateNewCustomer in interface CustomerService
Parameters:
customer - the nre customer.
Throws:
EmailExistException - - if the new customer's email address already exists in system.