Package de.hybris.platform.category
Interface CategoryService
-
- All Known Implementing Classes:
DefaultCategoryService
public interface CategoryService
Provides methods for working withCategoryModel
. Please be aware that since CategoryModel is catalog version aware, all methods of this service will work according to the active session catalog versions (seeCatalogVersionService.setSessionCatalogVersions(Collection)
for more details). So in consequence, the methods may return different results for different session users. If required, the following example shows how to temporarily switch these active catalog versions without changing the enclosing callers session context:SessionService sessionService = ...; CatalogVersionService catalogVersionService = ...; CatalogVersionModel myCatalogVersion = ...; Collection<CategoryModel> rootCategories = (Collection<CategoryModel>) sessionService .executeInLocalView(new SessionExecutionBody() { public Object execute() { catalogVersionService.setSessionCatalogVersions(Collections.singleton(myCatalogVersion)); return categoryService.getRootCategoriesForCatalogVersion(myCatalogVersion); } });
- See Also:
CatalogVersionService
- Spring Bean ID:
- categoryService
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description void
disableSubcategoryRemovalCheck()
Disable subcategory removal check.void
enableSubcategoryRemovalCheck()
Enable subcategory removal check.java.util.Collection<CategoryModel>
getAllSubcategoriesForCategory(CategoryModel category)
Gets all subcategories for category and all subcategories recursively.java.util.Collection<CategoryModel>
getAllSupercategoriesForCategory(CategoryModel category)
Gets the all supercategories for categories.java.util.Collection<CategoryModel>
getCategoriesForCode(java.lang.String code)
Retrieves for the givencode
all foundCategoryModel
s.CategoryModel
getCategory(CatalogVersionModel catalogVersion, java.lang.String code)
Deprecated.since 4.3, please usegetCategoryForCode(CatalogVersionModel, String)
.CategoryModel
getCategory(java.lang.String code)
Deprecated.since 4.3, please usegetCategoryForCode(String)
orgetCategoriesForCode(String)
.CategoryModel
getCategoryForCode(CatalogVersionModel catalogVersion, java.lang.String code)
Retrieves theCategoryModel
with the specifiedcode
which belonging to the specifiedcatalogVersion
.CategoryModel
getCategoryForCode(java.lang.String code)
Retrieves theCategoryModel
with the specificcode
.java.util.List<CategoryModel>
getCategoryPathForProduct(ProductModel product, java.lang.Class... includeOnlyCategories)
Gets the category path for product.java.util.List<CategoryModel>
getPath(CategoryModel category)
Deprecated.since 4.3, please usegetPathForCategory(CategoryModel)
.java.util.List<CategoryModel>
getPathForCategory(CategoryModel category)
Returns the path from root category to the givenCategoryModel
.java.util.Collection<java.util.List<CategoryModel>>
getPathsForCategory(CategoryModel category)
Returns all paths for thisCategoryModel
.java.util.Collection<CategoryModel>
getRootCategories(CatalogVersionModel catalogVersion)
Deprecated.since 4.3, please usegetRootCategoriesForCatalogVersion(CatalogVersionModel)
.java.util.Collection<CategoryModel>
getRootCategoriesForCatalogVersion(CatalogVersionModel catalogVersion)
Retrieves the rootCategoryModel
s of the specifiedCatalogVersionModel
.boolean
isEmpty(CategoryModel category)
Checks if theCategoryModel
has product or sub-category.boolean
isRoot(CategoryModel category)
Checks if the theCategoryModel
is a root category (has no super category).default boolean
isSetAllowedPrincipalsRecursivelyDisabled()
Checks if the attributeCategoryConstants.DISABLE_SETALLOWEDPRINCIPAL_RECURSIVELY
exists in the session and evaluates its value.boolean
isSubcategoryRemovalCheckDisabled()
Checks if the attributeCategoryConstants.DISABLE_SUBCATEGORY_REMOVALCHECK
exists in the session and evaluates its value.void
setAllowedPrincipalsForAllRelatedCategories(CategoryModel category, java.util.List<PrincipalModel> newPrincipals)
Sets the principals for the category and all supercategories and subcategories of passed as parameter category.void
setAllowedPrincipalsForCategory(CategoryModel category, java.util.List<PrincipalModel> newPrincipals)
Sets the principals for the category.
-
-
-
Method Detail
-
getRootCategories
@Deprecated java.util.Collection<CategoryModel> getRootCategories(CatalogVersionModel catalogVersion)
Deprecated.since 4.3, please usegetRootCategoriesForCatalogVersion(CatalogVersionModel)
.- Returns:
- the found
CategoryModel
s with the specifiedcode
.
-
getRootCategoriesForCatalogVersion
java.util.Collection<CategoryModel> getRootCategoriesForCatalogVersion(CatalogVersionModel catalogVersion)
Retrieves the rootCategoryModel
s of the specifiedCatalogVersionModel
.- Returns:
- all found
CategoryModel
s or an empty collection if no root categories can be found - Throws:
java.lang.IllegalArgumentException
- if thecatalogVersion
isnull
.
-
getCategory
@Deprecated CategoryModel getCategory(java.lang.String code)
Deprecated.since 4.3, please usegetCategoryForCode(String)
orgetCategoriesForCode(String)
. Retrieves the first foundCategoryModel
for the givencode
.- Parameters:
code
- the code of the to be foundCategoryModel
- Returns:
- the found
CategoryModel
ornull
if no category with this code exists
-
getCategoryForCode
CategoryModel getCategoryForCode(java.lang.String code)
Retrieves theCategoryModel
with the specificcode
.- Parameters:
code
- the code of the to be foundCategoryModel
- Returns:
- found
CategoryModel
- Throws:
UnknownIdentifierException
- if no category with the specified code can be found.AmbiguousIdentifierException
- if more than one category with the specifiedcode
andcatalogVersion
was found.java.lang.IllegalArgumentException
- if parametercode
isnull
.
-
getCategoriesForCode
java.util.Collection<CategoryModel> getCategoriesForCode(java.lang.String code)
Retrieves for the givencode
all foundCategoryModel
s.- Parameters:
code
- the code of the category.- Returns:
- all found
CategoryModel
s or an empty collection if no such category exists - See Also:
CatalogVersionService.setSessionCatalogVersions(Collection)
,CatalogVersionService.getSessionCatalogVersions()
,CatalogVersionService.addSessionCatalogVersion(CatalogVersionModel)
-
getCategory
@Deprecated CategoryModel getCategory(CatalogVersionModel catalogVersion, java.lang.String code)
Deprecated.since 4.3, please usegetCategoryForCode(CatalogVersionModel, String)
.- Returns:
- the found
CategoryModel
with the specifiedcode
.
-
getCategoryForCode
CategoryModel getCategoryForCode(CatalogVersionModel catalogVersion, java.lang.String code)
Retrieves theCategoryModel
with the specifiedcode
which belonging to the specifiedcatalogVersion
.- Parameters:
catalogVersion
- theCatalogVersionModel
where the returned category should be foundcode
- the code of theCategoryModel
- Returns:
- the
CategoryModel
with the specifiedcode
and belonging to theCatalogVersionModel
- Throws:
UnknownIdentifierException
- if no category with the specified code and catalogVersion can be found.AmbiguousIdentifierException
- if more than one category with the specifiedcode
andcatalogVersion
was found.java.lang.IllegalArgumentException
- if parametercode
orcatalogVersion
isnull
.
-
getPath
@Deprecated java.util.List<CategoryModel> getPath(CategoryModel category)
Deprecated.since 4.3, please usegetPathForCategory(CategoryModel)
. Returns the path from the givenCategoryModel
down to the root category. This method should be used only in cases without multiple super-categories; otherwise it cannot be predicted which path is chosen!- Parameters:
category
- theCategoryModel
- Returns:
- the first found path for this category
- Throws:
java.lang.IllegalArgumentException
- if parametercategory
isnull
.
-
getCategoryPathForProduct
java.util.List<CategoryModel> getCategoryPathForProduct(ProductModel product, java.lang.Class... includeOnlyCategories)
Gets the category path for product.- Parameters:
product
- the productincludeOnlyCategories
- classes which limits resulting path- Returns:
- the category path for product
-
getPathForCategory
java.util.List<CategoryModel> getPathForCategory(CategoryModel category)
Returns the path from root category to the givenCategoryModel
. To get all super-categories useCategoryModel.getSupercategories()
.- Parameters:
category
- theCategoryModel
- Returns:
- the found path for this category
- Throws:
java.lang.IllegalArgumentException
- if parametercategory
isnull
.AmbiguousIdentifierException
- if more than one path was found.
-
getPathsForCategory
java.util.Collection<java.util.List<CategoryModel>> getPathsForCategory(CategoryModel category)
Returns all paths for thisCategoryModel
. Each path is a list of all categories in the path from root to this category.- Parameters:
category
- the (sub)CategoryModel
- Returns:
- all paths for this
CategoryModel
, or empty collection if this category has no super-categories. - Throws:
java.lang.IllegalArgumentException
- if parametercategory
isnull
.
-
isEmpty
boolean isEmpty(CategoryModel category)
Checks if theCategoryModel
has product or sub-category.- Parameters:
category
- the category to be checked- Returns:
- true if the
CategoryModel
has neither product nor sub-category - Throws:
java.lang.IllegalArgumentException
- if parametercategory
isnull
.
-
isRoot
boolean isRoot(CategoryModel category)
Checks if the theCategoryModel
is a root category (has no super category).- Parameters:
category
- the category to be checked- Returns:
- true if the
CategoryModel
is a root category, false otherwise. - Throws:
java.lang.IllegalArgumentException
- if parametercategory
isnull
.
-
setAllowedPrincipalsForCategory
void setAllowedPrincipalsForCategory(CategoryModel category, java.util.List<PrincipalModel> newPrincipals)
Sets the principals for the category. The new principals will be set to theCategoryModel
so that the user rights can be defined specifically.- Parameters:
category
- the category where the principals will be applied tonewPrincipals
- the list with the new allowed principals of the category- Throws:
java.lang.IllegalArgumentException
- if parametercategory
isnull
ornewPrincipals
isnull
.- See Also:
CategoryPrincipalStrategy.replacePrincipalsForCategory(CategoryModel, List)
-
setAllowedPrincipalsForAllRelatedCategories
void setAllowedPrincipalsForAllRelatedCategories(CategoryModel category, java.util.List<PrincipalModel> newPrincipals)
Sets the principals for the category and all supercategories and subcategories of passed as parameter category. The new principals will be set to theCategoryModel
so that the user rights can be defined specifically.- Parameters:
category
- the category where the principals will be applied tonewPrincipals
- the list with the new allowed principals of the category- Throws:
java.lang.IllegalArgumentException
- if parametercategory
isnull
ornewPrincipals
isnull
.- See Also:
CategoryPrincipalStrategy.replacePrincipalsForCategory(CategoryModel, List)
-
disableSubcategoryRemovalCheck
void disableSubcategoryRemovalCheck()
Disable subcategory removal check. This method puts into the session flagCategoryConstants.DISABLE_SUBCATEGORY_REMOVALCHECK
with valueBoolean.TRUE
. This flag is next checked byCategoryRemovalValidator
to ensure that category should be checked against possible subcategories during remove.
-
enableSubcategoryRemovalCheck
void enableSubcategoryRemovalCheck()
Enable subcategory removal check. This method removes flagCategoryConstants.DISABLE_SUBCATEGORY_REMOVALCHECK
from the session and each possible remove action on category will always perform check against possible subcategories. Category which has subcategories will be not removed.
-
isSubcategoryRemovalCheckDisabled
boolean isSubcategoryRemovalCheckDisabled()
Checks if the attributeCategoryConstants.DISABLE_SUBCATEGORY_REMOVALCHECK
exists in the session and evaluates its value.- Returns:
- true if
CategoryConstants.DISABLE_SUBCATEGORY_REMOVALCHECK
exists in the session AND the value is true
-
isSetAllowedPrincipalsRecursivelyDisabled
default boolean isSetAllowedPrincipalsRecursivelyDisabled()
Checks if the attributeCategoryConstants.DISABLE_SETALLOWEDPRINCIPAL_RECURSIVELY
exists in the session and evaluates its value. If the flag is set to false (default) then while setting the principals for a given category, the subcategories and supercategories are updated as well. Copying the prinicpals down to subcategories means mostly replacing them. Pulling the principals up however allows only adding new principals in supercategories, never remove.- Returns:
- true if
CategoryConstants.DISABLE_SETALLOWEDPRINCIPAL_RECURSIVELY
exists in the session AND the value is true
-
getAllSubcategoriesForCategory
java.util.Collection<CategoryModel> getAllSubcategoriesForCategory(CategoryModel category)
Gets all subcategories for category and all subcategories recursively.- Parameters:
category
- the category for which subcategories should be obtained- Returns:
- the collection of subcategories
-
getAllSupercategoriesForCategory
java.util.Collection<CategoryModel> getAllSupercategoriesForCategory(CategoryModel category)
Gets the all supercategories for categories.- Parameters:
category
- the category for which supercategories should be obtained- Returns:
- the collection of supercategories
-
-