PageRenderTime 37ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/src/main/resources/com/onresolve/jira/groovy/canned/workflow/listeners/CustomListener.groovy

https://bitbucket.org/sorin/jira-plugin-intellij
Groovy | 77 lines | 59 code | 17 blank | 1 comment | 3 complexity | b6c93ead16c6090c128e3a3c9f89f0e2 MD5 | raw file
  1. package com.onresolve.jira.groovy.canned.workflow.listeners
  2. import com.onresolve.jira.groovy.canned.CannedScript
  3. import com.atlassian.jira.util.ErrorCollection
  4. import org.apache.log4j.Category
  5. import com.atlassian.jira.util.SimpleErrorCollection
  6. class CustomListener implements CannedScript {
  7. Category log = Category.getInstance(CustomListener.class)
  8. String getName() {
  9. return "Custom listener"
  10. }
  11. String getDescription() {
  12. return "Write your own groovy class as a custom listener."
  13. }
  14. List getCategories() {
  15. ["Listener"]
  16. }
  17. List getParameters(Map params) {
  18. [
  19. [
  20. Name:"clazz",
  21. Label:"Name of groovy class",
  22. Description:"""Fully-qualified class name class in the form com.acme.MyListener""",
  23. ]
  24. ]
  25. }
  26. ErrorCollection doValidate(Map params, boolean forPreview) {
  27. def errorCollection = new SimpleErrorCollection()
  28. def gcl = this.class.getClassLoader()
  29. if (! params["clazz"]) {
  30. errorCollection.addError("clazz", "You must provide a class name.")
  31. }
  32. else {
  33. try {
  34. gcl.loadClass(params["clazz"] as String, true, false).newInstance()
  35. }
  36. catch (Exception e) {
  37. errorCollection.addError("clazz", "Problem loading class: " + e.message)
  38. }
  39. }
  40. errorCollection
  41. }
  42. Map doScript(Map params) {
  43. log.debug(params)
  44. // this is the old custom listener... run it
  45. def gcl = this.class.getClassLoader()
  46. assert params["clazz"] as String
  47. Object delegate = gcl.loadClass(params["clazz"] as String, true, false).newInstance();
  48. if (! (delegate.respondsTo("workflowEvent"))) {
  49. log.warn("Listener class must implement workflowEvent(IssueEvent event).")
  50. }
  51. delegate.workflowEvent(params["event"])
  52. return params
  53. }
  54. String getDescription(Map params, boolean forPreview) {
  55. return "Custom listener: ${params['clazz']}"
  56. }
  57. Boolean isFinalParamsPage(Map params) {
  58. true
  59. }
  60. }