dave
12/09/2022, 5:22 PMHarmen Backhaus
12/15/2022, 1:26 PMdave
12/15/2022, 1:29 PMHarmen Backhaus
12/15/2022, 1:38 PMval webClient = WebclientFactory
.createWebClient(baseUrl = Environment.getEnvironment("BACKENDS_<Obfuscated-external-service>_BASEURL"), circuitBreaker = CIRCUIT_BREAKER)
.then(OkHttp())
fun getDisruptions(active: Boolean): List<Disruption> =
disruptionsResponseLens(
webClient(
Request(Method.GET, "/api/v3/disruptions?type=disruption&type=maintenance")
.query("isActive", active.toString())
)
)
companion object {
private val disruptionsResponseLens = Body.auto<List<Disruption>>().toLens()
private val CIRCUIT_BREAKER = CustomCircuitBreakerConfig.getCircuitBreaker("<Obfuscated-external-service>")
}
After that the same service use .filter to further process this:
.filter { disruption -> disruption.publicationSections.isNotEmpty() }
.filter { disruption ->
// Filter disruptions and maintenance within the given period
if (startDate != null && disruption.timespans.none { timespan -> timespan.start?.isAfter(startDate) == true }) {
return@filter false
}
if (endDate != null && disruption.timespans.none { timespan -> timespan.end?.isBefore(endDate) == true }) {
return@filter false
}
id.isNullOrBlank() || id == disruption.id
}
.flatMap { disruption ->
disruption.publicationSections
.map { section -> service.trajectToFeature(section, disruption.id, disruption.type) }
}
I'm not that deep into Kotlin as I'm helping my colleague from an AWS Cloud perspective, I do however enjoy learning about this 🙂.Harmen Backhaus
12/15/2022, 1:39 PMdave
12/15/2022, 1:40 PMHarmen Backhaus
12/15/2022, 1:43 PMdave
12/15/2022, 1:44 PMHarmen Backhaus
12/15/2022, 1:45 PMJames Richardson
12/15/2022, 5:29 PMHarmen Backhaus
12/19/2022, 8:20 PM