Interface CategoryTree


public interface CategoryTree
All categories in the project, represented as an in-memory tree.
  • Method Details

    • getRoots

      Root categories (the ones that have no parent).
      Returns:
      root categories
    • findById

      Finds a category by id.
      Parameters:
      id - the ID of the category to search for
      Returns:
      category
    • findByExternalId

      Finds a category by its external ID.
      Parameters:
      externalId - the external id of the category to find
      Returns:
      optional
    • findBySlug

      Finds a category by the slug and a specific locale.
      Parameters:
      locale - the locale
      slug - the slug
      Returns:
      a category matching the criteria
    • findByKey

      Finds a category by the key.
      Parameters:
      key - the category key
      Returns:
      a category matching the criteria
    • getAllAsFlatList

      All categories as a flat list.
      Returns:
      all categories
    • findChildren

      return the children for category. If there are no children or category is not in this CategoryTree then the list is empty.
      Parameters:
      category - the category which should be the parent category to the result list
      Returns:
      list of children or empty list
    • findSiblings

      Gets a list containing all categories that share a parent with at least one of the given categories.
      Parameters:
      categoryIds - Categories for which the sibling categories should be fetched
      Returns:
      a list of sibling categories
    • getSubtree

      CategoryTree getSubtree(Collection<? extends Identifiable<Category>> parentCategories)
      Gets the subtree of the given parent categories.
      Parameters:
      parentCategories - the list of parent categories to use as a starting point
      Returns:
      the subtree with the subcategories including the parent categories
    • getRootAncestor

      For a given category searches the ancestor that is in root level.
      Parameters:
      category - the category which to find the root ancestor
      Returns:
      the root ancestor of the category or the same category in case it is a root itself
    • getSubtreeRoots

      For a subtree the categories which are at the top level.

      Unlike getRoots() this does ignore the parent reference.

      Returns:
      subtree roots
    • of

      static CategoryTree of(List<Category> allCategoriesAsFlatList)
      Creates a category tree from a flat list of categories.
      Parameters:
      allCategoriesAsFlatList - all categories as flat list.
      Returns:
      the created category tree.