diff options
| author | Robert Jaros <rjaros@finn.pl> | 2020-03-11 16:18:17 +0100 |
|---|---|---|
| committer | Robert Jaros <rjaros@finn.pl> | 2020-03-11 16:18:17 +0100 |
| commit | 9e243a469ae6544e8cf523ad09b959f541c3f565 (patch) | |
| tree | be9c7447e221af49180c9e98434df7f988b940b8 /kvision-modules/kvision-common-types/src | |
| parent | ec6084c42c13a621e17b17bd40d90b5c7879f0ec (diff) | |
| download | kvision-9e243a469ae6544e8cf523ad09b959f541c3f565.tar.gz kvision-9e243a469ae6544e8cf523ad09b959f541c3f565.tar.bz2 kvision-9e243a469ae6544e8cf523ad09b959f541c3f565.zip | |
Upgrade to Kotlin 1.3.70 + other dependencies (Coroutinse, Serialization, Spring Boot)
Major refactoring of build architecture.
Diffstat (limited to 'kvision-modules/kvision-common-types/src')
7 files changed, 307 insertions, 0 deletions
diff --git a/kvision-modules/kvision-common-types/src/main/kotlin/pl/treksoft/kvision/types/Date.kt b/kvision-modules/kvision-common-types/src/commonMain/kotlin/pl/treksoft/kvision/types/Date.kt index 3e7152a1..3e7152a1 100644 --- a/kvision-modules/kvision-common-types/src/main/kotlin/pl/treksoft/kvision/types/Date.kt +++ b/kvision-modules/kvision-common-types/src/commonMain/kotlin/pl/treksoft/kvision/types/Date.kt diff --git a/kvision-modules/kvision-common-types/src/main/kotlin/pl/treksoft/kvision/types/Decimal.kt b/kvision-modules/kvision-common-types/src/commonMain/kotlin/pl/treksoft/kvision/types/Decimal.kt index 26d64654..26d64654 100644 --- a/kvision-modules/kvision-common-types/src/main/kotlin/pl/treksoft/kvision/types/Decimal.kt +++ b/kvision-modules/kvision-common-types/src/commonMain/kotlin/pl/treksoft/kvision/types/Decimal.kt diff --git a/kvision-modules/kvision-common-types/src/main/kotlin/pl/treksoft/kvision/types/KFile.kt b/kvision-modules/kvision-common-types/src/commonMain/kotlin/pl/treksoft/kvision/types/KFile.kt index ce4adca4..ce4adca4 100644 --- a/kvision-modules/kvision-common-types/src/main/kotlin/pl/treksoft/kvision/types/KFile.kt +++ b/kvision-modules/kvision-common-types/src/commonMain/kotlin/pl/treksoft/kvision/types/KFile.kt diff --git a/kvision-modules/kvision-common-types/src/jsMain/kotlin/pl/treksoft/kvision/types/Date.kt b/kvision-modules/kvision-common-types/src/jsMain/kotlin/pl/treksoft/kvision/types/Date.kt new file mode 100644 index 00000000..82e913fe --- /dev/null +++ b/kvision-modules/kvision-common-types/src/jsMain/kotlin/pl/treksoft/kvision/types/Date.kt @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2017-present Robert Jaros + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package pl.treksoft.kvision.types + +import kotlin.js.Date + +const val KV_DEFAULT_DATE_FORMAT = "YYYY-MM-DD HH:mm:ss" + +actual typealias LocalDateTime = Date + +actual typealias LocalDate = Date + +actual typealias LocalTime = Date + +actual typealias OffsetDateTime = Date + +actual typealias OffsetTime = Date diff --git a/kvision-modules/kvision-common-types/src/jsMain/kotlin/pl/treksoft/kvision/types/Decimal.kt b/kvision-modules/kvision-common-types/src/jsMain/kotlin/pl/treksoft/kvision/types/Decimal.kt new file mode 100644 index 00000000..d1c0366e --- /dev/null +++ b/kvision-modules/kvision-common-types/src/jsMain/kotlin/pl/treksoft/kvision/types/Decimal.kt @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2017-present Robert Jaros + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package pl.treksoft.kvision.types + +actual typealias Decimal = Double diff --git a/kvision-modules/kvision-common-types/src/jvmMain/kotlin/pl/treksoft/kvision/types/Date.kt b/kvision-modules/kvision-common-types/src/jvmMain/kotlin/pl/treksoft/kvision/types/Date.kt new file mode 100644 index 00000000..61f8ba58 --- /dev/null +++ b/kvision-modules/kvision-common-types/src/jvmMain/kotlin/pl/treksoft/kvision/types/Date.kt @@ -0,0 +1,200 @@ +/* + * Copyright (c) 2017-present Robert Jaros + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package pl.treksoft.kvision.types + +import com.fasterxml.jackson.core.JsonGenerator +import com.fasterxml.jackson.core.JsonParser +import com.fasterxml.jackson.databind.DeserializationContext +import com.fasterxml.jackson.databind.JsonDeserializer +import com.fasterxml.jackson.databind.JsonSerializer +import com.fasterxml.jackson.databind.SerializerProvider +import java.io.IOException +import java.time.LocalDate +import java.time.LocalDateTime +import java.time.LocalTime +import java.time.OffsetDateTime +import java.time.OffsetTime +import java.time.format.DateTimeFormatter +import java.time.format.DateTimeParseException + +actual typealias LocalDateTime = LocalDateTime + +actual typealias LocalDate = LocalDate + +actual typealias LocalTime = LocalTime + +actual typealias OffsetDateTime = OffsetDateTime + +actual typealias OffsetTime = OffsetTime + +fun String.toDateTimeF(): LocalDateTime = LocalDateTime.parse(this) + +fun String.toDateF(): LocalDate = LocalDate.parse(this) + +fun String.toTimeF(): LocalTime = LocalTime.parse(this) + +fun String.toOffsetDateTimeF(): OffsetDateTime = OffsetDateTime.parse(this) + +fun String.toOffsetTimeF(): OffsetTime = OffsetTime.parse(this) + +fun LocalDateTime.toStringF(): String = this.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME) + +fun LocalDate.toStringF(): String = this.format(DateTimeFormatter.ISO_LOCAL_DATE) + +fun LocalTime.toStringF(): String = this.format(DateTimeFormatter.ISO_LOCAL_TIME) + +fun OffsetDateTime.toStringF(): String = this.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME) + +fun OffsetTime.toStringF(): String = this.format(DateTimeFormatter.ISO_OFFSET_TIME) + +class LocalDateTimeSerializer : JsonSerializer<LocalDateTime>() { + @Throws(IOException::class) + override fun serialize(value: LocalDateTime, gen: JsonGenerator, provider: SerializerProvider) { + try { + val s = value.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME) + gen.writeString(s) + } catch (e: DateTimeParseException) { + System.err.println(e) + gen.writeString("") + } + } +} + +class LocalDateTimeDeserializer : JsonDeserializer<LocalDateTime>() { + @Throws(IOException::class) + override fun deserialize(p: JsonParser, ctx: DeserializationContext): LocalDateTime? { + val str = p.text + try { + @Suppress("MagicNumber") + return LocalDateTime.parse(str.dropLast(6), DateTimeFormatter.ISO_LOCAL_DATE_TIME) + } catch (e: DateTimeParseException) { + System.err.println(e) + return null + } + } +} + +class LocalDateSerializer : JsonSerializer<LocalDate>() { + @Throws(IOException::class) + override fun serialize(value: LocalDate, gen: JsonGenerator, provider: SerializerProvider) { + try { + val s = value.atStartOfDay().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME) + gen.writeString(s) + } catch (e: DateTimeParseException) { + System.err.println(e) + gen.writeString("") + } + } +} + +class LocalDateDeserializer : JsonDeserializer<LocalDate>() { + @Throws(IOException::class) + override fun deserialize(p: JsonParser, ctx: DeserializationContext): LocalDate? { + val str = p.text + try { + @Suppress("MagicNumber") + return LocalDate.parse(str.dropLast(6), DateTimeFormatter.ISO_LOCAL_DATE_TIME) + } catch (e: DateTimeParseException) { + System.err.println(e) + return null + } + } +} + +class LocalTimeSerializer : JsonSerializer<LocalTime>() { + @Throws(IOException::class) + override fun serialize(value: LocalTime, gen: JsonGenerator, provider: SerializerProvider) { + try { + val s = value.atDate(LocalDate.now()).format(DateTimeFormatter.ISO_LOCAL_DATE_TIME) + gen.writeString(s) + } catch (e: DateTimeParseException) { + System.err.println(e) + gen.writeString("") + } + } +} + +class LocalTimeDeserializer : JsonDeserializer<LocalTime>() { + @Throws(IOException::class) + override fun deserialize(p: JsonParser, ctx: DeserializationContext): LocalTime? { + val str = p.text + try { + @Suppress("MagicNumber") + return LocalTime.parse(str.dropLast(6), DateTimeFormatter.ISO_LOCAL_DATE_TIME) + } catch (e: DateTimeParseException) { + System.err.println(e) + return null + } + } +} + +class OffsetDateTimeSerializer : JsonSerializer<OffsetDateTime>() { + @Throws(IOException::class) + override fun serialize(value: OffsetDateTime, gen: JsonGenerator, provider: SerializerProvider) { + try { + val s = value.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME) + gen.writeString(s) + } catch (e: DateTimeParseException) { + System.err.println(e) + gen.writeString("") + } + } +} + +class OffsetDateTimeDeserializer : JsonDeserializer<OffsetDateTime>() { + @Throws(IOException::class) + override fun deserialize(p: JsonParser, ctx: DeserializationContext): OffsetDateTime? { + val str = p.text + return try { + OffsetDateTime.parse(str, DateTimeFormatter.ISO_OFFSET_DATE_TIME) + } catch (e: DateTimeParseException) { + System.err.println(e) + null + } + } +} + +class OffsetTimeSerializer : JsonSerializer<OffsetTime>() { + @Throws(IOException::class) + override fun serialize(value: OffsetTime, gen: JsonGenerator, provider: SerializerProvider) { + try { + val s = value.atDate(LocalDate.now()).format(DateTimeFormatter.ISO_OFFSET_DATE_TIME) + gen.writeString(s) + } catch (e: DateTimeParseException) { + System.err.println(e) + gen.writeString("") + } + } +} + +class OffsetTimeDeserializer : JsonDeserializer<OffsetTime>() { + @Throws(IOException::class) + override fun deserialize(p: JsonParser, ctx: DeserializationContext): OffsetTime? { + val str = p.text + return try { + OffsetTime.parse(str, DateTimeFormatter.ISO_OFFSET_DATE_TIME) + } catch (e: DateTimeParseException) { + System.err.println(e) + null + } + } +} diff --git a/kvision-modules/kvision-common-types/src/jvmMain/kotlin/pl/treksoft/kvision/types/Decimal.kt b/kvision-modules/kvision-common-types/src/jvmMain/kotlin/pl/treksoft/kvision/types/Decimal.kt new file mode 100644 index 00000000..1d37ae51 --- /dev/null +++ b/kvision-modules/kvision-common-types/src/jvmMain/kotlin/pl/treksoft/kvision/types/Decimal.kt @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2017-present Robert Jaros + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package pl.treksoft.kvision.types + +import com.fasterxml.jackson.core.JsonGenerator +import com.fasterxml.jackson.core.JsonParser +import com.fasterxml.jackson.databind.DeserializationContext +import com.fasterxml.jackson.databind.JsonDeserializer +import com.fasterxml.jackson.databind.JsonSerializer +import com.fasterxml.jackson.databind.SerializerProvider +import java.io.IOException +import java.math.BigDecimal + +actual typealias Decimal = BigDecimal + +class BigDecimalSerializer : JsonSerializer<BigDecimal>() { + @Throws(IOException::class) + override fun serialize(value: BigDecimal, gen: JsonGenerator, provider: SerializerProvider) { + gen.writeNumber(value.toDouble()) + } +} + +class BigDecimalDeserializer : JsonDeserializer<BigDecimal>() { + @Throws(IOException::class) + override fun deserialize(p: JsonParser, ctx: DeserializationContext): BigDecimal? { + return p.doubleValue.toBigDecimal() + } +} |
