PageRenderTime 42ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/sorin/jira-plugin-intellij
Groovy | 81 lines | 68 code | 12 blank | 1 comment | 3 complexity | e615901626662bd876686a9b025d8888 MD5 | raw file
  1. package com.onresolve.jira.groovy.canned.workflow.validators
  2. import com.atlassian.jira.ComponentManager
  3. import com.atlassian.jira.issue.MutableIssue
  4. import com.atlassian.jira.util.ErrorCollection
  5. import com.onresolve.jira.groovy.canned.CannedScript
  6. import com.onresolve.jira.groovy.canned.utils.ConditionUtils
  7. import org.apache.log4j.Category
  8. import com.opensymphony.workflow.InvalidInputException
  9. import com.opensymphony.util.TextUtils
  10. import com.onresolve.jira.groovy.canned.utils.CannedScriptUtils
  11. class SimpleScriptedValidator implements CannedScript{
  12. ComponentManager componentManager = ComponentManager.getInstance()
  13. Category log = Category.getInstance(SimpleScriptedValidator.class)
  14. def projectManager = componentManager.getProjectManager()
  15. public static String FIELD_ERROR_MSG = "FIELD_ERROR_MSG"
  16. public static String FIELD_FORM_FIELD = "FIELD_FORM_FIELD"
  17. String getName() {
  18. return "Simple scripted validator"
  19. }
  20. String getDescription() {
  21. "Runs a simple embedded script to find out whether to allow the transition or not"
  22. }
  23. List getCategories() {
  24. ["Validator"]
  25. }
  26. List getParameters(Map params) {
  27. [
  28. ConditionUtils.getConditionParameter(),
  29. [
  30. Label: "Error Message",
  31. Name: FIELD_ERROR_MSG,
  32. Description: "Error message that will be provided to the user if the condition is not true"
  33. ],
  34. [
  35. Label: "Field",
  36. Name: FIELD_FORM_FIELD,
  37. Description: """Form field that the error message will appear against. Leave blank for
  38. it to appear at the top.""",
  39. Type: "list",
  40. Values: CannedScriptUtils.getAllFields(true),
  41. ]
  42. ]
  43. }
  44. public ErrorCollection doValidate(Map params, boolean forPreview) {
  45. // todo: try parse script
  46. null
  47. }
  48. Map doScript(Map params) {
  49. MutableIssue issue = params['issue'] as MutableIssue
  50. Boolean doIt = ConditionUtils.processCondition(params[ConditionUtils.FIELD_CONDITION] as String, issue, false, params)
  51. if (! doIt) {
  52. def invalidInputException
  53. if (params[FIELD_FORM_FIELD]) {
  54. invalidInputException = new InvalidInputException(params[FIELD_FORM_FIELD] as String, params[FIELD_ERROR_MSG] as String)
  55. }
  56. else {
  57. invalidInputException = new InvalidInputException(params[FIELD_ERROR_MSG] as String)
  58. }
  59. params['invalidInputException'] = invalidInputException
  60. }
  61. return params
  62. }
  63. String getDescription(Map params, boolean forPreview) {
  64. getName() + " : Checks script: <pre>" + TextUtils.htmlEncode(params[ConditionUtils.FIELD_CONDITION] as String) + "</pre>"
  65. }
  66. public Boolean isFinalParamsPage(Map params) {
  67. true
  68. }
  69. }