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:
    CatalogVersionService
    Spring Bean ID:
    categoryService
    • Method Detail

      • getRootCategoriesForCatalogVersion

        java.util.Collection<CategoryModel> getRootCategoriesForCatalogVersion​(CatalogVersionModel catalogVersion)
        Retrieves the root CategoryModels of the specified CatalogVersionModel.
        Returns:
        all found CategoryModels or an empty collection if no root categories can be found
        Throws:
        java.lang.IllegalArgumentException - if the catalogVersion is null.
      • getPath

        @Deprecated(since="4.3",
                    forRemoval=true)
        java.util.List<CategoryModel> getPath​(CategoryModel category)
        Deprecated, for removal: This API element is subject to removal in a future version.
        since 4.3, please use getPathForCategory(CategoryModel). Returns the path from the given CategoryModel 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 - the CategoryModel
        Returns:
        the first found path for this category
        Throws:
        java.lang.IllegalArgumentException - if parameter category is null.
      • getCategoryPathForProduct

        java.util.List<CategoryModel> getCategoryPathForProduct​(ProductModel product,
                                                                java.lang.Class... includeOnlyCategories)
        Gets the category path for product.
        Parameters:
        product - the product
        includeOnlyCategories - classes which limits resulting path
        Returns:
        the category path for product
      • getPathsForCategory

        java.util.Collection<java.util.List<CategoryModel>> getPathsForCategory​(CategoryModel category)
        Returns all paths for this CategoryModel. 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 parameter category is null.
      • isEmpty

        boolean isEmpty​(CategoryModel category)
        Checks if the CategoryModel 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 parameter category is null.
      • isRoot

        boolean isRoot​(CategoryModel category)
        Checks if the the CategoryModel 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 parameter category is null.
      • setAllowedPrincipalsForCategory

        void setAllowedPrincipalsForCategory​(CategoryModel category,
                                             java.util.List<PrincipalModel> newPrincipals)
        Sets the principals for the category. The new principals will be set to the CategoryModel so that the user rights can be defined specifically.
        Parameters:
        category - the category where the principals will be applied to
        newPrincipals - the list with the new allowed principals of the category
        Throws:
        java.lang.IllegalArgumentException - if parameter category is null or newPrincipals is null.
        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 the CategoryModel so that the user rights can be defined specifically.
        Parameters:
        category - the category where the principals will be applied to
        newPrincipals - the list with the new allowed principals of the category
        Throws:
        java.lang.IllegalArgumentException - if parameter category is null or newPrincipals is null.
        See Also:
        CategoryPrincipalStrategy.replacePrincipalsForCategory(CategoryModel, List)
      • enableSubcategoryRemovalCheck

        void enableSubcategoryRemovalCheck()
        Enable subcategory removal check. This method removes flag CategoryConstants.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.
      • isSetAllowedPrincipalsRecursivelyDisabled

        default boolean isSetAllowedPrincipalsRecursivelyDisabled()
        Checks if the attribute CategoryConstants.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