forked from github/wulkanowy-mirror
Provide back-compatibility in school discover
This commit is contained in:
parent
b39b9f8bba
commit
78add470ba
@ -5,6 +5,7 @@ import io.github.wulkanowy.api.VulcanException
|
|||||||
import io.github.wulkanowy.api.generic.School
|
import io.github.wulkanowy.api.generic.School
|
||||||
import org.jsoup.nodes.Document
|
import org.jsoup.nodes.Document
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
|
import java.net.URL
|
||||||
|
|
||||||
class StartPage(val client: Client) {
|
class StartPage(val client: Client) {
|
||||||
|
|
||||||
@ -13,7 +14,7 @@ class StartPage(val client: Client) {
|
|||||||
fun getSchools(startPage: Document): MutableList<School> {
|
fun getSchools(startPage: Document): MutableList<School> {
|
||||||
val schoolList = mutableListOf<School>()
|
val schoolList = mutableListOf<School>()
|
||||||
|
|
||||||
val snpLinks = startPage.select(".panel.linkownia.pracownik.klient .appLink a")
|
val snpLinks = startPage.select(".panel.linkownia.pracownik.klient a[href*=\"uonetplus-opiekun\"]")
|
||||||
|
|
||||||
logger.debug("SnP links: {}", snpLinks.size)
|
logger.debug("SnP links: {}", snpLinks.size)
|
||||||
|
|
||||||
@ -24,7 +25,7 @@ class StartPage(val client: Client) {
|
|||||||
snpLinks.map {
|
snpLinks.map {
|
||||||
schoolList.add(School(
|
schoolList.add(School(
|
||||||
it.text(),
|
it.text(),
|
||||||
getExtractedIdFromUrl(it.attr("href")),
|
getExtractedSchoolSymbolFromUrl(it.attr("href")),
|
||||||
it == snpLinks.first()
|
it == snpLinks.first()
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
@ -32,10 +33,10 @@ class StartPage(val client: Client) {
|
|||||||
return schoolList
|
return schoolList
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun getExtractedIdFromUrl(snpPageUrl: String): String {
|
internal fun getExtractedSchoolSymbolFromUrl(snpPageUrl: String): String {
|
||||||
val path = snpPageUrl.split(client.host).getOrNull(1)?.split("/")
|
val path = URL(snpPageUrl).path.split("/")
|
||||||
|
|
||||||
if (6 != path?.size) {
|
if (6 != path.size) {
|
||||||
logger.error("Expected snp url, got {}", snpPageUrl)
|
logger.error("Expected snp url, got {}", snpPageUrl)
|
||||||
throw VulcanException("Na pewno używasz konta z dostępem do Witryny ucznia i rodzica?")
|
throw VulcanException("Na pewno używasz konta z dostępem do Witryny ucznia i rodzica?")
|
||||||
}
|
}
|
||||||
|
@ -51,18 +51,18 @@ class StartPageTest {
|
|||||||
@Test
|
@Test
|
||||||
fun getExtractedIDStandardTest() {
|
fun getExtractedIDStandardTest() {
|
||||||
assertEquals("123456", StartPage(client)
|
assertEquals("123456", StartPage(client)
|
||||||
.getExtractedIdFromUrl("https://uonetplus-opiekun.fakelog.cf/powiat/123456/Start/Index/"))
|
.getExtractedSchoolSymbolFromUrl("https://uonetplus-opiekun.fakelog.cf/powiat/123456/Start/Index/"))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun getExtractedIDDemoTest() {
|
fun getExtractedIDDemoTest() {
|
||||||
assertEquals("demo12345", StartPage(client)
|
assertEquals("demo12345", StartPage(client)
|
||||||
.getExtractedIdFromUrl("https://uonetplus-opiekun.fakelog.cf/demoupowiat/demo12345/Start/Index/"))
|
.getExtractedSchoolSymbolFromUrl("https://uonetplus-opiekun.fakelog.cf/demoupowiat/demo12345/Start/Index/"))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = VulcanException::class)
|
@Test(expected = VulcanException::class)
|
||||||
fun getExtractedIDNotLoggedTest() {
|
fun getExtractedIDNotLoggedTest() {
|
||||||
assertEquals("123", StartPage(client)
|
assertEquals("123", StartPage(client)
|
||||||
.getExtractedIdFromUrl("https://uonetplus.NOTfakelog.cf/powiat/"))
|
.getExtractedSchoolSymbolFromUrl("https://uonetplus.NOTfakelog.cf/powiat/"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,14 +10,25 @@
|
|||||||
<div class="content">
|
<div class="content">
|
||||||
<div class="panel linkownia pracownik klient">
|
<div class="panel linkownia pracownik klient">
|
||||||
<div class="appLink">
|
<div class="appLink">
|
||||||
<a href="https://uonetplus-opiekun.fakelog.cf/symbol/534213/Start/Index/">
|
<a href="http://uonetplus-opiekun.fakelog.localhost:3000/default/534213/Start/Index/">
|
||||||
<div class="imagedHeader directLink">
|
<div class="imagedHeader directLink">
|
||||||
<div id="idEmptyAppUczeń">
|
<div id="idEmptyAppUczen">
|
||||||
<div class="name">Uczeń</div>
|
<div class="name">Uczeń</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="newAppLink">
|
||||||
|
<div class="link">
|
||||||
|
<a href="http://uonetplus-uczen.fakelog.localhost:3000/default/012345/">
|
||||||
|
<div class="imagedHeader directLink">
|
||||||
|
<div id="idEmptyAppUczenExt">
|
||||||
|
<div class="name">Uczeń</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user