Author Topic: Documentation for EA Validator "Resolve Code" function  (Read 750 times)

heba

  • EA User
  • **
  • Posts: 44
  • Karma: +0/-0
    • View Profile
Documentation for EA Validator "Resolve Code" function
« on: July 11, 2024, 11:36:37 pm »
Hi all,

is there any documentation about how to use the "Resolve Code" feature in EA Validator add-in or does somebody has a Javascript example to share?

At the beginning I would be happy to simply be able to "delete" the selected items. But I don't know if I have to query these items via EA API (and how) or if the script maybe just needs to implement an interface which is then used by the add-in.

Thanks!
Heiko

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13065
  • Karma: +544/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Documentation for EA Validator "Resolve Code" function
« Reply #1 on: July 12, 2024, 01:22:15 am »
Hmm, a bit sloppy of the author not to update his documentation. ???

Here's an example of a real word resolve function
This is from a validator rule that says all classes in the same package should have the same color on a diagram.
The addin basically calls the function resolve() with the guid of wathever element, attribute, operation, connector,... is being checked.
The rest is like regular scripting, but without the EA quirks. Only the Repository object is present. No Session.

Code: [Select]
function resolve (itemGuid)
resolve = false 'initial value
dim sqlData
sqlGetData = "select do.Diagram_ID from t_diagramobjects do where do.Instance_ID = " & itemGuid
dim diagram
set diagram = getDiagramFromQuery(sqlGetData)
'get element
sqlGetData = "select do.Object_ID from t_diagramobjects do where do.Instance_ID = " & itemGuid
dim elements
set elements = Repository.GetElementSet(sqlGetData,2)
dim element
set element = elements(0)
'get diagramObject
dim diagramObject as EA.DiagramObject
for each diagramObject in diagram.DiagramObjects
if diagramObject.ElementID = element.ElementID then
'reset background color
diagramObject.BackgroundColor = -1
diagramObject.Update
'return success
resolve = true
exit for
end if
next
end function

function getDiagramFromQuery(sqlGetData)
dim xmlResult
xmlResult = Repository.SQLQuery(sqlGetData)
dim diagramIDs
diagramIDs = convertQueryResultToArray(xmlResult)
dim diagramID
dim diagram
set diagram = nothing
for each diagramID in diagramIDs
if diagramID > 0 then
set diagram =  Repository.GetDiagramByID(diagramID)
exit for
end if
next
'return
set getDiagramFromQuery = diagram
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
end if
convertQueryResultToArray = result
End Function

Geert

heba

  • EA User
  • **
  • Posts: 44
  • Karma: +0/-0
    • View Profile
Re: Documentation for EA Validator "Resolve Code" function
« Reply #2 on: July 16, 2024, 01:11:49 am »
Thank you very much!  I'll experiment with it.  :)