Skip to content

Commit

Permalink
Add and apply ktlint
Browse files Browse the repository at this point in the history
  • Loading branch information
Huulivoide committed Aug 19, 2024
1 parent d597612 commit 74e5806
Show file tree
Hide file tree
Showing 111 changed files with 4,053 additions and 3,322 deletions.
5 changes: 5 additions & 0 deletions spring-boot/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ indent_style = space
insert_final_newline = true
max_line_length = 120
tab_width = 4

[*.{kt,kts}]
ij_kotlin_allow_trailing_comma_on_call_site=false
ij_kotlin_allow_trailing_comma=false
ij_kotlin_packages_to_use_import_on_demand=false
1 change: 1 addition & 0 deletions spring-boot/.mvn/jvm.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--add-opens java.base/java.lang=ALL-UNNAMED
18 changes: 18 additions & 0 deletions spring-boot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<maven-compiler.plugin.version>3.13.0</maven-compiler.plugin.version>
<surefire-plugin.version>3.3.1</surefire-plugin.version>
<maven-enforcer-plugin.version>3.5.0</maven-enforcer-plugin.version>
<ktlint-plugin.version>3.2.0</ktlint-plugin.version>

<!-- Library versions -->
<arrow-core.version>1.2.4</arrow-core.version>
Expand Down Expand Up @@ -466,6 +467,23 @@
</execution>
</executions>
</plugin>

<plugin>
<groupId>com.github.gantsign.maven</groupId>
<artifactId>ktlint-maven-plugin</artifactId>
<version>${ktlint-plugin.version}</version>
<executions>
<execution>
<id>check</id>
<configuration>
<sourceRoots>${project.build.sourceDirectory}/fi</sourceRoots>
</configuration>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package fi.hsl.jore4.mapmatching

