com.elasticpath.service.catalog.impl
Class CategoryServiceImpl

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

public class CategoryServiceImpl
extends AbstractEpPersistenceServiceImpl
implements CategoryService

The default implementation of CategoryService.


Constructor Summary
CategoryServiceImpl()
           
 
Method Summary
 Category add(Category category)
          Adds the given category.
 java.util.List findAllUids()
          Returns all category uids as a list.
 java.util.Set findAncestorCategoryUidsByCategoryUid(long categoryUid)
          Returns the set of category uids, which are ancestors of the given category uid.
 java.util.Set findAncestorCategoryUidsByProductUid(long productUid)
          Returns the set of category uids, which are ancestors of the given product uid.
 java.util.List findAvailableUids()
          Returns all available category uids as a list.
 Category findByGuid(java.lang.String guid)
          Retrieve the category with the given guid.
 java.util.List findByUids(java.util.Collection categoryUids, CategoryLoadTuner loadTuner)
          Returns a list of Category based on the given uids.
 java.util.List findCategoryByCriteria(CategorySearchCriteria categorySearchCriteria)
          Retrieve the list of categories, whose specified property contain the given criteria value.
 java.util.List findCategoryLike(java.lang.String propertyName, java.lang.String criteriaValue)
          Retrieve the list of categories, whose specified property contain the given criteria value.
 java.util.List findDecendantCategoryUids(java.util.List categoryUids)
          Retrieve all decendant category uids of the given category uids.
 java.util.List findDecendantCategoryUids(long categoryUid)
          Retrieve all the uids of direct and indirct subcategories.
 java.util.List findFeaturedProductUidList(long categoryUid)
          Get a list of featured product uid by the category uid.
 long findUidById(java.lang.String categoryId)
          Get the category UID of the given category identifier.
 java.util.List findUidsByDeletedDate(java.util.Date date)
          Retrieves list of category uids where the deleted date is later than the specified date.
 java.util.List findUidsByModifiedDate(java.util.Date date)
          Retrieves list of Category uids where the last modified date is later than the specified date.
 Category get(long categoryUid)
          Get the category with the given UID.
 CategoryLoadTuner getCategoryLoadTunerAll()
          Returns the CategoryLoadTuner for populating all data.
 CategoryLoadTuner getCategoryLoadTunerDefault()
          Returns the default CategoryLoadTuner.
 CategoryLoadTuner getCategoryLoadTunerMinimal()
          Returns the CategoryLoadTuner for populating minimal data.
 Category getCategoryWithAttribute(long categoryUid)
          Get the category with the given UID.
 Category getCategoryWithSubCategories(long categoryUid)
          Get the category with the given UID.
 java.util.List getFeaturedProductsList(long categoryUid)
          Get a list of featured product by the category uid.
 java.lang.Object getObject(long uid)
          Generic get method for all persistable domain models.
 java.util.List getSubCategories(long categoryUid)
          Retrieve the list of sub-categories of the current category.
 Utility getUtility()
          Returns the utility instance.
 boolean guidExists(java.lang.String guid)
          Checks whether the given category guid exists or not, for category, i.e.
 boolean hasProduct(long categoryUid)
          Check if the category has product.
 boolean isProductInCategory(long productUid, long categoryUid)
          Return true if the product with the given productuid is in the category with the given categoryuid.
 java.util.List listRootCategories(boolean availableOnly)
          Retrieve all root categories.
 java.util.List listRootCategoriesWithTree(boolean availableOnly)
          Retrieve root categories with the entire tree of children loaded.
 Category load(long categoryUid)
          Load the category with the given Uid.
 void removeCategoryTree(long categoryUid)
          Deletes the category and all sub categories and products with the default category set.
 void saveOrUpdate(Category category)
          Save or update the given category.
 void setCategoryLoadTunerAll(CategoryLoadTuner categoryLoadTunerAll)
          Sets the CategoryLoadTuner for populating all data.
 void setCategoryLoadTunerDefault(CategoryLoadTuner categoryLoadTunerDefault)
          Sets the default CategoryLoadTuner.
 void setCategoryLoadTunerMinimal(CategoryLoadTuner categoryLoadTunerMinimal)
          Sets the CategoryLoadTuner for populating minimal data.
 void setIndexSearchService(IndexSearchService indexSearchService)
          Sets the index search service.
 void setLazyLoadHelper(LazyLoadHelper lazyLoadHelper)
          Sets the lazy load helper.
 void setUtility(Utility utility)
          Sets the utility.
 void update(Category category)
          Updates the given category.
 void updateOrder(long uidOne, long uidTwo)
          Re orders (swaps the ordering field) of the two parameter categories.
 void updatePosition(long uidPk, long oldParentUid, long newParentUid, java.lang.Long newPreviousCategoryUid)
          Updates the position (parent category) and ordering of category after a drag and drop.
 
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

CategoryServiceImpl

public CategoryServiceImpl()
Method Detail

add

public Category add(Category category)
             throws EpServiceException
Adds the given category.

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

findAllUids

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

