Moved generic value classes to separate module

This commit is contained in:
2023-10-26 19:06:26 +02:00
parent 50ec898257
commit b3a55af93a
55 changed files with 264 additions and 257 deletions
+5
View File
@@ -0,0 +1,5 @@
plugins {
id("twomartens.kotlin")
id("twomartens.java")
kotlin("kapt")
}
@@ -1,4 +1,4 @@
package de.twomartens.timetable.model.base
package de.twomartens.timetable.types
@JvmInline
value class Hour private constructor(val value: Int) {
@@ -1,4 +1,4 @@
package de.twomartens.timetable.model.base
package de.twomartens.timetable.types
import java.time.LocalDate
import java.time.LocalDateTime
@@ -1,4 +1,4 @@
package de.twomartens.timetable.model.base
package de.twomartens.timetable.types
@JvmInline
value class NonEmptyString(val name: String) {
@@ -1,4 +1,4 @@
package de.twomartens.timetable.model.base
package de.twomartens.timetable.types
@JvmInline
value class PositiveInteger(val value: Int) {
+1
View File
@@ -5,6 +5,7 @@ plugins {
}
dependencies {
implementation(project(":common"))
implementation(libs.mapstruct.base)
implementation(libs.bundles.spring.boot.security)
implementation(libs.jaxb.impl)
@@ -1,7 +1,7 @@
package de.twomartens.timetable.bahnApi.mapper
import de.twomartens.timetable.bahnApi.model.db.BahnTimetable
import de.twomartens.timetable.model.base.NonEmptyString
import de.twomartens.timetable.types.NonEmptyString
import org.mapstruct.*
import java.time.LocalDateTime
@@ -1,7 +1,7 @@
package de.twomartens.timetable.bahnApi.model
import de.twomartens.timetable.bahnApi.model.db.ScheduledFetchTask
import de.twomartens.timetable.model.base.HourAtDay
import de.twomartens.timetable.types.HourAtDay
import org.springframework.stereotype.Component
import java.time.LocalDateTime
@@ -1,7 +1,7 @@
package de.twomartens.timetable.bahnApi.model.db
import de.twomartens.timetable.bahnApi.model.Eva
import de.twomartens.timetable.model.base.NonEmptyString
import de.twomartens.timetable.types.NonEmptyString
import org.bson.types.ObjectId
import org.springframework.data.annotation.CreatedDate
import org.springframework.data.annotation.Id
@@ -2,7 +2,7 @@ package de.twomartens.timetable.bahnApi.model.db
import de.twomartens.timetable.bahnApi.model.Eva
import de.twomartens.timetable.bahnApi.model.dto.BahnStationStop
import de.twomartens.timetable.model.base.NonEmptyString
import de.twomartens.timetable.types.NonEmptyString
import org.bson.types.ObjectId
import org.springframework.data.annotation.CreatedDate
import org.springframework.data.annotation.Id
@@ -1,7 +1,7 @@
package de.twomartens.timetable.bahnApi.model.db
import de.twomartens.timetable.bahnApi.model.Eva
import de.twomartens.timetable.model.base.HourAtDay
import de.twomartens.timetable.types.HourAtDay
import org.bson.types.ObjectId
import org.springframework.data.annotation.CreatedDate
import org.springframework.data.annotation.Id
@@ -24,7 +24,7 @@ data class BahnStopEvent(
@field:XmlAttribute(name = "wings") var wings: String,
@field:XmlAttribute(name = "l") var line: String
) {
constructor(): this("", "",
constructor() : this("", "",
null,
null,
"", "", "", "",
@@ -5,7 +5,7 @@ import de.twomartens.timetable.bahnApi.model.dto.BahnStation
import de.twomartens.timetable.bahnApi.model.dto.BahnStations
import de.twomartens.timetable.bahnApi.model.dto.BahnTimetable
import de.twomartens.timetable.bahnApi.property.BahnApiProperties
import de.twomartens.timetable.model.base.HourAtDay
import de.twomartens.timetable.types.HourAtDay
import org.springframework.http.HttpEntity
import org.springframework.http.HttpHeaders
import org.springframework.http.HttpMethod
@@ -6,7 +6,7 @@ import de.twomartens.timetable.bahnApi.model.dto.BahnStation
import de.twomartens.timetable.bahnApi.model.dto.BahnTimetable
import de.twomartens.timetable.bahnApi.repository.BahnStationRepository
import de.twomartens.timetable.bahnApi.repository.BahnTimetableRepository
import de.twomartens.timetable.model.base.HourAtDay
import de.twomartens.timetable.types.HourAtDay
import org.mapstruct.factory.Mappers
import org.springframework.stereotype.Service
@@ -5,9 +5,9 @@ import de.twomartens.timetable.bahnApi.model.FetchDates
import de.twomartens.timetable.bahnApi.model.TaskFactory
import de.twomartens.timetable.bahnApi.model.db.ScheduledFetchTask
import de.twomartens.timetable.bahnApi.repository.ScheduledFetchTaskRepository
import de.twomartens.timetable.model.base.Hour
import de.twomartens.timetable.model.base.HourAtDay
import de.twomartens.timetable.model.db.TswRoute
import de.twomartens.timetable.types.Hour
import de.twomartens.timetable.types.HourAtDay
import mu.KotlinLogging
import org.springframework.stereotype.Service
import java.time.LocalDate
@@ -6,8 +6,8 @@ import de.twomartens.timetable.bahnApi.repository.ScheduledFetchTaskRepository
import de.twomartens.timetable.bahnApi.tasks.DeleteScheduledTask
import de.twomartens.timetable.bahnApi.tasks.FetchTimetableTask
import de.twomartens.timetable.bahnApi.tasks.StoreTimetableTask
import de.twomartens.timetable.model.base.HourAtDay
import de.twomartens.timetable.property.TimeProperties
import de.twomartens.timetable.types.HourAtDay
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler
import org.springframework.stereotype.Service
@@ -3,7 +3,7 @@ package de.twomartens.timetable.bahnApi.tasks
import de.twomartens.timetable.bahnApi.model.Eva
import de.twomartens.timetable.bahnApi.service.BahnApiService
import de.twomartens.timetable.bahnApi.service.TaskScheduler
import de.twomartens.timetable.model.base.HourAtDay
import de.twomartens.timetable.types.HourAtDay
import mu.KotlinLogging
import org.springframework.scheduling.annotation.Async
@@ -2,7 +2,7 @@ package de.twomartens.timetable.bahnApi.tasks
import de.twomartens.timetable.bahnApi.model.dto.BahnTimetable
import de.twomartens.timetable.bahnApi.service.BahnDatabaseService
import de.twomartens.timetable.model.base.HourAtDay
import de.twomartens.timetable.types.HourAtDay
import mu.KotlinLogging
import org.springframework.scheduling.annotation.Async
@@ -1,9 +1,9 @@
package de.twomartens.timetable.controller
import de.twomartens.timetable.bahnApi.service.ScheduledTaskService
import de.twomartens.timetable.model.base.NonEmptyString
import de.twomartens.timetable.model.db.UserId
import de.twomartens.timetable.repository.TswRouteRepository
import de.twomartens.timetable.types.NonEmptyString
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.Parameter
import io.swagger.v3.oas.annotations.responses.ApiResponse
@@ -1,6 +1,6 @@
package de.twomartens.timetable.model.db
import de.twomartens.timetable.model.base.PositiveInteger
import de.twomartens.timetable.types.PositiveInteger
@JvmInline
value class CoachCapacity(val capacity: PositiveInteger)
@@ -1,6 +1,6 @@
package de.twomartens.timetable.model.db
import de.twomartens.timetable.model.base.NonEmptyString
import de.twomartens.timetable.types.NonEmptyString
@JvmInline
value class CountryCode(val countryCode: NonEmptyString) {
@@ -1,6 +1,6 @@
package de.twomartens.timetable.model.db
import de.twomartens.timetable.model.base.NonEmptyString
import de.twomartens.timetable.types.NonEmptyString
import kotlin.time.Duration
data class Depot(
@@ -1,6 +1,6 @@
package de.twomartens.timetable.model.db
import de.twomartens.timetable.model.base.NonEmptyString
import de.twomartens.timetable.types.NonEmptyString
import org.bson.types.ObjectId
import org.springframework.data.annotation.CreatedDate
import org.springframework.data.annotation.Id
@@ -1,6 +1,6 @@
package de.twomartens.timetable.model.db
import de.twomartens.timetable.model.base.PositiveInteger
import de.twomartens.timetable.types.PositiveInteger
@JvmInline
value class FormationId(val id: PositiveInteger)
@@ -1,6 +1,6 @@
package de.twomartens.timetable.model.db
import de.twomartens.timetable.model.base.NonEmptyString
import de.twomartens.timetable.types.NonEmptyString
import kotlin.time.Duration
data class Portal(
@@ -1,6 +1,6 @@
package de.twomartens.timetable.model.db
import de.twomartens.timetable.model.base.NonEmptyString
import de.twomartens.timetable.types.NonEmptyString
@JvmInline
value class Section(val name: NonEmptyString)
@@ -1,6 +1,6 @@
package de.twomartens.timetable.model.db
import de.twomartens.timetable.model.base.NonEmptyString
import de.twomartens.timetable.types.NonEmptyString
@JvmInline
value class StationId(val id: NonEmptyString) {
@@ -1,6 +1,6 @@
package de.twomartens.timetable.model.db
import de.twomartens.timetable.model.base.PositiveInteger
import de.twomartens.timetable.types.PositiveInteger
@JvmInline
value class TrackId(val id: PositiveInteger)
@@ -1,6 +1,6 @@
package de.twomartens.timetable.model.db
import de.twomartens.timetable.model.base.NonEmptyString
import de.twomartens.timetable.types.NonEmptyString
import org.bson.types.ObjectId
import org.springframework.data.annotation.CreatedDate
import org.springframework.data.annotation.Id
@@ -1,6 +1,6 @@
package de.twomartens.timetable.model.db
import de.twomartens.timetable.model.base.NonEmptyString
import de.twomartens.timetable.types.NonEmptyString
import org.bson.types.ObjectId
import org.springframework.data.annotation.CreatedDate
import org.springframework.data.annotation.Id
@@ -1,6 +1,6 @@
package de.twomartens.timetable.model.db
import de.twomartens.timetable.model.base.NonEmptyString
import de.twomartens.timetable.types.NonEmptyString
@JvmInline
value class UserId(val id: NonEmptyString)
@@ -1,8 +1,8 @@
package de.twomartens.timetable.repository
import de.twomartens.timetable.model.base.NonEmptyString
import de.twomartens.timetable.model.db.TswRoute
import de.twomartens.timetable.model.db.UserId
import de.twomartens.timetable.types.NonEmptyString
import org.bson.types.ObjectId
import org.springframework.data.mongodb.repository.MongoRepository
@@ -1,8 +1,8 @@
package de.twomartens.timetable.support.configuration
import de.twomartens.timetable.property.RestTemplateTimeoutProperties
import de.twomartens.timetable.support.interceptor.HeaderInterceptorRest
import de.twomartens.timetable.support.interceptor.LoggingInterceptorRest
import de.twomartens.timetable.property.RestTemplateTimeoutProperties
import org.springframework.boot.web.client.RestTemplateBuilder
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
@@ -11,7 +11,7 @@ import org.springframework.web.bind.annotation.RestController
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
@ControllerAdvice(annotations = [RestController::class])
class ExceptionController: ResponseEntityExceptionHandler() {
class ExceptionController : ResponseEntityExceptionHandler() {
@ExceptionHandler(HttpStatusException::class)
fun handleException(e: HttpStatusException): ResponseEntity<ErrorMessage> {
if (e.cause != null) {
@@ -65,7 +65,8 @@ class VersionHtmlController {
JarFile(jarFileName).use { jarFile ->
val entry = jarFile.getEntry(JarFile.MANIFEST_NAME)
jarFile.getInputStream(entry).use { `in` ->
return String(`in`.readAllBytes(), StandardCharsets.UTF_8).lines().toList() }
return String(`in`.readAllBytes(), StandardCharsets.UTF_8).lines().toList()
}
}
} catch (ignored: FileNotFoundException) {
// do nothing if manifest file is not available
@@ -2,5 +2,5 @@ package de.twomartens.timetable.support.exception
import org.springframework.http.HttpStatus
class HttpStatusException(val status: HttpStatus, message: String, cause: Throwable?):
class HttpStatusException(val status: HttpStatus, message: String, cause: Throwable?) :
RuntimeException(message, cause)
@@ -8,7 +8,7 @@ import java.io.ByteArrayInputStream
import java.io.IOException
import java.io.InputStream
class BufferingClientHttpResponseWrapper(private val response: ClientHttpResponse): ClientHttpResponse {
class BufferingClientHttpResponseWrapper(private val response: ClientHttpResponse) : ClientHttpResponse {
private var body: ByteArray? = null
@Throws(IOException::class)
@@ -1,7 +1,7 @@
package de.twomartens.timetable.support.monitoring.actuator
import de.twomartens.timetable.support.interceptor.HeaderInterceptorRest
import de.twomartens.timetable.property.ServiceProperties
import de.twomartens.timetable.support.interceptor.HeaderInterceptorRest
import org.springframework.boot.actuate.health.Health
import org.springframework.boot.actuate.health.HealthIndicator
import org.springframework.boot.actuate.health.Status
@@ -5,7 +5,6 @@ import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.boot.context.properties.bind.ConstructorBinding
import org.springframework.boot.convert.DurationUnit
import org.springframework.cloud.context.config.annotation.RefreshScope
import org.springframework.context.annotation.Configuration
import java.time.Duration
import java.time.temporal.ChronoUnit
+1
View File
@@ -1,6 +1,7 @@
val projectname: String = providers.gradleProperty("projectname").get()
rootProject.name = projectname
include("common")
include("server")
include("deploy")