Book a Demo

Author Topic: Check if two elements are connected indirectly  (Read 4421 times)

jepessen

  • EA User
  • **
  • Posts: 106
  • Karma: +1/-1
    • View Profile
Check if two elements are connected indirectly
« on: November 15, 2020, 02:49:49 am »
Hi.

Let's suppose to have this diagram:



In order to accept the testcase, the requirement 6809 must be satisfied.

I'm writing a script that creates a test-case document, that list every test case and, for ever test case, it shows a list of all requirements that must be satisfied in order to solve it.

I would like to have something like:

Quote
Test case feature_TestCase2 depends on following requirements:
  • #6803 Create 2D polygon
  • #6809 2D polygon style

In order to do it, I need to retrieve the list of test cases, that I do with following jscript code:

Code: [Select]
function createTestCaseList(generator, requirements)
{
var query = "SELECT * FROM ea_map.t_object where Stereotype = 'testcase';";
var result = Repository.SQLQuery(query);
var xmlDoc = new ActiveXObject("MSXML2.DOMDocument.6.0");
xmlDoc.async = false;
xmlDoc.loadXML(result);
var nodes = xmlDoc.getElementsByTagName("Object_ID");
for (var j=0; j < nodes.length; j++) {
if (nodes.item(j).text != "") {
var testcase = Repository.GetElementByID(nodes.item(j).text);
if (testcase != null) {
//Here I've the test case
}
}
}
}

At this point, I need to retrieve the list of requirements associated to the test case. I can query the t_connector table I suppose, but with a direct query I can find only requirements that are directly connected to it, in the image only the #6803 one... I can try to find it recursively but I'm worried to go into a loop in some cases.

How can I check all requirements connected directly and indirectly to the test case?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Check if two elements are connected indirectly
« Reply #1 on: November 15, 2020, 04:23:07 am »
You can do two things:

1. Make a query that joins a t_object and t_connector a number of times to select all direct and indirect requirements. If you know you have maximum 5 levels, you could make your query to get 7 levels to make sure.

2. Query each "level" in a recursive way. You'll have to remember (in a dictionary or something) which requirements you already did to avoid endless loops. I do something similar when getting the packageTreeIDstring (except for the check to avoid endless loops)

Code: [Select]
'get the package id string of the given package tree
function getPackageTreeIDString(package)
dim allPackageTreeIDs
set allPackageTreeIDs = CreateObject("System.Collections.ArrayList")
dim parentPackageIDs
set parentPackageIDs = CreateObject("System.Collections.ArrayList")
if not package is nothing then
parentPackageIDs.Add package.PackageID
end if
'get the actual package ids
getPackageTreeIDsFast allPackageTreeIDs, parentPackageIDs
'return
getPackageTreeIDString = Join(allPackageTreeIDs.ToArray,",")
end function

function getPackageTreeIDsFast(allPackageTreeIDs, parentPackageIDs)
if parentPackageIDs.Count = 0 then
if allPackageTreeIDs.Count = 0 then
'make sure there is at least a 0 in the allPackageTreeIDs
allPackageTreeIDs.Add "0"
end if
'then exit
exit function
end if
'add the parent package ids
allPackageTreeIDs.AddRange(parentPackageIDs)
'get the child package IDs
dim sqlGetPackageIDs
sqlGetPackageIDs = "select p.Package_ID from t_package p where p.Parent_ID in (" & Join(parentPackageIDs.ToArray, ",") & ")"
dim queryResult
set queryResult = getVerticalArrayListFromQuery(sqlGetPackageIDs)
if queryResult.Count > 0 then
dim childPackageIDs
set childPackageIDs = queryResult(0)
'call recursive function with child package id's
getPackageTreeIDsFast allPackageTreeIDs, childPackageIDs
end if
end function

Geert

jepessen

  • EA User
  • **
  • Posts: 106
  • Karma: +1/-1
    • View Profile
Re: Check if two elements are connected indirectly
« Reply #2 on: November 15, 2020, 05:56:49 am »
Thanks, I'll check this solution and I'll see if I can solve it. The second way seems more suitable for my needs.