PageRenderTime 27ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/src/main/resources/com/onresolve/jira/groovy/canned/workflow/postfunctions/AddWatcher.groovy

https://bitbucket.org/sorin/jira-plugin-intellij
Groovy | 79 lines | 62 code | 16 blank | 1 comment | 5 complexity | 37a0d89f5c891b489313c49c7024d75a MD5 | raw file
  1. package com.onresolve.jira.groovy.canned.workflow.postfunctions
  2. import com.atlassian.jira.ComponentManager
  3. import com.atlassian.jira.issue.MutableIssue
  4. import com.atlassian.jira.issue.watchers.WatcherManager
  5. import com.atlassian.jira.util.ErrorCollection
  6. import com.onresolve.jira.groovy.canned.CannedScript
  7. import com.onresolve.jira.groovy.canned.utils.ConditionUtils
  8. import org.apache.log4j.Category
  9. import com.atlassian.crowd.embedded.api.User
  10. class AddWatcher implements CannedScript {
  11. Category log = Category.getInstance(AddWatcher.class)
  12. String getName() {
  13. "Adds the current user as a watcher"
  14. }
  15. public String getHelpUrl() {
  16. "https://studio.plugins.atlassian.com/wiki/display/GRV/Listeners#Listeners-AddWatcher"
  17. }
  18. String getDescription() {
  19. "Adds the user performing the action as a watcher, if condition applies"
  20. }
  21. List getCategories() {
  22. ["Function", "Listener"]
  23. }
  24. List getParameters(Map params) {
  25. [
  26. ConditionUtils.getConditionParameter()
  27. ]
  28. }
  29. ErrorCollection doValidate(Map params, boolean forPreview) {
  30. null
  31. }
  32. Map doScript(Map params) {
  33. MutableIssue issue = params['issue'] as MutableIssue
  34. Boolean doIt = ConditionUtils.processCondition(params[ConditionUtils.FIELD_CONDITION] as String, issue, false, params)
  35. if (! doIt) {
  36. return [:]
  37. }
  38. ComponentManager componentManager = ComponentManager.getInstance()
  39. WatcherManager watcherManager = componentManager.getWatcherManager()
  40. User user = componentManager.getJiraAuthenticationContext().getUser()
  41. if (user) {
  42. // doesn't matter if they're already watching
  43. watcherManager.startWatching(user, issue.genericValue)
  44. }
  45. else {
  46. log.debug("Anonymous user, not adding as a watcher")
  47. }
  48. params
  49. }
  50. String getDescription(Map params, boolean forPreview) {
  51. StringBuffer sb = new StringBuffer()
  52. sb << "Current user will be added to watcher list of issue"
  53. if (params[ConditionUtils.FIELD_CONDITION]) {
  54. sb << " if this condition is true:<br><pre>${params[ConditionUtils.FIELD_CONDITION]}</pre>"
  55. }
  56. else {
  57. sb << "."
  58. }
  59. }
  60. Boolean isFinalParamsPage(Map params) {
  61. true
  62. }
  63. }