feat(data): entities Room CRM converters et exclusions doublons
EBO <eric.bouhana@softalys.com> committé le 2026-07-22 15:22
71980dbb58cbaac76f4362c5bca2725a34c513e5
1 parent(s)
6 fichiers modifiés
+119
-0
A
android/app/src/main/java/fr/ebii/card2vcf/data/Converters.kt
+22
-0
@@ -0,0 +1,22 @@
| 1 | +package fr.ebii.card2vcf.data | |
| 2 | + | |
| 3 | +import androidx.room.TypeConverter | |
| 4 | +import org.json.JSONArray | |
| 5 | + | |
| 6 | +class Converters { | |
| 7 | + @TypeConverter | |
| 8 | + fun fromStringList(value: List<String>?): String { | |
| 9 | + val arr = JSONArray() | |
| 10 | + (value ?: emptyList()).forEach { arr.put(it) } | |
| 11 | + return arr.toString() | |
| 12 | + } | |
| 13 | + | |
| 14 | + @TypeConverter | |
| 15 | + fun toStringList(value: String?): List<String> { | |
| 16 | + if (value.isNullOrBlank()) return emptyList() | |
| 17 | + val arr = JSONArray(value) | |
| 18 | + return buildList { | |
| 19 | + for (i in 0 until arr.length()) add(arr.getString(i)) | |
| 20 | + } | |
| 21 | + } | |
| 22 | +} |
A
android/app/src/main/java/fr/ebii/card2vcf/data/CrmContactEntity.kt
+25
-0
@@ -0,0 +1,25 @@
| 1 | +package fr.ebii.card2vcf.data | |
| 2 | + | |
| 3 | +import androidx.room.Entity | |
| 4 | +import androidx.room.PrimaryKey | |
| 5 | + | |
| 6 | +@Entity(tableName = "crm_contacts") | |
| 7 | +data class CrmContactEntity( | |
| 8 | + @PrimaryKey(autoGenerate = true) val id: Long = 0, | |
| 9 | + val fullName: String? = null, | |
| 10 | + val firstName: String? = null, | |
| 11 | + val lastName: String? = null, | |
| 12 | + val company: String? = null, | |
| 13 | + val jobTitle: String? = null, | |
| 14 | + val phones: List<String> = emptyList(), | |
| 15 | + val emails: List<String> = emptyList(), | |
| 16 | + val website: String? = null, | |
| 17 | + val address: String? = null, | |
| 18 | + val notes: String? = null, | |
| 19 | + val cardImagePath: String? = null, | |
| 20 | + val profileImagePath: String? = null, | |
| 21 | + val createdAt: Long = 0L, | |
| 22 | + val updatedAt: Long = 0L, | |
| 23 | + val phonesText: String = "", // space-joined, pour FTS | |
| 24 | + val emailsText: String = "", | |
| 25 | +) |
A
android/app/src/main/java/fr/ebii/card2vcf/data/CrmContactFts.kt
+19
-0
@@ -0,0 +1,19 @@
| 1 | +package fr.ebii.card2vcf.data | |
| 2 | + | |
| 3 | +import androidx.room.Entity | |
| 4 | +import androidx.room.Fts4 | |
| 5 | + | |
| 6 | +@Fts4(contentEntity = CrmContactEntity::class) | |
| 7 | +@Entity(tableName = "crm_contacts_fts") | |
| 8 | +data class CrmContactFts( | |
| 9 | + val fullName: String?, | |
| 10 | + val firstName: String?, | |
| 11 | + val lastName: String?, | |
| 12 | + val company: String?, | |
| 13 | + val jobTitle: String?, | |
| 14 | + val website: String?, | |
| 15 | + val address: String?, | |
| 16 | + val notes: String?, | |
| 17 | + val phonesText: String?, | |
| 18 | + val emailsText: String?, | |
| 19 | +) |
A
android/app/src/main/java/fr/ebii/card2vcf/data/CrmDatabase.kt
+13
-0
@@ -0,0 +1,13 @@
| 1 | +package fr.ebii.card2vcf.data | |
| 2 | + | |
| 3 | +import android.content.Context | |
| 4 | + | |
| 5 | +/** | |
| 6 | + * Stub temporaire pour compiler Card2vcfApp tant que Task 2 n'a pas fourni | |
| 7 | + * la vraie base Room (DAO + @Database). | |
| 8 | + */ | |
| 9 | +class CrmDatabase private constructor() { | |
| 10 | + companion object { | |
| 11 | + fun get(context: Context): CrmDatabase = CrmDatabase() | |
| 12 | + } | |
| 13 | +} |
A
android/app/src/main/java/fr/ebii/card2vcf/data/DuplicateExclusionEntity.kt
+15
-0
@@ -0,0 +1,15 @@
| 1 | +package fr.ebii.card2vcf.data | |
| 2 | + | |
| 3 | +import androidx.room.Entity | |
| 4 | +import androidx.room.Index | |
| 5 | +import androidx.room.PrimaryKey | |
| 6 | + | |
| 7 | +@Entity( | |
| 8 | + tableName = "duplicate_exclusions", | |
| 9 | + indices = [Index(value = ["idA", "idB"], unique = true)], | |
| 10 | +) | |
| 11 | +data class DuplicateExclusionEntity( | |
| 12 | + @PrimaryKey(autoGenerate = true) val id: Long = 0, | |
| 13 | + val idA: Long, // always idA < idB | |
| 14 | + val idB: Long, | |
| 15 | +) |
A
android/app/src/test/java/fr/ebii/card2vcf/data/ConvertersTest.kt
+25
-0
@@ -0,0 +1,25 @@
| 1 | +package fr.ebii.card2vcf.data | |
| 2 | + | |
| 3 | +import org.junit.Assert.assertEquals | |
| 4 | +import org.junit.Test | |
| 5 | +import org.junit.runner.RunWith | |
| 6 | +import org.robolectric.RobolectricTestRunner | |
| 7 | +import org.robolectric.annotation.Config | |
| 8 | + | |
| 9 | +@RunWith(RobolectricTestRunner::class) | |
| 10 | +@Config(sdk = [31]) | |
| 11 | +class ConvertersTest { | |
| 12 | + private val c = Converters() | |
| 13 | + | |
| 14 | + @Test | |
| 15 | + fun roundTripStringList() { | |
| 16 | + val list = listOf("a@b.c", "x@y.z") | |
| 17 | + assertEquals(list, c.toStringList(c.fromStringList(list))) | |
| 18 | + } | |
| 19 | + | |
| 20 | + @Test | |
| 21 | + fun nullOrEmpty() { | |
| 22 | + assertEquals(emptyList<String>(), c.toStringList(null)) | |
| 23 | + assertEquals("[]", c.fromStringList(emptyList())) | |
| 24 | + } | |
| 25 | +} |
GitRust