Creating a NotificationRule?

I can't seem to find the necessary API calls to create and add a new notification rule.

I see the addNewRule method in NotificationRulesHolder, NotificationRulesManager, and UserGroupNotificationRulesManager, but this method requires a NotificationRule to be passed in, and I can't find a way to actually create a NotificationRule.

I see there's an undocumented factory, NotificationRuleFactory, but since it's undocumented, I'm assuming that's a closed API? Surely there has to be a way to create a notification rule via the Open API, if the addNewRule methods exist? :) Or perhaps, the intent is that you can only add existing rules as "new" rules for a given user/group/etc.?

Any help would be greatly appreciated!!

Comment actions Permalink

So it turns out that using NotificationRuleFactory to create the NotificationRule (well, technically, it creates a sub-interface, NotificationRuleInit) seems to work.  Here's what my code does:

Collection<NotificationRule.Event> events = new HashSet<NotificationRule.Event>();
events.add(NotificationRule.Event.BUILD_FINISHED_SUCCESS); events.add(NotificationRule.Event.BUILD_FINISHED_FAILURE); NotificationRuleInit rule = this.notificationRuleFactory.createRuleForProject(myProject, events); this.notificationRulesManager.addNewRule(this.userGroupManager.getAllUsersGroup().getKey(), EMAIL_NOTIFIER_TYPE, rule);

Note that notificationRuleFactory, notificationRulesManager, and userGroupManager are all Spring-autowired fields of my class.

However... I am still using the undocumented (closed API class) NotificationRuleFactory.  Is there a better/more correct way of doing this?

Comment actions Permalink

Sorry for delay with replying. Unfortunately there is no open API for creating notification rules at the moment. However if you want to add notification rule to a user, you do not have to use NotificationRulesManager, because SUser interface extends from NotificationRulesHolder which has methods allowing to manage user notification rules. The same is true for user group class.


Please sign in to leave a comment.