From c24f25ec0541ef9b075b832c5fa55e79010b61eb Mon Sep 17 00:00:00 2001 From: Dennis Ried Date: Tue, 6 Aug 2024 16:42:00 +0200 Subject: [PATCH 01/10] make lod functions public --- modules/lod.xqm | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/lod.xqm b/modules/lod.xqm index 22cd9ea26..793a35701 100644 --- a/modules/lod.xqm +++ b/modules/lod.xqm @@ -184,7 +184,7 @@ declare %private function lod:jsonld-entity($elem as element(), $lang as xs:stri (:~ : Helper function for creating the page description ~:) -declare %private function lod:DC.description($model as map(*), $lang as xs:string) as xs:string? { +declare function lod:DC.description($model as map(*), $lang as xs:string) as xs:string? { if($model?specID) then lang:get-language-string('metaDescriptionGuidelinesSpecs', ($model?specID), $lang) else if($model?chapID) then switch($model?chapID) @@ -226,7 +226,7 @@ declare %private function lod:DC.description($model as map(*), $lang as xs:strin (:~ : Helper function for creating the page title ~:) -declare %private function lod:page-title($model as map(*), $lang as xs:string) as xs:string? { +declare function lod:page-title($model as map(*), $lang as xs:string) as xs:string? { if($model?specID) then lang:get-language-string('metaTitleGuidelinesSpecs', ($model?specID, $model?schemaID), $lang) else if($model?chapID) then switch($model?chapID) @@ -251,7 +251,7 @@ declare %private function lod:page-title($model as map(*), $lang as xs:string) a (:~ : Helper function for creating the page title ~:) -declare %private function lod:DC.subject($model as map(*), $lang as xs:string) as xs:string? { +declare function lod:DC.subject($model as map(*), $lang as xs:string) as xs:string? { if($model?specID or $model?chapID) then 'Guidelines; Encoding' else switch($model('docID')) @@ -274,7 +274,7 @@ declare %private function lod:DC.subject($model as map(*), $lang as xs:string) a (:~ : Helper function for collecting creator information ~:) -declare %private function lod:DC.creator($model as map(*)) as xs:string? { +declare function lod:DC.creator($model as map(*)) as xs:string? { if($model('docID') = ('indices', 'home', 'search')) then 'Carl-Maria-von-Weber-Gesamtausgabe' else if($model?specID or $model?chapID) then 'Carl-Maria-von-Weber-Gesamtausgabe' else if(config:get-doctype-by-id($model('docID'))) then map:get(config:get-svn-props($model('docID')), 'author') @@ -294,7 +294,7 @@ declare %private function lod:DC.date($model as map(*)) as xs:string? { (:~ : Helper function for collecting identifier information ~:) -declare %private function lod:DC.identifier($model as map(*)) as xs:string? { +declare function lod:DC.identifier($model as map(*)) as xs:string? { if($model('docID') = ('indices', 'search')) then request:get-url() else if($model('docID') = 'home') then 'http://weber-gesamtausgabe.de' else if($model?specID or $model?chapID) then request:get-url() From a7db1fd5de7048c86fbb960251643c12ba1ebc7c Mon Sep 17 00:00:00 2001 From: Dennis Ried Date: Tue, 6 Aug 2024 16:42:22 +0200 Subject: [PATCH 02/10] introduce export as oai-xml --- modules/oai.xql | 117 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 modules/oai.xql diff --git a/modules/oai.xql b/modules/oai.xql new file mode 100644 index 000000000..4f521675b --- /dev/null +++ b/modules/oai.xql @@ -0,0 +1,117 @@ +xquery version "3.1" encoding "UTF-8"; + +(:~ + : + : Module for exporting BEACON files + : see https://de.wikipedia.org/wiki/Wikipedia:BEACON + : + :) + +declare namespace tei="http://www.tei-c.org/ns/1.0"; +declare namespace mei="http://www.music-encoding.org/ns/mei"; +declare namespace output="http://www.w3.org/2010/xslt-xquery-serialization"; +declare namespace request="http://exist-db.org/xquery/request"; +declare namespace response="http://exist-db.org/xquery/response"; +declare namespace util="http://exist-db.org/xquery/util"; +declare namespace oai="http://www.openarchives.org/OAI/2.0/"; + +import module namespace functx="http://www.functx.com"; +import module namespace crud="http://xquery.weber-gesamtausgabe.de/modules/crud" at "crud.xqm"; +import module namespace config="http://xquery.weber-gesamtausgabe.de/modules/config" at "config.xqm"; +import module namespace wega-util="http://xquery.weber-gesamtausgabe.de/modules/wega-util" at "wega-util.xqm"; +import module namespace date="http://xquery.weber-gesamtausgabe.de/modules/date" at "xmldb:exist:///db/apps/WeGA-WebApp-lib/xquery/date.xqm"; +import module namespace str="http://xquery.weber-gesamtausgabe.de/modules/str" at "xmldb:exist:///db/apps/WeGA-WebApp-lib/xquery/str.xqm"; +import module namespace mycache="http://xquery.weber-gesamtausgabe.de/modules/cache" at "xmldb:exist:///db/apps/WeGA-WebApp-lib/xquery/cache.xqm"; +import module namespace lod="http://xquery.weber-gesamtausgabe.de/modules/lod" at "lod.xqm"; +import module namespace lang="http://xquery.weber-gesamtausgabe.de/modules/lang" at "lang.xqm"; +import module namespace query="http://xquery.weber-gesamtausgabe.de/modules/query" at "query.xqm"; +import module namespace wdt="http://xquery.weber-gesamtausgabe.de/modules/wdt" at "wdt.xqm"; + +declare option output:method "xml"; +declare option output:media-type "application/xml"; +declare option output:indent "yes"; + +declare variable $oai:last-modified as xs:dateTime? := + if($config:svn-change-history-file/dictionary/@dateTime castable as xs:dateTime) + then $config:svn-change-history-file/dictionary/xs:dateTime(@dateTime) + else ( + let $versionDateSeq := tokenize(config:get-option('versionDate'),'-') + let $year := subsequence($versionDateSeq,1,1) + let $month := subsequence($versionDateSeq,2,1) + let $day := subsequence($versionDateSeq,3,1) + return + functx:dateTime($year,$month,$day,0,0,0) + ); + +declare %private function oai:response-headers() as empty-sequence() { + response:set-header('Access-Control-Allow-Origin', '*'), + response:set-header('Last-Modified', date:rfc822($oai:last-modified)), + response:set-header('Cache-Control', 'max-age=300,public') +}; + +declare function oai:oai($model as map(*)) as node() { + + {fn:current-dateTime()} + http://www.openarchives.org/OAI/2.0/oai_dc/ + + {oai:record($model)} + + +}; + +declare function oai:record($model as map(*)) as node() { + let $docID := $model('docID') + let $lang := $model('lang') + return + +
+ {lod:DC.identifier($model)} + {fn:current-dateTime()} + {$model('docType')} +
+ + + {lod:page-title($model, $lang)} + {lod:DC.creator($model)} + {lod:DC.subject($model, $lang)} + {lod:DC.description($model, $lang)} + {substring($oai:last-modified,1,10)} + {$docID} + + + + + + {config:get-option('permaLinkPrefix')} + {$docID} + {substring($oai:last-modified,1,10)} + http://www.openarchives.org/OAI/2.0/oai_dc/ + + + +
+}; + +let $lang := config:guess-language(()) +let $docID := request:get-attribute('docID') +let $doc := crud:doc($docID) +let $model := + map { + 'lang': $lang, + 'docID': $docID, + 'doc': $doc, + 'docType': config:get-doctype-by-id($docID) + } +return + ( + oai:response-headers(), + response:set-status-code(202), + oai:oai($model) + ) \ No newline at end of file From 1c679614af32e6a720114fb0b5dd1d69a65db1ec Mon Sep 17 00:00:00 2001 From: Dennis Ried Date: Tue, 6 Aug 2024 16:42:40 +0200 Subject: [PATCH 03/10] activate export --- controller.xql | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/controller.xql b/controller.xql index 5ed8a9db2..23a843d34 100644 --- a/controller.xql +++ b/controller.xql @@ -236,6 +236,14 @@ else if (matches($exist:path, '^/cmif_v2.xml$')) then +(: OAI-PMH-Interface :) +else if (matches($exist:path, '/(en|de)?/?' || config:get-option('generalIdPattern') || '(.*)/oai.xml')) then + + + + + + (: Sitemap :) else if (matches($exist:path, '^/sitemap(/?|/index.xml)?$') or matches($exist:path, '^/sitemap/sitemap_(en|de).xml.(gz|zip)$')) then From 5884bb79955f0bfe404a8418f508aaaed5eb8c66 Mon Sep 17 00:00:00 2001 From: Dennis Ried Date: Thu, 22 Aug 2024 19:45:20 +0200 Subject: [PATCH 04/10] call DC data by reading the lod output map --- modules/oai.xql | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/modules/oai.xql b/modules/oai.xql index 4f521675b..1e8df834e 100644 --- a/modules/oai.xql +++ b/modules/oai.xql @@ -62,10 +62,11 @@ declare function oai:oai($model as map(*)) as node() { declare function oai:record($model as map(*)) as node() { let $docID := $model('docID') let $lang := $model('lang') + let $lod-metadata := lod:metadata(, $model, $lang) return
- {lod:DC.identifier($model)} + {$lod-metadata?DC.identifier} {fn:current-dateTime()} {$model('docType')}
@@ -75,10 +76,10 @@ declare function oai:record($model as map(*)) as node() { xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd"> - {lod:page-title($model, $lang)} - {lod:DC.creator($model)} - {lod:DC.subject($model, $lang)} - {lod:DC.description($model, $lang)} + {$lod-metadata?meta-page-title} + {$lod-metadata?DC.creator} + {$lod-metadata?DC.subject} + {$lod-metadata?DC.description} {substring($oai:last-modified,1,10)} {$docID} From dde09189da44d12008d7f249428ce53edb8dfde8 Mon Sep 17 00:00:00 2001 From: Dennis Ried Date: Thu, 22 Aug 2024 19:45:38 +0200 Subject: [PATCH 05/10] adding documentation --- modules/oai.xql | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/modules/oai.xql b/modules/oai.xql index 1e8df834e..042c2c9aa 100644 --- a/modules/oai.xql +++ b/modules/oai.xql @@ -1,10 +1,8 @@ xquery version "3.1" encoding "UTF-8"; (:~ - : - : Module for exporting BEACON files - : see https://de.wikipedia.org/wiki/Wikipedia:BEACON - : + : Module for exporting data as oai/xml + : see https://www.openarchives.org/OAI/openarchivesprotocol.html :) declare namespace tei="http://www.tei-c.org/ns/1.0"; @@ -31,6 +29,11 @@ declare option output:method "xml"; declare option output:media-type "application/xml"; declare option output:indent "yes"; +(:~ + : Get the last date of modification from dataHistory.xml. Fallback: VersionDate from options.xml + : + : @author Dennis Ried +:) declare variable $oai:last-modified as xs:dateTime? := if($config:svn-change-history-file/dictionary/@dateTime castable as xs:dateTime) then $config:svn-change-history-file/dictionary/xs:dateTime(@dateTime) @@ -43,12 +46,22 @@ declare variable $oai:last-modified as xs:dateTime? := functx:dateTime($year,$month,$day,0,0,0) ); +(:~ + : Create a header response + : + : @author Dennis Ried +:) declare %private function oai:response-headers() as empty-sequence() { response:set-header('Access-Control-Allow-Origin', '*'), response:set-header('Last-Modified', date:rfc822($oai:last-modified)), response:set-header('Cache-Control', 'max-age=300,public') }; +(:~ + : Creating the response for the interface (header, calling record by oai:record) + : + : @author Dennis Ried +:) declare function oai:oai($model as map(*)) as node() { {fn:current-dateTime()} @@ -59,6 +72,11 @@ declare function oai:oai($model as map(*)) as node() { }; +(:~ + : Creating the record for the called file (body of response) + : + : @author Dennis Ried +:) declare function oai:record($model as map(*)) as node() { let $docID := $model('docID') let $lang := $model('lang') From cd5da9c2d1cfa9ab95ed4dfd1ba2d36c80946ed0 Mon Sep 17 00:00:00 2001 From: Dennis Ried Date: Thu, 22 Aug 2024 19:46:06 +0200 Subject: [PATCH 06/10] Revert "make lod functions public" This reverts commit c24f25ec0541ef9b075b832c5fa55e79010b61eb. --- modules/lod.xqm | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/lod.xqm b/modules/lod.xqm index 793a35701..22cd9ea26 100644 --- a/modules/lod.xqm +++ b/modules/lod.xqm @@ -184,7 +184,7 @@ declare %private function lod:jsonld-entity($elem as element(), $lang as xs:stri (:~ : Helper function for creating the page description ~:) -declare function lod:DC.description($model as map(*), $lang as xs:string) as xs:string? { +declare %private function lod:DC.description($model as map(*), $lang as xs:string) as xs:string? { if($model?specID) then lang:get-language-string('metaDescriptionGuidelinesSpecs', ($model?specID), $lang) else if($model?chapID) then switch($model?chapID) @@ -226,7 +226,7 @@ declare function lod:DC.description($model as map(*), $lang as xs:string) as xs: (:~ : Helper function for creating the page title ~:) -declare function lod:page-title($model as map(*), $lang as xs:string) as xs:string? { +declare %private function lod:page-title($model as map(*), $lang as xs:string) as xs:string? { if($model?specID) then lang:get-language-string('metaTitleGuidelinesSpecs', ($model?specID, $model?schemaID), $lang) else if($model?chapID) then switch($model?chapID) @@ -251,7 +251,7 @@ declare function lod:page-title($model as map(*), $lang as xs:string) as xs:stri (:~ : Helper function for creating the page title ~:) -declare function lod:DC.subject($model as map(*), $lang as xs:string) as xs:string? { +declare %private function lod:DC.subject($model as map(*), $lang as xs:string) as xs:string? { if($model?specID or $model?chapID) then 'Guidelines; Encoding' else switch($model('docID')) @@ -274,7 +274,7 @@ declare function lod:DC.subject($model as map(*), $lang as xs:string) as xs:stri (:~ : Helper function for collecting creator information ~:) -declare function lod:DC.creator($model as map(*)) as xs:string? { +declare %private function lod:DC.creator($model as map(*)) as xs:string? { if($model('docID') = ('indices', 'home', 'search')) then 'Carl-Maria-von-Weber-Gesamtausgabe' else if($model?specID or $model?chapID) then 'Carl-Maria-von-Weber-Gesamtausgabe' else if(config:get-doctype-by-id($model('docID'))) then map:get(config:get-svn-props($model('docID')), 'author') @@ -294,7 +294,7 @@ declare %private function lod:DC.date($model as map(*)) as xs:string? { (:~ : Helper function for collecting identifier information ~:) -declare function lod:DC.identifier($model as map(*)) as xs:string? { +declare %private function lod:DC.identifier($model as map(*)) as xs:string? { if($model('docID') = ('indices', 'search')) then request:get-url() else if($model('docID') = 'home') then 'http://weber-gesamtausgabe.de' else if($model?specID or $model?chapID) then request:get-url() From bf6ef976c80a2a7ec8887a77a946ae0ab5b47486 Mon Sep 17 00:00:00 2001 From: Dennis Ried Date: Fri, 23 Aug 2024 14:22:01 +0200 Subject: [PATCH 07/10] update get last-modified --- modules/oai.xql | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/modules/oai.xql b/modules/oai.xql index 042c2c9aa..953b2e227 100644 --- a/modules/oai.xql +++ b/modules/oai.xql @@ -31,29 +31,28 @@ declare option output:indent "yes"; (:~ : Get the last date of modification from dataHistory.xml. Fallback: VersionDate from options.xml - : : @author Dennis Ried + : + : @param $docID The ID of the document + : return The date ad xs:dateTime or empty :) -declare variable $oai:last-modified as xs:dateTime? := - if($config:svn-change-history-file/dictionary/@dateTime castable as xs:dateTime) - then $config:svn-change-history-file/dictionary/xs:dateTime(@dateTime) - else ( - let $versionDateSeq := tokenize(config:get-option('versionDate'),'-') - let $year := subsequence($versionDateSeq,1,1) - let $month := subsequence($versionDateSeq,2,1) - let $day := subsequence($versionDateSeq,3,1) - return - functx:dateTime($year,$month,$day,0,0,0) - ); +declare %private function oai:last-modified($docID) as xs:dateTime? { + if($config:svn-change-history-file//entry[@xml:id=$docID]/@dateTime castable as xs:dateTime) + then ($config:svn-change-history-file//entry[@xml:id=$docID]/@dateTime => xs:dateTime()) + else if (config:get-option('versionDate') castable as xs:dateTime) + then(config:get-option('versionDate') => xs:dateTime()) + else() + ) +}; (:~ : Create a header response : : @author Dennis Ried :) -declare %private function oai:response-headers() as empty-sequence() { +declare %private function oai:response-headers($docID) as empty-sequence() { response:set-header('Access-Control-Allow-Origin', '*'), - response:set-header('Last-Modified', date:rfc822($oai:last-modified)), + response:set-header('Last-Modified', date:rfc822(oai:last-modified($docID))), response:set-header('Cache-Control', 'max-age=300,public') }; @@ -80,6 +79,7 @@ declare function oai:oai($model as map(*)) as node() { declare function oai:record($model as map(*)) as node() { let $docID := $model('docID') let $lang := $model('lang') + let $dc-date := oai:last-modified($docID) => substring(1,10) let $lod-metadata := lod:metadata(, $model, $lang) return @@ -98,7 +98,7 @@ declare function oai:record($model as map(*)) as node() { {$lod-metadata?DC.creator} {$lod-metadata?DC.subject} {$lod-metadata?DC.description} - {substring($oai:last-modified,1,10)} + {$dc-date} {$docID} @@ -110,7 +110,7 @@ declare function oai:record($model as map(*)) as node() { {config:get-option('permaLinkPrefix')} {$docID} - {substring($oai:last-modified,1,10)} + {$dc-date} http://www.openarchives.org/OAI/2.0/oai_dc/ @@ -130,7 +130,7 @@ let $model := } return ( - oai:response-headers(), + oai:response-headers($docID), response:set-status-code(202), oai:oai($model) ) \ No newline at end of file From 9225cff26b38fa422472d2a87545d38d19ce5590 Mon Sep 17 00:00:00 2001 From: Dennis Ried Date: Fri, 23 Aug 2024 14:22:10 +0200 Subject: [PATCH 08/10] fix call of private function --- modules/oai.xql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/oai.xql b/modules/oai.xql index 953b2e227..7a5ebee60 100644 --- a/modules/oai.xql +++ b/modules/oai.xql @@ -64,7 +64,7 @@ declare %private function oai:response-headers($docID) as empty-sequence() { declare function oai:oai($model as map(*)) as node() { {fn:current-dateTime()} - http://www.openarchives.org/OAI/2.0/oai_dc/ + http://www.openarchives.org/OAI/2.0/oai_dc/ {oai:record($model)} From e54b0a1d7ba9897dd91f8f336a48cb7fb0569f47 Mon Sep 17 00:00:00 2001 From: Dennis Ried Date: Fri, 23 Aug 2024 16:33:25 +0200 Subject: [PATCH 09/10] update get last-modified (date) --- modules/oai.xql | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/modules/oai.xql b/modules/oai.xql index 7a5ebee60..e0c238b11 100644 --- a/modules/oai.xql +++ b/modules/oai.xql @@ -36,13 +36,12 @@ declare option output:indent "yes"; : @param $docID The ID of the document : return The date ad xs:dateTime or empty :) -declare %private function oai:last-modified($docID) as xs:dateTime? { - if($config:svn-change-history-file//entry[@xml:id=$docID]/@dateTime castable as xs:dateTime) - then ($config:svn-change-history-file//entry[@xml:id=$docID]/@dateTime => xs:dateTime()) - else if (config:get-option('versionDate') castable as xs:dateTime) - then(config:get-option('versionDate') => xs:dateTime()) - else() - ) +declare %private function oai:last-modified($docID) as xs:dateTime { + let $props := config:get-data-props($docID) + return + if($props?dateTime castable as xs:dateTime) + then ($props?dateTime => xs:dateTime()) + else (fn:current-dateTime()) }; (:~ From 3ce6c79fe015d8fbb7cc40c1425207c92e2bec3c Mon Sep 17 00:00:00 2001 From: Dennis Ried Date: Sat, 31 Aug 2024 06:37:25 +0200 Subject: [PATCH 10/10] Update modules/oai.xql Co-authored-by: Peter Stadler --- modules/oai.xql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/oai.xql b/modules/oai.xql index e0c238b11..62df547c2 100644 --- a/modules/oai.xql +++ b/modules/oai.xql @@ -125,7 +125,8 @@ let $model := 'lang': $lang, 'docID': $docID, 'doc': $doc, - 'docType': config:get-doctype-by-id($docID) + 'docType': config:get-doctype-by-id($docID), + 'lod': lod:metadata(, $model, $lang) } return (