From d2037c8ad1f91ed073e3a88d50e18c571ce11655 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 5 Apr 2024 20:16:05 +0000 Subject: [PATCH 1/2] Bump io.swagger.parser.v3:swagger-parser-v3 from 2.1.21 to 2.1.22 Bumps io.swagger.parser.v3:swagger-parser-v3 from 2.1.21 to 2.1.22. --- updated-dependencies: - dependency-name: io.swagger.parser.v3:swagger-parser-v3 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 46b47eb4..8cbd6f17 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -38,7 +38,7 @@ dependencies { testImplementation("io.rest-assured:json-path") testImplementation("io.rest-assured:xml-path") testImplementation("io.rest-assured:spring-mock-mvc") - testImplementation("io.swagger.parser.v3:swagger-parser-v3:2.1.21") + testImplementation("io.swagger.parser.v3:swagger-parser-v3:2.1.22") } java { From 502d3a20c1006f706ac7e36b3cc9839ab429212a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 5 Apr 2024 20:17:10 +0000 Subject: [PATCH 2/2] Formatting changes --- .../controllers/OffenderSearchController.kt | 114 +++++++++++++++--- .../controllers/advice/ErrorResponse.kt | 12 +- .../hmpps/probationsearch/dto/MatchRequest.kt | 15 ++- .../probationsearch/dto/OffenderDetail.kt | 5 +- .../hmpps/probationsearch/dto/SearchDto.kt | 4 +- .../probationsearch/dto/SearchPhraseFilter.kt | 11 +- .../justice/hmpps/probationsearch/dto/Team.kt | 6 +- .../probationsearch/health/HealthCheck.kt | 11 +- .../security/AuthAwareTokenConverter.kt | 3 +- .../probationsearch/services/SearchClient.kt | 3 +- .../services/TermHighlighter.kt | 5 +- .../controllers/ElasticIntegrationBase.kt | 10 +- .../OffenderSearchPhraseAPIIntegrationTest.kt | 8 +- .../ProbationStatusIntegrationTest.kt | 3 +- .../probationsearch/dto/OffenderDetailTest.kt | 8 +- .../services/HighlightingTest.kt | 6 +- .../services/MatchServiceTest.kt | 3 +- .../services/OffenderAccessServiceTest.kt | 35 +++++- .../services/PhraseParserKtTest.kt | 3 +- .../ProbationAreaFilterAggregatorKtTest.kt | 34 +++++- .../util/PersonSearchHelper.kt | 11 +- 21 files changed, 253 insertions(+), 57 deletions(-) diff --git a/src/main/kotlin/uk/gov/justice/hmpps/probationsearch/controllers/OffenderSearchController.kt b/src/main/kotlin/uk/gov/justice/hmpps/probationsearch/controllers/OffenderSearchController.kt index f419aba6..1947b186 100644 --- a/src/main/kotlin/uk/gov/justice/hmpps/probationsearch/controllers/OffenderSearchController.kt +++ b/src/main/kotlin/uk/gov/justice/hmpps/probationsearch/controllers/OffenderSearchController.kt @@ -81,7 +81,8 @@ class OffenderSearchController( ) @PreAuthorize("hasAnyRole('ROLE_COMMUNITY', 'ROLE_PROBATION__SEARCH_PERSON')") @RequestMapping("/search", method = [POST, GET]) - fun searchOffenders(@RequestBody searchForm: SearchDto): List? = searchService.performSearch(searchForm) + fun searchOffenders(@RequestBody searchForm: SearchDto): List? = + searchService.performSearch(searchForm) @Operation( summary = "Search for an offender in Delius using a search phrase. Only offenders matching all request attributes will be returned", @@ -123,8 +124,16 @@ class OffenderSearchController( @ApiResponses( value = [ ApiResponse(responseCode = "200", description = "OK"), - ApiResponse(responseCode = "401", description = "Unauthorised, requires a valid Oauth2 token", content = [Content(examples = [])]), - ApiResponse(responseCode = "403", description = "Forbidden, requires an authorisation with role ROLE_PROBATION__SEARCH_PERSON", content = [Content(examples = [])]), + ApiResponse( + responseCode = "401", + description = "Unauthorised, requires a valid Oauth2 token", + content = [Content(examples = [])] + ), + ApiResponse( + responseCode = "403", + description = "Forbidden, requires an authorisation with role ROLE_PROBATION__SEARCH_PERSON", + content = [Content(examples = [])] + ), ], ) @PostMapping("/phrase") @@ -143,9 +152,21 @@ class OffenderSearchController( @ApiResponses( value = [ ApiResponse(responseCode = "200", description = "OK"), - ApiResponse(responseCode = "401", description = "Unauthorised, requires a valid Oauth2 token", content = [Content(examples = [])]), - ApiResponse(responseCode = "403", description = "Forbidden, requires an authorisation with role ROLE_PROBATION__SEARCH_PERSON", content = [Content(examples = [])]), - ApiResponse(responseCode = "500", description = "The list of CRNs provided exceeds the maximum of 512", content = [Content(examples = [])]), + ApiResponse( + responseCode = "401", + description = "Unauthorised, requires a valid Oauth2 token", + content = [Content(examples = [])] + ), + ApiResponse( + responseCode = "403", + description = "Forbidden, requires an authorisation with role ROLE_PROBATION__SEARCH_PERSON", + content = [Content(examples = [])] + ), + ApiResponse( + responseCode = "500", + description = "The list of CRNs provided exceeds the maximum of 512", + content = [Content(examples = [])] + ), ], ) @PostMapping("/crns") @@ -169,12 +190,23 @@ class OffenderSearchController( @ApiResponses( value = [ ApiResponse(responseCode = "200", description = "OK"), - ApiResponse(responseCode = "401", description = "Unauthorised, requires a valid Oauth2 token", content = [Content(examples = [])]), - ApiResponse(responseCode = "403", description = "Forbidden, requires an authorisation with role ROLE_PROBATION__SEARCH_PERSON", content = [Content(examples = [])]), + ApiResponse( + responseCode = "401", + description = "Unauthorised, requires a valid Oauth2 token", + content = [Content(examples = [])] + ), + ApiResponse( + responseCode = "403", + description = "Forbidden, requires an authorisation with role ROLE_PROBATION__SEARCH_PERSON", + content = [Content(examples = [])] + ), ], ) @PostMapping("/nomsNumbers") - @Operation(description = "Match prisoners by a list of prisoner noms numbers", summary = "Requires ROLE_PROBATION__SEARCH_PERSON role") + @Operation( + description = "Match prisoners by a list of prisoner noms numbers", + summary = "Requires ROLE_PROBATION__SEARCH_PERSON role" + ) fun findByNomsNumbers( @Parameter(required = true, name = "nomsList") @RequestBody nomsList: List, ): List { @@ -185,8 +217,16 @@ class OffenderSearchController( @ApiResponses( value = [ ApiResponse(responseCode = "200", description = "OK"), - ApiResponse(responseCode = "401", description = "Unauthorised, requires a valid Oauth2 token", content = [Content(examples = [])]), - ApiResponse(responseCode = "403", description = "Forbidden, requires an authorisation with role ROLE_PROBATION__SEARCH_PERSON", content = [Content(examples = [])]), + ApiResponse( + responseCode = "401", + description = "Unauthorised, requires a valid Oauth2 token", + content = [Content(examples = [])] + ), + ApiResponse( + responseCode = "403", + description = "Forbidden, requires an authorisation with role ROLE_PROBATION__SEARCH_PERSON", + content = [Content(examples = [])] + ), ], ) @PostMapping("/ldu-codes") @@ -202,7 +242,10 @@ class OffenderSearchController( example = "10", ), ) - @Operation(summary = "Match prisoners by a list of ldu codes", description = "Requires ROLE_PROBATION__SEARCH_PERSON role") + @Operation( + summary = "Match prisoners by a list of ldu codes", + description = "Requires ROLE_PROBATION__SEARCH_PERSON role" + ) fun findByLduCode( @Parameter(required = true, name = "lduList") @RequestBody @@ -218,8 +261,16 @@ class OffenderSearchController( @ApiResponses( value = [ ApiResponse(responseCode = "200", description = "OK"), - ApiResponse(responseCode = "401", description = "Unauthorised, requires a valid Oauth2 token", content = [Content(examples = [])]), - ApiResponse(responseCode = "403", description = "Forbidden, requires an authorisation with role ROLE_PROBATION__SEARCH_PERSON", content = [Content(examples = [])]), + ApiResponse( + responseCode = "401", + description = "Unauthorised, requires a valid Oauth2 token", + content = [Content(examples = [])] + ), + ApiResponse( + responseCode = "403", + description = "Forbidden, requires an authorisation with role ROLE_PROBATION__SEARCH_PERSON", + content = [Content(examples = [])] + ), ], ) @PostMapping("/team-codes") @@ -235,7 +286,10 @@ class OffenderSearchController( example = "10", ), ) - @Operation(description = "Match prisoners by a list of team codes", summary = "Requires ROLE_PROBATION__SEARCH_PERSON role") + @Operation( + description = "Match prisoners by a list of team codes", + summary = "Requires ROLE_PROBATION__SEARCH_PERSON role" + ) fun findByTeamCode( @Parameter(required = true, name = "teamCodeList") @ParameterObject @@ -261,8 +315,16 @@ class OffenderSearchController( content = [Content(examples = [])], ), ApiResponse(responseCode = "404", description = "Not found", content = [Content(examples = [])]), - ApiResponse(responseCode = "401", description = "Unauthorised, requires a valid Oauth2 token", content = [Content(examples = [])]), - ApiResponse(responseCode = "403", description = "Forbidden, requires an authorisation with role ROLE_PROBATION__SEARCH_PERSON", content = [Content(examples = [])]), + ApiResponse( + responseCode = "401", + description = "Unauthorised, requires a valid Oauth2 token", + content = [Content(examples = [])] + ), + ApiResponse( + responseCode = "403", + description = "Forbidden, requires an authorisation with role ROLE_PROBATION__SEARCH_PERSON", + content = [Content(examples = [])] + ), ], ) @GetMapping("/ldu-codes/{lduCode}") @@ -286,8 +348,16 @@ class OffenderSearchController( content = [Content(examples = [])], ), ApiResponse(responseCode = "404", description = "Not found", content = [Content(examples = [])]), - ApiResponse(responseCode = "401", description = "Unauthorised, requires a valid Oauth2 token", content = [Content(examples = [])]), - ApiResponse(responseCode = "403", description = "Forbidden, requires an authorisation with role ROLE_PROBATION__SEARCH_PERSON", content = [Content(examples = [])]), + ApiResponse( + responseCode = "401", + description = "Unauthorised, requires a valid Oauth2 token", + content = [Content(examples = [])] + ), + ApiResponse( + responseCode = "403", + description = "Forbidden, requires an authorisation with role ROLE_PROBATION__SEARCH_PERSON", + content = [Content(examples = [])] + ), ], ) @GetMapping("/team-codes/{teamCode}") @@ -302,6 +372,10 @@ class OffenderSearchController( val start = System.currentTimeMillis() val results = searchService.performSearch(SearchDto(surname = "Smith")) - telemetryClient.trackEvent("synthetic-monitor", mapOf("results" to "${results.size}", "timeMs" to (System.currentTimeMillis() - start).toString()), null) + telemetryClient.trackEvent( + "synthetic-monitor", + mapOf("results" to "${results.size}", "timeMs" to (System.currentTimeMillis() - start).toString()), + null + ) } } diff --git a/src/main/kotlin/uk/gov/justice/hmpps/probationsearch/controllers/advice/ErrorResponse.kt b/src/main/kotlin/uk/gov/justice/hmpps/probationsearch/controllers/advice/ErrorResponse.kt index 41f03845..35f76a7a 100644 --- a/src/main/kotlin/uk/gov/justice/hmpps/probationsearch/controllers/advice/ErrorResponse.kt +++ b/src/main/kotlin/uk/gov/justice/hmpps/probationsearch/controllers/advice/ErrorResponse.kt @@ -10,6 +10,14 @@ data class ErrorResponse( @Schema(required = false, description = "Developer Information message", example = "System is down") val developerMessage: String? = null, @Schema(required = true, description = "Internal Error Code", example = "20012") val errorCode: Int? = null, - @Schema(required = true, description = "Error message information", example = "Offender Not Found") val userMessage: String? = null, - @Schema(required = false, description = "Additional information about the error", example = "Hard disk failure") val moreInfo: String? = null, + @Schema( + required = true, + description = "Error message information", + example = "Offender Not Found" + ) val userMessage: String? = null, + @Schema( + required = false, + description = "Additional information about the error", + example = "Hard disk failure" + ) val moreInfo: String? = null, ) diff --git a/src/main/kotlin/uk/gov/justice/hmpps/probationsearch/dto/MatchRequest.kt b/src/main/kotlin/uk/gov/justice/hmpps/probationsearch/dto/MatchRequest.kt index d4fab851..54be14fb 100644 --- a/src/main/kotlin/uk/gov/justice/hmpps/probationsearch/dto/MatchRequest.kt +++ b/src/main/kotlin/uk/gov/justice/hmpps/probationsearch/dto/MatchRequest.kt @@ -13,8 +13,17 @@ data class MatchRequest( @field:Past(message = "Date of birth must be in the past") @Schema(description = "Offender date of birth", example = "1996-02-10") val dateOfBirth: LocalDate? = null, - @Schema(description = "Police National Computer (PNC) number", example = "2018/0123456X") val pncNumber: String? = null, + @Schema( + description = "Police National Computer (PNC) number", + example = "2018/0123456X" + ) val pncNumber: String? = null, @Schema(description = "Criminal Records Office (CRO) number", example = "SF80/655108T") val croNumber: String? = null, - @Schema(description = "The Offender NOMIS Id (aka prison number/offender no in DPS)", example = "G5555TT") val nomsNumber: String? = null, - @Schema(description = "Filter so only offenders on a current sentence managed by probation will be returned", example = "true") val activeSentence: Boolean = false, + @Schema( + description = "The Offender NOMIS Id (aka prison number/offender no in DPS)", + example = "G5555TT" + ) val nomsNumber: String? = null, + @Schema( + description = "Filter so only offenders on a current sentence managed by probation will be returned", + example = "true" + ) val activeSentence: Boolean = false, ) diff --git a/src/main/kotlin/uk/gov/justice/hmpps/probationsearch/dto/OffenderDetail.kt b/src/main/kotlin/uk/gov/justice/hmpps/probationsearch/dto/OffenderDetail.kt index 6d74b94d..121d3ee6 100644 --- a/src/main/kotlin/uk/gov/justice/hmpps/probationsearch/dto/OffenderDetail.kt +++ b/src/main/kotlin/uk/gov/justice/hmpps/probationsearch/dto/OffenderDetail.kt @@ -27,7 +27,10 @@ data class OffenderDetail( val restrictionMessage: String? = null, val currentExclusion: Boolean? = null, val exclusionMessage: String? = null, - @Schema(description = "map of fields which matched a search term (Only return for phrase searching)", example = "{\"surname\": [\"Smith\"], \"offenderAliases.surname\": [\"SMITH\"]}") + @Schema( + description = "map of fields which matched a search term (Only return for phrase searching)", + example = "{\"surname\": [\"Smith\"], \"offenderAliases.surname\": [\"SMITH\"]}" + ) val highlight: Map>? = null, val accessDenied: Boolean? = null, val currentTier: String? = null, diff --git a/src/main/kotlin/uk/gov/justice/hmpps/probationsearch/dto/SearchDto.kt b/src/main/kotlin/uk/gov/justice/hmpps/probationsearch/dto/SearchDto.kt index 5f45970d..ff5aa711 100644 --- a/src/main/kotlin/uk/gov/justice/hmpps/probationsearch/dto/SearchDto.kt +++ b/src/main/kotlin/uk/gov/justice/hmpps/probationsearch/dto/SearchDto.kt @@ -17,6 +17,8 @@ data class SearchDto( ) { @get:Schema(hidden = true) val isValid: Boolean - get() = StringUtils.isNotBlank(firstName) || StringUtils.isNotBlank(surname) || dateOfBirth != null || StringUtils.isNotBlank(pncNumber) || StringUtils.isNotBlank(crn) || + get() = StringUtils.isNotBlank(firstName) || StringUtils.isNotBlank(surname) || dateOfBirth != null || StringUtils.isNotBlank( + pncNumber + ) || StringUtils.isNotBlank(crn) || StringUtils.isNotBlank(nomsNumber) || StringUtils.isNotBlank(croNumber) } diff --git a/src/main/kotlin/uk/gov/justice/hmpps/probationsearch/dto/SearchPhraseFilter.kt b/src/main/kotlin/uk/gov/justice/hmpps/probationsearch/dto/SearchPhraseFilter.kt index 1ef3310c..7603b435 100644 --- a/src/main/kotlin/uk/gov/justice/hmpps/probationsearch/dto/SearchPhraseFilter.kt +++ b/src/main/kotlin/uk/gov/justice/hmpps/probationsearch/dto/SearchPhraseFilter.kt @@ -7,6 +7,13 @@ data class SearchPhraseFilter( @field:NotBlank(message = "phrase must be supplied") @Schema(required = true, description = "Phrase containing the terms to search for", example = "john smith 19/07/1965") val phrase: String = "", - @Schema(required = false, description = "When true, only match offenders that match all terms. Analogous to AND versus OR") val matchAllTerms: Boolean = false, - @Schema(required = false, description = "Filter of probation area codes. Only offenders that have an active offender manager in one of the areas will be returned", example = "[\"N01\",\"N02\"]") val probationAreasFilter: List = listOf(), + @Schema( + required = false, + description = "When true, only match offenders that match all terms. Analogous to AND versus OR" + ) val matchAllTerms: Boolean = false, + @Schema( + required = false, + description = "Filter of probation area codes. Only offenders that have an active offender manager in one of the areas will be returned", + example = "[\"N01\",\"N02\"]" + ) val probationAreasFilter: List = listOf(), ) diff --git a/src/main/kotlin/uk/gov/justice/hmpps/probationsearch/dto/Team.kt b/src/main/kotlin/uk/gov/justice/hmpps/probationsearch/dto/Team.kt index 6f384f73..3f0d8959 100644 --- a/src/main/kotlin/uk/gov/justice/hmpps/probationsearch/dto/Team.kt +++ b/src/main/kotlin/uk/gov/justice/hmpps/probationsearch/dto/Team.kt @@ -5,7 +5,11 @@ import io.swagger.v3.oas.annotations.media.Schema data class Team( @Schema(description = "Team code", example = "C01T04") val code: String? = null, @Schema(description = "Team description", example = "OMU A") val description: String? = null, - @Schema(description = "Team telephone, often not populated", required = false, example = "OMU A") val telephone: String? = null, + @Schema( + description = "Team telephone, often not populated", + required = false, + example = "OMU A" + ) val telephone: String? = null, @Schema(description = "Local Delivery Unit - LDU") val localDeliveryUnit: KeyValue? = null, @Schema(description = "Team's district") val district: KeyValue? = null, @Schema(description = "Team's borough") val borough: KeyValue? = null, diff --git a/src/main/kotlin/uk/gov/justice/hmpps/probationsearch/health/HealthCheck.kt b/src/main/kotlin/uk/gov/justice/hmpps/probationsearch/health/HealthCheck.kt index ad1ba1eb..b98037a0 100644 --- a/src/main/kotlin/uk/gov/justice/hmpps/probationsearch/health/HealthCheck.kt +++ b/src/main/kotlin/uk/gov/justice/hmpps/probationsearch/health/HealthCheck.kt @@ -18,7 +18,11 @@ abstract class HealthCheck(private val webClient: WebClient, private val timeout .retrieve() .toEntity(String::class.java) .flatMap { Mono.just(Health.up().withDetail("HttpStatus", it?.statusCode).build()) } - .onErrorResume(WebClientResponseException::class.java) { Mono.just(Health.down(it).withDetail("body", it.responseBodyAsString).withDetail("HttpStatus", it.statusCode).build()) } + .onErrorResume(WebClientResponseException::class.java) { + Mono.just( + Health.down(it).withDetail("body", it.responseBodyAsString).withDetail("HttpStatus", it.statusCode).build() + ) + } .onErrorResume(Exception::class.java) { Mono.just(Health.down(it).build()) } .block(timeout) } @@ -26,4 +30,7 @@ abstract class HealthCheck(private val webClient: WebClient, private val timeout @Component class CommunityApiHealth -constructor(@Qualifier("communityApiHealthWebClient") webClient: WebClient, @Value("\${api.health-timeout:2s}") timeout: Duration) : HealthCheck(webClient, timeout) +constructor( + @Qualifier("communityApiHealthWebClient") webClient: WebClient, + @Value("\${api.health-timeout:2s}") timeout: Duration +) : HealthCheck(webClient, timeout) diff --git a/src/main/kotlin/uk/gov/justice/hmpps/probationsearch/security/AuthAwareTokenConverter.kt b/src/main/kotlin/uk/gov/justice/hmpps/probationsearch/security/AuthAwareTokenConverter.kt index 33d8b361..6d5d625f 100644 --- a/src/main/kotlin/uk/gov/justice/hmpps/probationsearch/security/AuthAwareTokenConverter.kt +++ b/src/main/kotlin/uk/gov/justice/hmpps/probationsearch/security/AuthAwareTokenConverter.kt @@ -9,7 +9,8 @@ import org.springframework.security.oauth2.server.resource.authentication.JwtAut import org.springframework.security.oauth2.server.resource.authentication.JwtGrantedAuthoritiesConverter class AuthAwareTokenConverter : Converter { - private val jwtGrantedAuthoritiesConverter: Converter> = JwtGrantedAuthoritiesConverter() + private val jwtGrantedAuthoritiesConverter: Converter> = + JwtGrantedAuthoritiesConverter() override fun convert(jwt: Jwt): AbstractAuthenticationToken { return AuthAwareAuthenticationToken( diff --git a/src/main/kotlin/uk/gov/justice/hmpps/probationsearch/services/SearchClient.kt b/src/main/kotlin/uk/gov/justice/hmpps/probationsearch/services/SearchClient.kt index f417322c..46740f60 100644 --- a/src/main/kotlin/uk/gov/justice/hmpps/probationsearch/services/SearchClient.kt +++ b/src/main/kotlin/uk/gov/justice/hmpps/probationsearch/services/SearchClient.kt @@ -11,5 +11,6 @@ import org.springframework.stereotype.Service class SearchClient( @param:Qualifier("openSearchClient") private val openSearchClient: RestHighLevelClient, ) { - fun search(searchRequest: SearchRequest): SearchResponse = openSearchClient.search(searchRequest, RequestOptions.DEFAULT) + fun search(searchRequest: SearchRequest): SearchResponse = + openSearchClient.search(searchRequest, RequestOptions.DEFAULT) } diff --git a/src/main/kotlin/uk/gov/justice/hmpps/probationsearch/services/TermHighlighter.kt b/src/main/kotlin/uk/gov/justice/hmpps/probationsearch/services/TermHighlighter.kt index 923b2d42..5dd34dd4 100644 --- a/src/main/kotlin/uk/gov/justice/hmpps/probationsearch/services/TermHighlighter.kt +++ b/src/main/kotlin/uk/gov/justice/hmpps/probationsearch/services/TermHighlighter.kt @@ -11,7 +11,10 @@ internal fun buildHighlightRequest() = HighlightBuilder() .preTags("") .postTags("") -internal fun OffenderDetail.mergeHighlights(highlightFields: Map, phrase: String): OffenderDetail = +internal fun OffenderDetail.mergeHighlights( + highlightFields: Map, + phrase: String +): OffenderDetail = this.copy(highlight = extractHighlights(highlightFields) + possibleDateOfBirthHighlight(phrase)) private fun OffenderDetail.possibleDateOfBirthHighlight(phrase: String): Map> { diff --git a/src/test/kotlin/uk/gov/justice/hmpps/probationsearch/controllers/ElasticIntegrationBase.kt b/src/test/kotlin/uk/gov/justice/hmpps/probationsearch/controllers/ElasticIntegrationBase.kt index 44603095..7052c0c3 100644 --- a/src/test/kotlin/uk/gov/justice/hmpps/probationsearch/controllers/ElasticIntegrationBase.kt +++ b/src/test/kotlin/uk/gov/justice/hmpps/probationsearch/controllers/ElasticIntegrationBase.kt @@ -93,8 +93,14 @@ abstract class ElasticIntegrationBase { it.offenderManagers.find { replacement -> replacement.active == offenderManager.active } .let { matchingReplacement -> offenderManager.copy( - probationArea = ProbationArea(code = matchingReplacement?.code, description = matchingReplacement?.description), - team = Team(code = matchingReplacement?.team?.code, localDeliveryUnit = matchingReplacement?.team?.localDeliveryUnit), + probationArea = ProbationArea( + code = matchingReplacement?.code, + description = matchingReplacement?.description + ), + team = Team( + code = matchingReplacement?.team?.code, + localDeliveryUnit = matchingReplacement?.team?.localDeliveryUnit + ), softDeleted = matchingReplacement?.softDeleted, ) } diff --git a/src/test/kotlin/uk/gov/justice/hmpps/probationsearch/controllers/OffenderSearchPhraseAPIIntegrationTest.kt b/src/test/kotlin/uk/gov/justice/hmpps/probationsearch/controllers/OffenderSearchPhraseAPIIntegrationTest.kt index a3d89a20..876857ae 100644 --- a/src/test/kotlin/uk/gov/justice/hmpps/probationsearch/controllers/OffenderSearchPhraseAPIIntegrationTest.kt +++ b/src/test/kotlin/uk/gov/justice/hmpps/probationsearch/controllers/OffenderSearchPhraseAPIIntegrationTest.kt @@ -1097,7 +1097,13 @@ class OffenderSearchPhraseAPIIntegrationTest : ElasticIntegrationBase() { OffenderReplacement( crn = "X00006", surname = "Gramsci", - offenderManagers = listOf(OffenderManagerReplacement(code = "N07", description = "NPS London", active = true)), + offenderManagers = listOf( + OffenderManagerReplacement( + code = "N07", + description = "NPS London", + active = true + ) + ), ), OffenderReplacement( crn = "X00007", diff --git a/src/test/kotlin/uk/gov/justice/hmpps/probationsearch/controllers/ProbationStatusIntegrationTest.kt b/src/test/kotlin/uk/gov/justice/hmpps/probationsearch/controllers/ProbationStatusIntegrationTest.kt index 3396ade7..0ca9aa0f 100644 --- a/src/test/kotlin/uk/gov/justice/hmpps/probationsearch/controllers/ProbationStatusIntegrationTest.kt +++ b/src/test/kotlin/uk/gov/justice/hmpps/probationsearch/controllers/ProbationStatusIntegrationTest.kt @@ -97,7 +97,8 @@ class ProbationStatusIntegrationTest : ElasticIntegrationBase() { assertThatJson(response).node("matches[0].offender.probationStatus.inBreach").isEqualTo(true) assertThatJson(response).node("matches[0].offender.probationStatus.awaitingPsr").isEqualTo(true) assertThatJson(response).node("matches[0].offender.probationStatus.preSentenceActivity").isEqualTo(false) - assertThatJson(response).node("matches[0].offender.probationStatus.previouslyKnownTerminationDate").isEqualTo("2021-02-08") + assertThatJson(response).node("matches[0].offender.probationStatus.previouslyKnownTerminationDate") + .isEqualTo("2021-02-08") } @Test diff --git a/src/test/kotlin/uk/gov/justice/hmpps/probationsearch/dto/OffenderDetailTest.kt b/src/test/kotlin/uk/gov/justice/hmpps/probationsearch/dto/OffenderDetailTest.kt index c76c9e3f..a6fa42c3 100644 --- a/src/test/kotlin/uk/gov/justice/hmpps/probationsearch/dto/OffenderDetailTest.kt +++ b/src/test/kotlin/uk/gov/justice/hmpps/probationsearch/dto/OffenderDetailTest.kt @@ -9,7 +9,13 @@ internal class OffenderDetailTest { @Test fun `age is calculated from date of birth`() { val expectedAge = LocalDate.now().year - 2000 - assertThat(OffenderDetail(otherIds = IDs("1234"), offenderId = 99, dateOfBirth = LocalDate.parse("2000-01-01")).age).isEqualTo(expectedAge) + assertThat( + OffenderDetail( + otherIds = IDs("1234"), + offenderId = 99, + dateOfBirth = LocalDate.parse("2000-01-01") + ).age + ).isEqualTo(expectedAge) } @Test diff --git a/src/test/kotlin/uk/gov/justice/hmpps/probationsearch/services/HighlightingTest.kt b/src/test/kotlin/uk/gov/justice/hmpps/probationsearch/services/HighlightingTest.kt index 5f9da54e..3edaf16e 100644 --- a/src/test/kotlin/uk/gov/justice/hmpps/probationsearch/services/HighlightingTest.kt +++ b/src/test/kotlin/uk/gov/justice/hmpps/probationsearch/services/HighlightingTest.kt @@ -54,7 +54,8 @@ internal class HighlightingTest { @Test fun `will highlight date of birth when format is same`() { - val offenderDetail = OffenderDetail(otherIds = IDs("1234"), offenderId = 99, dateOfBirth = LocalDate.parse("1965-07-19")) + val offenderDetail = + OffenderDetail(otherIds = IDs("1234"), offenderId = 99, dateOfBirth = LocalDate.parse("1965-07-19")) val highlights = mapOf( "dateOfBirth" to HighlightField("dateOfBirth", arrayOf(Text("1965-07-19"))), ) @@ -68,7 +69,8 @@ internal class HighlightingTest { @Test fun `will highlight date of birth even when format is different`() { - val offenderDetail = OffenderDetail(offenderId = 99, otherIds = IDs("1234"), dateOfBirth = LocalDate.parse("1965-07-19")) + val offenderDetail = + OffenderDetail(offenderId = 99, otherIds = IDs("1234"), dateOfBirth = LocalDate.parse("1965-07-19")) assertThat(offenderDetail.mergeHighlights(mapOf(), "19/7/1965").highlight) .containsExactlyEntriesOf( mapOf( diff --git a/src/test/kotlin/uk/gov/justice/hmpps/probationsearch/services/MatchServiceTest.kt b/src/test/kotlin/uk/gov/justice/hmpps/probationsearch/services/MatchServiceTest.kt index e4580d16..5eb0ed24 100644 --- a/src/test/kotlin/uk/gov/justice/hmpps/probationsearch/services/MatchServiceTest.kt +++ b/src/test/kotlin/uk/gov/justice/hmpps/probationsearch/services/MatchServiceTest.kt @@ -263,7 +263,8 @@ internal class MatchServiceTest { } private fun resultsOf(vararg offenders: OffenderDetail): SearchResponse { - val searchHits = offenders.map { SearchHit(it.offenderId.toInt()).apply { sourceRef(BytesArray(objectMapper.writeValueAsBytes(it))) } } + val searchHits = + offenders.map { SearchHit(it.offenderId.toInt()).apply { sourceRef(BytesArray(objectMapper.writeValueAsBytes(it))) } } val hits = SearchHits(searchHits.toTypedArray(), TotalHits(offenders.size.toLong(), EQUAL_TO), 10f) val searchResponseSections = SearchResponseSections(hits, null, null, false, null, null, 5) return SearchResponse(searchResponseSections, null, 8, 8, 0, 8, arrayOf(), null) diff --git a/src/test/kotlin/uk/gov/justice/hmpps/probationsearch/services/OffenderAccessServiceTest.kt b/src/test/kotlin/uk/gov/justice/hmpps/probationsearch/services/OffenderAccessServiceTest.kt index 33a982e1..01671ada 100644 --- a/src/test/kotlin/uk/gov/justice/hmpps/probationsearch/services/OffenderAccessServiceTest.kt +++ b/src/test/kotlin/uk/gov/justice/hmpps/probationsearch/services/OffenderAccessServiceTest.kt @@ -19,7 +19,12 @@ internal class OffenderAccessServiceTest { @BeforeEach internal fun setUp() { - whenever(communityService.canAccessOffender(any())).thenReturn(AccessLimitation(userRestricted = false, userExcluded = false)) + whenever(communityService.canAccessOffender(any())).thenReturn( + AccessLimitation( + userRestricted = false, + userExcluded = false + ) + ) } @Nested @@ -117,7 +122,12 @@ internal class OffenderAccessServiceTest { @Test fun `Will return true if can userExcluded is false`() { - whenever(communityService.canAccessOffender(any())).thenReturn(AccessLimitation(userRestricted = false, userExcluded = false)) + whenever(communityService.canAccessOffender(any())).thenReturn( + AccessLimitation( + userRestricted = false, + userExcluded = false + ) + ) val canAccess = offenderAccessService.canAccessOffender( offender, @@ -128,7 +138,12 @@ internal class OffenderAccessServiceTest { @Test fun `Will return false if can userExcluded is true`() { - whenever(communityService.canAccessOffender(any())).thenReturn(AccessLimitation(userRestricted = false, userExcluded = true)) + whenever(communityService.canAccessOffender(any())).thenReturn( + AccessLimitation( + userRestricted = false, + userExcluded = true + ) + ) val canAccess = offenderAccessService.canAccessOffender( offender, @@ -226,7 +241,12 @@ internal class OffenderAccessServiceTest { @Test fun `Will return true if can userRestricted is false`() { - whenever(communityService.canAccessOffender(any())).thenReturn(AccessLimitation(userRestricted = false, userExcluded = false)) + whenever(communityService.canAccessOffender(any())).thenReturn( + AccessLimitation( + userRestricted = false, + userExcluded = false + ) + ) val canAccess = offenderAccessService.canAccessOffender( offender, @@ -237,7 +257,12 @@ internal class OffenderAccessServiceTest { @Test fun `Will return false if can userRestricted is true`() { - whenever(communityService.canAccessOffender(any())).thenReturn(AccessLimitation(userRestricted = true, userExcluded = false)) + whenever(communityService.canAccessOffender(any())).thenReturn( + AccessLimitation( + userRestricted = true, + userExcluded = false + ) + ) val canAccess = offenderAccessService.canAccessOffender( offender, diff --git a/src/test/kotlin/uk/gov/justice/hmpps/probationsearch/services/PhraseParserKtTest.kt b/src/test/kotlin/uk/gov/justice/hmpps/probationsearch/services/PhraseParserKtTest.kt index 13b8a1d5..70baee56 100644 --- a/src/test/kotlin/uk/gov/justice/hmpps/probationsearch/services/PhraseParserKtTest.kt +++ b/src/test/kotlin/uk/gov/justice/hmpps/probationsearch/services/PhraseParserKtTest.kt @@ -220,7 +220,8 @@ internal class PhraseParserKtTest { @Test internal fun `will extract even with all combinations`() { - val terms = extractSearchableSimpleTermsWithSingleLetters("12345/99Z 2003/0004567A 20/20 SmItH a 19/5/1987 2001-01-12") + val terms = + extractSearchableSimpleTermsWithSingleLetters("12345/99Z 2003/0004567A 20/20 SmItH a 19/5/1987 2001-01-12") assertThat(terms).containsExactly("smith", "a") } } diff --git a/src/test/kotlin/uk/gov/justice/hmpps/probationsearch/services/ProbationAreaFilterAggregatorKtTest.kt b/src/test/kotlin/uk/gov/justice/hmpps/probationsearch/services/ProbationAreaFilterAggregatorKtTest.kt index 47e67b3d..5097abf7 100644 --- a/src/test/kotlin/uk/gov/justice/hmpps/probationsearch/services/ProbationAreaFilterAggregatorKtTest.kt +++ b/src/test/kotlin/uk/gov/justice/hmpps/probationsearch/services/ProbationAreaFilterAggregatorKtTest.kt @@ -42,14 +42,16 @@ internal class ProbationAreaFilterAggregatorKtTest { @Test internal fun `will divide active and inactive offender managers into probation area buckets`() { assertThat(aggregation.subAggregations.first().subAggregations).hasSize(1) - val probationAreaCodeAggregation = aggregation.subAggregations.first().subAggregations.first() as TermsAggregationBuilder + val probationAreaCodeAggregation = + aggregation.subAggregations.first().subAggregations.first() as TermsAggregationBuilder assertThat(probationAreaCodeAggregation.field()).isEqualTo("offenderManagers.probationArea.code") assertThat(probationAreaCodeAggregation.name).isEqualTo("byProbationAreaCode") } @Test internal fun `will restrict probation area bucket to more than know number of areas`() { - val probationAreaCodeAggregation = aggregation.subAggregations.first().subAggregations.first() as TermsAggregationBuilder + val probationAreaCodeAggregation = + aggregation.subAggregations.first().subAggregations.first() as TermsAggregationBuilder assertThat(probationAreaCodeAggregation.size()).isEqualTo(1000) } } @@ -307,10 +309,30 @@ internal class BuildProbationAreaFilter { fun getDefaultNamedXContents(): List { // required by ES to parse the contents of our aggregations val contentParsers = mapOf( - StringTerms.NAME to ContextParser { parser: XContentParser, name: Any -> ParsedStringTerms.fromXContent(parser, name as String) }, - NestedAggregationBuilder.NAME to ContextParser { parser: XContentParser, name: Any -> ParsedNested.fromXContent(parser, name as String) }, - LongTerms.NAME to ContextParser { parser: XContentParser, name: Any -> ParsedLongTerms.fromXContent(parser, name as String) }, - TopHitsAggregationBuilder.NAME to ContextParser { parser: XContentParser, name: Any -> ParsedTopHits.fromXContent(parser, name as String) }, + StringTerms.NAME to ContextParser { parser: XContentParser, name: Any -> + ParsedStringTerms.fromXContent( + parser, + name as String + ) + }, + NestedAggregationBuilder.NAME to ContextParser { parser: XContentParser, name: Any -> + ParsedNested.fromXContent( + parser, + name as String + ) + }, + LongTerms.NAME to ContextParser { parser: XContentParser, name: Any -> + ParsedLongTerms.fromXContent( + parser, + name as String + ) + }, + TopHitsAggregationBuilder.NAME to ContextParser { parser: XContentParser, name: Any -> + ParsedTopHits.fromXContent( + parser, + name as String + ) + }, ) return contentParsers .toList() diff --git a/src/test/kotlin/uk/gov/justice/hmpps/probationsearch/util/PersonSearchHelper.kt b/src/test/kotlin/uk/gov/justice/hmpps/probationsearch/util/PersonSearchHelper.kt index dadd7f7d..2184ffde 100644 --- a/src/test/kotlin/uk/gov/justice/hmpps/probationsearch/util/PersonSearchHelper.kt +++ b/src/test/kotlin/uk/gov/justice/hmpps/probationsearch/util/PersonSearchHelper.kt @@ -89,9 +89,16 @@ class PersonSearchHelper(private val openSearchClient: RestHighLevelClient) { private fun buildPipeline() { openSearchClient.ingest() - .putPipeline(PutPipelineRequest("person-search-pipeline", "/searchdata/create-pipeline.json".resourceAsByteReference(), JSON), RequestOptions.DEFAULT) + .putPipeline( + PutPipelineRequest( + "person-search-pipeline", + "/searchdata/create-pipeline.json".resourceAsByteReference(), + JSON + ), RequestOptions.DEFAULT + ) } } private fun String.resourceAsString() = PersonSearchHelper::class.java.getResource(this)!!.readText() -private fun String.resourceAsByteReference() = BytesArray(PersonSearchHelper::class.java.getResource(this)!!.readBytes()) +private fun String.resourceAsByteReference() = + BytesArray(PersonSearchHelper::class.java.getResource(this)!!.readBytes())