Skip to content

Commit

Permalink
Merge branch '4.2.x' of https://github.com/geonetwork/core-geonetwork
Browse files Browse the repository at this point in the history
…into 4.2.x
  • Loading branch information
josegar74 committed Oct 14, 2024
2 parents e43df12 + 7588082 commit a47529c
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.commons.text.StringEscapeUtils;
import org.fao.geonet.constants.Geonet;
import org.fao.geonet.kernel.csw.services.getrecords.IFieldMapper;
import org.fao.geonet.utils.DateUtil;
import org.fao.geonet.utils.Log;
import org.geotools.filter.visitor.AbstractFilterVisitor;
import org.locationtech.jts.geom.*;
Expand Down Expand Up @@ -338,7 +339,11 @@ public Object visitRange(BinaryComparisonOperator filter, String operator, Objec
String dataPropertyValue = stack.pop();
String dataPropertyName = stack.pop();

if (!NumberUtils.isNumber(dataPropertyValue)) {
boolean isDate = (DateUtil.parseBasicOrFullDateTime(dataPropertyValue) != null);

if (isDate) {
dataPropertyValue = CswFilter2Es.quoteString(dataPropertyValue);
} else if (!NumberUtils.isNumber(dataPropertyValue)) {
dataPropertyValue = StringEscapeUtils.escapeJson(CswFilter2Es.quoteString(dataPropertyValue));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,4 +381,27 @@ void assertFilterEquals(JsonNode expected, String actual, String filterSpecVersi

assertEquals(expected, MAPPER.readTree(new StringReader(result)));
}


@Test
void testPropertyIsGreaterThanDateValue() throws IOException {

// INPUT:
final String input =
" <ogc:Filter xmlns:ogc=\"http://www.opengis.net/ogc\">\n" +
" <ogc:PropertyIsGreaterThan>\n" +
" <ogc:PropertyName>Modified</ogc:PropertyName>\n" +
" <ogc:Literal>1910-02-05</ogc:Literal>\n" +
" </ogc:PropertyIsGreaterThan>\n" +
" </ogc:Filter>";

// EXPECTED:
final ObjectNode expected = EsJsonHelper.boolbdr(). //
must(array(range("Modified", "gt", "1910-02-05"))). //
filter(queryStringPart()). //
bld();


assertFilterEquals(expected, input);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2001-2023 Food and Agriculture Organization of the
* Copyright (C) 2001-2024 Food and Agriculture Organization of the
* United Nations (FAO-UN), United Nations World Food Programme (WFP)
* and United Nations Environment Programme (UNEP)
*
Expand Down Expand Up @@ -62,6 +62,35 @@ public static ObjectNode match(String property, String matchString) {
return outer;
}


/**
* Returns a structure like
*
* <pre>
* { "range":
* {
* "gt": "value"
* }
* </pre>
*
* @param property
* @param operator
* @param matchString
* @return
*/
public static ObjectNode range(String property, String operator, String matchString) {
final ObjectNode rangeOperatorObject = MAPPER.createObjectNode();
rangeOperatorObject.put(operator, matchString);

final ObjectNode rangeObject = MAPPER.createObjectNode();
rangeObject.put(property, rangeOperatorObject);

final ObjectNode outer = MAPPER.createObjectNode();
outer.set("range", rangeObject);
return outer;
}


private static ArrayNode bound(double x, double y) {
final ArrayNode bound = MAPPER.createArrayNode();
bound.add(x);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,21 @@
version="2.0"
xmlns:cit="http://standards.iso.org/iso/19115/-3/cit/2.0"
xmlns:mdb="http://standards.iso.org/iso/19115/-3/mdb/2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xsl:variable name="dateFormat"
as="xs:string"
select="'[Y0001]-[M01]-[D01]T[H01]:[m01]:[s01][ZN]'"/>

<xsl:template
match="mdb:MD_Metadata">
<xsl:variable name="revisionDate"
select="(mdb:dateInfo/cit:CI_Date
[cit:dateType/cit:CI_DateTypeCode/@codeListValue='revision']
/cit:date/*)[1]"/>
<dateStamp>
<xsl:choose>
<xsl:when test="normalize-space($revisionDate)">
<xsl:value-of select="$revisionDate"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="mdb:dateInfo/cit:CI_Date
[cit:dateType/cit:CI_DateTypeCode/@codeListValue='creation']
/cit:date/*"/>
<!-- TODO: Should we handle when no creation nor revision date
defined ? -->
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="(
mdb:dateInfo/*[cit:dateType/*/@codeListValue = 'revision']/cit:date/*[. != ''],
mdb:dateInfo/*[cit:dateType/*/@codeListValue = 'creation']/cit:date/*[. != ''],
format-dateTime(current-dateTime(), $dateFormat)
)[1]"/>
</dateStamp>
</xsl:template>
</xsl:stylesheet>

0 comments on commit a47529c

Please sign in to comment.