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
Fields Modifier and Type Field Description protected String
_defaultStorageRole
The default storage component role.protected ServiceManager
_serviceManager
The avalon service manager.protected Map<String,UserPreferencesStorage>
_storageManagers
A list of storage managers.protected UserPreferencesExtensionPoint
_userPrefEP
The user preferences extensions point.static String
ROLE
The avalon role.
-
Constructor Summary
Constructors Constructor Description UserPreferencesManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Map<String,Object>
_castValues(Map<String,String> untypedValues, Map<String,String> contextVars)
Cast 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.protected Set<String>
getStorageRoles(Map<String,String> contextVars)
Get all user preference storages.Map<String,Object>
getTypedUserPrefs(UserIdentity user, String storageContext, Map<String,String> contextVars)
Get a user's preference values cast as their own type for a given context.Map<String,String>
getUnTypedUserPrefs(UserIdentity user, String storageContext, Map<String,String> contextVars)
Get a user's preference values (as String) for a given context.Boolean
getUserPreferenceAsBoolean(UserIdentity user, String storageContext, Map<String,String> contextVars, String id)
Get a single boolean user preference value for a given context.Date
getUserPreferenceAsDate(UserIdentity user, String storageContext, Map<String,String> contextVars, String id)
Get a single date user preference value for a given context.Double
getUserPreferenceAsDouble(UserIdentity user, String storageContext, Map<String,String> contextVars, String id)
Get a single double user preference value for a given context.Long
getUserPreferenceAsLong(UserIdentity user, String storageContext, Map<String,String> contextVars, String id)
Get a single long user preference value for a given context.String
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.protected Map<String,Map<String,String>>
getUserPrefsValuesByStorage(Map<String,String> contextVars, Map<String,String> preferenceValues)
Get user preference values, divided up by storage role.void
initialize()
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 Detail
-
_userPrefEP
protected UserPreferencesExtensionPoint _userPrefEP
The user preferences extensions point.
-
_storageManagers
protected Map<String,UserPreferencesStorage> _storageManagers
A list of storage managers.
-
_defaultStorageRole
protected String _defaultStorageRole
The default storage component role.
-
_serviceManager
protected ServiceManager _serviceManager
The avalon service manager.
-
-
Constructor Detail
-
UserPreferencesManager
public UserPreferencesManager()
-
-
Method Detail
-
service
public void service(ServiceManager manager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
configure
public void configure(Configuration configuration) throws ConfigurationException
- Specified by:
configure
in interfaceConfigurable
- Throws:
ConfigurationException
-
initialize
public void initialize() throws Exception
- Specified by:
initialize
in interfaceInitializable
- Throws:
Exception
-
getUnTypedUserPrefs
public Map<String,String> getUnTypedUserPrefs(UserIdentity user, String storageContext, Map<String,String> contextVars) throws UserPreferencesException
Get 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 UserPreferencesException
Get 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 UserPreferencesException
Add 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,String> values) throws UserPreferencesException
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 UserPreferencesException
Remove 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 UserPreferencesException
Remove 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,String> preferenceValues) throws UserPreferencesException
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 UserPreferencesException
Get 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 UserPreferencesException
Get 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 UserPreferencesException
Get 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 UserPreferencesException
Get 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 UserPreferencesException
Get 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
protected Set<String> getStorageRoles(Map<String,String> contextVars)
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,String>> getUserPrefsValuesByStorage(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
protected UserPreferencesStorage getStorageManager(String role) throws UserPreferencesException
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 UserPreferencesException
Get 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.
-
-