import
com.atlassian.jira.component.ComponentAccessor
import
com.atlassian.jira.workflow.JiraWorkflow
import
com.atlassian.jira.workflow.WorkflowManager
import
java.util.regex.Matcher
String searchText =
'com.innovalog.jmwe.jira-misc-workflow-extensions'
WorkflowManager workflowManager = ComponentAccessor.getWorkflowManager()
Collection<JiraWorkflow> workflows = workflowManager.getWorkflows()
String result =
"Workflow;Function;Type;Action;Step\r\n<br/>"
workflows.each{workflow ->
def workflowXml = workflow.descriptor.asXML()
Matcher m = workflowXml =~ /${searchText}/
if
(m.find()) {
String workflow_name =
"${workflow.name}${if(!workflow.isActive()){"
;(inactive)
"} else ';active'}${if(workflow.isDraftWorkflow()){"
(draft)
"} else ''}"
def wf =
new
XmlParser().parseText(workflowXml)
List<Node> wf_flat = wf.depthFirst()
wf_flat.each{
if
(it.text() ==~ /.*${searchText}.*/){
result +=
"$workflow_name;${getNodeInfo(it,searchText)}\n\n<br/>"
}
}
}
}
result
String getNodeInfo(Node n, String search) {
String nodetext =
''
nodetext +=
"${n.text() - search}"
def p = n.parent()
while
(p) {
switch
(p.name()) {
case
'"post-functions"'
:
nodetext +=
";post-function "
;
break
case
'validators'
:
nodetext +=
";validator "
;
break
case
'conditions'
:
nodetext +=
";condition "
;
break
case
'action'
:
nodetext +=
";${p.attribute('name')} (${p.attribute('id')})"
;
break
case
'step'
:
nodetext +=
";${p.attribute('name')} (${p.attribute('id')})"
;
break
case
'global-actions'
:
nodetext +=
";GLOBAL "
;
break
case
'initial-actions'
:
nodetext +=
";INITIAL "
;
break
}
p = p.parent()
}
return
nodetext
}