com.elasticpath.service.catalog.impl
Class ProductServiceImpl

java.lang.Object
  extended by com.elasticpath.service.impl.AbstractEpServiceImpl
      extended by com.elasticpath.service.impl.AbstractEpPersistenceServiceImpl
          extended by com.elasticpath.service.catalog.impl.ProductServiceImpl
All Implemented Interfaces:
ProductService, EpPersistenceService, EpService

public class ProductServiceImpl
extends AbstractEpPersistenceServiceImpl
implements ProductService

The default implementation of ProductService.


Constructor Summary
ProductServiceImpl()
           
 
Method Summary
 Product add(Product product)
          Adds the given product.
 java.util.List findAllUids()
          Returns all product uids as a list.
 java.util.List findAvailableUids()
          Returns all available product uids as a list.
 java.util.List findAvailableUidsByModifiedDate(java.util.Date date)
          Retrieves list of Product uids where the last modified date is later than the specified date.
 java.util.List findByBrandUid(long brandUid)
          Returns a list of Product based on the given brand Uid.
 java.util.List findByBrandUid(long brandUid, ProductLoadTuner loadTuner)
          Returns a list of Product based on the given brand Uid.
 java.util.List findByCategoryUid(long categoryUid)
          Returns a list of Product based on the given category Uid.
 java.util.List findByCategoryUid(long categoryUid, ProductLoadTuner loadTuner)
          Returns a list of Product based on the given category Uid.
 java.util.List findByCategoryUidPaginated(long categoryUid, int startIndex, int numProducts, ProductLoadTuner loadTuner)
          Returns a list of Products based on the given category Uid.
 Product findByGuid(java.lang.String guid)
          Find the product with the given guid, for product, i.e.
 java.util.List findByModifiedDate(java.util.Date date)
          Retrieves list of Product where the last modified date is later than the specified date.
 java.util.List findByUids(java.util.Collection productUids, ProductLoadTuner loadTuner)
          Returns a list of Product based on the given uids.
 java.util.List findProductByCriteria(ProductSearchCriteria productSearchCriteria)
          Retrieve the list of products, whose specified property contain the given criteria value.
 java.util.List findProductTopSeller(int topCount, ProductLoadTuner productLoadTuner)
          Retrieve a list of top sellers of the whole store.
 java.util.List findProductTopSellerForCategory(long categoryUid)
          Retrieve the list of top selling products that belongs to the category or its subcategories.
 long findUidById(java.lang.String productId)
          Get the product UID of the given product identifier.
 java.util.List findUidsByCategoryUids(java.util.Collection categoryUids)
          Retrieves list of product uids belongs to either category uids given.
 java.util.List findUidsByDeletedDate(java.util.Date date)
          Retrieves list of product uids where the deleted date is later than the specified date.
 java.util.List findUidsByModifiedDate(java.util.Date date)
          Retrieves list of Product uids where the last modified date is later than the specified date.
 Product get(long productUid)
          Get the product with the given UID.
 java.lang.Object getObject(long uid)
          Generic get method for all persistable domain models.
 ProductCategory getProductCategoryByProCatUid(long productUid, long categoryUid)
          Get a ProductCategory by the product uidPk and category uidPk.
 ProductLoadTuner getProductLoadTunerMinimal()
          Returns the ProductLoadTuner for populating a minimal data set.
 int getProductSkuCount(long productUid)
          Get a count of ProductSkus belong to this product.
 Product getTuned(long productUid, ProductLoadTuner loadTuner, ShoppingCart shoppingCart)
          Get the product with the given UID.
 Utility getUtility()
          Returns the utility instance.
 Product getWithCategories(long productUid)
          Load the product with the given UID.
 boolean guidExists(java.lang.String guid)
          Checks whether the given product guid exists or not, for product, i.e.
 java.util.List list()
          List all products stored in the database.
 Product load(long productUid)
          Load the product with the given Uid.
 void removeProductList(java.util.List productUidList)
          Deletes the list of products.
 void removeProductTree(long productUid)
          Deletes the product and all it associations.
 void resetProductCategoryFeatured(long productUid, long categoryUid)
          Disable a ProductCategory as a featured product, if the featuredProductOrder is set to 0, means this productCategory is not featured.
 void saveOrUpdate(Product product)
          Save or update the given product.
 void setCategoryService(CategoryService categoryService)
          Set the CategoryService singleton.
 void setIndexSearchService(IndexSearchService indexSearchService)
          Set the indexSearchService instance.
 void setLazyLoadHelper(LazyLoadHelper lazyLoadHelper)
          Sets the lazy load helper.
 int setProductCategoryFeatured(long productUid, long categoryUid)
          Set a ProductCategory as a featured product, if the featuredProductOrder is set to be greater than 0, means this productCategory is featured.
 void setProductLoadTunerAll(ProductLoadTuner productLoadTunerAll)
          Sets the ProductLoadTuner for populating all data.
 void setProductLoadTunerForDefaultCategory(ProductLoadTuner productLoadTunerForDefaultCategory)
          Sets the ProductLoadTuner for populating the default category.
 void setProductLoadTunerMinimal(ProductLoadTuner productLoadTunerMinimal)
          Sets the ProductLoadTuner for populating a minimal data set.
 void setRuleEngine(EpRuleEngine epRuleEngine)
          Sets the rule engine.
 void setUtility(Utility utility)
          Sets the utility.
 void updateFeaturedProductOrder(long productUid, long categoryUid, long productUid2)
          Swap two ProductCategory featured product order.
 void updateLastModifiedTime(Product product)
          Update the product's last modified timestamp.
 
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

