Merge branch 'master' into feature/account-unlock

This commit is contained in:
Mikołaj Pich 2020-01-30 20:19:11 +01:00
commit fd2546ccab
No known key found for this signature in database
GPG key ID: F62B26E36D4C4BAA
16 changed files with 241 additions and 30 deletions

View file

@ -43,7 +43,7 @@ jobs:
- store_artifacts:
path: ./build/reports/tests/test
- store_artifacts:
path: ./build/libs/sdk-0.14.2.jar
path: ./build/libs/sdk-0.15.0.jar
deploy:
<<: *container_config
steps:

View file

@ -29,6 +29,6 @@ allprojects {
}
}
dependencies {
implementation 'io.github.wulkanowy:sdk:0.14.2'
implementation 'io.github.wulkanowy:sdk:0.15.0'
}
```

View file

@ -5,7 +5,7 @@ plugins {
}
ext {
PUBLISH_VERSION = '0.14.2'
PUBLISH_VERSION = '0.15.0'
SITE_URL = 'https://github.com/wulkanowy/sdk'
GIT_URL = 'https://github.com/wulkanowy/sdk.git'

View file

@ -44,7 +44,7 @@ data class Lesson(
val timetableId: Int,
@SerializedName("AdnotacjaOZmianie")
val annotationAboutChange: String,
val annotationAboutChange: String?,
@SerializedName("PrzekreslonaNazwa")
val overriddenName: Boolean,

View file

@ -0,0 +1,21 @@
package io.github.wulkanowy.sdk.mobile.grades
import io.github.wulkanowy.sdk.mobile.BaseLocalTest
import io.github.wulkanowy.sdk.mobile.repository.MobileRepository
import org.junit.Assert.assertEquals
import org.junit.Test
import retrofit2.create
class GradesTest : BaseLocalTest() {
private val grades by lazy { MobileRepository(getRetrofit().create()) }
@Test
fun getGrades() {
server.enqueueAndStart("Oceny.json")
val items = grades.getGrades(0, 0, 0).blockingGet()
assertEquals(2, items.size)
}
}

View file

@ -0,0 +1,54 @@
{
"Status": "Ok",
"TimeKey": 1580410527,
"TimeValue": "Thu, 30 Jan 2020 18:55:27 GMT",
"RequestId": "090cdefc-64a7-4a06-908c-d12703a5f465",
"DayOfWeek": 4,
"AppVersion": "17.09.0009.26859",
"Data": [
{
"Id": 1000,
"Pozycja": 1,
"PrzedmiotPozycja": 1,
"IdPrzedmiot": 300,
"IdKategoria": 26,
"Wpis": "3",
"Wartosc": 3,
"WagaModyfikatora": null,
"WagaOceny": 5,
"Licznik": null,
"Mianownik": null,
"Komentarz": null,
"Waga": "5,00",
"Opis": "Aktywność",
"DataUtworzenia": 1536883200,
"DataUtworzeniaTekst": "2018-09-14",
"DataModyfikacji": 1536883200,
"DataModyfikacjiTekst": "2018-09-14",
"IdPracownikD": 1,
"IdPracownikM": 1
},
{
"Id": 1001,
"Pozycja": 3,
"PrzedmiotPozycja": 8,
"IdPrzedmiot": 300,
"IdKategoria": 26,
"Wpis": "4",
"Wartosc": 4,
"WagaModyfikatora": null,
"WagaOceny": 5,
"Licznik": null,
"Mianownik": null,
"Komentarz": null,
"Waga": "5,00",
"Opis": "Aktywność",
"DataUtworzenia": 1538179200,
"DataUtworzeniaTekst": "2018-09-29",
"DataModyfikacji": 1538179200,
"DataModyfikacjiTekst": "2018-09-29",
"IdPracownikD": 1,
"IdPracownikM": 1
}
]
}

View file

@ -0,0 +1,41 @@
{
"Status": "Ok",
"TimeKey": 1579185018,
"TimeValue": "Thu, 16 Jan 2020 14:30:18 GMT",
"RequestId": "1799be6b-7a60-4665-b75c-1bca504e8ebd",
"DayOfWeek": 4,
"AppVersion": "17.09.0009.26859",
"Data": [
{
"IdOkresKlasyfikacyjny": 12,
"OkresPoziom": 4,
"OkresNumer": 1,
"OkresDataOd": 1567296000,
"OkresDataDo": 1580256000,
"OkresDataOdTekst": "2019-09-01",
"OkresDataDoTekst": "2020-01-29",
"IdJednostkaSprawozdawcza": 6,
"JednostkaSprawozdawczaSkrot": "Fake123456",
"JednostkaSprawozdawczaNazwa": "Fakelog public diary nr 1",
"JednostkaSprawozdawczaSymbol": "123456",
"IdJednostka": 0,
"JednostkaNazwa": "Publiczna szkoła Wulkanowego nr 1 w fakelog.cf",
"JednostkaSkrot": "Fake123456",
"OddzialSymbol": "A",
"OddzialKod": "4A",
"UzytkownikRola": "uczeń",
"UzytkownikLogin": "jan@fakelog.cf",
"UzytkownikLoginId": 1,
"UzytkownikNazwa": "Jan Kowalski",
"Id": 1,
"IdOddzial": 1,
"Imie": "Jan",
"Imie2": "Marek",
"Nazwisko": "Kowalski",
"Pseudonim": "",
"UczenPlec": 1,
"Pozycja": 0,
"LoginId": null
}
]
}

View file

@ -5,6 +5,7 @@ import io.github.wulkanowy.sdk.scrapper.register.Semester
import io.github.wulkanowy.sdk.scrapper.service.StudentService
import io.github.wulkanowy.sdk.scrapper.toLocalDate
import io.reactivex.Single
import org.slf4j.LoggerFactory
import org.threeten.bp.LocalDate.now
class StudentStartRepository(
@ -13,6 +14,10 @@ class StudentStartRepository(
private val api: StudentService
) {
companion object {
@JvmStatic private val logger = LoggerFactory.getLogger(this::class.java)
}
fun getSemesters(): Single<List<Semester>> {
return api.getDiaries()
.compose(ErrorHandlerTransformer())
@ -41,6 +46,10 @@ class StudentStartRepository(
.flatten()
.sortedByDescending { it.semesterId }
.toList()
.ifEmpty {
logger.debug("Diaries size: $diaries")
emptyList()
}
}.map {
if (it.isNotEmpty() && it.singleOrNull { semester -> semester.current } == null) it.apply { first().current = true }
else it

View file

@ -217,10 +217,10 @@ class Sdk {
}.toList().map { it.flatten() }
}
fun getSemesters(): Single<List<Semester>> {
fun getSemesters(now: LocalDate = LocalDate.now()): Single<List<Semester>> {
return when (mode) {
Mode.HYBRID, Mode.SCRAPPER -> scrapper.getSemesters().compose(ScrapperExceptionTransformer()).map { it.mapSemesters() }
Mode.API -> mobile.getStudents().map { it.mapSemesters(studentId) }
Mode.API -> mobile.getStudents().map { it.mapSemesters(studentId, now) }
}
}
@ -388,21 +388,21 @@ class Sdk {
fun getReceivedMessages(start: LocalDateTime, end: LocalDateTime): Single<List<Message>> {
return when (mode) {
Mode.SCRAPPER -> scrapper.getReceivedMessages(start, end).compose(ScrapperExceptionTransformer()).map { it.mapMessages() }
Mode.SCRAPPER -> scrapper.getReceivedMessages().compose(ScrapperExceptionTransformer()).map { it.mapMessages() } // TODO
Mode.HYBRID, Mode.API -> mobile.getMessages(start, end).map { it.mapMessages() }
}
}
fun getSentMessages(start: LocalDateTime, end: LocalDateTime): Single<List<Message>> {
return when (mode) {
Mode.SCRAPPER -> scrapper.getSentMessages(start, end).compose(ScrapperExceptionTransformer()).map { it.mapMessages() }
Mode.SCRAPPER -> scrapper.getSentMessages().compose(ScrapperExceptionTransformer()).map { it.mapMessages() }
Mode.HYBRID, Mode.API -> mobile.getMessagesSent(start, end).map { it.mapMessages() }
}
}
fun getDeletedMessages(start: LocalDateTime, end: LocalDateTime): Single<List<Message>> {
return when (mode) {
Mode.SCRAPPER -> scrapper.getDeletedMessages(start, end).compose(ScrapperExceptionTransformer()).map { it.mapMessages() }
Mode.SCRAPPER -> scrapper.getDeletedMessages().compose(ScrapperExceptionTransformer()).map { it.mapMessages() }
Mode.HYBRID, Mode.API -> mobile.getMessagesDeleted(start, end).map { it.mapMessages() }
}
}

View file

@ -12,7 +12,7 @@ fun List<ApiGrade>.mapGrades(dict: Dictionaries): List<Grade> {
return map { grade ->
Grade(
subject = dict.subjects.singleOrNull { it.id == grade.subjectId }?.name.orEmpty(),
description = dict.gradeCategories.singleOrNull { it.id == grade.categoryId }?.name.orEmpty(),
description = grade.description,
symbol = dict.gradeCategories.singleOrNull { it.id == grade.categoryId }?.code.orEmpty(),
comment = grade.comment.orEmpty(),
date = grade.creationDate.toLocalDate(),

View file

@ -1,8 +1,10 @@
package io.github.wulkanowy.sdk.mapper
import io.github.wulkanowy.sdk.exception.VulcanException
import io.github.wulkanowy.sdk.pojo.Semester
import io.github.wulkanowy.sdk.mobile.register.Student
import io.github.wulkanowy.sdk.toLocalDate
import org.threeten.bp.LocalDate
import org.threeten.bp.LocalDate.now
import org.threeten.bp.LocalDate.of
import org.threeten.bp.Month
@ -26,7 +28,7 @@ fun List<ScrapperSemester>.mapSemesters(): List<Semester> {
}
}
fun List<Student>.mapSemesters(studentId: Int): List<Semester> {
fun List<Student>.mapSemesters(studentId: Int, now: LocalDate = now()): List<Semester> {
return filter { it.id == studentId }.map {
Semester(
diaryId = 0,
@ -40,17 +42,18 @@ fun List<Student>.mapSemesters(studentId: Int): List<Semester> {
classId = it.classId,
unitId = it.reportingUnitId
)
}.let {
if (it.size == 1) {
val semesterNumber = it.single().semesterNumber
listOf(it.single(), it.single().copy(
semesterNumber = if (semesterNumber == 1) 2 else 1,
semesterId = if (semesterNumber == 1) it.single().semesterId + 1 else it.single().semesterId - 1,
start = if (semesterNumber == 1) it.single().end.plusDays(1) else of(it.single().schoolYear, 9, 1),
end = if (semesterNumber == 1) of(it.single().schoolYear + 1, 6, 30) else it.single().start.plusDays(1)
))
} else it
}.map {
it.copy(current = now() in it.start..it.end)
}.mockSecondSemester(now)
}
private fun List<Semester>.mockSecondSemester(now: LocalDate): List<Semester> {
if (size != 1) throw VulcanException("Expected semester list size 1, get $size")
val semester = single()
return (this + semester.copy(
semesterNumber = if (semester.semesterNumber == 1) 2 else 1,
semesterId = if (semester.semesterNumber == 1) semester.semesterId + 1 else semester.semesterId - 1,
start = if (semester.semesterNumber == 1) semester.end.plusDays(1) else of(semester.schoolYear, 9, 1),
end = if (semester.semesterNumber == 1) of(semester.schoolYear + 1, 8, 31) else semester.start.minusDays(1)
)).map {
it.copy(current = now in it.start..it.end)
}
}

View file

@ -6,7 +6,7 @@ import io.github.wulkanowy.sdk.mobile.dictionaries.Subject as ApiSubject
@JvmName("mapApiSubjects")
fun List<ApiSubject>.mapSubjects(): List<Subject> {
return filter { it.active }.map {
return listOf(Subject(-1, "Wszystkie")) + filter { it.active }.map {
Subject(
id = it.id,
name = it.name

View file

@ -17,11 +17,11 @@ fun List<ApiTimetable>.mapTimetable(dictionaries: Dictionaries): List<Timetable>
val time = dictionaries.lessonTimes.single { time -> time.id == it.lessonTimeId }
Timetable(
canceled = it.overriddenName,
changes = it.boldName || it.annotationAboutChange.isNotBlank(),
changes = it.boldName || !it.annotationAboutChange.isNullOrBlank(),
date = it.day.toLocalDate(),
end = time.end.toLocalDateTime(),
group = it.divisionShort.orEmpty(),
info = it.annotationAboutChange.substringAfter("(").substringBefore(")"),
info = it.annotationAboutChange?.substringAfter("(")?.substringBefore(")").orEmpty(),
number = it.lessonNumber,
room = it.room.orEmpty(),
roomOld = "",

View file

@ -0,0 +1,32 @@
package io.github.wulkanowy.sdk.mapper
import io.github.wulkanowy.sdk.Sdk
import io.github.wulkanowy.sdk.mobile.BaseLocalTest
import io.github.wulkanowy.sdk.mobile.grades.GradesTest
import org.junit.Assert.assertEquals
import org.junit.Test
class GradesMapperTest : BaseLocalTest() {
private val mobile by lazy {
Sdk().apply {
mode = Sdk.Mode.API
mobileBaseUrl = server.url("/").toString()
}
}
@Test
fun getApiGrades() {
server.enqueue("Slowniki.json", BaseLocalTest::class.java)
server.enqueueAndStart("Oceny.json", GradesTest::class.java)
val grades = mobile.getGrades(0).blockingGet()
assertEquals(2, grades.size)
with(grades[0]) {
assertEquals("3", entry)
assertEquals("Akt", symbol)
assertEquals("Aktywność", description)
}
}
}

View file

@ -5,6 +5,7 @@ import io.github.wulkanowy.sdk.mobile.BaseLocalTest
import io.github.wulkanowy.sdk.mobile.register.RegisterTest
import org.junit.Assert.assertEquals
import org.junit.Test
import org.threeten.bp.LocalDate.of
class SemesterMapperTest : BaseLocalTest() {
@ -16,20 +17,42 @@ class SemesterMapperTest : BaseLocalTest() {
}
@Test
fun getStudents_api() {
server.enqueueAndStart("ListaUczniow.json", RegisterTest::class.java) // TODO: modify response to match current now()
fun getStudents_api2() {
server.enqueueAndStart("ListaUczniow.json", RegisterTest::class.java)
mobile.studentId = 1
val semesters = mobile.getSemesters().blockingGet()
val semesters = mobile.getSemesters(of(2020, 1, 30)).blockingGet()
assertEquals(2, semesters.size)
with(semesters[0]) {
assertEquals(2, semesterNumber)
assertEquals(false, current)
assertEquals(true, current)
assertEquals(of(2020, 1, 30), start)
}
with(semesters[1]) {
assertEquals(1, semesterNumber)
assertEquals(false, current)
assertEquals(of(2019, 9, 1), start)
}
}
@Test
fun getStudents_api1() {
server.enqueueAndStart("ListaUczniow-2.json", RegisterTest::class.java)
mobile.studentId = 1
val semesters = mobile.getSemesters(of(2020, 1, 29)).blockingGet()
assertEquals(2, semesters.size)
with(semesters[0]) {
assertEquals(1, semesterNumber)
assertEquals(true, current)
assertEquals(of(2019, 9, 1), start)
}
with(semesters[1]) {
assertEquals(2, semesterNumber)
assertEquals(false, current)
assertEquals(of(2020, 1, 30), start)
}
}
}

View file

@ -0,0 +1,28 @@
package io.github.wulkanowy.sdk.mapper
import io.github.wulkanowy.sdk.Sdk
import io.github.wulkanowy.sdk.mobile.BaseLocalTest
import org.junit.Assert.assertEquals
import org.junit.Test
class SubjectsMapperTest : BaseLocalTest() {
private val mobile by lazy {
Sdk().apply {
mode = Sdk.Mode.API
mobileBaseUrl = server.url("/").toString()
}
}
@Test
fun getApiSubjects() {
server.enqueueAndStart("Slowniki.json", BaseLocalTest::class.java)
val subjects = mobile.getSubjects().blockingGet()
assertEquals(15, subjects.size)
with(subjects[0]) {
assertEquals(-1, id)
assertEquals("Wszystkie", name)
}
}
}