BLOG CATEGORIES



Rational Publishing Engine: All about recursion

When we need to use data recursion?
Let’s suppose that we have a schema like in Figure 1. We want to extract the list of SRRequirements (Software requirements). For each SRRequirement we want to extract all children requirements, for each child requirement we want to extract all children requirements and so on. In other words, for each SRRequirement we want to extract all descendant requirements.

Data Source Schema

Figure 1: Data Source Schema

In this situation we would have the following queries:
[$1] -> Project/Requirements/SRRequirement – for extracting the SRRequirements

[$2] -> $1/Children/Relationship/Requierement – children requirements of each SRRequirement

[$3] -> $2/Children/Relationship/Requirement – children requirements of each child requirement of each SRRequirement

If we want to go one level deep, we would have another query constructed from the previous one and adding as a suffix another Children/Relationship/Requirement query segment.

Rational Publishing Engine provides a mechanism to do it automatically. We don’t need to construct all the queries. We need only one query. Project/Requirements/SRRequirement/Children/Relationship/Requierement. [$2]
Starting with this query and with the help of two additional properties that Rational Publishing Engine provides, we will be able to achieve the desired output result.

Properties View

Figure 2: Properties View

In Figure 2 we can see the properties of the element containing the[$2]  Project/Requirements/SRRequirement/Children/Relationship/Requierement query
We will use 2 properties:

  • Recursive Level – represents the depth of recursion for the query.
  • Recursive Segments – represents the number of repetitive segments from the query.

We set the recursion level as deep as we want. For this example, taking into account the existing information in the Data Source we choose to go 4 levels deep.
The Recursive Segments value is 3 in this case: the segments that are added to construct the recursive query are Children/Relationship/Requierement.

Note: Observe that the [$2] query has a parent context set .  If you want to have recursion on a specific query for the moment it’s mandatory to have that query in the context of a parent query.

When this report containing this template will run, the following queries will be executed:
[$1] – Project/Requirements/SRRequirement/Children/Relationship/Requierement
[$2] – $1/ Children/Relationship/Requierement
[$3] – $2/Children/Relationship/Requierement
[$4] – $3/Children/Relationship/Requierement

Related links on IBM DeveloperWorks forum:

2 Comments to “Rational Publishing Engine: All about recursion”

  1. mick driver says:

    Hi

    Followed the links and implemented recursion levels = 3, not sure if i understand the use of the segment yet. any example around?

    Mine seems to start output at a lower level nested pacakge?

    Mick

  2. Erica says:

    I followed the instructions and I successfully implemented the recursion. However, now I have this question:
    For my parent/child/children structure that actually goes to the 6th level deep, I would like to display the name hierarchy of the folders, not just the name of the specific folder.
    For example, if I see
    Folder A
    Sub folder 1
    SubSub folder i
    If I display the folder name, I want to display the name as so: Folder A/subfolder 1/ sub sub folder i and then the corresponding data within folder i.
    I tried using variable assignments, but with a recursion with so many folders, all I can get is all the folder names the recursion loop has seen, not the specific parent child link.

Leave a Reply

(required)

(required)