Book a Demo

Author Topic: Adding to scenarioStep.UsesElementList ?  (Read 5066 times)

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Adding to scenarioStep.UsesElementList ?
« on: September 25, 2015, 10:46:22 pm »
Does anyone know the secret formula to add something to the scenarioStep.UsesElementList
I tried with element.Name and element.ElementGUID as parameters, but that doesn't seem to work.
I think the whole UsesElementList simply doesn't work because it is always empty, even if I added linked elements in the uses column manually.
If in anyway possible I would like to avoid having to change the xml in the t_objectscenarios.XMLContent

Here's what I have in the code so far.
Code: [Select]
     for each usecase in usecases
            dim scenario as EA.Scenario
            for each scenario in usecase.Scenarios
                  dim scenarioStep as EA.ScenarioStep
                  for each scenarioStep in scenario.Steps
                        dim matches
                        set matches = regExp.Execute(scenarioStep.Name)
                        dim classesToMatch
                        set classesToMatch = getClassesToMatchDictionary(matches, dictionary)
                        dim classToMatch as EA.Element
                        for each classToMatch in classesToMatch.Items
                              Session.Output "usesElementList before: " & scenarioStep.UsesElementList.Count
                              scenarioStep.UsesElementList.AddNew classToMatch.Name, classToMatch.ElementGUID
                              scenarioStep.Uses = scenarioStep.Uses & " " & classToMatch.Name
                              scenarioStep.Update
                              scenarioStep.UsesElementList.Refresh
                              Session.Output "usesElementList after: " & scenarioStep.UsesElementList.Count
                        next
                        Session.Output matches.Count & " matches found for step " & scenarioStep.Name
                  next
            next
      next

Thanks

Geert

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Adding to scenarioStep.UsesElementList ?
« Reply #1 on: September 25, 2015, 10:57:23 pm »
One thing I noticed already is that scenarioStep.Update doesn't do anything at all. You need to do scenario.Update before something happens in the database.

Geert

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Adding to scenarioStep.UsesElementList ?
« Reply #2 on: September 25, 2015, 11:23:14 pm »
The usesElementList returned from a scenario step has 0 elements though I had added some text in the GUI. An AddNew does not create anything at all. You know the game: report a bug and happy XML coding :P

q.

P.S. Oh. Uses in the GUI is not the list. It's the Uses property which is returned correctly. So where does the UsesElementList occur in the GUI?

P.P.S. Found it, but can't add anything. It's greyed out.

P3.S. EAUI. You need to enable the option   ::)

P4.S. The element returned is the linked one and not a special object. So you can't use AddNew. Back to square 1.
« Last Edit: September 25, 2015, 11:36:07 pm by qwerty »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Adding to scenarioStep.UsesElementList ?
« Reply #3 on: September 25, 2015, 11:58:47 pm »
I figured it out.

To make it work you have to create a relation from the element (use case) to the element you want to use (class).
Then you have to put the name of the used element in the uses field (and save the Scenario)
Then EA will automatically figure out that it knows the used element and show it as a hyperlink in the uses column (and also in the step column if that contains the same text).

So this is my working code:

Code: [Select]
function linkDomainClassesWithUseCases(dictionary,regExp,usecases)
      Session.Output usecases.Count & " use cases found"
      dim usecase as EA.Element
      'loop de use cases
      for each usecase in usecases
            'first remove all automatic traces
            removeAllAutomaticTraces usecase
            dim scenario as EA.Scenario
            for each scenario in usecase.Scenarios
                  dim scenarioStep as EA.ScenarioStep
                  for each scenarioStep in scenario.Steps
                        dim matches
                        set matches = regExp.Execute(scenarioStep.Name)
                        dim classesToMatch
                        set classesToMatch = getClassesToMatchDictionary(matches, dictionary)
                        dim classToMatch as EA.Element
                        for each classToMatch in classesToMatch.Items
                              Session.Output "scenarioStep.Uses before " & scenarioStep.Uses
                              if not instr(scenarioStep.Uses,classToMatch.Name) > 0 then
                                    scenarioStep.Uses = scenarioStep.Uses & " " & classToMatch.Name
                              end if
                              scenarioStep.Update
                              scenario.Update
                              'create the dependency between the use case and the domain model class
                              linkElementsWithAutomaticTrace usecase, classToMatch
                        next
                        Session.Output matches.Count & " matches found for step " & scenarioStep.Name
                  next
            next
      next
end function

function linkElementsWithAutomaticTrace(sourceElement, TargetElement)
      dim trace as EA.Connector
      set trace = sourceElement.Connectors.AddNew("","trace")
      trace.Alias = "automatic"
      trace.SupplierID = TargetElement.ElementID
      trace.Update
end function

Geert
« Last Edit: September 26, 2015, 12:00:20 am by Geert.Bellekens »