diff --git a/CHANGELOG.md b/CHANGELOG.md index c4f84af59644582cab5433a288268f8333f05701..6f9e287ede3531dfad4ceba442d3846b87763e41 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). +## [4.1.0] - 2021-02-05 + +### Added + +- license information within the image field on item level. As a consequence, each image is now connected with an SPDX identifier (if possible) and further notes about the image's creator. + + ## [4.0.1] - 2021-02-04 ### Fixed diff --git a/exist-app/build.properties b/exist-app/build.properties index 2f326bbeac2ad49781ec4a4d1fad4a1b35c67076..3b1cbc18a69994168ad984e9304d9d1a3c4aa1b4 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=4.0.1 +project.version=4.1.0 project.title=Ahiqar project.abbrev=ahikar-test project.processorversion=5.2.0 diff --git a/exist-app/modules/tapi-img.xqm b/exist-app/modules/tapi-img.xqm index a3bf4dcfba1bbbc2de1bdc6c1d0f1b3df50c2b5b..da62ebf72d55940df96f7c5821d4252b8f91a815 100644 --- a/exist-app/modules/tapi-img.xqm +++ b/exist-app/modules/tapi-img.xqm @@ -125,17 +125,7 @@ as xs:string { :) declare function tapi-img:is-image-public($img-uri as xs:string) as xs:boolean { - let $request := - try { - hc:send-request( - <hc:request method="GET" - href="https://textgridlab.org/1.0/tgcrud/rest/textgrid:{$img-uri}/metadata?sessionId={environment-variable('TEXTGRID.SESSION')}" - /> - ) - } catch * { - error(QName("http://ahikar.sub.uni-goettingen.de/ns/tapi/images", "IMG01"), "Requested image with the URI " || $img-uri || " could not be fetched from TextGrid.") - } - + let $request := tapi-img:get-img-metadata($img-uri) let $request-header := $request[1] let $request-body := $request[2] return @@ -149,6 +139,18 @@ as xs:boolean { false() }; +declare function tapi-img:get-img-metadata($img-uri as xs:string) { + try { + hc:send-request( + <hc:request method="GET" + href="https://textgridlab.org/1.0/tgcrud/rest/textgrid:{$img-uri}/metadata?sessionId={environment-variable('TEXTGRID.SESSION')}" + /> + ) + } catch * { + error(QName("http://ahikar.sub.uni-goettingen.de/ns/tapi/images", "IMG01"), "Requested image with the URI " || $img-uri || " could not be fetched from TextGrid.") + } +}; + declare function tapi-img:get-relevant-image-section($manifest-uri as xs:string, $page-uri as xs:string) as xs:string { diff --git a/exist-app/modules/tapi-item.xqm b/exist-app/modules/tapi-item.xqm index 50f0761b5dc32842159c3bffd9a545628a4e38f6..bf7a40beba523924ba70305e4391faad2de50571 100644 --- a/exist-app/modules/tapi-item.xqm +++ b/exist-app/modules/tapi-item.xqm @@ -9,8 +9,10 @@ xquery version "3.1"; module namespace tapi-item="http://ahikar.sub.uni-goettingen.de/ns/tapi/item"; declare namespace tei="http://www.tei-c.org/ns/1.0"; +declare namespace tgmd="http://textgrid.info/namespaces/metadata/core/2010"; import module namespace commons="http://ahikar.sub.uni-goettingen.de/ns/commons" at "commons.xqm"; +import module namespace functx="http://www.functx.com"; import module namespace tapi-img="http://ahikar.sub.uni-goettingen.de/ns/tapi/images" at "tapi-img.xqm"; @@ -30,6 +32,7 @@ as element(object) { <x-langString>{tapi-item:get-language-string($manifest-uri)}</x-langString> <image> <id>{tapi-item:make-facsimile-id($manifest-uri, $page, $server)}</id> + <license>{tapi-item:make-license-info-for-img($manifest-uri, $page)}</license> </image> <annotationCollection>{$server}/api/annotations/ahikar/{$collection-type}/{$manifest-uri}/{$page}/annotationCollection.json</annotationCollection> </object> @@ -117,3 +120,24 @@ as xs:string { else "restricted/" }; + +declare function tapi-item:make-license-info-for-img($manifest-uri as xs:string, + $page as xs:string) { + let $facsimile-uri := tapi-img:get-facsimile-uri-for-page($manifest-uri, $page) + let $img-metadata := tapi-img:get-img-metadata($facsimile-uri)[2] + let $notes := $img-metadata//tgmd:notes + => substring-after("access. ") + let $id := + if (matches($notes, "CC")) then + functx:get-matches($notes, "CC.*?\.\d") + => replace(" ", "-") + else if (matches(lower-case($notes), "public domain")) then + "Public domain" + else + "Copyright" + return + ( + <id>{$id}</id>, + <notes>{$notes}</notes> + ) +}; diff --git a/exist-app/tests/tapi-img-tests.xqm b/exist-app/tests/tapi-img-tests.xqm index 1336b8fc0ed4cd0c327aa82afe38d7822dc9bb36..ad12305f0723344b78399844652e28e3c5215754 100644 --- a/exist-app/tests/tapi-img-tests.xqm +++ b/exist-app/tests/tapi-img-tests.xqm @@ -115,9 +115,9 @@ as xs:string { declare %test:args("textgrid:1234 textgrid:4365") %test:assertError -function t:is-image-public($img-uri as xs:string) +function t:get-img-metadata($img-uri as xs:string) as xs:boolean { - tapi-img:is-image-public($img-uri) + tapi-img:get-img-metadata($img-uri) }; declare function local:create-and-store-test-data() diff --git a/exist-app/tests/tapi-item-tests.xqm b/exist-app/tests/tapi-item-tests.xqm index e67b9eea73a94fc8695c19e174f66654d8fb19d8..5131e057f6c53e0192f25046beca6ec3bc68ccb4 100644 --- a/exist-app/tests/tapi-item-tests.xqm +++ b/exist-app/tests/tapi-item-tests.xqm @@ -64,6 +64,8 @@ declare %test:assertXPath("$result//*[local-name(.) = 'content'] = 'http://0.0.0.0:8080/exist/restxq/api/content/sample_teixml-82a.html' ") (: checks if images connected to underlying pages are identified :) %test:assertXPath("$result//*[local-name(.) = 'id'] = 'http://0.0.0.0:8080/exist/restxq/api/images/restricted/3r1nz/50.03,0.48,49.83,100.00' ") + %test:assertXPath("$result//*[local-name(.) = 'license']//*[local-name(.) = 'id']") + %test:assertXPath("$result//*[local-name(.) = 'license']//*[local-name(.) = 'notes']") %test:assertXPath("$result//*[local-name(.) = 'annotationCollection'] = 'http://0.0.0.0:8080/exist/restxq/api/annotations/ahikar/sample_main_edition/sample_edition/82a/annotationCollection.json' ") function titemt:get-json($collection as xs:string, $document as xs:string, @@ -101,7 +103,7 @@ as xs:string { declare %test:args("3qzg5") %test:assertEquals("public/") - %test:args("3r85p") %test:assertEquals("restricted/") + %test:args("3r1nz") %test:assertEquals("restricted/") %test:assumeInternetAccess("https://textgridlab.org/1.0/tgcrud-public/rest/") function titemt:make-restricted-or-public-path-component($facsimile-uri as xs:string) as xs:string { @@ -110,7 +112,7 @@ as xs:string { declare %test:args("3qzg5") %test:assertEquals("http://0.0.0.0:8080/exist/restxq/api/images/public/3qzg5") - %test:args("3r85p") %test:assertEquals("http://0.0.0.0:8080/exist/restxq/api/images/restricted/3r85p") + %test:args("3r1nz") %test:assertEquals("http://0.0.0.0:8080/exist/restxq/api/images/restricted/3r1nz") %test:assumeInternetAccess("https://textgridlab.org/1.0/tgcrud-public/rest/") function titemt:make-img-url-prefix($facsimile-uri as xs:string) as xs:string { @@ -147,4 +149,3 @@ declare function local:remove-test-data() { xmldb:remove("/db/data/textgrid/meta", "ahiqar_sample_2.xml"), xmldb:remove("/db/data/textgrid/meta", "ahiqar_agg_wo_tile.xml") }; -