Book a Demo

Author Topic: Script to find the element at the "end " of a Realization  (Read 5333 times)

Modesto Vega

  • EA Practitioner
  • ***
  • Posts: 1183
  • Karma: +30/-8
    • View Profile
Script to find the element at the "end " of a Realization
« on: May 17, 2022, 08:51:18 pm »
I want to write a script that checks if a selected element has a Realization as one of its connectors and find the element at the other end of the Realization.

Is there a way of doing this that does involve iterating through the Element.Connectors collection? [Note: I am assuming the answer is no.]

Once the connector is found, what property do I use to get the element at the other end of the connector ClientID, ClientEnd, SupplierID, or SupplierEnd?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Script to find the element at the "end " of a Realization
« Reply #1 on: May 17, 2022, 09:05:53 pm »
Your assumption is wrong.
You can easily find the elements using an Repository.SQLQuery.

I use this utility functions to get me a collection of elements based on a query.

Code: [Select]
function getElementsFromQuery(sqlQuery)
dim elements
set elements = Repository.GetElementSet(sqlQuery,2)
dim result
set result = CreateObject("System.Collections.ArrayList")
dim element
for each element in elements
result.Add Element
next
set getElementsFromQuery = result
end function

This method is then called like this:

Code: [Select]
function getActors(useCase)
'first get the direct actors
dim getDirectActorsSQL
getDirectActorsSQL = "select act.Object_ID from t_object act                                                 " & _
" inner join t_connector act_uc on act_uc.Start_Object_ID = act.Object_ID               " & _
" and act_uc.Connector_Type in ('Association','UseCase')  " & _
" and act_uc.End_Object_ID = " & useCase.ElementID & " " & _
" where act.Object_Type = 'Actor'                                                   "
dim actors
set actors = getElementsFromQuery(getDirectActorsSQL)
set getActors = actors
end function

This is a LOT faster then iterating over the connectors.

Geert

PS. You can use Repository.GeElementByID to get an element object by it's ObjectID (such as ClientID)

Modesto Vega

  • EA Practitioner
  • ***
  • Posts: 1183
  • Karma: +30/-8
    • View Profile
Re: Script to find the element at the "end " of a Realization
« Reply #2 on: May 18, 2022, 12:09:46 am »
Thanks Geert. Glad my assumption was wrong. I will give it a try. Indeed it will be faster.

Daiim

  • EA User
  • **
  • Posts: 51
  • Karma: +0/-0
    • View Profile
Re: Script to find the element at the "end " of a Realization
« Reply #3 on: May 22, 2022, 09:22:21 pm »
Client* is the source, where the connector starts, and Supplier* (nobody knows why this is named like that) is the connectors target, where it points to! Keep attention to the connector type as the semantic direction may be the other way around. This is (sometimes) defined by the 'direction' property of the connector.

Modesto Vega

  • EA Practitioner
  • ***
  • Posts: 1183
  • Karma: +30/-8
    • View Profile
Re: Script to find the element at the "end " of a Realization
« Reply #4 on: June 10, 2022, 12:51:50 am »
I noticed a couple of things.

1) If the query does not have a field aliased Object_ID the following line of code will give an error - i.e., t_connector.End_Object_ID will always result on an error unless the field is aliased to Object_ID.
Code: [Select]
set elements = Repository.GetElementSet(sqlQuery,2)
2) The script assigns each element a fully qualified stereotype - i.e., <MDG Name>::<Stereotype>. This stereotype column in the t_object table holds the fully qualified value until something happens to element - e.g., viewing the properties. After something happens to the element, the value on the stereotype column changes to just <Stereotype>. The undesired effect of this, is that a where clause including Stereotype = '<Stereotype>' only works after something has happened to the element.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Script to find the element at the "end " of a Realization
« Reply #5 on: June 10, 2022, 01:58:31 am »
I noticed a couple of things.

1) If the query does not have a field aliased Object_ID the following line of code will give an error - i.e., t_connector.End_Object_ID will always result on an error unless the field is aliased to Object_ID.
Code: [Select]
set elements = Repository.GetElementSet(sqlQuery,2)
True, it looks for the Object_ID field.
Quote
2) The script assigns each element a fully qualified stereotype - i.e., <MDG Name>::<Stereotype>. This stereotype column in the t_object table holds the fully qualified value until something happens to element - e.g., viewing the properties. After something happens to the element, the value on the stereotype column changes to just <Stereotype>. The undesired effect of this, is that a where clause including Stereotype = '<Stereotype>' only works after something has happened to the element.
That shouldn't happen. Are you using StereotypeEx to set the fully qualified stereotype?
You shouldn't use the Stereotype Field to set a stereotype, unless you want EA to guess which MDG your stereotype belongs to.

Geert

Modesto Vega

  • EA Practitioner
  • ***
  • Posts: 1183
  • Karma: +30/-8
    • View Profile
Re: Script to find the element at the "end" of a Realization
« Reply #6 on: June 10, 2022, 07:52:09 pm »
Thanks Geert, Stereotype was used by one of the scripts instead of StereotypeEx.

I would like to move all utility scripts to a group of their own, can I have them in a normal group and use an include statement to reference them?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Script to find the element at the "end" of a Realization
« Reply #7 on: June 10, 2022, 09:28:31 pm »
Thanks Geert, Stereotype was used by one of the scripts instead of StereotypeEx.

I would like to move all utility scripts to a group of their own, can I have them in a normal group and use an include statement to reference them?
Yes, that's what I do as well.

Geert