PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/src/main/resources/com/onresolve/jira/groovy/canned/workflow/validators/TestValidator.groovy

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