Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New and updated model checks, improved XML export and bug fixes #15

Merged
merged 6 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
<a:Creator>WesselsH1</a:Creator>
<a:TargetCategory.Type>1</a:TargetCategory.Type>
<c:Categories>
<xi:include href="mdde_Classifier_IsMDDEMapping/mdde_Classifier_IsMDDEMapping.xml" />
<xi:include href="mdde_Criterion_IsMDDEMapping/mdde_Criterion_IsMDDEMapping.xml" />
</c:Categories>
</o:TypedCategoryTargetItem>
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<o:CustomCheckTargetItem Id="70F744D4-1B3D-4C91-948B-1095EF0DFD02">
<a:ObjectID>70F744D4-1B3D-4C91-948B-1095EF0DFD02</a:ObjectID>
<a:Name>Check duplicate source objects (MDDE)</a:Name>
<a:CreationDate>1704977369</a:CreationDate>
<a:Creator>WesselsH1</a:Creator>
<a:Comment>Check whether there are duplicate source objects in the mapping (meaning the same joined object with join conditions and offset period exists as a source object more then once).</a:Comment>
<a:TargetCategory.Type>1</a:TargetCategory.Type>
<a:HelpMessage>This check ensures that there are no are duplicate source objects in the mapping (meaning the same joined object with join conditions and offset period exists as a source object more then once).</a:HelpMessage>
<a:OutputMessage>The following mapping have one or more duplicate source objects:</a:OutputMessage>
<a:CheckScript>Function %Check%(obj)
&#39; Create all arrays to be used in this function.
&#39; The arrays must be created at the beginning, otherwise VBScript will complain (because of compile issues).
Dim arrSourceObjectKeyParts(), arrJoinConditionKeyParts()

&#39; Initialize the result with true.
%Check% = True

&#39; Create an array to store the source objects found so far.
Dim colSourceObjectKeys : Set colSourceObjectKeys = CreateObject(&quot;System.Collections.ArrayList&quot;)

&#39; Retrieve the source objects from the mapping.
Dim colSourceObjects : Set colSourceObjects = obj.GetExtendedCollection(&quot;mdde_SourceObjects&quot;)

&#39; If the mapping has no source objects, stop here.
If colSourceObjects.Count = 0 Then
Exit Function
End If

&#39; Now loop though all source objects and construct a unique string to compare the source objects on.
Dim objSourceObject
For Each objSourceObject In colSourceObjects
&#39; Get the joined object.
Dim objJoinedObject : Set objJoinedObject = objSourceObject.GetExtendedAttribute(&quot;mdde_JoinedObject&quot;)

&#39; If the joined object is nothing (unset), skip this source object.
If Not(objJoinedObject Is Nothing) Then

&#39; We will use: SourceObject.JoinedObject.Code + SourceObject.JoinType + SourceObject.OffsetPeriod + SourceObject.OffsetValue + SourceObject.JoinConditions
&#39; The JoinConditions collection should be alphabetically sorted to make sure we also find equal onces if the order of the joins is different.

&#39; Get the collection with join conditions of the current source object.
Dim objJoinConditions : Set objJoinConditions = objSourceObject.GetExtendedCollection(&quot;mdde_JoinConditions&quot;)

&#39; If there are no join conditions, skip creating the join conditions part.
If Not(objJoinConditions Is Nothing) And objJoinConditions.Count &gt; 0 Then

&#39; Create an array to contain the join condition key parts.
ReDim arrJoinConditionKeyParts(objJoinConditions.Count)
&#39; Loop through the join conditions and make a sortable array of join conditions.
Dim intCurrentJoinConditionIndex
For intCurrentJoinConditionIndex = 0 To objJoinConditions.Count - 1
Dim objJoinCondition : Set objJoinCondition = objJoinConditions.Item(intCurrentJoinConditionIndex)
&#39; Use the Xml Export template to get a textual representation of the join condition.
Dim TTI : Set TTI = obj.Model.FindMetaExtensionByName(objJoinCondition, PdCommon.cls_TemplateTargetItem, &quot;mdde_JoinCondition_XmlExport_Template&quot;)
Dim strJoinConditionKey : strJoinConditionKey = objJoinCondition.EvaluateTemplate(&quot;mdde_JoinCondition_XmlExport_Template&quot;, TTI)

