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

]