From c4d433ac62109302dab467b354a9c0f374dbe28a Mon Sep 17 00:00:00 2001 From: Glenn Walbran Date: Mon, 18 Mar 2019 14:29:51 +1300 Subject: [PATCH 1/2] MCP-2.0 schema can use base ISO19139 --- .../ISO19139MCP20Namespaces.java | 13 - .../ISO19139MCP20SchemaPlugin.java | 312 ------------------ .../resources/config-spring-geonetwork.xml | 2 +- 3 files changed, 1 insertion(+), 326 deletions(-) delete mode 100644 src/main/java/org/fao/geonet/schema/iso19139mcp20/ISO19139MCP20Namespaces.java delete mode 100644 src/main/java/org/fao/geonet/schema/iso19139mcp20/ISO19139MCP20SchemaPlugin.java diff --git a/src/main/java/org/fao/geonet/schema/iso19139mcp20/ISO19139MCP20Namespaces.java b/src/main/java/org/fao/geonet/schema/iso19139mcp20/ISO19139MCP20Namespaces.java deleted file mode 100644 index 7e6ced9..0000000 --- a/src/main/java/org/fao/geonet/schema/iso19139mcp20/ISO19139MCP20Namespaces.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.fao.geonet.schema.iso19139mcp20; - -import org.jdom.Namespace; - -/** - * Namespaces for iso19139.mcp-2.0 metadata standard. - */ -public class ISO19139MCP20Namespaces { - public static final Namespace MCP = - Namespace.getNamespace("mcp", "http://schemas.aodn.org.au/mcp-2.0"); - public static final Namespace GMX = - Namespace.getNamespace("gmx", "http://www.isotc211.org/2005/gmx"); -} diff --git a/src/main/java/org/fao/geonet/schema/iso19139mcp20/ISO19139MCP20SchemaPlugin.java b/src/main/java/org/fao/geonet/schema/iso19139mcp20/ISO19139MCP20SchemaPlugin.java deleted file mode 100644 index d7fbc9b..0000000 --- a/src/main/java/org/fao/geonet/schema/iso19139mcp20/ISO19139MCP20SchemaPlugin.java +++ /dev/null @@ -1,312 +0,0 @@ -/* - * Copyright (C) 2001-2016 Food and Agriculture Organization of the - * United Nations (FAO-UN), United Nations World Food Programme (WFP) - * and United Nations Environment Programme (UNEP) - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or (at - * your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA - * - * Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2, - * Rome - Italy. email: geonetwork@osgeo.org - */ - -package org.fao.geonet.schema.iso19139mcp20; - -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import org.apache.commons.lang.StringUtils; -import org.fao.geonet.kernel.schema.*; -import org.fao.geonet.utils.Log; -import org.fao.geonet.utils.Xml; -import org.jdom.Element; -import org.jdom.JDOMException; -import org.jdom.Namespace; -import org.jdom.filter.ElementFilter; -import org.jdom.xpath.XPath; - -import java.util.*; - -import static org.fao.geonet.schema.iso19139.ISO19139Namespaces.GCO; -import static org.fao.geonet.schema.iso19139.ISO19139Namespaces.GMD; -import static org.fao.geonet.schema.iso19139.ISO19139Namespaces.GMX; -import static org.fao.geonet.schema.iso19139.ISO19139Namespaces.SRV; - -/** - * Created by francois on 6/15/14. Modified for iso19139.mcp-2.0 by sppigot - */ -public class ISO19139MCP20SchemaPlugin - extends org.fao.geonet.kernel.schema.SchemaPlugin - implements - AssociatedResourcesSchemaPlugin, - MultilingualSchemaPlugin, - ExportablePlugin, - ISOPlugin { - public static final String IDENTIFIER = "iso19139.mcp-2.0"; - - private static ImmutableSet allNamespaces; - private static Map allTypenames; - private static Map allExportFormats; - - static { - allNamespaces = ImmutableSet.builder() - .add(GCO) - .add(GMD) - .add(GMX) - .add(SRV) - .add(ISO19139MCP20Namespaces.MCP) - .build(); - allTypenames = ImmutableMap.builder() - .put("csw:Record", Namespace.getNamespace("csw", "http://www.opengis.net/cat/csw/2.0.2")) - .put("mcp:MD_Metadata", ISO19139MCP20Namespaces.MCP) - .put("dcat", Namespace.getNamespace("dcat", "http://www.w3.org/ns/dcat#")) - .build(); - - allExportFormats = ImmutableMap.builder() - // This is more for all basic iso19139 profiles using this bean as default - // The conversion is not available in regular iso19139 plugin. - // This is for backward compatibility. - .put("convert/to19139.xsl", "metadata-iso19139.xml") - .build(); - } - - public ISO19139MCP20SchemaPlugin() { - super(IDENTIFIER, allNamespaces); - } - - - /** - * Return sibling relation defined in aggregationInfo. - */ - public Set getAssociatedResourcesUUIDs(Element metadata) { - - String XPATH_FOR_AGGRGATIONINFO = "*//gmd:aggregationInfo/*" + - "[gmd:aggregateDataSetIdentifier/*/gmd:code " + - "and gmd:associationType/gmd:DS_AssociationTypeCode/@codeListValue!='']"; - Set listOfResources = new HashSet(); - List sibs = null; - - try { - sibs = Xml.selectNodes( - metadata, - XPATH_FOR_AGGRGATIONINFO, - allNamespaces.asList()); - - - for (Object o : sibs) { - try { - if (o instanceof Element) { - Element sib = (Element) o; - Element agId = (Element) sib.getChild("aggregateDataSetIdentifier", GMD) - .getChildren().get(0); - String sibUuid = getChild(agId, "code", GMD) - .getChildText("CharacterString", GCO); - final Element associationTypeEl = getChild(sib, "associationType", GMD); - String associationType = getChild(associationTypeEl, "DS_AssociationTypeCode", GMD) - .getAttributeValue("codeListValue"); - final Element initiativeTypeEl = getChild(sib, "initiativeType", GMD); - String initiativeType = ""; - if (initiativeTypeEl != null) { - initiativeType = getChild(initiativeTypeEl, "DS_InitiativeTypeCode", GMD) - .getAttributeValue("codeListValue"); - } - AssociatedResource resource = new AssociatedResource(sibUuid, initiativeType, associationType); - listOfResources.add(resource); - } - } catch (Exception e) { - Log.error(Log.JEEVES, "Error getting resources UUIDs", e); - } - } - } catch (Exception e) { - Log.error(Log.JEEVES, "Error getting resources UUIDs", e); - } - return listOfResources; - } - - private Element getChild(Element el, String name, Namespace namespace) { - final Element child = el.getChild(name, namespace); - if (child == null) { - return new Element(name, namespace); - } - return child; - } - - @Override - public Set getAssociatedParentUUIDs(Element metadata) { - ElementFilter elementFilter = new ElementFilter("parentIdentifier", GMD); - return Xml.filterElementValues( - metadata, - elementFilter, - "CharacterString", GCO, - null); - } - - public Set getAssociatedDatasetUUIDs(Element metadata) { - return getAttributeUuidrefValues(metadata, "operatesOn", SRV); - } - - public Set getAssociatedFeatureCatalogueUUIDs(Element metadata) { - return getAttributeUuidrefValues(metadata, "featureCatalogueCitation", GMD); - } - - public Set getAssociatedSourceUUIDs(Element metadata) { - return getAttributeUuidrefValues(metadata, "source", GMD); - } - - private Set getAttributeUuidrefValues(Element metadata, String tagName, Namespace namespace) { - ElementFilter elementFilter = new ElementFilter(tagName, namespace); - return Xml.filterElementValues( - metadata, - elementFilter, - null, null, - "uuidref"); - } - - @Override - public List getTranslationForElement(Element element, String languageIdentifier) { - final String path = ".//gmd:LocalisedCharacterString" + - "[@locale='#" + languageIdentifier + "']"; - try { - XPath xpath = XPath.newInstance(path); - @SuppressWarnings("unchecked") - List matches = xpath.selectNodes(element); - return matches; - } catch (Exception e) { - Log.debug(LOGGER_NAME, getIdentifier() + ": getTranslationForElement failed " + - "on element " + Xml.getString(element) + - " using XPath '" + path + - "updatedLocalizedTextElement exception " + e.getMessage()); - } - return null; - } - - /** - * Add a LocalisedCharacterString to an element. In ISO19139, the translation are stored - * gmd:PT_FreeText/gmd:textGroup/gmd:LocalisedCharacterString. - * - *
-     * 
-     *    Template for Vector data in ISO19139 (multilingual)
-     *    
-     *        
-     *            Modèle de données vectorielles en
-     * ISO19139 (multilingue)
-     *        
-     * 
- */ - @Override - public void addTranslationToElement(Element element, String languageIdentifier, String value) { - // An ISO19139 element containing translation has an xsi:type attribute - element.setAttribute("type", "gmd:PT_FreeText_PropertyType", - Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance")); - - // Create a new translation for the language - Element langElem = new Element("LocalisedCharacterString", GMD); - langElem.setAttribute("locale", "#" + languageIdentifier); - langElem.setText(value); - Element textGroupElement = new Element("textGroup", GMD); - textGroupElement.addContent(langElem); - - // Get the PT_FreeText node where to insert the translation into - Element freeTextElement = element.getChild("PT_FreeText", GMD); - if (freeTextElement == null) { - freeTextElement = new Element("PT_FreeText", GMD); - element.addContent(freeTextElement); - } - freeTextElement.addContent(textGroupElement); - } - - /** - * Remove all multilingual aspect of an element. Keep the md language localized strings - * as default gco:CharacterString for the element. - * - * @param element - * @param langs Metadata languages. The main language MUST be the first one. - * @return - * @throws JDOMException - */ - @Override - public Element removeTranslationFromElement(Element element, List langs) throws JDOMException { - String mainLanguage = langs != null && langs.size() > 0 ? langs.get(0) : "#EN"; - - List nodesWithStrings = (List) Xml.selectNodes(element, "*//gmd:PT_FreeText", Arrays.asList(GMD)); - - for(Element e : nodesWithStrings) { - // Retrieve or create the main language element - Element mainCharacterString = ((Element)e.getParent()).getChild("CharacterString", GCO); - if (mainCharacterString == null) { - // create it if it does not exist - mainCharacterString = new Element("CharacterString", GCO); - ((Element)e.getParent()).addContent(0, mainCharacterString); - } - - // Retrieve the main language value if exist - List mainLangElement = (List) Xml.selectNodes( - e, - "*//gmd:LocalisedCharacterString[@locale='" + mainLanguage + "']", - Arrays.asList(GMD)); - - // Set the main language value - if (mainLangElement.size() == 1) { - String mainLangString = mainLangElement.get(0).getText(); - - if (StringUtils.isNotEmpty(mainLangString)) { - mainCharacterString.setText(mainLangString); - } else if (mainCharacterString.getAttribute("nilReason", GCO) == null){ - ((Element)mainCharacterString.getParent()).setAttribute("nilReason", "missing", GCO); - } - } else if (StringUtils.isEmpty(mainCharacterString.getText())) { - ((Element)mainCharacterString.getParent()).setAttribute("nilReason", "missing", GCO); - } - } - - // Remove unused lang entries - List translationNodes = (List)Xml.selectNodes(element, "*//node()[@locale]"); - for(Element el : translationNodes) { - // Remove all translations if there is no or only one language requested - if(langs.size() <= 1 || - !langs.contains(el.getAttribute("locale").getValue())) { - Element parent = (Element)el.getParent(); - parent.detach(); - } - } - - // Remove PT_FreeText which might be emptied by above processing - for(Element el : nodesWithStrings) { - if (el.getChildren().size() == 0) { - el.detach(); - } - } - - return element; - } - @Override - public String getBasicTypeCharacterStringName() { - return "gco:CharacterString"; - } - - @Override - public Element createBasicTypeCharacterString() { - return new Element("CharacterString", GCO); - } - - @Override - public Map getCswTypeNames() { - return allTypenames; - } - - @Override - public Map getExportFormats() { - return allExportFormats; - } -} diff --git a/src/main/resources/config-spring-geonetwork.xml b/src/main/resources/config-spring-geonetwork.xml index 2921ea7..46eabd3 100644 --- a/src/main/resources/config-spring-geonetwork.xml +++ b/src/main/resources/config-spring-geonetwork.xml @@ -5,5 +5,5 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> + class="org.fao.geonet.schema.iso19139.ISO19139SchemaPlugin"/> From fc5ff594b4948276d4c555966ee595a15a11d0b7 Mon Sep 17 00:00:00 2001 From: Glenn Walbran Date: Mon, 18 Mar 2019 14:31:13 +1300 Subject: [PATCH 2/2] Update version and set appMinorVersionSupported = 3.4.0 --- pom.xml | 4 ++-- src/main/plugin/iso19139.mcp-2.0/schema-ident.xml | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index ae63a96..543337a 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ schemas org.geonetwork-opensource - 3.4.0-SNAPSHOT + 3.4 4.0.0 @@ -21,7 +21,7 @@ ${project.groupId} schema-iso19139 - ${project.version} + ${gn.schemas.version} diff --git a/src/main/plugin/iso19139.mcp-2.0/schema-ident.xml b/src/main/plugin/iso19139.mcp-2.0/schema-ident.xml index 050632d..1e08720 100644 --- a/src/main/plugin/iso19139.mcp-2.0/schema-ident.xml +++ b/src/main/plugin/iso19139.mcp-2.0/schema-ident.xml @@ -3,6 +3,7 @@ iso19139.mcp-2.0 d22ad9e7-f969-4dab-a946-43811a2d4d87 2.0 + 3.4.0 iso19139 http://schemas.aodn.org.au/mcp-2.0 http://schemas.aodn.org.au/mcp-2.0/schema.xsd http://www.isotc211.org/2005/srv http://schemas.opengis.net/iso/19139/20060504/srv/srv.xsd http://www.isotc211.org/2005/gmx http://www.isotc211.org/2005/gmx/gmx.xsd http://rs.tdwg.org/dwc/terms/ http://schemas.aodn.org.au/mcp-2.0/mcpDwcTerms.xsd