Template für das Primo-System
volle Serverurl, inklusive trailing slash (z.B.: http://portal.ub.tu-berlin.de/primo_library/libweb/action/)
Login-URL für Interne (Studenten)
Login-URL für Externe
(veraltet) Institutsid der Bücherei im Primosystem
declare function local:raise($err){
string($err) ! (if (matches(., "Anmeldung fehlgeschlagen|The login credentials are incorrect|Benutzerkonto abgelaufen oder ungültige UserID und/oder Passwort|The username you entered cannot be identified|Wrong username or password|Ungültige Ausweisnummer und/oder Passwort")) then vl:raise-login(.)
else vl:raise(.))
};
$primo-explore := contains($baseurl, '/primo-explore')
server := substring-before($baseurl, "/primo-explore"),
vid := extract($baseurl, "vid=([^"||$amp||"]+)", 1)
xquery version "3.0-videlibri";
let $answer := json($raw) return
(
institute := ( $answer.beacon.alternative-institution-code, get("institute"), $vid )[.][1],
authentication := $answer.authentication,
authentication-header := "",
search-scopes := $answer.primo-view.scopes()
)
i := 1, datasend := false()
$request := let $auth := $authentication((if ($type ge 1) then $type else 1))
let $targeturl := x"{uri-encode($server)}/primo-explore/account?vid={uri-encode($vid)}"
let $preurl := $server || "/primo_library/libweb/primoExploreLogin"
return if ($auth.authentication-system = "ALMA") then
request-combine(
{"url": $preurl, "method": "POST"},
{"authenticationProfile": $auth.profile-name,
"institution": $institute,
"password": $password,
"targetUrl": $targeturl,
"username": $username,
"view": $vid}
)
else $preurl || x"?institution={uri-encode($institute)}&target-url={uri-encode($targeturl)}&authenticationProfile={uri-encode($auth.profile-name)}&auth={uri-encode($auth.authentication-system)}&isSilent=false"
$request := get("login-url-" || (if ($type ge 1) then $type else 1), ()),
if ($request) then () else $request := get("login-url")
let $j := json($raw) where $j("jwtData") return (
$i := 10000,
authentication-header := $j("jwtData")
)
{i:=10000}
{local:raise(.)}
{local:raise(.)}
{local:raise(.)}
{local:raise(.)}
{local:raise(.)}
{local:raise(.)}
{$request}
{$request}
{$request}
{$request}
$i := $i + 1
vl:raise-internal("Zuviele Weiterleitungen beim Login. Aktuelle Seite: " || base-uri() || substring(join(//body), 1, 1000))
videlibri:delete-current-books()
videlibri:delete-current-books()
Accept: application/json,*/*
Authorization: Bearer {$authentication-header}
xquery version "3.0-videlibri";
if (not(matches($raw, "^\s*[\[{]"))) then vl:raise(inner-text())
else let $answer := json($raw) return
for $loan in $answer.data.loans.loan() return
$book := $loan!{
"category": itemcategoryname,
"year": year,
"author": author,
"id": callnumber,
"issueDate": parse-date(loandate, "yyyymmdd"),
"title": title,
"libraryBranch": mainlocationname,
"_itemid": itemid,
"_loanid": loanid,
"dueDate": parse-date(duedate, "yyyymmdd"),
"status": loanstatus,
"statusId": if (renew eq "Y") then "curious" else "critical",
"barcode": itembarcode
}
Accept: application/json,*/*
Authorization: Bearer {$authentication-header}
xquery version "3.0-videlibri";
let $answer := json($raw) let $data := $answer.data return
for $type in ("hold", "request", "ill")
let $types := $type || "s"
for $loan in $data($types)($type)() return
$book := $loan!{
"cancelable": cancel eq "Y",
"libraryBranch": pickuplocationname,
"author": author,
"title": title,
"status": holdstatus,
"statusId": if (available eq "Y") then "provided" else "ordered",
"_requestid": requestid,
"_request_type": $types,
"issueDate": parse-date(requestdate, "yyyymmdd")
}
Content-Type: application/json; charset=utf-8
Accept: application/json,*/*
Authorization: Bearer {$authentication-header}
POST
{{"id": {$b._loanid} }}
Content-Type: application/json; charset=utf-8
Accept: application/json,*/*
Authorization: Bearer {$authentication-header}
POST
{{"request_id": {$b._requestid}, "request_type": {$b._request_type} }}
search-branches := $search-scopes ! scope-id, search-branch-id := 0
{"author": "creator", "title": "title", "keywords": "sub", "isbn": "isbn", "year": "cdate"}
all-raw-docs := (),
offset := 0,
if (empty($search-branches[$search-branch-id])) then $search-branch-id := 1 else (),
encoded-scope := uri-encode($search-scopes[$search-branch-id].scope-id),
encoded-tab := uri-encode($search-scopes[$search-branch-id].tab),
encoded-query := uri-encode(join(for $key in jn:keys($book) where boolean($book($key)) and exists($search-keys($key)) return
x"{$search-keys($key)},contains,{$book($key)},AND", ";"
))
declare function local:encode-request($offset, $limit){
join((
"blendFacetsSeparately=false",
"getMore=0",
"inst=" || uri-encode($institute),
"lang=de_DE",
"limit=" || $limit,
"offset=" || $offset,
"mode=advanced",
"newspapersActive=false",
"newspapersSearch=false",
"pcAvailability=true",
"q=" || $encoded-query,
"qExclude=",
"qInclude=",
"rtaLinks=true",
"scope=" || $encoded-scope,
"skipDelivery=Y",
"sort=rank",
"tab=" || $encoded-tab,
"vid=" || uri-encode($vid)
), $amp)
};()
let $header := json($raw) where $header instance of xs:string return authentication-header := $header
{"author": "creator", "title": "title", "keywords": "subject", "isbn": "isbn", "year": "cdate"}
redirect:=()
Accept: application/json,*/*
Authorization: Bearer {$authentication-header}
xquery version "3.0-videlibri";
let $answer := json($raw) return (
search-result-count := $answer.info.total,
$all-raw-docs[] := $answer.docs(),
for $d at $i in $answer.docs() return (
book := $d.pnx.display ! {
"title": join((title)()),
"publisher": join((publisher)()),
"author": join((creator, creatorcontrib)[1](), "; "),
"year": join((creationdate)()),
"statusId" ?: switch ((availpnx)()[1])
case "available" return
if (contains(replace((availinstitution)()[1], "unavailable", ""), "available")) then "available" else ()
case "unavailable" return "lend"
default return (),
"Schlagwörter!" ?: join((subject)(), ", ")[.],
"Beschreibung!" ?: join((description)(), ", ")[.],
"Format!" ?: (format)()[.],
"Sprache!" ?: (language)()[.],
"isbn" ?: replace(join((identifier)()), "[$][$].", " "),
"_offset": $offset + $i
(:,
"_@rta_link": $d("@rta_link"),
"_@id": $d("@id"):)
}
),
offset := $offset + 10,
search-next-page-available := $offset lt $search-result-count
)
index := xs:integer($book._offset)
Accept: application/json,*/*
Authorization: Bearer {$authentication-header}
Content-Type: application/json; charset=utf-8
{{"records": [ {serialize-json($all-raw-docs[$index] )} ] }}
$book.holdings := json($raw).docs(1).delivery.holding() ! {
"id": callNumber,
"statusId": switch (availabilityStatus)
case "available" return "available"
case "unavailable" return "lend"
default return "unknown"
,
"libraryLocation": subLocation,
"libraryBranch": libraryCode
}