Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
gaellafond opened this issue May 14, 2024 · 1 comment
Open

Comments

@gaellafond
Copy link

gaellafond commented May 14, 2024

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:

  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):

  • 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: #7527

@gaellafond gaellafond changed the title CSW GetRecords filter - java.lang.RuntimeException CSW GetRecords filter to get last modified records - java.lang.RuntimeException May 14, 2024
@gaellafond gaellafond changed the title CSW GetRecords filter to get last modified records - java.lang.RuntimeException CSW GetRecords filter to get last modified records - JsonParseException May 14, 2024
@gaellafond
Copy link
Author

gaellafond commented May 15, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant