/src/main/resources/com/onresolve/jira/groovy/canned/workflow/validators/SimpleScriptedValidator.groovy
Groovy | 81 lines | 68 code | 12 blank | 1 comment | 3 complexity | e615901626662bd876686a9b025d8888 MD5 | raw file
- package com.onresolve.jira.groovy.canned.workflow.validators
-
- import com.atlassian.jira.ComponentManager
- import com.atlassian.jira.issue.MutableIssue
- import com.atlassian.jira.util.ErrorCollection
- import com.onresolve.jira.groovy.canned.CannedScript
- import com.onresolve.jira.groovy.canned.utils.ConditionUtils
- import org.apache.log4j.Category
- import com.opensymphony.workflow.InvalidInputException
- import com.opensymphony.util.TextUtils
- import com.onresolve.jira.groovy.canned.utils.CannedScriptUtils
-
- class SimpleScriptedValidator implements CannedScript{
-
- ComponentManager componentManager = ComponentManager.getInstance()
- Category log = Category.getInstance(SimpleScriptedValidator.class)
- def projectManager = componentManager.getProjectManager()
- public static String FIELD_ERROR_MSG = "FIELD_ERROR_MSG"
- public static String FIELD_FORM_FIELD = "FIELD_FORM_FIELD"
-
- String getName() {
- return "Simple scripted validator"
- }
-
- String getDescription() {
- "Runs a simple embedded script to find out whether to allow the transition or not"
- }
-
- List getCategories() {
- ["Validator"]
- }
-
- List getParameters(Map params) {
- [
- ConditionUtils.getConditionParameter(),
- [
- Label: "Error Message",
- Name: FIELD_ERROR_MSG,
- Description: "Error message that will be provided to the user if the condition is not true"
- ],
- [
- Label: "Field",
- Name: FIELD_FORM_FIELD,
- Description: """Form field that the error message will appear against. Leave blank for
- it to appear at the top.""",
- Type: "list",
- Values: CannedScriptUtils.getAllFields(true),
- ]
- ]
- }
-
- public ErrorCollection doValidate(Map params, boolean forPreview) {
- // todo: try parse script
- null
- }
-
- Map doScript(Map params) {
- MutableIssue issue = params['issue'] as MutableIssue
- Boolean doIt = ConditionUtils.processCondition(params[ConditionUtils.FIELD_CONDITION] as String, issue, false, params)
- if (! doIt) {
- def invalidInputException
- if (params[FIELD_FORM_FIELD]) {
- invalidInputException = new InvalidInputException(params[FIELD_FORM_FIELD] as String, params[FIELD_ERROR_MSG] as String)
- }
- else {
- invalidInputException = new InvalidInputException(params[FIELD_ERROR_MSG] as String)
- }
- params['invalidInputException'] = invalidInputException
- }
-
- return params
- }
-
- String getDescription(Map params, boolean forPreview) {
- getName() + " : Checks script: <pre>" + TextUtils.htmlEncode(params[ConditionUtils.FIELD_CONDITION] as String) + "</pre>"
- }
-
- public Boolean isFinalParamsPage(Map params) {
- true
- }
- }