geonetwork / core-geonetwork

GeoNetwork is a catalog application to manage spatially referenced resources. It provides powerful metadata editing and search functions as well as an interactive web map viewer. It is currently used in numerous Spatial Data Infrastructure initiatives across the world.
http://geonetwork-opensource.org/
GNU General Public License v2.0
420 stars 489 forks source link

CSW GetRecords filter to get last modified records - JsonParseException #8034

Open gaellafond opened 4 months ago

gaellafond commented 4 months ago

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:

Doesn't apply to the following CSW filters:

To Reproduce Steps to reproduce the behavior:

  1. Log as admin in GeoNetwork
  2. Go to: Admin console - Settings - CSW test
  3. Copy / paste the request above in the "CSW Request" box
  4. Click the "Send CSW Request" button

Expected behavior List of records in the response

Desktop (please complete the following information):

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

gaellafond commented 4 months ago

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...

josegar74 commented 3 months ago

@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