Skip to content

Commit 3aeca5c

Browse files
Cleanup environment variable calls and remove test endpoint (#32)
1 parent 7dad27a commit 3aeca5c

File tree

1 file changed

+5
-18
lines changed

1 file changed

+5
-18
lines changed

src/webapp/validator.xqm

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,6 @@ module namespace e = 'http://elifesciences.org/modules/validate';
22
import module namespace session = "http://basex.org/modules/session";
33
import module namespace rest = "http://exquery.org/ns/restxq";
44
declare namespace svrl = "http://purl.oclc.org/dsdl/svrl";
5-
declare variable $e:ror-client-id := fn:environment-variable('ROR_CLIENT_ID');
6-
7-
declare
8-
%rest:GET
9-
%rest:path('/ror-test')
10-
function e:get-ror-client-id() {
11-
let $ror-client-id := fn:environment-variable('ROR_CLIENT_ID')
12-
return (
13-
if ($ror-client-id)
14-
then $ror-client-id
15-
else 'Variable was not found',
16-
fn:available-environment-variables()
17-
)
18-
19-
};
205

216
(: Schematron :)
227

@@ -409,6 +394,7 @@ declare function e:getXpath($node as node()) {
409394
};
410395

411396
declare function e:introduce-rors($xml as item()) {
397+
let $ror-client-id := fn:environment-variable('ROR_CLIENT_ID')
412398
let $node := if ($xml[.instance of xs:string]) then parse-xml($xml)
413399
else $xml
414400
let $new-xml :=
@@ -419,7 +405,7 @@ declare function e:introduce-rors($xml as item()) {
419405
let $json := try {
420406
http:send-request(
421407
<http:request method='get' href="{('https://api.ror.org/v2/organizations?affiliation='||web:encode-url($display))}" timeout='2'>
422-
<http:header name="Client-Id" value="{$e:ror-client-id}"/>
408+
<http:header name="Client-Id" value="{$ror-client-id}"/>
423409
</http:request>)//*:json}
424410
catch * {<json><number__of__results>0</number__of__results></json>}
425411
return if ((number($json//*:number__of__results) = 0) or not($json//*:items/_[number(*:score[1]) ge 0.8]))
@@ -444,7 +430,7 @@ declare function e:introduce-rors($xml as item()) {
444430
let $json := try {
445431
http:send-request(
446432
<http:request method='get' href="{('https://api.ror.org/v2/organizations?affiliation='||web:encode-url($inst))}" timeout='2'>
447-
<http:header name="Client-Id" value="{$e:ror-client-id}"/>
433+
<http:header name="Client-Id" value="{$ror-client-id}"/>
448434
</http:request>)//*:json}
449435
catch * {<json><number__of__results>0</number__of__results></json>}
450436
return if ((number($json//*:number__of__results) = 0) or not($json//*:items/_[number(*:score[1]) ge 0.8]))
@@ -797,14 +783,15 @@ declare function e:get-ror-rows($xml) as element(tr)* {
797783
let $isEvenTotal := $non-ror-count mod 2 = 0
798784
(: If there are <= 100 affiliations without RORs :)
799785
return if ($non-ror-count le 100) then (
786+
let $ror-client-id := fn:environment-variable('ROR_CLIENT_ID')
800787
for $result at $pos in (
801788
for $aff in $xml//*:aff[not(institution-wrap[*:institution-id]) and descendant::institution and (ancestor::*:article-meta or ancestor::*:contrib[@contrib-type="reviewer"] or ancestor::*:contrib[@contrib-type="author" and role[@specific-use="referee"]])]
802789
let $xpath := e:getXpath($aff)
803790
let $display := string-join($aff/descendant::*[not(local-name()=('label','institution-id','institution-wrap','named-content'))],', ')
804791
let $json := try {
805792
http:send-request(
806793
<http:request method='get' href="{('https://api.ror.org/v2/organizations?affiliation='||web:encode-url($display))}" timeout='2'>
807-
<http:header name="Client-Id" value="{$e:ror-client-id}"/>
794+
<http:header name="Client-Id" value="{$ror-client-id}"/>
808795
</http:request>)//*:json}
809796
catch * {<json><number__of__results>0</number__of__results></json>}
810797
where (number($json//*:number__of__results) gt 0) and $json//*:items/_[number(*:score[1]) ge 0.8]

0 commit comments

Comments
 (0)