PageRenderTime 38ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/src/main/resources/com/onresolve/jira/groovy/canned/workflow/conditions/TestCondition.groovy

https://bitbucket.org/sorin/jira-plugin-intellij
Groovy | 71 lines | 57 code | 13 blank | 1 comment | 3 complexity | 6e597c7bdc79292034576fc737b0a83f MD5 | raw file
  1. package com.onresolve.jira.groovy.canned.workflow.conditions
  2. import com.onresolve.jira.groovy.canned.CannedScript
  3. import com.atlassian.jira.ComponentManager
  4. import org.apache.log4j.Category
  5. import com.atlassian.jira.util.ErrorCollection
  6. import com.atlassian.jira.util.SimpleErrorCollection
  7. class TestCondition implements CannedScript{
  8. ComponentManager componentManager = ComponentManager.getInstance()
  9. Category log = Category.getInstance(TestCondition.class)
  10. def projectManager = componentManager.getProjectManager()
  11. String getName() {
  12. return "Sample condition"
  13. }
  14. String getDescription() {
  15. return "A condition used for testing with some <b>html</b>"
  16. }
  17. List getCategories() {
  18. ["Condition"]
  19. }
  20. List getParameters(Map params) {
  21. [
  22. [
  23. Name:"ProjectKey",
  24. Description:"Project key, ie one of " + componentManager.getProjectManager().getProjects()*.get("key"),
  25. ],
  26. [
  27. Name:"User",
  28. Description:"A user ID",
  29. ],
  30. ]
  31. }
  32. public ErrorCollection doValidate(Map params, boolean forPreview) {
  33. ErrorCollection errorCollection = new SimpleErrorCollection();
  34. Object projectKey = params["ProjectKey"]
  35. if (!projectKey) {
  36. errorCollection.addError "ProjectKey", "You must enter a project key"
  37. }
  38. else if (! projectManager.getProjectObjByKey(projectKey as String)) {
  39. errorCollection.addError "ProjectKey", "Project with key \"$projectKey\" not found"
  40. }
  41. errorCollection
  42. }
  43. Map doScript(Map params) {
  44. log.debug ("TestCondition.doScript with params: ${params}");
  45. log.debug ("project key: ${params['ProjectKey']}")
  46. params['passesCondition'] = true
  47. return params
  48. }
  49. String getDescription(Map params, boolean forPreview) {
  50. String projectKey = params['ProjectKey']
  51. def projectName = componentManager.getProjectManager().getProjectObjByKey(projectKey)?.getName() ?: "(Project not found)"
  52. // def projectName = "Some project"
  53. getName() + " : This is what the user sees when the args are validated OK - project <b>$projectName</b> will be checked"
  54. }
  55. public Boolean isFinalParamsPage(Map params) {
  56. true
  57. }
  58. }