Commit 00b43227 authored by mrodzis's avatar mrodzis 🌿
Browse files

Merge branch 'bugfix/Assure-coll-available' into 'develop'

Bugfix/assure coll available

See merge request !45
parents c8ce4bd8 627be8aa
......@@ -37,7 +37,7 @@ declare variable $etTransfo:cases :=
"3qtqz.xml" (: case E :)
);
declare variable $etTransfo:dir := "/db/apps/SADE/modules/fontane/edited-text/";
declare variable $etTransfo:coll := "/db/apps/SADE/modules/fontane/edited-text/";
(:~
......@@ -48,8 +48,8 @@ declare variable $etTransfo:dir := "/db/apps/SADE/modules/fontane/edited-text/";
: @return An intermediate TEI/XML with all notebooks in it in /db/sade-projects/textgrid/data/print/xml/fontane-full.xml
:)
declare function etTransfo:complete() {
etTransfo:assure-dir-available("print"),
etTransfo:assure-dir-available("log"),
etTransfo:assure-coll-available("print"),
etTransfo:assure-coll-available("log"),
for $case in $etTransfo:cases return
(etTransfo:create-case($case),
etTransfo:create-htmls($case)),
......@@ -69,8 +69,8 @@ declare function etTransfo:complete() {
:
: @param $uri The notebook's URI, e.g. "16b00" :)
declare function etTransfo:transform-single-nb($uri as xs:string) as xs:string* {
let $assure-dir-available := etTransfo:assure-dir-available("print")
let $assure-dir-available := etTransfo:assure-dir-available("log")
let $assure-dir-available := etTransfo:assure-coll-available("print")
let $assure-dir-available := etTransfo:assure-coll-available("log")
let $log := util:log-system-out("Start creating edited text for " || $uri)
let $log := etTransfo:create-log($uri)
......@@ -113,7 +113,7 @@ declare function etTransfo:create-case($showcase as xs:string) as xs:string {
let $log := util:log-system-out("Start creating case " || $showcase || " (" || $doc//tei:title[1] || ").")
let $new-filename := $doc//tei:title[1] => replace(" ", "-") || ".xml"
let $assure-dir-available := etTransfo:assure-dir-available("print")
let $assure-dir-available := etTransfo:assure-coll-available("print")
let $create-new-file := xmldb:store($config:data-root || "/print/xml/", $new-filename, $doc/*)
......@@ -150,7 +150,7 @@ declare function etTransfo:create-case($showcase as xs:string) as xs:string {
declare function etTransfo:get-teis($showcase as xs:string) as element(tei:TEI)* {
let $doc := doc("/db/sade-projects/textgrid/data/xml/data/" || $showcase)
let $summary-file-name := $doc//tei:title[1] => replace(" ", "-") || ".xml"
let $log := doc($etTransfo:dir || "logs/" || $doc//tei:title[1] => replace(" ", "-") || "-log.xml")
let $log := doc($etTransfo:coll || "logs/" || $doc//tei:title[1] => replace(" ", "-") || "-log.xml")
return
try {
doc($config:data-root || "/print/xml/" || $summary-file-name)//tei:TEI
......@@ -190,12 +190,20 @@ declare function etTransfo:create-htmls($showcase as xs:string) as xs:string* {
:)
declare function etTransfo:transform-tei($tei as element(tei:TEI), $log as xs:string) {
(: macro-sort:main($tei, $tei/@id):)
(: => fsort:main():)
(: let $macro-sorted :=:)
(: try {:)
(: macro-sort:main($tei, $tei/@id):)
(: } catch * {:)
(: etTransfo:add-log-entry($log, "ETTRANSFO14: Error while macro sorting this notebook. Reason: 
" ||:)
(: concat("[", $err:line-number, ": ", $err:column-number, "] Error ", $err:code, ": ", $err:description)):)
(: }:)
let $sorted :=
try {
fsort:main($tei, $log)
(: fsort:main($macro-sorted, $log) :)
} catch * {
etTransfo:add-log-entry($log, "ETTRANSFO09: Error while sorting this notebook. ")
etTransfo:add-log-entry($log, "ETTRANSFO09: Error while sorting this notebook. Reason: 
" ||
concat("[", $err:line-number, ": ", $err:column-number, "] Error ", $err:code, ": ", $err:description))
}
let $prepare-comment :=
......@@ -382,20 +390,34 @@ declare function etTransfo:make-bib-entries($type as xs:string) as element(tei:d
};
(:~
: Creates a log file for a given notebook.
:
: @author Michelle Weidling
: @param $uri The notebook's URI, e.g. "12345.xml"
: @return The location of the stored log-file, e.g. "/db/apps/sade/modules/fontane/edited-text/logs/12345-log.xml"
:)
declare function etTransfo:create-log($uri as xs:string) as xs:string {
let $assure-dir-available := etTransfo:assure-dir-available("logs")
let $assure-dir-available := etTransfo:assure-coll-available("logs")
let $log-name := $uri || "-log.xml"
return xmldb:store($etTransfo:dir || "logs", $log-name, <log/>)
return xmldb:store($etTransfo:coll || "logs", $log-name, <log/>)
};
declare function etTransfo:assure-dir-available($dir-name as xs:string) {
switch ($dir-name)
case "log" return
if(xmldb:collection-available($etTransfo:dir || "logs")) then
$etTransfo:dir || "logs"
(:~
: Makes sure a requested collection is available.
:
: @author Michelle Weidling
: @param $flag a string indicating the target collection
: @return The location of the log collection, "/db/apps/sade/modules/fontane/edited-text/logs/"
:)
declare function etTransfo:assure-coll-available($flag as xs:string) {
switch ($flag)
case "logs" return
if(xmldb:collection-available($etTransfo:coll || "logs")) then
$etTransfo:coll || "logs"
else
xmldb:create-collection($etTransfo:dir, "logs")
xmldb:create-collection($etTransfo:coll, "logs")
case "print" return
if(xmldb:collection-available($config:data-root || "/print/")) then
......@@ -405,10 +427,17 @@ declare function etTransfo:assure-dir-available($dir-name as xs:string) {
xmldb:create-collection($config:data-root || "/print/", "xml"),
xmldb:create-collection($config:data-root || "/print/", "xhtml"))
default return ()
};
(:~
: Adds a log entry to a given log file.
:
: @author Michelle Weidling
: @param $log-file The path to the log file, e.g. "/db/apps/sade/modules/fontane/edited-text/logs/12345-log.xml"
: @param $message The message of the log entry
: @return The location of the log collection, "/db/apps/sade/modules/fontane/edited-text/logs/"
:)
declare function etTransfo:add-log-entry($log-file as xs:string,
$message as xs:string) as empty-sequence() {
let $entry := <LogEntry timestamp="{util:system-time()}">{$message}</LogEntry>
......@@ -417,24 +446,27 @@ $message as xs:string) as empty-sequence() {
(:~
: Only the logs which acutally contain info should be kept.
:
: Removes all log files that don't contain any information.
: @author Michelle Weidling
:)
declare function etTransfo:tidy-logs() {
for $log in collection($etTransfo:dir || "logs/") return
declare function etTransfo:tidy-logs() as item()* {
for $log in collection($etTransfo:coll || "logs/") return
if($log//LogEntry) then
()
else
let $uri := substring-after(base-uri($log), "logs/")
return
xmldb:remove($etTransfo:dir || "logs/", $uri)
xmldb:remove($etTransfo:coll || "logs/", $uri)
};
(:~
: Prints all errors found to stdout.
: @author Michelle Weidling
:)
declare function etTransfo:report-errors() as item()* {
let $log-path := $etTransfo:dir || "logs/"
let $log-path := $etTransfo:coll || "logs/"
return
if(xmldb:get-child-resources($log-path) = "") then
if(normalize-space(xmldb:get-child-resources($log-path)) = "") then
util:log-system-out("No errors found while creating the edited text! Yay!")
else
(
......
Markdown is supported
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