Skip to content

Commit

Permalink
SLUB: Fix interlibrary loans and requests (#611)
Browse files Browse the repository at this point in the history
* convert pickup location code to location name
* change format "*" to "FL" for unnamed ill media formats
* take json field "X_FL_renewable" into account:
  0 = item is not an ill item (or ill item is not renewable at all?)
  1 = not yet renewable (X_is_renewable == 0 in this case)
  2 = renewable (X_is_renewable == 1 in this case)
* don't set id for ill items as it doesn't point to SLUB catalog
* avoid redundant entries of ill items in reservations, don't show if:
  status == 6 as item is also in the "hold" section and shows as reservation
  status == 11 or 13 as it's no longer relevant (item is returned)
  status == 16 as item is also in the "loans" section and shows as lent item
  • Loading branch information
StefRe authored Feb 26, 2021
1 parent d57646f commit d4dbfb2
Show file tree
Hide file tree
Showing 7 changed files with 307 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ open class SLUB : OkHttpBaseApi() {
"a14" to "Zentralbibliothek, Ebene -1, SB-Regal Zeitungen"
)

private val pickupLocations = mapOf(
"zell1" to "Zentralbibliothek",
"bebel1" to "ZwB Erziehungswissenschaften",
"berg1" to "ZwB Rechtswissenschaft",
"fied1" to "ZwB Medizin",
"tha1" to "ZwB Forstwissenschaft",
"zell9" to "Bereichsbibliothek Drepunct"
)

override fun init(library: Library, factory: HttpClientFactory) {
super.init(library, factory)
baseurl = library.data.getString("baseurl")
Expand Down Expand Up @@ -326,14 +335,7 @@ open class SLUB : OkHttpBaseApi() {
if (action == ACTION_COPY) {
val pickupLocations: Map<String, String>
if (selected.startsWith("reserve")) {
pickupLocations = mapOf(
"zell1" to "Zentralbibliothek",
"bebel1" to "ZwB Erziehungswissenschaften",
"berg1" to "ZwB Rechtswissenschaft",
"fied1" to "ZwB Medizin",
"tha1" to "ZwB Forstwissenschaft",
"zell9" to "Bereichsbibliothek Drepunct"
)
pickupLocations = this.pickupLocations.toMap()
} else {
val data = selected.split('\t')
if (data.size != 2) {
Expand Down Expand Up @@ -439,8 +441,10 @@ open class SLUB : OkHttpBaseApi() {
reservationsList.add(ReservedItem().apply {
title = it.optString("about").replace("¬", "")
author = it.optJSONArray("X_author")?.optString(0)
id = "bc/${it.optString("label")}"
format = it.optString("X_medientyp")
if (format != "FL"){
id = "bc/${it.optString("label")}"
}
status = when (type) { // TODO: maybe we need time (LocalDateTime) too make an educated guess on actual ready date for stack requests
"hold" -> stringProvider.getFormattedString(StringProvider.HOLD,
fmt.print(LocalDate(it.optString("X_date_reserved").substring(0, 10))))
Expand All @@ -462,16 +466,20 @@ open class SLUB : OkHttpBaseApi() {
}
}
items?.optJSONArray("ill")?.forEach<JSONObject> {
reservationsList.add(ReservedItem().apply {
title = it.optString("Titel").replace("¬", "")
author = it.optString("Autor")
//id = it.optString("Fernleih_ID") --> this id is of no use whatsoever
it.optString("Medientyp")?.run {
if (length > 0) format = this
}
branch = it.optString("Zweigstelle")
status = it.optString("Status_DESC")
})
if (it.getString("Status") !in listOf("6", "11", "13", "16")){
reservationsList.add(ReservedItem().apply {
title = it.optString("Titel").replace("¬", "")
author = it.optString("Autor")
//id = it.optString("Fernleih_ID") --> this id is of no use whatsoever
it.optString("Medientyp").run {
format = if (length > 0 && this != "*") this else "FL"
}
branch = it.optString("Zweigstelle").let {
pickupLocations.getOrElse(it) { it }
}
status = it.optString("Status_DESC")
})
}
}

return reservationsList
Expand All @@ -488,14 +496,17 @@ open class SLUB : OkHttpBaseApi() {
author = it.optJSONArray("X_author")?.optString(0)
setDeadline(it.optString("X_date_due"))
format = it.optString("X_medientyp")
id = "bc/${it.optString("label")}"
if (format != "FL") {
id = "bc/${it.optString("label")}"
}
barcode = it.optString("X_barcode")
if (it.optInt("X_is_renewable") == 1) { // TODO: X_is_flrenewable for ill items
if (it.optInt("X_is_renewable") == 1) {
isRenewable = true
prolongData = "$format\t$barcode"
} else {
isRenewable = false
status = when {
it.optInt("X_is_flrenewable") == 1 -> stringProvider.getString(StringProvider.NOT_YET_RENEWABLE)
it.optInt("X_is_reserved") != 0 -> stringProvider.getString(StringProvider.RESERVED)
it.optInt("renewals") > 0 -> stringProvider.getFormattedString(
StringProvider.RENEWED, it.optInt("renewals"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public interface StringProvider {
String ITEM_COPY = "item_copy";
String RESERVED = "reserved";
String RENEWED = "renewed";
String NOT_YET_RENEWABLE = "not_yet_renewable";

/**
* Returns the translated string identified by identifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,21 +140,53 @@ class SLUBAccountTest : BaseHtmlTest() {
}

@Test
fun testParseAccountDataIllInProgress() {
val json = JSONObject(readResource("/slub/account/account-ill_in_progress.json"))
val reserveditem = ReservedItem().apply {
title = "Kotlin"
author = "Szwillus, Karl"
//id = "145073"
branch = "zell1"
fun testParseAccountDataIll() {
val fmt = DateTimeFormat.shortDate()
val json = JSONObject(readResource("/slub/account/account-ill.json"))
// hold request filed --> show ill in reservations
val reserveditem1 = ReservedItem().apply {
title = "Title1"
author = "Author1"
format = "FL"
branch = "Zentralbibliothek"
status = "Bestellung ausgelöst"
}

// ready for pickup --> show hold in reservations
val reserveditem2 = ReservedItem().apply {
title = "Title2"
author = ""
format = "FL"
status = String.format("hold %s", fmt.print(LocalDate("2020-12-04")))
branch = "Zentralbibliothek Servicetheke"
}
// on loan not yet renewable --> show loan in lent items
val lentitem1 = LentItem().apply {
title = "Title5"
author = ""
setDeadline("2021-01-08")
format = "FL"
barcode = "12047398N"
isRenewable = false
status = "not_yet_renewable"
}
// on loan renewable --> show loan in lent items
val lentitem2 = LentItem().apply {
title = "Title6"
author = ""
setDeadline("2021-01-08")
format = "FL"
barcode = "12047398N"
isRenewable = true
prolongData = "FL\t12047398N"
}
val accountdata = slub.parseAccountData(Account(), json)

assertEquals(0, accountdata.lent.size)
assertEquals(1, accountdata.reservations.size)
assertThat(reserveditem, samePropertyValuesAs(accountdata.reservations[0]))
assertEquals(2, accountdata.reservations.size)
assertThat(accountdata.reservations, hasItems(sameBeanAs(reserveditem1),
sameBeanAs(reserveditem2)))
assertEquals(2, accountdata.lent.size)
assertThat(accountdata.lent, hasItems(sameBeanAs(lentitem1),
sameBeanAs(lentitem2)))
}

@Test
Expand Down
229 changes: 229 additions & 0 deletions opacclient/libopac/src/test/resources/slub/account/account-ill.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
{
"status": "1",
"userID": "1234567",
"memberInfo": {
"name": " Max Mustermann",
"email": "[email protected]",
"address": "Musterstr. 1, 01069 Dresden",
"expires": "2020-03-31T00:00:00Z",
"status": "N",
"X_status_desc": "Normal",
"X_name": {
"givenname": "Max",
"surname": "Mustermann"
},
"X_post_address": {
"street_1": "Musterstr. 1",
"plz": "01069",
"ort": "Dresden"
},
"X_residental_address": [],
"X_alternative_address": [],
"X_date_of_joining": "2000-01-01T00:00:00Z",
"X_date_of_last_issue_int": "65375",
"X_date_of_last_issue_ext": "2019-12-28",
"X_gender": "M",
"X_branch": "zell1",
"X_branch_desc": "Zentralbibliothek",
"X_category": "NE",
"X_category_desc": "Normal Email",
"X_blacklists": [],
"X_notes": [],
"X_webopac_notes": [],
"type": "NE"
},
"items": {
"ill": [
{
"Fernleih_ID": "145073",
"Titel": "Title1",
"Autor": "Author1",
"Datum_intern": "65381",
"Datum_extern": "2020-01-02T23:00:00Z",
"Datum_Ausleihe_intern": "65381",
"Datum_Ausleihe_extern": "2020-01-02T23:00:00Z",
"Zweigstelle": "zell1",
"Status": "2",
"Status_DESC": "Bestellung ausgelöst",
"Medientyp": "",
"History": []
},
{
"Fernleih_ID": "155976",
"Titel": "Title2",
"Autor": "",
"Datum_intern": "65700",
"Datum_extern": "2020-11-16T23:00:00Z",
"Datum_Ausleihe_intern": "65700",
"Datum_Ausleihe_extern": "2020-11-16T23:00:00Z",
"Zweigstelle": "zell1",
"Status": "6",
"Status_DESC": "Medium bereitgestellt",
"Medientyp": "*",
"History": []
},
{
"Fernleih_ID": "145073",
"Titel": "Title3",
"Autor": "Author3",
"Datum_intern": "65381",
"Datum_extern": "2020-01-02T23:00:00Z",
"Datum_Ausleihe_intern": "65381",
"Datum_Ausleihe_extern": "2020-01-02T23:00:00Z",
"Zweigstelle": "zell1",
"Status": "11",
"Status_DESC": "Medium zurückgegeben",
"Medientyp": "*",
"History": []
},
{
"Fernleih_ID": "145073",
"Titel": "Title4",
"Autor": "Author4",
"Datum_intern": "65381",
"Datum_extern": "2020-01-02T23:00:00Z",
"Datum_Ausleihe_intern": "65381",
"Datum_Ausleihe_extern": "2020-01-02T23:00:00Z",
"Zweigstelle": "zell1",
"Status": "13",
"Status_DESC": "Abgeschlossen/Abgeholt",
"Medientyp": "*",
"History": []
},
{
"Fernleih_ID": "155976",
"Titel": "Title5",
"Autor": "",
"Datum_intern": "65700",
"Datum_extern": "2020-11-16T23:00:00Z",
"Datum_Ausleihe_intern": "65700",
"Datum_Ausleihe_extern": "2020-11-16T23:00:00Z",
"Zweigstelle": "zell1",
"Status": "16",
"Status_DESC": "Medium ausgeliehen",
"Medientyp": "*",
"History": []
},
{
"Fernleih_ID": "155976",
"Titel": "Title6",
"Autor": "",
"Datum_intern": "65700",
"Datum_extern": "2020-11-16T23:00:00Z",
"Datum_Ausleihe_intern": "65700",
"Datum_Ausleihe_extern": "2020-11-16T23:00:00Z",
"Zweigstelle": "zell1",
"Status": "16",
"Status_DESC": "Medium ausgeliehen",
"Medientyp": "*",
"History": []
}
],
"hold": [
{
"status": 4,
"about": "Title2",
"label": "12047398N",
"starttime": "2020-12-03T23:00:00Z",
"X_status_desc": "on hold",
"X_pickup_code": "a13",
"X_pickup_desc": "Zentralbibliothek Servicetheke",
"X_medientyp": "FL",
"X_exstatus": "FL",
"X_exstatus_desc": "Fernleihe",
"X_ill_duedate": "2021-01-08",
"X_ill_request_id": "155976",
"X_author": [],
"X_internal_date_reserved": "65717",
"X_date_reserved": "2020-12-04",
"X_internal_date_noticed": "65718",
"X_date_noticed": "2020-12-05",
"X_provided_item": "12047398N",
"X_provided": 1,
"X_rsn": 16787924
}
],
"loan": [
{
"status": 3,
"about": "Title5",
"label": "12047398N",
"queue": "0",
"renewals": 0,
"starttime": "2020-12-05T11:22:58Z",
"endtime": "2021-01-07T23:00:00Z",
"X_status_desc": "on loan",
"X_barcode": "12047398N",
"X_author": [],
"X_medientyp": "FL",
"X_exstatus": "FL",
"X_exstatus_desc": "Fernleihe",
"X_shelfLocation": "FL",
"X_internal_date_issued": "65718,44578",
"X_date_issued": "2020-12-05 12:22:58",
"X_internal_date_due": "65752",
"X_date_due": "2021-01-08",
"X_days_to_due": "34",
"X_is_reserved": 0,
"X_is_renewable": 0,
"X_RenewMax": 5,
"X_RenewalCount": 0,
"X_is_flrenewable": 1,
"X_ill_id": 155976,
"X_rsn": 16787924
},
{
"status": 3,
"about": "Title6",
"label": "12047398N",
"queue": "0",
"renewals": 0,
"starttime": "2020-12-05T11:22:58Z",
"endtime": "2021-01-07T23:00:00Z",
"X_status_desc": "on loan",
"X_barcode": "12047398N",
"X_author": [],
"X_medientyp": "FL",
"X_exstatus": "FL",
"X_exstatus_desc": "Fernleihe",
"X_shelfLocation": "FL",
"X_internal_date_issued": "65718,44578",
"X_date_issued": "2020-12-05 12:22:58",
"X_internal_date_due": "65752",
"X_date_due": "2021-01-08",
"X_days_to_due": "3",
"X_is_reserved": 0,
"X_is_renewable": 1,
"X_RenewMax": 11,
"X_RenewalCount": 0,
"X_is_flrenewable": 2,
"X_ill_id": 155976,
"X_rsn": 16787924
}
]
},
"fees": {
"amount": "0,00 EUR",
"subset": "open",
"amount_list": "0,00 EUR",
"paid_all": "0,00 EUR",
"paid_list": "0,00 EUR",
"fee_all": "0,00 EUR",
"fee_list": "0,00 EUR",
"topay_all": "0,00 EUR",
"topay_list": "0,00 EUR",
"overdue_paid": "0,00 EUR",
"overdue_fee": "0,00 EUR",
"ill_paid": "0,00 EUR",
"ill_fee": "0,00 EUR",
"other_paid": "0,00 EUR",
"other_fee": "0,00 EUR",
"fee": []
},
"arguments": {
"controller": "API",
"action": "account",
"username": "1234567"
}
}

Loading

0 comments on commit d4dbfb2

Please sign in to comment.