diff options
Diffstat (limited to 'src/main/kotlin/dev')
| -rw-r--r-- | src/main/kotlin/dev/dnpm/etl/processor/functions.kt | 35 | ||||
| -rw-r--r-- | src/main/kotlin/dev/dnpm/etl/processor/services/RequestService.kt | 30 |
2 files changed, 49 insertions, 16 deletions
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 <https://www.gnu.org/licenses/>. + */ + +package dev.dnpm.etl.processor + +import org.springframework.data.domain.Page +import org.springframework.data.domain.PageImpl +import org.springframework.data.domain.Pageable + +fun <T : Any> List<T>.toPage(pageable: Pageable): Page<T> { + 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<Request>.filter(filter: RequestService.Filter, pageable: Pageable): Page<Request> { - 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) } |
