Interface UserPreferencesService
- All Known Implementing Classes:
UserPreferencesServiceImpl
There are two different user preferences:
UserPreference: a global preference entity providing avaluefor a givenkey.UserPreferences: an entity handling a collection ofUserPreferenceused to hold all the preferences for a given document or list all the current user global preference.
key must contain letters, digits, dashes, underscores or periods characters only. By default, value
is html-sanitized before being persisted. Sanitizing can be disabled with the
UserPreferencesUtil.PROP_SANITIZE_VALUES property. Null value is rejected.
User preferences are saved per repository, meaning 2 preferences with the same key but for different repositories can exist.
The maximum number of preferences for a given user and repository is defined by the
UserPreferencesUtil.PROP_MAX_PREFERENCES property (default value:
UserPreferencesUtil.DEFAULT_PROP_MAX_PREFERENCES). If this limit is exceeded, a
TooManyUserPreferencesException is thrown.
- Since:
- 2025.16
-
Method Summary
Modifier and TypeMethodDescriptioncreate(CoreSession session, String key, String value) Creates a current user's preference value for the given key.create(CoreSession session, DocumentRef docRef, Map<String, String> preferences) Creates current user's document preferences.createOrUpdate(CoreSession session, String key, String value) Creates or updates a current user's preference.voiddelete(CoreSession session, String key) Deletes the current user's preference for the given key.voiddelete(CoreSession session, DocumentRef docRef) Deletes all the current user's preferences for the given document reference.voiddeleteAllForDocument(CoreSession session, IdRef idRef) Internal use.voiddeleteAllForUser(CoreSession session, String userId) Internal use.get(CoreSession session, String key) Gets an optional current user's preference for the given key.get(CoreSession session, DocumentRef docRef) Gets current user's preferences for the given document reference.get(CoreSession session, DocumentRef docRef, String key) Gets optional current user's preference for the given document reference and key.list(CoreSession session) Lists all current user's global preferences.putAll(CoreSession session, DocumentRef docRef, UserPreferences preferences) Puts all current user's document preferences.remove(CoreSession session, DocumentRef docRef, String key) Removes the current user's preference for the given document reference and key.update(CoreSession session, String key, String value) Updates a current user's preference value.update(CoreSession session, DocumentRef docRef, UserPreferences preferences) Updates a current user's document preferences.
-
Method Details
-
get
Gets an optional current user's preference for the given key.- Parameters:
session- the core sessionkey- the preference key- Returns:
- the user preference entity if any
-
get
Gets current user's preferences for the given document reference.- Parameters:
session- the core sessiondocRef- the document reference- Returns:
- the user document preferences entity
-
get
Gets optional current user's preference for the given document reference and key.- Parameters:
session- the core sessiondocRef- the document referencekey- the user preference key- Returns:
- the user document preferences entity if any
-
list
Lists all current user's global preferences.- Parameters:
session- the core session- Returns:
- all the user preference entities
-
create
Creates a current user's preference value for the given key.- Parameters:
session- the core sessionkey- the preference keyvalue- the preference value- Returns:
- the created user preference
- Throws:
UserPreferencesExistsException- if aUserPreferencealready exists for the current user and key.TooManyUserPreferencesException- if the number of preferences exceedsUserPreferencesUtil.PROP_MAX_PREFERENCES
-
createOrUpdate
Creates or updates a current user's preference.- Parameters:
session- the core sessionkey- the user preference keyvalue- the preference value- Returns:
- the updated user preference
-
create
UserPreferences create(CoreSession session, @Nonnull DocumentRef docRef, @Nonnull Map<String, String> preferences) Creates current user's document preferences.- Parameters:
session- the core sessiondocRef- the document referencepreferences- the key / preferences map- Returns:
- the created user document preferences
- Throws:
UserPreferencesExistsException- if aUserPreferencesalready exists for the current user and document reference.TooManyUserPreferencesException- if the number of preferences exceedsUserPreferencesUtil.PROP_MAX_PREFERENCES- API Note:
- an empty preferences map is considered as a null preference, and so rejected
-
update
Updates a current user's preference value.- Parameters:
session- the core sessionkey- the user preference keyvalue- the preference new value- Returns:
- the updated user preference
- Throws:
UserPreferencesNotFound- if the user preference does not exist
-
update
UserPreferences update(CoreSession session, @Nonnull DocumentRef docRef, @Nonnull UserPreferences preferences) Updates a current user's document preferences.Existing document preferences are erased unlike
putAll(org.nuxeo.ecm.core.api.CoreSession, org.nuxeo.ecm.core.api.DocumentRef, org.nuxeo.user.preferences.api.UserPreferences)which preserves existing document preferences.- Parameters:
session- the core sessionpreferences- the user preferences to be updated- Returns:
- the updated user document preferences
- Throws:
UserPreferencesNotFound- if the user document preferences does not existTooManyUserPreferencesException- if the number of preferences exceedsUserPreferencesUtil.PROP_MAX_PREFERENCES- API Note:
- an empty preferences map is considered as a null preference, and so rejected
-
putAll
UserPreferences putAll(CoreSession session, @Nonnull DocumentRef docRef, @Nonnull UserPreferences preferences) Puts all current user's document preferences. If noUserPreferencesexists for current user and document reference, it is created.Existing document preferences are preserved unless explicitly overwritten by the given
UserPreferences.- Parameters:
session- the core sessionpreferences- the user preferences- Returns:
- the created or updated user document preferences
- Throws:
TooManyUserPreferencesException- if the number of preferences exceedsUserPreferencesUtil.PROP_MAX_PREFERENCES- API Note:
- an empty
UserPreferences.preferences()map is considered as a null preference, and so rejected
-
delete
Deletes the current user's preference for the given key.- Parameters:
session- the core sessionkey- the user preference key
-
delete
Deletes all the current user's preferences for the given document reference.- Parameters:
session- the core sessiondocRef- the user preferences document reference
-
remove
Removes the current user's preference for the given document reference and key.- Parameters:
session- the core sessiondocRef- the document referencekey- the preference key- Returns:
- the updated user preferences
-
deleteAllForDocument
Internal use.Deletes all user preferences for the given document reference. The core session must have sufficient privileges to delete preferences of all users.
- Parameters:
session- the core sessionidRef- the document id reference
-
deleteAllForUser
Internal use.Deletes all preferences for the given user id. The core session must have sufficient privileges to delete preferences of the given user id.
- Parameters:
session- the core sessionuserId- the user id
-