Package org.ametys.core.userpref
Class UserPreferencesManager
java.lang.Object
org.apache.avalon.framework.logger.AbstractLogEnabled
org.ametys.core.userpref.UserPreferencesManager
- All Implemented Interfaces:
Initializable
,Component
,Configurable
,LogEnabled
,Serviceable
,ThreadSafe
- Direct Known Subclasses:
FOUserPreferencesManager
public class UserPreferencesManager
extends AbstractLogEnabled
implements ThreadSafe, Component, Serviceable, Configurable, Initializable
Component handling user preference values retrieval and storage.
-
Field Summary
Modifier and TypeFieldDescriptionprotected String
The default storage component role.protected ServiceManager
The avalon service manager.protected Map<String,
UserPreferencesStorage> A list of storage managers.protected UserPreferencesExtensionPoint
The user preferences extensions point.static final String
The avalon role. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionCast the preference values as their real type.void
addUserPreference
(UserIdentity user, String storageContext, Map<String, String> contextVars, String name, String value) Add a user preferencevoid
addUserPreferences
(UserIdentity user, String storageContext, Map<String, String> contextVars, Map<String, String> values) Add a user preferencevoid
configure
(Configuration configuration) protected UserPreferencesStorage
getStorageManager
(String role) Get the storage component for a given role.protected UserPreferencesStorage
getStorageManager
(Map<String, String> contextVars, String id) Get the storage component for a given role.getStorageRoles
(Map<String, String> contextVars) Get all user preference storages.getTypedUserPrefs
(UserIdentity user, String storageContext, Map<String, String> contextVars) Get a user's preference values cast as their own type for a given context.getUnTypedUserPrefs
(UserIdentity user, String storageContext, Map<String, String> contextVars) Get a user's preference values (as String) for a given context.getUserPreferenceAsBoolean
(UserIdentity user, String storageContext, Map<String, String> contextVars, String id) Get a single boolean user preference value for a given context.getUserPreferenceAsDate
(UserIdentity user, String storageContext, Map<String, String> contextVars, String id) Get a single date user preference value for a given context.getUserPreferenceAsDouble
(UserIdentity user, String storageContext, Map<String, String> contextVars, String id) Get a single double user preference value for a given context.getUserPreferenceAsLong
(UserIdentity user, String storageContext, Map<String, String> contextVars, String id) Get a single long user preference value for a given context.getUserPreferenceAsString
(UserIdentity user, String storageContext, Map<String, String> contextVars, String id) Get a single string user preference value for a given context.protected Map<String,
Collection<UserPreference>> getUserPrefsByStorage
(Map<String, String> contextVars) Get all user preferences, grouped by storage point.Get user preference values, divided up by storage role.void
void
removeAllUserPreferences
(UserIdentity user, String storageContext, Map<String, String> contextVars) Remove all user preferences.void
removeUserPreference
(UserIdentity user, String storageContext, Map<String, String> contextVars, String name) Remove a user preferencevoid
service
(ServiceManager manager) void
setUserPreferences
(UserIdentity user, String storageContext, Map<String, String> contextVars, Map<String, String> preferenceValues) Set a user's preferences for a given context.Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
-
Field Details
-
ROLE
The avalon role. -
_userPrefEP
The user preferences extensions point. -
_storageManagers
A list of storage managers. -
_defaultStorageRole
The default storage component role. -
_serviceManager
The avalon service manager.
-
-
Constructor Details
-
UserPreferencesManager
public UserPreferencesManager()
-
-
Method Details
-
service
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
configure
- Specified by:
configure
in interfaceConfigurable
- Throws:
ConfigurationException
-
initialize
- Specified by:
initialize
in interfaceInitializable
- Throws:
Exception
-
getUnTypedUserPrefs
public Map<String,String> getUnTypedUserPrefs(UserIdentity user, String storageContext, Map<String, String> contextVars) throws UserPreferencesExceptionGet a user's preference values (as String) for a given context.- Parameters:
user
- the user.storageContext
- the preferences context.contextVars
- the context variables.- Returns:
- the user preference values as a Map of String indexed by preference ID.
- Throws:
UserPreferencesException
- if an error occurs getting the preferences.
-
getTypedUserPrefs
public Map<String,Object> getTypedUserPrefs(UserIdentity user, String storageContext, Map<String, String> contextVars) throws UserPreferencesExceptionGet a user's preference values cast as their own type for a given context.- Parameters:
user
- the user.storageContext
- the preferences context.contextVars
- the context variables.- Returns:
- the user preference values as a Map of Object indexed by preference ID.
- Throws:
UserPreferencesException
- if an error occurs getting the preferences.
-
addUserPreference
public void addUserPreference(UserIdentity user, String storageContext, Map<String, String> contextVars, String name, String value) throws UserPreferencesExceptionAdd a user preference- Parameters:
user
- the user.storageContext
- the preferences context.contextVars
- the context variables.name
- the user pref namevalue
- the user pref value- Throws:
UserPreferencesException
- if an error occurred
-
addUserPreferences
public void addUserPreferences(UserIdentity user, String storageContext, Map<String, String> contextVars, Map<String, throws UserPreferencesExceptionString> values) Add a user preference- Parameters:
user
- the user.storageContext
- the preferences context.contextVars
- the context variables.values
- the user prefs to add- Throws:
UserPreferencesException
- if an error occurred
-
removeUserPreference
public void removeUserPreference(UserIdentity user, String storageContext, Map<String, String> contextVars, String name) throws UserPreferencesExceptionRemove a user preference- Parameters:
user
- the user.storageContext
- the preferences context.contextVars
- the context variables.name
- the user pref name- Throws:
UserPreferencesException
- if an error occurred
-
removeAllUserPreferences
public void removeAllUserPreferences(UserIdentity user, String storageContext, Map<String, String> contextVars) throws UserPreferencesExceptionRemove all user preferences.- Parameters:
user
- the user.storageContext
- the preferences context.contextVars
- the context variables.- Throws:
UserPreferencesException
- if an error occurred
-
setUserPreferences
public void setUserPreferences(UserIdentity user, String storageContext, Map<String, String> contextVars, Map<String, throws UserPreferencesExceptionString> preferenceValues) Set a user's preferences for a given context.- Parameters:
user
- the user.storageContext
- the preferences context.contextVars
- the context variables.preferenceValues
- a Map of the preference values indexed by ID.- Throws:
UserPreferencesException
- if an error occurred
-
getUserPreferenceAsString
public String getUserPreferenceAsString(UserIdentity user, String storageContext, Map<String, String> contextVars, String id) throws UserPreferencesExceptionGet a single string user preference value for a given context.- Parameters:
user
- the user.storageContext
- the preferences context.contextVars
- the context variables.id
- the preference ID.- Returns:
- the user preference value as a String.
- Throws:
UserPreferencesException
- if an error occurred
-
getUserPreferenceAsLong
public Long getUserPreferenceAsLong(UserIdentity user, String storageContext, Map<String, String> contextVars, String id) throws UserPreferencesExceptionGet a single long user preference value for a given context.- Parameters:
user
- the user.storageContext
- the preferences context.contextVars
- the context variables.id
- the preference ID.- Returns:
- the user preference value as a Long.
- Throws:
UserPreferencesException
- if an error occurred
-
getUserPreferenceAsDate
public Date getUserPreferenceAsDate(UserIdentity user, String storageContext, Map<String, String> contextVars, String id) throws UserPreferencesExceptionGet a single date user preference value for a given context.- Parameters:
user
- the user.storageContext
- the preferences context.contextVars
- the context variables.id
- the preference ID.- Returns:
- the user preference value as a Date.
- Throws:
UserPreferencesException
- if an error occurred
-
getUserPreferenceAsBoolean
public Boolean getUserPreferenceAsBoolean(UserIdentity user, String storageContext, Map<String, String> contextVars, String id) throws UserPreferencesExceptionGet a single boolean user preference value for a given context.- Parameters:
user
- the user.storageContext
- the preferences context.contextVars
- the context variables.id
- the preference ID.- Returns:
- the user preference value as a Boolean.
- Throws:
UserPreferencesException
- if an error occurred
-
getUserPreferenceAsDouble
public Double getUserPreferenceAsDouble(UserIdentity user, String storageContext, Map<String, String> contextVars, String id) throws UserPreferencesExceptionGet a single double user preference value for a given context.- Parameters:
user
- the user.storageContext
- the preferences context.contextVars
- the context variables.id
- the preference ID.- Returns:
- the user preference value as a Double.
- Throws:
UserPreferencesException
- if an error occurred
-
getStorageRoles
Get all user preference storages.- Parameters:
contextVars
- the context variables.- Returns:
- a Set of storage roles.
-
getUserPrefsByStorage
protected Map<String,Collection<UserPreference>> getUserPrefsByStorage(Map<String, String> contextVars) Get all user preferences, grouped by storage point.- Parameters:
contextVars
- the context variables.- Returns:
- a Map of storage role -> collection of user preferences.
-
getUserPrefsValuesByStorage
protected Map<String,Map<String, getUserPrefsValuesByStorageString>> (Map<String, String> contextVars, Map<String, String> preferenceValues) Get user preference values, divided up by storage role.- Parameters:
contextVars
- the context variables.preferenceValues
- the unsorted preference values.- Returns:
- the preference values, divided up by storage role, as a Map of storage role -gt; preference values.
-
getStorageManager
Get the storage component for a given role.- Parameters:
role
- the storage component role.- Returns:
- the storage component.
- Throws:
UserPreferencesException
- if an error occurs looking up the storage manager.
-
getStorageManager
protected UserPreferencesStorage getStorageManager(Map<String, String> contextVars, String id) throws UserPreferencesExceptionGet the storage component for a given role.- Parameters:
contextVars
- The context varsid
- The preference id- Returns:
- the storage component.
- Throws:
UserPreferencesException
- if an error occurs looking up the storage manager.
-
_castValues
protected Map<String,Object> _castValues(Map<String, String> untypedValues, Map<String, String> contextVars) Cast the preference values as their real type.- Parameters:
untypedValues
- the untyped user preferencescontextVars
- the context variables.- Returns:
- typed user preferences
-