Skip to content

Commit

Permalink
Merge pull request #28 from costezki/feature/EP-104
Browse files Browse the repository at this point in the history
ep-106 and ep-104
  • Loading branch information
costezki authored May 31, 2020
2 parents 6b2019e + fb69e7b commit dc269c9
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 50 deletions.
50 changes: 50 additions & 0 deletions src/common/utils.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -357,4 +357,54 @@
/>
</xsl:function>

<xd:doc>
<xd:desc/>
<xd:param name="multiplicityString"/>
</xd:doc>
<xsl:function name="f:getMultiplicityMinFromString">
<xsl:param name="multiplicityString"/>
<xsl:variable name="min" select="fn:substring-before($multiplicityString, '..')"/>
<xsl:sequence
select="
if ($min = '' or $min = '*') then
()
else
$min"
/>
</xsl:function>

<xd:doc>
<xd:desc/>
<xd:param name="multiplicityString"/>
</xd:doc>
<xsl:function name="f:getMultiplicityMaxFromString">
<xsl:param name="multiplicityString"/>
<xsl:variable name="max" select="fn:substring-after($multiplicityString, '..')"/>
<xsl:sequence
select="
if ($max = '' or $max = '*') then
()
else
$max"
/>
</xsl:function>

<xd:doc>
<xd:desc/>
<xd:param name="multiplicityString"/>
</xd:doc>
<xsl:function name="f:normalizeMultiplicity">
<xsl:param name="multiplicityString"/>
<xsl:sequence
select="
if (fn:contains($multiplicityString, '..')) then
$multiplicityString
else
if (not(boolean($multiplicityString)) or $multiplicityString = '' or $multiplicityString = '*') then
()
else
fn:concat($multiplicityString, '..', $multiplicityString)"
/>
</xsl:function>

</xsl:stylesheet>
75 changes: 27 additions & 48 deletions src/shacl-shape-lib/connectors-shacl-shape.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -143,38 +143,43 @@

