此内容没有您所选择的语言版本。

9.2. Define a Work Item


A work item represents an atomic unit of work in a declarative way. The work item includes a unique name and parameters; in addition, each item can include results where results are expected to appear. A notification of a work item with no result parameters or icon could be defined as follows:
  Name: "Notification"
  Parameters
  From [String]
  To [String]
  Message [String]
  Priority [String]
Work item definitions are specified in one or more configuration files (with a .wid file extension) in the project classpath in the META-INF directory. The properties are provided as name-value pairs. Parameters and results are mapped and each parameter name is mapped to the expected data type. The configuration file also includes the display name and icon for the work item.

Example 9.2. Example Notification Work Item using MVEL

import org.drools.process.core.datatype.impl.type.StringDataType;
[
  // the Notification work item
  [
    "name" : "Notification",
    "parameters" : [
      "Message" : new StringDataType(),
      "From" : new StringDataType(),
      "To" : new StringDataType(),
      "Priority" : new StringDataType(),
    ],
    "displayName" : "Notification",
    "icon" : "icons/notification.gif"
  ]

]
Icons need to be in either .gif or .png format; both formats require a pixel size of 16x16. The icons should be stored in the resources directory:
project/src/main/resources/icons/notification.gif
In addition to the properties defined in the work item, all work items also have these three properties:
  1. Parameter Mapping:
    Maps the value of a variable in the process to a parameter of the work item. The work item can be customized based on the current state of the actual process instance (for example, the priority of the notification could be dependent on process-specific information).
  2. Result Mapping:
    Maps a result to a process variable, which is returned after the work item has been executed, and it makes the variable available to the rest of the process.
  3. Wait for completion:
    By default, the process waits until the requested work item has been completed before continuing with the process. It is also possible to continue immediately after the work item has been requested (and not wait for the results) by setting wait for completion to false.
The process below is an example that creates a domain-specific node to execute Java, asking for the class and method parameters. It includes a custom java.gif icon and consists of the following files and resulting screenshot:

Example 9.3. 

import org.drools.process.core.datatype.impl.type.StringDataType;
[
  // the Java Node work item located in:
  // project/src/main/resources/META-INF/JavaNodeDefinition.conf
  [
    "name" : "JavaNode",
    "parameters" : [
      "class" : new StringDataType(),
      "method" : new StringDataType(),
    ],
    "displayName" : "Java Node",
    "icon" : "icons/java.gif"
  ]

]

Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2026 Red Hat
返回顶部