From 8bedc5d3f923fbb5feb192481cb860a907b7c4f4 Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Thu, 12 Mar 2026 20:09:49 +0100 Subject: refactor: extract List.toPage() implementation (#269) --- .../kotlin/dev/dnpm/etl/processor/functions.kt | 35 ++++++++++++++++++++++ .../dnpm/etl/processor/services/RequestService.kt | 30 +++++++++---------- 2 files changed, 49 insertions(+), 16 deletions(-) create mode 100644 src/main/kotlin/dev/dnpm/etl/processor/functions.kt (limited to 'src/main/kotlin/dev/dnpm') diff --git a/src/main/kotlin/dev/dnpm/etl/processor/functions.kt b/src/main/kotlin/dev/dnpm/etl/processor/functions.kt new file mode 100644 index 0000000..aa4fc75 --- /dev/null +++ b/src/main/kotlin/dev/dnpm/etl/processor/functions.kt @@ -0,0 +1,35 @@ +/* + * This file is part of ETL-Processor + * + * Copyright (c) 2026 Comprehensive Cancer Center Mainfranken, Datenintegrationszentrum Philipps-Universität Marburg and Contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package dev.dnpm.etl.processor + +import org.springframework.data.domain.Page +import org.springframework.data.domain.PageImpl +import org.springframework.data.domain.Pageable + +fun List.toPage(pageable: Pageable): Page { + return PageImpl( + this.subList( + pageable.offset.toInt().coerceIn(0, this.size), + (pageable.offset.toInt() + pageable.pageSize).coerceIn(0, this.size) + ), + pageable, + this.size.toLong() + ) +} diff --git a/src/main/kotlin/dev/dnpm/etl/processor/services/RequestService.kt b/src/main/kotlin/dev/dnpm/etl/processor/services/RequestService.kt index 6e7c2f3..ba33fd6 100644 --- a/src/main/kotlin/dev/dnpm/etl/processor/services/RequestService.kt +++ b/src/main/kotlin/dev/dnpm/etl/processor/services/RequestService.kt @@ -23,11 +23,11 @@ import dev.dnpm.etl.processor.PatientPseudonym import dev.dnpm.etl.processor.RequestId import dev.dnpm.etl.processor.Tan import dev.dnpm.etl.processor.monitoring.* -import java.util.* +import dev.dnpm.etl.processor.toPage import org.springframework.data.domain.Page -import org.springframework.data.domain.PageImpl import org.springframework.data.domain.Pageable import org.springframework.stereotype.Service +import java.util.* @Service class RequestService(private val requestRepository: RequestRepository) { @@ -98,18 +98,16 @@ class RequestService(private val requestRepository: RequestRepository) { } fun List.filter(filter: RequestService.Filter, pageable: Pageable): Page { - val list = - this - .toList() - .filter { - it.type == RequestType.MTB_FILE - && sequenceOf(RequestStatus.SUCCESS, RequestStatus.WARNING).contains(it.status) - } - .filter { - filter == RequestService.Filter.ALL_DIP - || filter == RequestService.Filter.CONFIRMED && it.submissionAccepted - || filter == RequestService.Filter.UNCONFIRMED && !it.submissionAccepted - } - - return PageImpl(list, pageable, list.size.toLong()) + return this + .toList() + .filter { + it.type == RequestType.MTB_FILE + && sequenceOf(RequestStatus.SUCCESS, RequestStatus.WARNING).contains(it.status) + } + .filter { + filter == RequestService.Filter.ALL_DIP + || filter == RequestService.Filter.CONFIRMED && it.submissionAccepted + || filter == RequestService.Filter.UNCONFIRMED && !it.submissionAccepted + } + .toPage(pageable) } -- cgit v1.2.3