In any ALDSP project you can create XQuery libraries containing functions which can be used by any data service in your application. An XQuery function library is ideal for containing transformation and other types of functions without the overhead of having to build a data service. An XQuery function library can also be used to hold security functions which, in turn, can be used by any data service.
Objectives
After completing this lesson, you will be able to:
Create and use XFL functions.
View the results.
Overview
An XQuery Function Library (XFL) contains user functions that return discrete values, such as string, integer, or calendar. These functions are useful for data manipulation at query execution time.
35.1 Creating an XQuery Function Library
In this lesson, you will "encrypt" a customer's SSN to hide its value. As part of this process you will be modifying the getCustomerProfile() query function.
Objectives
In this exercise, you will:
Import a Java file into the DataServices project.
Import source metadata.
Test the function
Instructions
Create a new folder in the DataServices project and name it xfl.
Import protectSSN.java in the xfl folder. The file is located in:
samples\liquiddata\EvalGuide
Build the DataServices project.
Import source metadata into the xfl folder by completing the following steps:
Right-click the xfl folder and choose Import Source Metadata.
Select Java Function from the Data Source Type drop-down list and click Next.
Browse and select DataServices\xfl.protectSSN in the Class Name field and click Next.
Figure 35-1 Selecting the Java File
Select the protectSSN function, and then click Add.
Figure 35-2 Selecting the Java Function
Accept the default settings in the Select Side Effect Procedures window and click Next.
Click Next. The Summary window opens.
Figure 35-3 imported Java Metadata Summary
Click Finish.
Test the function, by completing the following steps:
Open library.xfl in Test View.
Select protectSSN from the Function drop-down list.
Insert any number in the Parameter field; for example, 3.
Click Execute. The test should return 999-99-9999, regardless of the input parameter.
Figure 35-4 XQuery Function Library Test
35.2 Using the XQuery Function Library in an XQuery
Adding an XQuery Function Library file to an XQuery.
Objectives
In this exercise, you will:
Add the protectSSN.xfl file to an XQuery.
Test the query.
View the results.
Instructions
Build the DataServices project.
In the ALDSP-console, navigate to:
DataServices\CustomerManagement\CustomerProfile
Click Admin and then Security.
Click the Access Policy icon for getCustomerProfile().
Remove the users Bob and Joe from the Policy Statement list.
Test the getCustomerProfile() function without the protectSSN function by completing the following steps:
Open CustomerProfile.ds in Test View.
Select getCustomerProfile() from the function drop-down list.
Enter CUSTOMER3 in the Parameter field.
Confirm that the query returns a valid SSN.
Set SSN protection, by completing the following steps:
Open CustomerProfile.ds in Source View.
Expand the getAllCustomers node.
Locate the SSN return code within the getAllCustomers() function. It should be as follows:
<ssn?>{fn:data($CUSTOMER/SSN)}</ssn>
In Data Services Palette, expand the xfl and library.xfl folders.
Drag and drop protectSSN() to the SSN return value.
Modify the remaining code, so that it is as follows:
{ssn?{ns9:protectSSN($CUSTOMER/SSN)}</ssn>)}
Note:
<a></a> is the renamed element. You can use any name for the element, but for the sake of clarity, we used the simple <a></a> name.
Test the getCustomerProfile() function with the protectSSN function, by completing the following steps:
Open CustomerProfile.ds in Test View.
Select getCustomerProfile() from the function drop-down list.
Enter CUSTOMER3 in the parameter field. The query should return an invalid social security number.