Class UserPreferencesServiceImpl
- All Implemented Interfaces:
Adaptable,Component,Extensible,TimestampedService,UserPreferencesService
Directory based implementation of UserPreferencesService.
Both UserPreference and UserPreferences are stored in the same DIRECTORY_NAME directory and
have the following fields:
userIdrepositorykeyvalue
UserPreferences has the docId additional field.- Since:
- 2025.16
-
Field Summary
FieldsFields inherited from class org.nuxeo.runtime.model.DefaultComponent
lastModified, name -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static voidcheckMaxPreferences(CoreSession session, Session dirSession, int nbNew) create(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.protected voiddoBatchDelete(QueryBuilder queryBuilder) protected UserPreferencedoCreate(CoreSession session, Session dirSession, String key, String value) protected UserPreferencesdoCreate(CoreSession session, Session dirSession, DocumentRef docRef, Map<String, String> preferences) protected Optional<DocumentModel> doGet(CoreSession session, Session dirSession, String key) doGet(CoreSession session, Session dirSession, IdRef idRef) protected UserPreferencedoUpdate(Session dirSession, DocumentModel docModel, String value) 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.protected static IdRefgetDocId(CoreSession session, DocumentRef documentRef) getFieldMap(CoreSession session, IdRef idRef, String key, String value) protected static booleanhasPreferences(CoreSession session, Session dirSession, IdRef idRef) list(CoreSession session) Lists all current user's global preferences.protected static UserPreferencenewUserPreference(DocumentModel document) putAll(CoreSession session, DocumentRef docRef, UserPreferences docPreferences) Puts all current user's document preferences.protected static DocumentModelListqueryPreferences(CoreSession session, Session dirSession, IdRef idRef, String key, long limit) remove(CoreSession session, DocumentRef docRef, String key) Removes the current user's preference for the given document reference and key.protected static DocumentModelListretrieveAllDocPreferences(CoreSession session, Session dirSession, IdRef idRef) protected static DocumentModelListretrieveAllPreferencesForUser(CoreSession session, Session dirSession) protected static Optional<DocumentModel> retrieveDocPreferenceForKey(CoreSession session, Session dirSession, IdRef idRef, String key) update(CoreSession session, String key, String value) Updates a current user's preference value.update(CoreSession session, DocumentRef docRef, UserPreferences docPreferences) Updates a current user's document preferences.protected static voidvalidatePreferences(Map<String, String> preferences) protected static voidwithDirectorySession(Consumer<Session> consumer) protected static <R> RwithDirectorySession(Function<Session, R> function) Methods inherited from class org.nuxeo.runtime.model.DefaultComponent
activate, addRuntimeMessage, addRuntimeMessage, deactivate, getAdapter, getDescriptor, getDescriptors, getLastModified, getRegistry, register, registerContribution, registerExtension, setLastModified, setModifiedNow, setName, start, stop, unregister, unregisterContribution, unregisterExtensionMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.nuxeo.runtime.model.Component
getApplicationStartedOrder
-
Field Details
-
DIRECTORY_NAME
- See Also:
-
-
Constructor Details
-
UserPreferencesServiceImpl
public UserPreferencesServiceImpl()
-
-
Method Details
-
get
Description copied from interface:UserPreferencesServiceGets an optional current user's preference for the given key.- Specified by:
getin interfaceUserPreferencesService- Parameters:
session- the core sessionkey- the preference key- Returns:
- the user preference entity if any
-
doGet
-
get
Description copied from interface:UserPreferencesServiceGets current user's preferences for the given document reference.- Specified by:
getin interfaceUserPreferencesService- Parameters:
session- the core sessiondocRef- the document reference- Returns:
- the user document preferences entity
-
doGet
-
get
public Optional<UserPreference> get(CoreSession session, @Nonnull DocumentRef docRef, @Nonnull String key) Description copied from interface:UserPreferencesServiceGets optional current user's preference for the given document reference and key.- Specified by:
getin interfaceUserPreferencesService- Parameters:
session- the core sessiondocRef- the document referencekey- the user preference key- Returns:
- the user document preferences entity if any
-
list
Description copied from interface:UserPreferencesServiceLists all current user's global preferences.- Specified by:
listin interfaceUserPreferencesService- Parameters:
session- the core session- Returns:
- all the user preference entities
-
create
Description copied from interface:UserPreferencesServiceCreates a current user's preference value for the given key.- Specified by:
createin interfaceUserPreferencesService- Parameters:
session- the core sessionkey- the preference keyvalue- the preference value- Returns:
- the created user preference
-
doCreate
protected UserPreference doCreate(CoreSession session, Session dirSession, String key, String value) -
createOrUpdate
public UserPreference createOrUpdate(CoreSession session, @Nonnull String key, @Nonnull String value) Description copied from interface:UserPreferencesServiceCreates or updates a current user's preference.- Specified by:
createOrUpdatein interfaceUserPreferencesService- Parameters:
session- the core sessionkey- the user preference keyvalue- the preference value- Returns:
- the updated user preference
-
create
public UserPreferences create(CoreSession session, @Nonnull DocumentRef docRef, @Nonnull Map<String, String> preferences) Description copied from interface:UserPreferencesServiceCreates current user's document preferences.- Specified by:
createin interfaceUserPreferencesService- Parameters:
session- the core sessiondocRef- the document referencepreferences- the key / preferences map- Returns:
- the created user document preferences
-
doCreate
protected UserPreferences doCreate(CoreSession session, Session dirSession, DocumentRef docRef, Map<String, String> preferences) -
hasPreferences
-
update
Description copied from interface:UserPreferencesServiceUpdates a current user's preference value.- Specified by:
updatein interfaceUserPreferencesService- Parameters:
session- the core sessionkey- the user preference keyvalue- the preference new value- Returns:
- the updated user preference
-
doUpdate
-
update
public UserPreferences update(CoreSession session, @Nonnull DocumentRef docRef, @Nonnull UserPreferences docPreferences) Description copied from interface:UserPreferencesServiceUpdates a current user's document preferences.Existing document preferences are erased unlike
UserPreferencesService.putAll(org.nuxeo.ecm.core.api.CoreSession, org.nuxeo.ecm.core.api.DocumentRef, org.nuxeo.user.preferences.api.UserPreferences)which preserves existing document preferences.- Specified by:
updatein interfaceUserPreferencesService- Parameters:
session- the core sessiondocPreferences- the user preferences to be updated- Returns:
- the updated user document preferences
-
putAll
public UserPreferences putAll(CoreSession session, @Nonnull DocumentRef docRef, @Nonnull UserPreferences docPreferences) Description copied from interface:UserPreferencesServicePuts 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.- Specified by:
putAllin interfaceUserPreferencesService- Parameters:
session- the core sessiondocPreferences- the user preferences- Returns:
- the created or updated user document preferences
-
remove
public UserPreferences remove(CoreSession session, @Nonnull DocumentRef docRef, @Nonnull String key) Description copied from interface:UserPreferencesServiceRemoves the current user's preference for the given document reference and key.- Specified by:
removein interfaceUserPreferencesService- Parameters:
session- the core sessiondocRef- the document referencekey- the preference key- Returns:
- the updated user preferences
-
delete
Description copied from interface:UserPreferencesServiceDeletes the current user's preference for the given key.- Specified by:
deletein interfaceUserPreferencesService- Parameters:
session- the core sessionkey- the user preference key
-
delete
Description copied from interface:UserPreferencesServiceDeletes all the current user's preferences for the given document reference.- Specified by:
deletein interfaceUserPreferencesService- Parameters:
session- the core sessiondocRef- the user preferences document reference
-
deleteAllForDocument
Description copied from interface:UserPreferencesServiceInternal use.Deletes all user preferences for the given document reference. The core session must have sufficient privileges to delete preferences of all users.
- Specified by:
deleteAllForDocumentin interfaceUserPreferencesService- Parameters:
session- the core sessionidRef- the document id reference
-
deleteAllForUser
Description copied from interface:UserPreferencesServiceInternal use.Deletes all preferences for the given user id. The core session must have sufficient privileges to delete preferences of the given user id.
- Specified by:
deleteAllForUserin interfaceUserPreferencesService- Parameters:
session- the core sessionuserId- the user id
-
doBatchDelete
-
checkMaxPreferences
-
getDocId
-
getFieldMap
-
newUserPreference
-
queryPreferences
protected static DocumentModelList queryPreferences(CoreSession session, Session dirSession, IdRef idRef, String key, long limit) -
retrieveAllDocPreferences
protected static DocumentModelList retrieveAllDocPreferences(CoreSession session, Session dirSession, IdRef idRef) -
retrieveAllPreferencesForUser
protected static DocumentModelList retrieveAllPreferencesForUser(CoreSession session, Session dirSession) -
retrieveDocPreferenceForKey
protected static Optional<DocumentModel> retrieveDocPreferenceForKey(CoreSession session, Session dirSession, IdRef idRef, String key) -
validatePreferences
-
withDirectorySession
-
withDirectorySession
-