core-geonetwork
core-geonetwork copied to clipboard
CSW GetRecords filter to get last modified records - JsonParseException
Describe the bug When doing a CSW GetRecords request with a Filter to get records modified since a given date, GeoNetwork generates an invalid JSON object for ElasticSearch.
Request example:
<GetRecords xmlns="http://www.opengis.net/cat/csw/2.0.2"
xmlns:ogc="http://www.opengis.net/ogc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
service="CSW"
version="2.0.2"
resultType="results"
startPosition="1"
maxRecords="10"
outputSchema="http://www.opengis.net/cat/csw/2.0.2"
xsi:schemaLocation="http://www.opengis.net/cat/csw/2.0.2 http://schemas.opengis.net/csw/2.0.2/CSW-discovery.xsd">
<Query typeNames="gmd:MD_Metadata">
<ElementSetName>full</ElementSetName>
<Constraint version="1.1.0">
<ogc:Filter>
<ogc:PropertyIsGreaterThan>
<ogc:PropertyName>Modified</ogc:PropertyName>
<ogc:Literal>1910-02-05</ogc:Literal>
</ogc:PropertyIsGreaterThan>
</ogc:Filter>
</Constraint>
</Query>
</GetRecords>
Response:
<?xml version="1.0" encoding="UTF-8"?>
<ows:ExceptionReport xmlns:ows="http://www.opengis.net/ows" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2.0" xsi:schemaLocation="http://www.opengis.net/ows http://schemas.opengis.net/ows/1.0.0/owsExceptionReport.xsd">
<ows:Exception exceptionCode="NoApplicableCode">
<ows:ExceptionText>java.lang.RuntimeException: com.fasterxml.jackson.core.JsonParseException: Unexpected character ('\' (code 92)): expected a valid value (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
at [Source: (String)"{ "bool": {
"must": [
{
"range" : {
"changeDate" : {
"gt" : \"1910-02-05\"
}
}
}
]
,"filter":{"query_string":{"query":"(op0:(1) ) AND (isTemplate:n) AND (draft:n OR draft:e)"}}}}"; line: 6, column: 26]</ows:ExceptionText>
</ows:Exception>
</ows:ExceptionReport>
NOTE: The quotes around the date value are escaped. That's what is causing the exception.
The bug applies to the following CSW filters:
-
<PropertyIsLessThan>
-
<PropertyIsLessThanOrEqualTo>
-
<PropertyIsGreaterThan>
-
<PropertyIsGreaterThanOrEqualTo>
-
<PropertyIsLike>
-
<PropertyIsBetween>
Doesn't apply to the following CSW filters:
-
<PropertyIsEqualTo>
-
<PropertyIsNotEqualTo>
To Reproduce Steps to reproduce the behavior:
- Log as admin in GeoNetwork
- Go to: Admin console - Settings - CSW test
- Copy / paste the request above in the "CSW Request" box
- Click the "Send CSW Request" button
Expected behavior List of records in the response
Desktop (please complete the following information):
- GeoNetwork Versions:
- 4.2.7: Not affected (filtering works)
- 4.2.8: Affected
- 4.2.9: Affected
- 4.4.4: Affected
Additional context GeoNetwork is running in Docker, using the official GeoNetwork Docker image found on DockerHub.
NOTE: I believe the following issue has introduced the bug: https://github.com/geonetwork/core-geonetwork/issues/7527
I figured out I can use timestamp (numerical value) for the "Modified" property. It's a good workaround, but the bug is still present. String comparison should not produce a JsonParseException.
The timestamp doesn't work with GeoNetwork 3 and GeoNetwork 4 (up to 4.2.7). A formatted date must be used in the filter. The point of using a standard API is to keep it consistent. There is nothing consistent in the implementation of the CSW API between version of GeoNetwork... It's very frustrating to use...
@gaellafond thanks for reporting the issue, indeed was introduced in https://github.com/geonetwork/core-geonetwork/issues/7527, trying to solve another issue.
I've created https://github.com/geonetwork/core-geonetwork/pull/8217, please check it