Skip to content
This repository has been archived by the owner on Dec 25, 2024. It is now read-only.

Commit

Permalink
NetBiblio: Support for orders in Basel
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelm committed Feb 26, 2021
1 parent 9c17b5b commit 2040420
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 46 deletions.
2 changes: 1 addition & 1 deletion opacclient/libopac/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ ext {
siteUrl = 'https://github.com/opacapp/opacclient'
gitUrl = 'https://github.com/opacapp/opacclient.git'

libraryVersion = '6.3.6'
libraryVersion = '6.3.8'

developerId = 'opacapp'
developerName = 'Web Opac App'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import org.jsoup.nodes.Document
import org.jsoup.nodes.Element
import org.jsoup.nodes.TextNode
import java.net.URL
import java.time.LocalDate

open class NetBiblio : OkHttpBaseApi() {
protected lateinit var opacUrl: String
Expand Down Expand Up @@ -336,66 +337,126 @@ open class NetBiblio : OkHttpBaseApi() {
return null
}

var reservationItemId: String? = null
var reservationAdressId: String? = null
var reservationKind: String? = null
private fun getBestCopy(copies: List<Copy>, branch: String? = null): Copy {
return copies.sortedWith(compareBy(
{ it.returnDate?.toDate()?.time ?: 0L },
{ if (it.branch == branch) 0 else 1 }
)).first()
}

override fun reservation(item: DetailedItem, account: Account, useraction: Int,
selection: String?): OpacApi.ReservationResult? {
if (useraction == 0 && selection == null) {
reservationAdressId = null
reservationItemId = null
reservationKind = null

// step 1: select item
val reservableCopies = item.copies.filter { it.resInfo != null }
when (reservableCopies.size) {
0 -> return OpacApi.ReservationResult(OpacApi.MultiStepResult.Status.ERROR, stringProvider.getString(StringProvider.NO_COPY_RESERVABLE))
1 -> return reservation(item, account, 1, reservableCopies.first()!!.resInfo)
else -> {
val options = reservableCopies.map { copy ->
hashMapOf(
"key" to copy.resInfo,
"value" to "${copy.branch} ${copy.status} ${copy.returnDate}"
)
}
return OpacApi.ReservationResult(OpacApi.MultiStepResult.Status.SELECTION_NEEDED).apply {
actionIdentifier = 1
this.selection = options
}
}
if (reservableCopies.size == 0) {
return OpacApi.ReservationResult(OpacApi.MultiStepResult.Status.ERROR, stringProvider.getString(StringProvider.NO_COPY_RESERVABLE))
}
} else if (useraction == 1) {
reservationItemId = selection
var doc = httpGet("$opacUrl/account/makeitemreservation?selectedItems%5B0%5D=$selection", ENCODING).html

// select any item, just to know which options we'll get
var doc = httpGet("$opacUrl/account/makeitemreservation?selectedItems%5B0%5D=${reservableCopies[0].resInfo}", ENCODING).html
if (doc.select("#wo-frm-login").count() > 0) {
login(account);
doc = httpGet("$opacUrl/account/makeitemreservation?selectedItems%5B0%5D=$selection", ENCODING).html
login(account)
doc = httpGet("$opacUrl/account/makeitemreservation?selectedItems%5B0%5D=${reservableCopies[0].resInfo}", ENCODING).html
}
val warning = doc.select("label:has(.wo-reservationkind[checked])").text
reservationAdressId = doc.select("input[name=AddessId]").first().`val`()
reservationKind = doc.select(".wo-reservationkind[checked]").`val`()
if (reservationKind!!.isEmpty()) reservationKind = "Reservation"
return OpacApi.ReservationResult(OpacApi.MultiStepResult.Status.CONFIRMATION_NEEDED).apply {
details = listOf(arrayOf(warning))

val resKind = doc.select(".wo-reservationkind[checked]").`val`()
val resKindText = doc.select("label:has(.wo-reservationkind[checked])").text

if (doc.select("input[name=CheckoutKind]").size > 0) {
// "PickUp" or "Mail", e.g. in Basel
// In this case, user should select a checkout kind and maybe a pickup and address location,
// but we choose the copy
val options = mutableListOf<Map<String, String>>()
for (cklabel in doc.select("label:has(input[name=CheckoutKind])")) {
val ck = cklabel.select("input").first().`val`()

if (ck == "PickUp") {
val addressId = doc.select("input[name=AddessId]").first().`val`()
for (opt in doc.select("select[name=BranchofficeId] option")) {
val key = JSONObject()
key.put("ItemId", getBestCopy(reservableCopies, opt.text().trim()).resInfo)
key.put("ReservationKind", resKind)
key.put("CheckoutKind", ck)
key.put("BranchofficeId", opt.`val`())
key.put("AddessId" /* sic! */, addressId)
options.add(
hashMapOf(
"key" to key.toString(),
"value" to "${opt.text()} / ${cklabel.text()}"
)
)
}
} else if (ck == "Mail") {
for (alabel in doc.select("label:has(input[name=AddessId])")) {
val key = JSONObject()
key.put("ItemId", getBestCopy(reservableCopies).resInfo)
key.put("ReservationKind", resKind)
key.put("CheckoutKind", ck)
key.put("AddessId" /* sic! */, alabel.select("input").first().`val`())
options.add(
0, // insert at beginning
hashMapOf(
"key" to key.toString(),
"value" to "${cklabel.text()} / ${alabel.text()}"
)
)
}
} else {
// whwatever this is
val addressId = doc.select("input[name=AddessId]").first().`val`()
val key = JSONObject()
key.put("ItemId", getBestCopy(reservableCopies).resInfo)
key.put("ReservationKind", resKind)
key.put("CheckoutKind", ck)
key.put("AddessId" /* sic! */, addressId)
options.add(
hashMapOf(
"key" to key.toString(),
"value" to cklabel.text()
)
)
}
}
return OpacApi.ReservationResult(OpacApi.MultiStepResult.Status.SELECTION_NEEDED).apply {
actionIdentifier = OpacApi.ReservationResult.ACTION_BRANCH
this.selection = options
}
} else {
// Reservation, e.g. in Bern
// In this case, user should select a copy

val addressId = doc.select("input[name=AddessId]").first().`val`()
val options = reservableCopies.map { copy ->
val key = JSONObject()
key.put("ItemId", copy.resInfo)
key.put("ReservationKind", resKind)
key.put("AddessId" /* sic! */, addressId)
hashMapOf(
"key" to key.toString(),
"value" to "${copy.branch} ${copy.status} ${copy.returnDate} (${resKindText})"
)
}
return OpacApi.ReservationResult(OpacApi.MultiStepResult.Status.SELECTION_NEEDED).apply {
actionIdentifier = OpacApi.ReservationResult.ACTION_BRANCH
this.selection = options
}
}
} else if (useraction == OpacApi.MultiStepResult.ACTION_CONFIRMATION) {
} else if (useraction == OpacApi.ReservationResult.ACTION_BRANCH) {
val data = JSONObject(selection)

val body = FormBody.Builder()
.add("ItemID", reservationItemId!!)
.add("ReservationKind", reservationKind!!)
.add("AddessId" /* sic! */, reservationAdressId!!)
.build()
val bodyBuilder = FormBody.Builder()
for (k in data.keys().iterator()) {
bodyBuilder.add(k as String, data.getString(k))
}

val doc = httpPost("$opacUrl/account/makeitemreservation", body, ENCODING).html
val doc = httpPost("$opacUrl/account/makeitemreservation", bodyBuilder.build(), ENCODING).html
if (doc.select(".alert-success").size == 1) {
return OpacApi.ReservationResult(OpacApi.MultiStepResult.Status.OK)
} else {
return OpacApi.ReservationResult(OpacApi.MultiStepResult.Status.ERROR)
}
} else {
return OpacApi.ReservationResult(OpacApi.MultiStepResult.Status.ERROR)
}
return OpacApi.ReservationResult(OpacApi.MultiStepResult.Status.ERROR)
}

override fun prolong(media: String, account: Account, useraction: Int, selection: String?): OpacApi.ProlongResult? {
Expand Down
4 changes: 2 additions & 2 deletions opacclient/opacapp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "de.geeksfactory.opacclient"
minSdkVersion 15
targetSdkVersion 29
versionCode 227
versionName "6.3.7"
versionCode 228
versionName "6.3.8"

multiDexEnabled true
vectorDrawables.useSupportLibrary = true
Expand Down
3 changes: 3 additions & 0 deletions opacclient/opacapp/src/main/res/raw-de/changelog.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
6.3.8<br>
Fehler behoben in in Basel, SLUB Dresden, Germering und Waiblingen
<br><br>
6.3.6<br>
Fehler behoben in Bielefeld, Köthen, Bern und an der SLUB Dresden behoben
<br><br>
Expand Down
3 changes: 3 additions & 0 deletions opacclient/opacapp/src/main/res/raw/changelog.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
6.3.8<br>
Fix issues in Basel, SLUB Dresden, Germering, and Waiblingen
<br><br>
6.3.6<br>
Fix issues in Bielefeld, Köthen, Bern, and SLUB Dresden
<br><br>
Expand Down

0 comments on commit 2040420

Please sign in to comment.