ProductServiceImpl

public ProductServiceImpl()
Method Detail

add

public Product add(Product product)
            throws EpServiceException
Adds the given product.

Specified by:
add in interface ProductService
Parameters:
product - the product to add
Returns:
the persisted instance of product
Throws:
EpServiceException - - in case of any errors

findAllUids

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

Specified by:
findAllUids in interface ProductService
Returns:
all product uids as a list

findAvailableUids

public java.util.List findAvailableUids()
Returns all available product uids as a list.

Specified by:
findAvailableUids in interface ProductService
Returns:
all available product uids as a list

findAvailableUidsByModifiedDate

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

Specified by:
findAvailableUidsByModifiedDate in interface ProductService
Parameters:
date - date to compare with the last modified date
Returns:
list of Product whose last modified date is later than the specified date

findByBrandUid

public java.util.List findByBrandUid(long brandUid)
Returns a list of Product based on the given brand Uid.

Specified by:
findByBrandUid in interface ProductService
Parameters:
brandUid - the brand Uid
Returns:
a list of Product

findByBrandUid

public java.util.List findByBrandUid(long brandUid,
                                     ProductLoadTuner loadTuner)
Returns a list of Product based on the given brand Uid. The returned products will be populated based on the given load tuner.

Specified by:
findByBrandUid in interface ProductService
Parameters:
brandUid - the brand Uid
loadTuner - the load tuner, give null to populate all related data
Returns:
a list of Product

findByCategoryUid

public java.util.List findByCategoryUid(long categoryUid)
Returns a list of Product based on the given category Uid.

Specified by:
findByCategoryUid in interface ProductService
Parameters:
categoryUid - the category Uid
Returns:
a list of Product

findByCategoryUid

public java.util.List findByCategoryUid(long categoryUid,
                                        ProductLoadTuner loadTuner)
Returns a list of Product based on the given category Uid. The returned products will be populated based on the given load tuner.

Specified by:
findByCategoryUid in interface ProductService
Parameters:
categoryUid - the category Uid
loadTuner - the load tuner, give null to populate all related data
Returns:
a list of Product

findByCategoryUidPaginated

public java.util.List findByCategoryUidPaginated(long categoryUid,
                                                 int startIndex,
                                                 int numProducts,
                                                 ProductLoadTuner loadTuner)
Returns a list of Products based on the given category Uid. The returned products will be populated based on the given load tuner. This method allows a subset of the products to be returned at a time by giving the starting index of the first product and the number of products to be returned.

Specified by:
findByCategoryUidPaginated in interface ProductService
Parameters:
categoryUid - the category Uid
startIndex - the starting index of the first product to be returned
numProducts - the number of products to be returned, starting from the start index
loadTuner - the load tuner, give null to populate all related data
Returns:
a list of Products

findByGuid

public Product findByGuid(java.lang.String guid)
                   throws EpServiceException
Find the product with the given guid, for product, i.e. product code.

Specified by:
findByGuid in interface ProductService
Parameters:
guid - the product code.
Returns:
the product that matches the given guid (code), otherwise null
Throws:
EpServiceException - - in case of any errors

findByModifiedDate

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

Specified by:
findByModifiedDate in interface ProductService
Parameters:
date - date to compare with the last modified date
Returns:
list of Product whose last modified date is later than the specified date

findByUids

public java.util.List findByUids(java.util.Collection productUids,
                                 ProductLoadTuner loadTuner)
