Samples Tutorial

     Previous  Next    Open TOC in new window    View as PDF - New Window  Get Adobe Reader - New Window
Content starts here

Creating an XQuery Function Library

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:

 


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:

Instructions

  1. Create a new folder in the DataServices project and name it xfl.
  2. Import protectSSN.java in the xfl folder. The file is located in:
  3. samples\liquiddata\EvalGuide
  4. Build the DataServices project.
  5. Import source metadata into the xfl folder by completing the following steps:
    1. Right-click the xfl folder and choose Import Source Metadata.
    2. Select Java Function from the Data Source Type drop-down list and click Next.
    3. Browse and select DataServices\xfl.protectSSN in the Class Name field and click Next.
    4. Figure 35-1 Selecting the Java File


      Selecting the Java File

    5. Select the protectSSN function, and then click Add.
    6. Figure 35-2 Selecting the Java Function


      Selecting the Java Function

    7. Accept the default settings in the Select Side Effect Procedures window and click Next.
    8. Click Next. The Summary window opens.
    9. Figure 35-3 imported Java Metadata Summary


      imported Java Metadata Summary

    10. Click Finish.
  6. Test the function, by completing the following steps:
    1. Open library.xfl in Test View.
    2. Select protectSSN from the Function drop-down list.
    3. Insert any number in the Parameter field; for example, 3.
    4. Click Execute. The test should return 999-99-9999, regardless of the input parameter.
    5. Figure 35-4 XQuery Function Library Test


      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:

Instructions

  1. Build the DataServices project.
  2. In the ALDSP-console, navigate to:
  3. DataServices\CustomerManagement\CustomerProfile
  4. Click Admin and then Security.
  5. Click the Access Policy icon for getCustomerProfile().
  6. Remove the users Bob and Joe from the Policy Statement list.
  7. Test the getCustomerProfile() function without the protectSSN function by completing the following steps:
    1. Open CustomerProfile.ds in Test View.
    2. Select getCustomerProfile() from the function drop-down list.
    3. Enter CUSTOMER3 in the Parameter field.
    4. Confirm that the query returns a valid SSN.
  8. Set SSN protection, by completing the following steps:
    1. Open CustomerProfile.ds in Source View.
    2. Expand the getAllCustomers node.
    3. Locate the SSN return code within the getAllCustomers() function. It should be as follows:
    4. <ssn?>{fn:data($CUSTOMER/SSN)}</ssn>
    5. In Data Services Palette, expand the xfl and library.xfl folders.
    6. Drag and drop protectSSN() to the SSN return value.
    7. Modify the remaining code, so that it is as follows:
    8. {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.
  9. Test the getCustomerProfile() function with the protectSSN function, by completing the following steps:
    1. Open CustomerProfile.ds in Test View.
    2. Select getCustomerProfile() from the function drop-down list.
    3. Enter CUSTOMER3 in the parameter field. The query should return an invalid social security number.
    4. Figure 35-5 Test View of Protected SSN


      Test View of Protected SSN

 


Lesson Summary

In this lesson, you learned how to:


  Back to Top       Previous  Next