Class ResultFlavor
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
Result flavors solve this by providing a clear contract:
- Each
Resultdeclares what "flavors" of data it contains viaResult.getFlavors() - Each
ResultActiondeclares which flavors it can process viagetSupportedFlavors() - 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:
- A
FileResultwith flavorFILE - A
TextResultwith flavorTEXT
If you configure an email action with file attachments enabled, it would return [FILE, TEXT, NONE] from
getSupportedFlavors(). The system would then:
- Send the
FileResultas an email attachment - Include the
TextResultcontent in the email body - Execute the action even if no results are present (due to
NONE)
Example - a job result with multiple result types:
A Job subclass can return a
ResultContainer containing different result types:
// A Job implementation can return this container from its run() method.
ResultContainer container = new ResultContainer( Arrays.asList(
new ByteArrayFileResult( "report.pdf", pdfBytes ),
new StringTextResult( "Summary: Report completed successfully", "text/plain" )
) );
// An email action can support files, text, and execution without results.
List<ResultFlavor> emailFlavors = Arrays.asList( FILE, TEXT, NONE );
// A file-save action can support files only.
List<ResultFlavor> saveFlavors = Arrays.asList( FILE );
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 attachedTEXT- For human-readable text data that can be displayed in emails or other text contextsPRINT- 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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceFunctional interface for internationalizing a ResultFlavor. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ResultFlavorThis flavor is used for any binary data with a known size.static final ResultFlavorThis flavor can be used to trigger aResultActionwithout passing any content data.static final ResultFlavorThis flavor is used for printable results.static final ResultFlavorThis flavor is used for textual data that is usually human-readable. -
Method Summary
Modifier and TypeMethodDescriptionstatic ResultFlavorCreates, registers and returns a newResultFlavortype.static ResultFlavorcreate(@Nonnull String key, ResultFlavor.FlavorLabel labelFunction) Creates, registers and returns a newResultFlavortype.@Nonnull StringgetKey()Returns the key of this ResultFlavorgetLabel()Returns the localized label of this flavortoString()static ResultFlavorGet the Flavor for the given key name.static Collection<ResultFlavor> values()Gets all registered result flavors.
-
Field Details
-
NONE
This flavor can be used to trigger aResultActionwithout passing any content data. For example, it is 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 aResultActionsupports this flavor then it is executed even if noresultsat all or when no matching results are available.There are no constraints on a
Resultthat supports this flavor, although doing so has no practical effect. -
FILE
This flavor is used for any binary data with a known size. If a result supports this flavor, it MUST implementFileResult. Results of this type can, for example, be stored to disk or attached to an e-mail. -
TEXT
This flavor is used for textual data that is usually human-readable. If a result supports this flavor, it MUST implementTextResult. Results of this type can be presented to a reader, for example, in the content of an e-mail. -
PRINT
This flavor is used for printable results. In case a result supports this flavor it MUST implementPrintResult.
-
-
Method Details
-
create
Creates, registers and returns a newResultFlavortype.Typically used as a constant:
public static final ResultFlavor TABLE = create( "TABLE" ); //table data flavorNote 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 uniquelabelFunction- optional function to provide an internationalized label for the flavor.- Returns:
- the newly created flavor
- Throws:
IllegalArgumentException- if the given key is null or a Flavor with this key exists already- Since:
- taskplanner 3.0
-
create
Creates, registers and returns a newResultFlavortype.Typically used as a constant:
public static final ResultFlavor TABLE = create( "TABLE" ); //table data flavorNote 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 newly created flavor
- Throws:
IllegalArgumentException- if the given key is null or a Flavor with this key exists already- Since:
- taskplanner 3.0
-
getKey
Returns the key of this ResultFlavor- Returns:
- the key of this flavor
- Since:
- taskplanner 3.0
-
valueOf
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
-
getLabel
Returns the localized label of this flavor- Returns:
- the label of this flavor for the current language
- Since:
- taskplanner 3.0
-
values
Gets all registered result flavors. This is equivalent to an enum's values() method, but returns a collection instead of an array.- Returns:
- a collection with the currently registered
ResultFlavors. Later registered flavors are not reflected in the returned collection. - Since:
- taskplanner 3.0
-