Skip to content

Commit

Permalink
Merge remote-tracking branch 'mw/dcat' into metawal-4.4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
fxprunayre committed Mar 7, 2024
2 parents 2951da9 + 41e1132 commit 02f9232
Show file tree
Hide file tree
Showing 72 changed files with 27,254 additions and 81 deletions.
21 changes: 12 additions & 9 deletions core/src/main/java/org/fao/geonet/kernel/SchemaManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
* Class that handles all functions relating to metadata schemas. This includes
Expand Down Expand Up @@ -106,6 +107,7 @@ public class SchemaManager {
private static int activeWriters = 0;
private Map<String, Schema> hmSchemas = new HashMap<>();
private Map<String, Namespace> hmSchemasTypenames = new HashMap<>();
private Map<String, String> cswOutputSchemas = new HashMap<>();
private String[] fnames = {"labels.xml", "codelists.xml", "strings.xml"};
private Path schemaPluginsDir;
private Path schemaPluginsCat;
Expand Down Expand Up @@ -958,6 +960,7 @@ private void addSchema(ApplicationContext applicationContext, Path schemaDir, El

if (mds.getSchemaPlugin() != null && mds.getSchemaPlugin().getCswTypeNames() != null) {
hmSchemasTypenames.putAll(mds.getSchemaPlugin().getCswTypeNames());
cswOutputSchemas.putAll(mds.getSchemaPlugin().getOutputSchemas());
}

// -- add cached xml files (schema codelists and label files)
Expand Down Expand Up @@ -1926,17 +1929,17 @@ public Map<String, Namespace> getHmSchemasTypenames() {
}

/**
* Return the list of namespace URI of all typenames declared in all schema plugins.
* Return the list of outputSchema declared in all schema plugins.
*/
public Map<String, String> getOutputSchemas() {
return cswOutputSchemas;
}

/**
* Return the list of namespace URI of all outputSchema declared in all schema plugins.
*/
public List<String> getListOfOutputSchemaURI() {
Iterator<String> iterator = hmSchemasTypenames.keySet().iterator();
List<String> listOfSchemaURI = new ArrayList<>();
while (iterator.hasNext()) {
String typeLocalName = iterator.next();
Namespace ns = hmSchemasTypenames.get(typeLocalName);
listOfSchemaURI.add(ns.getURI());
}
return listOfSchemaURI;
return new ArrayList<>(cswOutputSchemas.values());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import static org.fao.geonet.kernel.setting.SettingManager.isPortRequired;

Expand Down Expand Up @@ -529,6 +530,8 @@ private void setOperationsParameters(Element capabilities) {
*/
private void populateTypeNameAndOutputSchema(Element op) {
Map<String, Namespace> typenames = _schemaManager.getHmSchemasTypenames();
List<String> outputSchemas = _schemaManager.getOutputSchemas().values().stream().sorted().collect(Collectors.toList());

List<Element> operations = op.getChildren("Parameter", Csw.NAMESPACE_OWS);
for (Element operation : operations) {
if ("typeNames".equals(operation.getAttributeValue("name"))) {
Expand All @@ -541,12 +544,10 @@ private void populateTypeNameAndOutputSchema(Element op) {
.setText(typename));
}
} else if ("outputSchema".equals(operation.getAttributeValue("name"))) {
for (Map.Entry<String, Namespace> entry : typenames.entrySet()) {
Namespace ns = entry.getValue();
operation.addNamespaceDeclaration(ns);
outputSchemas.forEach(uri ->
operation.addContent(new Element("Value", Csw.NAMESPACE_OWS)
.setText(ns.getURI()));
}
.setText(uri))
);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,16 @@ public static String parse(String schema, SchemaManager schemaManager) throws In
if (schema.equals("own")) return "own";
if (schema.equals("mw")) return "mw";

Map<String, Namespace> typenames = schemaManager.getHmSchemasTypenames();
for (Map.Entry<String, Namespace> entry : typenames.entrySet()) {
Namespace ns = entry.getValue();
if (schema.equals(ns.getURI())) {
return ns.getPrefix();
Map<String, String> typenames = schemaManager.getOutputSchemas();
for (Map.Entry<String, String> entry : typenames.entrySet()) {
String ns = entry.getValue();
if (schema.equals(ns)) {
return entry.getKey();
}
}

throw new InvalidParameterValueEx("outputSchema",
String.format("'%s' schema is not valid. Supported values are %s",
String.format("'%s' output schema is not valid. Supported values are %s",
schema,
schemaManager.getListOfOutputSchemaURI().toString()));
}
Expand Down
14 changes: 8 additions & 6 deletions csw-server/src/main/java/org/fao/geonet/csw/common/util/Xml.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,22 +125,24 @@ public static Element applyElementSetName(ServiceContext context, SchemaManager
ResultType resultType, String id, String displayLanguage) throws InvalidParameterValueEx {
Path schemaDir = schemaManager.getSchemaCSWPresentDir(schema);
Path styleSheet = schemaDir.resolve(outputSchema + "-" + elementSetName + ".xsl");
Path styleSheetWithoutElementSet = schemaDir.resolve(outputSchema + ".xsl");

if (!Files.exists(styleSheet)) {
if (!Files.exists(styleSheet) && !Files.exists(styleSheetWithoutElementSet)) {
throw new InvalidParameterValueEx("OutputSchema",
String.format(
"OutputSchema '%s' not supported for metadata with '%s' (%s).\nCorresponding XSL transformation '%s' does not exist for this schema.\nThe record will not be returned in response.",
outputSchema, id, schema, styleSheet.getFileName()));
"OutputSchema '%s' not supported for metadata with '%s' (%s).\nCorresponding XSL transformation '%s' (or '%s') does not exist for this schema.\nThe record will not be returned in response.",
outputSchema, id, schema, styleSheet.getFileName(), styleSheetWithoutElementSet.getFileName()));
} else {
Map<String, Object> params = new HashMap<>();
params.put("lang", displayLanguage);

Path xslFile = Files.exists(styleSheet) ? styleSheet : styleSheetWithoutElementSet;
try {
result = org.fao.geonet.utils.Xml.transform(result, styleSheet, params);
result = org.fao.geonet.utils.Xml.transform(result, xslFile, params);
} catch (Exception e) {
String msg = String.format(
"Error occured while transforming metadata with id '%s' using '%s'.",
id, styleSheet.getFileName());
"Error occurred while transforming metadata with id '%s' using '%s'.",
id, xslFile.getFileName());
context.error(msg);
context.error(" (C) StackTrace:\n" + Util.getStackTrace(e));
throw new InvalidParameterValueEx("OutputSchema", msg);
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@
<groupId>org.apache.jena</groupId>
<artifactId>apache-jena-libs</artifactId>
<type>pom</type>
<version>3.17.0</version>
<version>4.10.0</version>
</dependency>

<!-- PDF stuff: Managed by Mapfish -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@

<bean id="iso19110SchemaPlugin"
class="org.fao.geonet.schema.iso19110.ISO19110SchemaPlugin">
<property name="outputSchemas">
<util:map key-type="java.lang.String" value-type="java.lang.String">
<entry key="csw" value="http://www.opengis.net/cat/csw/2.0.2"/>
<entry key="gfc" value="http://www.isotc211.org/2005/gfc"/>
</util:map>
</property>
<property name="xpathTitle">
<util:list value-type="java.lang.String">
<value>gmx:name/gco:CharacterString</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
<xsl:variable name="stylesheetVersion" select="'0.1'"/>


<xsl:template match="/">
<xsl:template match="/" name="to-iso19115-3">
<!--
root element (MD_Metadata or MI_Metadata)
-->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:locn="http://www.w3.org/ns/locn#"
xmlns:dcat="http://www.w3.org/ns/dcat#"
exclude-result-prefixes="#all">

<xsl:output method="xml"
indent="yes"
encoding="utf-8"
cdata-section-elements="locn:geometry dcat:bbox"/>

<xsl:param name="validation" as="xs:string" select="'false'"/>
<xsl:param name="isValidating" as="xs:boolean" select="xs:boolean($validation)"/>

<xsl:template name="create-namespaces">
<xsl:namespace name="rdf" select="'http://www.w3.org/1999/02/22-rdf-syntax-ns#'"/>
<xsl:namespace name="rdfs" select="'http://www.w3.org/2000/01/rdf-schema#'"/>
<xsl:namespace name="owl" select="'http://www.w3.org/2002/07/owl#'"/>
<xsl:namespace name="dct" select="'http://purl.org/dc/terms/'"/>
<xsl:namespace name="dcat" select="'http://www.w3.org/ns/dcat#'"/>
<xsl:namespace name="foaf" select="'http://xmlns.com/foaf/0.1/'"/>
<xsl:namespace name="vcard" select="'http://www.w3.org/2006/vcard/ns#'"/>
<xsl:namespace name="prov" select="'http://www.w3.org/ns/prov#'"/>
<xsl:namespace name="org" select="'http://www.w3.org/ns/org#'"/>
<xsl:namespace name="pav" select="'http://purl.org/pav/'"/>
<xsl:namespace name="adms" select="'http://www.w3.org/ns/adms#'"/>
<xsl:namespace name="skos" select="'http://www.w3.org/2004/02/skos/core#'"/>
</xsl:template>
</xsl:stylesheet>
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:cit="http://standards.iso.org/iso/19115/-3/cit/2.0"
xmlns:dqm="http://standards.iso.org/iso/19157/-2/dqm/1.0"
xmlns:gco="http://standards.iso.org/iso/19115/-3/gco/1.0"
xmlns:cat="http://standards.iso.org/iso/19115/-3/cat/1.0"
xmlns:lan="http://standards.iso.org/iso/19115/-3/lan/1.0"
xmlns:mcc="http://standards.iso.org/iso/19115/-3/mcc/1.0"
xmlns:mrc="http://standards.iso.org/iso/19115/-3/mrc/2.0"
xmlns:mco="http://standards.iso.org/iso/19115/-3/mco/1.0"
xmlns:mdb="http://standards.iso.org/iso/19115/-3/mdb/2.0"
xmlns:reg="http://standards.iso.org/iso/19115/-3/reg/1.0"
xmlns:mri="http://standards.iso.org/iso/19115/-3/mri/1.0"
xmlns:mrs="http://standards.iso.org/iso/19115/-3/mrs/1.0"
xmlns:mrl="http://standards.iso.org/iso/19115/-3/mrl/2.0"
xmlns:mex="http://standards.iso.org/iso/19115/-3/mex/1.0"
xmlns:msr="http://standards.iso.org/iso/19115/-3/msr/2.0"
xmlns:mrd="http://standards.iso.org/iso/19115/-3/mrd/1.0"
xmlns:mdq="http://standards.iso.org/iso/19157/-2/mdq/1.0"
xmlns:srv="http://standards.iso.org/iso/19115/-3/srv/2.1"
xmlns:gcx="http://standards.iso.org/iso/19115/-3/gcx/1.0"
xmlns:gex="http://standards.iso.org/iso/19115/-3/gex/1.0"
xmlns:gml="http://www.opengis.net/gml/3.2"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:dct="http://purl.org/dc/terms/"
exclude-result-prefixes="#all">

<!--
RDF Property: dcterms:accessRights
Definition: Information about who can access the resource or an indication of its security status.
Range: dcterms:RightsStatement
= First constraints of mdb:identificationInfo/*/mri:resourceConstraints/*[mco:accessConstraints] (then dct:rights)
RDF Property: dcterms:license
Definition: A legal document under which the resource is made available.
Range: dcterms:LicenseDocument
Usage note: Information about licenses and rights MAY be provided for the Resource. See also guidance at 9. License and rights statements.
= First useLimitation or constraints of mdb:identificationInfo/*/mri:resourceConstraints/*[mco:useConstraints] (then dct:rights)
RDF Property: dcterms:rights
Definition: A statement that concerns all rights not addressed with dcterms:license or dcterms:accessRights, such as copyright statements.
Range: dcterms:RightsStatement
Usage note: Information about licenses and rights MAY be provided for the Resource. See also guidance at 9. License and rights statements.
-->
<xsl:template mode="iso19115-3-to-dcat"
match="mdb:identificationInfo/*/mri:resourceConstraints/*[mco:accessConstraints]">
<xsl:if test="count(../preceding-sibling::mri:resourceConstraints/*[mco:accessConstraints]) = 0">
<xsl:for-each select="../../mri:resourceConstraints/*[mco:accessConstraints]/mco:otherConstraints">
<xsl:if test="position() = 1 or ($isPreservingAllResourceConstraints and position() > 1)">
<xsl:element name="{if (position() = 1) then 'dct:accessRights' else 'dct:rights'}">
<dct:RightsStatement>
<xsl:choose>
<xsl:when test="gcx:Anchor/@xlink:href">
<xsl:attribute name="rdf:about" select="gcx:Anchor/@xlink:href"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="rdf-localised">
<xsl:with-param name="nodeName" select="'rdfs:label'"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</dct:RightsStatement>
</xsl:element>
</xsl:if>
</xsl:for-each>
</xsl:if>
</xsl:template>


<xsl:template mode="iso19115-3-to-dcat"
name="iso19115-3-to-dcat-license"
match="mdb:identificationInfo/*/mri:resourceConstraints/*[mco:useConstraints]">
<xsl:if test="count(../preceding-sibling::mri:resourceConstraints/*[mco:useConstraints]) = 0">
<xsl:variable name="useConstraints"
as="node()*">
<xsl:copy-of select="../../mri:resourceConstraints/*[mco:useConstraints]/mco:otherConstraints"/>
<xsl:copy-of select="../../mri:resourceConstraints/*[mco:useConstraints]/mco:useLimitation"/>
</xsl:variable>
<xsl:for-each select="$useConstraints">
<xsl:choose>
<xsl:when test="position() = 1">
<dct:license>
<dct:LicenseDocument>
<xsl:choose>
<xsl:when test="gcx:Anchor/@xlink:href">
<xsl:attribute name="rdf:about" select="gcx:Anchor/@xlink:href"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="rdf-localised">
<xsl:with-param name="nodeName" select="'rdfs:label'"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</dct:LicenseDocument>
</dct:license>
</xsl:when>
<xsl:otherwise>
<xsl:if test="$isPreservingAllResourceConstraints">
<dct:rights>
<dct:RightsStatement>
<xsl:choose>
<xsl:when test="gcx:Anchor/@xlink:href">
<xsl:attribute name="rdf:about" select="gcx:Anchor/@xlink:href"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="rdf-localised">
<xsl:with-param name="nodeName" select="'rdfs:label'"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</dct:RightsStatement>
</dct:rights>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:if>
</xsl:template>



<!--
RDF Property: odrl:hasPolicy
Definition: An ODRL conformant policy expressing the rights associated with the resource.
Range: odrl:Policy
Usage note: Information about rights expressed as an ODRL policy [ODRL-MODEL] using the ODRL vocabulary [ODRL-VOCAB] MAY be provided for the resource. See also guidance at 9. License and rights statements.
https://www.w3.org/TR/odrl-model/00Model.png
TODO
-->
</xsl:stylesheet>
Loading

0 comments on commit 02f9232

Please sign in to comment.