Book a Demo

Author Topic: Finding the connector a connector is connected to  (Read 6545 times)

gunterkoenigsmann

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Finding the connector a connector is connected to
« on: March 09, 2024, 02:32:50 am »
As far as I have understood in EA connectors aren't objects => they have no list who connects to them. Instead a connector is never directly connected to a connector, but to a ProxyConnectorElement.

By vbScript actually finds ProxyConnector elements. But if I try to find out where they end by looking at their ClassifierID I get a "0".
What am I doing wrong?


   ' iterate over all objects
   dim objects
   set objects = Repository.GetElementSet("select object_id from t_object where object_type = 'Object'", 2)
   dim currentobject as EA.Element
   for j = 0 to objects.Count() - 1
      set currentobject = objects.GetAt(j)
      
      ' Now iterate over all connectors this object has
      dim objectConnector as EA.Connector
      for each objectConnector in currentobject.Connectors
         dim myconnectorTarget as EA.Element
         set myconnectorTarget = Repository.GetElementByID(objectConnector.ClientID)
         
         ' Our connector technically isn't directly connected to a connector, but to an connector proxy
         ' object named 'ProxyConnector' that then knows the ID of the connector => seach for
         ' proxy connectors
         Session.Output myconnectorTarget.Type
         Session.Output myconnectorTarget.ClassifierID
         if myconnectorTarget.Type = "ProxyConnector" then
            ' Let's try to find out what connector that ProxyConnector is connected to
            dim myconnectorTargetID
            myconnectorTargetID = myconnectorTarget.ClassifierID
            dim targetConnector as EA.Connector
            set targetConnector = Repository.GetElementByGuid(myconnectorTargetID)                  
         end if
      next
   next


qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Finding the connector a connector is connected to
« Reply #1 on: March 09, 2024, 08:04:28 am »
Hard to tell without having the model. But basicaclly you are right with your assumption. I just would guess a night will cure things by itself. I also think that access is possible with a single query (which Geert would probably have out of the box).

q.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Finding the connector a connector is connected to
« Reply #2 on: March 09, 2024, 07:41:46 pm »
This set targetConnector = Repository.GetElementByGuid(myconnectorTargetID) 
Should be set targetConnector = Repository.GetConnectorByID(myconnectorTargetID) 

Geert

gunterkoenigsmann

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: Finding the connector a connector is connected to
« Reply #3 on: March 11, 2024, 04:52:22 pm »
Waiting a weekend didn't help: myconnectorTarget.ClassifierID still reads zero for all ProxyConnector elements => Created a minimal .eapx file that allows to reproduce the problem?

Is there any means to attach it to a forum message?
« Last Edit: March 11, 2024, 04:57:59 pm by gunterkoenigsmann »

gunterkoenigsmann

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Finding the connector a connector is connected to
« Reply #5 on: March 11, 2024, 07:59:19 pm »
That's because the link is on Classifier_guid

Code: [Select]
select * from t_object o
inner join t_connector c on c.ea_guid = o.Classifier_guid
where o.Object_Type = 'ProxyConnector'

In my code I'm using the classifierID to get the relation, but I'm not 100% sure this actually works

Code: [Select]
                        //in case the source is linked to a connector there's a dummy element with type ProxyConnector
                        if (targetElementWrapper != null && targetElementWrapper.EAElementType == "ProxyConnector")
                        {
                            //get the source connector
                            this._source = this.EAModel.getRelationByID(targetElementWrapper.wrappedElement.ClassifierID);
                        }

The problem is that the classifier_GUID field is not exposed in the API, so if ClassifierID isn't working, you'll have to use Repository.SQLQuery to get the ID or GUID of the connector

Geert

gunterkoenigsmann

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: Finding the connector a connector is connected to
« Reply #6 on: March 11, 2024, 09:07:02 pm »
Wow... ...how do I make such a SQL request? And do we need to inform Sparx that the classifier GUID should be exposed to the API? If yes: How does one do that?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Finding the connector a connector is connected to
« Reply #7 on: March 11, 2024, 09:22:23 pm »
Repository.SQLQuery accepts an SQL query as parameter and returns an xml string with the results

I use this method in VBScript to get connectors based on their connector ID:

Code: [Select]
function getConnectorsFromQuery(sqlQuery)
dim xmlResult
xmlResult = Repository.SQLQuery(sqlQuery)
dim connectorIDs
connectorIDs = convertQueryResultToArray(xmlResult)
dim connectors
set connectors = CreateObject("System.Collections.ArrayList")
dim connectorID
dim connector as EA.Connector
for each connectorID in connectorIDs
if connectorID > 0 then
set connector = Repository.GetConnectorByID(connectorID)
if not connector is nothing then
connectors.Add(connector)
end if
end if
next
set getConnectorsFromQuery = connectors
end function

'converts the query results from Repository.SQLQuery from xml format to a two dimensional array of strings
Public Function convertQueryResultToArray(xmlQueryResult)
    Dim arrayCreated
    Dim i
    i = 0
    Dim j
    j = 0
    Dim result()
    Dim xDoc
    Set xDoc = CreateObject( "MSXML2.DOMDocument" )
    'load the resultset in the xml document
    If xDoc.LoadXML(xmlQueryResult) Then       
'select the rows
Dim rowList
Set rowList = xDoc.SelectNodes("//Row")

Dim rowNode
Dim fieldNode
arrayCreated = False
'loop rows and find fields
For Each rowNode In rowList
j = 0
If (rowNode.HasChildNodes) Then
'redim array (only once)
If Not arrayCreated Then
ReDim result(rowList.Length, rowNode.ChildNodes.Length)
arrayCreated = True
End If
For Each fieldNode In rowNode.ChildNodes
'write f
result(i, j) = fieldNode.Text
j = j + 1
Next
End If
i = i + 1
Next
'make sure the array has a dimension even is we don't have any results
if not arrayCreated then
ReDim result(0, 0)
end if
end if
    convertQueryResultToArray = result
End Function

See also https://github.com/GeertBellekens/Enterprise-Architect-VBScript-Library/blob/master/Framework/Utils/Util.vbs

So in this case I guess the query could be something like

Code: [Select]
select c.ConnectorID from t_object o
inner join t_connector c on c.ea_guid = o.Classifier_guid
where o.ea_guid = '<the guid of the ProxyConnector object>'

Geert

gunterkoenigsmann

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: Finding the connector a connector is connected to
« Reply #8 on: March 11, 2024, 09:33:48 pm »
Ha! Now it works. Thanks a lot!