Skip to content

Commit

Permalink
MIR-1241: refactoring: reducing the number of calls to URI-Resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleksiy 'Alex' Levshyn committed Oct 24, 2023
1 parent 6c84139 commit 4c7a962
Showing 1 changed file with 16 additions and 35 deletions.
51 changes: 16 additions & 35 deletions mir-module/src/main/resources/xsl/response-facets.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@
</xsl:choose>
</xsl:variable>

<!-- Check if a classification named $classId exists -->
<xsl:variable name="is_classification_exist">
<xsl:call-template name="is_classification_exist">
<xsl:with-param name="classId" select="$classId"/>
</xsl:call-template>
<!-- Get the classification named $classId -->
<xsl:variable name="classification">
<xsl:value-of select="concat('notnull:classification:metadata:all:children:',$classId)"/>
</xsl:variable>

<!-- TODO: remove conditions for facets 'worldReadableComplete' and 'mods.genre' after code refactoring -->
Expand Down Expand Up @@ -59,8 +57,8 @@
<xsl:value-of select="i18n:translate(concat('mir.response.facet.', $facet_name, '.title'))"/>
</xsl:when>

<xsl:when test="$is_classification_exist != 'false'">
<xsl:variable name="category_label" select="document(concat('notnull:classification:metadata:all:children:',$classId))/mycoreclass/label[@xml:lang=$CurrentLang]/@text"/>
<xsl:when test="name(document($classification)/*) != 'null'">
<xsl:variable name="category_label" select="document($classification)/mycoreclass/label[@xml:lang=$CurrentLang]/@text"/>
<!-- TODO: need we this choose? -->
<xsl:choose>
<xsl:when test="$category_label != ''">
Expand All @@ -75,6 +73,7 @@
<xsl:otherwise>
<xsl:value-of select="$facet_name"/>
</xsl:otherwise>

</xsl:choose>
</xsl:otherwise>
</xsl:choose>
Expand All @@ -93,6 +92,7 @@
<xsl:with-param name="facet_name" select="$facet_name"/>
<xsl:with-param name="i18nPrefix"
select="'mir.response.openAccess.facet.'"/>
<xsl:with-param name="classification" select="$classification"/>
</xsl:apply-templates>
</xsl:when>

Expand All @@ -102,17 +102,17 @@
select="/response/lst[@name='facet_counts']/lst[@name='facet_fields']">
<xsl:with-param name="facet_name" select="$facet_name"/>
<xsl:with-param name="classId" select="'mir_genres'"/>
<xsl:with-param name="classification" select="$classification"/>
</xsl:apply-templates>
</xsl:when>

<!-- all other facets -->
<xsl:otherwise>

<xsl:apply-templates
select="/response/lst[@name='facet_counts']/lst[@name='facet_fields']">
<xsl:with-param name="facet_name" select="$facet_name"/>
<xsl:with-param name="classId" select="$classId"/>
<xsl:with-param name="is_classification_facet" select="$is_classification_exist"/>
<xsl:with-param name="classification" select="$classification"/>
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
Expand All @@ -129,13 +129,7 @@
<xsl:param name="facet_name"/>
<xsl:param name="classId"/>
<xsl:param name="i18nPrefix"/>
<xsl:param name="is_classification_facet"/>

<xsl:variable name="is_classification_exist">
<xsl:call-template name="is_classification_exist">
<xsl:with-param name="classId" select="$classId"/>
</xsl:call-template>
</xsl:variable>
<xsl:param name="classification"/>

<xsl:for-each select="lst[@name=$facet_name]/int">
<xsl:variable name="fqValue" select="concat($facet_name,':',@name)"/>
Expand Down Expand Up @@ -193,21 +187,13 @@
<span class="title">
<xsl:choose>

<xsl:when test="$is_classification_facet='true'">
<xsl:when test="name(document($classification)/*) != 'null'">
<xsl:variable name="category" select="@name"/>
<xsl:variable name="category_label" select="document($classification)/mycoreclass/categories/category[@ID=$category]/label[@xml:lang=$CurrentLang]/@text"/>
<xsl:choose>
<xsl:when test="$is_classification_exist != 'false'">
<xsl:variable name="category" select="@name"/>
<xsl:variable name="category_label" select="document(concat('notnull:classification:metadata:all:children:',$classId))/mycoreclass/categories/category[@ID=$category]/label[@xml:lang=$CurrentLang]/@text"/>
<xsl:choose>
<xsl:when test="$category_label != ''">
<xsl:value-of select="$category_label"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@name"/>
</xsl:otherwise>
</xsl:choose>
<xsl:when test="$category_label != ''">
<xsl:value-of select="$category_label"/>
</xsl:when>

<xsl:otherwise>
<xsl:value-of select="@name"/>
</xsl:otherwise>
Expand All @@ -233,6 +219,7 @@
<xsl:otherwise>
<xsl:value-of select="@name"/>
</xsl:otherwise>

</xsl:choose>
</span>
<span class="hits">
Expand All @@ -244,10 +231,4 @@
</xsl:for-each>
</xsl:template>

<!-- The template checks if a classification named $classId exists and returns true or false -->
<xsl:template name="is_classification_exist">
<xsl:param name="classId"/>
<xsl:value-of select="name(document(concat('notnull:classification:metadata:all:children:',$classId))/*) != 'null'"/>
</xsl:template>

</xsl:stylesheet>

0 comments on commit 4c7a962

Please sign in to comment.