Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lisätään ehdottavan EO:n sijoitustietojen syöttöön tuki Excel-peräisille CSV-tiedostoille (BOM) #6088

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,20 @@ class PlacementToolServiceIntegrationTest : FullApplicationTest(resetDbBeforeEac
assertEquals(unit.id, data[child.id.raw.toString()])
}

@Test
fun `parse csv with BOM`() {
val csv =
"""
"lapsen_id";"esiopetusyksikon_id"
"${child.id}";"${unit.id}"
"""
.trimIndent()

val data = parsePlacementToolCsv("\ufeff$csv".byteInputStream())
assertEquals(1, data.size)
assertEquals(unit.id, data[child.id.raw.toString()])
}

@Test
fun `parse csv with ssn`() {
val csv =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import java.io.InputStream
import java.time.LocalDate
import java.util.UUID
import org.apache.commons.csv.CSVFormat
import org.apache.commons.io.input.BOMInputStream
import org.springframework.stereotype.Service
import org.springframework.web.multipart.MultipartFile

Expand Down Expand Up @@ -368,13 +369,14 @@ class PlacementToolService(
tx.getPreschoolTerms().firstOrNull { it.finnishPreschool.start > date }
}

fun parsePlacementToolCsv(inputStream: InputStream): Map<String, DaycareId> =
CSVFormat.Builder.create(CSVFormat.DEFAULT)
fun parsePlacementToolCsv(inputStream: InputStream): Map<String, DaycareId> {
val bomStream = BOMInputStream.builder().setInputStream(inputStream).get()
return CSVFormat.Builder.create(CSVFormat.DEFAULT)
.setHeader()
.apply { setIgnoreSurroundingSpaces(true) }
.apply { setDelimiter(';') }
.build()
.parse(inputStream.reader())
.parse(bomStream.reader())
.filter { row ->
row.get(PlacementToolCsvField.CHILD_ID.fieldName).isNotBlank() &&
row.get(PlacementToolCsvField.PRESCHOOL_UNIT_ID.fieldName).isNotBlank()
Expand All @@ -385,5 +387,6 @@ fun parsePlacementToolCsv(inputStream: InputStream): Map<String, DaycareId> =
UUID.fromString(row.get(PlacementToolCsvField.PRESCHOOL_UNIT_ID.fieldName))
)
}
}

data class PlacementToolData(val childId: ChildId, val preschoolId: DaycareId)
Loading