I am a Digital Archivist and was recently hired at a new organization. Turns out they had a very critical database go down 1.5/2 years ago and I've been helping them get it back up and running. The database utilizes exist-DB. I've gotten everything all set except for one final piece... printing box/folder labels. This is the snippet of code that deals with that:
declare function arc3:view($form) as xs:string*
{
(: let $real-user1 := session:get-attribute("user")
let $real-password := session:get-attribute("password")
let $new := session:set-current-user($real-user1, $real-password)
:)
let $s := arc3log:add-log-message("at top of local view")
let $file-name := $form/data/file
let $short-name := $form/data/shortTitle
(: let $current := xmldb:get-current-user()
let $temp := concat($current,"-temp-file.xml")
let $d := xmldb:store("/db/apps/archives3/data/", $temp, $form)
let $tempFile := concat("/db/apps/archives3/data/",$temp)
let $rec := util:eval("doc($tempFile)")
:)
let $rec := $form
let $rec := transform:transform($rec, "xmldb:exist:///apps/archives3/resources/styles/printLabel.xsl", <parameters><param name="filename" value="{$file-name}"/></parameters>)
let $query := if($form/data/type='folder') then concat($rec, "order by number($f/did/container[@type='box']),number($f/did/container[@type='folder']) return <folder><box>{$f/did/physloc/text()}</box><folderNumber>{$f/did/container[@type='folder']/text()}</folderNumber><folderTitle>{$f/did/unittitle/text()}</folderTitle><date1>{$f/did/unitdate/text()}</date1><Accession>{$f/acqinfo/p/num/text()}</Accession><Title>{$f/ancestor::ead/archdesc/did/unittitle[@type='short']/text()}</Title></folder>") else concat($rec,") order by number($boxes) return for $box in $boxes let $date2 := if (doc('",$file-name,"')/ead//dsc//container[.[@type='box'] = $box]/../unitdate/string-length(@normal) > 4) then max(doc('",$file-name,"')/ead//dsc//container[.[@type='box'] = $box]/../unitdate/substring(@normal,6)) else max(doc('",$file-name,"')/ead//dsc//container[.[@type='box'] = $box]/../unitdate/substring(@normal,1,4))
let $date3 := min(doc('",$file-name,"')/ead//dsc//container[.[@type='box'] = $box]/../unitdate/substring(@normal,1,4)) let $f := doc('",$file-name,"')/ead//dsc//container[.[@type='box'] = $box][1] let $d := doc('",$file-name,"')/ead//dsc//container[.[@type='box'] = $box][last()] let $line := $f/ancestor::c[@level='series']/did/unittitle/text() let $line2 := $d/ancestor::c[@level='series']/did/unittitle/text() let $test1 := if ($date3=$date2) then <date>{$date2}</date> else <date>{$date3}-{$date2}</date> let $test2 := if ($line=$line2) then <line>{$line}</line> else <line>{$line}-{$line2}</line> return <box><accession>{$f/../../acqinfo/p/num/text()}</accession><fonds><name>{$f/ancestor::archdesc/did/origination/text()}</name></fonds> <title><prime>{$f/ancestor::archdesc/did/unittitle[1]/text()}</prime>{$test2} {$test1} </title> <container>{$d/text()}</container> <stack>{$f/../physloc/text()}</stack></box>")
let $s := arc3log:add-log-message("did transform")
let $query := if($form/data/type='box' and contains($rec,'physloc')) then concat($rec, ") order by number($boxes)
return
for $box in $boxes
let $date2 := if(max(doc('",$file-name,"')/ead//dsc//physloc[. = $box]/../unitdate/string-length(@normal) > 5) then max(doc('",$file-name,"')/ead//dsc//physloc[. = $box]/../unitdate/substring(@normal,6)) else max(doc('",$file-name,"')/ead//dsc//physloc[. = $box]/../unitdate/substring(@normal,-1,4))
let $date3 := min(doc('",$file-name,"')/ead//dsc//physloc[. = $box]/../unitdate/substring(@normal,1,4))
let $f := doc('",$file-name,"')/ead//dsc//physloc[. = $box]/../container[@type='box'][1]
let $d := doc('",$file-name,"')/ead//dsc//physloc[. = $box]/../container[@type='box'][last()]
let $line := $f/ancestor::c[@level='series']/did/unittitle/text()
let $line2 := $d/ancestor::c[@level='series']/did/unittitle/text()
let $test1 := if ($date3=$date2) then <date>{$date2}</date> else <date>{$date3}-{$date2}</date>
let $test2 := if ($line=$line2) then <line>{$line}</line> else <line>{$line}-{$line2}</line>
return <box><accession>{$f/../../acqinfo/p/num/text()}</accession><fonds><name>{$f/ancestor::archdesc/did/origination/text()}</name></fonds> <title><prime>{$f/ancestor::archdesc/did/unittitle[1]/text()}</prime>{$test2} {$test1} </title> <container>{$d/text()}</container> <stack>{$f/../physloc/text()}</stack></box>") else $query
let $s := arc3log:add-log-message(concat("this Query is: ", $query))
let $recs := util:eval($query)
let $s := arc3log:add-log-message(concat("this result is: ", $recs))
let $blank-label := if ($form/data/type="folder") then <folder xmlns="" /> else <box xmlns="" />
let $count := $form/data/startLabel
let $add := (
for $p in 1 to (xs:int($count)-1)
return $blank-label
)
let $label := if($form/data/type ="folder" ) then
<FLD xmlns="">{$add} { $recs} </FLD>
else
<boxlbl xmlns="">{$add}{$recs}</boxlbl>
let $s := arc3log:add-log-message(concat("the label is: ", $label))
let $s := if ($form/data/type ="folder") then file:serialize($label,concat("../Labels-",$short-name,".xml"), "method=xml, omit-xml-declaration=no, media-type=application/xml, indent=no")
else
file:serialize($label, concat("../Boxes-",$short-name,".xml"),"method='xml',omit-xml-declaration='no',media-type='application/xml',indent='no'")
return
if ($form/data/type ="folder") then
concat("Labels-",$form/data/shortTitle,".xml")
else
concat("Boxes-",$form/data/shortTitle,".xml")
};
It fails to create the labels and gives me an error "ERROR Cannot serialize file. A problem occurred while serializing the node set: ../Boxes-.xml (Permission denied) [at line 66, column 33] In function: arc3:view(item()*) [25:27:/db/apps/archives3/modules/arc3.xql]
I updated the line/column to reflect the location in my pasted snippet.
Any help with this would be tremendously appreciated.
The "Permission denied" portion of the error message is the key indicator of the cause of this error. eXist-db's
file:serializefunction can only be called by the "admin" user or a member of the "dba" group. Either you need to make an explicit call to thexmldb:loginfunction (here or in the main module that calls thisarc3:viewfunction), or you need to set the setUid or setGid permissions on that main module. To do so, use thesm:chgrpfunction to ensure the the main module is owned by the dba group, and thesm:chmodfunction. Set$pathto the path to the main module that callsarc3:viewand$modeset tog+xs. For example,sm:chgrp(xs:anyURI("/db/my-main-module.xq"), "dba")andsm:chmod(xs:anyURI("/db/my-main-module.xq"), "g+s").(The commented-out call to the
session:set-current-userfunction could also set the user, but it assumes an HTTP session is active, and the username and password would need to be passed as session attributes. Only you would know if these assumptions are valid. The methods I described above do not make these assumptions.)