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

Return resources in the API v2 simple ontology schema #833

Merged
merged 21 commits into from
May 11, 2018

Conversation

benjamingeer
Copy link

@benjamingeer benjamingeer commented Apr 25, 2018

  • Refactor ReadResourcesSequenceV2 and its components, separating schema conversion from JSON-LD generation.
  • Enable ReadResourcesSequenceV2 and its components to return JSON-LD in the simple schema.
  • Use rdfs:label in responses instead of schema:name (requires a change in SALSAH 2).
  • Enable 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).
  • Fix the format of the string representation of dates in both schemas, so it conforms to StringFormatter.KnoraDateRegex.
  • Represent IRI values correctly in JSON-LD (Incorrect representation of IRI object values in JSON-LD #835), instead of as simple strings (requires a change in SALSAH 2).
  • Add tests.
  • Update docs.
  • Update release notes.

Resolves #725.
Fixes #835.
Fixes #797.

Requires dhlab-basel/Salsah#245 to be merged

…ma (ongoing).

- Use rdfs:label in responses instead of schema:name.
@benjamingeer benjamingeer added enhancement improve existing code or new feature API/V2 breaking (salsah2) labels Apr 25, 2018
@benjamingeer benjamingeer added this to the v1.5.0 milestone Apr 25, 2018
Benjamin Geer added 7 commits April 26, 2018 11:36
# 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.
@benjamingeer
Copy link
Author

@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?

@benjamingeer
Copy link
Author

...or instead of using X-Knora-Accept-Schema, the ARK server could just add ?schema=simple to the Knora API URL.

@subotic
Copy link
Collaborator

subotic commented Apr 27, 2018

If I may. Sounds good to me. Are we going to support both X-Knora-Accept-Schema and ?schema=simple?

@lrosenth
Copy link
Contributor

lrosenth commented Apr 27, 2018 via email

@benjamingeer
Copy link
Author

Sounds good to me. Are we going to support both X-Knora-Accept-Schema and ?schema=simple?

Both are supported in this PR.

Benjamin Geer added 3 commits April 30, 2018 14:32
- 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>
Copy link
Contributor

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"`

Copy link
Author

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.

Benjamin Geer and others added 7 commits May 8, 2018 17:04
# 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:

Copy link
Contributor

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

Copy link
Author

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?

Copy link
Contributor

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.
Copy link
Contributor

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

Copy link
Author

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.

Copy link
Contributor

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?

Copy link
Author

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.

Copy link
Contributor

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 {
Copy link
Contributor

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?

Copy link
Author

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.

Copy link
Contributor

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 {
Copy link
Contributor

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.

Copy link
Author

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.

Copy link
Contributor

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.

Copy link
Author

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")
Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Great, thanks!

@benjamingeer benjamingeer merged commit f618eae into develop May 11, 2018
@benjamingeer benjamingeer deleted the wip/return-resources-in-v2-simple branch May 11, 2018 12:46
@benjamingeer benjamingeer mentioned this pull request Jul 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API/V2 enhancement improve existing code or new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants