Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

JIRA: Target an attachment event

Viktor Mirzoyan
Contributor
March 4, 2012

I've implemeted an issue event listener in my plugin where I can distinguish between more general types of events ( resolved, closed, updated .. etc ). I need a spcific process to occur ONLY when an attachment has been added to an issue. My problem is an attachment event is seen as an ISSUE_UPDATED event, which is failry generic considering a handful of other actions can trigger this event type. I don't want to trigger my specific process on any issue update event. Is there there a way to "filter" or distinguish an attachement event from all others?

2 answers

1 accepted

3 votes
Answer accepted
Viktor Mirzoyan
Contributor
March 8, 2012

Thanks, some of that info was a little outdated but it definitely led me in the right direction.

If anyone is looking for the same type of task, i suggest looking into the following two:

https://developer.atlassian.com/display/JIRADEV/Database+Schema

and

your INF/classes/entitydefs/entitymodel.xml file.

Here's a snippet that worked out for what I was looking for:

    private boolean isAnAttachmentEvent(IssueEvent event)
    {    	
    	boolean isAttachmentEvent = false;
    	List<GenericValue> changeItems = null;
    	
    	try {
        	GenericValue log = event.getChangeLog();
			changeItems = log.internalDelegator.findByAnd("ChangeItem",EasyMap.build("group",log.get("id")));
		} catch (GenericEntityException e) {
			System.out.println(e.getMessage());
		}
		
		if(changeItems == null) return false;
		
		Iterator<GenericValue> it = changeItems.iterator();
		while(it.hasNext()){
			String p = it.next().getString("field");
			if(p.equalsIgnoreCase("Attachment"))
				isAttachmentEvent = true;
		}
		
		return isAttachmentEvent;
    }

1 vote
MatthewC
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 4, 2012

You should be able to get the ChangeLog for the event from IssueEvent and then scan that to see if a file was attached

MatthewC
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 5, 2012

Just found some example code on how to go through the change history, it may not be the most up to date but it will give you a statr: http://confluence.atlassian.com/display/JIRACOM/JiraIssueChangeHistory

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events