Package com.logicaldoc.core.security.menu

# Class HibernateMenuDAO

java.lang.Object
com.logicaldoc.core.HibernatePersistentObjectDAO<Menu>
com.logicaldoc.core.security.menu.HibernateMenuDAO

All Implemented Interfaces:
  `PersistentObjectDAO<Menu>`, `MenuDAO`

@Repository("menuDAO") public class HibernateMenuDAO extends HibernatePersistentObjectDAO<Menu> implements MenuDAO
Hibernate implementation of `MenuDAO`

Since:
  3.0
Author:
  Marco Meschieri - LogicalDOC

## Field Summary

### Fields inherited from interface com.logicaldoc.core.PersistentObjectDAO

`ENTITY`

## Constructor Summary

Constructors
Constructor
Description
`HibernateMenuDAO()`

## Method Summary

Modifier and Type
Method
Description
`String`
`computePathExtended(long menuId)`
Dynamically computes the path extended for the specified menu.
`Menu`
`createPath(long parentId, long tenantId, int type, String path, boolean inheritSecurity)`
Creates the menu for the specified path.
`void`
`delete(long menuId, int code)`
This method deletes an entity and you can give a deletion code
`void`
`deleteAll(Collection<Menu> menus)`
Deletes all entries form the database.
`List<Menu>`
`findByGroupId(long groupId)`
Finds all menus accessible by the passed group
`List<Menu>`
`findByName(Menu parent, String name, boolean caseSensitive)`
Finds all menus by menu text, contained in the parent menu
`List<Menu>`
`findByName(String name)`
Finds all menus by menu text.
`List<Menu>`
`findByNameAndParentId(String name, long parentId)`
Finds that folder that lies under a specific parent (given by the id) an with a given text(like operator is used)
`List<Menu>`
`findByParentId(long parentId, boolean enaledOnly)`
Finds all children(direct and indirect) by parentId
`List<Menu>`
`findByUserId(long userId)`
Finds authorized menus for a user.
`List<Menu>`
`findByUserId(long userId, long parentId, boolean enabledOnly)`
Finds direct children of a menu
`List<Menu>`
`findByUserId(long userId, long parentId, Integer type, boolean enabledOnly)`
`List<Menu>`
`findChildren(long parentId, long userId)`
Finds direct children of a menu accessible by the given user.
`List<Menu>`
`findChildren(long parentId, Integer max)`
Finds direct children of a menu.
`List<Long>`
`findIdByUserId(long userId, long parentId)`
This method selects only the menuId from the menus for which a user is authorized.
`List<Long>`
`findIdByUserId(long userId, long parentId, Integer type)`
`List<Long>`
`findMenuIdByUserId(long userId, boolean enabledOnly)`
This method selects only the menuId from the menus for which a user is authorized
`List<Long>`
`findMenuIdByUserIdAndPermission(long userId, Permission permission, boolean enabledOnly)`
Finds all menus ids with a specific permission enabled on the specified user
`String`
`findNameById(long menuId)`
This method selects only the menu text from a menu
`List<Menu>`
`findParents(long menuId)`
Returns a List of menus being a parent of the given menu.
`boolean`
`isReadAllowed(long menuId, long userId)`
This method is looking up for read rights for a menu and an user
`boolean`
`isWriteAllowed(long menuId, long userId)`
This method is looking up for writing rights for a menu and an user
`void`
`restore(long menuId, boolean parents)`
Restores a previously deleted menu
`void`
`store(Menu menu)`
This method persists the entity object

### Methods inherited from class com.logicaldoc.core.HibernatePersistentObjectDAO

`bulkUpdate, count, deleteAll, evict, evict, findById, findByObjectQuery, findByQuery, findByQuery, findByWhere, findIdsByWhere, getDatabaseMetadata, initialize, jdbcUpdate, jdbcUpdate, query, queryForDouble, queryForDouble, queryForInt, queryForInt, queryForList, queryForList, queryForList, queryForLong, queryForLong, queryForObject, queryForObject, queryForResultSet, queryForString, queryForString, setSessionFactory`

### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface com.logicaldoc.core.PersistentObjectDAO

`bulkUpdate, count, count, count, delete, deleteAll, evict, evict, findAll, findAll, findAllIds, findAllIds, findById, findById, findByObjectQuery, findByQuery, findByQuery, findByWhere, findByWhere, findIdsByWhere, findIdsByWhere, getDatabaseMetadata, getDbms, initialize, initialize, isMariaDB, isMySQL, isOracle, isPostgreSQL, isSQLServer, jdbcUpdate, jdbcUpdate, query, query, queryForDouble, queryForDouble, queryForInt, queryForInt, queryForList, queryForList, queryForList, queryForLong, queryForLong, queryForObject, queryForObject, queryForResultSet, queryForString, queryForString`

