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

API / Formatter / Add JSON and text responses support. #3191

Conversation

fxprunayre
Copy link
Member

Some formatter may provide text response and not only XML or PDF as
currently supported. Rename file with a proper extension based on file
type. Add support to formatter providing a text response. In such case
the XSLT formatter has to return one element like the following with the
text to be returned:

  <xsl:template match="/">
    <textResponse>
    {
    "@context": "http://schema.org",
    "@type": "Dataset",
    "@id": "https://doi.org/10.5438/4K3M-NYVG"
    ...
    }
    </textResponse>

The text response can be CSV or JSON, ...

The content type can still be controlled using accept header or the
output URL parameter.

eg.
http://localhost:8080/geonetwork/srv/api/records/ff8d8cd6-c753-4581-99a3-af23fe4c996b/formatters/jsonld?output=json

Some formatter may provide text responses and not only XML or PDF as
currently supported. Rename file with a proper extension based on file
type. Add support to formatter providing a text response. In such case
the XSLT formatter has to return one element like the following with the
text to be returned:

```
  <xsl:template match="/">
    <textResponse>
    {
    "@context": "http://schema.org",
    "@type": "Dataset",
    "@id": "https://doi.org/10.5438/4K3M-NYVG"

     <!-- <xsl:apply-templates select="$metadata"
                           mode="toJsonLd"/>-->
    }
    </textResponse>
```

The text can be CSV, or JSON, ...

The content type can still be controlled using accept header or the
output URL parameter.

eg.
http://localhost:8080/geonetwork/srv/api/records/ff8d8cd6-c753-4581-99a3-af23fe4c996b/formatters/jsonld?output=json
Copy link
Member

@josegar74 josegar74 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seem to test this PR is required also the changes in #3212, otherwise the Formatter API is returning a not very nice error if a formatter requested doesn't exists. The error seem not really related to these changes, but more related to the formatters API. Not sure if part of this PR, but something to improve:

http://localhost:8080/geonetwork/srv/api/records/0ad06b86-5d67-4c4c-8503-312de6cb6c8a/formatters/jsonld?output=json

javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is BadParameterEx : Format bundle jsonld does not exist is not a valid value for: xsl
	at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:146)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
	at org.eclipse.jetty.server.Server.handle(Server.java:503)
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:364)
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:260)
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:305)

@fxprunayre
Copy link
Member Author

Not sure if part of this PR, but something to improve:

This is not related to that PR which fix the formatter filename and default content type returned in most of the case text/html. At some point, we should maybe even declare the content type in the formatter config itself.
The error is at least almost meaningful BadParameterEx : Format bundle jsonld does not exist is not a valid value for: xsl even if we should probably improve that in the future. Maybe the formatter API should be capable of providing the list of formatter available for a schema. Maybe we could then build export menu in the UI based on the formatters available.

@fxprunayre
Copy link
Member Author

but something to improve:

Created an issue for this #3241

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

Successfully merging this pull request may close these issues.

2 participants