Commit 308270d3 authored by Mathias Goebel's avatar Mathias Goebel 🎠
Browse files

cleanup 4 architrave

parent 4853f3df
......@@ -8,5 +8,4 @@
<dependency package="http://exist-db.org/apps/shared"/>
<dependency package="http://textgrid.de/ns/SADE"/>
<dependency package="http://textgrid.de/exist/textgrid-connect"/>
<dependency package="http://textgrid.de/exist/fontane-lucene-exist-module"/>
</package>
xquery version "3.1";
xmldb:move("/db/apps/fontane/sade-projects", "/db")
import module namespace tgconnect="http://textgrid.info/namespaces/xquery/tgconnect" at "/db/apps/textgrid-connect/tg-connect.xql";
import module namespace tgclient="http://textgrid.info/namespaces/xquery/tgclient" at "/db/apps/textgrid-connect/tgclient.xqm";
declare namespace tgmd="http://textgrid.info/namespaces/metadata/core/2010";
declare variable $port := "8080";
declare variable $baseUrl := "http://localhost:" || $port ||"/exist/apps/SADE/textgrid/";
declare function local:test($what as xs:string) as xs:boolean {
switch ($what)
case "markdown" return local:test-do( $baseUrl || "content.html?id=institutionen.md", $testResultsExpected($what) )
case "doku-li" return local:test-do( $baseUrl || "doku.html", $testResultsExpected($what) )
case "doku-page" return local:test-do( $baseUrl || "doku.html?id=gesamtdokumentation_iii.3.10", $testResultsExpected($what) )
case "search" return local:test-do( $baseUrl || "results.html?q=luther", $testResultsExpected($what))
case "litvz" return local:test-do( $baseUrl || "literaturvz.html", $testResultsExpected($what))
default return ()
};
declare function local:test-do($url as xs:string, $expectation as node()) as xs:boolean {
let $response := local:test-get($url)
let $testIt :=
for $node in $response//*
return
(replace(serialize( $node ), "\s", "") = replace(serialize( $expectation ), "\s", ""))
return
if( count( $testIt[. = true()] ) gt 1 )
then true()
else false()
};
declare function local:test-get($url) {
httpclient:get(xs:anyURI($url), false(), ())
};
declare variable $testResultsExpected :=
map:new(
(map:entry("markdown",
<section>
<div class="block-header">
<h2><span class="title">INSTITUTIONEN</span><span class="decoration"></span><span class="decoration"></span><span class="decoration"></span></h2>
</div>
<ul>
<li>Georg-August-Universität Göttingen, Seminar für Deutsche Philologie, <a href="http://www.uni-goettingen.de/de/154180.html">Theodor Fontane-Arbeitsstelle</a></li>
<li>Georg-August-Universität Göttingen, <a href="http://www.sub.uni-goettingen.de">Niedersächsische Staats- und Universitätsbibliothek Göttingen</a></li>
<li>Digital Research Infrastructure for the Arts and Humanities (<a href="http://www.de.dariah.eu">DARIAH-DE</a>) </li>
<li>TextGrid – Virtuelle Forschungsumgebung für die Geisteswissenschaften (<a href="http://www.textgrid.de">TextGrid</a>)</li>
</ul>
<section>
<h3>Assoziierte Partnerin und Eigentümerin der Notizbücher Theodor Fontanes</h3>
<ul>
<li><a href="http://staatsbibliothek-berlin.de/die-staatsbibliothek/abteilungen/handschriften/">Staatsbibliothek zu Berlin</a>, Preußischer Kulturbesitz, Handschriftenabteilung </li>
</ul>
</section>
</section>),
map:entry("doku-li", <li>
<div> <a href="?id=gesamtdokumentation_iii.3.16">3.16 Verlinkung von Notizbuchaufzeichnungen</a>
</div>
</li>),
map:entry("doku-page", <p>Fettflecken auf den Notizbuchseiten bzw. auf den auf-/angeklebten Blättern und Drucken werden weder für die Transkription noch für den Edierten Text beschrieben, codiert oder visualisiert, es sei denn, sie sind der Grund für eine unentzifferte Zeichenfolge.</p>),
map:entry("search", <span class="hi">Luther</span>),
map:entry("litvz", <ul class="nav nav-tabs" style="font-size: smaller;">
<li class="">
<a data-toggle="tab" href="#I">Fontanes Werke</a>
</li>
<li class="">
<a data-toggle="tab" href="#II">Fontanes Quellen</a>
</li>
<li class="">
<a data-toggle="tab" href="#III">Allgemeine Nachschlagewerke</a>
</li>
<li class="">
<a data-toggle="tab" href="#IV">Nachschlagewerke der Fontane-Forschung</a>
</li>
<li class="">
<a data-toggle="tab" href="#V">Forschungsliteratur</a>
</li>
<li class="">
<a data-toggle="tab" href="#VI">Internetquellen</a>
</li>
</ul>)
));
declare function local:getColor($pos, $count) {
let $steps := (510 div $count) => floor()
let $this := $pos * $steps
return
if( $this lt 255 )
then "255;" || $pos * $steps || ";0"
else 510 - $pos * $steps || ";255;0"
};
(: using static pathes since $target and $dir serve some errors in eXist-db v3.1.1 :)
declare variable $moveProject := (
xmldb:move("/db/apps/fontane/sade-projects", "/db"),
xmldb:move("/db/apps/fontane/system/config/db/sade-projects", "/db/system/config/db"),
(: xmldb:move("/db/apps/fontane/system/config/db", "/db/system/config/db", "collection.xconf"), :)
xmldb:move("/db/apps/fontane/system/autostart", "/db/system")
);
declare variable $preconfigdoc := doc( "/db/sade-projects/textgrid/config.xml" );
declare variable $credentials :=
file:read("/var/lib/textgrid/fontane/credentials.txt")
=> tokenize("\n");
declare variable $credentialInjection :=
for $line at $pos in $credentials
return
switch ($pos)
case 1 return update replace $preconfigdoc//param[@key="textgrid.user"]/text() with text {$line}
case 2 return update replace $preconfigdoc//param[@key="textgrid.password"]/text() with text {$line}
case 3 return (
(update replace $preconfigdoc//param[@key="secret"]/text() with text {$line}),
(update replace $preconfigdoc//param[@key="sade.password"]/text() with text {$line}))
case 4 return update replace $preconfigdoc//param[@key="dokuwiki.user"]/text() with text {$line}
case 5 return update replace $preconfigdoc//param[@key="dokuwiki.password"]/text() with text {$line}
default return false();
declare variable $configdoc := doc( "/db/sade-projects/textgrid/config.xml" );
(:
the security manager is not available during autodeployment
declare variable $SetAdminPw := sm:passwd("admin", string($configdoc//param[@key="secret"]/text()));
:)
declare variable $config := map:new(for $param in $configdoc/config/param
return map:entry(string($param/@key), string($param))
);
declare variable $testone := util:log-system-out("webauth: "||$config("textgrid.webauth"));
declare variable $testtwo := util:log-system-out("webauth: "||$configdoc//param[@key="textgrid.webauth"]/string(.));
declare variable $sid :=
tgclient:getSid(
$config("textgrid.webauth"),
$config("textgrid.authZinstance"),
$config("textgrid.user"),
$config("textgrid.password")
);
let $log := util:log-system-out( "&#27;[30;43m initiating post-install.xql &#27;[0m" )
(: the uris we need to publish in an intended order! :)
let $filters := <filters>
<filter key="format" value="text/xml"/>
<filter key="project.id" value="TGPR-9b18459d-3a6b-004f-b6aa-4fba2b9e1d3e"/>
</filters>
(: im Titel nicht "Notizbuch" :)
let $log := util:log-system-out( "&#27;[30;43m getting non-notebook XML URIs &#27;[0m" )
let $query := "%21%28title%3A%22Notizbuch%22%29"
let $non-notebook-xmls := tgclient:tgsearch-query-filter($filters, $query, $sid, 2000, 0)
//tgmd:textgridUri/substring-before(., ".")
=> distinct-values()
let $filters := <filters>
<filter key="format" value="text/linkeditorlinkedfile"/>
<filter key="project.id" value="TGPR-9b18459d-3a6b-004f-b6aa-4fba2b9e1d3e"/>
</filters>
let $query := ""
let $log := util:log-system-out( "&#27;[30;43m getting TILE object URIs &#27;[0m" )
let $tble-objects := tgclient:tgsearch-query-filter($filters, $query, $sid, 2000, 0)
//tgmd:textgridUri/substring-before(., ".")
=> distinct-values()
let $filters := <filters>
<filter key="format" value="text/xml"/>
<filter key="project.id" value="TGPR-9b18459d-3a6b-004f-b6aa-4fba2b9e1d3e"/>
</filters>
(: im Titel "Notizbuch" :)
let $query := "%28title%3A%22Notizbuch%22%29"
let $log := util:log-system-out( "&#27;[30;43m getting notebook XML URIs &#27;[0m" )
let $notebooks := tgclient:tgsearch-query-filter($filters, $query, $sid, 2000, 0)
//tgmd:textgridUri/substring-before(., ".")
=> distinct-values()
let $notebooks := $notebooks
let $special-files := ( "textgrid:342bm" (: synonyms.txt :)
, "textgrid:34rhf" (: charmap.txt :)
)
let $installSequence := ( $special-files, $tble-objects, $non-notebook-xmls, $notebooks )
let $report := for $uri at $pos in $installSequence
return
update insert (<publish uri="{$uri}"/>) into //initlog/install/todo
let $log := if(count($notebooks) = 1)
then util:log-system-out( "&#27;[38;5;210m&#27;[48;5;33m we are on fastdeploy! &#27;[0m" )
else util:log-system-out( "&#27;[38;5;231m&#27;[48;5;52m complete import… got coffee? &#27;[0m" )
let $count := count( $installSequence )
(: there are some documents with an unknown status in the pipeline: :)
let $removeSomeObjects := ("textgrid:27656", "textgrid:27657", "textgrid:27658", "textgrid:2765b", "textgrid:2765c")
return
(
(: PUBLISH :)
util:log-system-out( "getting DATA from TextGrid…" ),
for $uri at $pos in $installSequence[. != $removeSomeObjects]
where starts-with($uri, "textgrid:")
let $color := local:getColor($pos, $count)
let $systemOut := util:log-system-out( "&#27;[48;2;"|| $color ||"m&#27;[38;2;0;0;0m " || $uri || " &#27;[0m" )
let $startTime := util:system-time()
let $response :=
try {
tgconnect:publish(
$uri,
$sid,
"data",
"admin",
"",
"textgrid",
"",
true())
} catch * { <error code="{$err:code}" timestamp="{current-dateTime()}">{$err:description}</error> }
return
update insert ( <report uri="{$uri}" started="{$startTime}" finished="{util:system-time()}">{$response}</report>) into //initlog/install/done,
(: INDEX :)
util:log-system-out( "reindexing…" ),
(
let $doc := doc( "/db/system/config/db/sade-projects/textgrid/data/xml/data/collection.xconf" )/*
let $tmp := xmldb:store( "/db", "tmp-collection.xconf", $doc )
let $log := util:log-system-out( "storing temp:" || $tmp )
let $newdoc := doc( $tmp )
let $remove := xmldb:remove( "/db/system/config/db/sade-projects/textgrid/data/xml/data", "collection.xconf"),
$log := util:log-system-out( "removing original…" )
let $store := xmldb:store( "/db/system/config/db/sade-projects/textgrid/data/xml/data", "collection.xconf", $newdoc ),
$log := util:log-system-out( "storing new:" || $store )
return
xmldb:remove( "/db", "tmp-collection.xconf" )
),
xmldb:reindex("/db/sade-projects/textgrid/data/xml/data"),
(: TEST
Tests will fail on autodeploy, because they are done via httprequest on localhost.
:)
util:log-system-out( "testing…" ),
for $what in
( "markdown",
"doku-li",
"doku-page",
"search",
"litvz")
let $test := local:test($what)
return
update insert ( <test what="{$what}">{$test}</test> ) into //initlog/tests,
(: set correct mode for autostart trigger :)
sm:chmod(xs:anyURI("/db/system/autostart"), "rwxrwx---"),
sm:chmod(xs:anyURI("/db/system/autostart/reindex.xq"), "rwxrwx---")
)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment