I hope someone is familiar with Atlassian SDK for Jira Server.
I try to catch an event when an attachment is added to Jira Issue. Here is my code listening to issue events:
<span>@Component</span>
<span>public</span> <span>class</span> <span>IssueEventListener</span> <span>implements</span> <span>InitializingBean</span>, DisposableBean {
<span>private</span> <span>static</span> <span>final</span> <span>Logger</span> <span>log</span> <span>=</span> LoggerFactory.getLogger(IssueEventListener.class);
<span>@JiraImport</span>
<span>private</span> <span>final</span> EventPublisher eventPublisher;
<span>@Autowired</span>
<span>public</span> <span>IssueEventListener</span><span>(EventPublisher eventPublisher)</span> {
<span>this</span>.eventPublisher = eventPublisher;
}
<span>@Override</span>
<span>public</span> <span>void</span> <span>destroy</span><span>()</span> <span>throws</span> Exception {
log.info(<span>"Disabling plugin"</span>);
eventPublisher.unregister(<span>this</span>);
}
<span>@Override</span>
<span>public</span> <span>void</span> <span>afterPropertiesSet</span><span>()</span> <span>throws</span> Exception {
log.info(<span>"Enabling plugin"</span>);
eventPublisher.register(<span>this</span>);
}
<span>@EventListener</span>
<span>public</span> <span>void</span> <span>onIssueEvent</span><span>(IssueEvent issueEvent)</span> {
<span>Long</span> <span>eventTypeId</span> <span>=</span> issueEvent.getEventTypeId();
<span>Issue</span> <span>issue</span> <span>=</span> issueEvent.getIssue();
<span>if</span> (eventTypeId.equals(EventType.ISSUE_CREATED_ID)) {
log.warn(<span>"Issue {} has been created at {}."</span>, issue.getKey(), issue.getCreated());
System.out.println(<span>"issue created"</span>);
}
<span>else</span> <span>if</span> (eventTypeId.equals(EventType.ISSUE_UPDATED_ID)) {
log.warn(<span>"Issue {} has been updated (Attachment created/deleted at {}."</span>, issue.getKey(), issue.getUpdated());
System.out.println(<span>"issue updated"</span>);
}
}
}Here is the code for attachment creation:
<span>CreateAttachmentParamsBean</span> <span>attachmentParamsBean</span> <span>=</span> <span>new</span> <span>CreateAttachmentParamsBean</span>.Builder(<span>new</span> <span>File</span>(path),
filename, <span>"text/plain"</span>, context.getLoggedInUser(),
issue).build();
<span>ChangeItemBean</span> <span>bean</span> <span>=</span> ComponentAccessor.getAttachmentManager().createAttachment(attachmentParamsBean);This code adds an attachment to the issue, but the event is not fired and issue history does not show that attachment also. On the other hand, when I add an attachment through Jira issue page manually, the event is fired and history shows an attachment too. So what is the problem with this code? Thanks in advance