Class NotificationManagerImpl
- java.lang.Object
-
- com.atlassian.bamboo.notification.NotificationManagerImpl
-
- All Implemented Interfaces:
NotificationManager
public class NotificationManagerImpl extends Object implements NotificationManager
-
-
Field Summary
Fields Modifier and Type Field Description static String
COMMITTER_RECIPIENT
static String
FAILED_CHAIN_NOTIFICATION
static String
USER_RECIPIENT
static String
WATCHER_RECIPIENT
static String
WEBHOOK_RECIPIENT
-
Constructor Summary
Constructors Constructor Description NotificationManagerImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description NotificationSet
cloneNotificationSet(NotificationSet oldSet)
Clone notification set and rules for use when cloningPlan
@NotNull NotificationRule
createNotificationRule(@NotNull Class<? extends NotificationType> notificationTypeClass, @Nullable String conditionData, @NotNull Class<? extends NotificationRecipient> recipientTypeClass, @Nullable String recipientString)
NotificationRule
createNotificationRule(String conditionKey, String conditionData, String recipientString, String recipientType)
Create notification rule and provide required managers.@NotNull NotificationRule
createNotificationRuleFromAction(String notificationTypeKey, String notificationRecipientKey, Map<String,String[]> actionParams)
Creates a notification rule based on the keys and params passed in from the action@NotNull NotificationSet
createOrGetSystemNotificationSet()
Get the system notification set for this bamboo and if one doesn't exist create it!List<NotificationRecipient>
getAllNotificationRecipients()
List<NotificationType>
getAllNotificationTypes()
List<NotificationType>
getChainNotificationTypes()
Return notification types marked explicitly as "chain" notification in plugin xml descriptionList<NotificationType>
getDeploymentNotificationTypes()
@Nullable NotificationRecipient
getNotificationRecipient(NotificationRule rule)
Instantiate and populate notification recipient from a rule.NotificationRecipient
getNotificationRecipientFromKey(String notificationRecipientKey)
@Nullable NotificationRule
getNotificationRuleById(long notificationId)
Get a specific notification rule@NotNull Set<NotificationRule>
getNotificationRules(@Nullable ImmutablePlan plan)
Extract notification rules for a plan.Set<NotificationRule>
getNotificationRules(@Nullable Plan plan)
@NotNull List<UsersNotification>
getNotificationRulesForUser(@NotNull BambooUser user)
Retrieves all notification rules associated with a given user searches for notification rules: * assigned to the user * assigned to a group the user belongs to * assigned to the user's email or user's im address * assigned to watchers of a build the user has marked as their favourite@Nullable NotificationSet
getNotificationSetById(long notificationSetId)
Get a specific notification set@NotNull List<NotificationSet>
getNotificationSetsForType(NotificationSet.NotificationSetType type)
@Nullable NotificationType
getNotificationType(NotificationRule rule)
Instantiate and populate notification type from a rule.@Nullable NotificationType
getNotificationTypeFromKey(String key)
Retrieve a specificNotificationType
plugin module based on the given key.List<NotificationType>
getPlanNotificationTypes()
List<NotificationType>
getSystemNotificationTypes()
boolean
isRecipientUserBase(NotificationRule notificationRule)
Determines whether or not a notification rule recipient evaluates to a bamboo user and therefore comply with the users notification preference.void
replaceNotificationRule(@NotNull NotificationSet notificationSet, long existingNotificationId, @NotNull NotificationRule newNotificationRule)
Replaces a notification rule with the new definition.void
saveNotificationSet(NotificationSet notificationSet)
Saves a notification set without requiring a build.void
saveSystemNotificationRule(@NotNull NotificationRule notificationRule)
Do not use this method.void
setNotificationDao(NotificationDao notificationRuleDao)
void
setPluginAccessor(com.atlassian.plugin.PluginAccessor pluginAccessor)
-
-
-
Field Detail
-
USER_RECIPIENT
public static final String USER_RECIPIENT
- See Also:
- Constant Field Values
-
COMMITTER_RECIPIENT
public static final String COMMITTER_RECIPIENT
- See Also:
- Constant Field Values
-
WATCHER_RECIPIENT
public static final String WATCHER_RECIPIENT
- See Also:
- Constant Field Values
-
WEBHOOK_RECIPIENT
public static final String WEBHOOK_RECIPIENT
- See Also:
- Constant Field Values
-
FAILED_CHAIN_NOTIFICATION
public static final String FAILED_CHAIN_NOTIFICATION
- See Also:
- Constant Field Values
-
-
Method Detail
-
saveNotificationSet
public void saveNotificationSet(NotificationSet notificationSet)
Description copied from interface:NotificationManager
Saves a notification set without requiring a build.- Specified by:
saveNotificationSet
in interfaceNotificationManager
- Parameters:
notificationSet
- the notification set to save
-
createNotificationRule
public NotificationRule createNotificationRule(String conditionKey, String conditionData, String recipientString, String recipientType)
Description copied from interface:NotificationManager
Create notification rule and provide required managers.- Specified by:
createNotificationRule
in interfaceNotificationManager
- Parameters:
conditionKey
- - key representation of the notification typeconditionData
- - any data the notification type requiresrecipientString
- - data the recipient type requires (e.g user or group name)recipientType
- - key representing the type of recipient- Returns:
- a newly created notification rule
-
createNotificationRule
@NotNull public @NotNull NotificationRule createNotificationRule(@NotNull @NotNull Class<? extends NotificationType> notificationTypeClass, @Nullable @Nullable String conditionData, @NotNull @NotNull Class<? extends NotificationRecipient> recipientTypeClass, @Nullable @Nullable String recipientString)
Description copied from interface:NotificationManager
- Specified by:
createNotificationRule
in interfaceNotificationManager
- Parameters:
notificationTypeClass
-NotificationType
conditionData
- - any data the notification type requiresrecipientTypeClass
-NotificationRecipient
recipientString
- - data the recipient type requires (e.g user or group name)- Returns:
- a newly created notification rule
-
createNotificationRuleFromAction
@NotNull public @NotNull NotificationRule createNotificationRuleFromAction(String notificationTypeKey, String notificationRecipientKey, Map<String,String[]> actionParams) throws IllegalArgumentException
Description copied from interface:NotificationManager
Creates a notification rule based on the keys and params passed in from the action- Specified by:
createNotificationRuleFromAction
in interfaceNotificationManager
- Parameters:
notificationTypeKey
- - the plugin key for the notification type selectednotificationRecipientKey
- - the plugin key for the notification recipient type selectedactionParams
- - the action params.- Returns:
- a new notification rule
- Throws:
IllegalArgumentException
- if either of the keys provided is invalid
-
getNotificationRules
public Set<NotificationRule> getNotificationRules(@Nullable @Nullable Plan plan)
- Specified by:
getNotificationRules
in interfaceNotificationManager
-
getNotificationRules
@NotNull public @NotNull Set<NotificationRule> getNotificationRules(@Nullable @Nullable ImmutablePlan plan)
Description copied from interface:NotificationManager
Extract notification rules for a plan.- Specified by:
getNotificationRules
in interfaceNotificationManager
- Parameters:
plan
- to get notifications for- Returns:
- a set of notification rules belonging to the given plan.
-
cloneNotificationSet
public NotificationSet cloneNotificationSet(NotificationSet oldSet)
Description copied from interface:NotificationManager
Clone notification set and rules for use when cloningPlan
- Specified by:
cloneNotificationSet
in interfaceNotificationManager
- Parameters:
oldSet
- - the notification set to clone- Returns:
- a new notification set containing the same notifications as in the original set.
-
getNotificationSetsForType
@NotNull public @NotNull List<NotificationSet> getNotificationSetsForType(NotificationSet.NotificationSetType type)
-
getAllNotificationTypes
public List<NotificationType> getAllNotificationTypes()
- Specified by:
getAllNotificationTypes
in interfaceNotificationManager
- Returns:
- a list of all enabled
NotificationType
plugin modules regardless of scope.
-
getSystemNotificationTypes
public List<NotificationType> getSystemNotificationTypes()
- Specified by:
getSystemNotificationTypes
in interfaceNotificationManager
- Returns:
- a list of all enabled
NotificationType
plugin modules which have the "system" scope
-
getDeploymentNotificationTypes
public List<NotificationType> getDeploymentNotificationTypes()
- Specified by:
getDeploymentNotificationTypes
in interfaceNotificationManager
- Returns:
- a list of all enabled
NotificationType
plugin modules which have the "deployment" scope
-
getPlanNotificationTypes
public List<NotificationType> getPlanNotificationTypes()
- Specified by:
getPlanNotificationTypes
in interfaceNotificationManager
- Returns:
- a list of all enabled
NotificationType
plugin modules which have the "plan" scope
-
getChainNotificationTypes
public List<NotificationType> getChainNotificationTypes()
Description copied from interface:NotificationManager
Return notification types marked explicitly as "chain" notification in plugin xml description- Specified by:
getChainNotificationTypes
in interfaceNotificationManager
- Returns:
- a list of all enabled
NotificationType
plugin modules which have the "chain" scope
-
getAllNotificationRecipients
public List<NotificationRecipient> getAllNotificationRecipients()
- Specified by:
getAllNotificationRecipients
in interfaceNotificationManager
- Returns:
- a list of all enabled
NotificationRecipient
plugin modules
-
getNotificationRecipientFromKey
public NotificationRecipient getNotificationRecipientFromKey(String notificationRecipientKey)
- Specified by:
getNotificationRecipientFromKey
in interfaceNotificationManager
- Parameters:
notificationRecipientKey
- representing the NotificationRecipient required- Returns:
- a specific
NotificationRecipient
plugin module based on the given key.
-
getNotificationRecipient
@Nullable public @Nullable NotificationRecipient getNotificationRecipient(NotificationRule rule)
Description copied from interface:NotificationManager
Instantiate and populate notification recipient from a rule.- Specified by:
getNotificationRecipient
in interfaceNotificationManager
-
getNotificationType
@Nullable public @Nullable NotificationType getNotificationType(NotificationRule rule)
Description copied from interface:NotificationManager
Instantiate and populate notification type from a rule.- Specified by:
getNotificationType
in interfaceNotificationManager
-
getNotificationTypeFromKey
@Nullable public @Nullable NotificationType getNotificationTypeFromKey(String key)
Description copied from interface:NotificationManager
Retrieve a specificNotificationType
plugin module based on the given key.- Specified by:
getNotificationTypeFromKey
in interfaceNotificationManager
- Parameters:
key
- of the notification type- Returns:
- a specific
NotificationType
plugin module based on the given key.
-
getNotificationRulesForUser
@NotNull public @NotNull List<UsersNotification> getNotificationRulesForUser(@NotNull @NotNull BambooUser user)
Description copied from interface:NotificationManager
Retrieves all notification rules associated with a given user searches for notification rules: * assigned to the user * assigned to a group the user belongs to * assigned to the user's email or user's im address * assigned to watchers of a build the user has marked as their favourite- Specified by:
getNotificationRulesForUser
in interfaceNotificationManager
- Parameters:
user
- BambooUser to look up notifications for- Returns:
- all notification rules associated with a given user following the above rules
-
isRecipientUserBase
public boolean isRecipientUserBase(NotificationRule notificationRule)
Description copied from interface:NotificationManager
Determines whether or not a notification rule recipient evaluates to a bamboo user and therefore comply with the users notification preference.- Specified by:
isRecipientUserBase
in interfaceNotificationManager
- Parameters:
notificationRule
- to check- Returns:
- true if the recipient evaluates to a user
-
replaceNotificationRule
public void replaceNotificationRule(@NotNull @NotNull NotificationSet notificationSet, long existingNotificationId, @NotNull @NotNull NotificationRule newNotificationRule)
Description copied from interface:NotificationManager
Replaces a notification rule with the new definition. This method should always be preferred when replacing an existing rule instead of operating on theNotificationSet
manually. Reason: as of current Hibernate, queries which modify collections (such asNotificationSet
) are batched and executed in a specific order. In particular, inserts are executed before deletes. Due to constraints on theNotificationRule
class/table this may lead to database constraint violations, resulting in unsuccessful updates and exceptions.- Specified by:
replaceNotificationRule
in interfaceNotificationManager
- Parameters:
notificationSet
- notification set on which the operation should be executedexistingNotificationId
- id of the existing notification rulenewNotificationRule
- new notification rule to replace the existing one- See Also:
- HHH-2801
-
createOrGetSystemNotificationSet
@NotNull public @NotNull NotificationSet createOrGetSystemNotificationSet()
Description copied from interface:NotificationManager
Get the system notification set for this bamboo and if one doesn't exist create it!- Specified by:
createOrGetSystemNotificationSet
in interfaceNotificationManager
- Returns:
-
saveSystemNotificationRule
public void saveSystemNotificationRule(@NotNull @NotNull NotificationRule notificationRule)
Description copied from interface:NotificationManager
Do not use this method. Use SystemNotificationService.saveSystemNotificationRule(); Save an individual system notification rule.- Specified by:
saveSystemNotificationRule
in interfaceNotificationManager
- Parameters:
notificationRule
- to be added
-
getNotificationRuleById
@Nullable public @Nullable NotificationRule getNotificationRuleById(long notificationId)
Description copied from interface:NotificationManager
Get a specific notification rule- Specified by:
getNotificationRuleById
in interfaceNotificationManager
- Parameters:
notificationId
- of the notification to get.- Returns:
- the notification rule with the given ID, or null if one doesn't eixst
-
getNotificationSetById
@Nullable public @Nullable NotificationSet getNotificationSetById(long notificationSetId)
Description copied from interface:NotificationManager
Get a specific notification set- Specified by:
getNotificationSetById
in interfaceNotificationManager
- Parameters:
notificationSetId
- of the notification set to get.- Returns:
- the notification set with the given ID, or null if one doesn't exist
-
setNotificationDao
public void setNotificationDao(NotificationDao notificationRuleDao)
-
setPluginAccessor
public void setPluginAccessor(com.atlassian.plugin.PluginAccessor pluginAccessor)
-
-