Class NotificationPreferencesHelper
- java.lang.Object
-
- org.ametys.runtime.plugin.component.AbstractLogEnabled
-
- org.ametys.plugins.workspaces.project.notification.preferences.NotificationPreferencesHelper
-
- All Implemented Interfaces:
LogEnabled
,Component
,Serviceable
public class NotificationPreferencesHelper extends AbstractLogEnabled implements Component, Serviceable
Helper for notifications preferences
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
NotificationPreferencesHelper.Frequency
The frequency of notifications
-
Field Summary
Fields Modifier and Type Field Description protected JSONUtils
_jsonUtils
The JSON utilsprotected ProjectManager
_projectManager
The project managerprotected UserPreferencesExtensionPoint
_userPrefEP
The user preferences extension pointprotected UserPreferencesManager
_userPrefManager
The user preferences managerstatic String
ROLE
The avalon rolestatic String
USERPREFS_ID
the id of the user prefs for notification preferences
-
Constructor Summary
Constructors Constructor Description NotificationPreferencesHelper()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
askedToBeNotified(UserIdentity userIdentity, String projectName, NotificationPreferencesHelper.Frequency frequency)
Determines if a user asked to be notify for a given project and frequencyboolean
askedToBeNotified(User user, String projectName, NotificationPreferencesHelper.Frequency frequency)
Determines if a user asked to be notify for a given project and frequencyvoid
deleteProjectNotificationPreferences(UserIdentity userIdentity, String projectName)
Delete the user preferences for notification on the given projectMap<String,Object>
getNotificationPreferences(User user)
Get the user's notification preferencesMap<String,Object>
getNotificationPreferences(UserIdentity userIdentity)
Get the user's notification preferencesString
getNotificationPreferencesAsString(User user)
Get the user's notification preferences as json StringString
getNotificationPreferencesAsString(UserIdentity userIdentity)
Get the user's notification preferences as json StringSet<String>
getUserProjectsWithFrequency(User user, NotificationPreferencesHelper.Frequency frequency)
Get the user's project set to receive notification for given frequencyboolean
hasFrequencyInPreferences(User user, NotificationPreferencesHelper.Frequency frequency)
Determines if a user has at least one notification preference with the given frequencyvoid
service(ServiceManager manager)
-
Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
-
-
-
Field Detail
-
USERPREFS_ID
public static final String USERPREFS_ID
the id of the user prefs for notification preferences- See Also:
- Constant Field Values
-
_jsonUtils
protected JSONUtils _jsonUtils
The JSON utils
-
_userPrefManager
protected UserPreferencesManager _userPrefManager
The user preferences manager
-
_userPrefEP
protected UserPreferencesExtensionPoint _userPrefEP
The user preferences extension point
-
_projectManager
protected ProjectManager _projectManager
The project manager
-
-
Constructor Detail
-
NotificationPreferencesHelper
public NotificationPreferencesHelper()
-
-
Method Detail
-
service
public void service(ServiceManager manager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
askedToBeNotified
public boolean askedToBeNotified(User user, String projectName, NotificationPreferencesHelper.Frequency frequency)
Determines if a user asked to be notify for a given project and frequency- Parameters:
user
- the userprojectName
- the project namefrequency
- the required frequency (each, daily, weekly or monthly)- Returns:
- true if the user need to be notified
-
askedToBeNotified
public boolean askedToBeNotified(UserIdentity userIdentity, String projectName, NotificationPreferencesHelper.Frequency frequency)
Determines if a user asked to be notify for a given project and frequency- Parameters:
userIdentity
- the user identityprojectName
- the project namefrequency
- the required frequency (each, daily, weekly or monthly). Cannot be null.- Returns:
- true if the user need to be notified
-
hasFrequencyInPreferences
public boolean hasFrequencyInPreferences(User user, NotificationPreferencesHelper.Frequency frequency)
Determines if a user has at least one notification preference with the given frequency- Parameters:
user
- the userfrequency
- the frequency- Returns:
- true if the user has at least one notification preference with the given frequency
-
getUserProjectsWithFrequency
public Set<String> getUserProjectsWithFrequency(User user, NotificationPreferencesHelper.Frequency frequency)
Get the user's project set to receive notification for given frequency- Parameters:
user
- the userfrequency
- the matching frequency- Returns:
- The names of user's project's with same frequency
-
getNotificationPreferences
public Map<String,Object> getNotificationPreferences(User user) throws UserPreferencesException
Get the user's notification preferences- Parameters:
user
- the user- Returns:
- the user's notification preferences
- Throws:
UserPreferencesException
- if failed to retrieve user's preferences
-
getNotificationPreferences
public Map<String,Object> getNotificationPreferences(UserIdentity userIdentity) throws UserPreferencesException
Get the user's notification preferences- Parameters:
userIdentity
- the user identity- Returns:
- the user's notification preferences
- Throws:
UserPreferencesException
- if failed to retrieve user's preference
-
getNotificationPreferencesAsString
public String getNotificationPreferencesAsString(User user) throws UserPreferencesException
Get the user's notification preferences as json String- Parameters:
user
- the user- Returns:
- the user's notification preferences as json String
- Throws:
UserPreferencesException
- if failed to retrieve user's preference
-
getNotificationPreferencesAsString
public String getNotificationPreferencesAsString(UserIdentity userIdentity) throws UserPreferencesException
Get the user's notification preferences as json String- Parameters:
userIdentity
- the user identity- Returns:
- the user's notification preferences as json String
- Throws:
UserPreferencesException
- if failed to retrieve user's preference
-
deleteProjectNotificationPreferences
public void deleteProjectNotificationPreferences(UserIdentity userIdentity, String projectName)
Delete the user preferences for notification on the given project- Parameters:
userIdentity
- the user identityprojectName
- the name of the project to delete
-
-