Topic
20 replies Latest Post - ‏2012-05-24T17:04:49Z by llandale
SystemAdmin
SystemAdmin
3180 Posts
ACCEPTED ANSWER

Pinned topic creating a DXL attribute using a multi-valued attribute input

‏2012-04-04T15:47:30Z |
Hello,

I want to create a DXL attribute that uses a multi-valued attribute as its input.

Verification Status: multi-valued attribute
Passed
Failed
Waived
Incomplete

The purpose of the DXL attribute is to determine the parent requirement's verification status based on its child requirement.

ex.
Level 1 requirements will contain the DXL attribute
Level 2 requirements has the 'Verification Status" attribute that is a multi-valued enumeration

The linked Level 2 requirements would have the following values 'checked',
Req2001 --> Passed and Waived
Req2002 --> Passed
Req2003 --> Incomplete

I would like the DXL attribute have the following result displayed to sum up the status of it's children requirements,
Req1001 --> Passed, Waived, Incomplete

I have already created a DXL attribute that will assign the result, but it was not for a multi-valued attribute. Would I need to change a lot of if I switched to a multi-valued attribute?

Thanks!
Updated on 2012-05-24T17:04:49Z at 2012-05-24T17:04:49Z by llandale
  • llandale
    llandale
    2735 Posts
    ACCEPTED ANSWER

    Re: creating a DXL attribute using a multi-valued attribute input

    ‏2012-04-04T17:17:46Z  in response to SystemAdmin

    First stab:

    bool bStatus[NumEnumerations]  // default setting is false
     
    for each oChild object
    {  for i=0; i<NumEnumerations; i++)
       {  if (isMember(oChild, Enumeration[i])) bStatus[i] = true
       }
    }
    Buffer bufResults = create()
    for i=0; i<NumEnumerations; i++)
    {  if (bStatus[i])
       {  if (length(bufResults) > 0) bufResults += ", "
          bufResults += Enumeration[i]
       }
    }
    obj.attrDXLName = tempStringOf(bufResults)
    delete(bufResults()
    


    -Louie

    Updated on 2014-01-06T19:25:21Z at 2014-01-06T19:25:21Z by iron-man
    • SystemAdmin
      SystemAdmin
      3180 Posts
      ACCEPTED ANSWER

      Re: creating a DXL attribute using a multi-valued attribute input

      ‏2012-04-04T20:49:36Z  in response to llandale
      Making sure I understand ...

      for each oChild object
      { for i=0; i<NumEnumerations; i++)
      { if (isMember(oChild, Enumeration[i])) bStatus[i] = true
      • This runs through the inlinks (child objects) and determines if it is actually an enumeration attribute, if so then it is set to true

      for i=0; i<NumEnumerations; i++)
      { if (bStatus[i])
      { if (length(bufResults) > 0) bufResults += ", "
      bufResults += Enumeration[i]
      }
      }
      obj.attrDXLName = tempStringOf(bufResults)

      • Iterates through the enumeration until complete
      • Puts the result in the buffer, separating by a ","
      • Then display the gathered values
      I guess my next question is if this would go in my for loop that accesses the Verification Status?
      (after line from previously attached code: L2Status = oSource."Verification Status")
      and would I even need the conditions shown throughout the rest of the code if it is gathering all the values checked from each linked requirement?

      Also, to avoid duplication, how would I have it not display the same status shown in multiple child requirements. If 2 linked requirements both have a verification status of "Incomplete", I would not want the script to display "Incomplete, Incomplete".
      • llandale
        llandale
        2735 Posts
        ACCEPTED ANSWER

        Re: creating a DXL attribute using a multi-valued attribute input

        ‏2012-04-05T15:03:54Z  in response to SystemAdmin

        Typo:

        • { if (isMember(oChild.NameAttr, Enumeration[i])) then bStatus[i] = true

        This presumes NameAttr is a multi-valued enuerated attribute. This asks if the oChild attr value for that enumerated attribute includes the "i"th value. So if enumerations are A, B, C, D and the first oChild has B and C selected, bStatus will have values false, true, true, false. If the 3rd oChild has just D selected, then bStatus becomes false, true, true, true. Since there is no else bStatus[i] =false clause, bStatus[i] remains true if any of the oChildren have that enum set.

        The second loop adds the enumerations to the result if their corresponding bStatus[i] is set true.

        The following may also help:

        string NameAttr = "MyEnumeratedAttr",
            Enum
        Object oChild = current
        Module mod = module(oChild)
        AttrDef ad = find(mod, NameAttr)
        if (null ad) {print "no such attr '" NameAttr "'\n"; halt}
        if (!ad.multi) {print "not multi attr '" NameAttr "'\n"; halt}
        AttrType at = ad.type
        noError()
        int i, NumEnums = at.size
        lastError()
        print "for attr '" NameAttr "' (count " NumEnums ")  and object " identifier(oChild) "...\n"
        print "\tEnum\tselected?\n"
        for (i=0; i<NumEnums; i++) 
        {  Enum = at.strings[i]
           print "\t[" Enum "]"
           if (isMember(oChild.NameAttr, Enum)) print "\tSelected"
           print "\n"
        }
        


        -Louie

        Updated on 2014-01-06T19:26:03Z at 2014-01-06T19:26:03Z by iron-man
        • SystemAdmin
          SystemAdmin
          3180 Posts
          ACCEPTED ANSWER

          Re: creating a DXL attribute using a multi-valued attribute input

          ‏2012-04-16T18:01:56Z  in response to llandale

          I took a few days away from this task and now just have 2 errors haunting me.

          I am receiving a "syntax error" for the following line,

          if (L2Status == ad.name){ // checking if the attribute type is the Verification Status attribute
          

           


          and "incorrectly concatenated tokens" for line,

           

           

          delete(bufResults())
          


          For the first error, I am trying to say that if the AttrDef name matches L2Status name then it would proceed to evaluating the contents of the attribute. I assumed it would allow me to compare the two strings being evaluated, but apparently not.

           

          Updated on 2014-01-06T19:27:04Z at 2014-01-06T19:27:04Z by iron-man
          • llandale
            llandale
            2735 Posts
            ACCEPTED ANSWER

            Re: creating a DXL attribute using a multi-valued attribute input

            ‏2012-04-16T18:22:08Z  in response to SystemAdmin
            The first one looks good. "Syntax Errors" often mean the line ABOVE is missing some closing parenthesis.

            • bufResults()
            That is a function with no parameters.
            • bufResults
            That is either a variable, or a function with no parameters.
            Since bufResults is a "Buffer" variable, you want:
            • delete(bufResults)
            I usually put the empty parens to make sure I know I'm dealing with a function:
            • Buffer bufResults = create()

            -Louie
            • SystemAdmin
              SystemAdmin
              3180 Posts
              ACCEPTED ANSWER

              Re: creating a DXL attribute using a multi-valued attribute input

              ‏2012-04-16T18:41:11Z  in response to llandale

              I've made a few changes and realized that I was not 'finding' the attribute definitions name to do the comparison and tweaked my code to the following:
               

              for inlink in obj <-"*" do { // for all objects that have inlinks (child requirements) do this ...
                  oSource = source(inlink)
                      if (null oSource)   continue  
                      if (exists attribute "Verification Status"){ // checking for the Verification Status attribute
                              L2Status = oSource."Verification Status"
                              ad = find(oSource, NameAttr)
                              if (L2Status == ad.name){ // checking if the attribute is the Verification Status attribute
                                      EnumSize = aType.size
                                      MultiEnum = aType.strings[i]
                                      for (i=0; i<EnumSize; i++) {
                                              if (isMember(oSource."Verification Status", MultiEnum)) {
                                                      bStatus = true // resets to true if it exists
                                              }
                                      }
                              }
                              else Incomplete == true
                      }
               
                      Buffer bufResults = create() // creates a 'space' to hold values
                      for (i=0; i<EnumSize; i++) {
                              if (bStatus) {
                                      if (length(bufResults) > 0) {
                                              bufResults += "\n"
                                              bufResults += MultiEnum[i]
                                      }
                              }
                      }
                      L1Status = tempStringOf(bufResults)
                      obj.attrDXLName = L1Status
                      delete(bufResults)
              }
              

               


              But now I am receiving an "incorrect arguments for function (find)" error on

               

               

              ad = find(oSource, NameAttr)
              

               

              Updated on 2014-01-06T19:28:13Z at 2014-01-06T19:28:13Z by iron-man
              • llandale
                llandale
                2735 Posts
                ACCEPTED ANSWER

                Re: creating a DXL attribute using a multi-valued attribute input

                ‏2012-04-17T16:20:59Z  in response to SystemAdmin
                Assuming NameAttr has a reasonable value, the "find" needs to be in the module not the object, perhaps
                • ad = find(current Module, NameAttr)

                At about line 7, this may be clearer:
                • if (L2Status == *NameAttr*){ // checking if the attribute is the Verification Status attribute
                After about line 7 I think you need this:
                • AttrType aType = ad.type
                At about line 7, are you sure attribute "Verification Status" has enumerations that are in fact attribute names?
                At about line 9, "i" does not yet have a value. I think you need to move this line down into the loop:
                • MultiEnum = aType.strings[i]
                Above about line 15 I think you need this:
                • Incomplete = false
                Line 16 or thereabouts needs to be this:
                • Incomplete = true
                At about line 19, the "Buffer" statement and the following loop, I think, need to be moved up into the previous loop, and execute only when Verification Status actually exists. OK, the Buffer statement actually needs to be before the 1st loop.
                At about line 30 I think this statement, while not needed, makes the code easier to understand:
                • else bufResults = "" // Not results when Verification Status doesn't exist
                At about line 38, the last 3 statement needs to be outside the "for link" loop; executed only once
                • obj.attrDXLName = L1Status
                Above line 4, I think you are wondering if Verification Status exists in the Source module; not the "current" module. The following may work:
                • current = mSource
                • if (exists attribute "Verification Status"){ // checking for the Verification Status attribute

                You are still not getting the result you want; look again at some of the previous responses.

                -Louie
                • SystemAdmin
                  SystemAdmin
                  3180 Posts
                  ACCEPTED ANSWER

                  Re: creating a DXL attribute using a multi-valued attribute input

                  ‏2012-04-18T18:48:49Z  in response to llandale

                  I have the following variables declared upfront,

                  LinkRef lr
                  Link    inlink
                  bool    Incomplete = false      // true when any linked object is "Incomplete"
                  bool    Passed = false  // true when any linked object has "Passed"
                  bool    Failed = false  // true when any linked object has "Failed"
                  bool    Waived = false  // true when any linked object is "Waived"
                  bool    Blank = false   // true when any linked object has no input
                  string  L2Status, L1Status
                  Object  oSource
                  string  NameAttr = "Verification Status"
                  AttrDef aDef = find(mod, NameAttr)
                  AttrType aType = aDef.type
                  int             i, EnumSize = aType.size // size of enumeration
                  string  MultiEnum[EnumSize]
                  bool    bStatus[EnumSize] // default setting is false
                  Buffer  bufResults = create() // creates a 'space' to hold values
                  

                   


                  The following code runs and creates my dxl attribute for all linked requirements,

                   

                   

                   

                  for inlink in obj <-"*" do { // for all objects that have inlinks (child requirements) do this ...
                      oSource = source(inlink)
                          if (null oSource)   continue  
                          if (exists attribute "Verification Status"){ // checking for the Verification Status attribute
                                  L2Status = oSource."Verification Status"
                                  if (L2Status == NameAttr){ // checking if the name of the attribute is Verification Status
                                          for (i=0; i<EnumSize; i++) {
                                                  MultiEnum[i] = aType.strings[i] // enumeration value names
                                                  if (isMember(oSource."Verification Status", MultiEnum[i])) {
                                                          bStatus[i] = true // resets to true if it exists
                                                  }
                                                  else Blank = false
                                          }
                                  }
                                  else bufResults = " " // if the Verification Status attribute doesnt exist, return an empty buffer
                   
                                  for (i=0; i<EnumSize; i++) {
                                          if (bStatus[i]) {
                                                  if (length(bufResults) > 0) {
                                                          bufResults += "\n"
                                                          bufResults += MultiEnum[i]
                                                  }
                                          }
                                  }
                          }
                  }
                  if (Blank) L1Status = " " // no input keep Blank
                  else L1Status = tempStringOf(bufResults)
                   
                  obj.attrDXLName = L1Status // DXL attribute column
                  delete(bufResults)
                  



                  but when I view the attribute the following error apprears,



                   

                   

                   

                  unassigned array element (bStatus[0])
                  



                  It is getting 'stuck' through the first iteration of i=0. The related numbers associated with the enumeration values are 0-3, for the booleens declared in the beginning with exception to 'Blank', meaning no selection is checked. I'm lost as to why it is returning an unassigned element



                   

                  Updated on 2014-01-06T19:29:51Z at 2014-01-06T19:29:51Z by iron-man
                  • llandale
                    llandale
                    2735 Posts
                    ACCEPTED ANSWER

                    Re: creating a DXL attribute using a multi-valued attribute input

                    ‏2012-04-18T21:37:47Z  in response to SystemAdmin

                    Oops, you do need to initialize that array:

                    for (i=0; i<EnumSize; i++) bStatus[i] = false
                    


                    But this is still messed up.
                    You hard code "Verification Status" and also use it in NameAttr. These two don't look right:

                     

                    L2Status = oSource."Verification Status"
                        if (L2Status == NameAttr){ // checking if the name of the attribute is Verification Status
                    


                    That looks like you expect Verification Status to have an enumeration of "Verification Status". Seems to me you can get rid of the if statement. Also the first statement since you don't use L2Status anywhere else.

                    Re-read the thread.

                    -Louie

                     

                    Updated on 2014-01-06T19:30:50Z at 2014-01-06T19:30:50Z by iron-man
                    • SystemAdmin
                      SystemAdmin
                      3180 Posts
                      ACCEPTED ANSWER

                      Re: creating a DXL attribute using a multi-valued attribute input

                      ‏2012-05-21T20:22:49Z  in response to llandale

                      I thought I had this completed but my inputs were misleading.

                      The following code collects the results from the incoming links, but instead of checking if the ith value is included and not repeating selections (See "llandale" explanation from Apr 5 @ 11:03:54am), it collects and returns all the selected items linked.

                      i.e.
                      Req001 --> Passed, Waived
                      Req002 --> Passed
                      Req003 --> Passed, Incomplete

                      Actual Result ---> Passed, Waived, Passed, Passed, Incomplete
                      Desired Result --> Passed, Waived, Incomplete (not repeating values already selected)

                      How do I code this to not compile all selected items in a giant list?
                       

                      for inlink in obj <-"*" do { 
                          oSource = source(inlink)
                              if (null oSource)   continue  
                              Module mod = module(oSource)
                              AttrDef aDef = find(mod, NameAttr)
                              AttrType aType = aDef.type
                              int     i, EnumSize = aType.size // size of enumeration
                              string  MultiEnum[EnumSize]
                              bool    bStatus[EnumSize] // default setting is false
                              
                              if (exists attribute "Verification Status"){ // checking for the Verification Status attribute
                                      if (null aDef) {print "no such attr" NameAttr "\n"; halt} 
                                      if (aDef.multi) {print "multi attr: " NameAttr "\n"} 
                                      noError()
                                      lastError()
                                      print "for attr " NameAttr " (count " EnumSize ") and object " identifier(oSource) "...\n"
                                      for (i=0; i<EnumSize; i++) {
                                              bStatus[i] = false
                                              MultiEnum[i] = aType.strings[i] // enumeration value names
                                              print MultiEnum[i] "\n"
                                              if (isMember(oSource.NameAttr, MultiEnum[i])) then {
                                                      print "\t CHECKED !!!"
                                                      print "\n"
                                                      bStatus[i] = true // resets to true if it exists
                                                      print "\t bR STATUS: " stringOf(bufResults) //prints status of buffer contents
                                                      print "\n \n"
                                              }
                                              else Blank = true // nothing 'checked/selected'
                                              //else bufResults = " "
                                      }
                                      for (i=0; i<EnumSize; i++) {
                                              if (bStatus[i]){
                                                      if (length(bufResults) >= 0){ 
                                                              bufResults += "\n"
                                                              bufResults += MultiEnum[i]
                                                              print "\t bufResult: " stringOf(bufResults) 
                                                              print "\n \n"
                                                      }
                                              }            
                                      }
                              } // ENDS attribute exists statement
                              else bufResults = "" // the Verification Status attribute doesnt exist, return an empty buffer
                       
                      } //ENDS inlink if statement
                       
                       
                      LStatus = tempStringOf(bufResults)
                      obj.attrDXLName = LStatus // DXL attribute column
                      delete(bufResults)
                      

                       


                      **Please excuse all the print statements, I was using them to debug

                       

                      Updated on 2014-01-06T19:31:51Z at 2014-01-06T19:31:51Z by iron-man
                      • llandale
                        llandale
                        2735 Posts
                        ACCEPTED ANSWER

                        Re: creating a DXL attribute using a multi-valued attribute input

                        ‏2012-05-22T13:16:04Z  in response to SystemAdmin

                        I think you need to set bstatusall to false before your link loop. Inside the link loop set bstatus[i] to true if that linked object so indicates. Display results after the link loop:

                        set all bstatus[x] = false
                        for each link
                        {  for each enumeration
                              if the linked object has this enumeration selected then bstatus[i] = true
                        }
                        for each enumeration
                          if bstatus[i] is true then add Enums[i] to results
                        display results
                        


                        So if ANY linked object is "PASSED" then the displayed results include "PASSED".

                        -Louie

                        Updated on 2014-01-06T19:32:27Z at 2014-01-06T19:32:27Z by iron-man
                        • SystemAdmin
                          SystemAdmin
                          3180 Posts
                          ACCEPTED ANSWER

                          Re: creating a DXL attribute using a multi-valued attribute input

                          ‏2012-05-22T15:30:33Z  in response to llandale

                          bStatus is declared in the link loop. If I move it outside the loop, then the other variables have to be moved and declared before it, but the oSource variable depends on my inlink variable, which isn't assigned until the link loop, and returns an unassigned variable error since each one depends upon the other.

                          I tried adding it after it is declared,

                           

                          set all bStatus[EnumSize] = false
                          


                          before

                           

                           

                          if (exists attribute "Verification Status"){ ...
                          


                          but I am recieving errors

                           

                           

                          -E- DXL: incorrect arguments for (=)
                          -E- DXL: incorrect arguments for function (all)
                          -E- DXL: incorrect arguments for function (set)
                          



                          then i tried,



                           

                           

                          void set (bStatus[EnumSize]) = false
                          


                          and received syntax errors

                          I tried looking to see if I am using all correctly, but the dxl manual seems to only mentions the function in for loops operating on modules. So then I tried altering the inlink loop

                           

                           

                          for inlink in all obj <-"*" do { ...
                          


                          but received more errors

                           

                           

                          -E- DXL: incorrect arguments for (<-)
                          -E- DXL: incorrect arguments for (do)
                          



                          My latest attempt was adding



                           

                           

                          for bStatus in all oSource {
                          


                          before the if exists statement but now I am receiving syntax errors

                          I am getting the selected values from the inlinks displayed in the attribute. I just would like to filter these results and not repeat items. Is this possible? I feel like I am a couple lines of code away from accomplishing this :/

                           

                          Updated on 2014-01-06T19:35:50Z at 2014-01-06T19:35:50Z by iron-man
                          • llandale
                            llandale
                            2735 Posts
                            ACCEPTED ANSWER

                            Re: creating a DXL attribute using a multi-valued attribute input

                            ‏2012-05-22T17:39:17Z  in response to SystemAdmin
                            That 8 lines of code was clearly psuedo-code; of course it won't interpret.
                            bStatus is declared in the link loop. If I move it outside the loop, then the other variables have to be moved and declared before it, but the oSource variable depends on my inlink variable, which isn't assigned until the link loop, and returns an unassigned variable error since each one depends upon the other.

                            This is inadequate logic; the order in which variables are declared, and in which context, has little to do with the order in which their values are determined; you only have a problem if their values are circular; A depends on B and B depends on A. Anyway, maybe I'm old-fashioned but it should be rare to declare a variable other than in the function's context; declarations inside usually make it harder to read; and if it is easier to read then probabaly your function is far too big.

                            Overall, I think you said you want to display an enumerated value if any of the linked objects have that value. If so, there is no getting around this (or similar) logic:
                            • initialize accumulated values (for each enum; bStatus/enum = false)
                            • for each linked object, if it has an enum set then set corresponding bStatus to true; but do NOT set if false.
                            • after the linked loop; display true bStatus values.
                            So if you are linked to A and B; and A has 1 and 4 set and B has 2 and 4 set, the result will be 1, 2, and 4. The results won't care that "1" is set in two objects. If so, then "bStatus" has to be declared up front.

                            Your "exists" statement is still faulty; it will find it in the "current Module", but is the module containing "obj" or the module containing "oSource" currently current? (it's probably "obj" but you want to know if it's in "oSource") You don't need that statement if you use function "probeAttr_" as that function gracefully handles when the attr doesn't exist and returns null.

                            -Louie
                            • SystemAdmin
                              SystemAdmin
                              3180 Posts
                              ACCEPTED ANSWER

                              Re: creating a DXL attribute using a multi-valued attribute input

                              ‏2012-05-22T21:42:41Z  in response to llandale

                              The entire script ...

                              Created a menu that contains a function 'L1-L2 Verfication Status'that calls and creates the dxl attribute
                               

                              Module mod = current
                               
                              string DxlCode = readFile("C:\\Program Files/IBM/Rational/DOORS/9.3/lib/dxl/addins/MyDXL/L1 Verification.dxl")
                              AttrDef ad = create(object dxl DxlCode type "String" attribute "L1-L2 Verification Status")
                              

                               


                              L1 Verfication.dxl ...

                               

                               

                              Module mod = current
                              LinkRef lr
                              Link    inlink
                              bool    Incomplete = false      // true when any linked object is "Incomplete"
                              bool    Passed = false  // true when any linked object has "Passed"
                              bool    Failed = false  // true when any linked object has "Failed"
                              bool    Waived = false  // true when any linked object is "Waived"
                              bool    Blank = false   // true when any linked object has no input
                              string  L1Status
                              Object  oSource 
                              string  NameAttr = "Verification Status"
                              Buffer  bufResults = create() // creates a 'space' to hold values
                               
                              AttrDef aDef = find(mod, NameAttr)
                              AttrType aType = aDef.type
                              int             i, EnumSize = aType.size // size of enumeration
                              string  MultiEnum[EnumSize]
                              bool    bStatus[EnumSize] = false // default setting is false
                               
                               
                              // Checking for null obj
                              if (null obj){
                                      obj = obj__()
                                      display "obj__() used: " identifier(obj) ""
                              }
                               
                              //   Open up modules that target this Object for links  
                              for lr in obj <-"*" do {
                                      read(fullName(source(lr)), false, true)   // Open linked module, even if it's already open
                              }
                               
                              for inlink in obj <-"*" do { // for all objects that have inlinks (child requirements) do this ...
                                      oSource = source(inlink)
                                      if (null oSource)   continue  
                                      for (i=0; i<EnumSize; i++) {
                                              bStatus[i] = false
                                              MultiEnum[i] = aType.strings[i] // enumeration value names
                                              if (isMember(oSource.NameAttr, MultiEnum[i])) then {
                                                      bStatus[i] = true // resets to true if it exists
                                              }
                                              else bStatus[i] = false
                                      }
                              }
                               
                              for (i=0; i<EnumSize; i++) {
                                      if (bStatus[i]){
                              //              if (length(bufResults) >= 0){ 
                                                      bufResults += "\n"
                                                      bufResults += MultiEnum[i]      
                              //              }
                                      }
                              }
                               
                              L1Status = tempStringOf(bufResults)
                              obj.attrDXLName = L1Status // DXL attribute column
                              delete(bufResults)
                              



                              Error



                               

                               

                              -R-E- DXL: unassigned array element (bStatus[1])
                              

                               

                              Updated on 2014-01-06T19:37:53Z at 2014-01-06T19:37:53Z by iron-man
                              • Mathias Mamsch
                                Mathias Mamsch
                                1734 Posts
                                ACCEPTED ANSWER

                                Re: creating a DXL attribute using a multi-valued attribute input

                                ‏2012-05-23T11:48:22Z  in response to SystemAdmin

                                Funny that this code works:
                                 

                                bool    bStatus[EnumSize] = false // default setting is false
                                

                                 


                                this should be:

                                 

                                 

                                bool bStatus[EnumSize]
                                int i; for (i = 0; i < EnumSize; i++) bStatus[i] = false
                                



                                Maybe that helps, regards, Mathias



                                 

                                 

                                 


                                Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

                                 

                                 

                                Updated on 2014-01-06T19:39:09Z at 2014-01-06T19:39:09Z by iron-man
                                • SystemAdmin
                                  SystemAdmin
                                  3180 Posts
                                  ACCEPTED ANSWER

                                  Re: creating a DXL attribute using a multi-valued attribute input

                                  ‏2012-05-23T15:47:40Z  in response to Mathias Mamsch

                                  I had it w/o the "= false" initally, but even after removing it, I am still recieving an error for this line
                                   

                                  for (i=0; i<EnumSize; i++) bStatus[i] = false { ...
                                  

                                   


                                  In both instances, if I state bStatus in the same line, I receive this error

                                   

                                   

                                  -R-E- DXL: array bounds exceeded (4)
                                  



                                  But when I state it like this ...



                                   

                                   

                                  for (i=0; i<EnumSize; i++) {
                                      bStatus[i] = false
                                  



                                  the first instance works, but of course the last for loop does not return anything, since the if statement will never be true, because bStatus is being set to false right before it.



                                   

                                   

                                  for (i=0; i<EnumSize; i++) {
                                      bStatus[i] = false
                                          if (bStatus[i]){
                                                  if (length(bufResults) >= 0){ 
                                                          bufResults += "\n"
                                                          bufResults += MultiEnum[i]      
                                                  }
                                          }
                                  }
                                  



                                  Before I was displaying all selected items, but now I am receiving errors and displaying "Attribute DXL Failed".



                                   

                                  Updated on 2014-01-06T19:41:00Z at 2014-01-06T19:41:00Z by iron-man
                                  • Mathias Mamsch
                                    Mathias Mamsch
                                    1734 Posts
                                    ACCEPTED ANSWER

                                    Re: creating a DXL attribute using a multi-valued attribute input

                                    ‏2012-05-23T22:04:28Z  in response to SystemAdmin

                                    Maybe you misinterpreted my statement. The code should be like that:
                                     

                                    Module mod = current
                                    LinkRef lr
                                    Link    inlink
                                    bool    Incomplete = false      // true when any linked object is "Incomplete"
                                    bool    Passed = false  // true when any linked object has "Passed"
                                    bool    Failed = false  // true when any linked object has "Failed"
                                    bool    Waived = false  // true when any linked object is "Waived"
                                    bool    Blank = false   // true when any linked object has no input
                                    string  L1Status
                                    Object  oSource 
                                    string  NameAttr = "Verification Status"
                                    Buffer  bufResults = create() // creates a 'space' to hold values
                                     
                                    AttrDef aDef = find(mod, NameAttr)
                                    AttrType aType = aDef.type
                                    int             i, EnumSize = aType.size // size of enumeration
                                    string  MultiEnum[EnumSize]
                                    bool    bStatus[EnumSize]
                                    for (i=0; i<EnumSize; i++) bStatus[i] = false
                                     
                                     
                                    // Checking for null obj
                                    if (null obj){
                                            obj = obj__()
                                            display "obj__() used: " identifier(obj) ""   // Display? Below you use 'attrDXLName', so I guess this is test code? 
                                    }
                                     
                                    //   Open up modules that target this Object for links  
                                    for lr in obj <-"*" do {
                                            ModuleVersion mv = sourceVersion lr  // want this to work for baseline sets? Use the correct source version!
                                            if (null data mv) load(mv, false) 
                                    }
                                     
                                    for inlink in obj <- "*" do { // for all objects that have inlinks (child requirements) do this ...
                                            oSource = source(inlink)
                                            if (null oSource)   continue  
                                            for (i=0; i<EnumSize; i++) {
                                                    MultiEnum[i] = aType.strings[i] 
                                                    bStatus[i] = isMember(oSource.NameAttr, MultiEnum[i]) // this is just a shorter version of your code
                                            }
                                    }
                                     
                                    for (i=0; i<EnumSize; i++) {
                                            if (bStatus[i]) {
                                                    if (length(bufResults) >= 0) bufResults += "\n"  // This way results will be nicely separated
                                                    bufResults += MultiEnum[i]      
                                            }
                                    }
                                     
                                    L1Status = tempStringOf(bufResults)
                                    obj.attrDXLName = L1Status 
                                    delete(bufResults)
                                    

                                     


                                    See some comments inline. Maybe that helps, regards, Mathias

                                     

                                     


                                    Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

                                     

                                    Updated on 2014-01-06T19:41:51Z at 2014-01-06T19:41:51Z by iron-man
                                    • Mathias Mamsch
                                      Mathias Mamsch
                                      1734 Posts
                                      ACCEPTED ANSWER

                                      Re: creating a DXL attribute using a multi-valued attribute input

                                      ‏2012-05-23T22:08:50Z  in response to Mathias Mamsch

                                      Now reading your first statement again, I figure there is still an error in the logic. You probably want this:
                                       

                                      for inlink in obj <- "*" do { // for all objects that have inlinks (child requirements) do this ...
                                          oSource = source(inlink)
                                              if (null oSource)   continue  
                                              for (i=0; i<EnumSize; i++) {
                                                      MultiEnum[i] = aType.strings[i] 
                                                      // if ANY inlink has this value, set it to true
                                                      // make sure it stays true, even if this object does NOT have the value set. 
                                                      bStatus[i] = bStatus[i] || isMember(oSource.NameAttr, MultiEnum[i]) 
                                              }
                                      }
                                      

                                       


                                      Regards, Mathias

                                       

                                       

                                       


                                      Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

                                       

                                       

                                      Updated on 2014-01-06T19:42:31Z at 2014-01-06T19:42:31Z by iron-man
                                      • SystemAdmin
                                        SystemAdmin
                                        3180 Posts
                                        ACCEPTED ANSWER

                                        Re: creating a DXL attribute using a multi-valued attribute input

                                        ‏2012-05-24T16:26:03Z  in response to Mathias Mamsch

                                        All this time I thought this line was in both my for loops, but it was supposed to be declared upfront ... sigh :/
                                         

                                        for (i=0; i<EnumSize; i++) bStatus[i] = false
                                        

                                         


                                        Thank you, thank you, thank you both ... it FINALLY works!

                                         

                                        Updated on 2014-01-06T19:43:09Z at 2014-01-06T19:43:09Z by iron-man
                              • llandale
                                llandale
                                2735 Posts
                                ACCEPTED ANSWER

                                Re: creating a DXL attribute using a multi-valued attribute input

                                ‏2012-05-24T17:04:49Z  in response to SystemAdmin
                                Mathias' comments look good.

                                It makes it easier if you give the line number generating such DXL errors. I have no clue about the wierd errors you expressed; I don't see how you could get them. But I wonder...
                                [1] Perhaps you get an explicit error after turning off AutoDeclare.
                                [2] Perhaps there is some code in play we don't see, such as in your top context.
                                [3] You get different results when you insert this Attr-DXL into a column of a clean Standard view. I have seen attr-DXL and layout context issues ("obj" and "attrDXLName" are wrong ) for views containing a few such columns.
                                [4] This line of code makes my hackles crawl for reason's I don't know:
                                • MultiEnum[i] = aType.strings[i]
                                because I notice that "aType" belongs to the original module but you are executing this code while some other module is "current" (a Source you just opened). Yes, that should not be a problem and yes sometimes my hackles are wrong. I then looked through some old notes and I see an incomplete one when dealing with "AttrType"s, that the "module must be current" but I don't remember what I was thinking 5 years ago.

                                There remains a fundamental structural problem: the code presumes that the current module and also ALL modules that source links to it have that attribute "Verification Status" AND they all have the same enumerations. Your code will fail rudely otherwise. The logic of the following lines should be within the link loop:
                                • aDef = find(mSource, NameAttr)
                                • aType = aDef.type
                                • EnumSize = aType.size // size of enumeration
                                and add something like this:
                                • if (aType.type != attrEnumeration or EnumSize is not what I expect) then ignore this link.

                                -Louie
                                This line should be moved up, perhaps where you initialize bStatus[i] = false
                                • MultiEnum[i] = aType.strings[i]

                                Seems to me you should "halt" if "obj" is null; but maybe function "obj__()" (which I've never used) has some magic I don't understand.

                                I would do nothing when "obj" isDeleted.

                                I would ignore the link when "oSource" isDeleted.

                                I would be tempted to make this Attr-DXL of type Enumeration with the correct enumerations(instead of type "string"). Then this line:
                                • if (isMember(oSource.NameAttr, MultiEnum[i])) then {bStatus[i] = true
                                becomes I think this:
                                • if (isMember(oSource.NameAttr, MultiEnum[i])) then obj.attrDXLName += MultiEnum[i]
                                and you don't need the buffer nor the closing "obj.attrDXLName =" last 13 lines of code.

                                Since I have OCD I would tweak your deploy code:
                                • string DxlCode = readFile("C:\\Program Files/IBM/Rational/DOORS/9.3/lib/dxl/addins/MyDXL/L1 Verification.dxl")
                                • if (!checkDXL(DxlCode)) //
                                • then I cannot deploy code with interpret errors
                                • else AttrDef ad = create(object dxl DxlCode type "String" attribute "L1-L2 Verification Status")
                                Also check if the attr exists with type "String", and if so "modify" it with the new code.