Samples > Rule Team Server Business Rule Management Extensions > How to Use Rule Team Server APIs to Report Differences Between Baselines

This sample shows how to use Rule Team Server APIs to report differences between two baselines.

Key Features

Key features in the sample include:

Installing this Sample

To install this sample through the Samples Console:

  1. In the Samples Console locate the teamserver/serverbaselinesdiff sample.
  2. Check that the Samples Server is started. For information on how to start and stop the Samples Server, see Stopping and Restarting the Samples Server from the Samples Console.
  3. Execute the build command to compile the sample.
  4. Wait until you see the BUILD SUCCESSFUL message.

Running this Sample

This sample can only be opened and run in the Samples Console.

Create the DiffProjectTest Project

You need to create a project called DiffProjectTest with some artifacts, and create a baseline named V1.

To create the DiffProjectTest project, execute the create-project command from the Samples Console.

You should see the following information in the console output:

create-project:
[echo] Running...
[java] Create the projet and elements in the project, and then create a baseline...
[java] referenceUser=rtsAdmin
[java] referencePassword=********
[java] referenceUrl=jnp://localhost:1099
[java] referenceDatasource=jdbc/ilogDataSource
[java] referenceProjectName=DiffProjectTest
[java] baseline=V1
[java] Baseline 'V1' successfully created.

This command creates:

Modify the Current Baseline of DiffProjectTest

To modify the current baseline of DiffProjectTest:

  1. From the Samples Console, execute the modify-project command.
  2. You should see the following information in the console output:
modify-project:
[echo] Running...
[java] Modify artifacts in a project ...
[java] referenceUser=rtsAdmin
[java] referencePassword=********
[java] referenceUrl=jnp://localhost:1099
[java] referenceDatasource=jdbc/ilogDataSource
[java] referenceProjectName=DiffProjectTest
[java] baseline=.
[java] Create brm.ActionRule:myrule2
[java] ...
[java] ...
[java] ...
[java] Baseline '.' successfully modified.
The current project baseline is modified by creating, modifying, and deleting elements in the project.
  1. Connect to Rule Team Server using the following URL: http://localhost:8080/teamserver.
  2. Sign in using the following details:
  3. Username: rtsAdmin
    Password: rtsAdmin
  4. On the Home page, select DiffProjectTest as the Project in use.
  5. On the Home page, click Change next to Consult a baseline.
  6. Display the Change Baseline drop-down list to confirm that the V1 baseline has been created.
  7. Click Cancel to close the page.
  8. Click the Explore tab.
  9. You will see that five project elements are displayed.
  10. Select the new name rule, and then click History.
  11. Two versions of the rule are displayed. Version 1.0 is used by the V1 baseline, and version 1.1 is the current version.
  12. Select the two check boxes: version 1.1 and version 1.0.
  13. Click Compare 2 Versions.
  14. The differences between versions 1.0 and 1.1 are displayed. You can see that some properties have changed.
  15. Click Content to see the differences in rule content between the two versions.
  16. Sign out of Rule Team Server.
Report Differences Between the Two Baselines

Instead of visiting project elements one by one, you will obtain a global view of differences between the two baselines.

To report on the differences between the two baselines:

  1. Execute the print-differences command in the Samples Console.
  2. You should see the following in the console output:
Executing print-differences
Running...
Difference between 2 RTS baselines
referenceUser=rtsAdmin
referencePassword=********
referenceUrl=jnp://localhost:1099
referenceDatasource=jdbc/ilogDataSource
referenceProjectName=DiffProjectTest
referenceBaseline=.
otherUser=rtsAdmin
otherPassword=********
otherUrl=jnp://localhost:1099
otherDatasource=jdbc/ilogDataSource
otherProjectName=DiffProjectTest
otherBaseline=V1
R E P O R T : Wed Apr 04 16:18:16 CEST 2007
Baseline reference (1) Project : DiffProjectTest Baseline : . Url : jnp://localhost:1099 
Datasource : jdbc/ilogDataSource
Baseline other (2) Project : DiffProjectTest Baseline : V1 Url : jnp://localhost:1099 
Datasource : jdbc/ilogDataSource
Create brm.ActionRule:myrule2
Create brm.DecisionTable:mydt2
Create brm.Function:myfunc2
Create brm.Query:findRule2
Create brm.TechnicalRule:mytechrule2
Create brm.Template:mytemplate2
Create brm.VariableSet:myvariables2
Delete brm.ActionRule:myrule1
Delete brm.DecisionTable:mydt1
Delete brm.Function:myfunc1
Delete brm.Query:findRule1
Delete brm.TechnicalRule:mytechrule1
Delete brm.Template:mytemplate1
Delete brm.VariableSet:myvariables1
Update brm.ActionRule:new name[definition[].body,documentation,group,lastChangedOn,name,tags[a tag]-,tags[new tag]+]
Update brm.DecisionTable:mydt[definition[].body,lastChangedOn]
Update brm.Function:myfunc[arguments[arg0].argumentType,arguments[arg0].name,arguments[arg1]+,lastChangedOn,returnType]
Update brm.Query:findRule[definition,lastChangedOn]
Update brm.TechnicalRule:new technical name[definition[].body,documentation,group,lastChangedOn,name,tags[a tag]-,tags[new tag]+]
Update brm.Template:mytemplate[definition,lastChangedOn]
Update brm.VariableSet:myvariables[lastChangedOn,variables[v1].bomType,variables[v1].verbalization,variables[v2]+]
Finished print-differences

