Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How automatically change the status of an issue when we attach a file to it ?

Mizan
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.
December 18, 2011

I am trying to create a plugin which which will change the status of an issue to a specified status when we attach any file to it.

I am doing this because i want to maintain consistency of any attached file to a issue upto a specific status.

Thanks in advance ..

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

3 votes
Answer accepted
Mizan
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.
December 20, 2011

Hi ,

I got my plugin working as i wanted.

i used MutableIssue issue1=getIssueObject(); to get the issue and added workflowTransitionUtil.progress(); to the code.

public class AttachFileChecker extends AttachFile {
Logger log=Logger.getLogger(AttachFileChecker.class);

public AttachFileChecker(
IssueLinkManager issueLinkManager,
SubTaskManager subTaskManager,
FieldScreenRendererFactory fieldScreenRendererFactory,
FieldManager fieldManager,
ProjectRoleManager projectRoleManager,
CommentService commentService,
AttachmentService attachmentService,
AttachmentManager attachmentManager,
IssueUpdater issueUpdater,
TemporaryAttachmentsMonitorLocator temporaryAttachmentsMonitorLocator) {
super(issueLinkManager, subTaskManager, fieldScreenRendererFactory,
fieldManager, projectRoleManager, commentService, attachmentService,
attachmentManager, issueUpdater, temporaryAttachmentsMonitorLocator);
}

@Override
protected String doExecute() throws Exception {
String ret_val = super.doExecute();
if (!ret_val.equals(Action.ERROR)){
postCreationTasks();
}
return ret_val;
}

private void postCreationTasks() {
MutableIssue issue1=getIssueObject();
final String remoteuser=ComponentManager.getInstance().getJiraAuthenticationContext().getUser().getName();
WorkflowTransitionUtil workflowTransitionUtil = ( WorkflowTransitionUtil ) JiraUtils.loadComponent( WorkflowTransitionUtilImpl.class );
workflowTransitionUtil.setIssue(issue1);
workflowTransitionUtil.setUsername(remoteuser);
workflowTransitionUtil.setAction(5);
workflowTransitionUtil.progress();
System.out.println("I reached here !!"+issue1.getSummary());
}
}

Thanx to Jobin and Nic :)

Nathanael Jefry April 26, 2018

Where should i put this code? is it a listner?

2 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 18, 2011

That sounds like a job for a listener. A listener can pick up the event (issue updated, from memory), scan it to see if the change was "attach a file" and then you can push it through a transition (bear in mind that your workflow will need to support that)

Mizan
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.
December 19, 2011

I tried do acheive this using a listener but was unable to do so .

now i created a plugin which extends jira action to attach file and i am able to do something like printing on the console when i attach any file.

now the only thing remaining is to change the issue status, for this i wrote a function however the issue status does not change from open->resolved.

below is the function i wrote .


private void postCreationTasks() {

MutableIssue issue = ComponentManager.getInstance().getIssueFactory().getIssue();
WorkflowTransitionUtil workflowTransitionUtil = ( WorkflowTransitionUtil ) JiraUtils.loadComponent( WorkflowTransitionUtilImpl.class );
workflowTransitionUtil.setIssue(issue);
workflowTransitionUtil.setAction(5);

System.out.println("I reached here !!");
}

"I reached here !!" is printed in the console when i attach a file.

Mizan
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.
December 19, 2011

I am even trying to do this through listeners, i am unable to scan the issue updated event to check whether the change was "Attach a file".

Can you help me ?

thanx :)

Jobin Kuruvilla [Adaptavist]
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.
December 19, 2011

Where are you calling workflowTransitionUtil.progress method? I don't see it in the above snippet. You need to call progress after setting issue, action etc!

Mizan
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.
December 20, 2011

When i called workflowTransitionUtil.progress(); it caused a runtime exception(Null pointer Exception) so i removed it without knowing its importance.

Now i found that the mutable issue object is null and since it is null cant perform any action on the issue.

i am trying to get the issue object in some other function however still it gives null value for the issue and prints a message continuosly.

below is the code

public class AttachFileChecker extends AttachFile(......


Logger log=Logger.getLogger(AttachFileChecker.class);
@Override
public String doDefault() throws Exception {
ComponentManager compMan=ComponentManager.getInstance();
MutableIssue issue1=compMan.getIssueFactory().getIssue();
final String remoteuser=ComponentManager.getInstance().getJiraAuthenticationContext().getUser().getName();
String iss =issue1.getSummary();
log.debug("this works");
System.out.println("Doing my crazy stuff here!"+iss+"..."+remoteuser);
return null;
}
@Override
protected String doExecute() throws Exception {
String ret_val = super.doExecute();
if (!ret_val.equals(Action.ERROR)){
postCreationTasks();
}
return ret_val;
}

private void postCreationTasks() {
/*WorkflowTransitionUtil workflowTransitionUtil = ( WorkflowTransitionUtil ) JiraUtils.loadComponent( WorkflowTransitionUtilImpl.class );
workflowTransitionUtil.setIssue(issue1);
workflowTransitionUtil.setUsername(remoteuser);
workflowTransitionUtil.setAction(5);
workflowTransitionUtil.progress();*/
System.out.println("I reached here !!");
}
}

Can u help me with this ?

thanx :)

0 votes
MattS
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.
December 22, 2011

I'm not even sure from memory that attaching an issue generates an event in all versions of JIRA. I did something like this for the JASF plugin that sets a copyright property on attachments by extending the action class just as Mizan did.

TAGS
AUG Leaders

Atlassian Community Events