0

I'm working on a simple JIRA Server plugin that will prevent a transition from occurring if a certain custom field has not been set. I have created a new workflow validator with atlas-create-jira-plugin-module and tailored the validate function to fit my needs. Strangely, when I add this new validator to a transition via the workflow editor, it appears in the list of validations with the wrong description. It is showing the description from the default condition, "Only users with Resolve Issues" permission can execute this transition".

I've been following along with this tutorial: https://developer.atlassian.com/server/jira/platform/creating-workflow-extensions/ I also came across this similar tutorial: https://www.j-tricks.com/tutorials/workflow-validator

In my atlassian-plugin.xml I made sure to define a "view" velocity resource:

<workflow-validator key="custom-field-is-set-validator" name="Custom Field Is Set Validator" i18n-name-key="custom-field-is-set-validator.name" class="com.ngc.jira.plugins.workflow.CustomFieldIsSetValidatorFactory"> 
    <description key="custom-field-is-set-validator.description">Validation to require that a custom field be given a value.</description>  
    <validator-class>com.ngc.jira.plugins.workflow.CustomFieldIsSetValidator</validator-class>  
    <resource type="velocity" name="view" location="templates/validators/custom-field-is-set-validator.vm"/>  
    <resource type="velocity" name="input-parameters" location="templates/validators/custom-field-is-set-validator-input.vm"/>  
    <resource type="velocity" name="edit-parameters" location="templates/validators/custom-field-is-set-validator-input.vm"/> 
  </workflow-validator>

And the contents of custom-field-is-set-validator.vm are as follows:

Only if the custom field <strong>$field</strong> has be set.

As a sanity check, I created a workflow condition and applied my velocity (vm) resource as the view template for it. It shows up correctly within this context!

However, when I try to use the same velocity resource for my workflow validator, the admin page still displays the validator as "Only users with Resolve Issues permission can execute this transition" instead of using my description.

What am I missing? Thanks!

Screenshot showing the built-in condition

Screenshot showing my validator that is wrongly appearing as the same condition

Jonathan.Taylor
  • 302
  • 1
  • 9

2 Answers2

0

I wrote an O'Reilly book Practical Jira Plugins back in 2011 that has a validator example. The source for this is at https://bitbucket.org/mdoar/practical-jira-plugins/src/default/ (and the book is Out There).

But frankly these days I'd use ScriptRunner, JMWE or other plugins that let you write custom workflow things. But don't let that stop you learning it! Good luck

mdoar
  • 6,758
  • 1
  • 21
  • 20
0

It turns out, I had copied/pasted a piece of code from my workflow condition that needed to be tweaked for a workflow validator. I was trying to cast to a ConditionDescriptor when I should have been casting to a ValidatorDescriptor:

Bad:

if (!(descriptor instanceof ConditionDescriptor)) {
          throw new IllegalArgumentException("Descriptor must be a ConditionDescriptor.");
        }

        ConditionDescriptor conditionDescriptor = (ConditionDescriptor) descriptor;

Good:

if (!(descriptor instanceof ValidatorDescriptor)) {
            throw new IllegalArgumentException("Descriptor must be a ValidatorDescriptor.");
        }

        ValidatorDescriptor validatorDescriptor = (ValidatorDescriptor) descriptor;

Pretty neat that instead of completely breaking my plugin, it ended up displaying a different description altogether. ;)

Jonathan.Taylor
  • 302
  • 1
  • 9