Hi all, I am building a JSP script to read all a workflow’s post functions and just print out on a page - nothing fancy and no VM files. The script will go under atlassian-jira\secure\admin
and can be accessed from JIRA itself (which means the resources are being share). The JSP script that I have so far is:
<%@ page import="com.atlassian.jira.component.ComponentAccessor" %>
<%@ page import="com.atlassian.jira.issue.status.Status" %>
<%@ page import="com.atlassian.jira.workflow.WorkflowManager" %>
<%@ page import="com.atlassian.jira.workflow.JiraWorkflow" %>
<%@ page import="com.opensymphony.workflow.loader.ActionDescriptor" %>
<%@ page import="com.opensymphony.workflow.loader.WorkflowDescriptor" %>
<%@ page import="com.opensymphony.workflow.loader.StepDescriptor" %>
<%@ page import="com.opensymphony.workflow.loader.FunctionDescriptor" %>
<%@ page import="com.opensymphony.workflow.loader.AbstractDescriptor" %>
<%@ page import="java.util.Collection" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Map" %>
<%@ page contentType="text/html; charset=UTF-8" %>
<html>
<head>
<title>Workflow Parser</title>
</head>
<body>
<%
if (request.getMethod().equals("POST") && request.getParameter("find") != null)
{
//out.print("<div>Parsing...</div><br>");
WorkflowManager workflowManager = ComponentAccessor.getWorkflowManager();
String workflowName = "<workflow name>";
JiraWorkflow workflow = workflowManager.getWorkflow(workflowName);
//String workflowXml = workflow.getName();
//out.print(workflowXml);
Collection<ActionDescriptor> allActions = workflow.getAllActions();
for (ActionDescriptor actionName: allActions)
{
String outMessage = String.format("<br><div>Transition Name: %s</div><br>", actionName);
out.print(outMessage);
Collection<StepDescriptor> allSteps = workflow.getStepsForTransition(actionName);
for (StepDescriptor stepName: allSteps)
{
//out.print(stepName);
//List<Status> status = workflow.getLinkedStatus(stepName);
Status status = workflow.getLinkedStatus(stepName);
String statusName = String.format("<div>From Status Name: %s</div>", status.getName());
out.print(statusName);
}
Collection<FunctionDescriptor> allPostFunct = workflow.getPostFunctionsForTransition(actionName);
out.print(allPostFunct.getClass() + "<br>");
for (FunctionDescriptor postFunct: allPostFunct)
{
out.print(postFunct.getClass() + "<br>");
Map postFunctArgs = postFunct.getArgs();
out.print(postFunctArgs.getClass() + "<br>");
out.print(postFunctArgs + "<br>");
}
}
}
else
{
%>
<p>This script will parse the workflow and list down all the workflow components in a table form</p>
<form action="" method="post">
<input type="hidden" name="find" value="yes" />
<input type="submit" value="Parse workflow" />
</form>
<%
}
%>
</body>
</html>
The output I am getting is:
Transition Name: Create
class java.util.ArrayList
class com.opensymphony.workflow.loader.FunctionDescriptor
class java.util.HashMap
{class.name=com.atlassian.jira.workflow.function.issue.IssueCreateFunction}
class com.opensymphony.workflow.loader.FunctionDescriptor
class java.util.HashMap
{class.name=com.atlassian.jira.workflow.function.issue.IssueReindexFunction}
class com.opensymphony.workflow.loader.FunctionDescriptor
class java.util.HashMap
{eventTypeId=1, class.name=com.atlassian.jira.workflow.function.event.FireIssueEventFunction}
Transition Name: Start Progress
...
As you can see , I manage to go up to FunctionDescriptor and now I am stuck here, I do not know how to convert these values to what we see in the JIRA’s UI. I did some digging and it seems like I need to parse this values with a different class to get those definition that I am seeing on the UI. Can someone help to point me to a right direction, I don’t mind if there is any example that I can refer to.
Cheers,
Mogavenasan