Skip to content

Commit

Permalink
Hardcode version 1.5.0 of ktlint and format
Browse files Browse the repository at this point in the history
This is to prevent the error with the default version JLLeitschuh/ktlint-gradle#809
  • Loading branch information
ben-madley-mt committed Jan 15, 2025
1 parent 6a4a8fc commit 9221440
Show file tree
Hide file tree
Showing 121 changed files with 3,901 additions and 3,129 deletions.
5 changes: 5 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,8 @@ tasks {
testlogger {
theme = com.adarshr.gradle.testlogger.theme.ThemeType.MOCHA
}

// this is to address JLLeitschuh/ktlint-gradle#809
ktlint {
version = "1.5.0"
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ class OpenAPIConfig {
"developerMessage" to Schema<String>().type("string").example("No query parameters specified."),
),
),
)
.addSchemas(
).addSchemas(
"PersonNotFound",
Schema<ErrorResponse>().description("Failed to find a person with the provided HMPPS ID.").properties(
mapOf(
Expand All @@ -69,8 +68,7 @@ class OpenAPIConfig {
"developerMessage" to Schema<String>().type("string").example("Could not find person with HMPPS id: 2003/0011991D."),
),
),
)
.addSchemas(
).addSchemas(
"InternalServerError",
Schema<ErrorResponse>().description("An upstream service was not responding, so we cannot verify the accuracy of any data we did get.").properties(
mapOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import java.util.stream.Collectors

// Intercepts incoming requests and logs them
@Component
class RequestLogger() : HandlerInterceptor {
class RequestLogger : HandlerInterceptor {
private val log: org.slf4j.Logger = LoggerFactory.getLogger(this::class.java)

override fun preHandle(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ import org.springframework.context.annotation.Configuration
@Configuration
class TomcatConfig {
@Bean
fun tomcatCustomizer(): WebServerFactoryCustomizer<TomcatServletWebServerFactory> {
return WebServerFactoryCustomizer { factory: TomcatServletWebServerFactory ->
fun tomcatCustomizer(): WebServerFactoryCustomizer<TomcatServletWebServerFactory> =
WebServerFactoryCustomizer { factory: TomcatServletWebServerFactory ->
factory.addConnectorCustomizers(
TomcatConnectorCustomizer { connector: Connector ->
connector.encodedSolidusHandling = EncodedSolidusHandling.PASS_THROUGH.value
},
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import org.springframework.web.servlet.config.annotation.InterceptorRegistry
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer

@Configuration
class ClientTrackingConfiguration(private val clientTrackingInterceptor: ClientTrackingInterceptor) : WebMvcConfigurer {
class ClientTrackingConfiguration(
private val clientTrackingInterceptor: ClientTrackingInterceptor,
) : WebMvcConfigurer {
override fun addInterceptors(registry: InterceptorRegistry) {
registry.addInterceptor(clientTrackingInterceptor).addPathPatterns("/**")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class ImageController(

auditService.createEvent("GET_PERSON_IMAGE", mapOf("imageId" to id.toString()))

return ResponseEntity.ok()
return ResponseEntity
.ok()
.header("content-type", "image/jpeg")
.body(response.data)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ import org.springframework.http.HttpStatus
import org.springframework.web.bind.annotation.ResponseStatus

@ResponseStatus(HttpStatus.FORBIDDEN)
class AuthenticationFailedException(message: String) : RuntimeException(message)
class AuthenticationFailedException(
message: String,
) : RuntimeException(message)
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ package uk.gov.justice.digital.hmpps.hmppsintegrationapi.exception

import java.lang.RuntimeException

class AuthorisationFailedException(message: String) : RuntimeException(message)
class AuthorisationFailedException(
message: String,
) : RuntimeException(message)
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.exception

class EntityNotFoundException(msg: String) : RuntimeException(msg)
class EntityNotFoundException(
msg: String,
) : RuntimeException(msg)
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,23 @@ class WebClientWrapper(
.builder()
.baseUrl(baseUrl)
.exchangeStrategies(
ExchangeStrategies.builder()
ExchangeStrategies
.builder()
.codecs { configurer ->
configurer.defaultCodecs()
configurer
.defaultCodecs()
.maxInMemorySize(-1)
}
.build(),
)
.build()
}.build(),
).build()

sealed class WebClientWrapperResponse<out T> {
data class Success<T>(val data: T) : WebClientWrapperResponse<T>()
data class Success<T>(
val data: T,
) : WebClientWrapperResponse<T>()

data class Error(val errors: List<UpstreamApiError>) : WebClientWrapperResponse<Nothing>()
data class Error(
val errors: List<UpstreamApiError>,
) : WebClientWrapperResponse<Nothing>()
}

inline fun <reified T> request(
Expand All @@ -40,18 +44,18 @@ class WebClientWrapper(
upstreamApi: UpstreamApi,
requestBody: Map<String, Any?>? = null,
forbiddenAsError: Boolean = false,
): WebClientWrapperResponse<T> {
return try {
): WebClientWrapperResponse<T> =
try {
val responseData =
getResponseBodySpec(method, uri, headers, requestBody).retrieve()
getResponseBodySpec(method, uri, headers, requestBody)
.retrieve()
.bodyToMono(T::class.java)
.block()!!

WebClientWrapperResponse.Success(responseData)
} catch (exception: WebClientResponseException) {
getErrorType(exception, upstreamApi, forbiddenAsError)
}
}

inline fun <reified T> requestList(
method: HttpMethod,
Expand All @@ -60,10 +64,11 @@ class WebClientWrapper(
upstreamApi: UpstreamApi,
requestBody: Map<String, Any?>? = null,
forbiddenAsError: Boolean = false,
): WebClientWrapperResponse<List<T>> {
return try {
): WebClientWrapperResponse<List<T>> =
try {
val responseData =
getResponseBodySpec(method, uri, headers, requestBody).retrieve()
getResponseBodySpec(method, uri, headers, requestBody)
.retrieve()
.bodyToFlux(T::class.java)
.collectList()
.block() as List<T>
Expand All @@ -72,7 +77,6 @@ class WebClientWrapper(
} catch (exception: WebClientResponseException) {
getErrorType(exception, upstreamApi, forbiddenAsError)
}
}

fun getResponseBodySpec(
method: HttpMethod,
Expand All @@ -81,7 +85,8 @@ class WebClientWrapper(
requestBody: Map<String, Any?>? = null,
): WebClient.RequestBodySpec {
val responseBodySpec =
client.method(method)
client
.method(method)
.uri(uri)
.headers { header -> headers.forEach { requestHeader -> header.set(requestHeader.key, requestHeader.value) } }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,11 @@ class NomisGateway(

return when (result) {
is WebClientWrapperResponse.Success -> {
Response(data = result.data.latestPrisonTerm.sentenceAdjustments.toSentenceAdjustment())
Response(
data =
result.data.latestPrisonTerm.sentenceAdjustments
.toSentenceAdjustment(),
)
}

is WebClientWrapperResponse.Error -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ class ProbationOffenderSearchGateway(
"pncNumber" to pncNumber,
"dateOfBirth" to dateOfBirth,
"includeAliases" to searchWithinAliases,
)
.filterValues { it != null }
).filterValues { it != null }

val result =
webClient.requestList<Offender>(
Expand Down Expand Up @@ -131,7 +130,14 @@ class ProbationOffenderSearchGateway(

return when (result) {
is WebClientWrapperResponse.Success -> {
return Response(result.data.firstOrNull()?.contactDetails?.addresses.orEmpty().map { it.toAddress() })
return Response(
result.data
.firstOrNull()
?.contactDetails
?.addresses
.orEmpty()
.map { it.toAddress() },
)
}
is WebClientWrapperResponse.Error -> {
Response(
Expand All @@ -150,11 +156,7 @@ class ProbationOffenderSearchGateway(
)
}

private fun isPncNumber(id: String?): Boolean {
return id?.matches(Regex("^[0-9]+/[0-9A-Za-z]+$")) == true
}
private fun isPncNumber(id: String?): Boolean = id?.matches(Regex("^[0-9]+/[0-9A-Za-z]+$")) == true

private fun isNomsNumber(id: String?): Boolean {
return id?.matches(Regex("^[A-Z]\\d{4}[A-Z]{2}+$")) == true
}
private fun isNomsNumber(id: String?): Boolean = id?.matches(Regex("^[A-Z]\\d{4}[A-Z]{2}+$")) == true
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import java.net.http.HttpClient
import java.net.http.HttpRequest
import java.net.http.HttpResponse

open class ExternalHealthIndicator(url: String) : HealthIndicator {
open class ExternalHealthIndicator(
url: String,
) : HealthIndicator {
private val healthUrl = url
private val log = LoggerFactory.getLogger(this::class.java)

Expand All @@ -17,12 +19,14 @@ open class ExternalHealthIndicator(url: String) : HealthIndicator {
// that specific component.
override fun health(): Health {
val healthStatus: Health.Builder =
Health.up()
Health
.up()
.withDetail("healthurl", healthUrl)

val client = HttpClient.newBuilder().build()
val request =
HttpRequest.newBuilder()
HttpRequest
.newBuilder()
.uri(URI.create(healthUrl))
.build()

Expand All @@ -31,14 +35,16 @@ open class ExternalHealthIndicator(url: String) : HealthIndicator {
client.send(request, HttpResponse.BodyHandlers.ofString())
} catch (e: Exception) {
log.error("Failed to connect to health endpoint $healthUrl are these services running?")
return healthStatus.up()
return healthStatus
.up()
.withDetail("status", "This component is down")
.withException(e)
.build()
}

if (response.statusCode() != 200) {
return healthStatus.up()
return healthStatus
.up()
.withDetail("httpStatusCode", response.statusCode())
.build()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import org.springframework.stereotype.Component
* Adds version data to the /health endpoint. This is called by the UI to display API details
*/
@Component
class HealthInfo(buildProperties: BuildProperties) : HealthIndicator {
class HealthInfo(
buildProperties: BuildProperties,
) : HealthIndicator {
private val version: String = buildProperties.version

override fun health(): Health = Health.up().withDetail("version", version).build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import org.springframework.context.annotation.Configuration
import org.springframework.context.event.EventListener

@Configuration
class VersionOutputter(buildProperties: BuildProperties) {
class VersionOutputter(
buildProperties: BuildProperties,
) {
private val version = buildProperties.version

@EventListener(ApplicationReadyEvent::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ data class ArnRiskSummary(
}

private fun toCamelCase(personGroup: String) =
personGroup.split(" ").map { it.replaceFirstChar(Char::uppercaseChar) }.joinToString("")
personGroup
.split(" ")
.map { it.replaceFirstChar(Char::uppercaseChar) }
.joinToString("")
.replaceFirstChar(Char::lowercaseChar)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ data class CrnRiskManagementPlans(
val limitedAccessOffender: String,
val riskManagementPlan: List<CrnRiskManagementPlan>,
) {
fun toRiskManagementPlans(): List<RiskManagementPlan> {
return this.riskManagementPlan.stream()
fun toRiskManagementPlans(): List<RiskManagementPlan> =
this.riskManagementPlan
.stream()
.map {
RiskManagementPlan(
assessmentId = it.assessmentId,
Expand All @@ -27,9 +28,7 @@ data class CrnRiskManagementPlans(
latestCompleteDate = it.latestCompleteDate,
latestSignLockDate = it.latestSignLockDate,
)
}
.collect(Collectors.toList())
}
}.collect(Collectors.toList())
}

data class CrnRiskManagementPlan(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps

import java.util.Base64

data class Credentials(val username: String, val password: String) {
data class Credentials(
val username: String,
val password: String,
) {
fun toBasicAuth(): String {
val encodedCredentials = Base64.getEncoder().encodeToString("$username:$password".toByteArray())
return "Basic $encodedCredentials"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ data class KeyDatesAndAdjustmentsDTO(
val adjustments: SentenceAdjustment? = null,
val keyDates: SentenceKeyDates? = null,
) {
fun toLatestSentenceKeyDatesAndAdjustments(): LatestSentenceKeyDatesAndAdjustments {
return LatestSentenceKeyDatesAndAdjustments(
fun toLatestSentenceKeyDatesAndAdjustments(): LatestSentenceKeyDatesAndAdjustments =
LatestSentenceKeyDatesAndAdjustments(
adjustments = this.adjustments,
automaticRelease = this.keyDates?.automaticRelease,
conditionalRelease = this.keyDates?.conditionalRelease,
Expand All @@ -60,5 +60,4 @@ data class KeyDatesAndAdjustmentsDTO(
tariffDate = this.keyDates?.tariffDate,
tariffEarlyRemovalSchemeEligibilityDate = this.keyDates?.tariffEarlyRemovalSchemeEligibilityDate,
)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps

data class Response<T>(val data: T, val errors: List<UpstreamApiError> = emptyList()) {
data class Response<T>(
val data: T,
val errors: List<UpstreamApiError> = emptyList(),
) {
companion object {
fun <T> merge(responses: List<Response<List<T>>>): Response<List<T>> = Response(data = responses.flatMap { it.data }, errors = responses.flatMap { it.errors })
}
Expand All @@ -13,4 +16,6 @@ data class Response<T>(val data: T, val errors: List<UpstreamApiError> = emptyLi
): Boolean = this.errors.any { it.type == type && it.causedBy == causedBy }
}

data class DataResponse<T>(val data: T)
data class DataResponse<T>(
val data: T,
)
Loading

0 comments on commit 9221440

Please sign in to comment.