DXL : Comparing attributes of objects across modules

38 views Asked by At

I am currently working with DOORS and require assistance in comparing attributes of objects between two modules using DXL.

The objective is to compare attributes of objects across two modules. Each object possesses a unique identifier attribute, referred to as "ID". In the first module, this attribute is named "IE ID", while in the second module, it is labeled as "Req Id". Those attributes aids in identifying corresponding objects across modules. Once matching objects are identified based on this identifier, the goal is to compare other attributes of these objects to detect any disparities.

Although I have already developed some DXL code for this purpose, I am encountering challenges in efficiently comparing attributes and detecting differences between corresponding objects.

I require assistance in refining my DXL code to accurately compare attributes of objects across modules and efficiently identify any discrepancies.

Thank you for your assistance!

I tried this code :

Module m1 = current
Module m2 = edit("/Firts project/System/Module Verification")

Object obj1
Object obj2
string ID1
string ID2

ID1 = obj1."IE ID" ""

obj2 = obj1 in m2

if (obj2 != null) {
 
    ID2 = obj2."Req Id" ""

    if (ID1 == ID2) {
      
        for attr in obj1 do {
            
            if (attr != "IE ID") {
                string att1 = attr ""
                string att2 = obj2.(attr) ""

                if (att1 != att2) {
                    print "Différence détectée pour l'objet " obj1."Absolute Number" " :"
                    print "  Attribut : " attr
                    print "  Module 1 : " att1
                    print "  Module 2 : " att2
                }
            }
        }
    }
} else {
  
    print "Objet non trouvé dans le deuxième module pour l'objet " obj1."Absolute Number"
}

But it shows me a lot of error messages

2

There are 2 answers

1
Mike On BEST ANSWER

Edit: Update in the code snippets after the discussion in the other answers

If the general loop shall be:

  1. iterate over all objects in m1, setting o1 to the current object
  2. Now iterate over all objects in m2 until you find the object o2 with the correct ID
  3. now iterate over each attribute definition (defined in m1 or in m2) and compare the values.

Then the code for step 1 is

//here step 1
for obj1 in entire m1 do{
   ID1 = obj1."IE ID" ""
   //here step 2
}

Step 1 must be replaced if this is about DXL Layout columns or DXL Attributes. In these cases, the code for step 1 will just be

Module m1 = module obj
ID1 = obj."IE ID" ""

The code for step 2 will be

bool foundIt = false
for obj2 in entire m2 do {
   ID2 = obj2."Req Id" ""
   if (ID1 == ID2 ) {
      foundIt = true
      //here step 3
   }
}
if (!foundIt) {
   print "Objet non trouvé dans le deuxième module pour l'objet " obj1."Absolute Number" ""
}

The code for step 3 will be (if you iterate over the attributes defined in m1)

AttrDef ad1
for ad1 in m1 do {
   // if the AttrDef exists for objects
   if (ad1.object) {
     string attrName = ad1.name
     AttrDef ad2 = find (m1, attrName)
     // if an attribute of the same name exists in m2
     if (!null ad2) {
       string att1 = obj1.attrName ""
       string att2 = obj2.attrName ""
       if (att1 != att2) {   
          // in DXL layout column, replace "print" with "display"
          // in attribute DXL, replace print by one line containing "obj.attrDXLName=strMessage" with strMessage being a string variable filled with the message
          print "Différence détectée pour l'objet " obj1."Absolute Number" " :" 
          print "  Attribut : " attrName
          print "  Module 1 : " att1
          print "  Module 2 : " att2  "\n"
...

You might have to adopt this if some AttrDefs are defined as integer or Date, but the general steps should be rather clear now.

5
Emilie rei On

I made the necessary modifications, below is the final code without syntax errors, but after execution, it only displays this message in the DXL column: 'Attribute DXL element failed,' and I can't identify the problem

Module m1 = current
Module m2 = edit(""/Firts project/System/Module Verification"")


Object obj2
string ID1
string ID2


   ID1 = obj."IE ID" ""
   bool foundIt = false
    for obj2 in entire m2 do {
        ID2 = obj2."Req Id" ""
        if (ID1 == ID2 ) {
        foundIt = true
        AttrDef ad1
            for ad1 in m1 do {
   // if the AttrDef exists for objects
                if (ad1.object) {
                     string attrName = ad1.name
                     string att1 = obj.attrName ""
                     string att2 = obj2.attrName ""
                     if (att1 != att2) {     
                        string resultMessage = "Différence détectée pour l'objet " obj."Absolute Number" " :" "  Attribut : " attrName "\n" "Module 1 : " att1 "\n" "  Module 2 : " att2
                        /* print "  Attribut : " attrName
                        print "  Module 1 : " att1
                        print "  Module 2 : " att2  "\n" */
                        
                        display resultMessage
                    }
                }
            }
        }
    }
    if (!foundIt) {
   display "Objet non trouvé dans le deuxième module pour l'objet " obj."Absolute Number" ""
    }

I also tried to write another code in parallel to specify the exact attribute I want to compare instead of all attributes (e.g., Absolute Number). The syntax of the code is correct, but the column remains empty without displaying any information or errors. The code is as follows:

Module m1 = current
Module m2 = edit("/Firts project/System/Module Verification")


Object obj2
string ID1
string ID2


   ID1 = obj."IE ID" ""
   bool foundIt = false
    for obj2 in entire m2 do {
        ID2 = obj2."Req Id" ""
        if (ID1 == ID2 ) {
        foundIt = true
                     string att1 = obj."Absolute Number" ""
                     string att2 = obj2."Absolute Number" ""
                     
                     if (att1 != att2) {     
                        string resultMessage = "Différence détectée pour l'objet " obj."Absolute Number" " :"  "\n" "Module 1 : " att1 "\n" "  Module 2 : " att2
                        
                        display resultMessage
                    }
        }
    }
    if (!foundIt) {
   display "Objet non trouvé dans le deuxième module pour l'objet " obj."Absolute Number" ""
    }