Skip to content

Commit

Permalink
Add model export extension for basic classes (#13)
Browse files Browse the repository at this point in the history
* Add model export extension for basic classes

* review comments

* Build all XEM files

* review comments

* review comments

* review comments
  • Loading branch information
willem-xbreeze authored Mar 1, 2024
1 parent f106588 commit e641d57
Show file tree
Hide file tree
Showing 92 changed files with 699 additions and 1,857 deletions.
4 changes: 2 additions & 2 deletions .github/actions/compose_and_publish_artifacts/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ runs:
uses: actions/upload-artifact@v3
with:
name: MDDE Extension
path: ./composed/extensions/MDDE_LDM.xem
path: ./composed/extensions/*.xem
- name: Publish sample models
uses: actions/upload-artifact@v3
with:
name: Sample models
path: ./composed/models/*.ldm
# TODO: add logic to version and add to a tag/release
# TODO: add logic to version and add to a tag/release
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# PowerDesigner-MDDE-Extension
A PowerDesigner LDM extension to support Model Driven Data Engineering using PowerDesigner LDM models.

This extensions is to add extra modeling possibilities to LDM models, where standard PowerDesigner functionalities are missing options to add metadata. These extra modeling options are listed below per object type.
This extension is to add extra modeling possibilities to LDM models, where standard PowerDesigner functionalities are missing options to add metadata. These extra modeling options are listed below per object type.

- Entity
- Mapping
Expand All @@ -22,6 +22,8 @@ This extensions is to add extra modeling possibilities to LDM models, where stan
- XML Export
- To generate code, tests, etc. using CrossGenerate for the model an XML export has been implemented on model level.

In many cases it is helpful to customize the XML Export to include project-specific extensions. The MDDE Model Export Extension can be used to include this type of project-specific model content in the MDDE XML Export without modifying the MDDE extension.

## Modeling manual
There is a modeling manual available [here](./manual/) on how to use the PowerDesigner extension.

Expand Down
1 change: 0 additions & 1 deletion decomposed/Workspace/Workspace.sws
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<Model ID="{3BC78F2D-650B-4443-9783-A97171290BFE}" Name="ExampleDWH" Type="{5F45F978-C4F3-4E35-A3FC-AF3318663A0F}" URL="file:///%MDDE_EXAMPLE_MODELS%/models/ExampleDWH.ldm"/>
<Model ID="{E0D7FF56-7977-4D8F-A64B-BB6D985687E7}" Name="Reference" Type="{5F45F978-C4F3-4E35-A3FC-AF3318663A0F}" URL="file:///%MDDE_EXAMPLE_MODELS%/models/Reference.ldm"/>
<Model ID="{D7F41E17-25EB-4620-B6EA-96957CAE246A}" Name="ExampleSource" Type="{5F45F978-C4F3-4E35-A3FC-AF3318663A0F}" URL="file:///%MDDE_EXAMPLE_MODELS%/models/ExampleSource.ldm"/>
<Model ID="{7FFD987F-402B-4A66-86B5-F3E8C4CF140F}" Name="ExampleBusinessConcepts" Type="{5F45F978-C4F3-4E35-A3FC-AF3318663A0F}" URL="file:///%MDDE_EXAMPLE_MODELS%/models/ExampleBusinessConcepts.ldm"/>
</Local>
<BrowserModule Name="Repository"/>
</Workspace>
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ Const cMDDE_EXT_CODE = &quot;MDDE_LDM&quot;
Const cMDDE_PDC_COMPOSED_FOLDER = &quot;composed&quot;
Const cMDDE_PDC_DECOMPOSED_FOLDER = &quot;decomposed&quot;
Const cMDDE_JOIN_TYPE_APPLY = &quot;Apply&quot;
Const cMDDE_EXPORT_EXTENSION_CODE = &quot;MDDE_LDM_Export_Extension&quot;
Const cMDDE_EXPORT_EXTENSION_INITIALIZATION_INDICATOR = &quot;mdde_Export_Extension_Initialization_Successful&quot;
Const cMDDE_NAMEDOBJECT_ATTRIBUTE_EXPORT_TEMPLATE_NAME = &quot;mddex_NamedObject_Attributes_Export_Template&quot;
Const cMDDE_NAMEDOBJECT_ATTRIBUTE_EXPORT_ATTRIBUTE_NAME = &quot;mddex_NamedObject_Attributes_Export_Content&quot;
Const cMDDE_DATASOURCE_STEREOTYPE = &quot;mdde_DataSource&quot;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
.foreach_item(mdde_Mapping_Examples,\n &lt;Examples&gt;\n,\n &lt;/Examples&gt;)
%mdde_Example_XmlExport_Template%
.next(\n)
.comment Add the content of the export extension template
.if (%Model.mdde_Export_Extension_Attached%)
.if (%.D:mddex_BaseClassifierMapping_Export_Content%)
%.D:mddex_BaseClassifierMapping_Export_Content%
.endif
.endif

&lt;/Mapping&gt;</a:TemplateTargetItem.Value>
<a:CreationDate>1651739964</a:CreationDate>
<a:Creator>WesselsH1</a:Creator>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
.endif
%SourceFeature.mdde_NamedObject_XmlAttributeExport_Template% /&gt;
.endif(\n)
.comment Add the content of the export extension template
.if (%Model.mdde_Export_Extension_Attached%)
.if(%.D:mddex_BaseStructuralFeatureMapping_Export_Content%)
%.D:mddex_BaseStructuralFeatureMapping_Export_Content%
.endif
.endif
&lt;/%Feature.mdde_NamedObject_XmlElementName%Mapping&gt;</a:TemplateTargetItem.Value>
<a:CreationDate>1651753617</a:CreationDate>
<a:Creator>WesselsH1</a:Creator>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@

%mdde_Entity_Stereotyped_XmlExport_Template%
.endif

.comment Add the content of the export extension template
.if (%Model.mdde_Export_Extension_Attached%)
.if(%.D:mddex_Entity_Export_Content%)
%.D:mddex_Entity_Export_Content%
.endif
.endif

&lt;/%mdde_NamedObject_XmlElementName%&gt;</a:TemplateTargetItem.Value>
<a:CreationDate>1651670451</a:CreationDate>
<a:Creator>WesselsH1</a:Creator>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
.if (%mdde_NamedObject_XmlElementExport_Template%)
\n %mdde_NamedObject_XmlElementExport_Template%
.endif(\n)
.comment Add the content of the export extension template
.if (%Model.mdde_Export_Extension_Attached%)
.if(%.D:mddex_EntityAttribute_Export_Content%)
%.D:mddex_EntityAttribute_Export_Content%
.endif
.endif

&lt;/%mdde_NamedObject_XmlElementName%&gt;</a:TemplateTargetItem.Value>
<a:CreationDate>1651670975</a:CreationDate>
<a:Creator>WesselsH1</a:Creator>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<o:TypedCategoryTargetItem Id="1E094FE4-6BB9-48B7-BD1F-50F4079BF878">
<a:TypePublicName>ExtendedAttributeTargetItem</a:TypePublicName>
<a:ObjectID>1E094FE4-6BB9-48B7-BD1F-50F4079BF878</a:ObjectID>
<a:Name>Extended Attributes</a:Name>
<a:CreationDate>1701429225</a:CreationDate>
<a:Creator>WillemOtten</a:Creator>
<a:TargetCategory.Type>1</a:TargetCategory.Type>
<c:Categories>
<xi:include href="mdde_Export_Extension_Attached.xml" />
<xi:include href="mdde_Export_Extension_Initialization_Successful.xml" />
</c:Categories>
</o:TypedCategoryTargetItem>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<o:ExtendedAttributeTargetItem Id="FD029C97-577C-44C5-A0C5-BFB158940D76">
<a:ObjectID>FD029C97-577C-44C5-A0C5-BFB158940D76</a:ObjectID>
<a:Name>mdde_Export_Extension_Attached</a:Name>
<a:CreationDate>1701429225</a:CreationDate>
<a:Creator>WillemOtten</a:Creator>
<a:Comment>Checks if the MDDE LDM Export extension is attached to the model</a:Comment>
<a:TargetCategory.Type>1</a:TargetCategory.Type>
<a:Computed>1</a:Computed>
<a:ComputedAccessType>RO</a:ComputedAccessType>
<a:GetMethodScript>Function %Get%(obj)
%Get% = False
&#39;Find the export extension
Dim extensionObject: Set extensionObject = obj.FindChildByCode (&quot;MDDE_LDM_Export_Extension&quot;, Cls_ExtendedModelDefinition, &quot;&quot;, Nothing, True, True)
%Get% = Not extensionObject is Nothing
End Function</a:GetMethodScript>
<a:Label>Indicator for export extension</a:Label>
</o:ExtendedAttributeTargetItem>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<o:ExtendedAttributeTargetItem Id="3CB69645-4260-4DBC-A602-0536A9D4E6B3">
<a:ObjectID>3CB69645-4260-4DBC-A602-0536A9D4E6B3</a:ObjectID>
<a:Name>mdde_Export_Extension_Initialization_Successful</a:Name>
<a:CreationDate>1701438410</a:CreationDate>
<a:Creator>WillemOtten</a:Creator>
<a:Comment>Used to check if the export initialization was successful</a:Comment>
<a:TargetCategory.Type>1</a:TargetCategory.Type>
<a:Label>MDDE Export extension initialized successful</a:Label>
<a:ValidateDataType>0</a:ValidateDataType>
</o:ExtendedAttributeTargetItem>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
&lt;Command Name=&quot;mdde_ExportXml&quot; Caption=&quot;Export XML (MDDE)&quot; /&gt;
&lt;Command Name=&quot;mdde_Decompose&quot; Caption=&quot;Decompose (MDDE)&quot; /&gt;
&lt;Command Name=&quot;mdde_UpdateDiagramPreferences&quot; Caption=&quot;Update Diagram Preferences (MDDE)&quot; /&gt;
&lt;Command Name=&quot;mdde_InitializeExportExtension&quot; Caption=&quot;Initialize Export Extension (MDDE)&quot; /&gt;
&lt;/Popup&gt;
&lt;/Menu&gt;
</a:MenuTargetItem.Value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
<xi:include href="mdde_ExportXmlAndDecompose.xml" />
<xi:include href="mdde_ExportXml.xml" />
<xi:include href="mdde_UpdateDiagramPreferences.xml" />
<xi:include href="mdde_InitializeExportExtension.xml" />
</c:Categories>
</o:TypedCategoryTargetItem>
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@
Dim strModelFolderLocaton : strModelFolderLocaton = objFileSystem.GetParentFolderName(obj.Filename) &amp; &quot;\&quot; &amp; objFileSystem.GetBaseName(obj.Filename)
WriteDebug &quot;Model folder location: &quot; &amp; strModelFolderLocaton

&#39; Check if there is a MDDE Export extension enabled and invoke the initializer
If obj.getExtendedAttribute(cMDDE_EXT_CODE &amp;&quot;.mdde_Export_Extension_Attached&quot;) Then
WriteInfo &quot;MDDE LDM Export extension found, start initializion&quot;
obj.ExecuteCustomMethod cMDDE_EXT_CODE &amp; &quot;.mdde_InitializeExportExtension&quot;
Dim exportInitializationSuccess: exportInitializationSuccess = obj.getExtendedAttribute (cMDDE_EXT_CODE &amp; &quot;.&quot; &amp; cMDDE_EXPORT_EXTENSION_INITIALIZATION_INDICATOR)
If exportInitializationSuccess Then
WriteInfo &quot;MDDE LDM Export extension initializion successful&quot;
Else
WriteError &quot;MDDE LDM Export extension initializion failed&quot;
Exit Sub
End If
End If

&#39; Update the generation path so the XML export is written to the same folder as the decomposed model.
obj.GetPackageOptions().GenerationPath = Replace(strModelFolderLocaton, cMDDE_PDC_COMPOSED_FOLDER, cMDDE_PDC_DECOMPOSED_FOLDER)

Expand All @@ -34,5 +47,7 @@
&#39; Revert the generation path to the original value.
obj.GetPackageOptions().GenerationPath = strGenerationPath

End Sub</a:MethodScript>
End Sub

</a:MethodScript>
</o:MethodTargetItem>
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
<o:MethodTargetItem Id="A2DF8843-2E87-46FC-9263-927B3E02D9E8">
<a:ObjectID>A2DF8843-2E87-46FC-9263-927B3E02D9E8</a:ObjectID>
<a:Name>mdde_InitializeExportExtension</a:Name>
<a:CreationDate>1701423896</a:CreationDate>
<a:Creator>WillemOtten</a:Creator>
<a:Comment>This method is included in the extension to load the contents of templates that are defined in the optionally attached export extension.
Since it is not possible to directly access the GTL templates in another extension via GTL, the contents of these templates is loaded in local extended attributes so it can be included in the XML export</a:Comment>
<a:TargetCategory.Type>1</a:TargetCategory.Type>
<a:MethodScript>Sub %Method%(obj)

WriteInfo &quot;MDDE LDM Export extension initializion started&quot;


Dim errorsFound: errorsFound = False
Dim templateAppliedWithoutErrors: templateAppliedWithoutErrors = False
Dim childPackagesProcessedWithoutErrors: childPackagesProcessedWithoutErrors = False

&#39;Set the mddex contents attribute on model
templateAppliedWithoutErrors = applyTemplateOnObject (obj, obj, &quot;mddex_Model_Export_Template&quot;, &quot;mddex_Model_Export_Content&quot;)
If templateAppliedWithoutErrors = False Then
errorsFound = True
End If

templateAppliedWithoutErrors = applyTemplateOnObject (obj, obj, cMDDE_NAMEDOBJECT_ATTRIBUTE_EXPORT_TEMPLATE_NAME, cMDDE_NAMEDOBJECT_ATTRIBUTE_EXPORT_ATTRIBUTE_NAME)
If templateAppliedWithoutErrors = False Then
errorsFound = True
End If

&#39;Process all child objects recursively in all packages
childPackagesProcessedWithoutErrors = processPackage (obj, obj)
If childPackagesProcessedWithoutErrors = False Then
errorsFound = True
End If

WriteInfo &quot;MDDE LDM Export extension initializion finished&quot;

&#39;Set initialization indicator to true
If errorsFound = True Then
Msgbox &quot;There where errors processing the MDDE LDM Export extension, consult the script output window for more information.&quot;
Else
obj.setExtendedAttribute cMDDE_EXT_CODE &amp; &quot;.&quot; &amp; cMDDE_EXPORT_EXTENSION_INITIALIZATION_INDICATOR, True
End If
End Sub

&#39; Check if the GTL output contains errors
Function GTLOutputHasErrors(GTLResult)
GTLOutputHasErrors = False
If InStr(GTLResult, cMDDE_EXPORT_EXTENSION_CODE &amp; &quot;::Profile&quot;) Then
GTLOutputHasErrors = True
End If
End Function

Function processPackage(objModel, objPackage)

Dim collectionProcessedWithoutErrors, childPackagesProcessedWithoutErrors
processPackage = True
collectionProcessedWithoutErrors = False
childPackagesProcessedWithoutErrors = False

&#39;Loop over Entities
collectionProcessedWithoutErrors = applyTemplateOnCollection(objModel, objPackage.Entities, &quot;mddex_Entity_Export_Template&quot;, &quot;mddex_Entity_Export_Content&quot;, True)
If collectionProcessedWithoutErrors = False Then
processPackage = False
End If

&#39;Loop over Entity Attributes
collectionProcessedWithoutErrors = applyTemplateOnCollection(objModel, objPackage.EntityAttributes, &quot;mddex_EntityAttribute_Export_Template&quot;, &quot;mddex_EntityAttribute_Export_Content&quot;, True)
If collectionProcessedWithoutErrors = False Then
processPackage = False
End If

&#39;Loop over Mappings
collectionProcessedWithoutErrors = applyTemplateOnCollection(objModel, objPackage.Mappings, &quot;mddex_BaseClassifierMapping_Export_Template&quot;, &quot;mddex_BaseClassifierMapping_Export_Content&quot;, True)
If collectionProcessedWithoutErrors = False Then
processPackage = False
End If

&#39;Loop over AttributeMappings
collectionProcessedWithoutErrors = applyTemplateOnCollection(objModel, objPackage.ModelEntityAttributeMappings, &quot;mddex_BaseStructuralFeatureMapping_Export_Template&quot;, &quot;mddex_BaseStructuralFeatureMapping_Export_Content&quot;, False)
If collectionProcessedWithoutErrors = False Then
processPackage = False
End If

&#39;Loop over packages
Dim childPackage
For Each childPackage in objPackage.Packages
childPackagesProcessedWithoutErrors = processPackage (objModel, childPackage)
If childPackagesProcessedWithoutErrors = False Then
processPackage = False
End If
Next

End Function

&#39;Apply template on object and check for translation errors
Function applyTemplateOnObject(objModel, objItem, templateName, extendedAttributeName)
&#39;Process the object specific template
Dim evaluatedTemplate: evaluatedTemplate = objItem.EvaluateTemplateFor(templateName, cMDDE_EXPORT_EXTENSION_CODE)
applyTemplateOnObject = True
&#39;Clear the extended attribute if it is set
If objItem.getExtendedAttributeText(extendedAttributeName) &lt;&gt; &quot;&quot; Then
objItem.setExtendedAttribute extendedAttributeName, Nothing
End If

&#39; Only set the extended attribute if the template evaluation gave a non-empty result
If Not evaluatedTemplate = empty And Not evaluatedTemplate = &quot;&quot; Then
objItem.setExtendedAttribute extendedAttributeName, evaluatedTemplate
If GTLOutputHasErrors(objItem.getExtendedAttribute(extendedAttributeName)) Then
WriteError (&quot;Error parsing template &quot; &amp; templateName &amp; &quot; for &quot; &amp; objItem.Code)
&#39;Set success indicator to false
objModel.setExtendedAttribute cMDDE_EXT_CODE &amp; &quot;.&quot; &amp; cMDDE_EXPORT_EXTENSION_INITIALIZATION_INDICATOR, False
applyTemplateOnObject = False
End If
End If

End Function


Function applyTemplateOnCollection(objModel, objCollection, templateName, extendedAttributeName, applyNamedObjectTemplate)
Dim obj, metaClassTemplateAppliedWithoutErrors, namedObjectTemplateAppliedWithoutErrors
&#39;Set default template and attribute that apply to all object types
Dim attributeTemplateName: attributeTemplateName = &quot;mddex_NamedObject_Attributes_Export_Template&quot;
Dim attributeExtendedAttributeName: attributeExtendedAttributeName = &quot;mddex_NamedObject_Attributes_Export_Content&quot;

applyTemplateOnCollection = True
metaClassTemplateAppliedWithoutErrors = True
namedObjectTemplateAppliedWithoutErrors = True
&#39;Loop over collection and set the extended attribute based on the export template
&#39;If specified, also apply the namedobject template for adding custom attributes to the element
For Each obj in objCollection
If Not obj.IsShortCut Then
metaClassTemplateAppliedWithoutErrors = applyTemplateOnObject (objModel, obj, templateName, extendedAttributeName)
If applyNamedObjectTemplate Then
namedObjectTemplateAppliedWithoutErrors = applyTemplateOnObject (objModel, obj, attributeTemplateName, attributeExtendedAttributeName)
End If
If metaClassTemplateAppliedWithoutErrors = False Or namedObjectTemplateAppliedWithoutErrors = False Then
applyTemplateOnCollection = False
End If
End If
Next
End Function
</a:MethodScript>
</o:MethodTargetItem>
1 change: 1 addition & 0 deletions decomposed/extensions/MDDE_LDM/Profile/Model/Model.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
<xi:include href="Menus/Menus.xml" />
<xi:include href="Templates/Templates.xml" />
<xi:include href="Generated_Files/Generated_Files.xml" />
<xi:include href="Extended_Attributes/Extended_Attributes.xml" />
</c:Categories>
</o:MetaClassTargetItem>
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@

.comment Include the package contents (a model is also a package).
%mdde_BasePackage_XmlExport_Template%
.comment Add the content of the export extension template
.if (%mdde_Export_Extension_Attached%)
.if(%.D:mddex_Model_Export_Content%)
%.D:mddex_Model_Export_Content%
.endif
.endif()

&lt;/Model&gt;</a:TemplateTargetItem.Value>
<a:CreationDate>1651665197</a:CreationDate>
<a:Creator>WesselsH1</a:Creator>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@
<a:TemplateTargetItem.Value>Id=&quot;%ObjectID%&quot; Code=&quot;%Code%&quot; Name=&quot;%Name%&quot;
.if (%Stereotype%)
Stereotype=&quot;%Stereotype%&quot;
.endif</a:TemplateTargetItem.Value>
.endif
.comment Add the content of the export extension template
.if (%Model.mdde_Export_Extension_Attached%)
.if(%.D:mddex_NamedObject_Attributes_Export_Content%)
%.D:mddex_NamedObject_Attributes_Export_Content%
.endif
.endif
</a:TemplateTargetItem.Value>
<a:CreationDate>1651665197</a:CreationDate>
<a:Creator>WesselsH1</a:Creator>
<a:TargetCategory.Type>1</a:TargetCategory.Type>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<a:CheckGlobalScript>&#39;******************************************************************************
&#39;* Purpose: This script holds global definitions shared by all the custom-
&#39;* checks scripts of the model extension.
&#39;******************************************************************************

Option Explicit &#39; This is to ensure all used variables are defined

</a:CheckGlobalScript>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<o:TargetCategory Id="4FA71D60-5526-4E0B-BFD7-8DD3DC0F71CE">
<a:ObjectID>4FA71D60-5526-4E0B-BFD7-8DD3DC0F71CE</a:ObjectID>
<a:Name>Generation</a:Name>
<a:CreationDate>1700834012</a:CreationDate>
<a:Creator>WillemOtten</a:Creator>
</o:TargetCategory>
Loading

0 comments on commit e641d57

Please sign in to comment.