The arguments for this command define two baselines: a first baseline qualified as reference, and a second baseline qualified as other. When running this command, the sample connects to the two baselines and navigates through all the reference baseline project artifacts, as follows:

The report displays the attributes of the compared baselines (project, baseline name, server URL and datasource) and shows the differences between the two baselines. The report is formatted as follows:

Report Heading 
Description 
Create brm.ActionRule:myrule2
This means that an action rule myrule2 has been created 
Delete brm.ActionRule:myrule1
This means that an action rule myrule1 has been deleted. 
Update brm.ActionRule:new 
name[definition[].body,documentation,gro
up,lastChangedOn,name,tags[a tag]-
,tags[new tag]+] 
This means that an action rule new name has been updated. The attributes that have been modified are:  

Source Files

This sample is located in <InstallDir>/teamserver/samples/serverbaselinesdiff. It contains the following files:

Class 
Description 
Argument
Arguments of the print-difference target 
Connection
An abstract representation of a connection to Rule Team Server 
DefaultProcessorImpl
A default report processor 
DifferenceBaseline
The main entry point to run the difference computation 
JBOSS40Connection
A connection to Rule Team Server installed on a JBoss server 
ActionRuleFactory
A factory to manage ActionRule artifacts 
Argument
Arguments of the create-baseline target 
BaselineFactory
A factory to manage Baseline artifacts 
CreateBaseline
The main entry point to create projects, artifacts, and the baseline 
ModifyBaseline
The main entry point to modify project artifacts 
DecisionTableFactory
A factory to manage decision table artifacts 
Factory
An abstract representation of an artifact factory 
FunctionFactory
A factory to manage function artifacts 
ModelFactory
A factory manager (groups all others factories) 
ProjectFactory
A factory to manage project artifacts 
QueryFactory
A factory to manage query artifacts 
TechnicalRuleFactory
A factory to manage technical rule artifacts 
TemplateFactory
A factory to manage template artifacts 
VariableSetFactory
A factory to manage VariableSet artifacts 
DiffHelper
A helper class that computes differences between artifacts 
RTSHelper
A Rule Team Server API wrapper 
Utilities
A utility class to handle string processing and I/O 
Baseline
Represents a target baseline 
DifferenceBaseLineReport
Represents a Difference report  
CreateEvent
Represents a Creation event  
DeleteEvent
Represents a Delete event  
Event
An abstract representation of an event 
EventProcessor
Represents an abstract event processor 
UpdateEvent
Represents an Update event 

Highlights

The highlights of this example include the following.

Class Arguments

Running this sample is carried out in three steps. In the first step it creates a project called DiffProjectTest, some artifacts, and a baseline named V1. The second step modifies elements in the project, and the last step prints the differences between the baseline and the current state of the project.

The main class executing the first step is baselinesdiff.factory.CreateBaseline. It takes the following arguments:

The main class executing the second step is baselinesdiff.factory.ModifyBaseline. It takes the following arguments:

In the third step, the sample reports differences between the current state of the project and the V1 baseline. The main class executing these actions is baselinesdiff.DifferenceBaseline. It takes the following arguments

Customizing the Sample

We provide a simple report processor. To customize this sample you can modify the -processor argument by setting a fully qualified class name implementing the baselinesdiff.model.event.EventProcessor interface.

Creating, Modifying, and Deleting Artifacts

Each of the following factory classes contains a createARTIFACT_TYPE, a modifyARTIFACT_TYPE, and a deleteARTIFACT_TYPE method to manage creating, modifying, and deleting artifacts:

Factory Class 
Description 
ActionRuleFactory
Manage ActionRule artifacts  
BaselineFactory
Manage Baseline artifacts 
DecisionTableFactory
Manage DecisionTable artifacts 
FunctionFactory
Manage Function artifacts 
ProjectFactory
Manage Project artifacts 
QueryFactory
Manage Query artifacts 
TechnicalRuleFactory
Manage TechnicalRule artifacts 
TemplateFactory
Manage Template artifacts 
VariableSetFactory
Manage VariableSet artifacts 

Retrieving Artifacts from Projects

See the method RTSHelper.getProjectElements (IlrSession session, IlrRuleProject project, int scope).

Getting Differences Between Baselines

See the method DiffHelper.DifferenceBaseLineReport getDifferences (Baseline reference, Baseline other).

Reporting the Baseline Differences

See the method DefaultProcessorImpl.process (DifferenceBaseLineReport report).

Rebuilding this Sample

To rebuild this example to restore it to its original state, in the Samples Console execute the build command to compile the code.

Related Tasks

Using the Rule Team Server API

Related Samples and Tutorials

How to Create and Populate Decision Tables in Rule Team Server
How to Execute a Query