Defining Relationships in WSO2 GREG using RXT

Reading time ~3 minutes

WSO2 GREG uses RXT files to describe the data model of an artifact. There are mainly two steps in creating an artifact using RXT files.

  1. Creating the RXT file. You can find details about the syntax used in RXT files in here.
  2. Deploying created RXT file in GREG. This is described in detail in here.

Relationship Model

Following is an explanation about the relationship model used in the GREG’s RXT files. In RXT files, we use the “relationships element” (more details here) to define relationships between two artificats. You can find several RXT examples inside

1
$GREG_HOME/samples/asset- models
directory. Following is an extract from the sample file
1
$GREG_HOME/samples/asset-models/TestPlanModel/registry-extensions/TestSuite.rxt
.

1
2
3
4
<relationships>
  <association type="usedBy" source="@{testCases_entry:value}"/>
  <dependency type="depends" target="@{testCases_entry:value}"/>
</relationships>

Here in line 2, we have added a “usedBy” association in the TestCase artifact to the TestSuite artifact using the association element. Note that we have used source attribute to indicate that the relationship is from “TestCase” to “TestSuite”. In the line 3 we have added a dependency in the TestSuite on “TestCase”. Note that we have used the “target” attribute to indicate that the relationship is from “TestSuite” to “TestCase”. The relationships element only indicate the type of relationship. To make it relate to one or many, we can use different type of fields. You can find a description about available field types from here.

If we look at the same sample file we took earlier we can see that a “TestSuite” artifact have an association with many “TestCase” artifacts. The relevant RXT code is mentioned below.

1
2
3
4
5
6
7
8
9
10
11
12
<table name="TestCases">
  <subheading>
    <heading>Type</heading>
    <heading>Path</heading>
  </subheading>
  <field type="option-text" maxoccurs="unbounded" path="true">
    <name>Case</name>
    <values>
      <value>Test Case</value>
    </values>
  </field>
</table>

In line 6 we have defined the field type as “option-text” with attribute “maxoccurs” set to “unbounded”. Therefore we can add many TestCases for a Testsuite. If we have used a field of type text field then a TestSuite can have only one TestCase.

Similarly you can use different combination of the “relationships” elements and field elements to create different relationship patterns.

Examples

Some Examples are listed below, I am taking “Project group” and “Person” as artifcats for following examples. I have only shown the relevant parts of the RXT file. You have to add all other required elements to make it a valid RXT file.

One-to-one

<!-- In Person RXT definition -->
<relationships>
    <association type="groupOwnerOf" source="@{overview_group}"/>
    <association type="own" target="@{overview_group}"/>
</relationships>

<content>
    <table name="Overview">
        <field type="text" required="true" path="true">
            <name>Group</name>
        </field>
    </table>
</content>

Many-to-many

<!-- In Person RXT definition -->
<relationships>
    <association type="member" source="@{membership_entry:value}"/>
    <association type="memberOf" target="@{membership_entry:value}"/>
</relationships>

<content>
    <table name="Membership">
        <subheading>
            <heading>Type</heading>
            <heading>Path</heading>
        </subheading>
        <field type="option-text" maxoccurs="unbounded" path="true">
            <name>Member</name>
            <values>
                <value>Junior</value>
                <value>Senior</value>
            </values>
        </field>
    </table>
</content>

One-to-many

<!-- In ProjectGroup RXT -->
<relationships>
    <association type="member" target="@{members_entry:value}"/>
</relationships>

<content>
    <table name="Members">
        <subheading>
            <heading>Type</heading>
            <heading>Path</heading>
        </subheading>
        <field type="option-text" maxoccurs="unbounded" path="true">
            <name>Member</name>
            <values>
                <value>Junior</value>
                <value>Senior</value>
            </values>
        </field>
    </table>
</content>

Online Pomodoro Timer

An Online Pomodoro Timer you can use to practice Pomodoro Technique Continue reading

Purging Git Branches

Published on October 12, 2015

Running Clustered Integration Tests in WSO2 MB

Published on October 05, 2015