Returns a list of Product based on the given uids. The returned products will be populated based on the given load tuner.

Specified by:
findByUids in interface ProductService
Parameters:
productUids - a collection of product uids
loadTuner - the load tuner
Returns:
a list of Products

findProductByCriteria

public java.util.List findProductByCriteria(ProductSearchCriteria productSearchCriteria)
Retrieve the list of products, whose specified property contain the given criteria value.

Specified by:
findProductByCriteria in interface ProductService
Parameters:
productSearchCriteria - criteria for product search.
Returns:
list of products matching the given criteria.

findProductTopSeller

public java.util.List findProductTopSeller(int topCount,
                                           ProductLoadTuner productLoadTuner)
                                    throws EpServiceException
Retrieve a list of top sellers of the whole store.

Specified by:
findProductTopSeller in interface ProductService
Parameters:
topCount - the number of top seller products to retrieve
productLoadTuner - the product load tunner to control data get loaded
Returns:
the list of top sellers of the whole store
Throws:
EpServiceException - in case of any error

findProductTopSellerForCategory

public java.util.List findProductTopSellerForCategory(long categoryUid)
                                               throws EpServiceException
Retrieve the list of top selling products that belongs to the category or its subcategories.

Specified by:
findProductTopSellerForCategory in interface ProductService
Parameters:
categoryUid - the category id
Returns:
the list of top selling products that belongs to the category or its subcategories
Throws:
EpServiceException - in case of any error

findUidById

public long findUidById(java.lang.String productId)
                 throws EpServiceException
Get the product UID of the given product identifier. The given product identifier will frist be dealt as a guid to try to find a product UID. It no product UID is found and the given identifier is a long value, itself will be dealt as UID.

Specified by:
findUidById in interface ProductService
Parameters:
productId - the Product Guid or UID.
Returns:
the product UID, otherwise 0
Throws:
EpServiceException - - in case of any errors

findUidsByCategoryUids

public java.util.List findUidsByCategoryUids(java.util.Collection categoryUids)
Retrieves list of product uids belongs to either category uids given.

Specified by:
findUidsByCategoryUids in interface ProductService
Parameters:
categoryUids - category uids
Returns:
list of product uids

findUidsByDeletedDate

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

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

findUidsByModifiedDate

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

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

get

public Product get(long productUid)
            throws EpServiceException
Get the product with the given UID. Return null if no matching record exists.

Specified by:
get in interface ProductService
Parameters:
productUid - the Product UID.
Returns:
the product if UID exists, otherwise null
Throws:
EpServiceException - - in case of any errors

getObject

public java.lang.Object getObject(long uid)
                           throws EpServiceException
Generic get 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

getProductCategoryByProCatUid

public ProductCategory getProductCategoryByProCatUid(long productUid,
                                                     long categoryUid)
Get a ProductCategory by the product uidPk and category uidPk.

Specified by:
getProductCategoryByProCatUid in interface ProductService
Parameters:
productUid - the unique identifier for the product
categoryUid - the unique identifier for the category
Returns:
productCategory the productCategory

getProductLoadTunerMinimal

public ProductLoadTuner getProductLoadTunerMinimal()
Returns the ProductLoadTuner for populating a minimal data set.

Returns:
a ProductLoadTuner for populating a minimal data set.

getProductSkuCount

public int getProductSkuCount(long productUid)
Get a count of ProductSkus belong to this product.

Specified by:
getProductSkuCount in interface ProductService
Parameters:
productUid - the uid of the product.
Returns:
a count of ProductSkus belong to this product.

getTuned

public Product getTuned(long productUid,
                        ProductLoadTuner loadTuner,
                        ShoppingCart shoppingCart)
                 throws EpServiceException
Get the product with the given UID. Return null if no matching record exists. You can give a product load tuner to fine control what data get populated of the returned product.

By giving a shopping cart, promotion rules will be applied to the returned product.

Specified by:
getTuned in interface ProductService
Parameters:
productUid - the Product UID.
loadTuner - the product load tuner
shoppingCart - the shopping cart, give null if you don't have it.
Returns:
the product if UID exists, otherwise null
Throws:
EpServiceException - - in case of any errors

getUtility

public Utility getUtility()
Returns the utility instance.

Returns:
the utility instance.

getWithCategories

public Product getWithCategories(long productUid)
                          throws EpServiceException
Load the product with the given UID. Also load all the categories that the product belongs to.

Specified by:
getWithCategories in interface ProductService
Parameters:
productUid - the product UID
Returns:
the product if UID exists, otherwise null
Throws:
EpServiceException - - in case of any errors

