-
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
Create image file values in API v2 #1011
Merged
Merged
Changes from 42 commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
9ba1565
feature (sipi): Add Lua code for uploading a file to Sipi as per #998
d47b0cf
refactor (api-v2): Refactor file value classes.
555c631
Merge branch 'develop' into wip/v2-file-values
84684dd
feature (api-v2): Implement file value creation (ongoing).
3e12a2e
Merge branch 'develop' into wip/v2-file-values
cb9a70e
feature (api-v2): Implement file value creation (ongoing).
3b41ce3
test (api-v2): Test creating and updating still image file values wit…
fbcc5ab
feature (api-v2): Have Sipi move a temporary file to permanent storag…
e6bb6e6
feature (api-v2): Have Sipi move a temporary file to permanent storag…
296830e
Merge branch 'develop' into wip/v2-file-values
3953c40
Merge branch 'develop' into wip/v2-file-values
ef484fd
refactor (Authenticator): Start replacing deprecated JWT library (#10…
65abbc9
Merge branch 'develop' into wip/v2-file-values
b9a394f
refactor (Authenticator): Continue replacing deprecated JWT library (…
fd3f215
refactor (Authenticator): Finish replacing deprecated JWT library (#1…
011a7e7
feature (sipi): Improve Lua script for Sipi file upload (ongoing).
5b0211f
feature (sipi): Validate JWT token in file upload.
ad9cdcf
feature (sipi): Improve JWT token validation.
611a84f
test (api-v2): Add integration test for creating a file value with Si…
44ebbe3
fix (sipi): Fix lots of Lua script bugs.
e107e18
feature (api-v2): If a file value triplestore update fails, have Sipi…
1a539a3
feature (sipi): Make SipiImage directly from uploaded file.
c6d93fd
test (sipi): Test deleting temp file if file value creation fails.
cc5f1ae
test (sipi): Activate subdirs in temp dir for tests.
7a2224c
refactor (sipi): Use simple form of SipiImage.new.
36bf482
Merge branch 'develop' into wip/v2-file-values
7a50cba
test (api-v2): Add tests of file uploads.
f180d4a
test (sipi): Test creating a resource with multiple file values.
dc80b41
Merge branch 'develop' into wip/v2-file-values
590fdb2
feature (sipi): Have Sipi return original filename in response to upl…
e6fe3df
docs (api-v2): Add API and design docs about file uploads.
1c06dc5
docs (release-notes): Update release notes.
70ed9af
Merge branch 'develop' into wip/v2-file-values
c4aac9c
Merge branch 'develop' into wip/v2-file-values
b24232d
test (sipi): Use new login request format.
f248f10
docs (api-v2): Add warning about #1068.
5e2ea34
Merge branch 'develop' into wip/v2-file-values
c0c0c85
fix (api-v1): Adapt API v1 to ignore preview image file values in tri…
5188fd7
fix (sipi): Use a JPEG 2000 image to generate previews for testing.
62a6895
Merge branch 'develop' into wip/v2-file-values
e8a4940
Merge branch 'develop' into wip/v2-file-values
5d4227f
Merge branch 'develop' into wip/v2-file-values
f588bd0
feature (sipi): Clean up a few things.
10ceb45
test (api-v1): Test resource context response when there's no preview…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1781,7 +1781,7 @@ | |
] , | ||
[ rdf:type owl:Restriction ; | ||
owl:onProperty :originalMimeType ; | ||
owl:maxCardinality "1"^^xsd:nonNegativeInteger | ||
owl:cardinality "1"^^xsd:nonNegativeInteger | ||
] , | ||
[ rdf:type owl:Restriction ; | ||
owl:onProperty :internalFilename ; | ||
|
@@ -1793,7 +1793,7 @@ | |
] , | ||
[ rdf:type owl:Restriction ; | ||
owl:onProperty :originalFilename ; | ||
owl:maxCardinality "1"^^xsd:nonNegativeInteger | ||
owl:cardinality "1"^^xsd:nonNegativeInteger | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
] . | ||
|
||
|
||
|
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 change is compatible with v1: https://github.com/dhlab-basel/Knora/blob/05091f32cebdcc7cbf852832137a2c37b51b99e5/webapi/src/main/scala/org/knora/webapi/routing/v1/ResourcesRouteV1.scala#L1012