diff --git a/CHANGELOG.md b/CHANGELOG.md index 8398a291ba2b3bdfff27b651b6be1d34ad35708a..b7fced9e03a9ab74f7c39b02ec95f6c19b0dab00 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.9.1] - 2020-08-31 + +### Fixed + +- Certain manifests are excluded from being listed in a collection. +These aren't "real" editions and shouldn't be displayed in the front end. + ## [1.9.0] - 2020-08-28 ### Added diff --git a/exist-app/build.properties b/exist-app/build.properties index 1d125c6962167c7ad5f54e7c2a0f76670a65fba8..aeca2821448c79592b0438d9d322ba358e7cd2e7 100644 --- a/exist-app/build.properties +++ b/exist-app/build.properties @@ -1,5 +1,5 @@ project.name=https://ahikar-test.sub.uni-goettingen.de/ -project.version=1.8.2 +project.version=1.9.1 project.title=TextAPI for Ahikar project.abbrev=ahikar-test project.processorversion=5.2.0 diff --git a/exist-app/modules/tapi.xqm b/exist-app/modules/tapi.xqm index 1ebafdb7f36e52f668d6bcb6f86bfc7c03131e3f..30e853471c56501880c9e77c126c6a16cfd03889 100644 --- a/exist-app/modules/tapi.xqm +++ b/exist-app/modules/tapi.xqm @@ -7,7 +7,7 @@ xquery version "3.1"; : : @author Mathias Göbel : @author Michelle Weidling - : @version 1.9.0 + : @version 1.9.1 : @since 0.0.0 : @see https://subugoe.pages.gwdg.de/ahiqar/api-documentation/page/text-api-specs/ : :) @@ -24,10 +24,11 @@ declare namespace tgmd="http://textgrid.info/namespaces/metadata/core/2010"; declare namespace xhtml="http://www.w3.org/1999/xhtml"; import module namespace fragment="https://wiki.tei-c.org/index.php?title=Milestone-chunk.xquery" at "fragment.xqm"; +import module namespace functx="http://www.functx.com"; import module namespace requestr="http://exquery.org/ns/request"; import module namespace rest="http://exquery.org/ns/restxq"; -declare variable $tapi:version := "1.9.0"; +declare variable $tapi:version := "1.9.1"; declare variable $tapi:server := if(requestr:hostname() = "existdb") then doc("../expath-pkg.xml")/*/@name => replace("/$", "") else "http://localhost:8094/exist/restxq"; declare variable $tapi:baseCollection := "/db/apps/sade/textgrid"; declare variable $tapi:dataCollection := $tapi:baseCollection || "/data/"; @@ -127,9 +128,10 @@ as item()+ { declare function tapi:collection($collection as xs:string, $server as xs:string) as item()+ { let $aggregation := doc($tapi:aggCollection || $collection || ".xml") + let $allowed-manifests := tapi:exclude-unwanted-manifests($aggregation/*) let $meta := collection($tapi:metaCollection)//tgmd:textgridUri[starts-with(., "textgrid:" || $collection)]/root() let $sequence := - for $i in $aggregation//*:aggregates/string(@*:resource) + for $i in $allowed-manifests/string(@*:resource) let $metaObject := collection($tapi:metaCollection)//tgmd:textgridUri[starts-with(., $i)]/root() return <sequence> @@ -247,12 +249,19 @@ as element(object) { :) declare function tapi:make-editors($documentNode as document-node()) as element(x-editor)* { let $role := "editor" - for $editor in $documentNode//tei:titleStmt//tei:editor + let $has-editor := exists($documentNode//tei:titleStmt//tei:editor) return - <x-editor> - <role>{$role}</role> - <name>{$editor/string()}</name> - </x-editor> + if ($has-editor) then + for $editor in $documentNode//tei:titleStmt//tei:editor + return + <x-editor> + <role>{$role}</role> + <name>{$editor/string()}</name> + </x-editor> + else + <x-editor> + <name>none</name> + </x-editor> }; (:~ @@ -804,3 +813,24 @@ declare function tapi:add-IDs-recursion($nodes as node()*) as node()* { tapi:add-IDs-recursion($node/node()) } }; + + +(:~ + : Some "editions" that appear in the ore:aggregates list of a collection are + : actually no editions; They lack an XML file. + : + : In order to not have them included in the list of "actual" editions, they + : have to be explicitly excluded. + : + : @param $doc The root element of an aggregation object + : @return A list of ore:aggregates without the manifests to be excluded + : + :) +declare function tapi:exclude-unwanted-manifests($doc as node()) as node()* { + let $not-allowed := + ( + "textgrid:3vp38" + ) + for $aggregate in $doc//ore:aggregates return + $aggregate[@rdf:resource != $not-allowed] +}; diff --git a/exist-app/tests.xqm b/exist-app/tests.xqm index 90e23c512748fbe3c686712fe46fd0aa0a32484a..8b05d45f37efc3bdde0b34016c23e570f4828cf9 100644 --- a/exist-app/tests.xqm +++ b/exist-app/tests.xqm @@ -10,6 +10,8 @@ xquery version "3.1"; module namespace tests="http://ahikar.sub.uni-goettingen.de/ns/tapi/tests"; declare namespace http = "http://expath.org/ns/http-client"; +declare namespace ore="http://www.openarchives.org/ore/terms/"; +declare namespace rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"; declare namespace tei="http://www.tei-c.org/ns/1.0"; import module namespace anno="http://ahikar.sub.uni-goettingen.de/ns/annotations" at "modules/annotations.xqm"; @@ -79,7 +81,7 @@ declare (: check if repo.xml works :) %test:assertXPath("map:get($result, 'meta') => map:get('target') = 'ahikar'") function tests:api-info() as item() { - let $url := $tests:restxq || "api/info" + let $url := $tests:restxq || "info" let $req := <http:request href="{$url}" method="get"> <http:header name="Connection" value="close"/> </http:request> @@ -252,13 +254,10 @@ function tests:html-creation($document as xs:string, $page as xs:string) as elem tapi:content($document, $page) }; - -(: this test has to be executed before tapi:compress-to-zip because it creates - : the /txt/ collection and its contents for the zipping. :) declare - %test:assertExists + %test:assertTrue function tests:zip-text() as item()+ { - tapi:zip-text() + xmldb:collection-available("/db/apps/sade/textgrid/txt") }; @@ -302,6 +301,14 @@ function tests:make-editors() as element()+ { tapi:make-editors($documentNode) }; +declare + %test:assertXPath("$result[local-name(.) = 'x-editor' and name/text() = 'none']") +function tests:make-editors-fail-gracefully() as element()+ { + let $documentNode := doc("/db/test-records/sample-tei.xml") + return + tapi:make-editors($documentNode) +}; + declare %test:assertXPath("$result[local-name(.) = 'x-date'][text() = '18.10.1697']") @@ -395,86 +402,104 @@ function tests:remove-whitespaces() as document-node() { }; +declare + %test:assertXPath("not($result//@rdf:resource[. = 'textgrid:3vp38'])") + %test:assertXPath("$result//@rdf:resource[. = 'textgrid:3rx14']") +function tests:exclude-aggregated-manifests() { + let $collection-metadata := + <rdf:RDF xmlns:ore="http://www.openarchives.org/ore/terms/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> + <rdf:Description xmlns:tei="http://www.tei-c.org/ns/1.0" rdf:about="textgrid:3r9ps.0"> + <ore:aggregates rdf:resource="textgrid:3rbm9"/> + <ore:aggregates rdf:resource="textgrid:3rbmc"/> + <ore:aggregates rdf:resource="textgrid:3rx14"/> + <ore:aggregates rdf:resource="textgrid:3vp38"/> + </rdf:Description> + </rdf:RDF> + return + tapi:exclude-unwanted-manifests($collection-metadata) +}; + + (: : ***************** : * AnnotationAPI * : ***************** :) - -declare - %test:args("ahiqar_sample", "data") - %test:assertXPath("$result//*[local-name(.) = 'TEI']") -function tests:anno-get-document($uri as xs:string, $type as xs:string) as document-node() { - anno:get-document($uri, $type) -}; - - -(:declare:) -(: %test:args("3r679", "114r"):) -(: %test:assertEquals("0"):) -(:function tests:anno-determine-start-index-for-page($uri as xs:string, $page as xs:string) {:) -(: anno:determine-start-index-for-page($uri, $page):) -(:};:) -(::) (::) (:declare:) -(: %test:args("3r131"):) -(: %test:assertEquals("16"):) -(:function tests:anno-determine-start-index($uri as xs:string) {:) -(: anno:determine-start-index($uri):) -(:};:) -(::) -(:declare:) -(: %test:args("3r131"):) -(: %test:assertEquals("3r679"):) -(:function tests:anno-get-parent-aggregation($uri as xs:string) {:) -(: anno:get-parent-aggregation($uri):) +(: %test:args("ahiqar_sample", "data"):) +(: %test:assertXPath("$result//*[local-name(.) = 'TEI']"):) +(:function tests:anno-get-document($uri as xs:string, $type as xs:string) as document-node() {:) +(: anno:get-document($uri, $type):) (:};:) (::) (::) -(:declare:) -(: %test:args("3r131"):) -(: %test:assertEquals("114r", "114v"):) -(:function tests:anno-get-pages-in-TEI($uri as xs:string) {:) -(: anno:get-pages-in-TEI($uri):) -(:};:) +(:(:declare:):) +(:(: %test:args("3r679", "114r"):):) +(:(: %test:assertEquals("0"):):) +(:(:function tests:anno-determine-start-index-for-page($uri as xs:string, $page as xs:string) {:):) +(:(: anno:determine-start-index-for-page($uri, $page):):) +(:(:};:):) +(:(::):) +(:(::):) +(:(:declare:):) +(:(: %test:args("3r131"):):) +(:(: %test:assertEquals("16"):):) +(:(:function tests:anno-determine-start-index($uri as xs:string) {:):) +(:(: anno:determine-start-index($uri):):) +(:(:};:):) +(:(::):) +(:(:declare:):) +(:(: %test:args("3r131"):):) +(:(: %test:assertEquals("3r679"):):) +(:(:function tests:anno-get-parent-aggregation($uri as xs:string) {:):) +(:(: anno:get-parent-aggregation($uri):):) +(:(:};:):) +(:(::):) +(:(::):) +(:(:declare:):) +(:(: %test:args("3r131"):):) +(:(: %test:assertEquals("114r", "114v"):):) +(:(:function tests:anno-get-pages-in-TEI($uri as xs:string) {:):) +(:(: anno:get-pages-in-TEI($uri):):) +(:(:};:):) +(:(::):) +(:(::):) +(:(:declare:):) +(:(: %test:args("3r679"):):) +(:(: %test:assertTrue:):) +(:(:function tests:anno-is-resource-edition($uri as xs:string) {:):) +(:(: anno:is-resource-edition($uri):):) +(:(:};:):) +(:(::):) +(:(::):) +(:(:declare:):) +(:(: %test:args("3r131"):):) +(:(: %test:assertTrue:):) +(:(:function tests:anno-is-resource-xml($uri as xs:string) {:):) +(:(: anno:is-resource-xml($uri):):) +(:(:};:):) (::) (::) (:declare:) -(: %test:args("3r679"):) -(: %test:assertTrue:) -(:function tests:anno-is-resource-edition($uri as xs:string) {:) -(: anno:is-resource-edition($uri):) +(: %test:assertEquals("A place's name."):) +(:function tests:anno-get-bodyValue() {:) +(: let $annotation := doc("/db/test-records/sample-tei.xml")//tei:placeName:) +(: return:) +(: anno:get-bodyValue($annotation):) (:};:) (::) (::) (:declare:) -(: %test:args("3r131"):) -(: %test:assertTrue:) -(:function tests:anno-is-resource-xml($uri as xs:string) {:) -(: anno:is-resource-xml($uri):) +(: %test:args("asdf"):) +(: %test:assertFalse:) +(:(: %test:args("3r131"):):) +(:(: %test:assertTrue:):) +(:function tests:anno-are-resources-available($resources as xs:string+) {:) +(: anno:are-resources-available($resources):) (:};:) -declare - %test:assertEquals("A place's name.") -function tests:anno-get-bodyValue() { - let $annotation := doc("/db/test-records/sample-tei.xml")//tei:placeName - return - anno:get-bodyValue($annotation) -}; - - -declare - %test:args("asdf") - %test:assertFalse -(: %test:args("3r131"):) -(: %test:assertTrue:) -function tests:anno-are-resources-available($resources as xs:string+) { - anno:are-resources-available($resources) -}; - - (:declare:) (: %test:args("3r131"):) (: %test:assertEquals("Simon Birol, Aly Elrefaei"):)