Class ResultFlavor

java.lang.Object
com.inet.taskplanner.server.api.result.ResultFlavor

@JsonData public final class ResultFlavor extends Object
A ResultFlavor is an enum-like class representing the 'type' of data a Result contains. It serves as a matching system between results produced by jobs and actions that can process those results.

Purpose and Concept:
The TaskPlanner system allows jobs to produce various types of results (text data, files, printable content, etc.). However, not every result action can handle every type of result. For example:

  • An email action might be able to attach files and include text content in the message body
  • A file save action can only handle file-type results
  • A print action can only handle printable results

ResultFlavors solve this by providing a clear contract:

  1. Each Result declares what "flavors" of data it contains via Result.getFlavors()
  2. Each ResultAction declares which flavors it can process via getSupportedFlavors()
  3. The system automatically matches compatible results to actions based on these declarations

Example Usage:
Suppose you have a job that generates both a report file and a summary text. The job would return a ResultContainer containing:

If you configure an email action with file attachments enabled, it would return [FILE, TEXT, NONE] from getSupportedFlavors(). The system would then:

  • Send the FileResult as an email attachment
  • Include the TextResult content in the email body
  • Execute the action even if no results are present (due to NONE)

Complete Example - Custom Report Job with Multiple Actions:


 // 1. Job produces multiple result types
 public class ReportJob implements Job {
     public ResultContainer execute(JobDefinition definition) {
         ResultContainer container = new ResultContainer();

         // Add a PDF report file (FileResult -> FILE flavor)
         container.addResult(new LocalFileResult("report.pdf", pdfStream, "application/pdf"));

         // Add a text summary (TextResult -> TEXT flavor)
         container.addResult(new StringTextResult("Summary: Report completed successfully", "text/plain"));

         return container;
     }
 }

 // 2. Email action factory defines supported flavors based on configuration
 public class EmailActionFactory extends ResultActionFactory<EmailAction> {
     public List<ResultFlavor> getSupportedFlavors(ResultActionDefinition definition) {
         List<ResultFlavor> flavors = new ArrayList<>();
         flavors.add(ResultFlavor.NONE); // Always send email

         if (definition.getProperty("attachFiles").equals("true")) {
             flavors.add(ResultFlavor.FILE); // Attach files if enabled
         }

         if (definition.getProperty("includeText").equals("true")) {
             flavors.add(ResultFlavor.TEXT); // Include text in body if enabled
         }

         return flavors;
     }
 }

 // 3. File save action only handles file results
 public class SaveFileActionFactory extends ResultActionFactory<SaveFileAction> {
     public List<ResultFlavor> getSupportedFlavors(ResultActionDefinition definition) {
         return Arrays.asList(ResultFlavor.FILE); // Only save files
     }
 }

 // Result: System automatically matches results to compatible actions
 // - EmailAction receives both FILE and TEXT results (if configured to accept them)
 // - SaveFileAction receives only the FILE result
 // - Both actions execute even if no results match (due to NONE flavor)
 

Built-in Flavors:

  • NONE - For actions that don't require result data (e.g., sending notification emails)
  • FILE - For binary data with known size (e.g., reports, images) that can be saved or attached
  • TEXT - For human-readable text data that can be displayed in emails or other text contexts
  • PRINT - For printable content that can be sent to printers

New types of Flavors can be added with create(String).

You can use '==' to check for equality because there cannot be more than one Flavor object with the same key.

Since:
taskplanner 3.0
  • Field Details

    • NONE

      public static final ResultFlavor NONE
      This flavor can be used to trigger a ResultAction without passing any content data. It's for instance accepted by the e-mail action to send an e-mail even in case the job produced no result content to attach to the e-mail. Or in other words, if a ResultAction supports this flavor then it is executed even if no results at all or no matching results are available.

      There are no constraints to a Result supporting this flavor, but this makes no sense.

    • FILE

      public static final ResultFlavor FILE
      This flavor is used for any binary data with a known size. In case a result supports this flavor it MUST implement FileResult. Results of this type can for instance be stored to disk or attached to an e-mail
    • TEXT

      public static final ResultFlavor TEXT
      This flavor is used for textual data that is usually human readable. In case a result supports this flavor it MUST implement TextResult. Results of this type can be presented to a reader e.g. in the content of an e-mail.
    • PRINT

      public static final ResultFlavor PRINT
      This flavor is used for printable results. In case a result supports this flavor it MUST implement PrintResult.
  • Method Details

    • create

      public static ResultFlavor create(@Nonnull @Nonnull String key, ResultFlavor.FlavorLabel labelFunction)
      Creates, registers and returns a new ResultFlavor type.

      Typically used as a constant:
      public static final ResultFlavor TABLE = create( "TABLE" ); //table data flavor

      Note that you can use "==" for equality checks because there cannot be more than one Flavor object with the same key.

      Parameters:
      key - the key of this type, must be unique
      labelFunction - optional function to provide a internationalized label for the flavor.
      Returns:
      the new created flavor
      Throws:
      IllegalArgumentException - if the given key is null or a Flavor with this key exists already
      Since:
      taskplanner 3.0
    • create

      public static ResultFlavor create(@Nonnull @Nonnull String key)
      Creates, registers and returns a new ResultFlavor type.

      Typically used as a constant:
      public static final ResultFlavor TABLE = create( "TABLE" ); //table data flavor

      Note that you can use "==" for equality checks because there cannot be more than one Flavor object with the same key.

      Parameters:
      key - the key of this type, must be unique
      Returns:
      the new created flavor
      Throws:
      IllegalArgumentException - if the given key is null or a Flavor with this key exists already
      Since:
      taskplanner 3.0
    • getKey

      @Nonnull public @Nonnull String getKey()
      Returns the key of this ResultFlavor
      Returns:
      the key of this flavor
      Since:
      taskplanner 3.0
    • valueOf

      public static ResultFlavor valueOf(String key)
      Get the Flavor for the given key name. This is equivalent to an enum's valueOf() method.
      Parameters:
      key - the key of the desired Flavor
      Returns:
      the ResultFlavor
      Throws:
      IllegalArgumentException - if there is no flavor for the given key
      Since:
      taskplanner 3.0
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getLabel

      public String getLabel()
      Returns the localized label of this flavor
      Returns:
      the label of this flavor for the current language
      Since:
      taskplanner 3.0
    • values

      public static Collection<ResultFlavor> values()
      Get all registered ResultFlavors. This is equivalent to an enum's values() method but with collection because array is ugly.
      Returns:
      List with currently registered ResultFlavors. Later registered Flavors are not reflected in the returned list.
      Since:
      taskplanner 3.0