From 357f461694396a3a5ce51a12f873c94b595ea839 Mon Sep 17 00:00:00 2001
From: Francois Prunayre <fx.prunayre@gmail.com>
Date: Mon, 30 Sep 2024 19:30:13 +0200
Subject: [PATCH] Formatter / DCAT / Applicable legislations

https://semiceu.github.io/DCAT-AP/r5r/releases/3.0.0/#applicableLegislation

Add the element to DCAT-AP base. Element is 0..n in DCAT-AP and should be present in extensions
(mobility, hvd, geodcat).

HVD requires at least http://data.europa.eu/eli/reg_impl/2023/138/oj and
cardinality is 1..n.

Do not restrict to a particular legislation list. A sample vocabulary is
provided but it can be extended depending on catalogue domains.
---
 .../formatter/dcat/dcat-core-keywords.xsl     |  2 +-
 .../eu-dcat-ap-hvd/eu-dcat-ap-hvd-core.xsl    | 60 +++----------------
 ...tion.rdf => eu-applicable-legislation.rdf} | 10 ++--
 .../eu-dcat-ap/eu-dcat-ap-core-dataset.xsl    | 30 ++++++++++
 .../formatter/eu-dcat-ap/eu-dcat-ap-core.xsl  |  4 --
 ...core-multipleAccrualPeriodicityAllowed.rdf |  6 +-
 ...so19115-3.2018-eu-dcat-ap-dataset-core.rdf |  6 +-
 ....2018-eu-dcat-ap-mobility-dataset-core.rdf |  6 +-
 ...9115-3.2018-eu-geodcat-ap-dataset-core.rdf |  6 +-
 9 files changed, 48 insertions(+), 82 deletions(-)
 rename schemas/iso19115-3.2018/src/main/plugin/iso19115-3.2018/formatter/eu-dcat-ap-hvd/vocabularies/{high-value-dataset-applicable-legislation.rdf => eu-applicable-legislation.rdf} (99%)

diff --git a/schemas/iso19115-3.2018/src/main/plugin/iso19115-3.2018/formatter/dcat/dcat-core-keywords.xsl b/schemas/iso19115-3.2018/src/main/plugin/iso19115-3.2018/formatter/dcat/dcat-core-keywords.xsl
index 32d9ecd58d5..25f14d568ec 100644
--- a/schemas/iso19115-3.2018/src/main/plugin/iso19115-3.2018/formatter/dcat/dcat-core-keywords.xsl
+++ b/schemas/iso19115-3.2018/src/main/plugin/iso19115-3.2018/formatter/dcat/dcat-core-keywords.xsl
@@ -5,9 +5,9 @@
                 xmlns:mri="http://standards.iso.org/iso/19115/-3/mri/1.0"
                 xmlns:gco="http://standards.iso.org/iso/19115/-3/gco/1.0"
                 xmlns:gcx="http://standards.iso.org/iso/19115/-3/gcx/1.0"
-                xmlns:xlink="http://www.w3.org/1999/xlink"
                 xmlns:dcat="http://www.w3.org/ns/dcat#"
                 xmlns:skos="http://www.w3.org/2004/02/skos/core#"
+                xmlns:xlink="http://www.w3.org/1999/xlink"
                 exclude-result-prefixes="#all">
 
   <!--
diff --git a/schemas/iso19115-3.2018/src/main/plugin/iso19115-3.2018/formatter/eu-dcat-ap-hvd/eu-dcat-ap-hvd-core.xsl b/schemas/iso19115-3.2018/src/main/plugin/iso19115-3.2018/formatter/eu-dcat-ap-hvd/eu-dcat-ap-hvd-core.xsl
index 6042ca5bacc..d526fc6ac14 100644
--- a/schemas/iso19115-3.2018/src/main/plugin/iso19115-3.2018/formatter/eu-dcat-ap-hvd/eu-dcat-ap-hvd-core.xsl
+++ b/schemas/iso19115-3.2018/src/main/plugin/iso19115-3.2018/formatter/eu-dcat-ap-hvd/eu-dcat-ap-hvd-core.xsl
@@ -19,16 +19,9 @@
   <xsl:variable name="hvdCategoryThesaurusKey"
                 select="'http://data.europa.eu/bna/asd487ae75'"/>
 
-  <xsl:variable name="hvdApplicableLegislationThesaurusKey"
-                select="'http://data.europa.eu/r5r/applicableLegislation'"/>
-
   <xsl:variable name="euHvdDataCategories"
                 select="document('vocabularies/high-value-dataset-category.rdf')"/>
 