Specified by:
findAllUids in interface CategoryService
Returns:
all category uids as a list

findAncestorCategoryUidsByCategoryUid

public java.util.Set findAncestorCategoryUidsByCategoryUid(long categoryUid)
Returns the set of category uids, which are ancestors of the given category uid.

Specified by:
findAncestorCategoryUidsByCategoryUid in interface CategoryService
Parameters:
categoryUid - the category uid
Returns:
a set of category uids

findAncestorCategoryUidsByProductUid

public java.util.Set findAncestorCategoryUidsByProductUid(long productUid)
Returns the set of category uids, which are ancestors of the given product uid.

Specified by:
findAncestorCategoryUidsByProductUid in interface CategoryService
Parameters:
productUid - the product uid
Returns:
a set of category uids

findAvailableUids

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

Specified by:
findAvailableUids in interface CategoryService
Returns:
all available category uids as a list

findByGuid

public Category findByGuid(java.lang.String guid)
                    throws EpServiceException
Retrieve the category with the given guid.

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

findByUids

public java.util.List findByUids(java.util.Collection categoryUids,
                                 CategoryLoadTuner loadTuner)
Returns a list of Category based on the given uids. The returned category will be populated based on the given load tuner.

Specified by:
findByUids in interface CategoryService
Parameters:
categoryUids - a collection of category uids
loadTuner - the load tuner
Returns:
a list of Categorys

findCategoryByCriteria

public java.util.List findCategoryByCriteria(CategorySearchCriteria categorySearchCriteria)
Retrieve the list of categories, whose specified property contain the given criteria value.

Specified by:
findCategoryByCriteria in interface CategoryService
Parameters:
categorySearchCriteria - criteria for category search.
Returns:
list of categories matching the given criteria.

findCategoryLike

public java.util.List findCategoryLike(java.lang.String propertyName,
                                       java.lang.String criteriaValue)
                                throws EpServiceException
Retrieve the list of categories, whose specified property contain the given criteria value.

Specified by:
findCategoryLike in interface CategoryService
Parameters:
propertyName - category property to search on.
criteriaValue - criteria value to be used for searching.
Returns:
list of categories matching the given criteria.
Throws:
EpServiceException - in case of any error

findDecendantCategoryUids

public java.util.List findDecendantCategoryUids(java.util.List categoryUids)
Retrieve all decendant category uids of the given category uids.

Specified by:
findDecendantCategoryUids in interface CategoryService
Parameters:
categoryUids - the category uids.
Returns:
the list of uids of the direct and indirct subcategories of the given start category uids.

findDecendantCategoryUids

public java.util.List findDecendantCategoryUids(long categoryUid)
Retrieve all the uids of direct and indirct subcategories.

Specified by:
findDecendantCategoryUids in interface CategoryService
Parameters:
categoryUid - the start category uid.
Returns:
the list of uids of the direct and indirct subcategories of the given start category.

findFeaturedProductUidList

public java.util.List findFeaturedProductUidList(long categoryUid)
Get a list of featured product uid by the category uid.

Specified by:
findFeaturedProductUidList in interface CategoryService
Parameters:
categoryUid - the category uid.
Returns:
a list of product uid.

findUidById

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

Specified by:
findUidById in interface CategoryService
Parameters:
categoryId - the category Guid or UID.
Returns:
the category UID, otherwise 0
Throws:
EpServiceException - - in case of any errors

findUidsByDeletedDate

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

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

findUidsByModifiedDate

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

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

get

public Category get(long categoryUid)
             throws EpServiceException
Get the category with the given UID. Return null if no matching record exists.

Specified by:
get in interface CategoryService
Parameters:
categoryUid - the category UID
Returns:
the category if UID exists, otherwise null
Throws:
EpServiceException - - in case of any errors

getCategoryLoadTunerAll

public CategoryLoadTuner getCategoryLoadTunerAll()
Returns the CategoryLoadTuner for populating all data.

Returns:
the CategoryLoadTuner for populating all data

getCategoryLoadTunerDefault

public CategoryLoadTuner getCategoryLoadTunerDefault()
Returns the default CategoryLoadTuner.

Returns:
the default CategoryLoadTuner

getCategoryLoadTunerMinimal

public CategoryLoadTuner getCategoryLoadTunerMinimal()
Returns the CategoryLoadTuner for populating minimal data.

Returns:
the CategoryLoadTuner for populating minimal data

getCategoryWithAttribute

public Category getCategoryWithAttribute(long categoryUid)
                                  throws EpServiceException
Get the category with the given UID. Return null if no matching record exists.

Specified by:
getCategoryWithAttribute in interface CategoryService
Parameters:
categoryUid - the category UID
Returns:
the category with attribute populated if UID exists, otherwise null
Throws:
EpServiceException - - in case of any errors

getCategoryWithSubCategories

public Category getCategoryWithSubCategories(long categoryUid)
                                      throws EpServiceException
Get the category with the given UID. Return null if no matching record exists. All sub-categories will also be poplulated. This method also populates attributes