guidExists

public boolean guidExists(java.lang.String guid)
                   throws EpServiceException
Checks whether the given product guid exists or not, for product, i.e. product code.

Specified by:
guidExists in interface ProductService
Parameters:
guid - the product code.
Returns:
true if the given guid(code) exists.
Throws:
EpServiceException - - in case of any errors

list

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

Specified by:
list in interface ProductService
Returns:
a list of products
Throws:
EpServiceException - - in case of any errors

load

public Product load(long productUid)
             throws EpServiceException
Load the product with the given Uid.

Specified by:
load in interface ProductService
Parameters:
productUid - the product Uid
Returns:
the product if ID exists, otherwise null
Throws:
EpServiceException - - in case of any errors

removeProductList

public void removeProductList(java.util.List productUidList)
                       throws EpServiceException
Deletes the list of products.

Specified by:
removeProductList in interface ProductService
Parameters:
productUidList - the product Uid List to be removed
Throws:
EpServiceException - - in case of any errors

removeProductTree

public void removeProductTree(long productUid)
                       throws EpServiceException
Deletes the product and all it associations.

Specified by:
removeProductTree in interface ProductService
Parameters:
productUid - the uid of product to remove
Throws:
EpServiceException - in case of any errors

resetProductCategoryFeatured

public void resetProductCategoryFeatured(long productUid,
                                         long categoryUid)
Disable a ProductCategory as a featured product, if the featuredProductOrder is set to 0, means this productCategory is not featured.

Specified by:
resetProductCategoryFeatured in interface ProductService
Parameters:
productUid - the unique identifier for the product
categoryUid - the unique identifier for the category

saveOrUpdate

public void saveOrUpdate(Product product)
                  throws EpServiceException
Save or update the given product.

Specified by:
saveOrUpdate in interface ProductService
Parameters:
product - the product to save or update
Throws:
EpServiceException - - in case of any errors

setCategoryService

public void setCategoryService(CategoryService categoryService)
Set the CategoryService singleton.

Parameters:
categoryService - the CategoryService singleton.

setIndexSearchService

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

Parameters:
indexSearchService - the indexSearchService instance.

setLazyLoadHelper

public void setLazyLoadHelper(LazyLoadHelper lazyLoadHelper)
Sets the lazy load helper.

Parameters:
lazyLoadHelper - the lazy load helper

setProductCategoryFeatured

public int setProductCategoryFeatured(long productUid,
                                      long categoryUid)
Set a ProductCategory as a featured product, if the featuredProductOrder is set to be greater than 0, means this productCategory is featured.

Specified by:
setProductCategoryFeatured in interface ProductService
Parameters:
productUid - the unique identifier for the product
categoryUid - the unique identifier for the category
Returns:
featuredProductOrder the fetured product order of the ProductCategory

setProductLoadTunerAll

public void setProductLoadTunerAll(ProductLoadTuner productLoadTunerAll)
Sets the ProductLoadTuner for populating all data.

Parameters:
productLoadTunerAll - the ProductLoadTuner for populating all data.

setProductLoadTunerForDefaultCategory

public void setProductLoadTunerForDefaultCategory(ProductLoadTuner productLoadTunerForDefaultCategory)
Sets the ProductLoadTuner for populating the default category.

Parameters:
productLoadTunerForDefaultCategory - the ProductLoadTuner for populating the default category.

setProductLoadTunerMinimal

public void setProductLoadTunerMinimal(ProductLoadTuner productLoadTunerMinimal)
Sets the ProductLoadTuner for populating a minimal data set.

Parameters:
productLoadTunerMinimal - the ProductLoadTuner

setRuleEngine

public void setRuleEngine(EpRuleEngine epRuleEngine)
Sets the rule engine.

Parameters:
epRuleEngine - the rule engine

setUtility

public void setUtility(Utility utility)
Sets the utility.

Parameters:
utility - the utility to set

updateFeaturedProductOrder

public void updateFeaturedProductOrder(long productUid,
                                       long categoryUid,
                                       long productUid2)
Swap two ProductCategory featured product order.

Specified by:
updateFeaturedProductOrder in interface ProductService
Parameters:
productUid - the unique identifier for the product
categoryUid - the unique identifier for the category
productUid2 - the unique identifier for the product to be swaped

updateLastModifiedTime

public void updateLastModifiedTime(Product product)
Update the product's last modified timestamp.

Specified by:
updateLastModifiedTime in interface ProductService
Parameters:
product - the product whose timestamp is to be updated.