From 56a63b276e17412adb5253e9e34d830228a24583 Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Sun, 23 Mar 2025 12:09:34 +0100 Subject: [PATCH] Code cleanup (#87) * refactor: Replace usage of Void with Kotlins Unit * refactor: make ConnectionCheckService a functional interface * refactor: ignore unused exception * refactor: use property access syntax * refactor: use const value for login path --- .../etl/processor/config/AppSecurityConfiguration.kt | 10 ++++++---- .../dnpm/etl/processor/input/MtbFileRestController.kt | 4 ++-- .../etl/processor/monitoring/ConnectionCheckService.kt | 8 ++++---- .../dev/dnpm/etl/processor/output/RestMtbFileSender.kt | 2 +- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/main/kotlin/dev/dnpm/etl/processor/config/AppSecurityConfiguration.kt b/src/main/kotlin/dev/dnpm/etl/processor/config/AppSecurityConfiguration.kt index 6b063bd..ddcf202 100644 --- a/src/main/kotlin/dev/dnpm/etl/processor/config/AppSecurityConfiguration.kt +++ b/src/main/kotlin/dev/dnpm/etl/processor/config/AppSecurityConfiguration.kt @@ -44,6 +44,8 @@ import org.springframework.security.web.SecurityFilterChain import java.util.* +private const val LOGIN_PATH = "/login" + @Configuration @EnableConfigurationProperties( value = [ @@ -104,15 +106,15 @@ class AppSecurityConfiguration( realmName = "ETL-Processor" } formLogin { - loginPage = "/login" + loginPage = LOGIN_PATH } oauth2Login { - loginPage = "/login" + loginPage = LOGIN_PATH } sessionManagement { sessionConcurrency { maximumSessions = 1 - expiredUrl = "/login?expired" + expiredUrl = "$LOGIN_PATH?expired" } sessionFixation { newSession() @@ -155,7 +157,7 @@ class AppSecurityConfiguration( realmName = "ETL-Processor" } formLogin { - loginPage = "/login" + loginPage = LOGIN_PATH } csrf { disable() } } diff --git a/src/main/kotlin/dev/dnpm/etl/processor/input/MtbFileRestController.kt b/src/main/kotlin/dev/dnpm/etl/processor/input/MtbFileRestController.kt index 9e282c2..ded485c 100644 --- a/src/main/kotlin/dev/dnpm/etl/processor/input/MtbFileRestController.kt +++ b/src/main/kotlin/dev/dnpm/etl/processor/input/MtbFileRestController.kt @@ -41,7 +41,7 @@ class MtbFileRestController( } @PostMapping - fun mtbFile(@RequestBody mtbFile: MtbFile): ResponseEntity { + fun mtbFile(@RequestBody mtbFile: MtbFile): ResponseEntity { if (mtbFile.consent.status == Consent.Status.ACTIVE) { logger.debug("Accepted MTB File for processing") requestProcessor.processMtbFile(mtbFile) @@ -54,7 +54,7 @@ class MtbFileRestController( } @DeleteMapping(path = ["{patientId}"]) - fun deleteData(@PathVariable patientId: String): ResponseEntity { + fun deleteData(@PathVariable patientId: String): ResponseEntity { logger.debug("Accepted patient ID to process deletion") requestProcessor.processDeletion(PatientId(patientId)) return ResponseEntity.accepted().build() diff --git a/src/main/kotlin/dev/dnpm/etl/processor/monitoring/ConnectionCheckService.kt b/src/main/kotlin/dev/dnpm/etl/processor/monitoring/ConnectionCheckService.kt index 9d96654..b845e21 100644 --- a/src/main/kotlin/dev/dnpm/etl/processor/monitoring/ConnectionCheckService.kt +++ b/src/main/kotlin/dev/dnpm/etl/processor/monitoring/ConnectionCheckService.kt @@ -35,7 +35,7 @@ import java.time.Instant import kotlin.time.Duration.Companion.seconds import kotlin.time.toJavaDuration -interface ConnectionCheckService { +fun interface ConnectionCheckService { fun connectionAvailable(): ConnectionCheckResult @@ -88,7 +88,7 @@ class KafkaConnectionCheckService( Instant.now(), if (result.available == available) { result.lastChange } else { Instant.now() } ) - } catch (e: TimeoutException) { + } catch (_: TimeoutException) { ConnectionCheckResult.KafkaConnectionCheckResult( false, Instant.now(), @@ -138,7 +138,7 @@ class RestConnectionCheckService( Instant.now(), if (result.available == available) { result.lastChange } else { Instant.now() } ) - } catch (e: Exception) { + } catch (_: Exception) { ConnectionCheckResult.RestConnectionCheckResult( false, Instant.now(), @@ -191,7 +191,7 @@ class GPasConnectionCheckService( Instant.now(), if (result.available == available) { result.lastChange } else { Instant.now() } ) - } catch (e: Exception) { + } catch (_: Exception) { ConnectionCheckResult.GPasConnectionCheckResult( false, Instant.now(), diff --git a/src/main/kotlin/dev/dnpm/etl/processor/output/RestMtbFileSender.kt b/src/main/kotlin/dev/dnpm/etl/processor/output/RestMtbFileSender.kt index 5ea42e3..016981c 100644 --- a/src/main/kotlin/dev/dnpm/etl/processor/output/RestMtbFileSender.kt +++ b/src/main/kotlin/dev/dnpm/etl/processor/output/RestMtbFileSender.kt @@ -103,7 +103,7 @@ abstract class RestMtbFileSender( val username = restTargetProperties.username val password = restTargetProperties.password val headers = HttpHeaders() - headers.setContentType(MediaType.APPLICATION_JSON) + headers.contentType = MediaType.APPLICATION_JSON if (username.isNullOrBlank() || password.isNullOrBlank()) { return headers