Package de.hybris.platform.category
Interface CategoryService
- All Known Implementing Classes:
DefaultCategoryService
public interface CategoryService
Provides methods for working with
CategoryModel. Please be aware that since CategoryModel is catalog version
aware, all methods of this service will work according to the active session catalog versions (see
CatalogVersionService.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:
- Spring Bean ID:
- categoryService
-
Method Summary
Modifier and TypeMethodDescriptionvoidDisable subcategory removal check.voidEnable subcategory removal check.getAllSubcategoriesForCategory(CategoryModel category) Gets all subcategories for category and all subcategories recursively.Gets the all supercategories for categories.getCategoriesForCode(String code) Retrieves for the givencodeall foundCategoryModels.getCategory(CatalogVersionModel catalogVersion, String code) Deprecated, for removal: This API element is subject to removal in a future version.getCategory(String code) Deprecated, for removal: This API element is subject to removal in a future version.since 4.3, please usegetCategoryForCode(String)orgetCategoriesForCode(String).getCategoryForCode(CatalogVersionModel catalogVersion, String code) Retrieves theCategoryModelwith the specifiedcodewhich belonging to the specifiedcatalogVersion.getCategoryForCode(String code) Retrieves theCategoryModelwith the specificcode.getCategoryPathForProduct(ProductModel product, Class... includeOnlyCategories) Gets the category path for product.getPath(CategoryModel category) Deprecated, for removal: This API element is subject to removal in a future version.since 4.3, please usegetPathForCategory(CategoryModel).getPathForCategory(CategoryModel category) Returns the path from root category to the givenCategoryModel.getPathsForCategory(CategoryModel category) Returns all paths for thisCategoryModel.getRootCategories(CatalogVersionModel catalogVersion) Deprecated, for removal: This API element is subject to removal in a future version.since 4.3, please usegetRootCategoriesForCatalogVersion(CatalogVersionModel).getRootCategoriesForCatalogVersion(CatalogVersionModel catalogVersion) Retrieves the rootCategoryModels of the specifiedCatalogVersionModel.booleanisEmpty(CategoryModel category) Checks if theCategoryModelhas product or sub-category.booleanisRoot(CategoryModel category) Checks if the theCategoryModelis a root category (has no super category).default booleanChecks if the attributeCategoryConstants.DISABLE_SETALLOWEDPRINCIPAL_RECURSIVELYexists in the session and evaluates its value.booleanChecks if the attributeCategoryConstants.DISABLE_SUBCATEGORY_REMOVALCHECKexists in the session and evaluates its value.voidsetAllowedPrincipalsForAllRelatedCategories(CategoryModel category, List<PrincipalModel> newPrincipals) Sets the principals for the category and all supercategories and subcategories of passed as parameter category.voidsetAllowedPrincipalsForCategory(CategoryModel category, List<PrincipalModel> newPrincipals) Sets the principals for the category.
-
Method Details
-
getRootCategories
@Deprecated(since="4.3", forRemoval=true) Collection<CategoryModel> getRootCategories(CatalogVersionModel catalogVersion) Deprecated, for removal: This API element is subject to removal in a future version.since 4.3, please usegetRootCategoriesForCatalogVersion(CatalogVersionModel).- Returns:
- the found
CategoryModels with the specifiedcode.
-
getRootCategoriesForCatalogVersion
Retrieves the rootCategoryModels of the specifiedCatalogVersionModel.- Returns:
- all found
CategoryModels or an empty collection if no root categories can be found - Throws:
IllegalArgumentException- if thecatalogVersionisnull.
-
getCategory
Deprecated, for removal: This API element is subject to removal in a future version.since 4.3, please usegetCategoryForCode(String)orgetCategoriesForCode(String). Retrieves the first foundCategoryModelfor the givencode.- Parameters:
code- the code of the to be foundCategoryModel- Returns:
- the found
CategoryModelornullif no category with this code exists
-
getCategoryForCode
Retrieves theCategoryModelwith 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 specifiedcodeandcatalogVersionwas found.IllegalArgumentException- if parametercodeisnull.
-
getCategoriesForCode
Retrieves for the givencodeall foundCategoryModels.- Parameters:
code- the code of the category.- Returns:
- all found
CategoryModels or an empty collection if no such category exists - See Also:
-
getCategory
@Deprecated(since="4.3", forRemoval=true) CategoryModel getCategory(CatalogVersionModel catalogVersion, String code) Deprecated, for removal: This API element is subject to removal in a future version.since 4.3, please usegetCategoryForCode(CatalogVersionModel, String).- Returns:
- the found
CategoryModelwith the specifiedcode.
-
getCategoryForCode
Retrieves theCategoryModelwith the specifiedcodewhich belonging to the specifiedcatalogVersion.- Parameters:
catalogVersion- theCatalogVersionModelwhere the returned category should be foundcode- the code of theCategoryModel- Returns:
- the
CategoryModelwith the specifiedcodeand 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 specifiedcodeandcatalogVersionwas found.IllegalArgumentException- if parametercodeorcatalogVersionisnull.
-
getPath
Deprecated, for removal: This API element is subject to removal in a future version.since 4.3, please usegetPathForCategory(CategoryModel). Returns the path from the givenCategoryModeldown 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:
IllegalArgumentException- if parametercategoryisnull.
-
getCategoryPathForProduct
Gets the category path for product.- Parameters:
product- the productincludeOnlyCategories- classes which limits resulting path- Returns:
- the category path for product
-
getPathForCategory
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:
IllegalArgumentException- if parametercategoryisnull.AmbiguousIdentifierException- if more than one path was found.
-
getPathsForCategory
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:
IllegalArgumentException- if parametercategoryisnull.
-
isEmpty
Checks if theCategoryModelhas product or sub-category.- Parameters:
category- the category to be checked- Returns:
- true if the
CategoryModelhas neither product nor sub-category - Throws:
IllegalArgumentException- if parametercategoryisnull.
-
isRoot
Checks if the theCategoryModelis a root category (has no super category).- Parameters:
category- the category to be checked- Returns:
- true if the
CategoryModelis a root category, false otherwise. - Throws:
IllegalArgumentException- if parametercategoryisnull.
-
setAllowedPrincipalsForCategory
Sets the principals for the category. The new principals will be set to theCategoryModelso 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:
IllegalArgumentException- if parametercategoryisnullornewPrincipalsisnull.- See Also:
-
setAllowedPrincipalsForAllRelatedCategories
void setAllowedPrincipalsForAllRelatedCategories(CategoryModel category, 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 theCategoryModelso 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:
IllegalArgumentException- if parametercategoryisnullornewPrincipalsisnull.- See Also:
-
disableSubcategoryRemovalCheck
void disableSubcategoryRemovalCheck()Disable subcategory removal check. This method puts into the session flagCategoryConstants.DISABLE_SUBCATEGORY_REMOVALCHECKwith valueBoolean.TRUE. This flag is next checked byCategoryRemovalValidatorto ensure that category should be checked against possible subcategories during remove. -
enableSubcategoryRemovalCheck
void enableSubcategoryRemovalCheck()Enable subcategory removal check. This method removes flagCategoryConstants.DISABLE_SUBCATEGORY_REMOVALCHECKfrom 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_REMOVALCHECKexists in the session and evaluates its value.- Returns:
- true if
CategoryConstants.DISABLE_SUBCATEGORY_REMOVALCHECKexists in the session AND the value is true
-
isSetAllowedPrincipalsRecursivelyDisabled
default boolean isSetAllowedPrincipalsRecursivelyDisabled()Checks if the attributeCategoryConstants.DISABLE_SETALLOWEDPRINCIPAL_RECURSIVELYexists 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_RECURSIVELYexists in the session AND the value is true
-
getAllSubcategoriesForCategory
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
Gets the all supercategories for categories.- Parameters:
category- the category for which supercategories should be obtained- Returns:
- the collection of supercategories
-
getCategoryForCode(CatalogVersionModel, String).