-  <xsl:variable name="euHvdApplicableLegislation"
-                select="document('vocabularies/high-value-dataset-applicable-legislation.rdf')"/>
-
-
   <xsl:template mode="iso19115-3-to-dcat-resource"
                 match="mdb:MD_Metadata">
     <xsl:call-template name="iso19115-3-to-dcat-ap-resource"/>
@@ -93,53 +86,16 @@
 
 
   <!--
-  applicable legislation	Legal Resource	1..*	The legislation that mandates the creation or management of the Data Service.	For HVD the value MUST include the ELI http://data.europa.eu/eli/reg_impl/2023/138/oj.
-  As multiple legislations may apply to the resource the maximum cardinality is not limited.		P
-  -->
-  <xsl:template mode="iso19115-3-to-dcat"
-                match="mri:descriptiveKeywords[*/mri:thesaurusName/*/cit:title/*/@xlink:href = $hvdApplicableLegislationThesaurusKey]">
-    <xsl:for-each select="*/mri:keyword[*/text() != '']">
+  applicable legislation	Legal Resource	1..*	The legislation that mandates the creation or management of the Data Service.
+  **For HVD the value MUST include the ELI http://data.europa.eu/eli/reg_impl/2023/138/oj.**
+  As multiple legislations may apply to the resource the maximum cardinality is not limited.
 
-      <xsl:variable name="legislation"
-                    as="xs:string?"
-                    select="current()/*/text()"/>
-      <xsl:variable name="applicableLegislation"
-                    select="$euHvdApplicableLegislation/rdf:RDF/*[skos:prefLabel/normalize-space() = $legislation]"/>
-      <xsl:if test="$applicableLegislation">
-        <dcatap:applicableLegislation rdf:resource="{$applicableLegislation/@rdf:about}">
-          <!--<eli:LegalResource>
-            <xsl:for-each select="$applicableLegislation/skos:prefLabel[@xml:lang = $languages/@iso2code]">
-              <dct:title xml:lang="{@xml:lang}">
-                <xsl:value-of select="."/>
-              </dct:title>
-            </xsl:for-each>
-            <xsl:for-each select="$applicableLegislation/skos:scopeNote[@xml:lang = $languages/@iso2code]">
-              <dct:description xml:lang="{@xml:lang}">
-                <xsl:value-of select="."/>
-              </dct:description>
-            </xsl:for-each>
-          </eli:LegalResource>-->
-        </dcatap:applicableLegislation>
-      </xsl:if>
-    </xsl:for-each>
-  </xsl:template>
+  See DCAT-AP
+  applicable legislation	Legal Resource	0..*	The legislation that mandates the creation or management of the Catalog.
 
-  <xsl:template mode="iso19115-3-to-dcat"
-                match="mri:resourceConstraints/mco:MD_LegalConstraints/mco:reference">
-    <xsl:variable name="href"
-                  select="*/cit:title/*/@xlink:href"/>
-    <xsl:if test="$href">
-      <dcatap:applicableLegislation rdf:resource="{$href}">
-        <!--<eli:LegalResource>
-          <xsl:for-each select="*/cit:title">
-            <xsl:call-template name="rdf-localised">
-              <xsl:with-param name="nodeName" select="'dct:title'"/>
-            </xsl:call-template>
-          </xsl:for-each>
-        </eli:LegalResource>-->
-      </dcatap:applicableLegislation>
-    </xsl:if>
-  </xsl:template>
+  To create valid HVD document, a keyword anchor or a title href of mri:resourceConstraints/mco:MD_LegalConstraints/mco:reference
+  in the ISO record MUST define the ELI http://data.europa.eu/eli/reg_impl/2023/138/oj.
+  -->
 
 
   <xsl:template mode="iso19115-3-to-dcat"
