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

Fix Linter after upgrade #229

Merged
merged 1 commit into from
May 2, 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
15 changes: 8 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ contracts {

includedFiles.set(
listOf(
"v1/*.yaml"
)
"v1/*.yaml",
),
)

ignoredFiles.set(emptyList())
Expand All @@ -143,7 +143,7 @@ contracts {

baseClassMappings.baseClassMapping(
".*\\.v1\\.lookup",
"$namespace.RaylevationControllerV1Base"
"$namespace.RaylevationControllerV1Base",
)
}

Expand Down Expand Up @@ -209,9 +209,10 @@ jib {
mainClass = "com.raynigon.raylevation.RaylevationApplicationKt"
ports = listOf("8080")
user = "1000"
environment = mapOf(
"SPRING_MAIN_BANNER-MODE" to "off"
)
environment =
mapOf(
"SPRING_MAIN_BANNER-MODE" to "off",
)
labels.put("org.opencontainers.image.created", OffsetDateTime.now().toString())
labels.put("org.opencontainers.image.authors", "Raynigon <opensource@raynigon.de>")
labels.put("org.opencontainers.image.url", "https://github.com/raynigon/raylevation/releases/tag/v${project.version}")
Expand All @@ -223,7 +224,7 @@ jib {
labels.put("org.opencontainers.image.title", "Raylevation Server")
labels.put(
"org.opencontainers.image.description",
"The Raylevation Server Docker Image provides the application with all dependencies"
"The Raylevation Server Docker Image provides the application with all dependencies",
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ abstract class AbstractStandaloneMvcTest<T> {
messageConverter.objectMapper = JacksonConfiguration().objectMapper()

// Create Standalone Setup
val standaloneMockMvcBuilder = MockMvcBuilders
.standaloneSetup(controller)
.setControllerAdvice(controllerAdvices)
.setConversionService(conversionService)
.setValidator(SpringValidatorAdapter(validator))
.setMessageConverters(messageConverter)
val standaloneMockMvcBuilder =
MockMvcBuilders
.standaloneSetup(controller)
.setControllerAdvice(controllerAdvices)
.setConversionService(conversionService)
.setValidator(SpringValidatorAdapter(validator))
.setMessageConverters(messageConverter)

RestAssuredMockMvc.standaloneSetup(standaloneMockMvcBuilder)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,23 @@ import io.mockk.mockk
* Base Class for [RaylevationController] Tests
*/
abstract class RaylevationControllerV1Base : AbstractStandaloneMvcTest<RaylevationController>() {

private val service = mockk<RaylevationService>().also { service ->
every { service.lookup(emptyList()) } returns listOf()
every { service.lookup(match { it.size == 3 }) } returns listOf(
LookupResult(GeoPoint(10.0, 10.0), Metre(515)),
LookupResult(GeoPoint(20.0, 20.0), Metre(545)),
LookupResult(GeoPoint(41.161758, -8.583933), Metre(117))
)
every { service.lookup(match { it.size == 4 }) } returns listOf(
LookupResult(GeoPoint(10.0, 10.0), Metre(515)),
LookupResult(GeoPoint(20.0, 20.0), Metre(545)),
LookupResult(GeoPoint(41.161758, -8.583933), Metre(117)),
LookupResult(GeoPoint(85.0, 10.1), Metre(0), "Missing elevation data for (85.0,10.1)")
)
}
private val service =
mockk<RaylevationService>().also { service ->
every { service.lookup(emptyList()) } returns listOf()
every { service.lookup(match { it.size == 3 }) } returns
listOf(
LookupResult(GeoPoint(10.0, 10.0), Metre(515)),
LookupResult(GeoPoint(20.0, 20.0), Metre(545)),
LookupResult(GeoPoint(41.161758, -8.583933), Metre(117)),
)
every { service.lookup(match { it.size == 4 }) } returns
listOf(
LookupResult(GeoPoint(10.0, 10.0), Metre(515)),
LookupResult(GeoPoint(20.0, 20.0), Metre(545)),
LookupResult(GeoPoint(41.161758, -8.583933), Metre(117)),
LookupResult(GeoPoint(85.0, 10.1), Metre(0), "Missing elevation data for (85.0,10.1)"),
)
}

override val controller: RaylevationController = RaylevationController(LocationsParserImpl(), service)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,18 @@ import org.springframework.web.bind.annotation.RestController
@RequestMapping("/api/v1/lookup")
class RaylevationController(
private val parser: LocationsParser,
private val service: RaylevationService
private val service: RaylevationService,
) {

/**
* Elevation request endpoint for query string requests
* @param locationsParam the locations as pipe seperated list of coordinates
* @return A [ElevationResponse] containing the elevation for each given geo point,
* or an error if no elevation data could be found
*/
@GetMapping
fun getElevation(@RequestParam("locations", defaultValue = "") locationsParam: String): ElevationResponse =
fun getElevation(
@RequestParam("locations", defaultValue = "") locationsParam: String,
): ElevationResponse =
parser.parse(locationsParam)
.let(service::lookup)
.map { ElevationResult(it.point, it.elevation, it.error) }
Expand All @@ -47,7 +48,9 @@ class RaylevationController(
* or an error if no elevation data could be found
*/
@PostMapping(consumes = [MediaType.APPLICATION_JSON_VALUE])
fun getElevation(@RequestBody body: ElevationRequest): ElevationResponse =
fun getElevation(
@RequestBody body: ElevationRequest,
): ElevationResponse =
body.locations.let(service::lookup)
.map { ElevationResult(it.point, it.elevation, it.error) }
.let(::ElevationResponse)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import org.springframework.web.bind.annotation.ResponseStatus
@ControllerAdvice(assignableTypes = [RaylevationController::class])
@Order(Ordered.HIGHEST_PRECEDENCE)
class RaylevationControllerAdvisor {

private val logger = LoggerFactory.getLogger(this::class.java)

/**
Expand All @@ -30,7 +29,7 @@ class RaylevationControllerAdvisor {
return ApiError(
HttpStatus.BAD_REQUEST,
"InvalidBody",
"Given request body is not valid"
"Given request body is not valid",
).toResponseEntity()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ import com.raynigon.raylevation.infrastructure.model.GeoPoint
* The JSON document is deserialized into the object structure.
*/
data class ElevationRequest(
val locations: List<GeoPoint>
val locations: List<GeoPoint>,
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import javax.measure.quantity.Length
*/
data class ElevationResponse(
val errors: Boolean,
val results: List<ElevationResult>
val results: List<ElevationResult>,
) {
constructor(results: List<ElevationResult>) : this(results.any { it.error != null }, results)
}
Expand All @@ -30,12 +30,12 @@ data class ElevationResult(
val latitude: Double,
val longitude: Double,
val elevation: Quantity<Length>,
val error: String?
val error: String?,
) {
constructor(point: GeoPoint, elevation: Quantity<Length>, error: String? = null) : this(
point.latitude,
point.longitude,
elevation,
error
error,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import kotlin.system.exitProcess
* or can be started in a setup mode, to fill the raylevation db with data.
*/
interface CliRunner : CommandLineRunner {

/**
* Process the given command line arguments
*
Expand All @@ -34,9 +33,8 @@ interface CliRunner : CommandLineRunner {
*/
@Service
class CliRunnerImpl(
private val srtmService: SRTMService
private val srtmService: SRTMService,
) : CliRunner {

companion object {
const val CLI_CMD_ENV_NAME = "RAYLEVATION_CLI_CMD"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import java.text.ParseException
* ```
*/
interface LocationsParser {

/**
* Parse the query string into [GeoPoint]s.
*
Expand All @@ -31,14 +30,16 @@ interface LocationsParser {
*/
@Service
class LocationsParserImpl : LocationsParser {

override fun parse(input: String): List<GeoPoint> {
if (input.isEmpty()) return emptyList()
return input.split('|')
.map { toGeoPoint(it, input) }
}

private fun toGeoPoint(point: String, totalInput: String): GeoPoint {
private fun toGeoPoint(
point: String,
totalInput: String,
): GeoPoint {
val parts = point.split(",").mapNotNull { it.toDoubleOrNull() }
if (parts.size != 2) {
val index = totalInput.indexOf(point)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import java.nio.file.Files
* in the current context.
*/
interface RaylevationDBFactory {

/**
* Create the [IRaylevationDB] if not existing and return it in a read only state
*/
Expand All @@ -34,9 +33,8 @@ interface RaylevationDBFactory {
class RaylevationDBFactoryImpl(
private val databaseConfig: DatabaseConfig,
private val meterRegistry: MeterRegistry,
private val objectMapper: ObjectMapper
private val objectMapper: ObjectMapper,
) : RaylevationDBFactory {

override fun create(): IRaylevationDB {
// If the Database does not exist yet, we need to create it in locked mode
if (!Files.exists(databaseConfig.path.resolve(RaylevationDB.STATE_FILE_NAME))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ interface RaylevationService {
@EnableConfigurationProperties(DatabaseConfig::class)
class RaylevationServiceImpl(
raylevationDBFactory: RaylevationDBFactory,
private val asyncService: AsyncService
private val asyncService: AsyncService,
) : RaylevationService {

companion object {
const val PARALLEL_LIMIT = 10_000
const val CACHE_REFRESH_INTERVAL = 1_000L
Expand Down
Loading
Loading