Skip to content

Commit

Permalink
Implementing check against existing app URIs
Browse files Browse the repository at this point in the history
See #3.
  • Loading branch information
wlpotter committed Jan 4, 2022
1 parent 24a04e9 commit 62ecf9d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
14 changes: 13 additions & 1 deletion modules/config.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,16 @@ declare variable $config:active-namespaces :=
where contains(string($ns/@entity), "all") or contains(string($ns/@entity), $config:collection-type)
let $prefix := string($ns/@prefix)
let $nsUri := $ns/text()
return namespace {$prefix} {$nsUri};
return namespace {$prefix} {$nsUri};

declare variable $config:index-url :=
string($config:collection-node/@index);

declare variable $config:index-of-existing-uris :=
if($config:index-url = "") then <error type="warning"><desc>No index available for the selected entity type</desc></error>
else
let $response := http:send-request(<http:request method='get'/>, $config:index-url)
return if(string($response[1]/@status) = "200") then
for $url in $response[2]/*/*
return string($url/@ref)
else <error type="warning"><desc>Unable to retrieve index from server</desc> {$response[1]}</error>;
6 changes: 4 additions & 2 deletions transform.xq
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,14 @@ return if(functx:atomic-type($inputCollection) = "xs:string")
: This base-uri is determined by the /meta/config/collections/collection/@record-URI-base of the collection whose @name matches /meta/config/collectionType/text():)
let $inDocUri := $inDoc//text//idno[@type="URI" and starts-with(text(), $config:uri-base)]/text()

(: if the mark the URI if it exists; only check if the index creation did not raise an error. successful index creation results in a sequence of strings:)
let $uriExists := if($config:index-of-existing-uris[1] instance of xs:string) then functx:is-value-in-sequence($inDocUri, $config:index-of-existing-uris) else false
let $outDoc := template:merge-record-into-template($inDoc, $config:record-template, $inDocUri)

(: write to the output folder or return to console. Variable controlled by config.xml/meta/config/io/fileOrConsole :)
return if($config:file-or-console = "file") then
return if($config:file-or-console = "file" and not($uriExists)) then
let $docFileName := substring-after($inDocUri, $config:uri-base) || ".xml"
let $outputTarget := $config:output-path || $docFileName
return file:write($outputTarget, $outDoc, map {'method': 'xml', 'omit-xml-declaration': 'no'})
else
$outDoc
if($uriExists) then <error type="warning"><desc>This record already exists in data</desc><recordUri>{$inDocUri}</recordUri></error> else $outDoc

0 comments on commit 62ecf9d

Please sign in to comment.