diff --git a/schemas/iso19115-3.2018/src/main/plugin/iso19115-3.2018/formatter/eu-dcat-ap-hvd/vocabularies/high-value-dataset-applicable-legislation.rdf b/schemas/iso19115-3.2018/src/main/plugin/iso19115-3.2018/formatter/eu-dcat-ap-hvd/vocabularies/eu-applicable-legislation.rdf
similarity index 99%
rename from schemas/iso19115-3.2018/src/main/plugin/iso19115-3.2018/formatter/eu-dcat-ap-hvd/vocabularies/high-value-dataset-applicable-legislation.rdf
rename to schemas/iso19115-3.2018/src/main/plugin/iso19115-3.2018/formatter/eu-dcat-ap-hvd/vocabularies/eu-applicable-legislation.rdf
index 2fbcc8cbaae..7502cb45ba2 100644
--- a/schemas/iso19115-3.2018/src/main/plugin/iso19115-3.2018/formatter/eu-dcat-ap-hvd/vocabularies/high-value-dataset-applicable-legislation.rdf
+++ b/schemas/iso19115-3.2018/src/main/plugin/iso19115-3.2018/formatter/eu-dcat-ap-hvd/vocabularies/eu-applicable-legislation.rdf
@@ -3,10 +3,10 @@
          xmlns:dct="http://purl.org/dc/terms/" xmlns:dc="http://purl.org/dc/elements/1.1/"
          xmlns:skos="http://www.w3.org/2004/02/skos/core#">
     <skos:ConceptScheme rdf:about="http://data.europa.eu/r5r/applicableLegislation">
-        <dct:title xml:lang="en">High-value dataset applicable legislations</dct:title>
-        <dct:title xml:lang="fr">High-value dataset applicable legislations</dct:title>
-        <dct:description xml:lang="fr">Législation sectorielle qui prescrit la création ou la gestion de la distribution
-            de données HVD
+        <dct:title xml:lang="en">EU applicable legislations</dct:title>
+        <dct:title xml:lang="fr">Législations applicables dans l'UE</dct:title>
+        <dct:description xml:lang="fr">Législation sectorielle qui prescrit la création ou la gestion de la ressource.
+          Liste non exhaustive.</dct:description>
         </dct:description>
     </skos:ConceptScheme>
     <skos:Concept rdf:about="http://data.europa.eu/eli/reg_impl/2023/138/oj">
@@ -569,4 +569,4 @@
             relative à la qualité des eaux destinées à la consommation humaine (refonte)
         </skos:scopeNote>
     </skos:Concept>
-</rdf:RDF>
\ No newline at end of file
+</rdf:RDF>
diff --git a/schemas/iso19115-3.2018/src/main/plugin/iso19115-3.2018/formatter/eu-dcat-ap/eu-dcat-ap-core-dataset.xsl b/schemas/iso19115-3.2018/src/main/plugin/iso19115-3.2018/formatter/eu-dcat-ap/eu-dcat-ap-core-dataset.xsl
index 6ddeeba3f34..449987dec3f 100644
--- a/schemas/iso19115-3.2018/src/main/plugin/iso19115-3.2018/formatter/eu-dcat-ap/eu-dcat-ap-core-dataset.xsl
+++ b/schemas/iso19115-3.2018/src/main/plugin/iso19115-3.2018/formatter/eu-dcat-ap/eu-dcat-ap-core-dataset.xsl
@@ -9,12 +9,14 @@
                 xmlns:mri="http://standards.iso.org/iso/19115/-3/mri/1.0"
                 xmlns:cit="http://standards.iso.org/iso/19115/-3/cit/2.0"
                 xmlns:gcx="http://standards.iso.org/iso/19115/-3/gcx/1.0"
+                xmlns:mco="http://standards.iso.org/iso/19115/-3/mco/1.0"
                 xmlns:mmi="http://standards.iso.org/iso/19115/-3/mmi/1.0"
                 xmlns:mrl="http://standards.iso.org/iso/19115/-3/mrl/2.0"
                 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
                 xmlns:skos="http://www.w3.org/2004/02/skos/core#"
                 xmlns:dcat="http://www.w3.org/ns/dcat#"
                 xmlns:adms="http://www.w3.org/ns/adms#"
+                xmlns:dcatap="http://data.europa.eu/r5r/"
                 xmlns:dct="http://purl.org/dc/terms/"
                 exclude-result-prefixes="#all">
 
@@ -209,6 +211,34 @@
   </xsl:template>
 
 
