-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create image file values in API v2 (#1011)
* feature (sipi): Add Lua code for uploading a file to Sipi as per #998 * refactor (api-v2): Refactor file value classes. - Remove deprecated properties isPreview and qualityLevel from API v2. * feature (api-v2): Implement file value creation (ongoing). * feature (api-v2): Implement file value creation (ongoing). * test (api-v2): Test creating and updating still image file values with mock Sipi. * feature (api-v2): Have Sipi move a temporary file to permanent storage (ongoing). - Fix broken tests. * feature (api-v2): Have Sipi move a temporary file to permanent storage (ongoing). * refactor (Authenticator): Start replacing deprecated JWT library (#1044). * refactor (Authenticator): Continue replacing deprecated JWT library (#1044). * refactor (Authenticator): Finish replacing deprecated JWT library (#1044). - Add more JWT tests. * feature (sipi): Improve Lua script for Sipi file upload (ongoing). - Delete old temporary files each time an upload is processed. - Fix incorrect log level names in Lua scripts. * feature (sipi): Validate JWT token in file upload. * feature (sipi): Improve JWT token validation. * test (api-v2): Add integration test for creating a file value with Sipi (ongoing). - Fix some bugs. - Fix broken authentication message package structure. * fix (sipi): Fix lots of Lua script bugs. - Improve error-handling in Lua scripts. - Fix test data for knora-api:fileValueAsUrl. * feature (api-v2): If a file value triplestore update fails, have Sipi delete the temp file (ongoing). * feature (sipi): Make SipiImage directly from uploaded file. - Take into account directory hashing in Lua scripts. - Recursively clean up temporary directory. - Clean up Lua scripts. * test (sipi): Test deleting temp file if file value creation fails. * test (sipi): Activate subdirs in temp dir for tests. * refactor (sipi): Use simple form of SipiImage.new. * test (api-v2): Add tests of file uploads. - Test creating a resource with a file value. - Test Knora's handling of Sipi errors. * test (sipi): Test creating a resource with multiple file values. - Fix upload.lua to preserve the order of uploaded files. - Give knora-api:stillImageFileValueHasIIIFBaseUrl a type of xsd:anyURI. - Fix test data. * feature (sipi): Have Sipi return original filename in response to upload. * docs (api-v2): Add API and design docs about file uploads. * docs (release-notes): Update release notes. * test (sipi): Use new login request format. * docs (api-v2): Add warning about #1068. * fix (api-v1): Adapt API v1 to ignore preview image file values in triplestore. - Update tests. * fix (sipi): Use a JPEG 2000 image to generate previews for testing. * feature (sipi): Clean up a few things. * test (api-v1): Test resource context response when there's no preview image in the triplestore.
- Loading branch information
Benjamin Geer
authored
Nov 28, 2018
1 parent
00faca8
commit 14e17df
Showing
121 changed files
with
34,231 additions
and
37,211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,3 +35,4 @@ docs/_format_docu_v2 | |
webapi/_fuseki/run | ||
triplestores/graphdb-se-7 | ||
idea.vmoptions | ||
sipi/test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<!--- | ||
Copyright © 2015-2018 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/>. | ||
--> | ||
|
||
# Knora API v2 Design | ||
|
||
@@toc { depth=1 } | ||
|
||
@@@ index | ||
|
||
- [API v2 Design Overview](overview.md) | ||
- [Knora and Sipi](sipi.md) | ||
- [Gravsearch](gravsearch.md) | ||
|
||
@@@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<!--- | ||
Copyright © 2015-2018 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/>. | ||
--> | ||
|
||
# Knora and Sipi | ||
|
||
@@toc | ||
|
||
## Configuration | ||
|
||
The Knora-specific configuration and scripts for Sipi are in the | ||
`sipi` subdirectory of the Knora source tree. See the `README.md` there for | ||
instructions on how to start Sipi with Knora. | ||
|
||
## Lua Scripts | ||
|
||
Knora API v2 uses custom Lua scripts to control Sipi. These scripts can be | ||
found in `sipi/scripts` in the Knora source tree. | ||
|
||
Each of these scripts expects a [JSON Web Token](https://jwt.io/) in the | ||
URL parameter `token`. In all cases, the token must be signed by Knora, | ||
it must have an expiration date and not have expired, its issuer must be `Knora`, | ||
and its audience must include `Sipi`. The other contents of the expected tokens | ||
are described below. | ||
|
||
### upload.lua | ||
|
||
The `upload.lua` script is available at Sipi's `upload` route. It processes one | ||
or more file uploads submitted to Sipi. It converts uploaded images to JPEG 2000 | ||
format, and stores them in Sipi's `tmp` directory. The usage of this script is described in | ||
@ref:[Creating File Values](../../../03-apis/api-v2/editing-values.md#creating-file-values). | ||
|
||
Each time `upload.lua` processes a request, it also deletes old temporary files | ||
from `tmp` and (recursively) from any subdirectories. The maximum allowed age of | ||
temporary files can be set in Sipi's configuration file, using the parameter | ||
`max_temp_file_age`, which takes a value in seconds, and defaults to | ||
86400 (1 day). | ||
|
||
### store.lua | ||
|
||
The `store.lua` script is available at Sipi's `store` route. It moves a file | ||
from temporary to permanent storage. It expects an HTTP `POST` request containing | ||
`application/x-www-form-urlencoded` data with the parameter `filename`, whose | ||
value is the internal Sipi-generated filename of the file to be moved. | ||
|
||
The JWT sent to this script must contain the key `knora-data`, whose value | ||
must be a JSON object containing: | ||
|
||
- `permission`: must be `StoreFile` | ||
- `filename`: must be the same as the filename submitted in the form data | ||
|
||
### delete_temp_file.lua | ||
|
||
The `delete_temp_file.lua` script is available at Sipi's `delete_temp_file` route. | ||
It is used only if Knora rejects a file value update request. It expects an | ||
HTTP `DELETE` request, with a filename as the last component of the URL. | ||
|
||
The JWT sent to this script must contain the key `knora-data`, whose value | ||
must be a JSON object containing: | ||
|
||
- `permission`: must be `DeleteTempFile` | ||
- `filename`: must be the same as the filename submitted in the URL | ||
|
||
## SipiResponderV2 | ||
|
||
In Knora, the responder `SipiResponderV2` handles all communication with Sipi. | ||
It blocks while processing each request, to ensure that the number of | ||
concurrent requests to Sipi is not greater than | ||
`akka.actor.deployment./responderManager/sipiRouterV2.nr-of-instances`. | ||
If it encounters an error, it returns `SipiException`. | ||
|
||
## The Image File Upload Workflow | ||
|
||
1. The client uploads an image file to the `upload` route, which runs | ||
`upload.lua`. The image is converted to JPEG 2000 and stored in Sipi's `tmp` | ||
directory. In the response, the client receives the JPEG 2000's unique, | ||
randomly generated filename. | ||
2. The client submits a JSON-LD request to a Knora route (`/v2/values` or `/v2/resources`) | ||
to create or change a file value. The request includes Sipi's internal filename. | ||
3. During parsing of this JSON-LD request, a `StillImageFileValueContentV2` | ||
is constructed to represent the file value. During the construction of this | ||
object, a `GetImageMetadataRequestV2` is sent to `SipiResponderV2`, which | ||
uses Sipi's built-in `knora.json` route to get the rest of the file's | ||
metadata. | ||
4. A responder (`ResourcesResponderV2` or `ValuesResponderV2`) validates | ||
the request and updates the triplestore. (If it is `ResourcesResponderV2`, | ||
it asks `ValuesResponderV2` to generate SPARQL for the values.) | ||
5. The responder that did the update calls `ValueUtilV2.doSipiPostUpdate`. | ||
If the triplestore update was successful, this method sends | ||
`MoveTemporaryFileToPermanentStorageRequestV2` to `SipiResponderV2`, which | ||
makes a request to Sipi's `store` route. Otherwise, the same method sends | ||
`DeleteTemporaryFileRequestV2` to `SipiResponderV2`, which makes a request | ||
to Sipi's `delete_temp_file` route. | ||
|
||
If the request to Knora cannot be parsed, the temporary file is not deleted | ||
immediately, but it will be deleted during the processing of a subsequent | ||
request by Sipi's `upload` route. | ||
|
||
If Sipi's `store` route fails, Knora returns the `SipiException` to the client. | ||
In this case, manual intervention may be necessary to restore consistency | ||
between Knora and Sipi. | ||
|
||
If Sipi's `delete_temp_file` route fails, the error is not returned to the client, | ||
because there is already a Knora error that needs to be returned to the client. | ||
In this case, the Sipi error is simply logged. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.