## Constructor Details

### HibernateMenuDAO

public HibernateMenuDAO()

## Method Details

### store

public void store(Menu menu) throws PersistenceException
Description copied from interface: `PersistentObjectDAO`
This method persists the entity object

Specified by:
  `store` in interface `PersistentObjectDAO<Menu>`
Overrides:
  `store` in class `HibernatePersistentObjectDAO<Menu>`
Parameters:
  `menu` - entity to be stored
Throws:
  `PersistenceException` - raised in case of errors in the database

### findByUserId

public List<Menu> findByUserId(long userId)
Description copied from interface: `MenuDAO`
Finds authorized menus for a user.

Specified by:
  `findByUserId` in interface `MenuDAO`
Parameters:
  `userId` - ID of the user.
Returns:
  List of found menus.

### findByUserId

public List<Menu> findByUserId(long userId, long parentId, boolean enabledOnly)
Description copied from interface: `MenuDAO`
Finds direct children of a menu

Specified by:
  `findByUserId` in interface `MenuDAO`
Parameters:
  `userId` - identifier of the user
  `parentId` - MenuId of the menu which children are wanted
  `enabledOnly` - if the menus must also be enabled
Returns:
  List of found menus sorted by name

### findByUserId

public List<Menu> findByUserId(long userId, long parentId, Integer type, boolean enabledOnly)

### findChildren

public List<Menu> findChildren(long parentId, Integer max)
Description copied from interface: `MenuDAO`
Finds direct children of a menu.

Specified by:
  `findChildren` in interface `MenuDAO`
Parameters:
  `parentId` - MenuId of the menu which children are wanted
  `max` - Optional, maximum number of children
Returns:
  List of found menus

### findChildren

public List<Menu> findChildren(long parentId, long userId)
Description copied from interface: `MenuDAO`
Finds direct children of a menu accessible by the given user.

Specified by:
  `findChildren` in interface `MenuDAO`
Parameters:
  `parentId` - MenuId of the menu which children are wanted
  `userId` - Identifier of the user that must have read access
Returns:
  List of found menus.

### findByParentId

public List<Menu> findByParentId(long parentId, boolean enaledOnly)
Description copied from interface: `MenuDAO`
Finds all children(direct and indirect) by parentId

Specified by:
  `findByParentId` in interface `MenuDAO`
Parameters:
  `parentId` - identifier of the parent menu
  `enaledOnly` - if the menus must also be enabled
Returns:
  list of children menus

### isWriteAllowed

public boolean isWriteAllowed(long menuId, long userId)
Description copied from interface: `MenuDAO`
This method is looking up for writing rights for a menu and an user

Specified by:
  `isWriteAllowed` in interface `MenuDAO`
Parameters:
  `menuId` - ID of the menu
  `userId` - ID of the user
Returns:
  id the user has write permission

### isReadAllowed

public boolean isReadAllowed(long menuId, long userId)
Description copied from interface: `MenuDAO`
This method is looking up for read rights for a menu and an user

Specified by:
  `isReadAllowed` in interface `MenuDAO`
Parameters:
  `menuId` - ID of the menu
  `userId` - ID of the user
Returns:
  if the user can access the menu

### findNameById

public String findNameById(long menuId)
Description copied from interface: `MenuDAO`
This method selects only the menu text from a menu

Specified by:
  `findNameById` in interface `MenuDAO`
Parameters:
  `menuId` - Id of the menu
Returns:
  Selected menu text

### findMenuIdByUserId

public List<Long> findMenuIdByUserId(long userId, boolean enabledOnly)
Description copied from interface: `MenuDAO`
This method selects only the menuId from the menus for which a user is authorized

Specified by:
  `findMenuIdByUserId` in interface `MenuDAO`
Parameters:
  `userId` - ID of the user
  `enabledOnly` - if the menus must also be enabled
Returns:
  List of selected menuId's

### findByGroupId

public List<Menu> findByGroupId(long groupId) throws PersistenceException
Description copied from interface: `MenuDAO`
Finds all menus accessible by the passed group

Specified by:
  `findByGroupId` in interface `MenuDAO`
Parameters:
  `groupId` - The group id
Returns:
  The List of menus
Throws:
  `PersistenceException` - Error in the database

### findIdByUserId

public List<Long> findIdByUserId(long userId, long parentId, Integer type)

### findByName

public List<Menu> findByName(String name)
Description copied from interface: `MenuDAO`
Finds all menus by menu text.

