From e196692e1d667e65554462701c28db7f428325a2 Mon Sep 17 00:00:00 2001 From: tiagohm Date: Sat, 3 Feb 2024 11:00:24 -0300 Subject: [PATCH] [api]: Fix FastCSV upgrade --- api/src/test/kotlin/SimbadDatabaseGenerator.kt | 12 ++++++------ .../astap/plate/solving/AstapPlateSolver.kt | 2 +- .../astap/star/detection/AstapStarDetector.kt | 9 +++++---- .../retrofit/CSVRecordListConverter.kt | 10 +++++----- .../retrofit/CSVRecordListConverterFactory.kt | 4 ++-- .../src/main/kotlin/nebulosa/simbad/Simbad.kt | 4 ++-- .../kotlin/nebulosa/simbad/SimbadService.kt | 18 +++++++++--------- .../nebulosa/skycatalog/hyg/HygDatabase.kt | 9 +++++---- .../main/kotlin/nebulosa/vizier/VizierTAP.kt | 4 ++-- .../kotlin/nebulosa/vizier/VizierTAPService.kt | 11 ++++++----- 10 files changed, 43 insertions(+), 40 deletions(-) diff --git a/api/src/test/kotlin/SimbadDatabaseGenerator.kt b/api/src/test/kotlin/SimbadDatabaseGenerator.kt index f2b99dcfa..8f194f059 100644 --- a/api/src/test/kotlin/SimbadDatabaseGenerator.kt +++ b/api/src/test/kotlin/SimbadDatabaseGenerator.kt @@ -1,6 +1,6 @@ import de.siegmar.fastcsv.reader.CommentStrategy import de.siegmar.fastcsv.reader.CsvReader -import de.siegmar.fastcsv.reader.NamedCsvRow +import de.siegmar.fastcsv.reader.NamedCsvRecord import nebulosa.adql.* import nebulosa.api.atlas.SimbadDatabaseWriter import nebulosa.api.atlas.SimbadEntity @@ -49,25 +49,25 @@ object SimbadDatabaseGenerator { @JvmStatic private val CALDWELL = resource("caldwell.csv")!! .use { stream -> - CSV_READER.build(InputStreamReader(stream, Charsets.UTF_8)) + CSV_READER.ofCsvRecord(InputStreamReader(stream, Charsets.UTF_8)) .associate { it.getField(1).ifEmpty { it.getField(2) } to it.getField(0) } } @JvmStatic private val BENNETT = resource("bennett.csv")!! .use { stream -> - CSV_READER.build(InputStreamReader(stream, Charsets.UTF_8)) + CSV_READER.ofCsvRecord(InputStreamReader(stream, Charsets.UTF_8)) .associate { it.getField(1) to it.getField(0) } } @JvmStatic private val DUNLOP = resource("dunlop.csv")!! .use { stream -> - CSV_READER.build(InputStreamReader(stream, Charsets.UTF_8)) + CSV_READER.ofCsvRecord(InputStreamReader(stream, Charsets.UTF_8)) .associate { it.getField(1) to it.getField(0) } } @JvmStatic private val HERSHEL = resource("hershel.csv")!! .use { stream -> - CSV_READER.build(InputStreamReader(stream, Charsets.UTF_8)) + CSV_READER.ofCsvRecord(InputStreamReader(stream, Charsets.UTF_8)) .associate { it.getField(1) to it.getField(0) } } @@ -225,7 +225,7 @@ object SimbadDatabaseGenerator { } @JvmStatic - private fun List.parse(entities: MutableList): List { + private fun List.parse(entities: MutableList): List { var writeCount = 0 for (row in this) { diff --git a/nebulosa-astap/src/main/kotlin/nebulosa/astap/plate/solving/AstapPlateSolver.kt b/nebulosa-astap/src/main/kotlin/nebulosa/astap/plate/solving/AstapPlateSolver.kt index ccf844f73..23afc4292 100644 --- a/nebulosa-astap/src/main/kotlin/nebulosa/astap/plate/solving/AstapPlateSolver.kt +++ b/nebulosa-astap/src/main/kotlin/nebulosa/astap/plate/solving/AstapPlateSolver.kt @@ -104,7 +104,7 @@ class AstapPlateSolver(path: Path) : PlateSolver { header.add(NOAOExt.CD2_1, cd21) header.add(NOAOExt.CD2_2, cd22) - val solution = PlateSolution(true, crota2.deg, cdelt2.deg, crval1.deg, crval2.deg, width.deg, height.deg, header = header) + val solution = PlateSolution(true, crota2.deg, cdelt2.deg, crval1.deg, crval2.deg, width.deg, height.deg) LOG.info("astap solved. calibration={}", solution) diff --git a/nebulosa-astap/src/main/kotlin/nebulosa/astap/star/detection/AstapStarDetector.kt b/nebulosa-astap/src/main/kotlin/nebulosa/astap/star/detection/AstapStarDetector.kt index 4b604591c..87306d63d 100644 --- a/nebulosa-astap/src/main/kotlin/nebulosa/astap/star/detection/AstapStarDetector.kt +++ b/nebulosa-astap/src/main/kotlin/nebulosa/astap/star/detection/AstapStarDetector.kt @@ -1,6 +1,7 @@ package nebulosa.astap.star.detection -import de.siegmar.fastcsv.reader.NamedCsvReader +import de.siegmar.fastcsv.reader.CommentStrategy +import de.siegmar.fastcsv.reader.CsvReader import nebulosa.common.process.ProcessExecutor import nebulosa.log.loggerFor import nebulosa.star.detection.ImageStar @@ -35,7 +36,7 @@ class AstapStarDetector(path: Path) : StarDetector { try { csvFile.inputStream().use { - for (record in CSV_READER.build(InputStreamReader(it, Charsets.UTF_8))) { + for (record in CSV_READER.ofNamedCsvRecord(InputStreamReader(it, Charsets.UTF_8))) { detectedStars.add( Star( record.getField("x").toDouble(), @@ -58,10 +59,10 @@ class AstapStarDetector(path: Path) : StarDetector { @JvmStatic private val LOG = loggerFor() - @JvmStatic private val CSV_READER = NamedCsvReader.builder() + @JvmStatic private val CSV_READER = CsvReader.builder() .fieldSeparator(',') .quoteCharacter('"') .commentCharacter('#') - .skipComments(true) + .commentStrategy(CommentStrategy.SKIP) } } diff --git a/nebulosa-retrofit/src/main/kotlin/nebulosa/retrofit/CSVRecordListConverter.kt b/nebulosa-retrofit/src/main/kotlin/nebulosa/retrofit/CSVRecordListConverter.kt index 4508cc1d3..dbb51bdb6 100644 --- a/nebulosa-retrofit/src/main/kotlin/nebulosa/retrofit/CSVRecordListConverter.kt +++ b/nebulosa-retrofit/src/main/kotlin/nebulosa/retrofit/CSVRecordListConverter.kt @@ -1,15 +1,15 @@ package nebulosa.retrofit -import de.siegmar.fastcsv.reader.NamedCsvReader -import de.siegmar.fastcsv.reader.NamedCsvRow +import de.siegmar.fastcsv.reader.CsvReader +import de.siegmar.fastcsv.reader.NamedCsvRecord import okhttp3.ResponseBody import retrofit2.Converter import java.io.InputStreamReader -data class CSVRecordListConverter(private val reader: NamedCsvReader.NamedCsvReaderBuilder) : Converter> { +data class CSVRecordListConverter(private val reader: CsvReader.CsvReaderBuilder) : Converter> { - override fun convert(value: ResponseBody): List { + override fun convert(value: ResponseBody): List { val charset = value.contentType()?.charset() ?: Charsets.UTF_8 - return value.use { reader.build(InputStreamReader(value.byteStream(), charset)).toList() } + return value.use { reader.ofNamedCsvRecord(InputStreamReader(value.byteStream(), charset)).toList() } } } diff --git a/nebulosa-retrofit/src/main/kotlin/nebulosa/retrofit/CSVRecordListConverterFactory.kt b/nebulosa-retrofit/src/main/kotlin/nebulosa/retrofit/CSVRecordListConverterFactory.kt index 8c39da918..c127affd7 100644 --- a/nebulosa-retrofit/src/main/kotlin/nebulosa/retrofit/CSVRecordListConverterFactory.kt +++ b/nebulosa-retrofit/src/main/kotlin/nebulosa/retrofit/CSVRecordListConverterFactory.kt @@ -1,11 +1,11 @@ package nebulosa.retrofit -import de.siegmar.fastcsv.reader.NamedCsvReader +import de.siegmar.fastcsv.reader.CsvReader import retrofit2.Converter import retrofit2.Retrofit import java.lang.reflect.Type -data class CSVRecordListConverterFactory(private val reader: NamedCsvReader.NamedCsvReaderBuilder) : Converter.Factory() { +data class CSVRecordListConverterFactory(private val reader: CsvReader.CsvReaderBuilder) : Converter.Factory() { override fun responseBodyConverter( type: Type, diff --git a/nebulosa-simbad/src/main/kotlin/nebulosa/simbad/Simbad.kt b/nebulosa-simbad/src/main/kotlin/nebulosa/simbad/Simbad.kt index a3fa5c28e..fcee0faa0 100644 --- a/nebulosa-simbad/src/main/kotlin/nebulosa/simbad/Simbad.kt +++ b/nebulosa-simbad/src/main/kotlin/nebulosa/simbad/Simbad.kt @@ -1,6 +1,6 @@ package nebulosa.simbad -import de.siegmar.fastcsv.reader.NamedCsvRow +import de.siegmar.fastcsv.reader.NamedCsvRecord import okhttp3.FormBody import retrofit2.Call import retrofit2.http.Body @@ -9,5 +9,5 @@ import retrofit2.http.POST interface Simbad { @POST("simbad/sim-tap/sync") - fun query(@Body body: FormBody): Call> + fun query(@Body body: FormBody): Call> } diff --git a/nebulosa-simbad/src/main/kotlin/nebulosa/simbad/SimbadService.kt b/nebulosa-simbad/src/main/kotlin/nebulosa/simbad/SimbadService.kt index ae7b7676a..7a089c55a 100644 --- a/nebulosa-simbad/src/main/kotlin/nebulosa/simbad/SimbadService.kt +++ b/nebulosa-simbad/src/main/kotlin/nebulosa/simbad/SimbadService.kt @@ -1,7 +1,8 @@ package nebulosa.simbad -import de.siegmar.fastcsv.reader.NamedCsvReader -import de.siegmar.fastcsv.reader.NamedCsvRow +import de.siegmar.fastcsv.reader.CommentStrategy +import de.siegmar.fastcsv.reader.CsvReader +import de.siegmar.fastcsv.reader.NamedCsvRecord import nebulosa.adql.* import nebulosa.log.loggerFor import nebulosa.math.* @@ -31,11 +32,11 @@ class SimbadService( private val service by lazy { retrofit.create() } - fun query(query: Query): Call> { + fun query(query: Query): Call> { return query("$query") } - fun query(query: String): Call> { + fun query(query: String): Call> { val body = FormBody.Builder() .add("request", "doQuery") .add("lang", "adql") @@ -49,9 +50,8 @@ class SimbadService( } fun search(query: Query): List { - val rows = query(query).execute().body() - if (rows.isNullOrEmpty()) return emptyList() - val res = ArrayList(rows.size) + val rows = query(query).execute().body() ?: return emptyList() + val res = ArrayList() val currentTime = UTC.now() fun matchName(name: String): String? { @@ -160,11 +160,11 @@ class SimbadService( @JvmStatic private val LOG = loggerFor() - @JvmStatic private val CSV_READER = NamedCsvReader.builder() + @JvmStatic private val CSV_READER = CsvReader.builder() .fieldSeparator('\t') .quoteCharacter('"') .commentCharacter('#') - .skipComments(true) + .commentStrategy(CommentStrategy.SKIP) @JvmStatic private val BASIC_TABLE = From("basic").alias("b") @JvmStatic private val FLUX_TABLE = From("allfluxes").alias("f") diff --git a/nebulosa-skycatalog-hyg/src/main/kotlin/nebulosa/skycatalog/hyg/HygDatabase.kt b/nebulosa-skycatalog-hyg/src/main/kotlin/nebulosa/skycatalog/hyg/HygDatabase.kt index d4deecf20..f60ba0852 100644 --- a/nebulosa-skycatalog-hyg/src/main/kotlin/nebulosa/skycatalog/hyg/HygDatabase.kt +++ b/nebulosa-skycatalog-hyg/src/main/kotlin/nebulosa/skycatalog/hyg/HygDatabase.kt @@ -1,6 +1,7 @@ package nebulosa.skycatalog.hyg -import de.siegmar.fastcsv.reader.NamedCsvReader +import de.siegmar.fastcsv.reader.CommentStrategy +import de.siegmar.fastcsv.reader.CsvReader import nebulosa.math.deg import nebulosa.math.hours import nebulosa.math.kms @@ -23,7 +24,7 @@ class HygDatabase : SkyCatalog(118005) { fun load(stream: InputStream) { clear() - val reader = CSV_READER.build(InputStreamReader(stream, Charsets.UTF_8)) + val reader = CSV_READER.ofNamedCsvRecord(InputStreamReader(stream, Charsets.UTF_8)) val names = ArrayList(7) val currentTime = UTC.now() @@ -79,10 +80,10 @@ class HygDatabase : SkyCatalog(118005) { companion object { - @JvmStatic private val CSV_READER = NamedCsvReader.builder() + @JvmStatic private val CSV_READER = CsvReader.builder() .fieldSeparator(',') .quoteCharacter('"') .commentCharacter('#') - .skipComments(true) + .commentStrategy(CommentStrategy.SKIP) } } diff --git a/nebulosa-vizier/src/main/kotlin/nebulosa/vizier/VizierTAP.kt b/nebulosa-vizier/src/main/kotlin/nebulosa/vizier/VizierTAP.kt index e90d9a312..a7ddb0901 100644 --- a/nebulosa-vizier/src/main/kotlin/nebulosa/vizier/VizierTAP.kt +++ b/nebulosa-vizier/src/main/kotlin/nebulosa/vizier/VizierTAP.kt @@ -1,6 +1,6 @@ package nebulosa.vizier -import de.siegmar.fastcsv.reader.NamedCsvRow +import de.siegmar.fastcsv.reader.NamedCsvRecord import okhttp3.FormBody import retrofit2.Call import retrofit2.http.Body @@ -9,5 +9,5 @@ import retrofit2.http.POST interface VizierTAP { @POST("TAPVizieR/tap/sync") - fun query(@Body body: FormBody): Call> + fun query(@Body body: FormBody): Call> } diff --git a/nebulosa-vizier/src/main/kotlin/nebulosa/vizier/VizierTAPService.kt b/nebulosa-vizier/src/main/kotlin/nebulosa/vizier/VizierTAPService.kt index e21ec2bd9..144993be8 100644 --- a/nebulosa-vizier/src/main/kotlin/nebulosa/vizier/VizierTAPService.kt +++ b/nebulosa-vizier/src/main/kotlin/nebulosa/vizier/VizierTAPService.kt @@ -1,7 +1,8 @@ package nebulosa.vizier -import de.siegmar.fastcsv.reader.NamedCsvReader -import de.siegmar.fastcsv.reader.NamedCsvRow +import de.siegmar.fastcsv.reader.CommentStrategy +import de.siegmar.fastcsv.reader.CsvReader +import de.siegmar.fastcsv.reader.NamedCsvRecord import nebulosa.retrofit.CSVRecordListConverterFactory import nebulosa.retrofit.RetrofitService import okhttp3.FormBody @@ -23,7 +24,7 @@ class VizierTAPService(url: String = "") : RetrofitService(url.ifBlank { URL }) private val service by lazy { retrofit.create() } - fun query(query: String): Call> { + fun query(query: String): Call> { val body = FormBody.Builder() .add("request", "doQuery") .add("lang", "adql") @@ -38,10 +39,10 @@ class VizierTAPService(url: String = "") : RetrofitService(url.ifBlank { URL }) const val URL = "http://tapvizier.cds.unistra.fr/" - @JvmStatic private val CSV_READER = NamedCsvReader.builder() + @JvmStatic private val CSV_READER = CsvReader.builder() .fieldSeparator(',') .quoteCharacter('"') .commentCharacter('#') - .skipComments(true) + .commentStrategy(CommentStrategy.SKIP) } }