Class DefaultMenuItemService<P extends NavMenuItem>

java.lang.Object
com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P>
com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService<P>
com.broadleafcommerce.adminnavigation.service.DefaultMenuItemService<P>
All Implemented Interfaces:
MenuItemService<P>, com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P>, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityService<P>

public class DefaultMenuItemService<P extends NavMenuItem> extends com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService<P> implements MenuItemService<P>
Author:
Samarth Dhruva (samarthd)
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
    static final String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    DefaultMenuItemService(NavMenuItemRepository<com.broadleafcommerce.data.tracking.core.Trackable> repository, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper helper)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    create(P menu, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
     
    void
    delete(String id, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
     
    protected boolean
    evaluateCustomNavigationPredicate(@NonNull NavigationPredicate predicate, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Extension point for custom navigation predicates.
    protected boolean
    evaluateNavigationPredicate(@NonNull NavigationPredicate predicate, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Evaluates whether a given NavigationPredicate is satisfied based on the provided request and context information.
    protected boolean
    evaluatePredicates(@NonNull NavMenuItem item, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Evaluates whether all navigation predicates associated with the specified NavMenuItem are satisfied within the context of the provided WebRequest and ContextInfo.
    A reference to the NavigationItemLocator responsible for contributing navigation menu items from various sources such as the database or a custom properties file.
    getMenuWithNavigationTree(int depthLimit, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Returns the admin menu with its submenu fully populated.
    protected NavMenuItemRepository<com.broadleafcommerce.data.tracking.core.Trackable>
     
    protected com.broadleafcommerce.common.extension.TypeFactory
     
    org.springframework.data.domain.Page<P>
    readAllByLabel(String labelQuery, boolean rootsOnly, cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Read all menu items for the admin menu, optionally filtered by label (ignoring case).
    readAllByParentMenuItemId(String parentMenuItemId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Read all menu items that are direct children of the specified NavMenuItem.
    readAncestors(String menuItemId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Accepts a menu item ID and returns a payload object containing the requested menu item and a list of its ancestors.
    replace(String id, P menu, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
     
    void
    A reference to the NavigationItemLocator responsible for contributing navigation menu items from various sources such as the database or a custom properties file.
    void
    setTypeFactory(com.broadleafcommerce.common.extension.TypeFactory typeFactory)
     
    update(String id, P menu, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
     

    Methods inherited from class com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService

    getRsqlHelper, readAll, readAll, readAll, readAll

    Methods inherited from class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService

    convertFromPersistentDomain, convertToPersistentDomain, createAll, createAllAllowingPartialSuccess, getHelper, getSortPositionStrategy, readAll, readAll, readAll, readAllByContextId, readByContextId, replaceAll, replaceAllAllowingPartialSuccess, setSortPositionStrategy, updateAll, updateAllAllowingPartialSuccess, updateSort

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService

    createAll, createAllAllowingPartialSuccess, readAll, readAll, readAll, readAllByContextId, readByContextId, replaceAll, replaceAllAllowingPartialSuccess, updateAll, updateAllAllowingPartialSuccess, updateSort

    Methods inherited from interface com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityService

    readAll, readAll, readAll, readAll
  • Field Details

  • Constructor Details

    • DefaultMenuItemService

      public DefaultMenuItemService(NavMenuItemRepository<com.broadleafcommerce.data.tracking.core.Trackable> repository, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper helper)
  • Method Details

    • readAllByLabel

      public org.springframework.data.domain.Page<P> readAllByLabel(@Nullable String labelQuery, boolean rootsOnly, @Nullable cz.jirutka.rsql.parser.ast.Node filters, @Nullable org.springframework.data.domain.Pageable page, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: MenuItemService
      Read all menu items for the admin menu, optionally filtered by label (ignoring case).
      Specified by:
      readAllByLabel in interface MenuItemService<P extends NavMenuItem>
      Parameters:
      labelQuery - (optional) the menu item label to filter by (ignoring case)
      rootsOnly - if true, restricts results to only the top-level menu items for the menu. Otherwise, returns all menu items for the menu.
      filters - additional filters to apply in the query. Should be EmptyNode if no additional filters should be applied.
      page - the requested page of results from the database
      contextInfo - context information surrounding sandboxing and multitenant state
      Returns:
      all menu items, optionally filtered by name
    • readAllByParentMenuItemId

      public List<P> readAllByParentMenuItemId(@NonNull String parentMenuItemId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: MenuItemService
      Read all menu items that are direct children of the specified NavMenuItem. In other words, find all menu items who have the given parentMenuItemId set as their NavMenuItem.getParentMenuItemId().
      Specified by:
      readAllByParentMenuItemId in interface MenuItemService<P extends NavMenuItem>
      Parameters:
      parentMenuItemId - the context ID of the NavMenuItem whose direct children should be returned
      contextInfo - context information surrounding sandboxing and multitenant state
      Returns:
      all the menu items which are direct children of the specified menu item
    • readAncestors

      @NonNull public MenuItemAncestorList readAncestors(@NonNull String menuItemId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: MenuItemService
      Accepts a menu item ID and returns a payload object containing the requested menu item and a list of its ancestors.
      Specified by:
      readAncestors in interface MenuItemService<P extends NavMenuItem>
      Parameters:
      menuItemId - the context ID of the menu item whose ancestors should be found
      contextInfo - context information surrounding sandboxing and multitenant state
      Returns:
      a payload object containing the requested menu item and a list of its ancestors, sorted with the immediate parent at the beginning and the top-level parent at the end
    • getMenuWithNavigationTree

      @Cacheable(cacheNames="adminNavigationMenuTreeCache", keyGenerator="adminNavigationMenuTreeKeyGenerator", condition="@cacheStateManager.isEnabled(#root.caches, #root.args)") public NavigableMenu getMenuWithNavigationTree(int depthLimit, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: MenuItemService
      Returns the admin menu with its submenu fully populated.
      Specified by:
      getMenuWithNavigationTree in interface MenuItemService<P extends NavMenuItem>
      Parameters:
      depthLimit - the output will be limited to only the top depthLimit levels of the tree. This should generally be at least 1 to return any sub menus. Negative values return the entire hierarchy, and 0 returns no sub menus at all
      contextInfo - context information surrounding sandboxing and multitenant state
      Returns:
      the requested menu with its navigation tree, limited to the first depthLimit levels. Each level will be sorted by the displayOrder specified in each item in that level.
    • create

      @CacheEvict(cacheNames="adminNavigationMenuTreeCache", allEntries=true) public P create(P menu, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Specified by:
      create in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends NavMenuItem>
      Overrides:
      create in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends NavMenuItem>
    • update

      @CacheEvict(cacheNames="adminNavigationMenuTreeCache", allEntries=true) public P update(String id, P menu, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Specified by:
      update in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends NavMenuItem>
      Overrides:
      update in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends NavMenuItem>
    • replace

      @CacheEvict(cacheNames="adminNavigationMenuTreeCache", allEntries=true) public P replace(String id, P menu, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Specified by:
      replace in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends NavMenuItem>
      Overrides:
      replace in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends NavMenuItem>
    • delete

      @CacheEvict(cacheNames="adminNavigationMenuTreeCache", allEntries=true) public void delete(String id, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Specified by:
      delete in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends NavMenuItem>
      Overrides:
      delete in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends NavMenuItem>
    • evaluatePredicates

      protected boolean evaluatePredicates(@NonNull @NonNull NavMenuItem item, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Evaluates whether all navigation predicates associated with the specified NavMenuItem are satisfied within the context of the provided WebRequest and ContextInfo.

      If the NavMenuItem contains no predicates, the method returns true. If either the request or contextInfo is null and the NavMenuItem has predicates, the method returns false.

      Parameters:
      item - The NavMenuItem whose associated predicates are to be evaluated. Must not be null.
      contextInfo - The ContextInfo containing contextual information related to the request. Maybe null.
      Returns:
      true if all predicates are satisfied or if the NavMenuItem contains no predicates; false otherwise.
      Since:
      Admin Navigation 3.0.0, Release Train 3.0.0
    • evaluateNavigationPredicate

      protected boolean evaluateNavigationPredicate(@NonNull @NonNull NavigationPredicate predicate, @NonNull com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Evaluates whether a given NavigationPredicate is satisfied based on the provided request and context information.
      Parameters:
      predicate - The navigation predicate to evaluate. Must not be null.
      contextInfo - The contextual information containing request details. Must not be null.
      Returns:
      true if the predicate is successfully satisfied; false otherwise.
      Since:
      Admin Navigation 3.0.0, Release Train 3.0.0
    • evaluateCustomNavigationPredicate

      protected boolean evaluateCustomNavigationPredicate(@NonNull @NonNull NavigationPredicate predicate, @NonNull com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Extension point for custom navigation predicates.
      Parameters:
      predicate - the predicate to evaluate
      contextInfo - the contextual information containing request details. Must not be null.
      Returns:
      true if the predicate is successfully satisfied; false otherwise.
      See Also:
    • getRepository

      @NonNull protected NavMenuItemRepository<com.broadleafcommerce.data.tracking.core.Trackable> getRepository()
      Overrides:
      getRepository in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends NavMenuItem>
    • setCompositeLocator

      @Autowired public void setCompositeLocator(NavigationItemLocator compositeLocator)
      A reference to the NavigationItemLocator responsible for contributing navigation menu items from various sources such as the database or a custom properties file.
      Since:
      Admin Navigation 3.0.0, Release Train 3.0.0
    • getCompositeLocator

      protected NavigationItemLocator getCompositeLocator()
      A reference to the NavigationItemLocator responsible for contributing navigation menu items from various sources such as the database or a custom properties file.
      Since:
      Admin Navigation 3.0.0, Release Train 3.0.0
    • setTypeFactory

      @Autowired public void setTypeFactory(com.broadleafcommerce.common.extension.TypeFactory typeFactory)
      Since:
      Admin Navigation 3.0.0, Release Train 3.0.0
    • getTypeFactory

      protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
      Since:
      Admin Navigation 3.0.0, Release Train 3.0.0