Skip to content

Commit

Permalink
move beacon to separate module
Browse files Browse the repository at this point in the history
and got rid of outdated api.xql
  • Loading branch information
peterstadler committed Aug 21, 2020
1 parent ac63e94 commit 6970cd1
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 215 deletions.
24 changes: 6 additions & 18 deletions controller.xql
Original file line number Diff line number Diff line change
Expand Up @@ -191,32 +191,26 @@ else if (matches($exist:path, concat('^/', $lang, '/[pg]nd/', '[-0-9X]+(\.\w+)?$
(: PND Beacon :)
else if (matches($exist:path, '^/pnd_beacon.txt$')) then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{concat($exist:controller, '/modules/dev/api.xql')}">
<add-parameter name="func" value="create-beacon"/>
<add-parameter name="type" value="pnd"/>
<add-parameter name="format" value="txt"/>
<forward url="{concat($exist:controller, '/modules/beacon.xql')}">
<set-attribute name="beacon" value="pnd"/>
<cache-control cache="yes"/>
</forward>
</dispatch>

(: GKD Beacon :)
else if (matches($exist:path, '^/gkd_beacon.txt$')) then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{concat($exist:controller, '/modules/dev/api.xql')}">
<add-parameter name="func" value="create-beacon"/>
<add-parameter name="type" value="gkd"/>
<add-parameter name="format" value="txt"/>
<forward url="{concat($exist:controller, '/modules/beacon.xql')}">
<set-attribute name="beacon" value="gkd"/>
<cache-control cache="yes"/>
</forward>
</dispatch>

(: Works Beacon :)
else if (matches($exist:path, '^/works_beacon.txt$')) then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{concat($exist:controller, '/modules/dev/api.xql')}">
<add-parameter name="func" value="create-beacon"/>
<add-parameter name="type" value="works"/>
<add-parameter name="format" value="txt"/>
<forward url="{concat($exist:controller, '/modules/beacon.xql')}">
<set-attribute name="beacon" value="works"/>
<cache-control cache="yes"/>
</forward>
</dispatch>
Expand Down Expand Up @@ -270,12 +264,6 @@ else if (matches($exist:path, '^/schema/v\d+\.\d+\.\d+/')) then
</dispatch>
:)

(: allow access to API (needed for datePicker) :)
else if($exist:path eq '/dev/api.xql') then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{concat($exist:controller, '/modules/dev/', $exist:resource)}"/>
</dispatch>

(: general forwarding of folder 'dev' for development XQueries :)
else if($config:isDevelopment and starts-with($exist:path, '/dev/')) then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
Expand Down
88 changes: 88 additions & 0 deletions modules/beacon.xql
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
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 beacon="https://de.wikipedia.org/wiki/Wikipedia:BEACON";
declare namespace request="http://exist-db.org/xquery/request";
declare namespace response="http://exist-db.org/xquery/response";

import module namespace core="http://xquery.weber-gesamtausgabe.de/modules/core" at "core.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 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";

declare option output:method "text";
declare option output:media-type "text/plain";


declare function beacon:new($type as xs:string) as xs:string {
let $gnd-ids :=
switch($type)
case 'pnd' return core:data-collection('persons')//tei:idno[@type='gnd']
case 'gkd' return core:data-collection('orgs')//tei:idno[@type='gnd']
case 'works' return core:data-collection('works')//mei:altId[@type='gnd']
default return ()
let $desc :=
switch($type)
case 'pnd' return '#DESCRIPTION: Personendatensätze der Carl-Maria-von-Weber-Gesamtausgabe'
case 'gkd' return '#DESCRIPTION: Datensätze Organisationen/Körperschaften der Carl-Maria-von-Weber-Gesamtausgabe'
case 'works' return '#DESCRIPTION: Werkdatensätze der Carl-Maria-von-Weber-Gesamtausgabe'
default return ()
let $feed :=
switch($type)
case 'pnd' return '#FEED: http://weber-gesamtausgabe.de/pnd_beacon.txt'
case 'gkd' return '#FEED: http://weber-gesamtausgabe.de/gkd_beacon.txt'
case 'works' return '#FEED: http://weber-gesamtausgabe.de/works_beacon.txt'
default return ()
let $header := (
'#FORMAT: BEACON',
'#PREFIX: http://d-nb.info/gnd/',
'#VERSION: 0.1',
'#TARGET: https://weber-gesamtausgabe.de/de/gnd/{ID}',
$feed,
'#CONTACT: Peter Stadler <stadler [ at ] weber-gesamtausgabe.de>',
'#INSTITUTION: Carl-Maria-von-Weber-Gesamtausgabe (WeGA)',
$desc,
concat('#TIMESTAMP: ', current-dateTime())
)
return concat(
string-join($header, '&#10;'),
'&#10;',
string-join($gnd-ids, '&#10;')
)
};

declare function beacon:beacon($type as xs:string) as xs:string {
let $fileName :=
switch($type)
case 'pnd' return 'pnd_beacon.txt'
case 'gkd' return 'gkd_beacon.txt'
case 'works' return 'works_beacon.txt'
default return ()
let $onFailureFunc := function($errCode, $errDesc) {
core:logToFile('warn', string-join(($errCode, $errDesc), ' ;; '))
}
return
util:binary-to-string(
mycache:doc(
str:join-path-elements(($config:tmp-collection-path, $fileName)),
beacon:new#1, $type,
function($currentDateTimeOfFile as xs:dateTime?) as xs:boolean { wega-util:check-if-update-necessary($currentDateTimeOfFile, ()) },
$onFailureFunc
)
)
};

let $beacon := request:get-attribute('beacon')
let $setHeader := response:set-header('Access-Control-Allow-Origin', '*')
return
beacon:beacon($beacon)
197 changes: 0 additions & 197 deletions modules/dev/api.xql

This file was deleted.

0 comments on commit 6970cd1

Please sign in to comment.