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 ..
Community moderators have prevented the ability to post new answers.
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 :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.