Commit 51f94730 authored by ByronCinNZ's avatar ByronCinNZ

Added needed changes to multiple files to bring in line with GN 3.4 + releases.

parent a3a5f901
#
# 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
#
schemasToLoad=iso19139.mcp-1.4
loadGeonetworkStrings=false
fixedLang=false
/*
* 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
*/
import iso19139.SummaryFactory
def isoHandlers = new iso19139.Handlers(handlers, f, env)
SummaryFactory.summaryHandler({it.parent() is it.parent()}, isoHandlers)
isoHandlers.addDefaultHandlers()
/*
* 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 iso19139
import org.fao.geonet.domain.ISODate
import java.text.SimpleDateFormat
public class Functions {
static final def CHAR_PATTERN = /\W/
def handlers;
def f
def env
common.Handlers commonHandlers
def clean = { text ->
if (text == null) {
return ''
}
def trimmed = text.trim()
if ((trimmed =~ CHAR_PATTERN).matches()) {
trimmed = '';
}
return trimmed;
}
def isoUrlText = { el ->
el.'gmd:URL'.text()
}
def isoAnchorUrlLink = { el ->
el.'gmx:Anchor'['@xlink:href'].text()
}
def isoAnchorUrlText = { el ->
el.'gmx:Anchor'.text()
}
def isoText = { el ->
def uiCode2 = '#'+env.lang2.toUpperCase()
def uiCode3 = '#'+env.lang3.toUpperCase()
def locStrings = el.'**'.findAll{ it.name() == 'gmd:LocalisedCharacterString' && !it.text().isEmpty()}
def ptEl = locStrings.find{(it.'@locale' == uiCode2 || it.'@locale' == uiCode3)}
if (ptEl != null) return ptEl.text()
def charString = el.'**'.findAll {it.name() == 'gco:CharacterString' && !it.text().isEmpty()}
if (!charString.isEmpty()) return charString[0].text()
if (!locStrings.isEmpty()) return locStrings[0].text()
""
}
def dateText = { el ->
String date = el.'gco:Date'.text()
String dateTime = el.'gco:DateTime'.text()
if (!date.isEmpty()) {
return date;
} else if (!dateTime.isEmpty()){
ISODate isoDate = new ISODate(dateTime)
return new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(isoDate.toDate())
}
}
/**
* A shortcut for: commonHandlers.func.textEl(node), text))
* @return
*/
def isoTextEl(node, text) {
return commonHandlers.func.textEl(f.nodeLabel(node), text)
}
/**
* A shortcut for: commonHandlers.func.wikiTextEl(node), text))
* @return
*/
def isoWikiTextEl(node, text) {
return commonHandlers.func.wikiTextEl(f.nodeLabel(node), text)
}
/**
* A shortcut for: commonHandlers.func.textEl(node), text))
* @return
*/
def isoUrlEl(node, href, text) {
return commonHandlers.func.urlEl(f.nodeLabel(node), href, text)
}
}
\ No newline at end of file
/*
* 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 iso19139
public class Matchers {
def handlers;
def f
def env
def isUrlEl = {!it.'gmd:URL'.text().isEmpty()}
def isAnchorUrlEl = {!it.'gmx:Anchor'['@xlink:href'].text().isEmpty()}
def simpleElements = ['gco:Decimal', 'gco:Integer', 'gco:Scale', 'gco:Angle', 'gco:Measure', 'gco:Distance',
'gmd:MD_PixelOrientationCode', 'gts:TM_PeriodDuration']
def skipContainers = [
'gmd:CI_Series', 'gmd:MD_ReferenceSystem', 'gmd:identificationInfo', 'gmd:transferOptions',
'gmd:contactInfo', 'gmd:address', 'gmd:phone', 'gmd:onlineResource', 'gmd:referenceSystemIdentifier',
'gmd:distributorTransferOptions', 'gmd:resourceMaintenance', 'gmd:resourceConstraints', 'gmd:aggregationInfo', 'gmd:scope',
'gmd:DQ_DataQuality', 'gmd:lineage', 'gmd:processStep', 'gmd:MD_Distribution', 'gmd:MD_Distributor'
]
def isBasicType = {el ->
el.children().size() == 1 && simpleElements.any{!el[it].text().isEmpty()}
}
def isDateEl = {!it.'gco:DateTime'.text().isEmpty() || !it.'gco:Date'.text().isEmpty()}
def isFormatEl = {!it.'gmd:MD_Format'.text().isEmpty() || (it.name() == 'gmd:MD_Format' && !it.text().isEmpty())}
def isBooleanEl = {!it.'gco:Boolean'.text().isEmpty()}
def hasDateChild = {it.children().size() == 1 && it.children().any(isDateEl)}
def isCodeListEl = {!it['@codeListValue'].text().isEmpty()}
def hasCodeListChild = {it.children().size() == 1 && it.children().any(isCodeListEl)}
def isTextEl = {el ->
!el.'gco:CharacterString'.text().isEmpty() ||
!el.'gmd:PT_FreeText'.'gmd:textGroup'.'gmd:LocalisedCharacterString'.text().isEmpty()
}
def isSimpleTextEl = {el ->
el.children().isEmpty() && !el.text().isEmpty()
}
def isContainerEl = {el ->
!isBasicType(el) && !isSimpleTextEl(el) &&
!isTextEl(el) && !isUrlEl(el) && !isAnchorUrlEl(el) &&
!isCodeListEl(el) && !hasCodeListChild(el) &&
!isDateEl(el) && !hasDateChild(el) &&
!el.children().isEmpty()
//!excludeContainer.any{it == el.name()}
}
def isRespParty = { el ->
!el.'gmd:CI_ResponsibleParty'.isEmpty() || el.'*'['@gco:isoType'].text() == 'gmd:CI_ResponsibleParty'
}
def isCiOnlineResourceParent = { el ->
!el.'gmd:CI_OnlineResource'.text().isEmpty()
}
def isBBox = { el ->
el.name() == 'gmd:EX_GeographicBoundingBox'
}
def isPolygon = { el ->
el.name() == 'gmd:EX_BoundingPolygon'
}
def isRoot = { el ->
el.parent() is el
}
def isSkippedContainer = { el ->
skipContainers.contains(el.name())
}
}
/*
* 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 iso19139
import org.fao.geonet.api.records.formatters.FormatType
import org.fao.geonet.api.records.formatters.groovy.Environment
import org.fao.geonet.api.records.formatters.groovy.util.*
import java.util.regex.Pattern
/**
* Creates the {@link org.fao.geonet.api.records.formatters.groovy.util.Summary} instance for the iso19139 class.
*
* @author Jesse on 11/18/2014.
*/
class SummaryFactory {
def isoHandlers;
org.fao.geonet.api.records.formatters.groovy.Handlers handlers
org.fao.geonet.api.records.formatters.groovy.Functions f
Environment env
def navBarItems
/*
* This field can be set by the creator and provided a closure that will be passed the summary object. The closure can
* perform customization for its needs.
*/
Closure<Summary> summaryCustomizer = null
SummaryFactory(isoHandlers, summaryCustomizer) {
this.isoHandlers = isoHandlers
this.handlers = isoHandlers.handlers;
this.f = isoHandlers.f;
this.env = isoHandlers.env;
this.navBarItems = ['gmd:identificationInfo', 'gmd:distributionInfo', isoHandlers.rootEl]
this.summaryCustomizer = summaryCustomizer;
}
SummaryFactory(isoHandlers) {
this(isoHandlers, null)
}
static void summaryHandler(select, isoHandler) {
def factory = new SummaryFactory(isoHandler)
factory.handlers.add name: "Summary Handler", select: select, {factory.create(it).getResult()}
}
Summary create(metadata) {
Summary summary = new Summary(this.handlers, this.env, this.f)
summary.title = this.isoHandlers.isofunc.isoText(metadata.'gmd:identificationInfo'.'*'.'gmd:citation'.'gmd:CI_Citation'.'gmd:title')
summary.abstr = this.isoHandlers.isofunc.isoText(metadata.'gmd:identificationInfo'.'*'.'gmd:abstract').replaceAll("\n", "<br>")
configureKeywords(metadata, summary)
configureFormats(metadata, summary)
configureExtent(metadata, summary)
configureThumbnails(metadata, summary)
LinkBlock linkBlock = new LinkBlock('links', "fa fa-link");
configureLinks(linkBlock, 'link', false, {
def linkParts = it.split("\\|")
[
title : isoHandlers.isofunc.clean(linkParts[0]),
desc : isoHandlers.isofunc.clean(linkParts[1]),
href : isoHandlers.isofunc.clean(linkParts[2]),
protocol: isoHandlers.isofunc.clean(linkParts[3])
]
})
if (!linkBlock.links.isEmpty()) {
summary.links.add(linkBlock)
}
/*
* TODO fix the xslt transform required by loadHierarchyLinkBlocks when running tests.
*/
if (env.formatType == FormatType.pdf/* || env.formatType == FormatType.testpdf */) {
summary.associated.add(isoHandlers.commonHandlers.loadHierarchyLinkBlocks())
} else {
summary.associated.add(createDynamicAssociatedHtml(summary))
}
def toNavBarItem = {s ->
def name = f.nodeLabel(s, null)
def abbrName = f.nodeTranslation(s, null, "abbrLabel")
new NavBarItem(name, abbrName, '.' + s.replace(':', "_"))
}
summary.navBar = this.isoHandlers.packageViews.findAll{navBarItems.contains(it)}.collect (toNavBarItem)
summary.navBarOverflow = this.isoHandlers.packageViews.findAll{!navBarItems.contains(it)}.collect (toNavBarItem)
summary.navBarOverflow.add(isoHandlers.commonHandlers.createXmlNavBarItem())
summary.content = this.isoHandlers.rootPackageEl(metadata)
if (summaryCustomizer != null) {
summaryCustomizer(summary);
}
return summary
}
def configureKeywords(metadata, summary) {
def keywords = metadata."**".findAll{it.name() == 'gmd:descriptiveKeywords'}
if (!keywords.isEmpty()) {
summary.keywords = this.isoHandlers.keywordsEl(keywords).toString()
}
}
def configureFormats(metadata, summary) {
def formats = metadata."**".findAll this.isoHandlers.matchers.isFormatEl
if (!formats.isEmpty()) {
summary.formats = this.isoHandlers.formatEls(formats).toString()
}
}
def configureExtent(metadata, summary) {
def extents = metadata."**".findAll { this.isoHandlers.matchers.isPolygon(it) || this.isoHandlers.matchers.isBBox(it) }
def split = extents.split this.isoHandlers.matchers.isPolygon
def polygons = split[0]
def bboxes = split[1]
def extent = ""
if (!polygons.isEmpty()) {
extent = this.isoHandlers.polygonEl(true)(polygons[0]).toString()
} else if (!bboxes.isEmpty()) {
extent = this.isoHandlers.bboxEl(true)(bboxes[0]).toString()
}
summary.extent = extent
}
def configureLinks(linkBlock, indexKey, urlAndTextEquals, objParser) {
Collection<String> links = this.env.indexInfo[indexKey];
if (links != null && !links.isEmpty()) {
links.each { link ->
def linkParts = objParser(link)
def title = linkParts.title
def desc = linkParts.desc
def href = linkParts.href
if (title.isEmpty()) {
title = desc;
}
if (title.isEmpty()) {
title = href;
}
if (href != '') {
def protocol = linkParts.protocol != null ? linkParts.protocol.toLowerCase() : '';
def linkClass = href.isEmpty() ? 'text-muted' : '';
def imagesDir = "../../images/formatter/"
def type;
def icon = "";
def iconClasses = "";
if (protocol.contains("kml")) {
type = "kml";
icon = imagesDir + "kml.png";
} else if (protocol.contains("wms")) {
type = "wms";
icon = imagesDir + "wms.png";
} else if (protocol.contains("download")) {
type = "download";
iconClasses = "fa fa-download"
} else if (protocol.contains("wfs")) {
type = "wfs";
icon = imagesDir + "wfs.png";
} else if (protocol.contains("ogc:")) {
type = "ogc";
} else {
if (indexKey == 'wms_uri' ) {
type = "wms";
icon = imagesDir + "wms.png";
} else {
type = "link";
iconClasses = "fa fa-link"
}
}
def linkType = new LinkType(type, null, icon, iconClasses)
def linkObj = new Link(href, title, linkClass)
if (urlAndTextEquals) {
linkBlock.linkMap.put(linkType, linkObj);
} else {
linkBlock.put(linkType, linkObj)
}
}
}
}
}
LinkBlock createDynamicAssociatedHtml(Summary summary) {
def associated = "associated-link"
def html = """
<script type="text/javascript">
//<![CDATA[
gnFormatter.loadAssociated(undefined, '.${LinkBlock.CSS_CLASS_PREFIX + associated}', '${this.env.metadataUUID}', undefined, '.associated-spinner')
//]]></script>
<div><i class="fa fa-circle-o-notch fa-spin pad-right associated-spinner"></i>Loading...</div>
"""
LinkBlock linkBlock = new LinkBlock(associated, "fa fa-sitemap")
linkBlock.html = html
return linkBlock;
}
private static void configureThumbnails(metadata, header) {
def logos = metadata.'gmd:identificationInfo'.'*'.'gmd:graphicOverview'.'gmd:MD_BrowseGraphic'.'gmd:fileName'.'gco:CharacterString'
logos.each { logo ->
header.addThumbnail(logo.text())
}
}
}
<!--
~ 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
-->
<div>
<div class="row">
{{title}}
{{altTitle}}
{{date}}
{{editionInfo}}
</div>
<div class="row">
{{identifier}}
{{presentationForm}}
{{ISBN}}
{{ISSN}}
</div>
<div>
{{otherData}}
</div>
</div>
<!--
~ 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
-->
<div fmt-transclude="html/2-level-entry.html" fmt-transclude-model="childData">
<ul class="container-list">
<li fmt-repeat="(opName, links) in resources">
<strong>{{opName}}</strong>
<ul class="md-value-list">
<li fmt-repeat="link in links">
<span fmt-include="html/single-resource.html" fmt-include-replace="true"/>
</li>
</ul>
</li>
</ul>
</div>
<!--
~ 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
-->
<div fmt-transclude="html/2-level-entry.html" fmt-transclude-model="childData">
<ul class="container-list">
<li fmt-repeat="f in formats">
<strong>{{f.name}} ({{f.version}})</strong>
<ul class="md-value-list">
<li fmt-if="f.amendmentNumber">
<dt fmt-translate="node">gmd:amendmentNumber</dt>
<dd>{{f.amendmentNumber}}</dd>
</li>
<li fmt-if="f.specification">
<dt fmt-translate="node">gmd:specification</dt>
<dd>{{f.specification}}</dd>
</li>
<li fmt-if="f.fileDecompressionTechnique">
<dt fmt-translate="node">gmd:fileDecompressionTechnique</dt>
<dd>{{f.fileDecompressionTechnique}}</dd>
</li>
<li fmt-if="f.formatDistributor">
{{f.formatDistributor}}
</li>
</ul>
</li>
</ul>
</div>
<!--
~ 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
-->
<div fmt-transclude="html/2-level-entry.html" fmt-transclude-model="childData">
<div class="row">
<div fmt-repeat="g in graphics" class="col-md-3">
<div class="dropdown">
<a data-toggle="dropdown" aria-haspopup="true" role="button" aria-expanded="false">
<img class="graphic-overview" src="{{g.src}}"></img>
</a>
<img class="graphic-overview dropdown-menu large" role="menu" src="{{g.src}}"></img>
</div>
</div>
</div>
</div>
<!--
~ 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)