Skip to content

Commit 5e1d4af

Browse files
committed
new release v0.47.1
1 parent 4be2449 commit 5e1d4af

File tree

3 files changed

+38
-16
lines changed

3 files changed

+38
-16
lines changed

content/adsabs.xql

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ xquery version "3.1";
77
: Since a barear token is required please set it in cache or store in to module/data/adsabs.xml .
88
:
99
: Prefer the use of getter to retrieve result's content or use the following namespace to work directly on ads records:
10-
: declare namespace ads="http://ads.harvard.edu/schema/abs/1.1/abstracts";
10+
: declare namespace ads="https://ads.harvard.edu/schema/abs/1.1/abstracts";
1111
:
1212
: Note: get-record and get-record functions always cache retrieved records
1313
:
@@ -18,7 +18,7 @@ import module namespace http = "http://expath.org/ns/http-client";
1818
import module namespace test="http://exist-db.org/xquery/xqsuite" at "resource:org/exist/xquery/lib/xqsuite/xqsuite.xql";
1919

2020

21-
declare namespace ads="http://ads.harvard.edu/schema/abs/1.1/abstracts";
21+
declare namespace ads="https://ads.harvard.edu/schema/abs/1.1/abstracts";
2222

2323
(: define ads cache collection path to store documents :)
2424
declare variable $adsabs:collection-uri := "/db/ads/records/";
@@ -94,13 +94,16 @@ declare function adsabs:query( $query-url as xs:string, $query-payload as xs:str
9494
return
9595
if ($response-head/@status = ("200","404"))
9696
then
97+
(: let $log := util:log("info", "response from ads : ") :)
9798
let $json := util:binary-to-string($response-body)
99+
(: let $log := util:log("info", $json ) :)
98100
let $cache := cache:put($adsabs:expirable-cache-name, $key, $json) (: always cache last result :)
99101
return $json
100102
else
101103
(util:log("error",replace(serialize($request), $adsabs:token, "XXXXXXXX")),
102104
util:log("error",serialize($response-head)),
103105
util:log("error",serialize($response-body)),
106+
util:log("error",util:base64-decode(serialize($response-body))),
104107
(: util:log("error", "token is " || $adsabs:token),:)
105108
fn:error(xs:QName("adsabs:bad-request-1"), $response-head/@status ||":"|| $response-head/@message))
106109
else
@@ -179,10 +182,12 @@ declare function adsabs:get-records($bibcodes as xs:string*, $use-cache as xs:bo
179182

180183
(: TODO perform a load test to check limit of returned records 2000 ? :)
181184
let $new-records := if ( exists($bibcodes-todo) ) then
185+
let $log := util:log("info", "requesting bibcodes : " || string-join($bibcodes-todo ! concat(""",.,"""), ", " ) )
182186
let $quoted-bibcodes-todo := for $b in $bibcodes-todo return """||$b||"""
183187
let $payload := '{"bibcode": [' || string-join($quoted-bibcodes-todo, ", ") || "]}"
184188
let $json-resp := adsabs:query("/export/refabsxml",$payload)
185189
let $json-resp-export := parse-json($json-resp)?export
190+
(: let $log := util:log("info", "xml response is : " || $json-resp-export ) :)
186191
return
187192
parse-xml($json-resp-export)//ads:record
188193
else
@@ -192,7 +197,17 @@ declare function adsabs:get-records($bibcodes as xs:string*, $use-cache as xs:bo
192197

193198
let $bibcodes-not-done := $bibcodes-todo[not(.=$new-records/ads:bibcode)]
194199
let $bibcodes-not-requested := $new-records/ads:bibcode[not(.=$bibcodes-todo)]
195-
let $log := if(exists($bibcodes-not-done)) then util:log("warn", "Missmatch between request and response:
absent bibcodes : ("" || string-join($bibcodes-not-done, "", "") || "")" || "
unrequested bibcodes : ("" || string-join($bibcodes-not-requested, "", "") || "")") else ()
200+
let $log := if(exists($bibcodes-not-done))
201+
then
202+
(
203+
util:log("warn", "Missmatch between request and response:")
204+
,util:log("warn", "absent bibcodes : " || string-join($bibcodes-not-done ! concat(""",.,"""), ", " ) )
205+
,util:log("warn", "unrequested bibcodes : " || string-join($bibcodes-not-requested ! concat(""",.,"""), ", "))
206+
,util:log("warn", "new records :")
207+
,util:log("warn", $new-records )
208+
)
209+
else
210+
()
196211

197212
return
198213
($new-records,$cached-records)
@@ -248,7 +263,7 @@ declare function adsabs:library($name-or-id)
248263
};
249264
declare function adsabs:library($name-or-id, $use-cache as xs:boolean)
250265
{
251-
let $id := adsabs:get-libraries()?*?*[?name=$name-or-id or ?id=$name-or-id]?id
266+
let $id := adsabs:get-libraries()?libraries?*[?name=$name-or-id or ?id=$name-or-id]?id
252267
return parse-json(adsabs:query("/biblib/libraries/"||$id, (), $use-cache))
253268
};
254269
declare function adsabs:library-id($name){
@@ -266,7 +281,7 @@ declare function adsabs:library-get-permissions($name-or-id)
266281

267282
declare function adsabs:library-get-permissions($name-or-id, $use-cache as xs:boolean)
268283
{
269-
let $id := adsabs:get-libraries()?*?*[?name=$name-or-id or ?id=$name-or-id]?id
284+
let $id := adsabs:get-libraries()?libraries?*[?name=$name-or-id or ?id=$name-or-id]?id
270285
return parse-json(adsabs:query("/biblib/permissions/"||$id, (), $use-cache))
271286
};
272287

@@ -295,7 +310,7 @@ declare function adsabs:library-get-bibcodes($name-or-id, $use-cache as xs:boole
295310

296311
declare function adsabs:library-get-search-expr($name-or-id)
297312
{
298-
let $id := adsabs:get-libraries()?*?*[?name=$name-or-id or ?id=$name-or-id]?id
313+
let $id := adsabs:get-libraries()?libraries?*[?name=$name-or-id or ?id=$name-or-id]?id
299314
return "docs(library/"||$id||")"
300315
};
301316

@@ -334,29 +349,33 @@ declare function adsabs:library-clear($name-or-id){
334349
};
335350

336351
declare %private function adsabs:library-add-or-remove($name-or-id, $bibcodes, $action){
337-
let $bibcodes := $bibcodes[.!='']
352+
let $bibcodes:=$bibcodes[string-length(.)>0]
338353
return
339354
if (exists($bibcodes)) then
340355
let $quoted-bibcodes-todo := for $b in $bibcodes return """||$b||"""
341356
let $payload := '{"action":"'||$action||'" ,"bibcode": [' || string-join($quoted-bibcodes-todo, ", ") || "]}"
342-
let $id := adsabs:get-libraries()?*?*[?name=$name-or-id or ?id=$name-or-id]?id
357+
let $id := adsabs:get-libraries()?libraries?*[?name=$name-or-id or ?id=$name-or-id]?id
343358
return
344359
parse-json(adsabs:query("/biblib/documents/"||$id, $payload, false()))
345360
else
346361
util:log("info", "Skipping action on library " || $name-or-id || ". no bibcode provided for "||$action)
347362
};
348363

349364
declare function adsabs:search-bibcodes($query) as xs:string*{
350-
adsabs:search($query, "bibcode")?response?docs?*?bibcode
365+
adsabs:search-bibcodes($query, true())
366+
};
367+
368+
declare function adsabs:search-bibcodes($query, $cache) as xs:string*{
369+
adsabs:search($query, "bibcode", $cache)?response?docs?*?bibcode
351370
};
352371

353372
(: Search without using cache :)
354-
declare function adsabs:search($query as xs:string, $fl as xs:string*)
373+
declare function adsabs:search($query as xs:string, $fl as xs:string?)
355374
{
356375
adsabs:search($query, $fl, true())
357376
};
358377

359-
declare function adsabs:search($query as xs:string, $fl as xs:string*, $use-cache as xs:boolean)
378+
declare function adsabs:search($query as xs:string, $fl as xs:string?, $use-cache as xs:boolean)
360379
{
361380
parse-json(
362381
adsabs:query("/search/query?q="||encode-for-uri($query)
@@ -367,10 +386,12 @@ declare function adsabs:search($query as xs:string, $fl as xs:string*, $use-cach
367386
};
368387

369388
(:~
370-
: Give access to the solr endpoint.
371-
: default output format is defined to xml.
389+
: Query ADS using the full SOLR interface
390+
: @param $params map of query params ( default output format is defined to wt=xml )
391+
: @param $use-cache true use cache to retrieve last result if any else skip flag
392+
: @return true if refereed, false else
372393
:)
373-
declare function adsabs:search-solr($params as map(*), $use-cache as xs:boolean)
394+
declare function adsabs:search-map($params as map(*), $use-cache as xs:boolean)
374395
{
375396
let $params-keys := map:keys($params)
376397
let $defaults := (

expath-pkg.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<package xmlns="http://expath.org/ns/pkg" name="http://exist.jmmc.fr/jmmc-resources" abbrev="jmmc-resources" version="0.47.0" spec="1.0">
2+
<package xmlns="http://expath.org/ns/pkg" name="http://exist.jmmc.fr/jmmc-resources" abbrev="jmmc-resources" version="0.47.1" spec="1.0">
33
<title>JMMC Commons module</title>
44
<dependency processor="http://exist-db.org" semver-min="6.0.0"/>
55
<!--

repo.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
<prepare/>
1212
<finish>post-install.xql</finish>
1313
<changelog>
14-
<change version="0.47.0">
14+
<change version="0.47.1">
1515
<ul xmlns="">
1616
<li>jmmc-tap : tap-adql-query() use optional votable-name with priority if provided.</li>
17+
<li>adsabs : fix extract of json response following API namespace change for xml content.</li>
1718
<li>New module jmmc-ws : function wrapper to call JMMC webservices.</li>
1819
</ul>
1920
</change>

0 commit comments

Comments
 (0)