Author Topic: Searching Linked Documents  (Read 1974 times)

shimon

  • EA User
  • **
  • Posts: 106
  • Karma: +3/-0
    • View Profile
Searching Linked Documents
« on: July 26, 2024, 01:32:26 am »
Hi,
We use linked documents to write the Use Cases. The normal Find of EA does not look through these documents. Has anyone created a scriplet or addin to search through these RTF's?

Thanks in advance,
Shimon

qwerty

  • EA Guru
  • *****
  • Posts: 13574
  • Karma: +395/-301
  • I'm no guru at all
    • View Profile
Re: Searching Linked Documents
« Reply #1 on: July 26, 2024, 06:32:02 am »
Just search t_document for elements linked via ElementId with ElementType = ModelDocument

q.

Takeshi K

  • EA User
  • **
  • Posts: 542
  • Karma: +33/-1
    • View Profile
Re: Searching Linked Documents
« Reply #2 on: July 26, 2024, 09:12:27 am »
The linked documents are stored in the t_document table, as Thomas wrote, but they are binary and compressed. So we have to export all the data as RTF files, decompress them and then search for them. This must be a very heavy process, so I guess EA does not (cannot) offer a feature to search in the linked documents.
« Last Edit: July 26, 2024, 09:27:55 am by Takeshi K »
--
t-kouno

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8568
  • Karma: +254/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Searching Linked Documents
« Reply #3 on: July 26, 2024, 11:19:28 am »
The linked documents are stored in the t_document table, as Thomas wrote, but they are binary and compressed. So we have to export all the data as RTF files, decompress them and then search for them. This must be a very heavy process, so I guess EA does not (cannot) offer a feature to search in the linked documents.
Hi Takeshi-san,
So, technically they are embedded documents not linked documents, yes?  ;)

Paolo
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

Takeshi K

  • EA User
  • **
  • Posts: 542
  • Karma: +33/-1
    • View Profile
Re: Searching Linked Documents
« Reply #4 on: July 26, 2024, 11:33:41 am »
Hi Paolo-san,

I think that 'Linked' means the RTF document is linked to an element, not mean a document is stored as a separated file.
There is similar property in the 'Files' tab of the Properies dialog.

The Linked Document (right-click an element in a diagram | Linked Document)
-> the data (as RTF document) is stored in the t_document as zipped binary

The file path / URL for an element (double-click an element in a diagram | the Files group)
-> the path information (as text) is stored in the t_objectfiles as simple string

We might feel the latter is 'linked'  :)
--
t-kouno

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13136
  • Karma: +547/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Searching Linked Documents
« Reply #5 on: July 26, 2024, 07:14:18 pm »
I have a script search that can be used to search in Linked Documents (regardless whether that is a semantically correct description of the concept)

Code: [Select]
'[path=\Projects\Project A\Search Scripts]
'[group=Search Scripts]
option explicit

!INC Local Scripts.EAConstants-VBScript
!INC Wrappers.Include

'
' This code has been included from the default Search Script template.
' If you wish to modify this template, it is located in the Config\Script Templates
' directory of your EA install path.   
'
' Script Name: In Linked Documents
' Author: Geert Bellekens
' Purpose: Search for a certain string in the linked documents
' Date: 2021-06-25
'

' TODO 1: Define your search specification:
' The columns that will apear in the Model Search window
dim SEARCH_SPECIFICATION
SEARCH_SPECIFICATION = "<ReportViewData>" &_
       "<Fields>" &_
        "<Field name=""CLASSGUID""/>" &_
        "<Field name=""CLASSTYPE"" />" &_
        "<Field name=""Name"" />" &_
        "<Field name=""Type"" />" &_
        "<Field name=""Stereotype"" />" &_
        "<Field name=""Description"" />" &_
        "<Field name=""Path"" />" &_
       "</Fields>" &_
       "<Rows/>" &_
      "</ReportViewData>"

