Search code examples
sqltemplatesdocumentation-generationenterprise-architect

Nested Template Fragments with Custom Queries?


First, in the Sparx help I read under 'Creating a Template Fragment':

"If you embed a Template Fragment within another Fragment, report generation from the parent template will be slower".

So, I understand that nesting template fragments should be possible, in general.

I have a number of diagrams from which I want to generate documentation. For each diagram, I want to process the elements of certain types (e.g. activities) on that diagram. Therefore, my primary template (which processes the diagram), references a template fragment that is based on a custom query:

select o.Name as ActivityName, ...
from t_object o, t_diagramobjects do
where 
   o.Object_ID = do.Object_ID 
   and do.Diagram_ID = #DIAGRAMID# 
   and o.Object_Type = 'Activity'

That works - I can for instance insert custom field {ActivityName} in the Template Fragment.

However, I would also like to query the tagged values of an object linked to each activity... For this I have another template fragment based on a custom query, looking like this:

select op.Property as LinkedTagName, op.Value as LinkedTagValue
from 
   t_object o1, t_connector c, t_object o2, t_objectproperties op
where
   o1.Object_ID = #OBJECTID#
   and o1.Object_ID = c.Start_Object_ID
   and c.End_Object_ID = o2.Object_ID
   and o2.Object_ID = op.Object_ID

Used directly, this second template fragment also works fine, and I can build a table referencing {TagName} and {TagValue}

However, what I cannot figure out is how to make both work together, so the second template fragment nested in the first one, so that for each diagram element, I can also show the linked tagged values.

Probably the 'inner' custom query does not receive an #OBJECTID# ? I tried a.o. to return OBJECTID as a field in the 'outer' custom query, but that does not make any difference.

Is it somehow possible to have nested template fragments with custom queries...?


Solution

  • The problem is that your fragment should be used in the element section under the diagram, but EA doesn't allow that

    package >
    Package Name: {Pkg.Name}
    diagram >
    Diagram name: {Diagram.Name}
    element >
    The fragment should be added here but EA doesn't allow that
    < element
    < diagram
    < package
    

    I guess you then added it to the diagram> section, but that won't work as it will not have the #OBJECTID# available.

    Possible solutions

    1. Use the #DIAGRAMID# in your fragment and create one big table for all elements and their tagged values in the diagram You can use a query such as

      select o.[Name] AS Owner, tv.[Property] as TV_Name, tv.[VALUE] AS TV_Value, tv.[Notes] as TV_Notes from (((t_object o inner join t_diagramObjects dob on dob.[Object_ID] = o.[Object_ID]) inner join t_diagram d on dob.[Diagram_ID] = d.[Diagram_ID]) left join t_objectproperties tv on tv.[Object_ID] = o.[Object_ID]) where d.[Diagram_ID] = #DIAGRAMID#

    Then add you SQL Fragment to the Diagram Section of your template

    package >
    Package Name: {Pkg.Name}
    diagram >
    Diagram name: {Diagram.Name}
    {My SQL Template Fragment}
    < diagram
    < package
    
    1. Use a Virtual Document where you add a model document for the diagram part of your template, and you add a model document for the elements part of the template. In that case you can use an SQL search to define the elements that should be reported by the fragment. Use something like:

      select o.[ea_guid] AS CLASSGUID, o.[Object_Type] AS CLASSTYPE, o.[Name] as Name from ((t_object o inner join t_diagramObjects dob on dob.[Object_ID] = o.[Object_ID]) inner join t_diagram d on dob.[Diagram_ID] = d.[Diagram_ID]) where d.[ea_guid] = '<Search Term>'

    Put the name of the search in the tagged value SearchName and put the GUID of the diagram (right click on diagram in project browser and choose Copy/Paste..|Copy Node GUID to clipboard) in the tagged value SearchValue

    Then make a normal template and use something like

    package >
    element >
    Element Name: {Element.Name}
    tagged value >
    Tagged Value Name: {ElementTagVal.Name} 
    Tagged Value Value: {ElementTagVal.Value}
    Tagged Value Notes: {ElementTagVal.Notes}
    < tagged value
    < element
    < package