/src/main/resources/com/onresolve/jira/groovy/canned/workflow/listeners/CustomListener.groovy
Groovy | 77 lines | 59 code | 17 blank | 1 comment | 3 complexity | b6c93ead16c6090c128e3a3c9f89f0e2 MD5 | raw file
- package com.onresolve.jira.groovy.canned.workflow.listeners
-
- import com.onresolve.jira.groovy.canned.CannedScript
- import com.atlassian.jira.util.ErrorCollection
- import org.apache.log4j.Category
- import com.atlassian.jira.util.SimpleErrorCollection
-
- class CustomListener implements CannedScript {
-
- Category log = Category.getInstance(CustomListener.class)
-
- String getName() {
- return "Custom listener"
- }
-
- String getDescription() {
- return "Write your own groovy class as a custom listener."
- }
-
- List getCategories() {
- ["Listener"]
- }
-
- List getParameters(Map params) {
- [
- [
- Name:"clazz",
- Label:"Name of groovy class",
- Description:"""Fully-qualified class name class in the form com.acme.MyListener""",
- ]
- ]
- }
-
- ErrorCollection doValidate(Map params, boolean forPreview) {
- def errorCollection = new SimpleErrorCollection()
- def gcl = this.class.getClassLoader()
- if (! params["clazz"]) {
- errorCollection.addError("clazz", "You must provide a class name.")
- }
- else {
- try {
- gcl.loadClass(params["clazz"] as String, true, false).newInstance()
- }
- catch (Exception e) {
- errorCollection.addError("clazz", "Problem loading class: " + e.message)
- }
- }
-
- errorCollection
-
- }
-
- Map doScript(Map params) {
- log.debug(params)
-
- // this is the old custom listener... run it
- def gcl = this.class.getClassLoader()
- assert params["clazz"] as String
- Object delegate = gcl.loadClass(params["clazz"] as String, true, false).newInstance();
-
- if (! (delegate.respondsTo("workflowEvent"))) {
- log.warn("Listener class must implement workflowEvent(IssueEvent event).")
- }
-
- delegate.workflowEvent(params["event"])
-
- return params
- }
-
- String getDescription(Map params, boolean forPreview) {
- return "Custom listener: ${params['clazz']}"
- }
-
- Boolean isFinalParamsPage(Map params) {
- true
- }
- }