Specified by:
  `findByName` in interface `MenuDAO`
Parameters:
  `name` - name of the menu
Returns:
  List of menus with given menu text.

### findByName

public List<Menu> findByName(Menu parent, String name, boolean caseSensitive)
Description copied from interface: `MenuDAO`
Finds all menus by menu text, contained in the parent menu

Specified by:
  `findByName` in interface `MenuDAO`
Parameters:
  `parent` - The parent menu(optional)
  `name` - the name to search
  `caseSensitive` - if we have to consider the search case sensitive
Returns:
  List of menus with given menu name.

### computePathExtended

public String computePathExtended(long menuId)
Description copied from interface: `MenuDAO`
Dynamically computes the path extended for the specified menu. The path extended is a human readable path in the form: /menu1/menu2/menu3

Specified by:
  `computePathExtended` in interface `MenuDAO`
Parameters:
  `menuId` - identifier of the menu
Returns:
  full path of the menu

### findByNameAndParentId

public List<Menu> findByNameAndParentId(String name, long parentId)
Description copied from interface: `MenuDAO`
Finds that folder that lies under a specific parent (given by the id) an with a given text(like operator is used)

Specified by:
  `findByNameAndParentId` in interface `MenuDAO`
Parameters:
  `name` - name of the menu
  `parentId` - identifier of the parent menu
Returns:
  list of manues

### findParents

public List<Menu> findParents(long menuId)
Description copied from interface: `MenuDAO`
Returns a List of menus being a parent of the given menu. The list is ordered starting from the root of menus.

Specified by:
  `findParents` in interface `MenuDAO`
Parameters:
  `menuId` - identifier of the group
Returns:
  hierarchy of parents

### restore

public void restore(long menuId, boolean parents) throws PersistenceException
Description copied from interface: `MenuDAO`
Restores a previously deleted menu

Specified by:
  `restore` in interface `MenuDAO`
Parameters:
  `menuId` - The menu identifier
  `parents` - true if parents must be restored also
Throws:
  `PersistenceException` - is happened a database error

### findMenuIdByUserIdAndPermission

public List<Long> findMenuIdByUserIdAndPermission(long userId, Permission permission, boolean enabledOnly)
Description copied from interface: `MenuDAO`
Finds all menus ids with a specific permission enabled on the specified user

Specified by:
  `findMenuIdByUserIdAndPermission` in interface `MenuDAO`
Parameters:
  `userId` - The user identifier
  `permission` - The permission to check
  `enabledOnly` - if the menus must also be enabled
Returns:
  list of folder IDs

### deleteAll

public void deleteAll(Collection<Menu> menus) throws PersistenceException
Description copied from interface: `PersistentObjectDAO`
Deletes all entries form the database. Same as deleteAll(entities, `PersistentObject.DELETED_CODE_DEFAULT`)

Specified by:
  `deleteAll` in interface `PersistentObjectDAO<Menu>`
Parameters:
  `menus` - The entities to be deleted
Throws:
  `PersistenceException` - raised in case of errors in the database

### delete

public void delete(long menuId, int code) throws PersistenceException
Description copied from interface: `PersistentObjectDAO`
This method deletes an entity and you can give a deletion code

Specified by:
  `delete` in interface `PersistentObjectDAO<Menu>`
Overrides:
  `delete` in class `HibernatePersistentObjectDAO<Menu>`
Parameters:
  `menuId` - ID of the entity which should be deleted
  `code` - Deletion code
Throws:
  `PersistenceException` - raised in case of errors in the database

### findIdByUserId

public List<Long> findIdByUserId(long userId, long parentId)
Description copied from interface: `MenuDAO`
This method selects only the menuId from the menus for which a user is authorized. Only menus direct child of the specified parent are returned.

Specified by:
  `findIdByUserId` in interface `MenuDAO`
Parameters:
  `userId` - ID of the user.
  `parentId` - Parent menu
Returns:
  List of selected menuId's.

### createPath

public Menu createPath(long parentId, long tenantId, int type, String path, boolean inheritSecurity) throws PersistenceException
Description copied from interface: `MenuDAO`
Creates the menu for the specified path. All unexisting nodes specified in the path will be created.

Specified by:
  `createPath` in interface `MenuDAO`
Parameters:
  `parentId` - Identifier of the parent menu
  `tenantId` - Identifier of the tenant that will own the new menu
  `type` - The type of the created menus
  `path` - The folder path(for example /dog/cat/mouse)
  `inheritSecurity` - If true the new menus will 'point' to the parent for the security policies.
Returns:
  The created folder
Throws:
  `PersistenceException` - error at data layer