forked from github/szkolny
[API/Grades] Add data remove model for grades.
This commit is contained in:
parent
8f8eb64364
commit
52ac40c826
@ -12,6 +12,7 @@ import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.DataIdziennik
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.ENDPOINT_IDZIENNIK_WEB_GRADES
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.IdziennikWeb
|
||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
||||
import pl.szczodrzynski.edziennik.data.api.models.DataRemoveModel
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.grades.Grade
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
|
||||
@ -23,7 +24,7 @@ class IdziennikWebGrades(override val data: DataIdziennik,
|
||||
private const val TAG = "IdziennikWebGrades"
|
||||
}
|
||||
|
||||
init {
|
||||
init { data.profile?.also { profile ->
|
||||
webApiGet(TAG, IDZIENNIK_WEB_GRADES, mapOf(
|
||||
"idPozDziennika" to data.registerId
|
||||
)) { result ->
|
||||
@ -141,15 +142,22 @@ class IdziennikWebGrades(override val data: DataIdziennik,
|
||||
profileId,
|
||||
Metadata.TYPE_GRADE,
|
||||
id,
|
||||
data.profile?.empty ?: false,
|
||||
data.profile?.empty ?: false,
|
||||
data.profile.empty,
|
||||
data.profile.empty,
|
||||
addedDate
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
data.toRemove.addAll(listOf(
|
||||
Grade.TYPE_NORMAL,
|
||||
Grade.TYPE_SEMESTER1_FINAL,
|
||||
Grade.TYPE_YEAR_FINAL
|
||||
).map {
|
||||
DataRemoveModel.Grades.semesterWithType(profile.currentSemester, it)
|
||||
})
|
||||
data.setSyncNext(ENDPOINT_IDZIENNIK_WEB_GRADES, SYNC_ALWAYS)
|
||||
onSuccess()
|
||||
}
|
||||
}
|
||||
} ?: onSuccess() }
|
||||
}
|
||||
|
@ -4,13 +4,14 @@
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.web
|
||||
|
||||
import pl.szczodrzynski.edziennik.asJsonObjectList
|
||||
import pl.szczodrzynski.edziennik.data.api.ERROR_IDZIENNIK_WEB_REQUEST_NO_DATA
|
||||
import pl.szczodrzynski.edziennik.data.api.IDZIENNIK_WEB_MISSING_GRADES
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.DataIdziennik
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.ENDPOINT_IDZIENNIK_WEB_PROPOSED_GRADES
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.IdziennikWeb
|
||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
||||
import pl.szczodrzynski.edziennik.asJsonObjectList
|
||||
import pl.szczodrzynski.edziennik.data.api.models.DataRemoveModel
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.grades.Grade
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.grades.Grade.TYPE_SEMESTER1_PROPOSED
|
||||
@ -106,8 +107,11 @@ class IdziennikWebProposedGrades(override val data: DataIdziennik,
|
||||
}
|
||||
}
|
||||
|
||||
data.toRemove.addAll(listOf(TYPE_SEMESTER1_PROPOSED, TYPE_YEAR_PROPOSED).map {
|
||||
DataRemoveModel.Grades.semesterWithType(profile.currentSemester, it)
|
||||
})
|
||||
data.setSyncNext(ENDPOINT_IDZIENNIK_WEB_PROPOSED_GRADES, SYNC_ALWAYS)
|
||||
onSuccess()
|
||||
}
|
||||
}}
|
||||
} ?: onSuccess() }
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import pl.szczodrzynski.edziennik.*
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.DataLibrus
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.ENDPOINT_LIBRUS_API_BEHAVIOUR_GRADES
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.LibrusApi
|
||||
import pl.szczodrzynski.edziennik.data.api.models.DataRemoveModel
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.grades.Grade
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.grades.GradeCategory
|
||||
@ -23,7 +24,7 @@ class LibrusApiBehaviourGrades(override val data: DataLibrus,
|
||||
|
||||
private val nameFormat by lazy { DecimalFormat("#.##") }
|
||||
|
||||
init { data.profile?.let { profile ->
|
||||
init { data.profile?.also { profile ->
|
||||
apiGet(TAG, "BehaviourGrades/Points") { json ->
|
||||
|
||||
if (data.startPointsSemester1 > 0) {
|
||||
@ -147,8 +148,9 @@ class LibrusApiBehaviourGrades(override val data: DataLibrus,
|
||||
))
|
||||
}
|
||||
|
||||
data.toRemove.add(DataRemoveModel.Grades.semesterWithType(profile.currentSemester, Grade.TYPE_BEHAVIOUR))
|
||||
data.setSyncNext(ENDPOINT_LIBRUS_API_BEHAVIOUR_GRADES, SYNC_ALWAYS)
|
||||
onSuccess()
|
||||
}
|
||||
}}
|
||||
} ?: onSuccess() }
|
||||
}
|
||||
|
@ -4,8 +4,10 @@ import pl.szczodrzynski.edziennik.*
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.DataLibrus
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.ENDPOINT_LIBRUS_API_NORMAL_GRADES
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.LibrusApi
|
||||
import pl.szczodrzynski.edziennik.data.api.models.DataRemoveModel
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.grades.Grade
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.grades.Grade.*
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.grades.GradeCategory
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
|
||||
import pl.szczodrzynski.edziennik.utils.Utils
|
||||
@ -17,7 +19,7 @@ class LibrusApiGrades(override val data: DataLibrus,
|
||||
const val TAG = "LibrusApiGrades"
|
||||
}
|
||||
|
||||
init {
|
||||
init { data.profile?.also { profile ->
|
||||
apiGet(TAG, "Grades") { json ->
|
||||
val grades = json.getJsonArray("Grades").asJsonObjectList()
|
||||
|
||||
@ -68,15 +70,15 @@ class LibrusApiGrades(override val data: DataLibrus,
|
||||
|
||||
when {
|
||||
grade.getBoolean("IsConstituent") ?: false ->
|
||||
gradeObject.type = Grade.TYPE_NORMAL
|
||||
gradeObject.type = TYPE_NORMAL
|
||||
grade.getBoolean("IsSemester") ?: false -> // semester final
|
||||
gradeObject.type = if (gradeObject.semester == 1) Grade.TYPE_SEMESTER1_FINAL else Grade.TYPE_SEMESTER2_FINAL
|
||||
gradeObject.type = if (gradeObject.semester == 1) TYPE_SEMESTER1_FINAL else TYPE_SEMESTER2_FINAL
|
||||
grade.getBoolean("IsSemesterProposition") ?: false -> // semester proposed
|
||||
gradeObject.type = if (gradeObject.semester == 1) Grade.TYPE_SEMESTER1_PROPOSED else Grade.TYPE_SEMESTER2_PROPOSED
|
||||
gradeObject.type = if (gradeObject.semester == 1) TYPE_SEMESTER1_PROPOSED else TYPE_SEMESTER2_PROPOSED
|
||||
grade.getBoolean("IsFinal") ?: false -> // year final
|
||||
gradeObject.type = Grade.TYPE_YEAR_FINAL
|
||||
gradeObject.type = TYPE_YEAR_FINAL
|
||||
grade.getBoolean("IsFinalProposition") ?: false -> // year final
|
||||
gradeObject.type = Grade.TYPE_YEAR_PROPOSED
|
||||
gradeObject.type = TYPE_YEAR_PROPOSED
|
||||
}
|
||||
|
||||
grade.getJsonObject("Improvement")?.also {
|
||||
@ -94,14 +96,25 @@ class LibrusApiGrades(override val data: DataLibrus,
|
||||
profileId,
|
||||
Metadata.TYPE_GRADE,
|
||||
id,
|
||||
profile?.empty ?: false,
|
||||
profile?.empty ?: false,
|
||||
profile.empty,
|
||||
profile.empty,
|
||||
addedDate
|
||||
))
|
||||
}
|
||||
|
||||
data.toRemove.addAll(listOf(
|
||||
TYPE_NORMAL,
|
||||
TYPE_SEMESTER1_FINAL,
|
||||
TYPE_SEMESTER2_FINAL,
|
||||
TYPE_SEMESTER1_PROPOSED,
|
||||
TYPE_SEMESTER2_PROPOSED,
|
||||
TYPE_YEAR_FINAL,
|
||||
TYPE_YEAR_PROPOSED
|
||||
).map {
|
||||
DataRemoveModel.Grades.semesterWithType(profile.currentSemester, it)
|
||||
})
|
||||
data.setSyncNext(ENDPOINT_LIBRUS_API_NORMAL_GRADES, SYNC_ALWAYS)
|
||||
onSuccess()
|
||||
}
|
||||
}
|
||||
} ?: onSuccess() }
|
||||
}
|
||||
|
@ -5,12 +5,13 @@
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.mobidziennik.data.api
|
||||
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.mobidziennik.DataMobidziennik
|
||||
import pl.szczodrzynski.edziennik.data.api.models.DataRemoveModel
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.grades.Grade
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.grades.Grade.*
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
|
||||
|
||||
class MobidziennikApiGrades(val data: DataMobidziennik, rows: List<String>) {
|
||||
init { run {
|
||||
init { data.profile?.also { profile -> run {
|
||||
data.db.gradeDao().getDetails(
|
||||
data.profileId,
|
||||
data.gradeAddedDates,
|
||||
@ -73,6 +74,17 @@ class MobidziennikApiGrades(val data: DataMobidziennik, rows: List<String>) {
|
||||
subjectId)
|
||||
gradeObject.type = type
|
||||
|
||||
data.toRemove.addAll(listOf(
|
||||
TYPE_NORMAL,
|
||||
TYPE_SEMESTER1_FINAL,
|
||||
TYPE_SEMESTER2_FINAL,
|
||||
TYPE_SEMESTER1_PROPOSED,
|
||||
TYPE_SEMESTER2_PROPOSED,
|
||||
TYPE_YEAR_FINAL,
|
||||
TYPE_YEAR_PROPOSED
|
||||
).map {
|
||||
DataRemoveModel.Grades.semesterWithType(profile.currentSemester, it)
|
||||
})
|
||||
data.gradeList.add(gradeObject)
|
||||
data.metadataList.add(
|
||||
Metadata(
|
||||
@ -85,5 +97,5 @@ class MobidziennikApiGrades(val data: DataMobidziennik, rows: List<String>) {
|
||||
))
|
||||
addedDate++
|
||||
}
|
||||
}}
|
||||
}}}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import pl.szczodrzynski.edziennik.data.api.Regexes
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.mobidziennik.DataMobidziennik
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.mobidziennik.ENDPOINT_MOBIDZIENNIK_WEB_GRADES
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.mobidziennik.data.MobidziennikWeb
|
||||
import pl.szczodrzynski.edziennik.data.api.models.DataRemoveModel
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.grades.Grade
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
|
||||
@ -25,8 +26,10 @@ class MobidziennikWebGrades(override val data: DataMobidziennik,
|
||||
private const val TAG = "MobidziennikWebGrades"
|
||||
}
|
||||
|
||||
init {
|
||||
webGet(TAG, "/dziennik/oceny?semestr=${profile?.currentSemester ?: 1}") { text ->
|
||||
init { data.profile?.also { profile ->
|
||||
val currentSemester = profile.currentSemester
|
||||
|
||||
webGet(TAG, "/dziennik/oceny?semestr=$currentSemester") { text ->
|
||||
MobidziennikLuckyNumberExtractor(data, text)
|
||||
|
||||
val doc = Jsoup.parse(text)
|
||||
@ -90,7 +93,7 @@ class MobidziennikWebGrades(override val data: DataMobidziennik,
|
||||
)
|
||||
val time = Time.fromH_m_s(it[4])
|
||||
gradeAddedDateMillis = gradeAddedDate.combineWith(time)
|
||||
gradeSemester = profile?.dateToSemester(gradeAddedDate) ?: 1
|
||||
gradeSemester = profile.dateToSemester(gradeAddedDate)
|
||||
}
|
||||
|
||||
if (Regexes.MOBIDZIENNIK_GRADES_COUNT_TO_AVG.containsMatchIn(html)) {
|
||||
@ -129,8 +132,8 @@ class MobidziennikWebGrades(override val data: DataMobidziennik,
|
||||
profileId,
|
||||
Metadata.TYPE_GRADE,
|
||||
gradeObject.id,
|
||||
profile?.empty ?: false,
|
||||
profile?.empty ?: false,
|
||||
profile.empty,
|
||||
profile.empty,
|
||||
gradeAddedDateMillis
|
||||
))
|
||||
}
|
||||
@ -143,8 +146,9 @@ class MobidziennikWebGrades(override val data: DataMobidziennik,
|
||||
}
|
||||
}
|
||||
|
||||
data.toRemove.add(DataRemoveModel.Grades.semesterWithType(currentSemester, Grade.TYPE_NORMAL))
|
||||
data.setSyncNext(ENDPOINT_MOBIDZIENNIK_WEB_GRADES, SYNC_ALWAYS)
|
||||
onSuccess()
|
||||
}
|
||||
}
|
||||
}}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import pl.szczodrzynski.edziennik.data.api.VULCAN_API_ENDPOINT_GRADES
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.DataVulcan
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.ENDPOINT_VULCAN_API_GRADES
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.VulcanApi
|
||||
import pl.szczodrzynski.edziennik.data.api.models.DataRemoveModel
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.grades.Grade
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
|
||||
@ -109,6 +110,7 @@ class VulcanApiGrades(override val data: DataVulcan, val onSuccess: () -> Unit)
|
||||
))
|
||||
}
|
||||
|
||||
data.toRemove.add(DataRemoveModel.Grades.semesterWithType(data.studentSemesterNumber, Grade.TYPE_NORMAL))
|
||||
data.setSyncNext(ENDPOINT_VULCAN_API_GRADES, SYNC_ALWAYS)
|
||||
onSuccess()
|
||||
}
|
||||
|
@ -27,17 +27,23 @@ open class DataRemoveModel {
|
||||
}
|
||||
}
|
||||
|
||||
class Grades(private val all: Boolean, private val semester: Int?) : DataRemoveModel() {
|
||||
class Grades(private val all: Boolean, private val semester: Int?, private val type: Int?) : DataRemoveModel() {
|
||||
companion object {
|
||||
fun all() = Grades(true, null)
|
||||
fun semester(semester: Int) = Grades(false, semester)
|
||||
fun all() = Grades(true, null, null)
|
||||
fun allWithType(type: Int) = Grades(true, null, type)
|
||||
fun semester(semester: Int) = Grades(false, semester, null)
|
||||
fun semesterWithType(semester: Int, type: Int) = Grades(false, semester, type)
|
||||
}
|
||||
|
||||
fun commit(profileId: Int, dao: GradeDao) {
|
||||
if (all) {
|
||||
dao.clear(profileId)
|
||||
if (type != null) dao.clearWithType(profileId, type)
|
||||
else dao.clear(profileId)
|
||||
}
|
||||
semester?.let {
|
||||
if (type != null) dao.clearForSemesterWithType(profileId, it, type)
|
||||
else dao.clearForSemester(profileId, it)
|
||||
}
|
||||
semester?.let { dao.clearForSemester(profileId, it) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,9 +27,15 @@ public abstract class GradeDao {
|
||||
@Query("DELETE FROM grades WHERE profileId = :profileId")
|
||||
public abstract void clear(int profileId);
|
||||
|
||||
@Query("DELETE FROM grades WHERE profileId = :profileId AND gradeType = :type")
|
||||
public abstract void clearWithType(int profileId, int type);
|
||||
|
||||
@Query("DELETE FROM grades WHERE profileId = :profileId AND gradeSemester = :semester")
|
||||
public abstract void clearForSemester(int profileId, int semester);
|
||||
|
||||
@Query("DELETE FROM grades WHERE profileId = :profileId AND gradeSemester = :semester AND gradeType = :type")
|
||||
public abstract void clearForSemesterWithType(int profileId, int semester, int type);
|
||||
|
||||
@RawQuery(observedEntities = {Grade.class})
|
||||
abstract LiveData<List<GradeFull>> getAll(SupportSQLiteQuery query);
|
||||
public LiveData<List<GradeFull>> getAll(int profileId, String filter, String orderBy) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user