BugFix importCSV
parent
4caef75230
commit
7806821abc
|
@ -28,7 +28,6 @@ import kotlinx.serialization.json.put
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileWriter
|
import java.io.FileWriter
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import kotlinx.serialization.json.Json
|
|
||||||
import kotlinx.serialization.encodeToString
|
import kotlinx.serialization.encodeToString
|
||||||
import kotlinx.serialization.json.JsonObject
|
import kotlinx.serialization.json.JsonObject
|
||||||
|
|
||||||
|
@ -211,11 +210,11 @@ fun App() {
|
||||||
fun exportToCSV(jsonFilePath: String, csvFilePath: String) {
|
fun exportToCSV(jsonFilePath: String, csvFilePath: String) {
|
||||||
val glossary = readJsonFile(jsonFilePath)
|
val glossary = readJsonFile(jsonFilePath)
|
||||||
val csvContent = buildString {
|
val csvContent = buildString {
|
||||||
appendLine("nom,description,contextePrincipal,contexte2,lieA,synonyme,antonyme")
|
appendLine("Mot;Description;Contexte principal;Contexte 2;Lié à;Synonyme;Antonyme;")
|
||||||
glossary.forEach { entry ->
|
glossary.forEach { entry ->
|
||||||
appendLine(
|
appendLine(
|
||||||
"${entry["nom"]},${entry["description"]},${entry["contextePrincipal"]}," +
|
"${entry["nom"]};${entry["description"]};${entry["contextePrincipal"]};" +
|
||||||
"${entry["contexte2"]},${entry["lieA"]},${entry["synonyme"]},${entry["antonyme"]}"
|
"${entry["contexte2"]};${entry["lieA"]};${entry["synonyme"]};${entry["antonyme"]}"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -245,35 +244,40 @@ fun importCSV(cheminFichier: String) {
|
||||||
val dataLines = lines.drop(1)
|
val dataLines = lines.drop(1)
|
||||||
|
|
||||||
dataLines.forEach { line ->
|
dataLines.forEach { line ->
|
||||||
val values = line.split(";")
|
// Check if the line is not empty or blank
|
||||||
values.forEach { value ->
|
if (line.isNotBlank()) {
|
||||||
println(value)
|
val values = line.replace("\r", "").replace("\n", "").split(";")
|
||||||
}
|
|
||||||
val mot = header.zip(values).toMap().toMutableMap()
|
|
||||||
val nouveauMot = Mot(
|
|
||||||
nom = mot["Mot"]!!,
|
|
||||||
description = mot["Description"]!!,
|
|
||||||
contextePrincipal = mot["Contexte principal"]!!,
|
|
||||||
contexte2 = mot["Contexte 2"]!!,
|
|
||||||
lieA = mot["Lié à"]!!,
|
|
||||||
synonyme = mot["Synonyme"]!!,
|
|
||||||
antonyme = mot["Antonyme"]!!
|
|
||||||
)
|
|
||||||
|
|
||||||
if(mot["Antonyme"] == "\r") {
|
values.forEach { value ->
|
||||||
mot["Antonyme"] = ""
|
println(value)
|
||||||
|
}
|
||||||
|
val mot = header.zip(values).toMap().toMutableMap()
|
||||||
|
val nouveauMot = Mot(
|
||||||
|
nom = mot["Mot"]!!,
|
||||||
|
description = mot["Description"]!!,
|
||||||
|
contextePrincipal = mot["Contexte principal"]!!,
|
||||||
|
contexte2 = mot["Contexte 2"]!!,
|
||||||
|
lieA = mot["Lié à"]!!,
|
||||||
|
synonyme = mot["Synonyme"]!!,
|
||||||
|
antonyme = mot["Antonyme"]!!
|
||||||
|
)
|
||||||
|
|
||||||
|
if (mot["Antonyme"] == "\r") {
|
||||||
|
mot["Antonyme"] = ""
|
||||||
|
}
|
||||||
|
if (mot["Mot"] == null || mot["Mot"] == "") {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (!verifierChampsRequis(mot)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ajouterMotAuGlossaire(nouveauMot)
|
||||||
}
|
}
|
||||||
if (mot["Mot"] == null || mot["Mot"] == "") {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (!verifierChampsRequis(mot)) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
ajouterMotAuGlossaire(nouveauMot)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fun verifierChampsRequis(mot: Map<String, String>): Boolean {
|
fun verifierChampsRequis(mot: Map<String, String>): Boolean {
|
||||||
//Vérifier que les headers sont égales aux champs requis
|
//Vérifier que les headers sont égales aux champs requis
|
||||||
val champsRequis = listOf(
|
val champsRequis = listOf(
|
||||||
|
|
Loading…
Reference in New Issue