+
+  <!--
+  applicable legislation	Legal Resource	0..*	The legislation that mandates the creation or management of the Dataset.
+  -->
+  <xsl:template mode="iso19115-3-to-dcat"
+                match="mri:descriptiveKeywords/*/mri:keyword[starts-with(*/@xlink:href, 'http://data.europa.eu/eli')]"
+                priority="20">
+    <dcatap:applicableLegislation rdf:resource="{*/@xlink:href}"/>
+  </xsl:template>
+
+  <xsl:template mode="iso19115-3-to-dcat"
+                match="mri:resourceConstraints/mco:MD_LegalConstraints/mco:reference">
+    <xsl:variable name="href"
+                  select="*/cit:title/*/@xlink:href"/>
+    <xsl:if test="$href">
+      <dcatap:applicableLegislation rdf:resource="{$href}">
+        <!--<eli:LegalResource>
+          <xsl:for-each select="*/cit:title">
+            <xsl:call-template name="rdf-localised">
+              <xsl:with-param name="nodeName" select="'dct:title'"/>
+            </xsl:call-template>
+          </xsl:for-each>
+        </eli:LegalResource>-->
+      </dcatap:applicableLegislation>
+    </xsl:if>
+  </xsl:template>
+
+
   <!--
   [o]	theme	Concept	0..*	A category of the Dataset.	A Dataset may be associated with multiple themes.	https://w3c.github.io/dxwg/dcat/#Property:resource_theme
   Vocabulary http://publications.europa.eu/resource/authority/data-theme
diff --git a/schemas/iso19115-3.2018/src/main/plugin/iso19115-3.2018/formatter/eu-dcat-ap/eu-dcat-ap-core.xsl b/schemas/iso19115-3.2018/src/main/plugin/iso19115-3.2018/formatter/eu-dcat-ap/eu-dcat-ap-core.xsl
index 492c36f31ab..c566e2a76d7 100644
--- a/schemas/iso19115-3.2018/src/main/plugin/iso19115-3.2018/formatter/eu-dcat-ap/eu-dcat-ap-core.xsl
+++ b/schemas/iso19115-3.2018/src/main/plugin/iso19115-3.2018/formatter/eu-dcat-ap/eu-dcat-ap-core.xsl
@@ -3,12 +3,8 @@
                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                 xmlns:xs="http://www.w3.org/2001/XMLSchema"
                 xmlns:mdb="http://standards.iso.org/iso/19115/-3/mdb/2.0"
-                xmlns:mcc="http://standards.iso.org/iso/19115/-3/mcc/1.0"
-                xmlns:gco="http://standards.iso.org/iso/19115/-3/gco/1.0"
                 xmlns:mrl="http://standards.iso.org/iso/19115/-3/mrl/2.0"
-                xmlns:mri="http://standards.iso.org/iso/19115/-3/mri/1.0"
                 xmlns:cit="http://standards.iso.org/iso/19115/-3/cit/2.0"
-                xmlns:mco="http://standards.iso.org/iso/19115/-3/mco/1.0"
                 xmlns:lan="http://standards.iso.org/iso/19115/-3/lan/1.0"
                 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
                 xmlns:dct="http://purl.org/dc/terms/"
diff --git a/services/src/test/resources/org/fao/geonet/api/records/formatters/iso19115-3.2018-eu-dcat-ap-dataset-core-multipleAccrualPeriodicityAllowed.rdf b/services/src/test/resources/org/fao/geonet/api/records/formatters/iso19115-3.2018-eu-dcat-ap-dataset-core-multipleAccrualPeriodicityAllowed.rdf
index f9570efe923..53c215ebf6a 100644
--- a/services/src/test/resources/org/fao/geonet/api/records/formatters/iso19115-3.2018-eu-dcat-ap-dataset-core-multipleAccrualPeriodicityAllowed.rdf
+++ b/services/src/test/resources/org/fao/geonet/api/records/formatters/iso19115-3.2018-eu-dcat-ap-dataset-core-multipleAccrualPeriodicityAllowed.rdf
@@ -358,11 +358,7 @@
     </dcat:theme>
     <dcat:keyword xml:lang="fre">Mobilité</dcat:keyword>
     <dcat:keyword xml:lang="fre">Observation de la terre et environnement</dcat:keyword>
-    <dcat:theme>
-      <skos:Concept rdf:about="http://data.europa.eu/eli/reg/2014/1143/oj">
-        <skos:prefLabel xml:lang="fre">1143/2014</skos:prefLabel>
-      </skos:Concept>
-    </dcat:theme>
+    <dcatap:applicableLegislation rdf:resource="http://data.europa.eu/eli/reg/2014/1143/oj"/>
     <dct:accessRights>
       <dct:RightsStatement rdf:about="http://inspire.ec.europa.eu/metadata-codelist/LimitationsOnPublicAccess/noLimitations"/>
     </dct:accessRights>