<xsl:template name="connectorMultiplicity">
<xsl:param name="connector"/>
<xsl:variable name="targetMultiplicity"
select="f:normalizeMultiplicity($connector/target/type/@multiplicity)"/>
<xsl:variable name="targetMultiplicityMin"
select="fn:substring($connector/target/type/@multiplicity, 1, 1)"/>
select="f:getMultiplicityMinFromString($targetMultiplicity)"/>
<xsl:variable name="targetMultiplicityMax"
select="fn:substring($connector/target/type/@multiplicity, 4, 1)"/>
select="f:getMultiplicityMaxFromString($targetMultiplicity)"/>
<xsl:variable name="sourceMultiplicity"
select="f:normalizeMultiplicity($connector/source/type/@multiplicity)"/>
<xsl:variable name="sourceMultiplicityMin"
select="fn:substring($connector/source/type/@multiplicity, 1, 1)"/>
select="f:getMultiplicityMinFromString($sourceMultiplicity)"/>
<xsl:variable name="sourceMultiplicityMax"
select="fn:substring($connector/source/type/@multiplicity, 4, 1)"/>
select="f:getMultiplicityMaxFromString($sourceMultiplicity)"/>
<xsl:variable name="sourceClassURI"
select="f:buildURIfromLexicalQName($connector/source/model/@name, fn:true())"/>
<!-- <xsl:value-of select="$connector/target/type/@multiplicity"/>-->
<!--<xsl:value-of select="$targetMultiplicity"/>-->
<xsl:variable name="sourceRole"
select="
if (boolean($connector/source/role/@name)) then
f:lexicalQNameToWords($connector/source/role/@name)
else ()
"/>
if (boolean($connector/source/role/@name)) then
f:lexicalQNameToWords($connector/source/role/@name)
else
()
"/>
<xsl:variable name="sourceRoleURI"
select="
if (boolean($sourceRole)) then
f:buildURIfromLexicalQName($sourceRole, fn:false())
else
()"
/>
()"/>
<xsl:variable name="targetClassURI"
select="f:buildURIfromLexicalQName($connector/target/model/@name, fn:true())"/>
<xsl:variable name="targetRole"
select="
if (boolean($connector/target/role/@name)) then
f:lexicalQNameToWords($connector/target/role/@name)
else
concat($mockUnknownPrefix, ':', $mockUnnamedElement)"
/>
concat($mockUnknownPrefix, ':', $mockUnnamedElement)"/>
<xsl:variable name="targetRoleURI"
select="f:buildURIfromLexicalQName($targetRole, fn:false())"/>
<xsl:variable name="connectorDirection" select="$connector/properties/@direction"/>
Expand All @@ -183,29 +188,20 @@
<xsl:if
test="
$connectorDirection = 'Source -&gt; Destination' and
$connector/target/type/not(@multiplicity) = fn:false()">
boolean($targetMultiplicity)">
<sh:NodeShape rdf:about="{$sourceClassURI}">
<sh:property>
<sh:PropertyShape>
<sh:path rdf:resource="{$targetRoleURI}"/>
<sh:name>
<xsl:value-of select="$targetRole"/>
</sh:name>
<xsl:if
test="$targetMultiplicityMin != '*' and $targetMultiplicityMax != '*'">
<sh:minCount rdf:datatype="{$datatypeURI}">
<xsl:value-of select="$targetMultiplicityMin"/>
</sh:minCount>
<sh:maxCount rdf:datatype="{$datatypeURI}">
<xsl:value-of select="$targetMultiplicityMax"/>
</sh:maxCount>
</xsl:if>
<xsl:if test="$targetMultiplicityMin = '*'">
<xsl:if test="boolean($targetMultiplicityMax)">
<sh:maxCount rdf:datatype="{$datatypeURI}">
<xsl:value-of select="$targetMultiplicityMax"/>
</sh:maxCount>
</xsl:if>
<xsl:if test="$targetMultiplicityMax = '*'">
<xsl:if test="boolean($targetMultiplicityMin)">
<sh:minCount rdf:datatype="{$datatypeURI}">
<xsl:value-of select="$targetMultiplicityMin"/>
</sh:minCount>
Expand All @@ -217,29 +213,20 @@
<xsl:if
test="
$connectorDirection = 'Bi-Directional' and
$connector/target/type/not(@multiplicity) = fn:false()">
boolean($targetMultiplicity)">
<sh:NodeShape rdf:about="{$sourceClassURI}">
<sh:property>
<sh:PropertyShape>
<sh:path rdf:resource="{$targetRoleURI}"/>
<sh:name>
<xsl:value-of select="$targetRole"/>
</sh:name>
<xsl:if
test="$targetMultiplicityMin != '*' and $targetMultiplicityMax != '*'">
<sh:minCount rdf:datatype="{$datatypeURI}">
<xsl:value-of select="$targetMultiplicityMin"/>
</sh:minCount>
<sh:maxCount rdf:datatype="{$datatypeURI}">
<xsl:value-of select="$targetMultiplicityMax"/>
</sh:maxCount>
</xsl:if>
<xsl:if test="$targetMultiplicityMin = '*'">
<xsl:if test="boolean($targetMultiplicityMax)">
<sh:maxCount rdf:datatype="{$datatypeURI}">
<xsl:value-of select="$targetMultiplicityMax"/>
</sh:maxCount>
</xsl:if>
<xsl:if test="$targetMultiplicityMax = '*'">
<xsl:if test="boolean($targetMultiplicityMin)">
<sh:minCount rdf:datatype="{$datatypeURI}">
<xsl:value-of select="$targetMultiplicityMin"/>
</sh:minCount>
Expand All @@ -251,29 +238,20 @@
<xsl:if
test="
$connectorDirection = 'Bi-Directional' and
$connector/source/type/not(@multiplicity) = fn:false()">
boolean($sourceMultiplicity)">
<sh:NodeShape rdf:about="{$targetClassURI}">
<sh:property>
<sh:PropertyShape>
<sh:path rdf:resource="{$sourceRoleURI}"/>
<sh:name>
<xsl:value-of select="$sourceRole"/>
</sh:name>
<xsl:if
test="$sourceMultiplicityMin != '*' and $sourceMultiplicityMax != '*'">
<sh:minCount rdf:datatype="{$datatypeURI}">
<xsl:value-of select="$sourceMultiplicityMin"/>
</sh:minCount>
<xsl:if test="boolean($sourceMultiplicityMax)">
<sh:maxCount rdf:datatype="{$datatypeURI}">
<xsl:value-of select="$sourceMultiplicityMax"/>
</sh:maxCount>
</xsl:if>
<xsl:if test="$sourceMultiplicityMin = '*'">
<sh:maxCount rdf:datatype="{$datatypeURI}">
<xsl:value-of select="$sourceMultiplicityMax"/>
</sh:maxCount>
</xsl:if>
<xsl:if test="$sourceMultiplicityMax = '*'">
<xsl:if test="boolean($sourceMultiplicityMin)">
<sh:minCount rdf:datatype="{$datatypeURI}">
<xsl:value-of select="$sourceMultiplicityMin"/>
</sh:minCount>
Expand All @@ -282,6 +260,7 @@
</sh:property>
</sh:NodeShape>
</xsl:if>

