Skip to content

Commit

Permalink
add works BEACON file and redirections #169
Browse files Browse the repository at this point in the history
  • Loading branch information
peterstadler committed Jul 6, 2018
1 parent 43d5e03 commit 8ede622
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
11 changes: 11 additions & 0 deletions controller.xql
Expand Up @@ -241,6 +241,17 @@ else if (matches($exist:path, '^/gkd_beacon.txt$')) then
<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"/>
<cache-control cache="yes"/>
</forward>
</dispatch>

(: correspDesc Beacon :)
else if (matches($exist:path, '^/correspDesc.xml$')) then
Expand Down
3 changes: 2 additions & 1 deletion modules/controller.xqm
Expand Up @@ -403,7 +403,8 @@ declare function controller:translate-URI($uri as xs:string, $sourceLang as xs:s
};

declare function controller:redirect-by-gnd($exist-vars as map(*)) as element(exist:dispatch) {
let $doc := query:doc-by-gnd(controller:basename($exist-vars('exist:resource')))
(: especially for works there can be several documents with the same GND :)
let $doc := query:doc-by-gnd(controller:basename($exist-vars('exist:resource')))[last()]
let $media-type := controller:media-type($exist-vars)
return
if(exists($doc) and $media-type) then controller:redirect-absolute(controller:path-to-resource($doc, $exist-vars('lang')) || '.' || $media-type)
Expand Down
12 changes: 10 additions & 2 deletions modules/dev/api.xql
Expand Up @@ -72,29 +72,35 @@ declare function local:diaryDay-to-kml($params as map(*)) as element(kml:Placema
</kml:kml>
};


(:~
: Create BEACON files
: (see https://de.wikipedia.org/wiki/Wikipedia:BEACON)
~:)
declare function local:create-beacon($params as map(*)) as xs:string {
let $callBack := function($type as xs:string) {
let $pnds :=
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: http://www.weber-gesamtausgabe.de/de/gnd/{ID}',
'#TARGET: https://weber-gesamtausgabe.de/de/gnd/{ID}',
$feed,
'#CONTACT: Peter Stadler <stadler [ at ] weber-gesamtausgabe.de>',
'#INSTITUTION: Carl Maria von Weber Gesamtausgabe (WeGA)',
Expand All @@ -111,6 +117,7 @@ declare function local:create-beacon($params as map(*)) as xs:string {
switch($params('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), ' ;; '))
Expand All @@ -125,6 +132,7 @@ declare function local:create-beacon($params as map(*)) as xs:string {
)
)
};

(:http://localhost:8080/exist/apps/WeGA-WebApp/dev/api.xql?func=facets&docID=indices&docType=letters&facet=sender&format=json:)
declare function local:facets($params as map(*)) {
let $search := search:results(<span/>, map { 'docID' := $params('docID') }, $params('docType'))
Expand Down
2 changes: 1 addition & 1 deletion modules/query.xqm
Expand Up @@ -82,7 +82,7 @@ declare function query:get-author-element($doc as document-node()?) as element()
: @param $gnd the GND (Gemeinsame Normdatei = German Authority File) identifier
: @return xs:string
:)
declare function query:doc-by-gnd($gnd as xs:string) as document-node()? {
declare function query:doc-by-gnd($gnd as xs:string) as document-node()* {
core:getOrCreateColl('persons', 'indices', true())//tei:idno[.=$gnd][@type='gnd']/root() |
core:getOrCreateColl('orgs', 'indices', true())//tei:idno[.=$gnd][@type='gnd']/root() |
core:getOrCreateColl('works', 'indices', true())//mei:altId[.=$gnd][@type='gnd']/root()
Expand Down

0 comments on commit 8ede622

Please sign in to comment.