object Constants {

const val SNAP_TO_LINK_ENDPOINT_DISTANCE_IN_METERS = 0.5
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ fun main(args: Array<String>) {
)
@EnableTransactionManagement
class MapMatchingApplication {

@Bean
fun methodValidationPostProcessor(): MethodValidationPostProcessor {
val mv = MethodValidationPostProcessor()
Expand All @@ -50,14 +49,16 @@ class MapMatchingApplication {

return ObjectMapper()
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
.registerModule(KotlinModule.Builder()
.withReflectionCacheSize(512)
.configure(KotlinFeature.NullToEmptyCollection, false)
.configure(KotlinFeature.NullToEmptyMap, false)
.configure(KotlinFeature.NullIsSameAsDefault, false)
.configure(KotlinFeature.SingletonSupport, false)
.configure(KotlinFeature.StrictNullChecks, true)
.build())
.registerModule(
KotlinModule.Builder()
.withReflectionCacheSize(512)
.configure(KotlinFeature.NullToEmptyCollection, false)
.configure(KotlinFeature.NullToEmptyMap, false)
.configure(KotlinFeature.NullIsSameAsDefault, false)
.configure(KotlinFeature.SingletonSupport, false)
.configure(KotlinFeature.StrictNullChecks, true)
.build()
)
.registerModule(geolatteModule)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ private val LOGGER = KotlinLogging.logger {}
class MapMatchingController
@Autowired
constructor(
val matchingService: IMatchingService,
val matchingService: IMatchingService
) {
@PostMapping(
"/$TRANSPORTATION_MODE_PARAM",
"/$TRANSPORTATION_MODE_PARAM.json",
"/$TRANSPORTATION_MODE_PARAM.json"
)
fun findMatchForPublicTransportRoute(
@PathVariable transportationMode: String,
@Valid @RequestBody request: PublicTransportRouteMatchRequestDTO,
@Valid @RequestBody request: PublicTransportRouteMatchRequestDTO
): RoutingResponse {
LOGGER.debug { "Given transportation mode: $transportationMode" }

Expand All @@ -46,12 +46,12 @@ class MapMatchingController

@PostMapping(
"/$TRANSPORTATION_MODE_PARAM/$VEHICLE_TYPE_PARAM",
"/$TRANSPORTATION_MODE_PARAM/$VEHICLE_TYPE_PARAM.json",
"/$TRANSPORTATION_MODE_PARAM/$VEHICLE_TYPE_PARAM.json"
)
fun findMatchForPublicTransportRoute(
@PathVariable transportationMode: String,
@PathVariable vehicleTypeParam: String,
@Valid @RequestBody request: PublicTransportRouteMatchRequestDTO,
@Valid @RequestBody request: PublicTransportRouteMatchRequestDTO
): RoutingResponse {
LOGGER.debug { "Given profile: $transportationMode/$vehicleTypeParam" }

Expand All @@ -64,7 +64,7 @@ class MapMatchingController

private fun findMatch(
request: PublicTransportRouteMatchRequestDTO,
vehicleType: VehicleType,
vehicleType: VehicleType
): RoutingResponse {
LOGGER.debug { "Given route geometry: ${request.routeGeometry}" }
LOGGER.debug {
Expand All @@ -81,7 +81,7 @@ class MapMatchingController
request.routeGeometry,
request.routePoints,
vehicleType,
getMatchingParameters(request),
getMatchingParameters(request)
)
} catch (ex: Exception) {
RoutingResponse.invalidUrl(ex.message ?: "Map-matching failed")
Expand All @@ -104,7 +104,7 @@ class MapMatchingController
private const val DEFAULT_JUNCTION_NODE_CLEARING_DISTANCE: Double = 30.0

fun getMatchingParameters(
request: PublicTransportRouteMatchRequestDTO,
request: PublicTransportRouteMatchRequestDTO
): PublicTransportRouteMatchingParameters {
val parameters: MapMatchingParametersDTO? = request.matchingParameters

Expand Down Expand Up @@ -136,7 +136,7 @@ class MapMatchingController
terminusLinkQueryLimit,
maxStopLocationDeviation,
fallbackToViaNodesAlgorithm,
roadJunctionMatchingParameters,
roadJunctionMatchingParameters
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ import jakarta.validation.Valid
data class PublicTransportRouteFindRequestDTO(
@field:Valid val routePoints: List<LatLng>,
val linkSearchRadius: Int?,
val simplifyClosedLoopTraversals: Boolean?,
val simplifyClosedLoopTraversals: Boolean?
)
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ data class PublicTransportRouteMatchRequestDTO(
@field:Pattern(regexp = "[\\w\\d-_ ]{1,50}") val routeId: String?,
val routeGeometry: LineString<G2D>,
@field:Valid val routePoints: List<RoutePoint>,
@field:Valid val matchingParameters: MapMatchingParametersDTO?,
@field:Valid val matchingParameters: MapMatchingParametersDTO?
) {
/**
* Contains parameters that can be adjusted for the purpose of getting
Expand Down Expand Up @@ -79,7 +79,7 @@ data class PublicTransportRouteMatchRequestDTO(
val roadJunctionMatchingEnabled: Boolean?,
val junctionNodeMatchDistance: Double?,
val junctionNodeClearingDistance: Double?,
val fallbackToViaNodesAlgorithm: Boolean?,
val fallbackToViaNodesAlgorithm: Boolean?
) {
private val isRoadJunctionMatchingEnabled: Boolean
get() = roadJunctionMatchingEnabled != false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ import jakarta.validation.constraints.Pattern
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.MediaType
import org.springframework.validation.annotation.Validated
import org.springframework.web.bind.annotation.*
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController

private val LOGGER = KotlinLogging.logger {}

Expand All @@ -24,18 +30,18 @@ private val LOGGER = KotlinLogging.logger {}
class RouteController
@Autowired
constructor(
val routingService: IRoutingService,
val routingService: IRoutingService
) {
@Deprecated("GET request should be replaced with POST")
@GetMapping(
"/$TRANSPORTATION_MODE_PARAM/{coords}",
"/$TRANSPORTATION_MODE_PARAM/{coords}.json",
"/$TRANSPORTATION_MODE_PARAM/{coords}.json"
)
fun findRoute(
@PathVariable transportationMode: String,
@Pattern(regexp = ParameterUtils.COORDINATE_LIST) @PathVariable coords: String,
@RequestParam(required = false) linkSearchRadius: Int?,
@RequestParam(required = false) simplifyClosedLoopTraversals: Boolean?,
@RequestParam(required = false) simplifyClosedLoopTraversals: Boolean?
): RoutingResponse {
LOGGER.debug { "Given transportation mode: $transportationMode" }
LOGGER.debug { "Given coordinate sequence: $coords" }
Expand All @@ -50,7 +56,7 @@ class RouteController
@PostMapping("/$TRANSPORTATION_MODE_PARAM", consumes = [MediaType.APPLICATION_JSON_VALUE])
fun findRoute(
@PathVariable transportationMode: String,
@Valid @RequestBody request: PublicTransportRouteFindRequestDTO,
@Valid @RequestBody request: PublicTransportRouteFindRequestDTO
): RoutingResponse {
LOGGER.debug { "Given transportation mode: $transportationMode" }
LOGGER.debug { "Given coordinate points: ${request.routePoints}" }
Expand All @@ -63,21 +69,21 @@ class RouteController
request.routePoints,
vehicleType,
request.linkSearchRadius,
request.simplifyClosedLoopTraversals,
request.simplifyClosedLoopTraversals
)
}

@Deprecated("GET request should be replaced with POST")
@GetMapping(
"/$TRANSPORTATION_MODE_PARAM/$VEHICLE_TYPE_PARAM/{coords}",
"/$TRANSPORTATION_MODE_PARAM/$VEHICLE_TYPE_PARAM/{coords}.json",
"/$TRANSPORTATION_MODE_PARAM/$VEHICLE_TYPE_PARAM/{coords}.json"
)
fun findRoute(
@PathVariable transportationMode: String,
@PathVariable vehicleTypeParam: String,
@Pattern(regexp = ParameterUtils.COORDINATE_LIST) @PathVariable coords: String,
@RequestParam(required = false) linkSearchRadius: Int?,
@RequestParam(required = false) simplifyClosedLoopTraversals: Boolean?,
@RequestParam(required = false) simplifyClosedLoopTraversals: Boolean?
): RoutingResponse {
LOGGER.debug { "Given profile: $transportationMode/$vehicleTypeParam" }
LOGGER.debug { "Given coordinate sequence: $coords" }
Expand All @@ -93,7 +99,7 @@ class RouteController
fun findRoute(
@PathVariable transportationMode: String,
@PathVariable vehicleTypeParam: String,
@Valid @RequestBody request: PublicTransportRouteFindRequestDTO,
@Valid @RequestBody request: PublicTransportRouteFindRequestDTO
): RoutingResponse {
LOGGER.debug { "Given profile: $transportationMode/$vehicleTypeParam" }
LOGGER.debug { "Given coordinate points: ${request.routePoints}" }
Expand All @@ -106,15 +112,15 @@ class RouteController
request.routePoints,
vehicleType,
request.linkSearchRadius,
request.simplifyClosedLoopTraversals,
request.simplifyClosedLoopTraversals
)
}

private fun findRouteInternal(
coords: String,
vehicleType: VehicleType,
linkSearchRadius: Int?,
simplifyClosedLoopTraversals: Boolean?,
simplifyClosedLoopTraversals: Boolean?
): RoutingResponse {
val parsedCoordinates: List<LatLng>

Expand All @@ -128,23 +134,23 @@ class RouteController
parsedCoordinates,
vehicleType,
linkSearchRadius,
simplifyClosedLoopTraversals,
simplifyClosedLoopTraversals
)
}

private fun findRouteInternal(
coords: List<LatLng>,
vehicleType: VehicleType,
linkSearchRadius: Int?,
simplifyClosedLoopTraversals: Boolean?,
simplifyClosedLoopTraversals: Boolean?
): RoutingResponse =
routingService.findRoute(
toPoints(coords),
vehicleType,
RoutingExtraParameters(
linkSearchRadius ?: DEFAULT_LINK_SEARCH_RADIUS,
simplifyClosedLoopTraversals ?: DEFAULT_SIMPLIFY_CLOSED_LOOP_TRAVERSALS,
),
simplifyClosedLoopTraversals ?: DEFAULT_SIMPLIFY_CLOSED_LOOP_TRAVERSALS
)
)

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import org.springframework.context.annotation.Configuration
*/
@Configuration
class FlywaySupplementalConfig : FlywayConfigurationCustomizer {

override fun customize(configuration: FluentConfiguration?) {
// Customising `search_path` is required at least by migrations that add PostGIS geometry columns.
configuration?.run {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import org.springframework.web.servlet.resource.PathResourceResolver

@Configuration
class WebConfig : WebMvcConfigurer {

@Development
@Configuration
class DevelopmentWebConfig : WebMvcConfigurer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ class WebSecurityConfig {
HttpMethod.GET,
RouteController.URL_PREFIX + "/**",
"/actuator/health",
"/*", // matches static landing page for examining results from route API
"/*" // matches static landing page for examining results from route API
).permitAll()
.requestMatchers(
HttpMethod.POST,
MapMatchingController.URL_PREFIX + "/**",
RouteController.URL_PREFIX + "/**",
RouteController.URL_PREFIX + "/**"
).permitAll()
.anyRequest()
.denyAll()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import org.springframework.context.annotation.PropertySource
@Configuration
@PropertySource("classpath:db/jooq.properties")
class JOOQConfig {

@Bean
fun settings(): Settings =
SettingsTools.defaultSettings()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,20 @@ import org.geolatte.geom.codec.Wkt
import org.locationtech.jts.io.ParseException

class GeometryConverter(private val geometryType: GeometryType) {

fun from(databaseObject: Any?): Geometry<C2D>? = databaseObject?.let {
try {
val geom: Geometry<C2D> = read(it.toString())
require(geometryType == geom.geometryType) {
"Unsupported geometry type: ${geom.geometryType.camelCased}"
fun from(databaseObject: Any?): Geometry<C2D>? =
databaseObject?.let {
try {
val geom: Geometry<C2D> = read(it.toString())
require(geometryType == geom.geometryType) {
"Unsupported geometry type: ${geom.geometryType.camelCased}"
}
geom
} catch (e: ParseException) {
throw IllegalArgumentException("Failed to parse EWKB string", e)
}
geom
} catch (e: ParseException) {
throw IllegalArgumentException("Failed to parse EWKB string", e)
}
}

companion object {

fun to(geom: Geometry<C2D>?): String? = geom?.let { Wkt.toWkt(geom) }

internal fun read(hex: String): Geometry<C2D> = Wkb.fromWkb(ByteBuffer.from(hex)) as Geometry<C2D>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import java.sql.Types
import java.util.Objects

class LineStringBinding : Binding<Any, LineString<C2D>> {

override fun converter(): Converter<Any, LineString<C2D>> = LineStringConverter.INSTANCE

@Throws(SQLException::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import org.jooq.Converter
* Converts between LineString geometries and PostGIS EWKT/EWKB formats.
*/
class LineStringConverter : Converter<Any, LineString<C2D>> {

override fun from(databaseObject: Any?) = CONVERTER.from(databaseObject) as LineString?

override fun to(userObject: LineString<C2D>): Any? = GeometryConverter.to(userObject)
Expand Down
Loading

0 comments on commit 74e5806

Please sign in to comment.