【问题标题】:How to set the description of a JIRA Workflow Validator?如何设置 JIRA Workflow Validator 的描述?
【发布时间】:2019-11-28 17:57:52
【问题描述】:

我正在开发一个简单的 JIRA 服务器插件,如果没有设置某个自定义字段,它将防止发生转换。我使用atlas-create-jira-plugin-module 创建了一个新的工作流验证器,并定制了验证功能以满足我的需求。奇怪的是,当我通过工作流编辑器将这个新验证器添加到转换时,它会出现在验证列表中,并且描述错误。它显示了默认条件中的描述,“只有具有解决问题权限的用户才能执行此转换”。

我一直在关注本教程:https://developer.atlassian.com/server/jira/platform/creating-workflow-extensions/ 我也遇到过这个类似的教程:https://www.j-tricks.com/tutorials/workflow-validator

在我的 atlassian-plugin.xml 中,我确保定义了一个“视图”速度资源:

<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>

而custom-field-is-set-validator.vm的内容如下:

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

作为健全性检查,我创建了一个工作流条件并将我的速度 (vm) 资源应用为它的视图模板。它在此上下文中正确显示!

但是,当我尝试为我的工作流验证器使用相同的速度资源时,管理页面仍将验证器显示为“只有具有解决问题权限的用户才能执行此转换”,而不是使用我的描述。

我错过了什么?谢谢!

Screenshot showing the built-in condition

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

【问题讨论】:

    标签: jira jira-plugin atlassian-plugin-sdk


    【解决方案1】:

    事实证明,我从工作流条件中复制/粘贴了一段代码,需要针对工作流验证器进行调整。当我应该转换为 ValidatorDescriptor 时,我试图转换为 ConditionDescriptor:

    不好:

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

    好:

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

    非常简洁,它没有完全破坏我的插件,而是完全显示了不同的描述。 ;)

    【讨论】:

      【解决方案2】:

      我在 2011 年写了一本 O'Reilly 的书 Practical Jira Plugins,其中有一个验证器示例。来源是https://bitbucket.org/mdoar/practical-jira-plugins/src/default/(这本书在外面)。

      但坦率地说,这些天我会使用 ScriptRunner、JMWE 或其他插件来让您编写自定义工作流程。但不要让这阻止你学习它!祝你好运

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2022-10-31
        • 2015-03-24
        • 2015-06-24
        • 2015-10-09
        • 1970-01-01
        • 1970-01-01
        • 2016-06-06
        相关资源
        最近更新 更多