diff --git a/services/src/test/resources/org/fao/geonet/api/records/formatters/iso19115-3.2018-eu-dcat-ap-dataset-core.rdf b/services/src/test/resources/org/fao/geonet/api/records/formatters/iso19115-3.2018-eu-dcat-ap-dataset-core.rdf
index 6520912bc5a..fb929cfe444 100644
--- a/services/src/test/resources/org/fao/geonet/api/records/formatters/iso19115-3.2018-eu-dcat-ap-dataset-core.rdf
+++ b/services/src/test/resources/org/fao/geonet/api/records/formatters/iso19115-3.2018-eu-dcat-ap-dataset-core.rdf
@@ -358,11 +358,7 @@
       </dcat:theme>
       <dcat:keyword xml:lang="fre">Mobilité</dcat:keyword>
       <dcat:keyword xml:lang="fre">Observation de la terre et environnement</dcat:keyword>
-      <dcat:theme>
-         <skos:Concept rdf:about="http://data.europa.eu/eli/reg/2014/1143/oj">
-            <skos:prefLabel xml:lang="fre">1143/2014</skos:prefLabel>
-         </skos:Concept>
-      </dcat:theme>
+     <dcatap:applicableLegislation rdf:resource="http://data.europa.eu/eli/reg/2014/1143/oj"/>
       <dct:accessRights>
          <dct:RightsStatement rdf:about="http://inspire.ec.europa.eu/metadata-codelist/LimitationsOnPublicAccess/noLimitations"/>
       </dct:accessRights>
diff --git a/services/src/test/resources/org/fao/geonet/api/records/formatters/iso19115-3.2018-eu-dcat-ap-mobility-dataset-core.rdf b/services/src/test/resources/org/fao/geonet/api/records/formatters/iso19115-3.2018-eu-dcat-ap-mobility-dataset-core.rdf
index 89ab678ac69..e8f5acf2af0 100644
--- a/services/src/test/resources/org/fao/geonet/api/records/formatters/iso19115-3.2018-eu-dcat-ap-mobility-dataset-core.rdf
+++ b/services/src/test/resources/org/fao/geonet/api/records/formatters/iso19115-3.2018-eu-dcat-ap-mobility-dataset-core.rdf
@@ -359,11 +359,7 @@
       </dcat:theme>
       <dcat:keyword xml:lang="fre">Mobilité</dcat:keyword>
       <dcat:keyword xml:lang="fre">Observation de la terre et environnement</dcat:keyword>
-      <dcat:theme>
-         <skos:Concept rdf:about="http://data.europa.eu/eli/reg/2014/1143/oj">
-            <skos:prefLabel xml:lang="fre">1143/2014</skos:prefLabel>
-         </skos:Concept>
-      </dcat:theme>
+      <dcatap:applicableLegislation rdf:resource="http://data.europa.eu/eli/reg/2014/1143/oj"/>
       <dct:accessRights>
          <dct:RightsStatement rdf:about="http://inspire.ec.europa.eu/metadata-codelist/LimitationsOnPublicAccess/noLimitations"/>
       </dct:accessRights>
diff --git a/services/src/test/resources/org/fao/geonet/api/records/formatters/iso19115-3.2018-eu-geodcat-ap-dataset-core.rdf b/services/src/test/resources/org/fao/geonet/api/records/formatters/iso19115-3.2018-eu-geodcat-ap-dataset-core.rdf
index 506fc04d7bf..429f3a0df93 100644
--- a/services/src/test/resources/org/fao/geonet/api/records/formatters/iso19115-3.2018-eu-geodcat-ap-dataset-core.rdf
+++ b/services/src/test/resources/org/fao/geonet/api/records/formatters/iso19115-3.2018-eu-geodcat-ap-dataset-core.rdf
@@ -359,11 +359,7 @@
       </dcat:theme>
       <dcat:keyword xml:lang="fre">Mobilité</dcat:keyword>
       <dcat:keyword xml:lang="fre">Observation de la terre et environnement</dcat:keyword>
-      <dcat:theme>
-         <skos:Concept rdf:about="http://data.europa.eu/eli/reg/2014/1143/oj">
-            <skos:prefLabel xml:lang="fre">1143/2014</skos:prefLabel>
-         </skos:Concept>
-      </dcat:theme>
+     <dcatap:applicableLegislation rdf:resource="http://data.europa.eu/eli/reg/2014/1143/oj"/>
       <dct:accessRights>
          <dct:RightsStatement rdf:about="http://inspire.ec.europa.eu/metadata-codelist/LimitationsOnPublicAccess/noLimitations"/>
       </dct:accessRights>