-
Notifications
You must be signed in to change notification settings - Fork 18
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
Return resources in the API v2 simple ontology schema #833
Conversation
…ma (ongoing). - Use rdfs:label in responses instead of schema:name.
# Conflicts: # webapi/src/test/resources/test-data/resourcesR2RV2/NarrenschiffFirstPage.jsonld # webapi/src/test/resources/test-data/resourcesR2RV2/NarrenschiffFirstPageExpanded.jsonld # webapi/src/test/resources/test-data/searchR2RV2/IncomingLinksForBook.jsonld # webapi/src/test/resources/test-data/searchR2RV2/RegionsForPage.jsonld # webapi/src/test/resources/test-data/searchR2RV2/ThingWithBooleanOptional.jsonld # webapi/src/test/scala/org/knora/webapi/responders/v2/ResourcesResponderV2SpecFullData.scala # webapi/src/test/scala/org/knora/webapi/responders/v2/SearchResponderV2SpecFullData.scala
- Refactor ResponseCheckerR2RV2 to use JsonLDDocument and to handle values in the simple schema.
… it from the request.
@lrosenth I've been thinking about how we can handle content negotiation when using ARK URLs for resources. I suggest it could work like this: If the client is a browser, they'll probably send an HTTP
Then our ARK server can redirect them to the SALSAH GUI. If the client wants JSON or JSON-LD, they'll probably send an
In that case, we could assume that they don't know much about Knora (otherwise they wouldn't be using the ARK URL), and that they want something like Linked Open Data, i.e. something simple and interoperable. So ARK server can redirect them directly to the Knora API to get the resource, and add this header:
Then they'll get the resource as JSON-LD, using the simple schema. How does that sound? |
...or instead of using |
If I may. Sounds good to me. Are we going to support both |
Sound very reasonable to me!!
Thanks,
Lukas
Am 27.04.2018 um 17:39 schrieb Benjamin Geer <[email protected]<mailto:[email protected]>>:
@lrosenth<https://github.com/lrosenth> I've been thinking about how we can handle content negotiation when using ARK URLs for resources. I suggest it could work like this:
If the client is a browser, they'll probably send an HTTP Accept header like this when they open the ARK URL:
Accept: text/html
Then our ARK server can redirect them to the SALSAH GUI.
If the client wants JSON or JSON-LD, they'll probably send an Accept header like this:
Accept: application/json,application/ld+json
In that case, we could assume that they don't know much about Knora (otherwise they wouldn't be using the ARK URL), and that they want something like Linked Open Data, i.e. something simple and interoperable. So ARK server can redirect them directly to the Knora API to get the resource, and add this header:
X-Knora-Accept-Schema: simple
Then they'll get the resource as JSON-LD, using the simple schema.
How does that sound?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#833 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AFN9zIb7ogRc1lqUOXPQsWoevDmG0dlrks5tszubgaJpZM4Tjlmm>.
|
Both are supported in this PR. |
- Fix representations of list values and links in JSON-LD in the simple schema. - Add more tests for resources returned as JSON-LD in the simple schema. - Fix incorrect tests. - Fix GenerateContributorsFile. - Update release notes.
# Conflicts: # docs/src/paradox/00-release-notes/v1.5.0.md
- Stefan Münnich <https://github.com/musicEnfanthen> | ||
- André Kilchenmann <https://github.com/kilchenmann> | ||
- <https://github.com/janCstoffregen> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't that be "Jan Stoffregen https://github.com/janCstoffregen"`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can't be, because he hasn't put his name in his GitHub accont.
# Conflicts: # docs/src/sphinx/03-knora-api-server/api_v2/api-general.rst # docs/src/sphinx/03-knora-api-server/api_v2/knora-iris.rst # docs/src/sphinx/03-knora-api-server/api_v2/ontology-information.rst # docs/src/sphinx/03-knora-api-server/api_v2/reading-and-searching-resources.rst
# Conflicts: # webapi/src/main/scala/org/knora/webapi/messages/v2/responder/KnoraResponseV2.scala # webapi/src/main/scala/org/knora/webapi/util/ConstructResponseUtilV2.scala # webapi/src/test/scala/org/knora/webapi/e2e/v2/JSONLDHandlingV2R2RSpec.scala # webapi/src/test/scala/org/knora/webapi/e2e/v2/ResponseCheckerR2RV2.scala # webapi/src/test/scala/org/knora/webapi/responders/v2/SearchResponderV2SpecFullData.scala
@@ -47,27 +47,45 @@ To get metadata about all ontologies: | |||
HTTP GET to http://host/v2/ontologies/metadata | |||
``` | |||
|
|||
The response is in the default API v2 schema. Sample response: | |||
The response is in the complex API v2 schema. Sample response: | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want to add this to the TypeScript interfaces? -> docs/src/api-v2
You can have a look at resourcesResponse.ts
as an example
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can I do this in a later pull request?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely, it i snot urgent.
) | ||
} else if (objArray.value.forall { | ||
case jsonObjElem: JsonLDObject if JsonLDUtil.isStringWithLang(jsonObjElem) => | ||
// All the elements of the array are strings with language codes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these language codes going to end up in the response? Or is there always only one language returned to the client (preferred language or fallback language)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is processing JSON-LD received from the client in a request. It is not generating JSON-LD to be sent to the client.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When an ontology is created or modified?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When an ontology entity is created or modified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, got it.
@@ -270,46 +266,16 @@ class OntologyV2R2RSpec extends R2RSpec { | |||
} | |||
} | |||
|
|||
"serve a project-specific ontology whose IRI contains a project ID, as JSON-LD, using the simple schema" in { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you remove these test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It became redundant, because now all the ontology IRIs contain project IDs. So this is already covered by the tests that serve the incunabula ontology.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I understand.
@@ -93,6 +94,32 @@ class ResourcesRouteV2R2Spec extends R2RSpec { | |||
} | |||
} | |||
|
|||
"perform a resource request for the book 'Reise ins Heilige Land' using the simple schema (specified by an HTTP header)" in { | |||
|
|||
Get(s"/v2/resources/${URLEncoder.encode("http://rdfh.ch/2a6221216701", "UTF-8")}").addHeader(new SchemaHeader(RouteUtilV2.SIMPLE_SCHEMA_NAME)) ~> resourcesPath ~> check { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addHeader(new SchemaHeader(RouteUtilV2.SIMPLE_SCHEMA_NAME)
Wouldn't it be better for a test to send the complete header as a string: "x-knora-accept-schema: simple"
In order to make sure that the parsing works correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no way to do that with Akka-HTTP. A custom header has to be specified as a class. There's a link to the relevant docs in SchemaHeader.scala
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is because the tests are not actual HTTP requests as the browser would send them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't anything specific to testing, it seems to be inherent in the design of the Akka HTTP client API:
https://doc.akka.io/docs/akka-http/current/common/http-model.html#custom-headers
I didn't find any other way to add a custom header to an HTTP request in Akka.
|
||
assert(expectedResponseAsScala == receivedResponseAsScala, "Mapping creation request response did not match expected response") | ||
|
||
assert(expectedJsonLDDocument == receivedJsonLDDocument, "Mapping creation request response did not match expected response") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add a test to make sure this method works correctly?
We could add a test the expects this method to fail. I am thinking of the received == received
or expected == expcted
bug ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know there is no logical way to rule out errors. So I won't ask for a test that checks the tests for the test ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I'll add a ResponseCheckerV2Spec
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thanks!
ReadResourcesSequenceV2
and its components, separating schema conversion from JSON-LD generation.ReadResourcesSequenceV2
and its components to return JSON-LD in the simple schema.rdfs:label
in responses instead ofschema:name
(requires a change in SALSAH 2).ResourcesRouteV2
to handle requests that ask for a response in either the simple or the complex schema, using an HTTP header (X-Knora-Accept-Schema
) or a URL parameter (schema
).StringFormatter.KnoraDateRegex
.Resolves #725.
Fixes #835.
Fixes #797.
Requires dhlab-basel/Salsah#245 to be merged