Add semesters list to student
This commit is contained in:
parent
aba6e34e3f
commit
5b99fd1d2b
9 changed files with 67 additions and 41 deletions
|
@ -0,0 +1,17 @@
|
|||
package io.github.wulkanowy.sdk.scrapper.register
|
||||
|
||||
import io.github.wulkanowy.sdk.scrapper.toLocalDate
|
||||
|
||||
fun Diary.toSemesters() = semesters!!.map {
|
||||
Semester(
|
||||
diaryId = diaryId,
|
||||
diaryName = "$level$symbol",
|
||||
schoolYear = year,
|
||||
semesterId = it.id,
|
||||
semesterNumber = it.number,
|
||||
start = it.start.toLocalDate(),
|
||||
end = it.end.toLocalDate(),
|
||||
classId = it.classId,
|
||||
unitId = it.unitId
|
||||
)
|
||||
}
|
|
@ -5,9 +5,6 @@ import pl.droidsonroids.jspoon.annotation.Selector
|
|||
|
||||
class SendCertificateResponse {
|
||||
|
||||
@Selector(".panel.linkownia.pracownik.klient a[href*=\"uonetplus-opiekun\"]")
|
||||
var oldStudentSchools: List<Element> = emptyList()
|
||||
|
||||
@Selector(".panel.linkownia.pracownik.klient a[href*=\"uonetplus-uczen\"]")
|
||||
var studentSchools: List<Element> = emptyList()
|
||||
}
|
||||
|
|
|
@ -14,5 +14,6 @@ data class Student(
|
|||
val classId: Int,
|
||||
val baseUrl: String,
|
||||
val loginType: Scrapper.LoginType,
|
||||
val isParent: Boolean
|
||||
val isParent: Boolean,
|
||||
val semesters: List<Semester>
|
||||
)
|
||||
|
|
|
@ -12,6 +12,7 @@ import io.github.wulkanowy.sdk.scrapper.login.LoginHelper
|
|||
import io.github.wulkanowy.sdk.scrapper.register.Diary
|
||||
import io.github.wulkanowy.sdk.scrapper.register.SendCertificateResponse
|
||||
import io.github.wulkanowy.sdk.scrapper.register.Student
|
||||
import io.github.wulkanowy.sdk.scrapper.register.toSemesters
|
||||
import io.github.wulkanowy.sdk.scrapper.repository.AccountRepository.Companion.SELECTOR_ADFS
|
||||
import io.github.wulkanowy.sdk.scrapper.repository.AccountRepository.Companion.SELECTOR_ADFS_CARDS
|
||||
import io.github.wulkanowy.sdk.scrapper.repository.AccountRepository.Companion.SELECTOR_ADFS_LIGHT
|
||||
|
@ -117,7 +118,11 @@ class RegisterRepository(
|
|||
classId = diary.semesters!![0].classId,
|
||||
baseUrl = url.generate(ServiceManager.UrlGenerator.Site.BASE),
|
||||
loginType = loginType,
|
||||
isParent = cache?.isParent ?: false
|
||||
isParent = cache?.isParent == true,
|
||||
semesters = diaries
|
||||
.filter { it.studentId == diary.studentId && it.semesters?.getOrNull(0)?.classId == diary.semesters[0].classId }
|
||||
.map { it.toSemesters() }
|
||||
.flatten()
|
||||
)
|
||||
}.ifEmpty {
|
||||
logger.debug("No supported student found in diaries: $diaries")
|
||||
|
@ -138,9 +143,9 @@ class RegisterRepository(
|
|||
.data.orEmpty()
|
||||
|
||||
private fun List<Diary>.filterDiaries() = this
|
||||
.filter { diary -> diary.semesters?.isNotEmpty() ?: false }
|
||||
.sortedByDescending { diary -> diary.level }
|
||||
.distinctBy { diary -> listOf(diary.studentId, diary.semesters!![0].classId) }
|
||||
.filter { it.semesters.orEmpty().isNotEmpty() }
|
||||
.sortedByDescending { it.level }
|
||||
.distinctBy { listOf(it.studentId, it.semesters!![0].classId) }
|
||||
|
||||
private fun getExtractedSchoolSymbolFromUrl(snpPageUrl: String): String {
|
||||
val path = URL(snpPageUrl).path.split("/")
|
||||
|
|
|
@ -2,8 +2,8 @@ package io.github.wulkanowy.sdk.scrapper.repository
|
|||
|
||||
import io.github.wulkanowy.sdk.scrapper.interceptor.handleErrors
|
||||
import io.github.wulkanowy.sdk.scrapper.register.Semester
|
||||
import io.github.wulkanowy.sdk.scrapper.register.toSemesters
|
||||
import io.github.wulkanowy.sdk.scrapper.service.StudentService
|
||||
import io.github.wulkanowy.sdk.scrapper.toLocalDate
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
class StudentStartRepository(
|
||||
|
@ -21,24 +21,10 @@ class StudentStartRepository(
|
|||
val diaries = api.getDiaries().handleErrors().data
|
||||
return diaries.orEmpty()
|
||||
.asSequence()
|
||||
.filter { it.semesters?.isNotEmpty() ?: false }
|
||||
.filter { it.semesters.orEmpty().isNotEmpty() }
|
||||
.filter { it.studentId == studentId }
|
||||
.filter { it.semesters!![0].classId == classId }
|
||||
.map { diary ->
|
||||
diary.semesters!!.map {
|
||||
Semester(
|
||||
diaryId = diary.diaryId,
|
||||
diaryName = "${diary.level}${diary.symbol}",
|
||||
schoolYear = diary.year,
|
||||
semesterId = it.id,
|
||||
semesterNumber = it.number,
|
||||
start = it.start.toLocalDate(),
|
||||
end = it.end.toLocalDate(),
|
||||
classId = it.classId,
|
||||
unitId = it.unitId
|
||||
)
|
||||
}
|
||||
}
|
||||
.map { it.toSemesters() }
|
||||
.flatten()
|
||||
.sortedByDescending { it.semesterId }
|
||||
.toList()
|
||||
|
|
|
@ -49,7 +49,7 @@ class LoginTest : BaseLocalTest() {
|
|||
|
||||
val res = runBlocking { adfs.login("jan@fakelog.cf", "jan123") }
|
||||
|
||||
assertTrue(res.oldStudentSchools.isNotEmpty())
|
||||
assertTrue(res.studentSchools.isNotEmpty())
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -60,7 +60,7 @@ class LoginTest : BaseLocalTest() {
|
|||
|
||||
val res = runBlocking { normal.login("jan@fakelog.cf", "jan123") }
|
||||
|
||||
assertTrue(res.oldStudentSchools.isNotEmpty())
|
||||
assertTrue(res.studentSchools.isNotEmpty())
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -86,17 +86,6 @@ class LoginTest : BaseLocalTest() {
|
|||
assertEquals("[text=LoginName=jan&Password=jan123]", server.takeRequest().body.toString())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun normalLogin_beforeNewStudentSite() {
|
||||
server.enqueue(MockResponse().setBody(LoginTest::class.java.getResource("Logowanie-uonet.html").readText()))
|
||||
server.enqueue(MockResponse().setBody(LoginTest::class.java.getResource("Login-success-old.html").readText()))
|
||||
server.start(3000)
|
||||
|
||||
val res = runBlocking { normal.login("jan@fakelog.cf", "jan123") }
|
||||
|
||||
assertTrue(res.oldStudentSchools.isNotEmpty())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun normalLogin_encodingError() {
|
||||
server.enqueue(MockResponse().setBody(LoginTest::class.java.getResource("Logowanie-uonet-encoding-error.html").readText()))
|
||||
|
|
|
@ -59,9 +59,37 @@ class RegisterRepositoryTest : BaseLocalTest() {
|
|||
with(students[0]) {
|
||||
assertEquals("012345", schoolSymbol)
|
||||
assertEquals("", schoolShortName)
|
||||
assertEquals(2, semesters.size)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun normalLogin_semesters() {
|
||||
server.enqueue("LoginPage-standard.html", LoginTest::class.java)
|
||||
server.enqueue("Logowanie-uonet.html", LoginTest::class.java)
|
||||
server.enqueue("Login-success.html", LoginTest::class.java)
|
||||
|
||||
server.enqueue("LoginPage-standard.html", LoginTest::class.java)
|
||||
server.enqueue("WitrynaUcznia.html", RegisterTest::class.java)
|
||||
server.enqueue("UczenCache.json", RegisterTest::class.java)
|
||||
server.enqueue("UczenDziennik.json", RegisterTest::class.java)
|
||||
|
||||
(0..5).onEach { // 5x symbol
|
||||
server.enqueue("Logowanie-brak-dostepu.html", LoginTest::class.java)
|
||||
}
|
||||
server.start(3000)
|
||||
|
||||
val students = runBlocking { getRegisterRepository("Default").getStudents() }
|
||||
|
||||
assertEquals(2, students.size)
|
||||
with(students[0]) {
|
||||
assertEquals("012345", schoolSymbol)
|
||||
assertEquals("", schoolShortName)
|
||||
assertEquals(6, semesters.size)
|
||||
}
|
||||
assertEquals(6, students[1].semesters.size)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun normalLogin_triple() {
|
||||
server.enqueue("LoginPage-standard.html", LoginTest::class.java)
|
||||
|
|
|
@ -23,7 +23,8 @@ fun List<ApiStudent>.mapStudents(symbol: String) = map {
|
|||
scrapperBaseUrl = "",
|
||||
mobileBaseUrl = it.mobileBaseUrl,
|
||||
privateKey = it.privateKey,
|
||||
certificateKey = it.certificateKey
|
||||
certificateKey = it.certificateKey,
|
||||
semesters = mapSemesters(it.id)
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -45,6 +46,7 @@ fun List<ScrapperStudent>.mapStudents() = map {
|
|||
scrapperBaseUrl = it.baseUrl,
|
||||
mobileBaseUrl = "",
|
||||
certificateKey = "",
|
||||
privateKey = ""
|
||||
privateKey = "",
|
||||
semesters = it.semesters.mapSemesters()
|
||||
)
|
||||
}
|
||||
|
|
|
@ -19,5 +19,6 @@ data class Student(
|
|||
val scrapperBaseUrl: String,
|
||||
val mobileBaseUrl: String,
|
||||
val certificateKey: String,
|
||||
val privateKey: String
|
||||
val privateKey: String,
|
||||
val semesters: List<Semester>
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue