public class UserPreferencesManager extends AbstractLogEnabled implements ThreadSafe, Component, Serviceable, Configurable, Initializable
Modifier and Type | Field and 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 and Description |
---|
UserPreferencesManager() |
Modifier and Type | Method and 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 preference
|
void |
addUserPreferences(UserIdentity user,
String storageContext,
Map<String,String> contextVars,
Map<String,String> values)
Add a user preference
|
void |
configure(Configuration configuration) |
protected UserPreferencesStorage |
getStorageManager(Map<String,String> contextVars,
String id)
Get the storage component for a given role.
|
protected UserPreferencesStorage |
getStorageManager(String role)
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 preference
|
void |
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.
|
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
protected UserPreferencesExtensionPoint _userPrefEP
protected Map<String,UserPreferencesStorage> _storageManagers
protected String _defaultStorageRole
protected ServiceManager _serviceManager
public UserPreferencesManager()
public void service(ServiceManager manager) throws ServiceException
service
in interface Serviceable
ServiceException
public void configure(Configuration configuration) throws ConfigurationException
configure
in interface Configurable
ConfigurationException
public void initialize() throws Exception
initialize
in interface Initializable
Exception
public Map<String,String> getUnTypedUserPrefs(UserIdentity user, String storageContext, Map<String,String> contextVars) throws UserPreferencesException
user
- the user.storageContext
- the preferences context.contextVars
- the context variables.UserPreferencesException
- if an error occurs getting the preferences.public Map<String,Object> getTypedUserPrefs(UserIdentity user, String storageContext, Map<String,String> contextVars) throws UserPreferencesException
user
- the user.storageContext
- the preferences context.contextVars
- the context variables.UserPreferencesException
- if an error occurs getting the preferences.public void addUserPreference(UserIdentity user, String storageContext, Map<String,String> contextVars, String name, String value) throws UserPreferencesException
user
- the user.storageContext
- the preferences context.contextVars
- the context variables.name
- the user pref namevalue
- the user pref valueUserPreferencesException
- if an error occurredpublic void addUserPreferences(UserIdentity user, String storageContext, Map<String,String> contextVars, Map<String,String> values) throws UserPreferencesException
user
- the user.storageContext
- the preferences context.contextVars
- the context variables.values
- the user prefs to addUserPreferencesException
- if an error occurredpublic void removeUserPreference(UserIdentity user, String storageContext, Map<String,String> contextVars, String name) throws UserPreferencesException
user
- the user.storageContext
- the preferences context.contextVars
- the context variables.name
- the user pref nameUserPreferencesException
- if an error occurredpublic void removeAllUserPreferences(UserIdentity user, String storageContext, Map<String,String> contextVars) throws UserPreferencesException
user
- the user.storageContext
- the preferences context.contextVars
- the context variables.UserPreferencesException
- if an error occurredpublic void setUserPreferences(UserIdentity user, String storageContext, Map<String,String> contextVars, Map<String,String> preferenceValues) throws UserPreferencesException
user
- the user.storageContext
- the preferences context.contextVars
- the context variables.preferenceValues
- a Map of the preference values indexed by ID.UserPreferencesException
- if an error occurredpublic String getUserPreferenceAsString(UserIdentity user, String storageContext, Map<String,String> contextVars, String id) throws UserPreferencesException
user
- the user.storageContext
- the preferences context.contextVars
- the context variables.id
- the preference ID.UserPreferencesException
- if an error occurredpublic Long getUserPreferenceAsLong(UserIdentity user, String storageContext, Map<String,String> contextVars, String id) throws UserPreferencesException
user
- the user.storageContext
- the preferences context.contextVars
- the context variables.id
- the preference ID.UserPreferencesException
- if an error occurredpublic Date getUserPreferenceAsDate(UserIdentity user, String storageContext, Map<String,String> contextVars, String id) throws UserPreferencesException
user
- the user.storageContext
- the preferences context.contextVars
- the context variables.id
- the preference ID.UserPreferencesException
- if an error occurredpublic Boolean getUserPreferenceAsBoolean(UserIdentity user, String storageContext, Map<String,String> contextVars, String id) throws UserPreferencesException
user
- the user.storageContext
- the preferences context.contextVars
- the context variables.id
- the preference ID.UserPreferencesException
- if an error occurredpublic Double getUserPreferenceAsDouble(UserIdentity user, String storageContext, Map<String,String> contextVars, String id) throws UserPreferencesException
user
- the user.storageContext
- the preferences context.contextVars
- the context variables.id
- the preference ID.UserPreferencesException
- if an error occurredprotected Set<String> getStorageRoles(Map<String,String> contextVars)
contextVars
- the context variables.protected Map<String,Collection<UserPreference>> getUserPrefsByStorage(Map<String,String> contextVars)
contextVars
- the context variables.protected Map<String,Map<String,String>> getUserPrefsValuesByStorage(Map<String,String> contextVars, Map<String,String> preferenceValues)
contextVars
- the context variables.preferenceValues
- the unsorted preference values.protected UserPreferencesStorage getStorageManager(String role) throws UserPreferencesException
role
- the storage component role.UserPreferencesException
- if an error occurs looking up the storage manager.protected UserPreferencesStorage getStorageManager(Map<String,String> contextVars, String id) throws UserPreferencesException
contextVars
- The context varsid
- The preference idUserPreferencesException
- if an error occurs looking up the storage manager.