The estimated duration of this unit is about 1 hour.
Semarchy xDM allows you to create Enrichers to normalize, standardize, and enrich data loaded or authored in your application.
Several enrichers can be defined for an entity. They are executed in sequence.
You will learn how to define two types of enrichers:
SemQL Enrichers that define the rules using the SemQL language.
API enrichers that use Java to perform more complex data transformations or external API calls (for example, to look up information from a remote micro-service such as Google Maps).
In the next sections, you will be guided to:
Create a SemQL enricher to standardize first and last names.
Add a default value to the hire date if it is empty.
Create a complex type to store additional phone attributes.
Use a Plug-in enricher to standardize phone numbers and populate these attributes.
What you'll learn
Creating SemQL enrichers
Adding a Complex Type
Creating API enrichers
Add the StandardizeNames enricher
Let's use SemQL enrichers to perform basic data standardization on the employees' FirstName and LastName. The goal is to make sure that these attributes are always spelled with the first letter in upper case and the remaining letters in lower case.
Open your HRTutorial model in the Application Builder and navigate to Entities > Employee > Enrichers.
Right-click the Enrichers node and then select Add SemQL Enricher.
Set the Name to StandardizeNames and then click Next.
Select the FirstName and LastName attributes in the Available Attributes list, click Add to add them to the Used Attributes list, and then click Finish.
Enter the SemQL expression for each attribute in the Enricher Expressions section:
For the FirstName attribute: INITCAP(FirstName)
For the LastName attribute: INITCAP(LastName)
Save your work.
Add the DefaultHireDate enricher
You will now create another SemQL enricher to assign a default date to the HireDate attribute if no date was provided.
Navigate again to Entities > Employee > Enrichers.
Right-click the Enrichers node and select Add SemQL Enricher.
Set the Name to DefaultHireDate and click Next.
Add HireDate to the Used Attributes list and click Next.
To ensure that the enricher is triggered only if HireDate is not set, set the Filter to the following SemQL expression, and then click Finish: HireDate is null
Set the Expression of the HireDate attribute with the following expression in the Enricher Expressions section: CURRENT_DATE()
Save your work.
Add the StandardizePhone enricher
In this section, you will use the Phone Enricher Plug-in to standardize and enrich phone numbers. This plug-in exposes several outputs given a phone number and a country of origin.
Add the PhoneType Complex Type
You first need to create a Complex Type that will be populated by the phone enricher.
Right-click the Complex Types node in the Model Design View, and then select Add Complex Type.
Set the Name to PhoneType and click Finish.
Select the Definition Attributes finger tab and then click the Add Definition Attribute button.
Enter the following values and then click Finish:
Name: Country
Length: 2
Repeat the same steps to add all the following attributes:
Attribute
Datatype
Notes
Country
String(2)
ISO-3166-1 country code for this phone
EnrichedPhone
String(128)
Standardized phone number
LineType
String(128)
Type of line guessed by the plug-in
Carrier
String(128)
Name of the carrier when available
Location
String(128)
Name of the guessed location of the phone
Timezones
String(128)
Time zones for this phone
IsPossible
String(128)
Whether this phone is possible
IsValid
String(128)
Whether this phone is valid
Check the result and save your work.
Go back to the Details finger tab, click the Define... button, and then click the Define Display Name button.
Click Next in the first step of the wizard.
Add the EnrichedPhone attribute to the Selected Attributes list, and then click Finish.
Save your work.
Expand the Employee entity under Entities > Employee in the Model Design View, and then right-click Attributes and select Add Complex Attribute.
Enter the following values, and then click Finish.
Name: EnrichedPhone
Type: PhoneType [Complex Type]
Save your work.
Add the phone enricher
The Phone Enricher Plug-in accepts several inputs and produces several outputs such as the standardized phone or the geolocation of the phone line:
Navigate again to Entities > Employee in the Model Design View.
Expand the Employee entity, right-click Enrichers, and select Add API Enricher.
Enter the following values and then click Finish:
Select Java Plug-in.
Select the Semarchy Phone Enricher in the drop-down list.
Set the Name to StandardizePhone.
Scroll down to the Inputs section of the editor, and then click the Define Inputs button.
Select the Region Code, Input Phone Number and Enriched Phone Format inputs, click the Add button to add them to the Used Inputs list, and then click Finish.
Set the following expressions in the Expression column for each input listed in the Inputs section:
Region Code: COALESCE(EnrichedPhone.Country, 'US')
Input Phone Number: Phone
Enriched Phone Format: 'INTERNATIONAL'
Scroll down to the Outputs section and click the Define Outputs button:
Add the following attributes to the Attributes Used list, and then click Finish:
EnrichedPhone.Carrier
EnrichedPhone.EnrichedPhone
EnrichedPhone.IsPossible
EnrichedPhone.IsValid
EnrichedPhone.LineType
EnrichedPhone.Location
EnrichedPhone.Timezones
Select the following values in the Output Name column for each Attribute Name from the Outputs list:
Attribute Name
Output Name
EnrichedPhone.Carrier
Carrier Name
EnrichedPhone.EnrichedPhone
Enriched Phone Number
EnrichedPhone.IsPossible
Possible Phone Number
EnrichedPhone.IsValid
Valid Phone Number
EnrichedPhone.LineType
Phone Line Type
EnrichedPhone.Location
Geocoding Data
EnrichedPhone.Timezones
Time Zones
Check the enricher configuration in the Inputs and Outputs sections, and then save your work.
Congratulations
You have completed the first part of this tutorial by adding data standardization rules to your model.
What we've covered
Creating a SemQL enricher to standardize first and last names
Setting a default value to the hire date using another SemQL enricher
Creating a complex type to hold additional phone attributes
Using a Plug-in enricher to standardize phone numbers and populate those attributes.
The next step will focus on adding validation and match rules!
Semarchy xDM provides various types of data validation rules when authoring data. These rules act as a firewall to prevent bad data from being entered or imported in the data hub.
Some of the rules are implicit, such as mandatory attributes, lists of values, or referential integrity. Others can be set explicitly, such as SemQL validations, Plug-in validations, and match rules.
In this step, you will learn how to use SemQL to validate your data and ensure data consistency.
You will be guided to:
Create a SemQL validation rule to check that the hire date of an employee is before his contract end date.
Create a SemQL validation rule to make the email mandatory when the employee is a contractor.
Create a SemQL match rule to prevent the creation of duplicate employees.
What you'll learn
Creating SemQL validations
Creating match rules
Validate end dates
An employee's end date can either be null if the employee is still in the company, or it must be greater than the hire date.
Let's add a validation that applies this rule.
Go to Entities > Employee > Validations in the Model Design View of the Application Builder.
Right-click Validations and select Add SemQL Validation.
Fill in the wizard with the following values and then click Finish:
Name: CheckEndDate
Description: End date must be greater than the hire date
Condition: (EndDate is null) OR (EndDate > HireDate)
Save your work.
Validate emails
You will now add a rule that makes the email mandatory only if the employee is a contractor.
Navigate again to Entities > Employee > Validations in the Model Design View.
Right-click Validations, and then select Add SemQL Validation.
Fill in the wizard with the following values and click Finish:
Name: CheckContractorEmail
Description: Contractors must have an email address
Condition: (IsContractor = '1' and Email is not null) OR IsContractor = '0'
Save your work.
Prevent duplicates
It is a best practice to prevent users from creating duplicate records. Here, you will create a match rule that will be used to prevent the creation of an employee record if another employee with the exact same first and last name already exists within the same subsidiary.
Go to Entities > Employee > Matcher in the Model Design View.
Right-click Matcher and select Define SemQL Matcher.
Set the Description to Prevent duplicate employees and click Finish.
Click the Add Match Rule button in the Match Rules section of the SemQL Matcher Editor.
Set the Name of your match rule to MatchOnName.
Scroll down to the Matching section, and then click the Edit Expression button.
Add the following SemQL Condition and click OK:
Upper(Record1.FirstName) = Upper(Record2.FirstName)
and Upper(Record1.LastName) = Upper(Record2.LastName)
and Record1.Subsidiary = Record2.Subsidiary
Save your work.
Congratulations
You have successfully completed the second part of this tutorial by adding validation and match rules to your model.
What we've covered
You created a SemQL validation to check that the hire date is before the end date.
You created another SemQL validation to set email as mandatory when the employee is a contractor.
You created a SemQL match rule to prevent the creation of duplicate employees.
The next part will focus on wiring enrichers and validation rules in the user interface and deploying a new version of your application.
Semarchy xDM gives you the flexibility to control exactly which rules should apply when users are authoring data using a Stepper.
Enrichers can be triggered on data changes or when entering or exiting a step.
Validations can be triggered while users are entering data in forms, or when data is submitted to your application.
In the next sections, you will learn how to make the enrichers and validation rules effective in the user-facing application. You will be guided to:
Modify the EmployeeForm to add the missing phone enricher attributes.
Modify the AuthorEmployee stepper to activate the rules.
Deploy your changes.
Modify the EmployeeForm
You will now modify the EmployeeForm to add the enriched phone attributes and reorganize the form fields.
In the Application Builder, navigate to Entity > Employee > Form, and then double-click EmployeeForm.
Select the Phone attribute in the form's tree view, and then use the Move Up button to move this attribute between LastName and Salutation.
Expand the EnrichedPhone attribute in the Attributes list, and then select all attributes it is composed of (hold the shift key + select the first and last attribute):
Drag and drop the selected attributes to the Form's tree view between Phone and Salutation:
Enter the following values in the Label column these new attributes:
EnrichedPhone_Country: Phone Country
EnrichedPhone_EnrichedPhone: Enriched Phone
EnrichedPhone_LineType: Line Type
EnrichedPhone_Carrier: Carrier
EnrichedPhone_Location: Location
EnrichedPhone_Timezones: Time Zones
EnrichedPhone_IsPossible: Possible?
EnrichedPhone_IsValid: Valid?
Select the FDN_Department attribute and use the Move Up button to move it between Title and HireDate (alternatively, drag and drop the attribute at the expected position).
Make the EnrichedPhone_EnrichedPhone attribute read-only:
Select the EnrichedPhone_EnrichedPhone attribute.
Select the General finger tab in the Properties view.
Select Read-Only.
Repeat the same procedure to make the following attributes read-only:
EnrichedPhone_EnrichedPhone
EnrichedPhone_LineType
EnrichedPhone_Carrier
EnrichedPhone_Location
EnrichedPhone_Timezones
EnrichedPhone_IsPossible
EnrichedPhone_IsValid
Save your work.
Modify the AuthorEmployee stepper
Before you deploy your changes, you need to modify the AuthorEmployee stepper to enable the validations and enrichers that you defined in the previous steps.
Go to Entities > Employee > Steppers in the Model Design View, and then double-click AuthorEmployees.
Configure the validations to perform on stepper finish:
Scroll down to the Validations section of the editor.
Select the first row of the table (DETECT_DUPS) and then select Warn in the On Stepper Finish column.
Select all the other rows: hold the shift key, select the CheckContractorEmail row, and then select the last row of the table. Right-click the selection and then select Block. This makes all the selected validations blocking the completion of the employee stepper.
Scroll up to the Steps section and select the second step: Employee.
In the Properties view, open the Step Transition Validations finger tab, select the first row of the table (DETECT_DUPS), and then select Warn in the On Step Exit column.
Make all other validations blocking for steps transitions:
Select all rows starting from the second one (CheckContractorEmail).
Right-click this selection and then select Block.
Configure all validations on data change:
Select the Form Validations finger tab.
Select all rows in the table.
Right-click the selection and select On Data Change.
Configure validations on form open:
Select the following rows (hold the Ctrl key + select): CheckContractorEmail, CheckEndDate, Department|MANDATORY, FirstName, HireDate, LastName and Subsidiary|MANDATORY.
Right-click this selection.
Select On Form Open.
Set up the execution of enrichers:
Select the Form Enrichers finger tab.
Select On Data Change for StandardizeNames and StandardizePhone.
Select On Form Open for DefaultHireDate.
Save your work.
Deploy the model changes
You are now ready to deploy your changes, have a first glance at the employee creation form, and see the impact of your changes.
In the Application Builder, right-click on the root node in the Model Design View, corresponding to the HRTutorial [0.0] model, and then select Validate. The validation report should raise no error.
Go to the Management perspective of the Application Builder.
Right-click on your data location EmployeeTutorial and select Deploy Model Edition.
Click Finish in the wizard to deploy your model changes.
Congratulations
You have successfully completed the third part of this tutorial by plugging in the validations and enrichers and deploying the changes to your application.
What we've covered
You modified the Employee form to add missing attributes.
You modified the AuthorEmployee stepper to activate rules.
You deployed your changes.
The next part will showcase all your rules in action in your application.
In this step of the tutorial, you will try several combinations for creating employees to see your enrichers and validations in action in the user-facing interface.
Enrichers in action
In the first step of this tutorial, you created 3 enrichers to standardize names, enrich phone information, and set the default hire date. Let's see them in action:
Open your application from the Welcome Page.
Select Employees in the Navigation Drawer, open the actions menu, and then select Create.
Set the First Name to jack and the Last Name to BOLT-HarriSson. Notice how the StandardizeNames enricher re-formats values automatically.
Set the Phone to 0478963556 and the Country to FR. Notice the outputs of the phone enricher:
Scroll down to see that the Hire Date field was automatically set to the current date.
Discard your changes: click again on Employees in the Navigation Drawer, and then click DISCARD ALL on the popup that appears.
Validations in action
In the first part of this tutorial, you added 2 validations on top of the built-in validations and enabled them in the AuthorEmployee stepper. Let's see them in action.
Select Employees in the Navigation Drawer of your application, and then select Create from the actions menu.
Set the First Name to Jack and the Last Name to Bolt, and then click FINISH.
Two validation issues are raised. Click CANCEL.
Fill in the following fields:
Subsidiary: ACME EU
Title: Senior Consultant
Department: Consulting
Set End Date to a date before the hire date. Notice the error message.
Select Is Contractor. Notice the error message due to a missing email address.