diff --git a/opacclient/libopac/src/main/java/de/geeksfactory/opacclient/apis/SLUB.kt b/opacclient/libopac/src/main/java/de/geeksfactory/opacclient/apis/SLUB.kt index 9cea90afa..305100942 100644 --- a/opacclient/libopac/src/main/java/de/geeksfactory/opacclient/apis/SLUB.kt +++ b/opacclient/libopac/src/main/java/de/geeksfactory/opacclient/apis/SLUB.kt @@ -159,15 +159,22 @@ open class SLUB : OkHttpBaseApi() { override fun getResultById(id: String, homebranch: String?): DetailedItem { val json: JSONObject - val url = - if (id.startsWith("id")) { - "$baseurl/$id/" - } else { - val noRedirectClient = http_client.newBuilder() - .followRedirects(false) - .build() - httpHead("$baseurl/$id/", "Location", "", noRedirectClient) - } + "?type=1369315142&tx_find_find[format]=data&tx_find_find[data-format]=app" + val url = when { + id.startsWith("id/") -> + "$baseurl/$id/" + id.startsWith("bc/") || id.startsWith("rsn/") -> + http_client.newBuilder() + .followRedirects(false) + .build() + .run { + httpHead("$baseurl/$id/", + "Location", + "", + this) + } + else -> // legacy case: id identifier without prefix + "$baseurl/id/$id/" + } + "?type=1369315142&tx_find_find[format]=data&tx_find_find[data-format]=app" try { json = JSONObject(httpGet(url, ENCODING)) } catch (e: JSONException) { diff --git a/opacclient/libopac/src/test/java/de/geeksfactory/opacclient/apis/SLUBTest.kt b/opacclient/libopac/src/test/java/de/geeksfactory/opacclient/apis/SLUBTest.kt index 99298c5f3..03038a6fe 100644 --- a/opacclient/libopac/src/test/java/de/geeksfactory/opacclient/apis/SLUBTest.kt +++ b/opacclient/libopac/src/test/java/de/geeksfactory/opacclient/apis/SLUBTest.kt @@ -838,6 +838,32 @@ class SLUBGetResultByIdMockTest : BaseHtmlTest() { verify(slub).httpGet("https://test.de/id/123/?type=1369315142&tx_find_find[format]=data&tx_find_find[data-format]=app", "UTF-8") assertEquals("id/123", actual.id) } + + @Test + fun testRsnIdentifier() { + doReturn("https://test.de/id/123/").`when`(slub).httpHead(Matchers.any(), + Matchers.any(), Matchers.any(), Matchers.any()) + val response = """{"record":{"title":"The title"},"id":"123","thumbnail":"","links":[],"linksRelated":[], + |"linksAccess":[],"linksGeneral":[],"references":[],"copies":[],"parts":{}}""".trimMargin() + doReturn(response).`when`(slub).httpGet(Matchers.any(), Matchers.any()) + val actual = slub.getResultById("rsn/456", null) + verify(slub).httpHead(eq("https://test.de/rsn/456/"), eq("Location"), eq(""), + argThat(ClientDoesntFollowRedirects())) + verify(slub).httpGet("https://test.de/id/123/?type=1369315142&tx_find_find[format]=data&tx_find_find[data-format]=app", "UTF-8") + assertEquals("id/123", actual.id) + } + + @Test + fun testLegacyIdentifier() { + // id without prefix, e.g. from old favorites list + val response = """{"record":{"title":"The title"},"id":"123","thumbnail":"","links":[],"linksRelated":[], + |"linksAccess":[],"linksGeneral":[],"references":[],"copies":[],"parts":{}}""".trimMargin() + doReturn(response).`when`(slub).httpGet(Matchers.any(), Matchers.any()) + val actual = slub.getResultById("123", null) + verify(slub).httpGet("https://test.de/id/123/?type=1369315142&tx_find_find[format]=data&tx_find_find[data-format]=app", "UTF-8") + verify(slub, never()).httpHead(any(), any(), any(), any()) + assertEquals("id/123", actual.id) + } } @RunWith(Parameterized::class)