Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,293,491
Community Members
 
Community Events
165
Community Groups

Attachment create event does not fire when attachment is created through Java

Edited

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:

@Component
public class IssueEventListener implements InitializingBean, DisposableBean {

    private static final Logger log = LoggerFactory.getLogger(IssueEventListener.class);

    @JiraImport
    private final EventPublisher eventPublisher;

    @Autowired
    public IssueEventListener(EventPublisher eventPublisher) {
        this.eventPublisher = eventPublisher;
    }

    @Override
    public void destroy() throws Exception {
        log.info("Disabling plugin");
        eventPublisher.unregister(this);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        log.info("Enabling plugin");
        eventPublisher.register(this);
    }

    @EventListener
    public void onIssueEvent(IssueEvent issueEvent) {
        Long eventTypeId = issueEvent.getEventTypeId();
        Issue issue = issueEvent.getIssue();

        if (eventTypeId.equals(EventType.ISSUE_CREATED_ID)) {
            log.warn("Issue {} has been created at {}.", issue.getKey(), issue.getCreated());
            System.out.println("issue created");
        } 
        else if (eventTypeId.equals(EventType.ISSUE_UPDATED_ID)) {
            log.warn("Issue {} has been updated (Attachment created/deleted at {}.", issue.getKey(), issue.getUpdated());
            System.out.println("issue updated");
        }

    }
}

Here is the code for attachment creation:

CreateAttachmentParamsBean attachmentParamsBean = new CreateAttachmentParamsBean.Builder(new File(path),
                filename, "text/plain", context.getLoggedInUser(),
                issue).build();
        ChangeItemBean bean = 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

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Atlassian Account

How to change your Atlassian account email address

When using an Atlassian account that is not managed, it’s possible to change the email address, but we often receive the following notification on the email that we want to use: Sorry, we couldn'...

1,055 views 2 18
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you