I need to modify MailListener.java (for Jira version 7.0.10) to NOT send out email if the current logged-in user is <some-userid>.
Here's the code snippet of MailListener.java :
........... import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.user.ApplicationUser; .............. private static final ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(); ...... @EventListener public void handleIssueEventBundle(final IssueEventBundle bundle) { if (currentUser == null) { log.error("Cannot determine current logged-in user"); // <<<<--------- this error shows up in the log return; } if (currentUser.getUsername().equals(specialUser)) { log.debug("1. Ignore sending email notification because user=[" + currentUser.getUsername() + "]"); return; } issueEventBundleMailHandler.handle(bundle); }
In the atlassian-jira.log, i see:
[c.a.j.e.listeners.mail.MailListener] Cannot determine current logged-in user
What is the correct way to get the current logged-in user in MailListener.java ?
https://docs.atlassian.com/jira/7.0.9/com/atlassian/jira/event/issue/IssueEvent.html has a getUser() method that should tell you the info you want
protected void handleDefaultIssueEvent(final IssueEvent event) { if (event.isRedundant()) { return; } handleIssueEventBundle(issueEventBundleFactory.wrapInBundle(event)); }
Thanks. I saw that method, but the debug messages i've put in indicate that handleIssueEventBundle() is STILL being invoked by Jira. As far as i can tell, emails are getting sent out by handleIssueEventBundle().
The argument to handleIssueEventBundle is of type "IssueEventBundle". I have not been able to get the appropriate code in place in order to convert IssueEventBundle to an IssueEvent.
Do you have any pointers on how to get an IssueEvent from within handleIssueEventBundle() method?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
DefaultIssueEventBundle has a getEvents method that looks like it returns JiraIssueEvent objects which have a asIssueEvent method to access the original IssueEvent object
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Matt, thanks again for your help.
I also saw that earlier in the docs and already tried:
@EventListener public void handleIssueEventBundle(final IssueEventBundle bundle) { Collection<JiraIssueEvent> Cjie = bundle.getEvents(); for (JiraIssueEvent jie: Cjie) { IssueEvent event = jie.asIssueEvent(); // <<--- compiler complains about asIssueEvent() being not found log.debug("user of current event object is [" + event.getUser().getName() + "]"); } issueEventBundleMailHandler.handle(bundle); }
However, i got compilation errors:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project jira-core: Compilation failure [ERROR] /...../atlassian-jira-software-7.0.10-source/jira-project/jira-components/jira-core/src/main/java/com/atlassian/jira/event/listeners/mail/MailListener.java:[147,35] cannot find symbol [ERROR] symbol: method asIssueEvent() [ERROR] location: variable jie of type com.atlassian.jira.event.issue.JiraIssueEvent
Any other suggestions would be greatly appreciated.
Thanks
--Andrew
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hmm. Cast jie to DelegatingJiraIssueEvent perhaps
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.