Skip to content

Commit 9f39bcf

Browse files
committed
Extract function for whether a value should be filtered out.
1 parent 8e8a606 commit 9f39bcf

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/models/roleconfig/ConsumerFilters.kt

+17-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,20 @@ package uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.roleconfig
22

33
data class ConsumerFilters(
44
val filters: Map<String, List<String>>? = emptyMap(),
5-
)
5+
) {
6+
fun matchesAtKey(
7+
filterKey: String,
8+
value: String?,
9+
): Boolean {
10+
if (filters == null) {
11+
return true
12+
}
13+
if (!filters.containsKey(filterKey)) {
14+
return true
15+
}
16+
if (filters.getOrDefault(filterKey, emptyList()).contains(value)) {
17+
return true
18+
}
19+
return false
20+
}
21+
}

src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/services/GetPersonService.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ class GetPersonService(
151151
val posPrisoner = prisonResponse.data
152152

153153
if (
154-
filters?.filters?.containsKey("prisons") == true && filters.filters["prisons"]?.contains(posPrisoner?.prisonId) == false
154+
filters != null && !filters.matchesAtKey("prisons", posPrisoner?.prisonId)
155155
) {
156156
return Response(
157157
data = null,

0 commit comments

Comments
 (0)