Skip to content

Commit

Permalink
feat!: add archive representation to DSP-API (DEV-17) (#1926)
Browse files Browse the repository at this point in the history
* feat: add bundle representation to knora-base ontology and constants

* fix: overlook in knora-base ontology

* test: try to break stuff that should break

* feat: un-break tests as good as possible

* refactor: move some json-ld generation to model

* refactor: tidy up a bit

* refactor: add ChangeFileRequest to FileModels

* chore: update test data according to new knora-base ontology

* refactor: get rid of some code smells

* refactor: remove code smell

* refactor: move more json-ld generation into FileModels

* temporarily disable all sipi integration tests

* fix: error in books ontology

* bring back sipi inntegration test

* ignore failing tests

* test: move more json-ld generation to FileModels

* refactor: further simplify generating json-ld through FileModels

* refactor: improve file model

* feat: add bundle to lua scripts

* test: temporarily ignore some tests

* feat: forbid bundles in document file type

* test: add test for uploading a BundleRepresentation

* test: add test for changing BundleRepresentation

* refactor: improve file models

* docs: update documentation

* docs: update documentation

* docs: add documentation and auto-reformat some markdown

* test: add unit test for creating a DocumentRepresentation

* refactor: start using models for unit tests

* refactor: generalize file message model

* refactor: further generalize file message model

* refactor: expand file message models

* test: add unit test for creating a bundle representation

* refactor: tidy up books ontology

* docs: update documentation

* refactor: move some string literals into constants

* docs: add scaladoc comments to FileModels

* refactor: final clean up

* docs: update docs according to review

* fix: remove wrong properties from ArchiveRepresentation

* refactor: rename bundle to archive

* test: update test data

* refactor: change file models

* refactor: change file models

* refactor: rework file models

* fix: oversight in json-ld generation in file models

* fix: use wrong IRI in FileModels toMessage function

* fix: expect correct permission for archive representation

* test: add test for file models

* test: add more file model tests

* test: improve file model tests
  • Loading branch information
BalduinLandolt committed Nov 25, 2021
1 parent fe6106f commit 0123a8f
Show file tree
Hide file tree
Showing 39 changed files with 8,275 additions and 6,466 deletions.
1,372 changes: 517 additions & 855 deletions docs/02-knora-ontologies/knora-base.md

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions docs/03-apis/api-v2/editing-values.md
Expand Up @@ -222,6 +222,7 @@ DSP-API v2 currently supports using Sipi to store the following types of files:
* Audio: MPEG, MP4, or Waveform audio file format (.wav, .x-wav, .vnd.wave)
* Text files: TXT, XML, or CSV
* Video files: MP4
* Archive files: ZIP, TAR, GZIP

Support for other types of files will be added in the future.

Expand Down Expand Up @@ -328,6 +329,10 @@ For a text file, use `knora-api:TextRepresentation`, which has the property
`knora-api:hasTextFileValue`, pointing to a
`knora-api:TextFileValue`.

For an archive like zip, use `knora-api:ArchiveRepresentation`, which has the property
`knora-api:hasArchiveFileValue`, pointing to a
`knora-api:ArchiveFileValue`.

## Updating a Value

To update a value, use this route:
Expand Down
85 changes: 66 additions & 19 deletions knora-ontologies/knora-base.ttl
Expand Up @@ -371,22 +371,45 @@

:hasDocumentFileValue rdf:type owl:ObjectProperty ;

rdfs:label "hat Dokument"@de ,
"has document"@en ,
"a document"@fr ,
"ha documento"@it ;
rdfs:label "hat Dokument"@de ,
"has document"@en ,
"a document"@fr ,
"ha documento"@it ;

rdfs:comment "Connects a Representation to a document"@en ;
rdfs:comment "Connects a Representation to a document"@en ;

:objectClassConstraint :DocumentFileValue ;
:objectClassConstraint :DocumentFileValue ;

:subjectClassConstraint :DocumentRepresentation ;
:subjectClassConstraint :DocumentRepresentation ;

:isEditable true ;
:isEditable true ;

salsah-gui:guiElement salsah-gui:Fileupload ;
salsah-gui:guiElement salsah-gui:Fileupload ;

rdfs:subPropertyOf :hasFileValue .
rdfs:subPropertyOf :hasFileValue .



### http://www.knora.org/ontology/knora-base#hasArchiveFileValue

:hasArchiveFileValue rdf:type owl:ObjectProperty ;

rdfs:label "hat Zip"@de ,
"has zip"@en ,
"a zip"@fr ,
"ha zip"@it ;

rdfs:comment "Connects a Representation to a zip archive"@en ;

:objectClassConstraint :ArchiveFileValue ;

:subjectClassConstraint :ArchiveRepresentation ;

:isEditable true ;

salsah-gui:guiElement salsah-gui:Fileupload ;

rdfs:subPropertyOf :hasFileValue .



Expand Down Expand Up @@ -1041,8 +1064,8 @@
# No :subjectClassConstraint, because this can be used with :Resource or :Value.

:objectClassConstraint knora-admin:User .


#################################################################
#
# Datatype properties
Expand Down Expand Up @@ -1797,15 +1820,39 @@
:DocumentRepresentation rdf:type owl:Class ;

rdfs:label "Repräsentation (Dokument)"@de ,
"Representation (Document)"@en ,
"Répresentation (Document)"@fr ,
"Rappresentazione (Documento)"@it ;
"Representation (Document)"@en ,
"Répresentation (Document)"@fr ,
"Rappresentazione (Documento)"@it ;

rdfs:subClassOf :Representation ,
[ rdf:type owl:Restriction ;
owl:onProperty :hasDocumentFileValue ;
owl:cardinality "1"^^xsd:nonNegativeInteger
] .
[ rdf:type owl:Restriction ;
owl:onProperty :hasDocumentFileValue ;
owl:cardinality "1"^^xsd:nonNegativeInteger
] .



### http://www.knora.org/ontology/knora-base#ArchiveFileValue

:ArchiveFileValue rdf:type owl:Class ;

rdfs:subClassOf :FileValue .


### http://www.knora.org/ontology/knora-base#ArchiveRepresentation

:ArchiveRepresentation rdf:type owl:Class ;

rdfs:label "Repräsentation (Zip)"@de ,
"Representation (Zip)"@en ,
"Répresentation (Zip)"@fr ,
"Rappresentazione (Zip)"@it ;

rdfs:subClassOf :Representation ,
[ rdf:type owl:Restriction ;
owl:onProperty :hasArchiveFileValue ;
owl:cardinality "1"^^xsd:nonNegativeInteger
] .



Expand Down
34 changes: 27 additions & 7 deletions sipi/scripts/file_info.lua
Expand Up @@ -11,6 +11,7 @@ IMAGE = "image"
DOCUMENT = "document"
AUDIO = "audio"
VIDEO = "video"
ARCHIVE = "archive"

-------------------------------------------------------------------------------
-- Mimetype constants
Expand Down Expand Up @@ -67,10 +68,7 @@ local text_mime_types = {

local document_mime_types = {
APPLICATION_PDF,
APPLICATION_TAR,
APPLICATION_ZIP,
APPLICATION_ISO,
APPLICATION_GZIP,
APPLICATION_DOC,
APPLICATION_DOCX,
APPLICATION_XLS,
Expand All @@ -79,6 +77,12 @@ local document_mime_types = {
APPLICATION_PPTX
}

local archive_mime_types = {
APPLICATION_TAR,
APPLICATION_ZIP,
APPLICATION_GZIP
}

local video_mime_types = {
VIDEO_MP4
}
Expand All @@ -99,10 +103,7 @@ local text_extensions = {

local document_extensions = {
"pdf",
"zip",
"tar",
"iso",
"gz",
"doc",
"docx",
"xls",
Expand All @@ -111,6 +112,12 @@ local document_extensions = {
"pptx"
}

local archive_extensions = {
"zip",
"tar",
"gz"
}

local video_extensions = {
"mp4"
}
Expand Down Expand Up @@ -162,6 +169,17 @@ function make_document_file_info(extension)
end
end

function make_archive_file_info(extension)
if not table.contains(archive_extensions, extension) then
return nil
else
return {
media_type = ARCHIVE,
extension = extension
}
end
end

-------------------------------------------------------------------------------
-- Determines the media type and file extension of a file.
-- Parameters:
Expand All @@ -174,7 +192,7 @@ end
function get_file_info(filename, mimetype)

local extension = filename:match("^.+%.([^.]+)$")

if extension == nil then
return nil
elseif table.contains(image_mime_types, mimetype) then
Expand All @@ -187,6 +205,8 @@ function get_file_info(filename, mimetype)
return make_text_file_info(extension)
elseif table.contains(document_mime_types, mimetype) then
return make_document_file_info(extension)
elseif table.contains(archive_mime_types, mimetype) then
return make_archive_file_info(extension)
else
-- no supported mediatype could be determined
return nil
Expand Down
4 changes: 2 additions & 2 deletions test_data/ontologies/books-onto.ttl
Expand Up @@ -41,7 +41,7 @@

:Book
rdf:type owl:Class ;
rdfs:subClassOf knora-base:Resource;
rdfs:subClassOf knora-base:Resource ;
knora-base:resourceIcon "book.png" ;
rdfs:label "Buch"@de, "Book"@en ;
rdfs:comment """A resource describing a book."""@en .
Expand All @@ -58,7 +58,7 @@

:Page
rdf:type owl:Class ;
rdfs:subClassOf knora-base:Resource;
rdfs:subClassOf knora-base:Resource ;
knora-base:resourceIcon "page.png" ;
rdfs:label "Seite"@de, "Page"@en ;
rdfs:comment """A resource describing a page in a book."""@en .

0 comments on commit 0123a8f

Please sign in to comment.