'
' Search Script main function
'
sub OnSearchScript()
 'get the search term
 dim searchTerm
 searchTerm = InputBox( "Please enter term to search for", "search term" )
 'ask if we should look only under selected branch
 dim response
 response = MsgBox("Search only in selected package branch?", vbYesNo+vbQuestion, "Search scope")
 dim package as EA.Package
 if response = vbYes then
  set package = Repository.GetTreeSelectedPackage
 else
  set package = nothing
 end if
 'get the linked documents
 dim allLinkedDocuments
 set allLinkedDocuments = getAllLinkedDocuments(package)
 
 
 ' Create a DOM object to represent the search tree
 dim xmlDOM
 set xmlDOM = CreateObject( "MSXML2.DOMDocument.6.0" )
 xmlDOM.validateOnParse = false
 xmlDOM.async = false
 
 ' Load the search template
 if xmlDOM.loadXML( SEARCH_SPECIFICATION ) = true then
 
  dim rowsNode
  set rowsNode = xmlDOM.selectSingleNode( "//ReportViewData//Rows" )
 
  ' TODO 2: Gather the required data from the repository
  dim element as EA.Element
  for each element in allLinkedDocuments.Keys
   dim ldText
   ldText = allLinkedDocuments(element)
   if instr(1,ldText, searchTerm,  1) > 0 then
    AddRow xmlDOM, rowsNode, element
   end if
  next
'  'debug
'  dim debugFile
'  set debugFile = new TextFile
'  debugFile.Contents = xmlDOM.xml
'  'save the debug file
'  debugFile.FullPath = "I:\temp\scriptDebug.xml"
'  debugFile.Save
'  'end debug
  ' Fill the Model Search window with the results
  Repository.RunModelSearch "", "", "", xmlDOM.xml
 
 else
  Session.Prompt "Failed to load search xml", promptOK
 end if
end sub

'
' TODO 3: Modify this function signature to include all information required for the search
' results. Entire objects (such as elements, attributes, operations etc) may be passed in.
'
' Adds an entry to the xml row node 'rowsNode'
'
sub AddRow( xmlDOM, rowsNode, element)
 
 ' Create a Row node
 dim row
 set row = xmlDOM.createElement( "Row" )
 
 ' Add the Model Search row data to the DOM
 AddField xmlDOM, row, "CLASSGUID", element.elementGUID
 AddField xmlDOM, row, "CLASSTYPE", element.Type
 AddField xmlDOM, row, "Name", element.Name
 AddField xmlDOM, row, "Type", element.Type
 AddField xmlDOM, row, "Stereotype", element.Stereotype
 AddField xmlDOM, row, "Description", element.Notes
 AddField xmlDOM, row, "Path", element.FQName
 
 ' Append the newly created row node to the rows node
 rowsNode.appendChild( row )

end sub

'
' Adds an Element to the DOM called Field which makes up the Row data for the Model Search window.
' <Field name "" value ""/>
'
sub AddField( xmlDOM, row, name, value )

 dim fieldNode
 set fieldNode = xmlDOM.createElement( "Field" )
 
 ' Create first attribute for the name
 dim nameAttribute
 set nameAttribute = xmlDOM.createAttribute( "name" )
 nameAttribute.value = name
 fieldNode.attributes.setNamedItem( nameAttribute )
 
 if len(value) > 0 then
  ' Create second attribute for the value
  dim valueAttribute
  set valueAttribute = xmlDOM.createAttribute( "value" )
  valueAttribute.value = value
  fieldNode.attributes.setNamedItem( valueAttribute )
 end if
 ' Append the fieldNode
 row.appendChild( fieldNode )

end sub

'returns a dictionary of all elements that have a linked document as key and the text of the linked document as value.
function getAllLinkedDocuments(package)
 dim queryString
 queryString = "select o.object_ID from t_document d              " & vbNewLine & _
     " inner join t_object o on d.ElementID = o.ea_guid " & vbNewLine & _
     " where d.ElementType = 'ModelDocument'            "
 if not package is nothing then
  'get package tree id string
  dim packageTreeIDString
  packageTreeIDString = getPackageTreeIDString(package)
  queryString = queryString & vbNewLine & _
      " and o.package_ID in (" & packageTreeIDString & ")"
 end if
 dim elementsWithLinkedDocument
 set elementsWithLinkedDocument = getElementsFromQuery(queryString)
 dim linkedDocumentsDictionary
 set linkedDocumentsDictionary = CreateObject("Scripting.Dictionary")
 dim element as EA.Element
 'loop the elements and add element and its linked document to the dictionary
 for each element in elementsWithLinkedDocument
  dim linkedDocumentText
  linkedDocumentText = getLinkedDocumentContent(element, "TXT")
  linkedDocumentsDictionary.Add element, linkedDocumentText
 next
 set getAllLinkedDocuments = linkedDocumentsDictionary
end function


OnSearchScript()
Geert

shimon

  • EA User
  • **
  • Posts: 106
  • Karma: +3/-0
    • View Profile
Re: Searching Linked Documents
« Reply #6 on: July 30, 2024, 12:50:03 am »
Hi Geert,
Thanks. I'll try to test this soon.
Sincerely,
Shimon