&#39; Now we need to insert the key at the right place in the array (so the array stays alphabetically sorted).
&#39; So we loop over the array until we find a join condition key which is larger then the current one (or we reach the end).
&#39; Then we know at which position the new key needs to be and which keys to move up one position.
Dim intCompareJoinConditionIndex
Dim intNewJoinConditionKeyIndex : intNewJoinConditionKeyIndex = intCurrentJoinConditionIndex
For intCompareJoinConditionIndex = 0 To intCurrentJoinConditionIndex
&#39; If we find the first key which is larger then the current one, we have found the position to store the new key in.
If arrJoinConditionKeyParts(intCompareJoinConditionIndex) &gt; strJoinConditionKey Then
&#39; Update the new join condition key index to the found position.
intNewJoinConditionKeyIndex = intCompareJoinConditionIndex
&#39; This means we have to move all keys from this position onwards one index further.
&#39; So we loop from the index of the new key to the last index in reverse order
Dim intOldJoinConditionIndex
For intOldJoinConditionIndex = intCurrentJoinConditionIndex - 1 To intNewJoinConditionKeyIndex Step -1
&#39; Move the value of the key one index further.
arrJoinConditionKeyParts(intOldJoinConditionIndex + 1) = arrJoinConditionKeyParts(intOldJoinConditionIndex)
&#39; To be sure, empty the value on the old position.
arrJoinConditionKeyParts(intOldJoinConditionIndex) = vbEmpty
Next

&#39; Since we found the right place, we can exit the loop.
Exit For
End If
Next

&#39; Update the array to have the new join condition key at the designated index.
arrJoinConditionKeyParts(intNewJoinConditionKeyIndex) = strJoinConditionKey
Next
End If

&#39; Create an array to store the source object key parts.
&#39; Initialize the array for 5 items in it (so upperbound 4).
ReDim arrSourceObjectKeyParts(4)

&#39; Construct the first part of the source object key.
arrSourceObjectKeyParts(0) = objJoinedObject.Code
arrSourceObjectKeyParts(1) = objSourceObject.GetExtendedAttributeText(&quot;mdde_JoinType&quot;)
arrSourceObjectKeyParts(2) = objSourceObject.GetExtendedAttributeText(&quot;mdde_OffsetPeriod&quot;)
arrSourceObjectKeyParts(3) = objSourceObject.GetExtendedAttributeText(&quot;mdde_OffsetValue&quot;)
arrSourceObjectKeyParts(4) = Join(arrJoinConditionKeyParts, &quot;&amp;&quot;)

