Red Hat Training

A Red Hat training course is available for Red Hat Decision Manager

Chapter 2. Data objects

Data objects are the building blocks for the rule assets that you create. Data objects are custom data types implemented as Java objects in specified packages of your project. For example, you might create a Person object with data fields Name, Address, and DateOfBirth to specify personal details for loan application rules. These custom data types determine what data your assets and your decision services are based on.

The following tables show the Violation and Driver data objects that you will create in this tutorial.

Table 2.1. Violation data object

IDLabelType

code

Code

String

points

Points

Integer

violationDate

Violation Date

Date

type

Type

String

fineAmount

Fine Amount

Double

speedLimit

Speed Limit

Integer

actualSpeed

Actual Speed

Integer

Table 2.2. Driver data object

IDLabelType

name

Name

String

age

Age

Integer

state

State

String

city

City

String

violations

Violations

Violation (org.jboss.example.traffic_violations.Violation) Note: The violations field is set to "List" to hold multiple items for the given type.

fineAmount

Fine Amount

Double

totalPoints

Total Points

Integer

reason

Reason

String

2.1. Creating the Violation data object

The Violation data object contains data fields based on violation details, such as Violation Date, Fine Amount, and Speed Limit.

Prerequisites

You have created the Driver_department_traffic_violations project.

Procedure

  1. Click Add AssetData Object.
  2. In the Create new Data Object wizard, enter the following values:

    • Data Object: Violation
    • Package: select com.myspace.driver_department_traffic_violations
  3. Click Ok.

    Figure 2.1. Create new Data Object window

    data object

2.1.1. Adding the Violation data object constraints

Populate the Violation data object fields with the constraints that you will select when you define your rules.

Prerequisites

You have created the Violation data object.

Procedure

  1. In the 'Violation'-general properties section, enter Violation in the Label field.

    Figure 2.2. General properties

    gen props
  2. Click + add field.
  3. Enter the following values:

    • Id: code
    • Label: Code
    • Type: String
  4. Click Create and continue, then enter the following values:

    • Id: points
    • Label: Points
    • Type: Integer
  5. Click Create and continue, then enter the following values:

    • Id: violationDate
    • Label: Violation Date
    • Type: Date
  6. Click Create and continue, then enter the following values:

    • Id: type
    • Label: Type
    • Type: String
  7. Click Create and continue, then enter the following values:

    • Id: fineAmount
    • Label: Fine Amount
    • Type: Double
  8. Click Create and continue, then enter the following values:

    • Id: speedLimit
    • Label: Speed Limit
    • Type: Integer
  9. Click Create and continue, then enter the following values:

    • Id: actualSpeed
    • Label: Actual Speed
    • Type: Integer
  10. Click Create.
  11. Click Save, and then click Save to confirm your changes.
  12. Click the Driver_department_traffic_violations label to return to the Assets view of the project.

    Figure 2.3. Violation data object fields

    violation data fields

2.2. Creating the Driver data object

The Driver data object contains data fields based on driver details, such as Name, Age, and Total Points.

Prerequisites

You have created the Driver_department_traffic_violations project.

Procedure

  1. Click Add AssetData Object.
  2. In the Create new Data Object wizard, enter the following values:

    • Data Object: Driver
    • Package: select com.myspace.driver_department_traffic_violations
  3. Click Ok.

    Figure 2.4. Create new Data Object window

    data object2

2.2.1. Adding the Driver data object constraints

Populate the Driver data object fields with the constraints that you will select when you define your rules.

Prerequisites

You have created the Driver data object.

Procedure

  1. In the 'Driver'-general properties section, enter Driver in the Label field.
  2. Click + add field.
  3. Enter the following values:

    • Id: name
    • Label: Full Name
    • Type: String
  4. Click Create and continue, then enter the following values:

    • Id: age
    • Label: Age
    • Type: Integer
  5. Click Create and continue, then enter the following values:

    • Id: state
    • Label: State
    • Type: String
  6. Click Create and continue, then enter the following values:

    • Id: city
    • Label: City
    • Type: String
  7. Click Create and continue, then enter the following values:

    • Id: violations
    • Label: Violations
    • Type: Violation(com.myspace.driver_department_traffic_violations.Violation)
    • List: Select this check box to enable the field to hold multiple items for the specified type.
  8. Click Create and continue, then enter the following values:

    • Id: fineAmount
    • Label: Fine Amount
    • Type: Double
  9. Click Create and continue, then enter the following values:

    • Id: totalPoints
    • Label: Total Points
    • Type: Integer
  10. Click Create and continue, then enter the following values:

    • Id: reason
    • Label: Reason
    • Type: String
  11. Click Create.
  12. Click Save, and then click Save to confirm your changes.
  13. Click the Driver_department_traffic_violations label to return to the Assets view of the project.

    Figure 2.5. Driver data object fields

    driver data fields