From 9c9760c3ec31b6c7bfc9977d85d64e0ac6dfef35 Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Tue, 1 Aug 2023 08:45:30 +0200 Subject: Add delete requests to be shown in statistics page --- .../etl/processor/web/StatisticsRestController.kt | 52 ++++++++++++++++++---- 1 file changed, 44 insertions(+), 8 deletions(-) (limited to 'src/main/kotlin/dev') diff --git a/src/main/kotlin/dev/dnpm/etl/processor/web/StatisticsRestController.kt b/src/main/kotlin/dev/dnpm/etl/processor/web/StatisticsRestController.kt index 1e56c28..a418772 100644 --- a/src/main/kotlin/dev/dnpm/etl/processor/web/StatisticsRestController.kt +++ b/src/main/kotlin/dev/dnpm/etl/processor/web/StatisticsRestController.kt @@ -21,10 +21,12 @@ package dev.dnpm.etl.processor.web import dev.dnpm.etl.processor.monitoring.RequestRepository import dev.dnpm.etl.processor.monitoring.RequestStatus +import dev.dnpm.etl.processor.monitoring.RequestType import org.springframework.http.MediaType import org.springframework.http.codec.ServerSentEvent import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RequestParam import org.springframework.web.bind.annotation.RestController import reactor.core.publisher.Flux import reactor.core.publisher.Sinks @@ -41,8 +43,14 @@ class StatisticsRestController( ) { @GetMapping(path = ["requeststates"]) - fun requestStates(): List { - return requestRepository.countStates() + fun requestStates(@RequestParam(required = false, defaultValue = "false") delete: Boolean): List { + val states = if (delete) { + requestRepository.countDeleteStates() + } else { + requestRepository.countStates() + } + + return states .map { val color = when (it.status) { RequestStatus.ERROR -> "red" @@ -56,9 +64,21 @@ class StatisticsRestController( } @GetMapping(path = ["requestslastmonth"]) - fun requestsLastMonth(): List { + fun requestsLastMonth( + @RequestParam( + required = false, + defaultValue = "false" + ) delete: Boolean + ): List { + val requestType = if (delete) { + RequestType.DELETE + } else { + RequestType.MTB_FILE + } + val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd").withZone(ZoneId.of("Europe/Berlin")) val data = requestRepository.findAll() + .filter { it.type == requestType } .filter { it.processedAt.isAfter(Instant.now().minus(30, ChronoUnit.DAYS)) } .groupBy { formatter.format(it.processedAt) } .map { @@ -91,8 +111,14 @@ class StatisticsRestController( } @GetMapping(path = ["requestpatientstates"]) - fun requestPatientStates(): List { - return requestRepository.findPatientUniqueStates().map { + fun requestPatientStates(@RequestParam(required = false, defaultValue = "false") delete: Boolean): List { + val states = if (delete) { + requestRepository.findPatientUniqueDeleteStates() + } else { + requestRepository.findPatientUniqueStates() + } + + return states.map { val color = when (it.status) { RequestStatus.ERROR -> "red" RequestStatus.WARNING -> "darkorange" @@ -109,13 +135,23 @@ class StatisticsRestController( Flux.fromIterable( listOf( ServerSentEvent.builder() - .event("requeststates").id("none").data(this.requestStates()) + .event("requeststates").id("none").data(this.requestStates(false)) + .build(), + ServerSentEvent.builder() + .event("requestslastmonth").id("none").data(this.requestsLastMonth(false)) + .build(), + ServerSentEvent.builder() + .event("requestpatientstates").id("none").data(this.requestPatientStates(false)) + .build(), + + ServerSentEvent.builder() + .event("deleterequeststates").id("none").data(this.requestStates(true)) .build(), ServerSentEvent.builder() - .event("requestslastmonth").id("none").data(this.requestsLastMonth()) + .event("deleterequestslastmonth").id("none").data(this.requestsLastMonth(true)) .build(), ServerSentEvent.builder() - .event("requestpatientstates").id("none").data(this.requestPatientStates()) + .event("deleterequestpatientstates").id("none").data(this.requestPatientStates(true)) .build() ) ) -- cgit v1.2.3