View difference between Paste ID: J3pQyLmi and RCeKkgxk
SHOW: | | - or go back to the newest paste.
1-
/***********************************/
1+
/**
2-
/*   CARPETA - Plantilla Fichero   */
2+
* Script que busca el uso de cierta paquetería ('searchText') en todos los workflows.
3-
/***********************************/
3+
* Sirve para localizar dónde se está utilizando cierto addon a partir de su paquetería.
4
*/
5-
// Titulo 01
5+
import com.atlassian.jira.component.ComponentAccessor
6-
// Titulo 02
6+
import com.atlassian.jira.workflow.JiraWorkflow
7
import com.atlassian.jira.workflow.WorkflowManager
8-
/************************************************************************/
8+
import java.util.regex.Matcher
9
 
10-
// Titulo 01
10+
String searchText = 'com.ats.jira' // busca usos del addon auto-transitions
11-
Codigo 011
11+
12-
.....
12+
WorkflowManager workflowManager = ComponentAccessor.getWorkflowManager()
13-
Codigo 012
13+
Collection<JiraWorkflow> workflows = workflowManager.getWorkflows()
14-
Codigo 013
14+
15-
	> CodigoAñadido 0131
15+
String result = "Workflow;Function;Type;Action;Source-Step<br>"
16
 
17
workflows.each{workflow ->
18-
// Titulo 02
18+
    def workflowXml = workflow.descriptor.asXML()
19-
Codigo 021		// Comentario 021
19+
    Matcher m = workflowXml =~ /${searchText}/
20-
20+
    if (m.find()) {
21-
//// Opcion 2
21+
        String workflow_name = "${workflow.name}${if(!workflow.isActive()){"(inactive)"} else ''}${if(workflow.isDraftWorkflow()){"(draft)"} else ''}"
22-
Codigo 021b
22+
        def wf = new XmlParser().parseText(workflowXml)
23
        List<Node> wf_flat = wf.depthFirst()
24
        wf_flat.each{
25
            if (it.text() ==~ /.*${searchText}.*/){
26
                def nodeInfo = getNodeInfo(it,searchText)
27
                if (nodeInfo){
28
                    result += "$workflow_name;$nodeInfo<br>"
29
                }
30
            }
31
        }
32
    }
33
}
34
result
35
 
36
String getNodeInfo(Node n, String search) {
37
    String nodetext = ''
38
    def valid_action = false
39
    def valid_function = false
40
    def valid_step = false
41
    if (n.name() == 'function') {
42
        def m = n.value() =~ /[^\[{]*/ + search + /[^\]}]*/
43
        if (m) {
44
            nodetext += m[0].toString() + ";"
45
        }
46
        def p = n.parent()
47
        while (p) {
48
            switch (p.name()) {
49
                case 'post-functions':
50
                    valid_function = true
51
                    nodetext += "post-function;"; break
52
                case 'validators':
53
                    valid_function = true
54
                    nodetext += "validator;"; break
55
                case 'conditions':
56
                    valid_function = true
57
                    nodetext += "condition;"; break
58
                case 'action':
59
                    valid_action = true
60
                    nodetext += "${p.attribute('name')} (${p.attribute('id')});"; break
61
                case 'step':
62
                    valid_step = true
63
                    nodetext += "${p.attribute('name')} (${p.attribute('id')})"; break
64
                case 'global-actions':
65
                    valid_step = true
66
                    nodetext += "GLOBAL"; break
67
                case 'initial-actions':
68
                    valid_step = true
69
                    nodetext += "INITIAL"; break
70
            }
71
            p = p.parent()
72
        }
73
    }
74
    if (valid_action && valid_function && valid_step) {
75
        return nodetext
76
    } else {
77
        return ""
78
    }
79
}
80
/************************************/
81