Skip to content

Commit

Permalink
SLUB: fallback in getResultById for legacy id identifiers without prefix
Browse files Browse the repository at this point in the history
which could result from items added to favorites list before commit 31d6006.
Also add final '/' to identifier when checking (in case a legacy identifier
starts with the characters 'id' which are not a prefix in this case).
Make implicit support for 'rsn' identifiers (currently not used) explicit.
  • Loading branch information
StefRe committed Nov 2, 2020
1 parent 406b535 commit 360b9e5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 360b9e5

Please sign in to comment.