Double quotes now escaped in csv.

This commit is contained in:
neviyn 2020-01-15 14:09:30 +00:00
parent 52c37b1770
commit 0600af16b4

View File

@ -45,6 +45,7 @@ data class Tutor(
@ManyToOne(fetch = FetchType.LAZY)
val site: Site = Site(-1)
) {
@Suppress("JpaDataSourceORMInspection")
@JsonIgnore
@ManyToMany
@JoinTable(name = "tutor_observations",
@ -90,27 +91,30 @@ data class Observation(
val person: String = "UNKNOWN"
) {
fun toCsvFormat(): String {
fun escapeSpecialCharacters(data: String): String {
return data.replace("\"", "\"\"")
}
val dataPortion = "${date.toString("dd/MM/yyyy")},\"${scenarios.joinToString { it.title }}\"," +
"\"Training\",\"Operations - Shift Operations\",\"${site.name}\",\"N/A\"," +
"${roundScore(monitoring)},${roundScore(controlProcedural)},${roundScore(control)}," +
"${roundScore(conservatism)},${roundScore(teamworkCommunications)},${roundScore(teamworkLeadership)}," +
"${roundScore(teamworkWorkload)},${roundScore(knowledge)}," +
"\"${scenarios.map { it.monitoringStrengths }.filter { it.isNotEmpty() }.joinToString(separator = "; ")}\"," +
"\"${scenarios.map { it.controlProceduralStrengths }.filter { it.isNotEmpty() }.joinToString(separator = "; ")}\"," +
"\"${scenarios.map { it.controlStrengths }.filter { it.isNotEmpty() }.joinToString(separator = "; ")}\"," +
"\"${scenarios.map { it.conservatismStrengths }.filter { it.isNotEmpty() }.joinToString(separator = "; ")}\"," +
"\"${scenarios.map { it.teamworkCommunicationsStrengths }.filter { it.isNotEmpty() }.joinToString(separator = "; ")}\"," +
"\"${scenarios.map { it.teamworkLeadershipStrengths }.filter { it.isNotEmpty() }.joinToString(separator = "; ")}\"," +
"\"${scenarios.map { it.teamworkWorkloadStrengths }.filter { it.isNotEmpty() }.joinToString(separator = "; ")}\"," +
"\"${scenarios.map { it.knowledgeStrengths }.filter { it.isNotEmpty() }.joinToString(separator = "; ")}\"," +
"\"${scenarios.map { it.monitoringImprovements }.filter { it.isNotEmpty() }.joinToString(separator = "; ")}\"," +
"\"${scenarios.map { it.controlProceduralImprovements }.filter { it.isNotEmpty() }.joinToString(separator = "; ")}\"," +
"\"${scenarios.map { it.controlImprovements }.filter { it.isNotEmpty() }.joinToString(separator = "; ")}\"," +
"\"${scenarios.map { it.conservatismImprovements }.filter { it.isNotEmpty() }.joinToString(separator = "; ")}\"," +
"\"${scenarios.map { it.teamworkCommunicationsImprovements }.filter { it.isNotEmpty() }.joinToString(separator = "; ")}\"," +
"\"${scenarios.map { it.teamworkLeadershipImprovements }.filter { it.isNotEmpty() }.joinToString(separator = "; ")}\"," +
"\"${scenarios.map { it.teamworkWorkloadImprovements }.filter { it.isNotEmpty() }.joinToString(separator = "; ")}\"," +
"\"${scenarios.map { it.knowledgeImprovements }.filter { it.isNotEmpty() }.joinToString(separator = "; ")}\"," +
"\"${scenarios.map { it.monitoringStrengths }.filter { it.isNotEmpty() }.joinToString(separator = "; ") { escapeSpecialCharacters(it) }}\"," +
"\"${scenarios.map { it.controlProceduralStrengths }.filter { it.isNotEmpty() }.joinToString(separator = "; ") { escapeSpecialCharacters(it) }}\"," +
"\"${scenarios.map { it.controlStrengths }.filter { it.isNotEmpty() }.joinToString(separator = "; ") { escapeSpecialCharacters(it) }}\"," +
"\"${scenarios.map { it.conservatismStrengths }.filter { it.isNotEmpty() }.joinToString(separator = "; ") { escapeSpecialCharacters(it) }}\"," +
"\"${scenarios.map { it.teamworkCommunicationsStrengths }.filter { it.isNotEmpty() }.joinToString(separator = "; ") { escapeSpecialCharacters(it) }}\"," +
"\"${scenarios.map { it.teamworkLeadershipStrengths }.filter { it.isNotEmpty() }.joinToString(separator = "; ") { escapeSpecialCharacters(it) }}\"," +
"\"${scenarios.map { it.teamworkWorkloadStrengths }.filter { it.isNotEmpty() }.joinToString(separator = "; ") { escapeSpecialCharacters(it) }}\"," +
"\"${scenarios.map { it.knowledgeStrengths }.filter { it.isNotEmpty() }.joinToString(separator = "; ") { escapeSpecialCharacters(it) }}\"," +
"\"${scenarios.map { it.monitoringImprovements }.filter { it.isNotEmpty() }.joinToString(separator = "; ") { escapeSpecialCharacters(it) }}\"," +
"\"${scenarios.map { it.controlProceduralImprovements }.filter { it.isNotEmpty() }.joinToString(separator = "; ") { escapeSpecialCharacters(it) }}\"," +
"\"${scenarios.map { it.controlImprovements }.filter { it.isNotEmpty() }.joinToString(separator = "; ") { escapeSpecialCharacters(it) }}\"," +
"\"${scenarios.map { it.conservatismImprovements }.filter { it.isNotEmpty() }.joinToString(separator = "; ") { escapeSpecialCharacters(it) }}\"," +
"\"${scenarios.map { it.teamworkCommunicationsImprovements }.filter { it.isNotEmpty() }.joinToString(separator = "; ") { escapeSpecialCharacters(it) }}\"," +
"\"${scenarios.map { it.teamworkLeadershipImprovements }.filter { it.isNotEmpty() }.joinToString(separator = "; ") { escapeSpecialCharacters(it) }}\"," +
"\"${scenarios.map { it.teamworkWorkloadImprovements }.filter { it.isNotEmpty() }.joinToString(separator = "; ") { escapeSpecialCharacters(it) }}\"," +
"\"${scenarios.map { it.knowledgeImprovements }.filter { it.isNotEmpty() }.joinToString(separator = "; ") { escapeSpecialCharacters(it) }}\"," +
";#None;#,"
return tutors.joinToString("\n") { it.name + "," + dataPortion }
}