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

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

3 votes
Accepted answer

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 :)

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

2 votes

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)

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.

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 :)

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!

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 :)

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.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published yesterday in Agile

How Scrum works? It starts with training and education

To answer “How scrum works,” most of the teams I've worked with first addressed the question: “where to start?”  That question applies to both implementation and improvements on the Scrum framew...

106 views 3 3
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you