</xsl:template>

<xd:doc>
Expand Down
4 changes: 2 additions & 2 deletions test/testData/ePO-CM-v2.0.2-2020-05-17_test.eap.xmi
Original file line number Diff line number Diff line change
Expand Up @@ -44223,7 +44223,7 @@
<target xmi:idref="EAID_E84B97D8_2656_498d_B584_D95C2DBBD7A1">
<model ea_localid="1294" type="Class" name="epo:Agent"/>
<role visibility="Public" targetScope="instance"/>
<type aggregation="none" containment="Unspecified"/>
<type aggregation="none" containment="Unspecified" multiplicity="1"/>
<constraints/>
<modifiers isOrdered="false" changeable="none" isNavigable="true"/>
<style value="Union=0;Derived=0;AllowDuplicates=0;Owned=0;Navigable=Navigable;"/>
Expand Down Expand Up @@ -50211,7 +50211,7 @@
<target xmi:idref="EAID_9D96D0CB_35A7_4908_87DB_EE8B4980064B">
<model ea_localid="23" type="Class" name="epo:Tender"/>
<role name="epo:evaluates" visibility="Public" targetScope="instance"/>
<type multiplicity="0..n" aggregation="none" containment="Unspecified"/>
<type multiplicity="*" aggregation="none" containment="Unspecified"/>
<constraints/>
<modifiers isOrdered="false" changeable="none" isNavigable="true"/>
<style value="Union=0;Derived=0;AllowDuplicates=0;Owned=0;Navigable=Navigable;"/>
Expand Down
22 changes: 22 additions & 0 deletions test/unitTests/test-common/test-utils.xspec
Original file line number Diff line number Diff line change
Expand Up @@ -351,4 +351,26 @@
<x:expect label="result" select="string('Long integer')"/>
</x:scenario>


<x:scenario label="Scenario for getting the min value for multiplicity">
<x:call function="f:getMultiplicityMinFromString">
<x:param name="multiplicityString" href="../../testData/ePO-CM-v2.0.2-2020-05-17_test.eap.xmi" select="/xmi:XMI/xmi:Extension[1]/connectors[1]/connector[41]/target/type/@multiplicity"/>
</x:call>
<x:expect label="result" select="string('0')"/>
</x:scenario>

<x:scenario label="Scenario for getting the max value for multiplicity">
<x:call function="f:getMultiplicityMaxFromString">
<x:param name="multiplicityString" href="../../testData/ePO-CM-v2.0.2-2020-05-17_test.eap.xmi" select="/xmi:XMI/xmi:Extension[1]/connectors[1]/connector[41]/target/type/@multiplicity"/>
</x:call>
<x:expect label="result" select="string('1')"/>
</x:scenario>

<x:scenario label="Scenario for formatting the value of multiplicity to have a min and max">
<x:call function="f:normalizeMultiplicity">
<x:param name="multiplicityString" href="../../testData/ePO-CM-v2.0.2-2020-05-17_test.eap.xmi" select="/xmi:XMI/xmi:Extension[1]/connectors[1]/connector[42]/target/type/@multiplicity"/>
</x:call>
<x:expect label="result" select="string('1..1')"/>
</x:scenario>

</x:description>
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@
<x:expect label="expect to do nothing" select="()"/>
</x:scenario>

<x:scenario label="Scenario for multiplicity in data shape layer when the connector has Source -&gt; Destination direction and the target multiplicity is *">
<x:call template="connectorMultiplicity">
<x:param name="connector" href="../../testData/ePO-CM-v2.0.2-2020-05-17_test.eap.xmi" select="/xmi:XMI/xmi:Extension[1]/connectors[1]/connector[216]"/>
</x:call>
<x:expect label="expect to do nothing" select="()"/>
</x:scenario>

<x:scenario label="Scenario for multiplicity in data shape layer when the connector has Bi-Directional direction and only the target has multiplicity ">
<x:call template="connectorMultiplicity">
<x:param name="connector" href="../../testData/ePO-CM-v2.0.1-2020-03-27_test.eap.xmi" select="/xmi:XMI/xmi:Extension[1]/connectors[1]/connector[56]"/>
Expand Down

0 comments on commit dc269c9

Please sign in to comment.