Specified by:
getCategoryWithSubCategories in interface CategoryService
Parameters:
categoryUid - the category UID
Returns:
the category if UID exists, otherwise null
Throws:
EpServiceException - - in case of any errors

getFeaturedProductsList

public java.util.List getFeaturedProductsList(long categoryUid)
Get a list of featured product by the category uid.

Specified by:
getFeaturedProductsList in interface CategoryService
Parameters:
categoryUid - the category uidPk.
Returns:
a list of Product

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

getSubCategories

public java.util.List getSubCategories(long categoryUid)
Retrieve the list of sub-categories of the current category.

Specified by:
getSubCategories in interface CategoryService
Parameters:
categoryUid - the current category
Returns:
the list of sub-categories of the current category.

getUtility

public Utility getUtility()
Returns the utility instance.

Returns:
the utility instance.

guidExists

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

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

hasProduct

public boolean hasProduct(long categoryUid)
                   throws EpServiceException
Check if the category has product.

Specified by:
hasProduct in interface CategoryService
Parameters:
categoryUid - the Uid of the category to be checked.
Returns:
true if the category has products
Throws:
EpServiceException - in case of any error

isProductInCategory

public boolean isProductInCategory(long productUid,
                                   long categoryUid)
Return true if the product with the given productuid is in the category with the given categoryuid. Otherwise, false

Specified by:
isProductInCategory in interface CategoryService
Parameters:
productUid - the product uid
categoryUid - the category uid
Returns:
true if the product with the given productuid is in the category with the given categoryuid. Otherwise, false

listRootCategories

public java.util.List listRootCategories(boolean availableOnly)
Retrieve all root categories.

Specified by:
listRootCategories in interface CategoryService
Parameters:
availableOnly - set it to true to only list available root categories
Returns:
return all root categories

listRootCategoriesWithTree

public java.util.List listRootCategoriesWithTree(boolean availableOnly)
Retrieve root categories with the entire tree of children loaded.

Specified by:
listRootCategoriesWithTree in interface CategoryService
Parameters:
availableOnly - set it to true to only list available categories
Returns:
root categories with the entrie tree of children categories loaded

load

public Category load(long categoryUid)
              throws EpServiceException
Load the category with the given Uid.

Specified by:
load in interface CategoryService
Parameters:
categoryUid - the category Uid
Returns:
the category if ID exists, otherwise null
Throws:
EpServiceException - - in case of any errors

removeCategoryTree

public void removeCategoryTree(long categoryUid)
                        throws EpServiceException
Deletes the category and all sub categories and products with the default category set.

Specified by:
removeCategoryTree in interface CategoryService
Parameters:
categoryUid - the uid of the category to remove
Throws:
EpServiceException - - in case of any errors

saveOrUpdate

public void saveOrUpdate(Category category)
                  throws EpServiceException
Save or update the given category.

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

setCategoryLoadTunerAll

public void setCategoryLoadTunerAll(CategoryLoadTuner categoryLoadTunerAll)
Sets the CategoryLoadTuner for populating all data.

Parameters:
categoryLoadTunerAll - the CategoryLoadTuner for populating all data.

setCategoryLoadTunerDefault

public void setCategoryLoadTunerDefault(CategoryLoadTuner categoryLoadTunerDefault)
Sets the default CategoryLoadTuner.

Parameters:
categoryLoadTunerDefault - the default CategoryLoadTuner

setCategoryLoadTunerMinimal

public void setCategoryLoadTunerMinimal(CategoryLoadTuner categoryLoadTunerMinimal)
Sets the CategoryLoadTuner for populating minimal data.

Parameters:
categoryLoadTunerMinimal - the CategoryLoadTuner for populating minimal data.

setIndexSearchService

public void setIndexSearchService(IndexSearchService indexSearchService)
Sets the index search service.

Parameters:
indexSearchService - the index search service.

setLazyLoadHelper

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

Parameters:
lazyLoadHelper - the lazy load helper

setUtility

public void setUtility(Utility utility)
Sets the utility.

Parameters:
utility - the utility to set

update

public void update(Category category)
            throws EpServiceException
Updates the given category.

Specified by:
update in interface CategoryService
Parameters:
category - the category to update
Throws:
EpServiceException - - in case of any errors

updateOrder

public void updateOrder(long uidOne,
                        long uidTwo)
Re orders (swaps the ordering field) of the two parameter categories. If ordering hasn't been set before, then will go thru the whole parent category and order all the child categories first.

Specified by:
updateOrder in interface CategoryService
Parameters:
uidOne - uid of a category to reorder
uidTwo - uid of a category to reorder

updatePosition

public void updatePosition(long uidPk,
                           long oldParentUid,
                           long newParentUid,
                           java.lang.Long newPreviousCategoryUid)
Updates the position (parent category) and ordering of category after a drag and drop.

Specified by:
updatePosition in interface CategoryService
Parameters:
uidPk - uid of category
oldParentUid - uid of old parent
newParentUid - uid of new parent
newPreviousCategoryUid - uid of category directly in front of category (ordering-wise).