&#39; Construct the textual representation of the source object key by joining the key parts together.
Dim strSourceObjectKey : strSourceObjectKey = Join(arrSourceObjectKeyParts, &quot;|&quot;)
&#39; Now check whether the source object key already exists in the keys collection.
&#39; If so we have found a duplicate, so report it.
If colSourceObjectKeys.Contains(strSourceObjectKey) Then
WriteError(&quot;The mapping &#39;&quot; &amp; obj.DisplayName &amp; &quot;&#39; contains duplicate source objects, where the duplicate source object is: &#39;&quot; &amp; objSourceObject.DisplayName &amp; &quot;&#39;&quot;)
WriteDebug(&quot; &gt; Duplicate key: &quot; &amp; strSourceObjectKey)
%Check% = False
&#39; If we haven&#39;t found the key yet, add it to the key collection.
Else
colSourceObjectKeys.Add strSourceObjectKey
End If

End If
Next
End Function</a:CheckScript>
<a:AutoFixScrpt>Function %Fix%(obj, outmsg)
&#39; Implement your automatic correction on &lt;obj&gt; here
&#39; filling &lt;outmsg&gt; as you wish
&#39; and return True if successful.

outmsg = &quot;Automatic correction not implemented&quot;

%Fix% = False
End Function</a:AutoFixScrpt>
</o:CustomCheckTargetItem>
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
<a:TargetCategory.Type>1</a:TargetCategory.Type>
<c:Categories>
<xi:include href="mdde_Check_OrderOfSourceObjects.xml" />
<xi:include href="Check_duplicate_source_objects_(MDDE).xml" />
</c:Categories>
</o:TypedCategoryTargetItem>
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Function CheckSourceObjects(objMapping, boolAutoFix)

&#39; Check whether the from is the first source join.
If UCase(colSourceObjects.Item(0).GetExtendedAttributeText(&quot;mdde_JoinType&quot;)) &lt;&gt; &quot;FROM&quot; Then
WriteError(&quot;Mapping &#39;&quot; &amp; objMapping.DisplayName &amp; &quot;&#39;: The first source objects in the mapping doesn&#39;t have join type &#39;FROM&#39;!&quot;)
WriteError(&quot;Mapping &#39;&quot; &amp; objMapping.DisplayName &amp; &quot;&#39;: The first source object in the mapping doesn&#39;t have join type &#39;FROM&#39;!&quot;)
CheckSourceObjects = False
Exit Function
End If
Expand All @@ -43,7 +43,7 @@ Function CheckSourceObjects(objMapping, boolAutoFix)

&#39; Loop over all remaining source objects to check it&#39;s join conditions (we take count - 1 since the index is starting at 0).
Dim intSourceObjectCount : intSourceObjectCount = colSourceObjects.Count - 1
&#39; We start at index 1, since the FROM source object is at index 0. We don&#39;t need to check the FROM source object, since it has not join conditions.
&#39; We start at index 1, since the FROM source object is at index 0. We don&#39;t need to check the FROM source object, since it has no join conditions.
Dim intCurrentSourceObjectIndex
For intCurrentSourceObjectIndex = 1 To intSourceObjectCount
&#39; Store a reference to the current source object,
Expand All @@ -61,7 +61,7 @@ Function CheckSourceObjects(objMapping, boolAutoFix)
&#39; If we are fixing, try to fix the issue.
Else
&#39; Now we loop trough the remaining source object (current index = 1), searching for a source object which we can trade places with.
&#39; This means finding a source object which references only to parent object which are listed above the current source object.
&#39; This means finding a source object where the join condition parent object(s) are all listed above the current source object.
&#39; When we find such a source object we can stop looping and try the current source object again (since it will be checked again later, since it&#39;s position is moved).
&#39; Store wether we have moved anything in the loop below.
Dim boolMovedSomething : boolMovedSomething = False
Expand All @@ -88,7 +88,7 @@ Function CheckSourceObjects(objMapping, boolAutoFix)
&#39; If no valid source object was found for the current index, either the referenced parent side is broken or there is a circular dependency in the mapping.
If boolMovedSomething = False Then
CheckSourceObjects = False
WriteError &quot;Cannnot fix the source object order for source object &#39;&quot; &amp; objCurrentSourceObject.DisplayName &amp; &quot;&#39; in mapping &#39;&quot; &amp; objMapping.DisplayName &amp; &quot;&#39;. There is probably a circular dependency.&quot;
WriteError &quot;Cannot fix the source object order for source object &#39;&quot; &amp; objCurrentSourceObject.DisplayName &amp; &quot;&#39; in mapping &#39;&quot; &amp; objMapping.DisplayName &amp; &quot;&#39;. There is probably a circular dependency.&quot;
Exit Function
End If
End If
Expand All @@ -104,18 +104,27 @@ Function SourceObjectHasInvalidReference(ByRef objSourceObject, ByRef colAvailab
&#39; Initialize the reulst with false.
SourceObjectHasInvalidReference = False

&#39; Loop over the ajcs and check the ajc-sjc against the collections, depending on the join type
&#39; Loop over the sourcebject join conditions and check the referenced objects in the join conditions against the available source objects (uptill now).
Dim objJoinCondition
For Each objJoinCondition in objSourceObject.GetExtendedCollection(&quot;mdde_JoinConditions&quot;)
&#39; Store a reference to the references source object.
Dim objParentSouceObject : Set objParentSouceObject = objJoinCondition.GetExtendedAttribute(&quot;mdde_ParentSourceObject&quot;)

If Not(colAvailableSourceObjects.Contains(objParentSouceObject)) Then
WriteError(&quot;The source object &#39;&quot; &amp; objSourceObject.DisplayName &amp; &quot;&#39; in mapping &#39;&quot; &amp; objSourceObject.ParentObject.DisplayName &amp; &quot;&#39; is referencing a source object &#39;&quot; &amp; objParentSouceObject.DisplayName &amp; &quot;&#39; which is not above the current one.&quot;)
SourceObjectHasInvalidReference = True
Dim objParentSourceObject : Set objParentSourceObject = objJoinCondition.GetExtendedAttribute(&quot;mdde_ParentSourceObject&quot;)
If objParentSourceObject is Nothing Then
Exit Function
End If
next

&#39; Check if parent attribute is a literal value if False it continues
Dim parentIsLiteralValue : parentIsLiteralValue = objJoinCondition.GetExtendedAttribute(&quot;mdde_ParentIsLiteralValue&quot;)
If parentIsLiteralValue = False Then

&#39; Store a reference to the references source object.
If Not(colAvailableSourceObjects.Contains(objParentSourceObject)) Then
WriteError(&quot;The source object &#39;&quot; &amp; objSourceObject.DisplayName &amp; &quot;&#39; in mapping &#39;&quot; &amp; objSourceObject.ParentObject.DisplayName &amp; &quot;&#39; is referencing a source object &#39;&quot; &amp; objParentSourceObject.DisplayName &amp; &quot;&#39; which is not above the current one.&quot;)
SourceObjectHasInvalidReference = True
Exit Function
End If
End If
Next
End Function
</a:CheckScript>
<a:AutoFixScrpt>Function %Fix%(obj, outmsg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@
.foreach_item(mdde_Mapping_Examples,\n &lt;Examples&gt;\n,\n &lt;/Examples&gt;)
%mdde_Example_XmlExport_Template%
.next(\n)
.if (%mdde_NamedObject_XmlElementExport_Template%)

%mdde_NamedObject_XmlElementExport_Template%
.endif
.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%

%.D:mddex_BaseClassifierMapping_Export_Content%
.endif
.endif

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<o:CriterionTargetItem Id="A2A060E6-1927-4A9C-9BBC-0D3021B68C98">
<a:ObjectID>A2A060E6-1927-4A9C-9BBC-0D3021B68C98</a:ObjectID>
<a:Name>mdde_Classifier_IsMDDEMapping</a:Name>
<a:CriterionTargetItem.Value>(%DataSource.Stereotype%==&quot;&quot;) Or (%DataSource.Stereotype%==&quot;mdde_DataSource&quot;)</a:CriterionTargetItem.Value>
<a:Name>mdde_Criterion_IsMDDEMapping</a:Name>
<a:CriterionTargetItem.Value>%DataSource.mdde_IsMDDEDataSource% == &quot;True&quot;</a:CriterionTargetItem.Value>
<a:CreationDate>1701944918</a:CreationDate>
<a:Creator>WillemOtten</a:Creator>
<a:TargetCategory.Type>1</a:TargetCategory.Type>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
<c:Categories>
<xi:include href="Stereotypes/Stereotypes.xml" />
<xi:include href="Forms/Forms.xml" />
<xi:include href="Criteria/Criteria.xml" />
</c:Categories>
</o:MetaClassTargetItem>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<o:TypedCategoryTargetItem Id="8EC2655D-4D06-4870-8B2B-C0CC4132546B">
<a:TypePublicName>CriterionTargetItem</a:TypePublicName>
<a:ObjectID>8EC2655D-4D06-4870-8B2B-C0CC4132546B</a:ObjectID>
<a:Name>Criteria</a:Name>
<a:CreationDate>1709820290</a:CreationDate>
<a:Creator>WesselsH1</a:Creator>
<a:TargetCategory.Type>1</a:TargetCategory.Type>
<c:Categories>
<xi:include href="mdde_Criterion_IsMDDEDataSource/mdde_Criterion_IsMDDEDataSource.xml" />
</c:Categories>
</o:TypedCategoryTargetItem>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<o:TypedCategoryTargetItem Id="04574872-0E16-4BE1-9404-F8EF62AE5918">
<a:TypePublicName>TemplateTargetItem</a:TypePublicName>
<a:ObjectID>04574872-0E16-4BE1-9404-F8EF62AE5918</a:ObjectID>
<a:Name>Templates</a:Name>
<a:CreationDate>1709820334</a:CreationDate>
<a:Creator>WesselsH1</a:Creator>
<a:TargetCategory.Type>1</a:TargetCategory.Type>
<c:Categories>
<xi:include href="mdde_IsMDDEDataSource.xml" />
</c:Categories>
</o:TypedCategoryTargetItem>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<o:TemplateTargetItem Id="B319137E-9329-4A06-82A5-663C4A0E5F3B">
<a:ObjectID>B319137E-9329-4A06-82A5-663C4A0E5F3B</a:ObjectID>
<a:Name>mdde_IsMDDEDataSource</a:Name>
<a:TemplateTargetItem.Value>True</a:TemplateTargetItem.Value>
<a:CreationDate>1709820334</a:CreationDate>
<a:Creator>WesselsH1</a:Creator>
<a:TargetCategory.Type>1</a:TargetCategory.Type>
</o:TemplateTargetItem>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<o:CriterionTargetItem Id="078B9AFB-C42D-4955-B7C1-9488775BD364">
<a:ObjectID>078B9AFB-C42D-4955-B7C1-9488775BD364</a:ObjectID>
<a:Name>mdde_Criterion_IsMDDEDataSource</a:Name>
<a:CriterionTargetItem.Value>(%Stereotype% == null) Or (%Stereotype% == &quot;&quot;) Or (%Stereotype% == &quot;mdde_DataSource&quot;)</a:CriterionTargetItem.Value>
<a:CreationDate>1709820290</a:CreationDate>
<a:Creator>WesselsH1</a:Creator>
<a:TargetCategory.Type>1</a:TargetCategory.Type>
<c:Categories>
<xi:include href="Templates/Templates.xml" />
</c:Categories>
</o:CriterionTargetItem>
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<a:ObjectID>E0D4E34B-C088-4AEB-8CB3-EB21FFF9F211</a:ObjectID>
<a:Name>mdde_BasePackage_XmlExport_Template</a:Name>
<a:TemplateTargetItem.Value>.comment For all child packages, include the output of this template of the child-package.
.foreach_item(Packages,&lt;Packages&gt;\n,\n&lt;/Packages&gt;\n,%IsSelected%==true)
.foreach_item(Packages,&lt;Packages&gt;\n,\n&lt;/Packages&gt;\n,%IsSelected%==true,%Item1.Code% &gt; %Item2.Code%)
%mdde_Package_XmlExport_Template%
.next(\n)
.comment Include all Entities in current Package.
.foreach_item(Entities,&lt;Entities&gt;,\n&lt;/Entities&gt;\n,%IsSelected%==true)
.foreach_item(Entities,&lt;Entities&gt;,\n&lt;/Entities&gt;\n,%IsSelected%==true,%Item1.Code% &gt; %Item2.Code%)
.if (%IsShortcut%==false)

%mdde_Entity_XmlExport_Template%
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<o:TypedCategoryTargetItem Id="94026E1B-A9E5-4BA2-A0EF-B76EF3DBEDF1">
<o:TypedCategoryTargetItem Id="436DE3DF-C43A-416B-9158-D08F0F1D4BB3">
<a:TypePublicName>CriterionTargetItem</a:TypePublicName>
<a:ObjectID>94026E1B-A9E5-4BA2-A0EF-B76EF3DBEDF1</a:ObjectID>
<a:ObjectID>436DE3DF-C43A-416B-9158-D08F0F1D4BB3</a:ObjectID>
<a:Name>Criteria</a:Name>
<a:CreationDate>1701945386</a:CreationDate>
<a:Creator>WillemOtten</a:Creator>
<a:CreationDate>1709791623</a:CreationDate>
<a:Creator>WesselsH1</a:Creator>
<a:TargetCategory.Type>1</a:TargetCategory.Type>
<c:Categories>
<xi:include href="mdde_Criterion_ClassifierIsAggregateBusinessRule/mdde_Criterion_ClassifierIsAggregateBusinessRule.xml" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<o:TypedCategoryTargetItem Id="968AD01E-9187-4A70-95C5-64BF34DA8503">
<o:TypedCategoryTargetItem Id="BB065AFA-729F-4712-B250-558BEEED188A">
<a:TypePublicName>CustomCheckTargetItem</a:TypePublicName>
<a:ObjectID>968AD01E-9187-4A70-95C5-64BF34DA8503</a:ObjectID>
<a:ObjectID>BB065AFA-729F-4712-B250-558BEEED188A</a:ObjectID>
<a:Name>Custom Checks</a:Name>
<a:CreationDate>1701945386</a:CreationDate>
<a:Creator>WillemOtten</a:Creator>
<a:CreationDate>1650377393</a:CreationDate>
<a:Creator>WesselsH1</a:Creator>
<a:TargetCategory.Type>1</a:TargetCategory.Type>
<c:Categories>
<xi:include href="mdde_Check_AttributeMappingHasValidSourceObject.xml" />
Expand Down
Loading
Loading