Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,10 @@ paths:
The meta data for the new corpus can be provided in either JSON or XML
format. The JSON structure is a straightforward object providing
corpus name, title and (optionally) a repository URL. The XML format
needs to be a TEI document with `teiCorpus` as its root element. The
needs to be a TEI document with `dracorCorpus` as its root element. The
corpus title needs to be provided in the `titleStmt` while the name
and repo URL are encoded in particular `idno` elements in the
`publicationStmt` (see example).

NB: Contrary to the TEI schema our teiCorpus document must not contain
the `TEI` elements for individual plays.
content:
application/json:
schema:
Expand Down Expand Up @@ -183,20 +180,20 @@ paths:
type: string
example: |
<?xml version="1.0" encoding="UTF-8"?>
<teiCorpus xmlns="http://www.tei-c.org/ns/1.0">
<dracorCorpus xmlns="http://www.tei-c.org/ns/1.0">
<teiHeader>
<fileDesc>
<titleStmt>
<title>Test Drama Corpus</title>
</titleStmt>
<publicationStmt>
<publisher>DraCor</publisher>
<idno type="URI" xml:base="https://dracor.org/">test</idno>
<idno type="repo">https://github.com/dracor-org/testdracor</idno>
<idno>test</idno>
<ref type="repo" target="https://github.com/dracor-org/testdracor"/>
</publicationStmt>
</fileDesc>
</teiHeader>
</teiCorpus>
</dracorCorpus>
responses:
'200':
description: Returns corpus metadata
Expand Down
6 changes: 4 additions & 2 deletions jobs/process-webhook-delivery.xq
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,10 @@ declare function local:process-delivery () {
/delivery[@id = $local:delivery and not(@processed)]
let $repo := $delivery/@repo/string()
let $after := $delivery/@after/string()
let $corpus := collection($config:corpora-root)//tei:teiCorpus[
tei:teiHeader//tei:publicationStmt/tei:idno[@type="repo" and . = $repo]
(: DEPRECATED: remove teiCorpus support in v2 :)
let $corpus := collection($config:corpora-root)/(tei:dracorCorpus|tei:teiCorpus)[
tei:teiHeader//tei:publicationStmt/tei:ref[@type="repo" and @target = $repo]
or tei:teiHeader//tei:publicationStmt/tei:idno[@type="repo" and . = $repo]
]

let $info := dutil:get-corpus-info($corpus)
Expand Down
135 changes: 44 additions & 91 deletions modules/api.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ declare
%output:method("json")
function api:corpora($include) {
array {
for $corpus in collection($config:corpora-root)//tei:teiCorpus
(: DEPRECATED: remove teiCorpus support in v2 :)
for $corpus in collection($config:corpora-root)/(tei:dracorCorpus|tei:teiCorpus)
let $info := dutil:get-corpus-info($corpus)
let $name := $info?name
order by $name
Expand All @@ -256,11 +257,8 @@ function api:corpora($include) {
(:~
: Add new corpus
:
: @param $data corpus.xml containing teiCorpus element.
: @result XML document
:
: FIXME: create utility function that can be used both here and in
: api:corpora-post-json() below.
: @param $data corpus.xml containing dracorCorpus element.
: @result JSON
:)
declare
%rest:POST("{$data}")
Expand All @@ -269,79 +267,47 @@ declare
%rest:consumes("application/xml", "text/xml")
%rest:produces("application/json")
%output:method("json")
function api:corpora-post-tei($data, $auth) {
function api:corpora-post-tei($data as document-node(), $auth) {
if (not($auth)) then
(
<rest:response>
<http:response status="401"/>
</rest:response>,
map {
"message": "authorization required"
}
<rest:response><http:response status="401"/></rest:response>,
map { "message": "authorization required" }
)
else

let $header := if ($data) then $data//tei:teiCorpus/tei:teiHeader else ()
let $name := $header//tei:publicationStmt/tei:idno[
@type = "URI" and @xml:base = "https://dracor.org/"
]/text()

let $title := $header//tei:titleStmt/tei:title[1]/text()

return if (not($header)) then
else try {
dutil:create-corpus-from-xml($data/*)
} catch dutil:invalid-corpus-document {
(
<rest:response>
<http:response status="400"/>
</rest:response>,
map {
"error": "invalid document, expecting <teiCorpus>"
}
<rest:response><http:response status="400"/></rest:response>,
map { "error": "Invalid corpus document. " || $err:description }
)
else if (not($name) or not($title)) then
} catch dutil:invalid-corpus-name {
(
<rest:response>
<http:response status="400"/>
</rest:response>,
map {
"error": "missing name or title"
}
<rest:response><http:response status="400"/></rest:response>,
map { "error": $err:description }
)
else if (not(matches($name, '^[-a-z0-1]+$'))) then
} catch dutil:corpus-exists {
(
<rest:response>
<http:response status="400"/>
</rest:response>,
map {
"error": "invalid name",
"message": "Only lower case ASCII letters and digits are accepted."
}
<rest:response><http:response status="409"/></rest:response>,
map { "error": $err:description }
)
else
let $corpus := dutil:get-corpus($name)
return if ($corpus) then (
<rest:response>
<http:response status="409"/>
</rest:response>,
map {
"error": "corpus already exists"
}
) else (
dutil:create-corpus($name, $data/tei:teiCorpus),
} catch * {
(
<rest:response><http:response status="500"/></rest:response>,
map {
"name": $name,
"title": $title
"error": $err:description,
"module": $err:module,
"line": $err:line-number,
"code": $err:code
}
)
}
};

(:~
: Add new corpus
:
: @param $data JSON object describing corpus meta data
: @result JSON object
:
: FIXME: create utility function that can be used both here and in
: api:corpora-post-tei() above.
:)
declare
%rest:POST("{$data}")
Expand All @@ -351,43 +317,30 @@ declare
%output:media-type("application/json")
%output:method("json")
function api:corpora-post-json($data) {
let $json := parse-json(util:base64-decode($data))
let $name := $json?name
let $description := $json?description
let $corpus := dutil:get-corpus($name)

return if ($corpus) then
if (not($auth)) then
(
<rest:response>
<http:response status="409"/>
</rest:response>,
map {
"error": "corpus already exists"
}
<rest:response><http:response status="401"/></rest:response>,
map { "message": "authorization required" }
)
else if (not($name) or not($json?title)) then
else try {
let $json := parse-json(util:base64-decode($data))
return dutil:create-corpus($json)
} catch dutil:invalid-corpus-name {
(
<rest:response>
<http:response status="400"/>
</rest:response>,
map {
"error": "missing name or title"
}
<rest:response><http:response status="400"/></rest:response>,
map { "error": $err:description }
)
else if (not(matches($name, '^[-a-z0-1]+$'))) then
} catch dutil:corpus-exists {
(
<rest:response>
<http:response status="400"/>
</rest:response>,
map {
"error": "invalid name",
"message": "Only lower case ASCII letters and digits are accepted."
}
<rest:response><http:response status="409"/></rest:response>,
map { "error": $err:description }
)
else (
dutil:create-corpus($json),
$json
)
} catch * {
(
<rest:response><http:response status="500"/></rest:response>,
map { "error": $err:description }
)
}
};

(:~
Expand Down
17 changes: 11 additions & 6 deletions modules/dts.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ as item()+ {
"Paging is not possible on a single resource. Try without parameter 'page'!"
)

else if ($corpus/name() eq "teiCorpus") then
(: DEPRECATED: remove teiCorpus support in v2 :)
else if ($corpus/name() = ("dracorCorpus", "teiCorpus")) then
if ( $nav eq 'parents') then
local:corpus-to-collection-with-parent-as-member($id)
else
Expand All @@ -238,7 +239,8 @@ as item()+ {
let $corpusname := local:uri-to-id($id)
let $corpus := dutil:get-corpus($corpusname)
return
if ($corpus/name() eq "teiCorpus") then
(: DEPRECATED: remove teiCorpus support in v2 :)
if ($corpus/name() = ("dracorCorpus", "teiCorpus")) then
if ( $page ) then
(: paging is currently not supported :)
(: test: http://localhost:8088/api/v1/dts/collection?id=http://localhost:8088/id/rus&page=1 :)
Expand Down Expand Up @@ -368,10 +370,13 @@ as item()+ {
:)
declare function local:root-collection()
as map() {
(: Get the corpora, get info needed for the member-array :)
let $corpora := collection($config:corpora-root)//tei:teiCorpus
(: get all the ids – these has to evaluate the teiCorpus files, unfortunately :)
let $corpus-ids := $corpora//tei:idno[@type eq "URI"][@xml:base eq "https://dracor.org/"]/string()
(: Get the corpora, get info needed for the member-array :)
(: DEPRECATED: remove teiCorpus support in v2 :)
let $corpora := collection($config:corpora-root)//(tei:dracorCorpus|tei:teiCorpus)
(: get all the ids – these has to evaluate the dracorCorpus files, unfortunately :)
let $corpus-ids := $corpora//tei:publicationStmt/tei:idno[
not(@type) or (@type eq "URI" and @xml:base eq "https://dracor.org/")
]/string()
let $members := array {
for $corpus-id in $corpus-ids
return local:collection-member-by-id($corpus-id)
Expand Down
8 changes: 5 additions & 3 deletions modules/load.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,13 @@ declare function local:record-corpus-sha($name) {
(:~
: Load corpus from ZIP archive
:
: @param $corpus The <corpus> element providing corpus name and archive URL
: @param $corpus The <dracorCorpus> element providing corpus name and archive URL
: @return List of created collections and files
:
: NB: until we remove support for it in v2 $corpus can also be a <teiCorpus>
: element
:)
declare function load:load-corpus($corpus as element(tei:teiCorpus))
as xs:string* {
declare function load:load-corpus($corpus as element()) as xs:string* {
let $info := dutil:get-corpus-info($corpus)
let $name := $info?name

Expand Down
3 changes: 2 additions & 1 deletion modules/metrics.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ declare function metrics:collect-sitelinks($corpus as xs:string) {
: sitelinks collection
:)
declare function metrics:collect-sitelinks() {
for $corpus in collection($config:corpora-root)//tei:teiCorpus
(: DEPRECATED: remove teiCorpus support in v2 :)
for $corpus in collection($config:corpora-root)/(tei:dracorCorpus|tei:teiCorpus)
let $info := dutil:get-corpus-info($corpus)
return metrics:collect-sitelinks($info?name)
};
Expand Down
Loading
Loading