mirror of https://github.com/tasks/tasks
Separate principal and principal_access tables
parent
14cf7b39ec
commit
3d980ebc59
File diff suppressed because it is too large
Load Diff
@ -1,76 +1,38 @@
|
||||
package org.tasks.data
|
||||
|
||||
import androidx.room.*
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.ForeignKey
|
||||
import androidx.room.Index
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(
|
||||
tableName = "principals",
|
||||
foreignKeys = [ForeignKey(
|
||||
entity = CaldavCalendar::class,
|
||||
parentColumns = arrayOf("cdl_id"),
|
||||
childColumns = arrayOf("principal_list"),
|
||||
onDelete = ForeignKey.CASCADE
|
||||
)],
|
||||
indices = [Index(value = ["principal_list", "principal"], unique = true)]
|
||||
foreignKeys = [
|
||||
ForeignKey(
|
||||
entity = CaldavAccount::class,
|
||||
parentColumns = arrayOf("cda_id"),
|
||||
childColumns = arrayOf("account"),
|
||||
onDelete = ForeignKey.CASCADE
|
||||
)
|
||||
],
|
||||
indices = [Index(value = ["account", "href"], unique = true)]
|
||||
)
|
||||
class Principal {
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
@ColumnInfo(name = "principal_id")
|
||||
@Transient
|
||||
var id: Long = 0
|
||||
|
||||
@ColumnInfo(name = "principal_list")
|
||||
var list: Long = 0
|
||||
|
||||
@ColumnInfo(name = "principal")
|
||||
var principal: String? = null
|
||||
|
||||
@ColumnInfo(name = "display_name")
|
||||
var displayName: String? = null
|
||||
|
||||
@ColumnInfo(name = "invite")
|
||||
var inviteStatus: Int = CaldavCalendar.INVITE_UNKNOWN
|
||||
|
||||
@ColumnInfo(name = "access")
|
||||
var access: Int = CaldavCalendar.ACCESS_UNKNOWN
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as Principal
|
||||
|
||||
if (id != other.id) return false
|
||||
if (list != other.list) return false
|
||||
if (principal != other.principal) return false
|
||||
if (displayName != other.displayName) return false
|
||||
if (inviteStatus != other.inviteStatus) return false
|
||||
if (access != other.access) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = id.hashCode()
|
||||
result = 31 * result + list.hashCode()
|
||||
result = 31 * result + (principal?.hashCode() ?: 0)
|
||||
result = 31 * result + (displayName?.hashCode() ?: 0)
|
||||
result = 31 * result + inviteStatus
|
||||
result = 31 * result + access
|
||||
return result
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return "Principal(id=$id, list=$list, principal=$principal, displayName=$displayName, inviteStatus=$inviteStatus, access=$access)"
|
||||
}
|
||||
data class Principal(
|
||||
@PrimaryKey(autoGenerate = true) var id: Long = 0,
|
||||
val account: Long,
|
||||
val href: String,
|
||||
var email: String? = null,
|
||||
@ColumnInfo(name = "display_name") var displayName: String? = null
|
||||
) {
|
||||
val name: String
|
||||
get() = displayName
|
||||
?: href
|
||||
.replace(MAILTO, "")
|
||||
.replaceFirst(LAST_SEGMENT, "$1")
|
||||
|
||||
companion object {
|
||||
private val MAILTO = "^mailto:".toRegex()
|
||||
private val LAST_SEGMENT = ".*/([^/]+).*".toRegex()
|
||||
|
||||
val Principal.name: String?
|
||||
get() = displayName
|
||||
?: principal
|
||||
?.replace(MAILTO, "")
|
||||
?.replaceFirst(LAST_SEGMENT, "$1")
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package org.tasks.data
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.ForeignKey
|
||||
import androidx.room.Index
|
||||
import androidx.room.PrimaryKey
|
||||
import org.tasks.data.CaldavCalendar.Companion.ACCESS_UNKNOWN
|
||||
import org.tasks.data.CaldavCalendar.Companion.INVITE_UNKNOWN
|
||||
|
||||
@Entity(
|
||||
tableName = "principal_access",
|
||||
foreignKeys = [
|
||||
ForeignKey(
|
||||
entity = Principal::class,
|
||||
parentColumns = arrayOf("id"),
|
||||
childColumns = arrayOf("principal"),
|
||||
onDelete = ForeignKey.CASCADE
|
||||
),
|
||||
ForeignKey(
|
||||
entity = CaldavCalendar::class,
|
||||
parentColumns = arrayOf("cdl_id"),
|
||||
childColumns = arrayOf("list"),
|
||||
onDelete = ForeignKey.CASCADE
|
||||
)],
|
||||
indices = [
|
||||
Index(value = ["list", "principal"], unique = true),
|
||||
Index(value = ["principal"])
|
||||
]
|
||||
)
|
||||
data class PrincipalAccess(
|
||||
@PrimaryKey(autoGenerate = true) var id: Long = 0,
|
||||
val principal: Long = 0,
|
||||
val list: Long,
|
||||
var invite: Int = INVITE_UNKNOWN,
|
||||
var access: Int = ACCESS_UNKNOWN
|
||||
)
|
@ -0,0 +1,19 @@
|
||||
package org.tasks.data
|
||||
|
||||
import androidx.room.Embedded
|
||||
import androidx.room.Relation
|
||||
|
||||
data class PrincipalWithAccess(
|
||||
@Embedded val access: PrincipalAccess,
|
||||
@Relation(
|
||||
parentColumn = "principal",
|
||||
entityColumn = "id"
|
||||
)
|
||||
val principal: Principal
|
||||
) {
|
||||
val displayName get() = principal.displayName
|
||||
val list get() = access.list
|
||||
val href get() = principal.href
|
||||
val inviteStatus get() = access.invite
|
||||
val name get() = principal.name
|
||||
}
|
Loading…
Reference in New Issue