Skip to content
Permalink
Browse files

feat(api-v2): Add an RDF processing façade (DSP-1020) (#1754)

  • Loading branch information
benjamingeer committed Nov 17, 2020
1 parent f31c075 commit 9170419f052746346c4ee5ff2138ab69125a5e1e
Showing with 9,390 additions and 3,462 deletions.
  1. +1 −0 docs/05-internals/design/principles/index.md
  2. +111 −0 docs/05-internals/design/principles/rdf-api.md
  3. +1 −5 webapi/BUILD.bazel
  4. +2 −2 webapi/src/it/scala/org/knora/webapi/ITKnoraLiveSpec.scala
  5. +5 −4 webapi/src/it/scala/org/knora/webapi/e2e/v2/KnoraSipiIntegrationV2ITSpec.scala
  6. +13 −0 webapi/src/main/resources/application.conf
  7. +8 −0 webapi/src/main/scala/org/knora/webapi/RdfMediaTypes.scala
  8. +10 −1 webapi/src/main/scala/org/knora/webapi/app/ApplicationActor.scala
  9. +3 −0 webapi/src/main/scala/org/knora/webapi/app/BUILD.bazel
  10. +9 −1 webapi/src/main/scala/org/knora/webapi/exceptions/Exceptions.scala
  11. +0 −3 webapi/src/main/scala/org/knora/webapi/feature/BUILD.bazel
  12. +3 −4 webapi/src/main/scala/org/knora/webapi/feature/FeatureFactory.scala
  13. +1 −1 webapi/src/main/scala/org/knora/webapi/http/handler/KnoraExceptionHandler.scala
  14. +1 −4 webapi/src/main/scala/org/knora/webapi/messages/BUILD.bazel
  15. +8 −3 webapi/src/main/scala/org/knora/webapi/messages/OntologyConstants.scala
  16. +50 −27 ...i/src/main/scala/org/knora/webapi/messages/admin/responder/groupsmessages/GroupsMessagesADM.scala
  17. +32 −17 webapi/src/main/scala/org/knora/webapi/messages/admin/responder/listsmessages/ListsMessagesADM.scala
  18. +41 −30 .../scala/org/knora/webapi/messages/admin/responder/permissionsmessages/PermissionsMessagesADM.scala
  19. +54 −27 ...c/main/scala/org/knora/webapi/messages/admin/responder/projectsmessages/ProjectsMessagesADM.scala
  20. +9 −4 webapi/src/main/scala/org/knora/webapi/messages/admin/responder/sipimessages/SipiMessagesADM.scala
  21. +8 −4 ...i/src/main/scala/org/knora/webapi/messages/admin/responder/storesmessages/StoresMessagesADM.scala
  22. +90 −57 webapi/src/main/scala/org/knora/webapi/messages/admin/responder/usersmessages/UsersMessagesADM.scala
  23. +82 −79 webapi/src/main/scala/org/knora/webapi/messages/store/triplestoremessages/TriplestoreMessages.scala
  24. +42 −12 webapi/src/main/scala/org/knora/webapi/messages/util/ConstructResponseUtilV2.scala
  25. +8 −1 webapi/src/main/scala/org/knora/webapi/messages/util/PermissionUtilADM.scala
  26. +0 −135 webapi/src/main/scala/org/knora/webapi/messages/util/RdfFormatUtil.scala
  27. +4 −0 webapi/src/main/scala/org/knora/webapi/messages/util/UserUtilADM.scala
  28. +40 −13 webapi/src/main/scala/org/knora/webapi/messages/util/ValueUtilV1.scala
  29. +269 −253 webapi/src/main/scala/org/knora/webapi/messages/util/{ → rdf}/JsonLDUtil.scala
  30. +86 −0 webapi/src/main/scala/org/knora/webapi/messages/util/rdf/RdfFeatureFactory.scala
  31. +211 −0 webapi/src/main/scala/org/knora/webapi/messages/util/rdf/RdfFormatUtil.scala
  32. +335 −0 webapi/src/main/scala/org/knora/webapi/messages/util/rdf/RdfModel.scala
  33. +89 −0 webapi/src/main/scala/org/knora/webapi/messages/util/rdf/jenaimpl/JenaFormatUtil.scala
  34. +387 −0 webapi/src/main/scala/org/knora/webapi/messages/util/rdf/jenaimpl/JenaModel.scala
  35. +74 −0 webapi/src/main/scala/org/knora/webapi/messages/util/rdf/rdf4jimpl/RDF4JFormatUtil.scala
  36. +339 −0 webapi/src/main/scala/org/knora/webapi/messages/util/rdf/rdf4jimpl/RDF4JModel.scala
  37. +7 −1 webapi/src/main/scala/org/knora/webapi/messages/v1/responder/ckanmessages/CkanMessagesV1.scala
  38. +24 −12 ...i/src/main/scala/org/knora/webapi/messages/v1/responder/ontologymessages/OntologyMessagesV1.scala
  39. +27 −13 webapi/src/main/scala/org/knora/webapi/messages/v1/responder/projectmessages/ProjectMessagesV1.scala
  40. +76 −43 ...i/src/main/scala/org/knora/webapi/messages/v1/responder/resourcemessages/ResourceMessagesV1.scala
  41. +21 −7 ...i/src/main/scala/org/knora/webapi/messages/v1/responder/standoffmessages/StandoffMessagesV1.scala
  42. +17 −9 webapi/src/main/scala/org/knora/webapi/messages/v1/responder/usermessages/UserMessagesV1.scala
  43. +62 −36 webapi/src/main/scala/org/knora/webapi/messages/v1/responder/valuemessages/ValueMessagesV1.scala
  44. +17 −20 webapi/src/main/scala/org/knora/webapi/messages/v2/responder/KnoraRequestV2.scala
  45. +33 −28 webapi/src/main/scala/org/knora/webapi/messages/v2/responder/KnoraResponseV2.scala
  46. +13 −7 webapi/src/main/scala/org/knora/webapi/messages/v2/responder/listsmessages/ListsMessagesV2.scala
  47. +19 −10 ...i/src/main/scala/org/knora/webapi/messages/v2/responder/metadatamessages/MetadataMessagesV2.scala
  48. +197 −138 ...i/src/main/scala/org/knora/webapi/messages/v2/responder/ontologymessages/OntologyMessagesV2.scala
  49. +106 −64 ...i/src/main/scala/org/knora/webapi/messages/v2/responder/resourcemessages/ResourceMessagesV2.scala
  50. +29 −14 webapi/src/main/scala/org/knora/webapi/messages/v2/responder/searchmessages/SearchMessagesV2.scala
  51. +48 −26 ...i/src/main/scala/org/knora/webapi/messages/v2/responder/standoffmessages/StandoffMessagesV2.scala
  52. +140 −98 webapi/src/main/scala/org/knora/webapi/messages/v2/responder/valuemessages/ValueMessagesV2.scala
  53. +1 −0 webapi/src/main/scala/org/knora/webapi/responders/BUILD.bazel
  54. +206 −72 webapi/src/main/scala/org/knora/webapi/responders/admin/GroupsResponderADM.scala
  55. +192 −68 webapi/src/main/scala/org/knora/webapi/responders/admin/ListsResponderADM.scala
  56. +131 −112 webapi/src/main/scala/org/knora/webapi/responders/admin/PermissionsResponderADM.scala
  57. +188 −66 webapi/src/main/scala/org/knora/webapi/responders/admin/ProjectsResponderADM.scala
  58. +6 −2 webapi/src/main/scala/org/knora/webapi/responders/admin/SipiResponderADM.scala
  59. +11 −4 webapi/src/main/scala/org/knora/webapi/responders/admin/StoresResponderADM.scala
  60. +394 −159 webapi/src/main/scala/org/knora/webapi/responders/admin/UsersResponderADM.scala
  61. +98 −22 webapi/src/main/scala/org/knora/webapi/responders/v1/CkanResponderV1.scala
  62. +49 −22 webapi/src/main/scala/org/knora/webapi/responders/v1/OntologyResponderV1.scala
  63. +68 −25 webapi/src/main/scala/org/knora/webapi/responders/v1/ProjectsResponderV1.scala
  64. +181 −69 webapi/src/main/scala/org/knora/webapi/responders/v1/ResourcesResponderV1.scala
  65. +37 −16 webapi/src/main/scala/org/knora/webapi/responders/v1/StandoffResponderV1.scala
  66. +63 −24 webapi/src/main/scala/org/knora/webapi/responders/v1/UsersResponderV1.scala
  67. +291 −119 webapi/src/main/scala/org/knora/webapi/responders/v1/ValuesResponderV1.scala
  68. +22 −8 webapi/src/main/scala/org/knora/webapi/responders/v2/ListsResponderV2.scala
  69. +10 −9 webapi/src/main/scala/org/knora/webapi/responders/v2/MetadataResponderV2.scala
  70. +182 −46 webapi/src/main/scala/org/knora/webapi/responders/v2/OntologyResponderV2.scala
  71. +137 −40 webapi/src/main/scala/org/knora/webapi/responders/v2/ResourcesResponderV2.scala
  72. +15 −3 webapi/src/main/scala/org/knora/webapi/responders/v2/ResponderWithStandoffV2.scala
  73. +67 −21 webapi/src/main/scala/org/knora/webapi/responders/v2/SearchResponderV2.scala
  74. +79 −29 webapi/src/main/scala/org/knora/webapi/responders/v2/StandoffResponderV2.scala
  75. +79 −24 webapi/src/main/scala/org/knora/webapi/responders/v2/ValuesResponderV2.scala
  76. +87 −37 webapi/src/main/scala/org/knora/webapi/routing/Authenticator.scala
  77. +1 −2 webapi/src/main/scala/org/knora/webapi/routing/BUILD.bazel
  78. +10 −6 webapi/src/main/scala/org/knora/webapi/routing/KnoraRoute.scala
  79. +8 −1 webapi/src/main/scala/org/knora/webapi/routing/RouteUtilV1.scala
  80. +11 −11 webapi/src/main/scala/org/knora/webapi/routing/RouteUtilV2.scala
  81. +46 −10 webapi/src/main/scala/org/knora/webapi/routing/admin/GroupsRouteADM.scala
  82. +27 −6 webapi/src/main/scala/org/knora/webapi/routing/admin/PermissionsRouteADM.scala
  83. +168 −38 webapi/src/main/scala/org/knora/webapi/routing/admin/ProjectsRouteADM.scala
  84. +10 −2 webapi/src/main/scala/org/knora/webapi/routing/admin/SipiRouteADM.scala
  85. +6 −1 webapi/src/main/scala/org/knora/webapi/routing/admin/StoreRouteADM.scala
  86. +124 −36 webapi/src/main/scala/org/knora/webapi/routing/admin/UsersRouteADM.scala
  87. +42 −9 webapi/src/main/scala/org/knora/webapi/routing/admin/lists/NewListsRouteADMFeature.scala
  88. +51 −11 webapi/src/main/scala/org/knora/webapi/routing/admin/lists/OldListsRouteADMFeature.scala
  89. +16 −4 webapi/src/main/scala/org/knora/webapi/routing/v1/AuthenticationRouteV1.scala
  90. +11 −2 webapi/src/main/scala/org/knora/webapi/routing/v1/CkanRouteV1.scala
  91. +8 −2 webapi/src/main/scala/org/knora/webapi/routing/v1/ListsRouteV1.scala
  92. +26 −10 webapi/src/main/scala/org/knora/webapi/routing/v1/ProjectsRouteV1.scala
  93. +54 −12 webapi/src/main/scala/org/knora/webapi/routing/v1/ResourceTypesRouteV1.scala
  94. +114 −24 webapi/src/main/scala/org/knora/webapi/routing/v1/ResourcesRouteV1.scala
  95. +8 −2 webapi/src/main/scala/org/knora/webapi/routing/v1/SearchRouteV1.scala
  96. +9 −8 webapi/src/main/scala/org/knora/webapi/routing/v1/StandoffRouteV1.scala
  97. +36 −8 webapi/src/main/scala/org/knora/webapi/routing/v1/UsersRouteV1.scala
  98. +50 −11 webapi/src/main/scala/org/knora/webapi/routing/v1/ValuesRouteV1.scala
  99. +10 −5 webapi/src/main/scala/org/knora/webapi/routing/v2/AuthenticationRouteV2.scala
  100. +18 −4 webapi/src/main/scala/org/knora/webapi/routing/v2/ListsRouteV2.scala
  101. +29 −9 webapi/src/main/scala/org/knora/webapi/routing/v2/MetadataRouteV2.scala
  102. +80 −18 webapi/src/main/scala/org/knora/webapi/routing/v2/OntologiesRouteV2.scala
  103. +55 −12 webapi/src/main/scala/org/knora/webapi/routing/v2/ResourcesRouteV2.scala
  104. +48 −10 webapi/src/main/scala/org/knora/webapi/routing/v2/SearchRouteV2.scala
  105. +14 −5 webapi/src/main/scala/org/knora/webapi/routing/v2/StandoffRouteV2.scala
  106. +21 −5 webapi/src/main/scala/org/knora/webapi/routing/v2/ValuesRouteV2.scala
  107. +1 −0 webapi/src/main/scala/org/knora/webapi/store/BUILD.bazel
  108. +50 −63 webapi/src/main/scala/org/knora/webapi/store/triplestore/http/HttpTriplestoreConnector.scala
  109. +1 −0 webapi/src/main/scala/org/knora/webapi/util/BUILD.bazel
  110. +4 −6 webapi/src/main/scala/org/knora/webapi/util/JavaUtil.scala
  111. +18 −3 webapi/src/test/scala/org/knora/webapi/CoreSpec.scala
  112. +18 −11 webapi/src/test/scala/org/knora/webapi/E2ESpec.scala
  113. +30 −19 webapi/src/test/scala/org/knora/webapi/R2RSpec.scala
  114. +37 −27 webapi/src/test/scala/org/knora/webapi/e2e/FeatureToggleR2RSpec.scala
  115. +7 −6 webapi/src/test/scala/org/knora/webapi/e2e/InstanceChecker.scala
  116. +3 −4 webapi/src/test/scala/org/knora/webapi/e2e/admin/ProjectsADME2ESpec.scala
  117. +1 −1 webapi/src/test/scala/org/knora/webapi/e2e/v2/JSONLDHandlingV2R2RSpec.scala
  118. +9 −9 webapi/src/test/scala/org/knora/webapi/e2e/v2/ListsRouteV2R2RSpec.scala
  119. +9 −9 webapi/src/test/scala/org/knora/webapi/e2e/v2/MetadataRouteV2E2ESpec.scala
  120. +3 −4 webapi/src/test/scala/org/knora/webapi/e2e/v2/OntologyV2R2RSpec.scala
  121. +18 −17 webapi/src/test/scala/org/knora/webapi/e2e/v2/ResourcesRouteV2E2ESpec.scala
  122. +11 −10 webapi/src/test/scala/org/knora/webapi/e2e/v2/ResponseCheckerV2.scala
  123. +8 −8 webapi/src/test/scala/org/knora/webapi/e2e/v2/SearchRouteV2R2RSpec.scala
  124. +122 −121 webapi/src/test/scala/org/knora/webapi/e2e/v2/ValuesRouteV2E2ESpec.scala
  125. +6 −6 webapi/src/test/scala/org/knora/webapi/e2e/v2/ValuesV2R2RSpec.scala
  126. +20 −6 ...la/org/knora/webapi/messages/admin/responder/permissionsmessages/PermissionsMessagesADMSpec.scala
  127. +0 −57 webapi/src/test/scala/org/knora/webapi/messages/util/BUILD.bazel
  128. +19 −11 webapi/src/test/scala/org/knora/webapi/messages/util/ConstructResponseUtilV2Spec.scala
  129. +0 −81 webapi/src/test/scala/org/knora/webapi/messages/util/RdfFormatUtilSpec.scala
  130. +14 −0 webapi/src/test/scala/org/knora/webapi/messages/util/rdf/BUILD.bazel
  131. +86 −27 webapi/src/test/scala/org/knora/webapi/messages/util/{ → rdf}/JsonLDUtilSpec.scala
  132. +21 −13 webapi/src/test/scala/org/knora/webapi/messages/util/{ → rdf}/KnoraResponseV2Spec.scala
  133. +149 −0 webapi/src/test/scala/org/knora/webapi/messages/util/rdf/RdfFormatUtilSpec.scala
  134. +217 −0 webapi/src/test/scala/org/knora/webapi/messages/util/rdf/RdfModelSpec.scala
  135. +84 −0 webapi/src/test/scala/org/knora/webapi/messages/util/rdf/jenaimpl/BUILD.bazel
  136. +28 −0 webapi/src/test/scala/org/knora/webapi/messages/util/rdf/jenaimpl/JenaFormatUtilSpec.scala
  137. +28 −0 webapi/src/test/scala/org/knora/webapi/messages/util/rdf/jenaimpl/JenaJsonLDUtilSpec.scala
  138. +28 −0 webapi/src/test/scala/org/knora/webapi/messages/util/rdf/jenaimpl/JenaKnoraResponseV2Spec.scala
  139. +28 −0 webapi/src/test/scala/org/knora/webapi/messages/util/rdf/jenaimpl/JenaModelSpec.scala
  140. +83 −0 webapi/src/test/scala/org/knora/webapi/messages/util/rdf/rdf4jimpl/BUILD.bazel
  141. +28 −0 webapi/src/test/scala/org/knora/webapi/messages/util/rdf/rdf4jimpl/RDF4JFormatUtilSpec.scala
  142. +28 −0 webapi/src/test/scala/org/knora/webapi/messages/util/rdf/rdf4jimpl/RDF4JJsonLDUtilSpec.scala
  143. +28 −0 webapi/src/test/scala/org/knora/webapi/messages/util/rdf/rdf4jimpl/RDF4JKnoraResponseV2Spec.scala
  144. +28 −0 webapi/src/test/scala/org/knora/webapi/messages/util/rdf/rdf4jimpl/RDF4JModelSpec.scala
  145. +11 −10 ...c/test/scala/org/knora/webapi/messages/v2/responder/metadatamessages/MetadataMessagesV2Spec.scala
  146. +1 −1 .../src/test/scala/org/knora/webapi/messages/v2/responder/ontologymessages/InputOntologyV2Spec.scala
  147. +40 −16 webapi/src/test/scala/org/knora/webapi/other/v1/DrawingsGodsV1Spec.scala
  148. +49 −26 webapi/src/test/scala/org/knora/webapi/responders/admin/GroupsResponderADMSpec.scala
  149. +148 −132 webapi/src/test/scala/org/knora/webapi/responders/admin/ListsResponderADMSpec.scala
  150. +19 −2 webapi/src/test/scala/org/knora/webapi/responders/admin/PermissionsResponderADMSpec.scala
  151. +76 −33 webapi/src/test/scala/org/knora/webapi/responders/admin/ProjectsResponderADMSpec.scala
  152. +9 −7 webapi/src/test/scala/org/knora/webapi/responders/admin/SipiResponderADMSpec.scala
  153. +120 −70 webapi/src/test/scala/org/knora/webapi/responders/admin/UsersResponderADMSpec.scala
  154. +8 −4 webapi/src/test/scala/org/knora/webapi/responders/v1/OntologyResponderV1Spec.scala
  155. +29 −12 webapi/src/test/scala/org/knora/webapi/responders/v1/ProjectsResponderV1Spec.scala
  156. +52 −25 webapi/src/test/scala/org/knora/webapi/responders/v1/ResourcesResponderV1Spec.scala
  157. +49 −15 webapi/src/test/scala/org/knora/webapi/responders/v1/UsersResponderV1Spec.scala
  158. +81 −5 webapi/src/test/scala/org/knora/webapi/responders/v1/ValuesResponderV1Spec.scala
  159. +10 −2 webapi/src/test/scala/org/knora/webapi/responders/v2/ListsResponderV2Spec.scala
  160. +13 −13 webapi/src/test/scala/org/knora/webapi/responders/v2/MetadataResponderV2Spec.scala
  161. +140 −8 webapi/src/test/scala/org/knora/webapi/responders/v2/OntologyResponderV2Spec.scala
  162. +116 −17 webapi/src/test/scala/org/knora/webapi/responders/v2/ResourcesResponderV2Spec.scala
  163. +14 −5 webapi/src/test/scala/org/knora/webapi/responders/v2/SearchResponderV2Spec.scala
  164. +133 −4 webapi/src/test/scala/org/knora/webapi/responders/v2/ValuesResponderV2Spec.scala
  165. +32 −42 webapi/src/test/scala/org/knora/webapi/routing/AuthenticatorSpec.scala
@@ -23,6 +23,7 @@ License along with Knora. If not, see <http://www.gnu.org/licenses/>.
- [Futures with Akka](futures-with-akka.md)
- [HTTP Module](http-module.md)
- [Store Module](store-module.md)
- [RDF Processing API](rdf-api.md)
- [Triplestore Updates](triplestore-updates.md)
- [Consistency Checking](consistency-checking.md)
- [Authentication](authentication.md)
@@ -0,0 +1,111 @@
<!---
Copyright © 2015-2019 the contributors (see Contributors.md).
This file is part of Knora.
Knora is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Knora is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public
License along with Knora. If not, see <http://www.gnu.org/licenses/>.
-->

# RDF Processing API

Knora provides an API for parsing and formatting RDF data and
for working with RDF graphs. This allows Knora developers to use a single,
idiomatic Scala API as a façade for a Java RDF library.
By using a feature toggle, you can choose either
[Jena](https://jena.apache.org/tutorials/rdf_api.html)
or
[RDF4J](https://rdf4j.org/documentation/programming/)
as the underlying implementation.


## Overview

The API is in the package `org.knora.webapi.messages.util.rdf`. It includes:

- `RdfModel`, which represents a set of RDF graphs (a default graph and/or one or more named graphs).
A model can be constructed from scratch, modified, and searched.

- `RdfNode` and its subclasses, which represent RDF nodes (IRIs, blank nodes, and literals).

- `Statement`, which represents a triple or quad.

- `RdfNodeFactory`, which creates nodes and statements.

- `RdfModelFactory`, which creates empty RDF models.

- `RdfFormatUtil`, which parses and formats RDF models.

- `JsonLDUtil`, which provides specialised functionality for working
with RDF in JSON-LD format, and for converting between RDF models
and JSON-LD documents. `RdfFormatUtil` uses `JsonLDUtil` when appropriate.

To work with RDF models, start with `RdfFeatureFactory`, which returns instances
of `RdfNodeFactory`, `RdfModelFactory`, and `RdfFormatUtil`, using feature toggle
configuration.

`JsonLDUtil` does not need a feature factory.


## Implementations

- The Jena-based implementation, in package `org.knora.webapi.messages.util.rdf.jenaimpl`.

- The RDF4J-based implementation, in package `org.knora.webapi.messages.util.rdf.rdf4jimpl`.


## Feature toggle

For an overview of feature toggles, see [Feature Toggles](feature-toggles.md).

The RDF API uses the feature toggle `jena-rdf-library`:

- `on`: use the Jena implementation.

- `off` (the default): use the RDF4J implementation.


The default setting is used on startup, e.g. to read ontologies from the
repository. After startup, the per-request setting is used.


## What still uses RDF4J directly

Before this API was added, Knora mainly used the RDF4J API directly, and still does
in some places:

- Code that uses RDF4J's streaming API to process large amounts of data, especially to
avoid constructing a large string in TriG format:

- `ProjectsResponderADM.projectDataGetRequestADM`

- `HttpTriplestoreConnector.turtleToTrig`

- `RepositoryUpdater`

- The repository update plugin tests, which use SPARQL.

- `TEIHeader`: uses XSLT that depends on the exact format of the RDF/XML generated by RDF4J.
The XSLT would need to be improved to handle `rdf:Description`.

- `GravsearchParser`: uses RDF4J's SPARQL parser. This is probably
not worth changing.


## TODO

- SHACL validation.

- SPARQL querying.

- A streaming parsing/formatting API for processing large graphs.
@@ -2,7 +2,6 @@ package(default_visibility = ["//visibility:public"])

load("@io_bazel_rules_scala//scala:scala.bzl", "scala_binary", "scala_library", "scala_repl", "scala_test")


# alias added for convenience. To call, use: bazel run //webapi:GenerateContributorsFile
alias(
name = "GenerateContributorsFile",
@@ -156,6 +155,7 @@ scala_library(
"//webapi/src/main/scala/org/knora/webapi/http/handler",
"//webapi/src/main/scala/org/knora/webapi/instrumentation",
"//webapi/src/main/scala/org/knora/webapi/messages",
"//webapi/src/main/scala/org/knora/webapi/feature",
"//webapi/src/main/scala/org/knora/webapi/responders",
"//webapi/src/main/scala/org/knora/webapi/routing",
"//webapi/src/main/scala/org/knora/webapi/settings",
@@ -167,17 +167,14 @@ scala_library(
# Test Libs
"@maven//:com_typesafe_akka_akka_testkit_2_12",
"@maven//:com_typesafe_akka_akka_http_testkit_2_12",
"@maven//:com_jsuereth_scala_arm_2_12",
"@maven//:com_typesafe_akka_akka_actor_2_12",
"@maven//:com_typesafe_akka_akka_http_2_12",
"@maven//:com_typesafe_akka_akka_http_core_2_12",
"@maven//:com_typesafe_akka_akka_http_spray_json_2_12",
"@maven//:com_typesafe_akka_akka_stream_2_12",
"@maven//:com_typesafe_config",
"@maven//:io_spray_spray_json_2_12",
"@maven//:org_eclipse_rdf4j_rdf4j_client",
"@maven//:org_scalactic_scalactic_2_12",
"@maven//:org_scalatest_scalatest_2_12",
"@maven//:org_scalatest_scalatest_core_2_12",
"@maven//:org_scalatest_scalatest_wordspec_2_12",
"@maven//:org_scalatest_scalatest_matchers_core_2_12",
@@ -236,7 +233,6 @@ scala_library(
"@maven//:org_scala_lang_scala_library",
"@maven//:org_scala_lang_scala_reflect",
"@maven//:org_scalactic_scalactic_2_12",
"@maven//:org_scalatest_scalatest_2_12",
"@maven//:org_scalatest_scalatest_core_2_12",
"@maven//:org_scalatest_scalatest_wordspec_2_12",
"@maven//:org_scalatest_scalatest_matchers_core_2_12",
@@ -36,8 +36,8 @@ import org.knora.webapi.exceptions.AssertionException
import org.knora.webapi.messages.StringFormatter
import org.knora.webapi.messages.app.appmessages.{AppStart, AppStop, SetAllowReloadOverHTTPState}
import org.knora.webapi.messages.store.triplestoremessages.{RdfDataObject, TriplestoreJsonProtocol}
import org.knora.webapi.messages.util.{JsonLDDocument, JsonLDUtil}
import org.knora.webapi.settings.{KnoraDispatchers, KnoraSettings, KnoraSettingsImpl, _}
import org.knora.webapi.messages.util.rdf.{JsonLDDocument, JsonLDUtil}
import org.knora.webapi.settings._
import org.knora.webapi.util.StartupUtils
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpecLike
@@ -31,6 +31,7 @@ import org.knora.webapi.exceptions.AssertionException
import org.knora.webapi.messages.IriConversions._
import org.knora.webapi.messages.store.triplestoremessages.TriplestoreJsonProtocol
import org.knora.webapi.messages.util._
import org.knora.webapi.messages.util.rdf.{JsonLDArray, JsonLDKeywords, JsonLDDocument, JsonLDObject, JsonLDValue}
import org.knora.webapi.messages.v2.routing.authenticationmessages._
import org.knora.webapi.messages.{OntologyConstants, SmartIri, StringFormatter}
import org.knora.webapi.sharedtestdata.SharedTestDataADM
@@ -157,11 +158,11 @@ class KnoraSipiIntegrationV2ITSpec extends ITKnoraLiveSpec(KnoraSipiIntegrationV
private def getValueFromResource(resource: JsonLDDocument,
propertyIriInResult: SmartIri,
expectedValueIri: IRI): JsonLDObject = {
val resourceIri: IRI = resource.requireStringWithValidation(JsonLDConstants.ID, stringFormatter.validateAndEscapeIri)
val resourceIri: IRI = resource.requireStringWithValidation(JsonLDKeywords.ID, stringFormatter.validateAndEscapeIri)
val propertyValues: JsonLDArray = getValuesFromResource(resource = resource, propertyIriInResult = propertyIriInResult)

val matchingValues: Seq[JsonLDObject] = propertyValues.value.collect {
case jsonLDObject: JsonLDObject if jsonLDObject.requireStringWithValidation(JsonLDConstants.ID, stringFormatter.validateAndEscapeIri) == expectedValueIri => jsonLDObject
case jsonLDObject: JsonLDObject if jsonLDObject.requireStringWithValidation(JsonLDKeywords.ID, stringFormatter.validateAndEscapeIri) == expectedValueIri => jsonLDObject
}

if (matchingValues.isEmpty) {
@@ -620,7 +621,7 @@ class KnoraSipiIntegrationV2ITSpec extends ITKnoraLiveSpec(KnoraSipiIntegrationV

val request = Post(s"$baseApiUrl/v2/resources", HttpEntity(RdfMediaTypes.`application/ld+json`, jsonLdEntity)) ~> addCredentials(BasicHttpCredentials(anythingUserEmail, password))
val responseJsonDoc: JsonLDDocument = getResponseJsonLD(request)
val resourceIri: IRI = responseJsonDoc.body.requireStringWithValidation(JsonLDConstants.ID, stringFormatter.validateAndEscapeIri)
val resourceIri: IRI = responseJsonDoc.body.requireStringWithValidation(JsonLDKeywords.ID, stringFormatter.validateAndEscapeIri)
csvResourceIri.set(responseJsonDoc.body.requireIDAsKnoraDataIri.toString)

// Get the resource from Knora.
@@ -768,7 +769,7 @@ class KnoraSipiIntegrationV2ITSpec extends ITKnoraLiveSpec(KnoraSipiIntegrationV

val request = Post(s"$baseApiUrl/v2/resources", HttpEntity(RdfMediaTypes.`application/ld+json`, jsonLdEntity)) ~> addCredentials(BasicHttpCredentials(anythingUserEmail, password))
val responseJsonDoc: JsonLDDocument = getResponseJsonLD(request)
val resourceIri: IRI = responseJsonDoc.body.requireStringWithValidation(JsonLDConstants.ID, stringFormatter.validateAndEscapeIri)
val resourceIri: IRI = responseJsonDoc.body.requireStringWithValidation(JsonLDKeywords.ID, stringFormatter.validateAndEscapeIri)
xmlResourceIri.set(responseJsonDoc.body.requireIDAsKnoraDataIri.toString)

// Get the resource from Knora.
@@ -279,6 +279,19 @@ app {
"Benjamin Geer <benjamin.geer@dasch.swiss>"
]
}

jena-rdf-library {
description = "Use the Jena API for RDF processing. If turned off, use the RDF4J API."

available-versions = [ 1 ]
default-version = 1
enabled-by-default = no
override-allowed = yes

developer-emails = [
"Benjamin Geer <benjamin.geer@dasch.swiss>"
]
}
}

print-extended-config = false // If true, an extended list of configuration parameters will be printed out at startup.
@@ -48,13 +48,21 @@ object RdfMediaTypes {
fileExtensions = List("rdf")
)

val `application/trig`: MediaType.WithFixedCharset = MediaType.customWithFixedCharset(
mainType = "application",
subType = "trig",
charset = HttpCharsets.`UTF-8`,
fileExtensions = List("trig")
)

/**
* A map of MIME types (strings) to supported RDF media types.
*/
val registry: Map[String, MediaType.NonBinary] = Set(
`application/json`,
`application/ld+json`,
`text/turtle`,
`application/trig`,
`application/rdf+xml`
).map {
mediaType => mediaType.toString -> mediaType
@@ -32,6 +32,7 @@ import com.typesafe.scalalogging.LazyLogging
import kamon.Kamon
import org.knora.webapi.core.LiveActorMaker
import org.knora.webapi.exceptions.{InconsistentTriplestoreDataException, SipiException, UnexpectedMessageException, UnsupportedValueException}
import org.knora.webapi.feature.{FeatureFactoryConfig, KnoraSettingsFeatureFactoryConfig}
import org.knora.webapi.http.handler
import org.knora.webapi.http.version.ServerVersion
import org.knora.webapi.messages.admin.responder.KnoraRequestADM
@@ -105,6 +106,11 @@ class ApplicationActor extends Actor with Stash with LazyLogging with AroundDire
*/
implicit val knoraSettings: KnoraSettingsImpl = KnoraSettings(system)

/**
* The default feature factory configuration, which is used during startup.
*/
val defaultFeatureFactoryConfig: FeatureFactoryConfig = new KnoraSettingsFeatureFactoryConfig(knoraSettings)

/**
* Provides the actor materializer (akka-http)
*/
@@ -353,7 +359,10 @@ class ApplicationActor extends Actor with Stash with LazyLogging with AroundDire

/* load ontologies request */
case LoadOntologies() =>
responderManager ! LoadOntologiesRequestV2(KnoraSystemInstances.Users.SystemUser)
responderManager ! LoadOntologiesRequestV2(
featureFactoryConfig = defaultFeatureFactoryConfig,
requestingUser = KnoraSystemInstances.Users.SystemUser
)

/* load ontologies response */
case SuccessResponseV2(_) =>
@@ -10,6 +10,7 @@ scala_library(
"//webapi/src/main/scala/org/knora/webapi",
"//webapi/src/main/scala/org/knora/webapi/core",
"//webapi/src/main/scala/org/knora/webapi/exceptions",
"//webapi/src/main/scala/org/knora/webapi/feature",
"//webapi/src/main/scala/org/knora/webapi/http/handler",
"//webapi/src/main/scala/org/knora/webapi/http/version",
"//webapi/src/main/scala/org/knora/webapi/instrumentation",
@@ -54,6 +55,8 @@ scala_binary(
"@maven//:ch_qos_logback_logback_core",
"@maven//:com_typesafe_akka_akka_slf4j_2_12",
"@maven//:org_slf4j_log4j_over_slf4j",
"@maven//:org_glassfish_jakarta_json",
"@maven//:org_scala_lang_modules_scala_java8_compat_2_12",
],
)

@@ -467,6 +467,14 @@ case class TestConfigurationException(message: String) extends ApplicationConfig
*/
case class FeatureToggleException(message: String, cause: Option[Throwable] = None) extends ApplicationConfigurationException(message)

/**
* Indicates that RDF processing failed.
*
* @param message a description of the error.
* @param cause the original exception representing the cause of the error, if any.
*/
case class RdfProcessingException(message: String, cause: Option[Throwable] = None) extends InternalServerException(message)

/**
* Helper functions for error handling.
*/
@@ -482,7 +490,7 @@ object ExceptionUtil {
SerializationUtils.serialize(e)
true
} catch {
case serEx: SerializationException => false
case _: SerializationException => false
}
}

@@ -9,12 +9,9 @@ scala_library(
deps = [
"//webapi/src/main/scala/org/knora/webapi",
"//webapi/src/main/scala/org/knora/webapi/exceptions",
"//webapi/src/main/scala/org/knora/webapi/messages",
"//webapi/src/main/scala/org/knora/webapi/settings",
"@maven//:com_typesafe_akka_akka_actor_2_12",
"@maven//:com_typesafe_akka_akka_http_2_12",
"@maven//:com_typesafe_akka_akka_http_core_2_12",
"@maven//:com_typesafe_scala_logging_scala_logging_2_12",
"@maven//:org_apache_jena_apache_jena_libs",
],
)
@@ -23,12 +23,12 @@ import akka.http.scaladsl.model.{HttpHeader, HttpResponse}
import akka.http.scaladsl.model.headers.RawHeader
import akka.http.scaladsl.server.RequestContext
import org.knora.webapi.exceptions.{BadRequestException, FeatureToggleException}
import org.knora.webapi.messages.StringFormatter
import org.knora.webapi.settings.KnoraSettings.FeatureToggleBaseConfig
import org.knora.webapi.settings.KnoraSettingsImpl

import scala.annotation.tailrec
import scala.util.{Failure, Success, Try}
import scala.util.control.Exception._

/**
* A tagging trait for module-specific factories that produce implementations of features.
@@ -362,8 +362,7 @@ object RequestContextFeatureFactoryConfig {
* @param parent the parent [[FeatureFactoryConfig]].
*/
class RequestContextFeatureFactoryConfig(requestContext: RequestContext,
parent: FeatureFactoryConfig)(implicit stringFormatter: StringFormatter) extends OverridingFeatureFactoryConfig(parent) {

parent: FeatureFactoryConfig) extends OverridingFeatureFactoryConfig(parent) {
import FeatureToggle._
import RequestContextFeatureFactoryConfig._

@@ -392,7 +391,7 @@ class RequestContextFeatureFactoryConfig(requestContext: RequestContext,
}

val maybeVersion: Option[Int] = featureNameAndVersion.drop(1).headOption.map {
versionStr => stringFormatter.validateInt(versionStr, throw BadRequestException(s"Invalid version number '$versionStr' in feature toggle $featureName"))
versionStr: String => allCatch.opt(versionStr.toInt).getOrElse(throw BadRequestException(s"Invalid version number '$versionStr' in feature toggle $featureName"))
}

featureName -> FeatureToggle(
@@ -26,7 +26,7 @@ import com.typesafe.scalalogging.LazyLogging
import org.knora.webapi.exceptions.{InternalServerException, RequestRejectedException}
import org.knora.webapi.http.status.{ApiStatusCodesV1, ApiStatusCodesV2}
import org.knora.webapi.messages.OntologyConstants
import org.knora.webapi.messages.util.{JsonLDDocument, JsonLDObject, JsonLDString}
import org.knora.webapi.messages.util.rdf.{JsonLDDocument, JsonLDObject, JsonLDString}
import org.knora.webapi.settings.KnoraSettingsImpl
import spray.json.{JsNumber, JsObject, JsString, JsValue}

0 comments on commit 9170419

Please sign in to comment.