Formatter plugin overview

Formatter plugin overview

There will be times where a Web Determinations interview will have an attribute that requires custom input data, or custom output format of the value of the attribute.

For example, say we have two variable 'number' attributes called 'longitude' and 'latitude'. While it is stored in Web Determinations as a double, during the Web Determinations interview it should allow the user to enter proper longitude and latitude formats; that is, angular measurements that consist of degrees/minutes/seconds and direction (for example, 66 33' 39" N).

Formatter plugins are Platform Session plugins that allow Web Determinations to correctly parse custom input data formats, and correctly 'format' custom output data formats.

With the above example:

 

See the topic, Formatter - sample code.

 

Web Determinations ships with a default Formatter. There are no special steps involved in using the default Formatter as it is automatically used to process input and output formats based on the attribute type. The default Formatter does have some very basic configuration to modify formats for Date, DateTime, Currency. More information about configuring these formats can be found in Input and output formats.

Like many other plugins, only one Formatter plugin can be registered per Web Determinations interview. The default Formatter provides important core functionality that needs to be extended (rather than overridden) - therefore custom Formatter plugins in almost all cases, delegate the core functionality to the default Formatter plugin except for functionality that needs to be customized/overridden. For more information about this, refer to the topic below, Developing a Formatter for a specific project/implementation.

Common scenarios

Ability to accept custom input format

A Web Determinations interview has a 'Number' variable attribute (or several attributes) that requires a standardized input format, for example angular measurements such as Latitude and Longitude(degrees/minutes/seconds and direction). The user needs to be able to enter standard angular measurement format(s) for fields that gather input data for those attributes in the Web Determinations interview, and those input values need to be translated to the number value (the format in which Web Determinations stores it).

Ability to display custom output format

Following custom input format above, a Web Determinations interview has a 'Number' variable attribute (or several attributes) it needs to display in the aforementioned Latitude/Longitude format. When the value of the attribute(s) needs to be displayed to the user, it needs to be converted from a number value (the format in which Web Determinations stores it) into the standardized angular measurement with direction .

Formatter and the Web Determination architecture

This section details how the Formatter fits into the Web Determinations architecture, and how to use it in the Web Determinations environment.

How Web Determinations use Formatter plugin by default

The default Formatter (DefaultFormatter) plugin is used automatically as it provides core functionality to Web Determinations  in terms of parsing all input data and formatting all output data. All input data for attributes provided during the Web Determinations interview; for example, in interview question screen is processed by the registered Formatter plugin. All output data displayed from attribute values; for example, Decision Report for an attribute also uses the registered Formatter plugin.

While other plugins are optional (for example, a Web Determinations interview does not need to have a Data Adaptor), or a List Provider plugin registered to the current interview session, a Formatter must always be registered to a Web Determinations interview. Furthermore, if the registered Formatter is a custom Formatter, it should also provide all the functionality the default Formatter provides together with custom formatting.

Formatter plugin and other Web Determination extensions

Most Web Determinations extensions are provided with input data that has already passed through the registered Formatter plugin, and thus has no need to directly access and use the Formatter. Also, output data returned by Web Determinations extensions to Web Determinations for display, usually passes through the registered Formatter for formatting before being displayed, and thus has no need to directly access and use the Formatter.

Formatter plugins are useful only to Web Determinations extensions that have to handle raw input and output data. These extensions are the Custom Screen and Custom Control plugins. Custom formatting of input and/or output data that is used by multiple Custom Screens/Controls should be contained in a Formatter.

Formatter class methods - functional methods

A Formatter plugin implements the interface WebDeterminationsFormatterPlugin. The WebDeterminationsFormatterPlugin interface in turn extends the  PlatformSessionPlugin and Formatter interface.

Below are important methods the WebDeterminationsFormatterPlugin interface requires when implemented. For details on other methods required, see the API documentation for the WebDeterminationsFormatterPlugin.

 

Method signature
Description
Object parse(
byte type,
String value,
Attribute attr)
Parses an input data value (String value) and returns its object representation using the input format(s) for the specified attribute value. Used by the Web Determinations to parse input data into a Ruleengine datatype (byte type).
  • 'type' relates to the value's Ruleengine datatype; for example, Boolean, Number, Date, and so on. See the HaleyType object (com.oracle.determinations.engine.HaleyType) for more information.
  • 'value' is the actual  value of the input data, as a String (since all data from the Web Determinations interview webpages are submitted as String).
  • 'attr' is the Attribute object to which the value belongs.
  • the returned Object is a standard Java/.NET data type. The calling method knows the HaleyType, and can therefore cast this object to the corresponding Java/.NET datatype.
Object parse(
byte type,
String value)
Parses an input data value (String value) and returns its object representation using the input format(s) for the specified attribute value. Used by the Web Determinations to parse input data into a Ruleengine datatype (byte type).
  • 'type' relates to the value's Ruleengine datatype; for example, Boolean, Number, Date, and so on. See the HaleyType object (com.oracle.determinations.engine.HaleyType) for more information.
  • 'value' is the actual  value of the input data, as a String (since all data from the Web Determinations interview webpages are submitted as String).
  • the returned Object is a standard Java/.NET data type. The calling method knows the HaleyType, and can therefore cast this object to the corresponding Java/.NET datatype.
String getFormattedValue(
byte type,
Object value,
Attribute attribute)
Formats a Ruleengine data value into output data (its formatted display representation) according to the specified Ruleengine datatype (byte type).
  • 'type' relates to the value's Ruleengine datatype; for example, Boolean, Number, Date, and so on. See the HaleyType object (com.oracle.determinations.engine.HaleyType) for more information.
  • 'value' is the Ruleengine data value, represented by an Object. This Object is a standard Java/.NET datatype based on the Ruleengine datatype.
  • 'attr' is the Attribute object to which the value belongs.
  • the returned String value is the value to be displayed.
String getFormattedValue(
byte type,
Object value)
Formats a Ruleengine data value into output data (its formatted display representation) according to the specified Ruleengine datatype (byte type).
  • 'type' relates to the value's Ruleengine datatype; for example, Boolean, Number, Date, and so on. See the HaleyType object (com.oracle.determinations.engine.HaleyType) for more information.
  • 'value' is the Ruleengine data value, represented by an Object. This Object is a standard Java/.NET datatype based on the Ruleengine datatype.
  • the returned String value is the value to be displayed.

Ruleengine datatypes

Below is a table listing the various Ruleengine datatypes (which correspond to the various attribute datatypes that exist when authoring rules in Oracle Policy Modeling) and the Java/.NET Object that corresponds to the datatype.

Note that the Ruleengine datatype column is derived from HaleyType values (see API documentation for com.oracle.determinations.engine.HaleyType).

 

Ruleengine datatype
Java/.NET object 
Boolean Boolean
Statement Boolean
Text String
Number Double
Currency Double
Date Date
DateTime Date
TimeOfDay com.oracle.determinations.engine.DeterminationsEngineTimeOfDay

Developing a Formatter for a specific project/implementation

This section explains the various approaches on designing and developing a Formatter plugin for a specific project/implementation.

Common design approach when building a custom Formatter plugin

A custom Formatter is usually required when specific and custom input and/or output format of a particular attribute's data (or attributes') need to be supported.

As was previously mentioned,  because Formatters perform core functionality for Web Determinations  (that is, parsing/formatting most or all input and output data), custom Formatters usually only need to extend the default Formatter (or override formatting of an existing Ruleengine datatype).

Therefore a custom Formatter should delegate function calls to the DefaultFormatter for normal (core) processing of input/output data, except in cases where the input/output data requires custom formatting (by inspecting the attribute members).

Using attribute members to determine custom formatting needs

A common way to determine if the input/output data needs custom formatting is by accessing members of the attribute object.

 

As an example, where Web Determinations needs to be able to process standardized angular movement formats (latitude and longitude), attributes can have a custom property with the key 'latlongformat' and value of 'longitude' or 'latitude'. Attribute custom properties are usually added by the rulebase author in Oracle Policy Modeling.

 

Note:  Longitude can only be East(E) or West(W) directions while Latitude can only be North(N) or South(S) - hence the need for different values in the 'latlongformat' property

 

In the custom Formatter plugin, the existence of the key in the attribute's properties can trigger the custom formatting, and the key's value determines whether the attribute should be parsed/formatted as a Longitude (which is degrees/minutes/seconds EorW) or Latitude (same as longitude but expects NorS). See the sample code below for code implementation of this design.

About the data and objects passed into the Formatter methods

Below are descriptions of the input data for the main methods.

parse(byte type, String value, Attribute attribute)
 getFormattedValue(byte type, Object value, Attribute attribute)
How to use the data passed into the Formatter methods

The sample code below demonstrate the following

 

The needsCustomFormat() method encapsulates logic that checks whether a parse/formatting request needs custom formatting, or simply needs the default core formatting. The sample below checks the properties of the Attribute object, by taking in the Attribute object, and the HaleyType byte data. It checks whether the attribute has a property with a certain key value to determine if the input/output data needs custom formatting.