mirror of
https://github.com/pcvolkmer/etl-processor.git
synced 2025-07-01 14:12:55 +00:00
Merge branch 'master' into check-consent-status
# Conflicts: # build.gradle.kts # src/main/kotlin/dev/dnpm/etl/processor/config/AppConfiguration.kt # src/main/kotlin/dev/dnpm/etl/processor/input/MtbFileRestController.kt # src/main/kotlin/dev/dnpm/etl/processor/services/RequestProcessor.kt # src/test/kotlin/dev/dnpm/etl/processor/input/KafkaInputListenerTest.kt # src/test/kotlin/dev/dnpm/etl/processor/input/MtbFileRestControllerTest.kt
This commit is contained in:
6
.github/workflows/deploy.yml
vendored
6
.github/workflows/deploy.yml
vendored
@ -30,6 +30,6 @@ jobs:
|
|||||||
- name: Execute image build and push
|
- name: Execute image build and push
|
||||||
run: |
|
run: |
|
||||||
./gradlew bootBuildImage
|
./gradlew bootBuildImage
|
||||||
docker tag ghcr.io/ccc-mf/etl-processor ghcr.io/ccc-mf/etl-processor:${{ github.ref_name }}
|
docker tag ghcr.io/${{ github.repository }} ghcr.io/${{ github.repository }}:${{ github.ref_name }}
|
||||||
docker push ghcr.io/ccc-mf/etl-processor
|
docker push ghcr.io/${{ github.repository }}
|
||||||
docker push ghcr.io/ccc-mf/etl-processor:${{ github.ref_name }}
|
docker push ghcr.io/${{ github.repository }}:${{ github.ref_name }}
|
93
README.md
93
README.md
@ -1,6 +1,6 @@
|
|||||||
# ETL-Processor for bwHC data [](https://github.com/CCC-MF/etl-processor/actions/workflows/test.yml)
|
# ETL-Processor for DNPM:DIP [](https://github.com/pcvolkmer/etl-processor/actions/workflows/test.yml)
|
||||||
|
|
||||||
Diese Anwendung versendet ein bwHC-MTB-File an das bwHC-Backend und pseudonymisiert die Patienten-ID.
|
Diese Anwendung versendet ein bwHC-MTB-File im bwHC-Datenmodell 1.0 an DNPM:DIP und pseudonymisiert die Patienten-ID.
|
||||||
|
|
||||||
## Einordnung innerhalb einer DNPM-ETL-Strecke
|
## Einordnung innerhalb einer DNPM-ETL-Strecke
|
||||||
|
|
||||||
@ -9,7 +9,7 @@ Diese Anwendung erlaubt das Entgegennehmen von HTTP/REST-Anfragen aus dem Onkost
|
|||||||
Der Inhalt einer Anfrage, wenn ein bwHC-MTBFile, wird pseudonymisiert und auf Duplikate geprüft.
|
Der Inhalt einer Anfrage, wenn ein bwHC-MTBFile, wird pseudonymisiert und auf Duplikate geprüft.
|
||||||
Duplikate werden verworfen, Änderungen werden weitergeleitet.
|
Duplikate werden verworfen, Änderungen werden weitergeleitet.
|
||||||
|
|
||||||
Löschanfragen werden immer als Löschanfrage an das bwHC-backend weitergeleitet.
|
Löschanfragen werden immer als Löschanfrage an DNPM:DIP weitergeleitet.
|
||||||
|
|
||||||
Zudem ist eine minimalistische Weboberfläche integriert, die einen Einblick in den aktuellen Zustand der Anwendung gewährt.
|
Zudem ist eine minimalistische Weboberfläche integriert, die einen Einblick in den aktuellen Zustand der Anwendung gewährt.
|
||||||
|
|
||||||
@ -22,7 +22,17 @@ Die Erkennung von Duplikaten ist normalerweise immer aktiv, kann jedoch über de
|
|||||||
|
|
||||||
### Datenübermittlung über HTTP/REST
|
### Datenübermittlung über HTTP/REST
|
||||||
|
|
||||||
Anfragen werden, wenn nicht als Duplikat behandelt, nach der Pseudonymisierung direkt an das bwHC-Backend gesendet.
|
Anfragen werden, wenn nicht als Duplikat behandelt, nach der Pseudonymisierung direkt an DNPM:DIP gesendet.
|
||||||
|
|
||||||
|
Ein HTTP Request kann, angenommen die Installation erfolgte auf dem Host `dnpm.example.com` an nachfolgende URLs gesendet werden:
|
||||||
|
|
||||||
|
| HTTP-Request | URL | Consent-Status im Datensatz | Bemerkung |
|
||||||
|
|--------------|-----------------------------------------|-----------------------------|---------------------------------------------------------------------------------|
|
||||||
|
| `POST` | `https://dnpm.example.com/mtb` | `ACTIVE` | Die Anwendung verarbeitet den eingehenden Datensatz |
|
||||||
|
| `POST` | `https://dnpm.example.com/mtb` | `REJECT` | Die Anwendung sendet einen Lösch-Request für die im Datensatz angegebene Pat-ID |
|
||||||
|
| `DELETE` | `https://dnpm.example.com/mtb/12345678` | - | Die Anwendung sendet einen Lösch-Request für Pat-ID `12345678` |
|
||||||
|
|
||||||
|
Anstelle des Pfads `/mtb` kann auch, wie in Version 0.9 und älter üblich, `/mtbfile` verwendet werden.
|
||||||
|
|
||||||
### Datenübermittlung mit Apache Kafka
|
### Datenübermittlung mit Apache Kafka
|
||||||
|
|
||||||
@ -33,15 +43,21 @@ Siehe hierzu auch: https://github.com/CCC-MF/kafka-to-bwhc
|
|||||||
|
|
||||||
## Konfiguration
|
## Konfiguration
|
||||||
|
|
||||||
### Breaking Changes nach Version 0.10
|
### 🔥 Wichtige Änderungen in Version 0.10
|
||||||
|
|
||||||
|
Ab Version 0.10 wird [DNPM:DIP](https://github.com/dnpm-dip) unterstützt und als Standardendpunkt verwendet.
|
||||||
|
Soll noch das alte bwHC-Backend verwendet werden, so ist die Umgebungsvariable `APP_REST_IS_BWHC` auf `true` zu setzen.
|
||||||
|
|
||||||
|
### 🔥 Breaking Changes nach Version 0.10
|
||||||
|
|
||||||
In Versionen des ETL-Processors **nach Version 0.10** werden die folgenden Konfigurationsoptionen entfernt:
|
In Versionen des ETL-Processors **nach Version 0.10** werden die folgenden Konfigurationsoptionen entfernt:
|
||||||
|
|
||||||
* `APP_PSEUDONYMIZE_GPAS_SSLCALOCATION`: Nutzen Sie hier, wie unter [_Integration eines eigenen Root CA
|
|
||||||
Zertifikats_](#integration-eines-eigenen-root-ca-zertifikats) beschrieben, das Einbinden eigener Zertifikate.
|
|
||||||
* `APP_KAFKA_TOPIC`: Nutzen Sie nun die Konfigurationsoption `APP_KAFKA_OUTPUT_TOPIC`
|
* `APP_KAFKA_TOPIC`: Nutzen Sie nun die Konfigurationsoption `APP_KAFKA_OUTPUT_TOPIC`
|
||||||
* `APP_KAFKA_RESPONSE_TOPIC`: Nutzen Sie nun die Konfigurationsoption `APP_KAFKA_OUTPUT_RESPONSE_TOPIC`
|
* `APP_KAFKA_RESPONSE_TOPIC`: Nutzen Sie nun die Konfigurationsoption `APP_KAFKA_OUTPUT_RESPONSE_TOPIC`
|
||||||
|
|
||||||
|
Der Pfad zum Versenden von MTB-Daten ist nun offiziell `/mtb`.
|
||||||
|
In Versionen **nach Version 0.10** wird die Unterstützung des Pfads `/mtbfile` entfernt.
|
||||||
|
|
||||||
### Pseudonymisierung der Patienten-ID
|
### Pseudonymisierung der Patienten-ID
|
||||||
|
|
||||||
Wenn eine URI zu einer gPAS-Instanz (Version >= 2023.1.0) angegeben ist, wird diese verwendet.
|
Wenn eine URI zu einer gPAS-Instanz (Version >= 2023.1.0) angegeben ist, wird diese verwendet.
|
||||||
@ -50,13 +66,11 @@ Ist diese nicht gesetzt. wird intern eine Anonymisierung der Patienten-ID vorgen
|
|||||||
* `APP_PSEUDONYMIZE_PREFIX`: Standortbezogenes Präfix - `UNKNOWN`, wenn nicht gesetzt
|
* `APP_PSEUDONYMIZE_PREFIX`: Standortbezogenes Präfix - `UNKNOWN`, wenn nicht gesetzt
|
||||||
* `APP_PSEUDONYMIZE_GENERATOR`: `BUILDIN` oder `GPAS` - `BUILDIN`, wenn nicht gesetzt
|
* `APP_PSEUDONYMIZE_GENERATOR`: `BUILDIN` oder `GPAS` - `BUILDIN`, wenn nicht gesetzt
|
||||||
|
|
||||||
**Hinweise**:
|
**Hinweis**
|
||||||
|
|
||||||
* Der alte Konfigurationsparameter `APP_PSEUDONYMIZER` mit den Werten `GPAS` oder `BUILDIN` sollte nicht mehr verwendet
|
Die Pseudonymisierung erfolgt im ETL-Prozessor nur für die Patienten-ID.
|
||||||
werden.
|
Andere IDs werden mithilfe des standortbezogenen Präfixes (erneut) anonymisiert, um für den aktuellen Kontext nicht
|
||||||
* Die Pseudonymisierung erfolgt im ETL-Prozessor nur für die Patienten-ID.
|
vergleichbare IDs bereitzustellen.
|
||||||
Andere IDs werden mithilfe des standortbezogenen Präfixes (erneut) anonymisiert, um für den aktuellen Kontext nicht
|
|
||||||
vergleichbare IDs bereitzustellen.
|
|
||||||
|
|
||||||
#### Eingebaute Anonymisierung
|
#### Eingebaute Anonymisierung
|
||||||
|
|
||||||
@ -72,13 +86,6 @@ Wurde die Verwendung von gPAS konfiguriert, so sind weitere Angaben zu konfiguri
|
|||||||
* `APP_PSEUDONYMIZE_GPAS_TARGET`: gPas Domänenname
|
* `APP_PSEUDONYMIZE_GPAS_TARGET`: gPas Domänenname
|
||||||
* `APP_PSEUDONYMIZE_GPAS_USERNAME`: gPas Basic-Auth Benutzername
|
* `APP_PSEUDONYMIZE_GPAS_USERNAME`: gPas Basic-Auth Benutzername
|
||||||
* `APP_PSEUDONYMIZE_GPAS_PASSWORD`: gPas Basic-Auth Passwort
|
* `APP_PSEUDONYMIZE_GPAS_PASSWORD`: gPas Basic-Auth Passwort
|
||||||
* ~~`APP_PSEUDONYMIZE_GPAS_SSLCALOCATION`~~: **Veraltet** - Root Zertifikat für gPas, falls es dediziert hinzugefügt werden muss.
|
|
||||||
**Wird in nach Version 0.10 entfernt**
|
|
||||||
|
|
||||||
Der Konfigurationsparameter `APP_PSEUDONYMIZE_GPAS_SSLCALOCATION` sollte nicht mehr verwendet werden und wird nach
|
|
||||||
Version 0.10 entfernt.
|
|
||||||
Stattdessen sollte das Root Zertifikat wie unter [_Integration eines eigenen Root CA
|
|
||||||
Zertifikats_](#integration-eines-eigenen-root-ca-zertifikats) beschrieben eingebunden werden.
|
|
||||||
|
|
||||||
### Anmeldung mit einem Passwort
|
### Anmeldung mit einem Passwort
|
||||||
|
|
||||||
@ -145,7 +152,7 @@ Sie bekommen dabei wieder die Standardrolle zugewiesen.
|
|||||||
#### Auswirkungen auf den dargestellten Inhalt
|
#### Auswirkungen auf den dargestellten Inhalt
|
||||||
|
|
||||||
Nur Administratoren haben Zugriff auf den Konfigurationsbereich, nur angemeldete Benutzer können die anonymisierte oder
|
Nur Administratoren haben Zugriff auf den Konfigurationsbereich, nur angemeldete Benutzer können die anonymisierte oder
|
||||||
pseudonymisierte Patienten-ID sowie den Qualitätsbericht des bwHC-Backends einsehen.
|
pseudonymisierte Patienten-ID sowie den Qualitätsbericht von DNPM:DIP einsehen.
|
||||||
|
|
||||||
Wurde kein Administrator-Account konfiguriert, sind diese Inhalte generell nicht verfügbar.
|
Wurde kein Administrator-Account konfiguriert, sind diese Inhalte generell nicht verfügbar.
|
||||||
|
|
||||||
@ -161,7 +168,7 @@ zur Nutzung des MTB-File-Endpunkts eine HTTP-Basic-Authentifizierung voraussetze
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
In diesem Fall können den Endpunkt für das Onkostar-Plugin **[onkostar-plugin-dnpmexport](https://github.com/CCC-MF/onkostar-plugin-dnpmexport)** wie folgt konfigurieren:
|
In diesem Fall kann der Endpunkt für das Onkostar-Plugin **[onkostar-plugin-dnpmexport](https://github.com/CCC-MF/onkostar-plugin-dnpmexport)** wie folgt konfiguriert werden:
|
||||||
|
|
||||||
```
|
```
|
||||||
https://testonkostar:MTg1NTL...NGU4@etl.example.com/mtbfile
|
https://testonkostar:MTg1NTL...NGU4@etl.example.com/mtbfile
|
||||||
@ -174,7 +181,7 @@ Alternativ kann eine Authentifizierung über Benutzername/Passwort oder OIDC erf
|
|||||||
### Transformation von Werten
|
### Transformation von Werten
|
||||||
|
|
||||||
In Onkostar kann es vorkommen, dass ein Wert eines Merkmalskatalogs an einem Standort angepasst wurde und dadurch nicht dem Wert entspricht,
|
In Onkostar kann es vorkommen, dass ein Wert eines Merkmalskatalogs an einem Standort angepasst wurde und dadurch nicht dem Wert entspricht,
|
||||||
der vom bwHC-Backend akzeptiert wird.
|
der von DNPM:DIP akzeptiert wird.
|
||||||
|
|
||||||
Diese Anwendung bietet daher die Möglichkeit, eine Transformation vorzunehmen. Hierzu muss der "Pfad" innerhalb des JSON-MTB-Files angegeben werden und
|
Diese Anwendung bietet daher die Möglichkeit, eine Transformation vorzunehmen. Hierzu muss der "Pfad" innerhalb des JSON-MTB-Files angegeben werden und
|
||||||
welcher Wert wie ersetzt werden soll.
|
welcher Wert wie ersetzt werden soll.
|
||||||
@ -194,18 +201,21 @@ Werden sowohl REST als auch Kafka-Endpunkt konfiguriert, wird nur der REST-Endpu
|
|||||||
|
|
||||||
#### REST
|
#### REST
|
||||||
|
|
||||||
Folgende Umgebungsvariablen müssen gesetzt sein, damit ein bwHC-MTB-File an das bwHC-Backend gesendet wird:
|
Folgende Umgebungsvariablen müssen gesetzt sein, damit ein bwHC-MTB-File an DNPM:DIP gesendet wird:
|
||||||
|
|
||||||
* `APP_REST_URI`: URI der zu benutzenden API der bwHC-Backend-Instanz. z.B.: `http://localhost:9000/bwhc/etl/api`
|
* `APP_REST_URI`: URI der zu benutzenden API der Backend-Instanz. Zum Beispiel:
|
||||||
|
* `http://localhost:9000/bwhc/etl/api` für **bwHC Backend**
|
||||||
|
* `http://localhost:9000/api` für **dnpm:dip**
|
||||||
|
* `APP_REST_USERNAME`: Basic-Auth-Benutzername für den REST-Endpunkt
|
||||||
|
* `APP_REST_PASSWORD`: Basic-Auth-Passwort für den REST-Endpunkt
|
||||||
|
* `APP_REST_IS_BWHC`: `true` für **bwHC Backend**, weglassen oder `false` für **dnpm:dip**
|
||||||
|
|
||||||
#### Kafka-Topics
|
#### Kafka-Topics
|
||||||
|
|
||||||
Folgende Umgebungsvariablen müssen gesetzt sein, damit ein bwHC-MTB-File an ein Kafka-Topic übermittelt wird:
|
Folgende Umgebungsvariablen müssen gesetzt sein, damit ein bwHC-MTB-File an ein Kafka-Topic übermittelt wird:
|
||||||
|
|
||||||
* `APP_KAFKA_OUTPUT_TOPIC`: Zu verwendendes Topic zum Versenden von Anfragen.
|
* `APP_KAFKA_OUTPUT_TOPIC`: Zu verwendendes Topic zum Versenden von Anfragen.
|
||||||
Ersetzt ~~`APP_KAFKA_TOPIC`~~, **welches nach Version 0.10 entfernt wird**.
|
|
||||||
* `APP_KAFKA_OUTPUT_RESPONSE_TOPIC`: Topic mit Antworten über den Erfolg des Versendens. Standardwert: `APP_KAFKA_TOPIC` mit Anhang "_response".
|
* `APP_KAFKA_OUTPUT_RESPONSE_TOPIC`: Topic mit Antworten über den Erfolg des Versendens. Standardwert: `APP_KAFKA_TOPIC` mit Anhang "_response".
|
||||||
Ersetzt ~~`APP_KAFKA_RESPONSE_TOPIC`~~, **welches nach Version 0.10 entfernt wird**.
|
|
||||||
* `APP_KAFKA_GROUP_ID`: Kafka GroupID des Consumers. Standardwert: `APP_KAFKA_TOPIC` mit Anhang "_group".
|
* `APP_KAFKA_GROUP_ID`: Kafka GroupID des Consumers. Standardwert: `APP_KAFKA_TOPIC` mit Anhang "_group".
|
||||||
* `APP_KAFKA_SERVERS`: Zu verwendende Kafka-Bootstrap-Server als kommagetrennte Liste
|
* `APP_KAFKA_SERVERS`: Zu verwendende Kafka-Bootstrap-Server als kommagetrennte Liste
|
||||||
|
|
||||||
@ -213,7 +223,7 @@ Wird keine Rückantwort über Apache Kafka empfangen und es gibt keine weitere M
|
|||||||
|
|
||||||
Weitere Einstellungen können über die Parameter von Spring Kafka konfiguriert werden.
|
Weitere Einstellungen können über die Parameter von Spring Kafka konfiguriert werden.
|
||||||
|
|
||||||
Lässt sich keine Verbindung zu dem bwHC-Backend aufbauen, wird eine Rückantwort mit Status-Code `900` erwartet, welchen es
|
Lässt sich keine Verbindung zu dem Backend aufbauen, wird eine Rückantwort mit Status-Code `900` erwartet, welchen es
|
||||||
für HTTP nicht gibt.
|
für HTTP nicht gibt.
|
||||||
|
|
||||||
Wird die Umgebungsvariable `APP_KAFKA_INPUT_TOPIC` gesetzt, kann eine Nachricht auch über dieses Kafka-Topic an den ETL-Prozessor übermittelt werden.
|
Wird die Umgebungsvariable `APP_KAFKA_INPUT_TOPIC` gesetzt, kann eine Nachricht auch über dieses Kafka-Topic an den ETL-Prozessor übermittelt werden.
|
||||||
@ -250,7 +260,7 @@ kafka-configs.sh --bootstrap-server localhost:9092 --alter --topic test --add-co
|
|||||||
Da als Key eines Records die (pseudonymisierte) Patienten-ID verwendet wird, stehen mit obiger Konfiguration
|
Da als Key eines Records die (pseudonymisierte) Patienten-ID verwendet wird, stehen mit obiger Konfiguration
|
||||||
der Kafka-Topics nach 10 Sekunden nur noch der jeweils letzte Eintrag für den entsprechenden Key zur Verfügung.
|
der Kafka-Topics nach 10 Sekunden nur noch der jeweils letzte Eintrag für den entsprechenden Key zur Verfügung.
|
||||||
|
|
||||||
Da der Key sowohl für die Records in Richtung bwHC-Backend für die Rückantwort identisch aufgebaut ist, lassen sich so
|
Da der Key sowohl für die Records in Richtung DNPM:DIP, als auch für die Rückantwort identisch aufgebaut ist, lassen sich so
|
||||||
auch im Falle eines Consent-Widerspruchs die enthaltenen Daten als auch die Offenlegung durch Verifikationsdaten in der
|
auch im Falle eines Consent-Widerspruchs die enthaltenen Daten als auch die Offenlegung durch Verifikationsdaten in der
|
||||||
Antwort effektiv verhindern, da diese nach 10 Sekunden gelöscht werden.
|
Antwort effektiv verhindern, da diese nach 10 Sekunden gelöscht werden.
|
||||||
|
|
||||||
@ -259,9 +269,30 @@ ein Consent-Widerspruch erfolgte.
|
|||||||
|
|
||||||
Dieses Vorgehen empfiehlt sich, wenn Sie gespeicherte Records nachgelagert für andere Auswertungen verwenden möchten.
|
Dieses Vorgehen empfiehlt sich, wenn Sie gespeicherte Records nachgelagert für andere Auswertungen verwenden möchten.
|
||||||
|
|
||||||
|
### Antworten und Statusauswertung
|
||||||
|
|
||||||
|
Anfragen an das bwHC-Backend aus Versionen bis 0.9.x wurden wie folgt behandelt:
|
||||||
|
|
||||||
|
| HTTP-Response | Status |
|
||||||
|
|----------------|-----------|
|
||||||
|
| `HTTP 200` | `SUCCESS` |
|
||||||
|
| `HTTP 201` | `WARNING` |
|
||||||
|
| `HTTP 400-...` | `ERROR` |
|
||||||
|
|
||||||
|
Dies konnte dazu führen, dass zwar mit einem `HTTP 201` geantwortet wurde, aber dennoch in der Issue-Liste die
|
||||||
|
Severity `error` aufgetaucht ist.
|
||||||
|
|
||||||
|
Ab Version 0.10 wird die Issue-Liste der Antwort verwendet und die darion enthaltene höchste Severity-Stufe als Ergebnis verwendet.
|
||||||
|
|
||||||
|
| Höchste Severity | Status |
|
||||||
|
|------------------|-----------|
|
||||||
|
| `info` | `SUCCESS` |
|
||||||
|
| `warning` | `WARNING` |
|
||||||
|
| `error`, `fatal` | `ERROR` |
|
||||||
|
|
||||||
## Docker-Images
|
## Docker-Images
|
||||||
|
|
||||||
Diese Anwendung ist auch als Docker-Image verfügbar: https://github.com/CCC-MF/etl-processor/pkgs/container/etl-processor
|
Diese Anwendung ist auch als Docker-Image verfügbar: https://github.com/pcvolkmer/etl-processor/pkgs/container/etl-processor
|
||||||
|
|
||||||
### Images lokal bauen
|
### Images lokal bauen
|
||||||
|
|
||||||
@ -374,3 +405,5 @@ Die Datei `application-dev.yml` enthält hierzu die Konfiguration für das Profi
|
|||||||
|
|
||||||
Beim Ausführen der Integrationstests wird eine Testdatenbank in einem Docker-Container gestartet.
|
Beim Ausführen der Integrationstests wird eine Testdatenbank in einem Docker-Container gestartet.
|
||||||
Siehe hier auch die Klasse `AbstractTestcontainerTest` unter `src/integrationTest`.
|
Siehe hier auch die Klasse `AbstractTestcontainerTest` unter `src/integrationTest`.
|
||||||
|
|
||||||
|
Ein einfaches Entwickler-Setup inklusive DNPM:DIP ist mit Hilfe von https://github.com/pcvolkmer/dnpmdip-devenv realisierbar.
|
@ -2,34 +2,35 @@ import org.gradle.api.tasks.testing.logging.TestLogEvent
|
|||||||
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
|
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
|
||||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||||
import org.springframework.boot.gradle.tasks.bundling.BootBuildImage
|
import org.springframework.boot.gradle.tasks.bundling.BootBuildImage
|
||||||
import java.text.SimpleDateFormat
|
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
war
|
war
|
||||||
id("org.springframework.boot") version "3.3.1"
|
id("org.springframework.boot") version "3.4.5"
|
||||||
id("io.spring.dependency-management") version "1.1.5"
|
id("io.spring.dependency-management") version "1.1.7"
|
||||||
kotlin("jvm") version "1.9.24"
|
kotlin("jvm") version "1.9.25"
|
||||||
kotlin("plugin.spring") version "1.9.24"
|
kotlin("plugin.spring") version "1.9.25"
|
||||||
jacoco
|
jacoco
|
||||||
}
|
}
|
||||||
|
|
||||||
group = "de.ukw.ccc"
|
group = "dev.dnpm"
|
||||||
version = "0.10.0-SNAPSHOT"
|
version = "0.11.0-SNAPSHOT"
|
||||||
|
|
||||||
var versions = mapOf(
|
var versions = mapOf(
|
||||||
"bwhc-dto-java" to "0.3.0",
|
"bwhc-dto-java" to "0.4.0",
|
||||||
"hapi-fhir" to "6.10.5",
|
"mtb-dto" to "0.1.0-SNAPSHOT",
|
||||||
"commons-compress" to "1.26.2",
|
"hapi-fhir" to "7.6.0",
|
||||||
"mockito-kotlin" to "5.3.1",
|
"mockito-kotlin" to "5.4.0",
|
||||||
"archunit" to "1.3.0",
|
"archunit" to "1.3.0",
|
||||||
// Webjars
|
// Webjars
|
||||||
|
"webjars-locator" to "0.52",
|
||||||
"echarts" to "5.4.3",
|
"echarts" to "5.4.3",
|
||||||
"htmx.org" to "1.9.12"
|
"htmx.org" to "1.9.12"
|
||||||
)
|
)
|
||||||
|
|
||||||
java {
|
java {
|
||||||
sourceCompatibility = JavaVersion.VERSION_21
|
toolchain {
|
||||||
|
languageVersion = JavaLanguageVersion.of(21)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
@ -48,9 +49,18 @@ configurations {
|
|||||||
compileOnly {
|
compileOnly {
|
||||||
extendsFrom(configurations.annotationProcessor.get())
|
extendsFrom(configurations.annotationProcessor.get())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
all {
|
||||||
|
resolutionStrategy {
|
||||||
|
cacheChangingModulesFor(5, "minutes")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
|
maven {
|
||||||
|
url = uri("https://git.dnpm.dev/api/packages/public-snapshots/maven")
|
||||||
|
}
|
||||||
maven {
|
maven {
|
||||||
url = uri("https://git.dnpm.dev/api/packages/public/maven")
|
url = uri("https://git.dnpm.dev/api/packages/public/maven")
|
||||||
}
|
}
|
||||||
@ -72,30 +82,35 @@ dependencies {
|
|||||||
implementation("commons-codec:commons-codec")
|
implementation("commons-codec:commons-codec")
|
||||||
implementation("io.projectreactor.kotlin:reactor-kotlin-extensions")
|
implementation("io.projectreactor.kotlin:reactor-kotlin-extensions")
|
||||||
implementation("de.ukw.ccc:bwhc-dto-java:${versions["bwhc-dto-java"]}")
|
implementation("de.ukw.ccc:bwhc-dto-java:${versions["bwhc-dto-java"]}")
|
||||||
|
implementation("dev.pcvolkmer.mv64e:mtb-dto:${versions["mtb-dto"]}") { isChanging = true }
|
||||||
implementation("ca.uhn.hapi.fhir:hapi-fhir-base:${versions["hapi-fhir"]}")
|
implementation("ca.uhn.hapi.fhir:hapi-fhir-base:${versions["hapi-fhir"]}")
|
||||||
implementation("ca.uhn.hapi.fhir:hapi-fhir-structures-r4:${versions["hapi-fhir"]}")
|
implementation("ca.uhn.hapi.fhir:hapi-fhir-structures-r4:${versions["hapi-fhir"]}")
|
||||||
implementation("org.apache.httpcomponents.client5:httpclient5")
|
implementation("org.apache.httpcomponents.client5:httpclient5")
|
||||||
implementation("com.jayway.jsonpath:json-path")
|
implementation("com.jayway.jsonpath:json-path")
|
||||||
implementation("org.webjars:webjars-locator:0.52")
|
implementation("org.webjars:webjars-locator:${versions["webjars-locator"]}")
|
||||||
implementation("org.webjars.npm:echarts:${versions["echarts"]}")
|
implementation("org.webjars.npm:echarts:${versions["echarts"]}")
|
||||||
implementation("org.webjars.npm:htmx.org:${versions["htmx.org"]}")
|
implementation("org.webjars.npm:htmx.org:${versions["htmx.org"]}")
|
||||||
|
|
||||||
runtimeOnly("org.mariadb.jdbc:mariadb-java-client")
|
runtimeOnly("org.mariadb.jdbc:mariadb-java-client")
|
||||||
runtimeOnly("org.postgresql:postgresql")
|
runtimeOnly("org.postgresql:postgresql")
|
||||||
|
|
||||||
developmentOnly("org.springframework.boot:spring-boot-devtools")
|
developmentOnly("org.springframework.boot:spring-boot-devtools")
|
||||||
developmentOnly("org.springframework.boot:spring-boot-docker-compose")
|
developmentOnly("org.springframework.boot:spring-boot-docker-compose")
|
||||||
|
|
||||||
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
|
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
|
||||||
|
|
||||||
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
|
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
|
||||||
|
|
||||||
testImplementation("org.springframework.boot:spring-boot-starter-test")
|
testImplementation("org.springframework.boot:spring-boot-starter-test")
|
||||||
testImplementation("org.springframework.security:spring-security-test")
|
testImplementation("org.springframework.security:spring-security-test")
|
||||||
testImplementation("io.projectreactor:reactor-test")
|
testImplementation("io.projectreactor:reactor-test")
|
||||||
testImplementation("org.mockito.kotlin:mockito-kotlin:${versions["mockito-kotlin"]}")
|
testImplementation("org.mockito.kotlin:mockito-kotlin:${versions["mockito-kotlin"]}")
|
||||||
|
|
||||||
integrationTestImplementation("org.testcontainers:junit-jupiter")
|
integrationTestImplementation("org.testcontainers:junit-jupiter")
|
||||||
integrationTestImplementation("org.testcontainers:postgresql")
|
integrationTestImplementation("org.testcontainers:postgresql")
|
||||||
integrationTestImplementation("com.tngtech.archunit:archunit:${versions["archunit"]}")
|
integrationTestImplementation("com.tngtech.archunit:archunit:${versions["archunit"]}")
|
||||||
integrationTestImplementation("net.sourceforge.htmlunit:htmlunit")
|
integrationTestImplementation("org.htmlunit:htmlunit")
|
||||||
integrationTestImplementation("org.springframework:spring-webflux")
|
integrationTestImplementation("org.springframework:spring-webflux")
|
||||||
// Override dependency version from org.testcontainers:junit-jupiter - CVE-2024-26308, CVE-2024-25710
|
|
||||||
integrationTestImplementation("org.apache.commons:commons-compress:${versions["commons-compress"]}")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.withType<KotlinCompile> {
|
tasks.withType<KotlinCompile> {
|
||||||
@ -112,8 +127,9 @@ tasks.withType<Test> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
task<Test>("integrationTest") {
|
tasks.register<Test>("integrationTest") {
|
||||||
description = "Runs integration tests"
|
description = "Runs integration tests"
|
||||||
|
group = "verification"
|
||||||
|
|
||||||
testClassesDirs = sourceSets["integrationTest"].output.classesDirs
|
testClassesDirs = sourceSets["integrationTest"].output.classesDirs
|
||||||
classpath = sourceSets["integrationTest"].runtimeClasspath
|
classpath = sourceSets["integrationTest"].runtimeClasspath
|
||||||
@ -122,6 +138,8 @@ task<Test>("integrationTest") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tasks.register("allTests") {
|
tasks.register("allTests") {
|
||||||
|
description = "Run all tests"
|
||||||
|
group = JavaBasePlugin.VERIFICATION_GROUP
|
||||||
dependsOn(tasks.withType<Test>())
|
dependsOn(tasks.withType<Test>())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,9 +153,8 @@ tasks.jacocoTestReport {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
tasks.named<BootBuildImage>("bootBuildImage") {
|
tasks.named<BootBuildImage>("bootBuildImage") {
|
||||||
imageName.set("ghcr.io/ccc-mf/etl-processor")
|
imageName.set("ghcr.io/pcvolkmer/etl-processor")
|
||||||
|
|
||||||
// Binding for CA Certs
|
// Binding for CA Certs
|
||||||
bindings.set(listOf(
|
bindings.set(listOf(
|
||||||
@ -146,9 +163,8 @@ tasks.named<BootBuildImage>("bootBuildImage") {
|
|||||||
|
|
||||||
environment.set(environment.get() + mapOf(
|
environment.set(environment.get() + mapOf(
|
||||||
// Enable this line to embed CA Certs into image on build time
|
// Enable this line to embed CA Certs into image on build time
|
||||||
"BP_EMBED_CERTS" to "true",
|
//"BP_EMBED_CERTS" to "true",
|
||||||
"BP_OCI_CREATED" to SimpleDateFormat("MM-dd-yyyy_hh-mm").format(Date()),
|
"BP_OCI_SOURCE" to "https://github.com/pcvolkmer/etl-processor",
|
||||||
"BP_OCI_SOURCE" to "https://github.com/CCC-MF/etl-processor",
|
|
||||||
"BP_OCI_LICENSES" to "AGPLv3",
|
"BP_OCI_LICENSES" to "AGPLv3",
|
||||||
"BP_OCI_DESCRIPTION" to "ETL Processor for bwHC MTB files"
|
"BP_OCI_DESCRIPTION" to "ETL Processor for bwHC MTB files"
|
||||||
))
|
))
|
||||||
|
@ -18,6 +18,9 @@ services:
|
|||||||
APP_KAFKA_GROUP_ID: ${DNPM_KAFKA_GROUP_ID}
|
APP_KAFKA_GROUP_ID: ${DNPM_KAFKA_GROUP_ID}
|
||||||
APP_KAFKA_RESPONSE_TOPIC: ${DNPM_KAFKA_RESPONSE_TOPIC}
|
APP_KAFKA_RESPONSE_TOPIC: ${DNPM_KAFKA_RESPONSE_TOPIC}
|
||||||
APP_REST_URI: ${DNPM_BWHC_REST_URI}
|
APP_REST_URI: ${DNPM_BWHC_REST_URI}
|
||||||
|
APP_REST_USERNAME: ${DNPM_BWHC_REST_USERNAME}
|
||||||
|
APP_REST_PASSWORD: ${DNPM_BWHC_REST_PASSWORD}
|
||||||
|
APP_REST_IS_BWHC: ${DNPM_BWHC_REST_IS_BWHC}
|
||||||
APP_SECURITY_ADMIN_USER: ${DNPM_ADMIN_USER}
|
APP_SECURITY_ADMIN_USER: ${DNPM_ADMIN_USER}
|
||||||
APP_SECURITY_ADMIN_PASSWORD: ${DNPM_ADMIN_PASSWORD}
|
APP_SECURITY_ADMIN_PASSWORD: ${DNPM_ADMIN_PASSWORD}
|
||||||
SPRING_DATASOURCE_URL: ${DNPM_DATASOURCE_URL}
|
SPRING_DATASOURCE_URL: ${DNPM_DATASOURCE_URL}
|
||||||
|
@ -28,6 +28,9 @@ DNPM_DATASOURCE_URL=jdbc:mariadb://dnpm-monitor-db:3306/$DNPM_MARIADB_DB
|
|||||||
## TARGET SYSTEMS CONFIG
|
## TARGET SYSTEMS CONFIG
|
||||||
# in case of direct access to bwhc enter endpoint url here
|
# in case of direct access to bwhc enter endpoint url here
|
||||||
DNPM_BWHC_REST_URI=
|
DNPM_BWHC_REST_URI=
|
||||||
|
DNPM_BWHC_REST_USERNAME=
|
||||||
|
DNPM_BWHC_REST_PASSWORD=
|
||||||
|
DNPM_BWHC_REST_IS_BWHC=false
|
||||||
|
|
||||||
# produce mtb files to this topic - values 'false' disabling kafka processing
|
# produce mtb files to this topic - values 'false' disabling kafka processing
|
||||||
DNPM_KAFKA_TOPIC=false
|
DNPM_KAFKA_TOPIC=false
|
||||||
|
BIN
docs/etl.png
BIN
docs/etl.png
Binary file not shown.
Before Width: | Height: | Size: 120 KiB After Width: | Height: | Size: 115 KiB |
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,6 +1,6 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
|
||||||
networkTimeout=10000
|
networkTimeout=10000
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
@ -23,6 +23,7 @@ import com.fasterxml.jackson.databind.ObjectMapper
|
|||||||
import de.ukw.ccc.bwhc.dto.*
|
import de.ukw.ccc.bwhc.dto.*
|
||||||
import dev.dnpm.etl.processor.monitoring.RequestRepository
|
import dev.dnpm.etl.processor.monitoring.RequestRepository
|
||||||
import dev.dnpm.etl.processor.monitoring.RequestStatus
|
import dev.dnpm.etl.processor.monitoring.RequestStatus
|
||||||
|
import dev.dnpm.etl.processor.output.BwhcV1MtbFileRequest
|
||||||
import dev.dnpm.etl.processor.output.MtbFileSender
|
import dev.dnpm.etl.processor.output.MtbFileSender
|
||||||
import org.assertj.core.api.Assertions.assertThat
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
import org.junit.jupiter.api.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
@ -33,10 +34,10 @@ import org.mockito.kotlin.*
|
|||||||
import org.springframework.beans.factory.annotation.Autowired
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
|
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
|
||||||
import org.springframework.boot.test.context.SpringBootTest
|
import org.springframework.boot.test.context.SpringBootTest
|
||||||
import org.springframework.boot.test.mock.mockito.MockBean
|
|
||||||
import org.springframework.context.ApplicationContext
|
import org.springframework.context.ApplicationContext
|
||||||
import org.springframework.http.MediaType
|
import org.springframework.http.MediaType
|
||||||
import org.springframework.test.context.TestPropertySource
|
import org.springframework.test.context.TestPropertySource
|
||||||
|
import org.springframework.test.context.bean.override.mockito.MockitoBean
|
||||||
import org.springframework.test.context.junit.jupiter.SpringExtension
|
import org.springframework.test.context.junit.jupiter.SpringExtension
|
||||||
import org.springframework.test.web.servlet.MockMvc
|
import org.springframework.test.web.servlet.MockMvc
|
||||||
import org.springframework.test.web.servlet.post
|
import org.springframework.test.web.servlet.post
|
||||||
@ -45,7 +46,7 @@ import org.testcontainers.junit.jupiter.Testcontainers
|
|||||||
@Testcontainers
|
@Testcontainers
|
||||||
@ExtendWith(SpringExtension::class)
|
@ExtendWith(SpringExtension::class)
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@MockBean(MtbFileSender::class)
|
@MockitoBean(types = [MtbFileSender::class])
|
||||||
@TestPropertySource(
|
@TestPropertySource(
|
||||||
properties = [
|
properties = [
|
||||||
"app.rest.uri=http://example.com",
|
"app.rest.uri=http://example.com",
|
||||||
@ -73,7 +74,7 @@ class EtlProcessorApplicationTests : AbstractTestcontainerTest() {
|
|||||||
)
|
)
|
||||||
inner class TransformationTest {
|
inner class TransformationTest {
|
||||||
|
|
||||||
@MockBean
|
@MockitoBean
|
||||||
private lateinit var mtbFileSender: MtbFileSender
|
private lateinit var mtbFileSender: MtbFileSender
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@ -91,7 +92,7 @@ class EtlProcessorApplicationTests : AbstractTestcontainerTest() {
|
|||||||
fun mtbFileIsTransformed() {
|
fun mtbFileIsTransformed() {
|
||||||
doAnswer {
|
doAnswer {
|
||||||
MtbFileSender.Response(RequestStatus.SUCCESS)
|
MtbFileSender.Response(RequestStatus.SUCCESS)
|
||||||
}.whenever(mtbFileSender).send(any<MtbFileSender.MtbFileRequest>())
|
}.whenever(mtbFileSender).send(any<BwhcV1MtbFileRequest>())
|
||||||
|
|
||||||
val mtbFile = MtbFile.builder()
|
val mtbFile = MtbFile.builder()
|
||||||
.withPatient(
|
.withPatient(
|
||||||
@ -134,9 +135,9 @@ class EtlProcessorApplicationTests : AbstractTestcontainerTest() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val captor = argumentCaptor<MtbFileSender.MtbFileRequest>()
|
val captor = argumentCaptor<BwhcV1MtbFileRequest>()
|
||||||
verify(mtbFileSender).send(captor.capture())
|
verify(mtbFileSender).send(captor.capture())
|
||||||
assertThat(captor.firstValue.mtbFile.diagnoses).hasSize(1).allMatch { diagnosis ->
|
assertThat(captor.firstValue.content.diagnoses).hasSize(1).allMatch { diagnosis ->
|
||||||
diagnosis.icd10.version == "2014"
|
diagnosis.icd10.version == "2014"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,9 +26,9 @@ import dev.dnpm.etl.processor.output.KafkaMtbFileSender
|
|||||||
import dev.dnpm.etl.processor.output.RestMtbFileSender
|
import dev.dnpm.etl.processor.output.RestMtbFileSender
|
||||||
import dev.dnpm.etl.processor.pseudonym.AnonymizingGenerator
|
import dev.dnpm.etl.processor.pseudonym.AnonymizingGenerator
|
||||||
import dev.dnpm.etl.processor.pseudonym.GpasPseudonymGenerator
|
import dev.dnpm.etl.processor.pseudonym.GpasPseudonymGenerator
|
||||||
import dev.dnpm.etl.processor.services.RequestProcessor
|
|
||||||
import dev.dnpm.etl.processor.security.TokenRepository
|
import dev.dnpm.etl.processor.security.TokenRepository
|
||||||
import dev.dnpm.etl.processor.security.TokenService
|
import dev.dnpm.etl.processor.security.TokenService
|
||||||
|
import dev.dnpm.etl.processor.services.RequestProcessor
|
||||||
import org.assertj.core.api.Assertions.assertThat
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
import org.junit.jupiter.api.Nested
|
import org.junit.jupiter.api.Nested
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
@ -36,24 +36,25 @@ import org.junit.jupiter.api.assertThrows
|
|||||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException
|
import org.springframework.beans.factory.NoSuchBeanDefinitionException
|
||||||
import org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration
|
import org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration
|
||||||
import org.springframework.boot.test.context.SpringBootTest
|
import org.springframework.boot.test.context.SpringBootTest
|
||||||
import org.springframework.boot.test.mock.mockito.MockBean
|
|
||||||
import org.springframework.boot.test.mock.mockito.MockBeans
|
|
||||||
import org.springframework.context.ApplicationContext
|
import org.springframework.context.ApplicationContext
|
||||||
import org.springframework.retry.support.RetryTemplate
|
import org.springframework.retry.support.RetryTemplate
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder
|
import org.springframework.security.crypto.password.PasswordEncoder
|
||||||
import org.springframework.security.provisioning.InMemoryUserDetailsManager
|
import org.springframework.security.provisioning.InMemoryUserDetailsManager
|
||||||
import org.springframework.test.context.ContextConfiguration
|
import org.springframework.test.context.ContextConfiguration
|
||||||
import org.springframework.test.context.TestPropertySource
|
import org.springframework.test.context.TestPropertySource
|
||||||
|
import org.springframework.test.context.bean.override.mockito.MockitoBean
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@ContextConfiguration(classes = [
|
@ContextConfiguration(
|
||||||
|
classes = [
|
||||||
AppConfiguration::class,
|
AppConfiguration::class,
|
||||||
AppSecurityConfiguration::class,
|
AppSecurityConfiguration::class,
|
||||||
KafkaAutoConfiguration::class,
|
KafkaAutoConfiguration::class,
|
||||||
AppKafkaConfiguration::class,
|
AppKafkaConfiguration::class,
|
||||||
AppRestConfiguration::class
|
AppRestConfiguration::class
|
||||||
])
|
]
|
||||||
@MockBean(ObjectMapper::class)
|
)
|
||||||
|
@MockitoBean(types = [ObjectMapper::class])
|
||||||
@TestPropertySource(
|
@TestPropertySource(
|
||||||
properties = [
|
properties = [
|
||||||
"app.pseudonymize.generator=BUILDIN",
|
"app.pseudonymize.generator=BUILDIN",
|
||||||
@ -86,7 +87,7 @@ class AppConfigurationTest {
|
|||||||
"app.kafka.group-id=test"
|
"app.kafka.group-id=test"
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
@MockBean(RequestRepository::class)
|
@MockitoBean(types = [RequestRepository::class])
|
||||||
inner class AppConfigurationKafkaTest(private val context: ApplicationContext) {
|
inner class AppConfigurationKafkaTest(private val context: ApplicationContext) {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -145,7 +146,7 @@ class AppConfigurationTest {
|
|||||||
"app.kafka.group-id=test"
|
"app.kafka.group-id=test"
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
@MockBean(RequestProcessor::class)
|
@MockitoBean(types = [RequestProcessor::class])
|
||||||
inner class AppConfigurationUsingKafkaInputTest(private val context: ApplicationContext) {
|
inner class AppConfigurationUsingKafkaInputTest(private val context: ApplicationContext) {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -181,40 +182,7 @@ class AppConfigurationTest {
|
|||||||
@Nested
|
@Nested
|
||||||
@TestPropertySource(
|
@TestPropertySource(
|
||||||
properties = [
|
properties = [
|
||||||
"app.pseudonymize.generator=",
|
"app.pseudonymize.generator=buildin"
|
||||||
"app.pseudonymizer=buildin",
|
|
||||||
]
|
|
||||||
)
|
|
||||||
inner class AppConfigurationPseudonymizerBuildinTest(private val context: ApplicationContext) {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun shouldUseConfiguredGenerator() {
|
|
||||||
assertThat(context.getBean(AnonymizingGenerator::class.java)).isNotNull
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nested
|
|
||||||
@TestPropertySource(
|
|
||||||
properties = [
|
|
||||||
"app.pseudonymize.generator=",
|
|
||||||
"app.pseudonymizer=gpas",
|
|
||||||
]
|
|
||||||
)
|
|
||||||
inner class AppConfigurationPseudonymizerGpasTest(private val context: ApplicationContext) {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun shouldUseConfiguredGenerator() {
|
|
||||||
assertThat(context.getBean(GpasPseudonymGenerator::class.java)).isNotNull
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nested
|
|
||||||
@TestPropertySource(
|
|
||||||
properties = [
|
|
||||||
"app.pseudonymize.generator=buildin",
|
|
||||||
"app.pseudonymizer=",
|
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
inner class AppConfigurationPseudonymizeGeneratorBuildinTest(private val context: ApplicationContext) {
|
inner class AppConfigurationPseudonymizeGeneratorBuildinTest(private val context: ApplicationContext) {
|
||||||
@ -229,8 +197,7 @@ class AppConfigurationTest {
|
|||||||
@Nested
|
@Nested
|
||||||
@TestPropertySource(
|
@TestPropertySource(
|
||||||
properties = [
|
properties = [
|
||||||
"app.pseudonymize.generator=gpas",
|
"app.pseudonymize.generator=gpas"
|
||||||
"app.pseudonymizer=",
|
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
inner class AppConfigurationPseudonymizeGeneratorGpasTest(private val context: ApplicationContext) {
|
inner class AppConfigurationPseudonymizeGeneratorGpasTest(private val context: ApplicationContext) {
|
||||||
@ -248,11 +215,13 @@ class AppConfigurationTest {
|
|||||||
"app.security.enable-tokens=true"
|
"app.security.enable-tokens=true"
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
@MockBeans(value = [
|
@MockitoBean(
|
||||||
MockBean(InMemoryUserDetailsManager::class),
|
types = [
|
||||||
MockBean(PasswordEncoder::class),
|
InMemoryUserDetailsManager::class,
|
||||||
MockBean(TokenRepository::class)
|
PasswordEncoder::class,
|
||||||
])
|
TokenRepository::class
|
||||||
|
]
|
||||||
|
)
|
||||||
inner class AppConfigurationTokenEnabledTest(private val context: ApplicationContext) {
|
inner class AppConfigurationTokenEnabledTest(private val context: ApplicationContext) {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -263,11 +232,13 @@ class AppConfigurationTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
@MockBeans(value = [
|
@MockitoBean(
|
||||||
MockBean(InMemoryUserDetailsManager::class),
|
types = [
|
||||||
MockBean(PasswordEncoder::class),
|
InMemoryUserDetailsManager::class,
|
||||||
MockBean(TokenRepository::class)
|
PasswordEncoder::class,
|
||||||
])
|
TokenRepository::class
|
||||||
|
]
|
||||||
|
)
|
||||||
inner class AppConfigurationTokenDisabledTest(private val context: ApplicationContext) {
|
inner class AppConfigurationTokenDisabledTest(private val context: ApplicationContext) {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -39,13 +39,13 @@ import org.mockito.junit.jupiter.MockitoExtension
|
|||||||
import org.mockito.kotlin.*
|
import org.mockito.kotlin.*
|
||||||
import org.springframework.beans.factory.annotation.Autowired
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
|
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
|
||||||
import org.springframework.boot.test.mock.mockito.MockBean
|
|
||||||
import org.springframework.http.MediaType
|
import org.springframework.http.MediaType
|
||||||
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository
|
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository
|
||||||
import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.anonymous
|
import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.anonymous
|
||||||
import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user
|
import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user
|
||||||
import org.springframework.test.context.ContextConfiguration
|
import org.springframework.test.context.ContextConfiguration
|
||||||
import org.springframework.test.context.TestPropertySource
|
import org.springframework.test.context.TestPropertySource
|
||||||
|
import org.springframework.test.context.bean.override.mockito.MockitoBean
|
||||||
import org.springframework.test.context.junit.jupiter.SpringExtension
|
import org.springframework.test.context.junit.jupiter.SpringExtension
|
||||||
import org.springframework.test.web.servlet.MockMvc
|
import org.springframework.test.web.servlet.MockMvc
|
||||||
import org.springframework.test.web.servlet.delete
|
import org.springframework.test.web.servlet.delete
|
||||||
@ -60,7 +60,7 @@ import org.springframework.test.web.servlet.post
|
|||||||
ConsentCheckedIgnored::class, ICheckConsent::class
|
ConsentCheckedIgnored::class, ICheckConsent::class
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
@MockBean(TokenRepository::class, RequestProcessor::class)
|
@MockitoBean(types = [TokenRepository::class, RequestProcessor::class])
|
||||||
@TestPropertySource(
|
@TestPropertySource(
|
||||||
properties = [
|
properties = [
|
||||||
"app.pseudonymize.generator=BUILDIN",
|
"app.pseudonymize.generator=BUILDIN",
|
||||||
@ -95,7 +95,7 @@ class MtbFileRestControllerTest {
|
|||||||
status { isAccepted() }
|
status { isAccepted() }
|
||||||
}
|
}
|
||||||
|
|
||||||
verify(requestProcessor, times(1)).processMtbFile(any())
|
verify(requestProcessor, times(1)).processMtbFile(any<MtbFile>())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -108,7 +108,7 @@ class MtbFileRestControllerTest {
|
|||||||
status { isAccepted() }
|
status { isAccepted() }
|
||||||
}
|
}
|
||||||
|
|
||||||
verify(requestProcessor, times(1)).processMtbFile(any())
|
verify(requestProcessor, times(1)).processMtbFile(any<MtbFile>())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -121,7 +121,7 @@ class MtbFileRestControllerTest {
|
|||||||
status { isUnauthorized() }
|
status { isUnauthorized() }
|
||||||
}
|
}
|
||||||
|
|
||||||
verify(requestProcessor, never()).processMtbFile(any())
|
verify(requestProcessor, never()).processMtbFile(any<MtbFile>())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -134,7 +134,7 @@ class MtbFileRestControllerTest {
|
|||||||
status { isForbidden() }
|
status { isForbidden() }
|
||||||
}
|
}
|
||||||
|
|
||||||
verify(requestProcessor, never()).processMtbFile(any())
|
verify(requestProcessor, never()).processMtbFile(any<MtbFile>())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -160,7 +160,7 @@ class MtbFileRestControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
@MockBean(UserRoleRepository::class, ClientRegistrationRepository::class)
|
@MockitoBean(types = [UserRoleRepository::class, ClientRegistrationRepository::class])
|
||||||
@TestPropertySource(
|
@TestPropertySource(
|
||||||
properties = [
|
properties = [
|
||||||
"app.pseudonymize.generator=BUILDIN",
|
"app.pseudonymize.generator=BUILDIN",
|
||||||
@ -182,7 +182,7 @@ class MtbFileRestControllerTest {
|
|||||||
status { isAccepted() }
|
status { isAccepted() }
|
||||||
}
|
}
|
||||||
|
|
||||||
verify(requestProcessor, times(1)).processMtbFile(any())
|
verify(requestProcessor, times(1)).processMtbFile(any<MtbFile>())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -195,7 +195,7 @@ class MtbFileRestControllerTest {
|
|||||||
status { isAccepted() }
|
status { isAccepted() }
|
||||||
}
|
}
|
||||||
|
|
||||||
verify(requestProcessor, times(1)).processMtbFile(any())
|
verify(requestProcessor, times(1)).processMtbFile(any<MtbFile>())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,8 +27,8 @@ import org.junit.jupiter.api.extension.ExtendWith
|
|||||||
import org.springframework.beans.factory.annotation.Autowired
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
import org.springframework.boot.test.autoconfigure.data.jdbc.DataJdbcTest
|
import org.springframework.boot.test.autoconfigure.data.jdbc.DataJdbcTest
|
||||||
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase
|
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase
|
||||||
import org.springframework.boot.test.mock.mockito.MockBean
|
|
||||||
import org.springframework.test.context.TestPropertySource
|
import org.springframework.test.context.TestPropertySource
|
||||||
|
import org.springframework.test.context.bean.override.mockito.MockitoBean
|
||||||
import org.springframework.test.context.junit.jupiter.SpringExtension
|
import org.springframework.test.context.junit.jupiter.SpringExtension
|
||||||
import org.springframework.transaction.annotation.Transactional
|
import org.springframework.transaction.annotation.Transactional
|
||||||
import org.testcontainers.junit.jupiter.Testcontainers
|
import org.testcontainers.junit.jupiter.Testcontainers
|
||||||
@ -39,7 +39,7 @@ import java.time.Instant
|
|||||||
@DataJdbcTest
|
@DataJdbcTest
|
||||||
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
|
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
|
||||||
@Transactional
|
@Transactional
|
||||||
@MockBean(MtbFileSender::class)
|
@MockitoBean(types = [MtbFileSender::class])
|
||||||
@TestPropertySource(
|
@TestPropertySource(
|
||||||
properties = [
|
properties = [
|
||||||
"app.pseudonymize.generator=buildin",
|
"app.pseudonymize.generator=buildin",
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of ETL-Processor
|
* This file is part of ETL-Processor
|
||||||
*
|
*
|
||||||
* Copyright (c) 2024 Comprehensive Cancer Center Mainfranken, Datenintegrationszentrum Philipps-Universität Marburg and Contributors
|
* Copyright (c) 2025 Comprehensive Cancer Center Mainfranken, Datenintegrationszentrum Philipps-Universität Marburg and Contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Affero General Public License as published
|
||||||
@ -49,10 +49,9 @@ class GpasPseudonymGeneratorTest {
|
|||||||
fun setup() {
|
fun setup() {
|
||||||
val retryTemplate = RetryTemplateBuilder().customPolicy(SimpleRetryPolicy(1)).build()
|
val retryTemplate = RetryTemplateBuilder().customPolicy(SimpleRetryPolicy(1)).build()
|
||||||
val gPasConfigProperties = GPasConfigProperties(
|
val gPasConfigProperties = GPasConfigProperties(
|
||||||
"http://localhost/ttp-fhir/fhir/gpas/\$pseudonymizeAllowCreate",
|
"https://localhost/ttp-fhir/fhir/gpas/\$pseudonymizeAllowCreate",
|
||||||
"test",
|
"test",
|
||||||
null,
|
null,
|
||||||
null,
|
|
||||||
null
|
null
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -66,7 +65,7 @@ class GpasPseudonymGeneratorTest {
|
|||||||
fun shouldReturnExpectedPseudonym() {
|
fun shouldReturnExpectedPseudonym() {
|
||||||
this.mockRestServiceServer.expect {
|
this.mockRestServiceServer.expect {
|
||||||
method(HttpMethod.POST)
|
method(HttpMethod.POST)
|
||||||
requestTo("http://localhost/ttp-fhir/fhir/gpas/\$pseudonymizeAllowCreate")
|
requestTo("https://localhost/ttp-fhir/fhir/gpas/\$pseudonymizeAllowCreate")
|
||||||
}.andRespond {
|
}.andRespond {
|
||||||
withStatus(HttpStatus.OK).body(
|
withStatus(HttpStatus.OK).body(
|
||||||
getDummyResponseBody(
|
getDummyResponseBody(
|
||||||
@ -85,7 +84,7 @@ class GpasPseudonymGeneratorTest {
|
|||||||
fun shouldThrowExceptionIfGpasNotAvailable() {
|
fun shouldThrowExceptionIfGpasNotAvailable() {
|
||||||
this.mockRestServiceServer.expect {
|
this.mockRestServiceServer.expect {
|
||||||
method(HttpMethod.POST)
|
method(HttpMethod.POST)
|
||||||
requestTo("http://localhost/ttp-fhir/fhir/gpas/\$pseudonymizeAllowCreate")
|
requestTo("https://localhost/ttp-fhir/fhir/gpas/\$pseudonymizeAllowCreate")
|
||||||
}.andRespond {
|
}.andRespond {
|
||||||
withException(IOException("Simulated IO error")).createResponse(it)
|
withException(IOException("Simulated IO error")).createResponse(it)
|
||||||
}
|
}
|
||||||
@ -97,7 +96,7 @@ class GpasPseudonymGeneratorTest {
|
|||||||
fun shouldThrowExceptionIfGpasDoesNotReturn2xxResponse() {
|
fun shouldThrowExceptionIfGpasDoesNotReturn2xxResponse() {
|
||||||
this.mockRestServiceServer.expect {
|
this.mockRestServiceServer.expect {
|
||||||
method(HttpMethod.POST)
|
method(HttpMethod.POST)
|
||||||
requestTo("http://localhost/ttp-fhir/fhir/gpas/\$pseudonymizeAllowCreate")
|
requestTo("https://localhost/ttp-fhir/fhir/gpas/\$pseudonymizeAllowCreate")
|
||||||
}.andRespond {
|
}.andRespond {
|
||||||
withStatus(HttpStatus.FOUND)
|
withStatus(HttpStatus.FOUND)
|
||||||
.header(
|
.header(
|
||||||
|
@ -31,8 +31,8 @@ import org.junit.jupiter.api.Test
|
|||||||
import org.junit.jupiter.api.extension.ExtendWith
|
import org.junit.jupiter.api.extension.ExtendWith
|
||||||
import org.springframework.beans.factory.annotation.Autowired
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
import org.springframework.boot.test.context.SpringBootTest
|
import org.springframework.boot.test.context.SpringBootTest
|
||||||
import org.springframework.boot.test.mock.mockito.MockBean
|
|
||||||
import org.springframework.test.context.TestPropertySource
|
import org.springframework.test.context.TestPropertySource
|
||||||
|
import org.springframework.test.context.bean.override.mockito.MockitoBean
|
||||||
import org.springframework.test.context.junit.jupiter.SpringExtension
|
import org.springframework.test.context.junit.jupiter.SpringExtension
|
||||||
import org.springframework.transaction.annotation.Transactional
|
import org.springframework.transaction.annotation.Transactional
|
||||||
import org.testcontainers.junit.jupiter.Testcontainers
|
import org.testcontainers.junit.jupiter.Testcontainers
|
||||||
@ -42,7 +42,7 @@ import java.time.Instant
|
|||||||
@ExtendWith(SpringExtension::class)
|
@ExtendWith(SpringExtension::class)
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@Transactional
|
@Transactional
|
||||||
@MockBean(MtbFileSender::class)
|
@MockitoBean(types = [MtbFileSender::class])
|
||||||
@TestPropertySource(
|
@TestPropertySource(
|
||||||
properties = [
|
properties = [
|
||||||
"app.pseudonymize.generator=buildin",
|
"app.pseudonymize.generator=buildin",
|
||||||
|
@ -19,8 +19,6 @@
|
|||||||
|
|
||||||
package dev.dnpm.etl.processor.web
|
package dev.dnpm.etl.processor.web
|
||||||
|
|
||||||
import com.gargoylesoftware.htmlunit.WebClient
|
|
||||||
import com.gargoylesoftware.htmlunit.html.HtmlPage
|
|
||||||
import dev.dnpm.etl.processor.config.AppConfiguration
|
import dev.dnpm.etl.processor.config.AppConfiguration
|
||||||
import dev.dnpm.etl.processor.config.AppSecurityConfiguration
|
import dev.dnpm.etl.processor.config.AppSecurityConfiguration
|
||||||
import dev.dnpm.etl.processor.monitoring.ConnectionCheckResult
|
import dev.dnpm.etl.processor.monitoring.ConnectionCheckResult
|
||||||
@ -29,11 +27,13 @@ import dev.dnpm.etl.processor.monitoring.RestConnectionCheckService
|
|||||||
import dev.dnpm.etl.processor.output.MtbFileSender
|
import dev.dnpm.etl.processor.output.MtbFileSender
|
||||||
import dev.dnpm.etl.processor.pseudonym.Generator
|
import dev.dnpm.etl.processor.pseudonym.Generator
|
||||||
import dev.dnpm.etl.processor.security.Role
|
import dev.dnpm.etl.processor.security.Role
|
||||||
import dev.dnpm.etl.processor.services.RequestProcessor
|
|
||||||
import dev.dnpm.etl.processor.security.TokenService
|
import dev.dnpm.etl.processor.security.TokenService
|
||||||
import dev.dnpm.etl.processor.services.TransformationService
|
|
||||||
import dev.dnpm.etl.processor.security.UserRoleService
|
import dev.dnpm.etl.processor.security.UserRoleService
|
||||||
|
import dev.dnpm.etl.processor.services.RequestProcessor
|
||||||
|
import dev.dnpm.etl.processor.services.TransformationService
|
||||||
import org.assertj.core.api.Assertions.assertThat
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
|
import org.htmlunit.WebClient
|
||||||
|
import org.htmlunit.html.HtmlPage
|
||||||
import org.junit.jupiter.api.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
import org.junit.jupiter.api.Nested
|
import org.junit.jupiter.api.Nested
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
@ -46,7 +46,6 @@ import org.mockito.kotlin.verify
|
|||||||
import org.mockito.kotlin.whenever
|
import org.mockito.kotlin.whenever
|
||||||
import org.springframework.beans.factory.annotation.Autowired
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
|
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
|
||||||
import org.springframework.boot.test.mock.mockito.MockBean
|
|
||||||
import org.springframework.http.HttpHeaders
|
import org.springframework.http.HttpHeaders
|
||||||
import org.springframework.http.MediaType
|
import org.springframework.http.MediaType
|
||||||
import org.springframework.http.MediaType.TEXT_EVENT_STREAM
|
import org.springframework.http.MediaType.TEXT_EVENT_STREAM
|
||||||
@ -55,6 +54,7 @@ import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequ
|
|||||||
import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user
|
import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user
|
||||||
import org.springframework.test.context.ContextConfiguration
|
import org.springframework.test.context.ContextConfiguration
|
||||||
import org.springframework.test.context.TestPropertySource
|
import org.springframework.test.context.TestPropertySource
|
||||||
|
import org.springframework.test.context.bean.override.mockito.MockitoBean
|
||||||
import org.springframework.test.context.junit.jupiter.SpringExtension
|
import org.springframework.test.context.junit.jupiter.SpringExtension
|
||||||
import org.springframework.test.web.reactive.server.WebTestClient
|
import org.springframework.test.web.reactive.server.WebTestClient
|
||||||
import org.springframework.test.web.servlet.*
|
import org.springframework.test.web.servlet.*
|
||||||
@ -81,14 +81,16 @@ abstract class MockSink : Sinks.Many<Boolean>
|
|||||||
"app.pseudonymize.generator=BUILDIN"
|
"app.pseudonymize.generator=BUILDIN"
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
@MockBean(name = "configsUpdateProducer", classes = [MockSink::class])
|
@MockitoBean(name = "configsUpdateProducer", types = [MockSink::class])
|
||||||
@MockBean(
|
@MockitoBean(
|
||||||
|
types = [
|
||||||
Generator::class,
|
Generator::class,
|
||||||
MtbFileSender::class,
|
MtbFileSender::class,
|
||||||
RequestProcessor::class,
|
RequestProcessor::class,
|
||||||
TransformationService::class,
|
TransformationService::class,
|
||||||
GPasConnectionCheckService::class,
|
GPasConnectionCheckService::class,
|
||||||
RestConnectionCheckService::class,
|
RestConnectionCheckService::class
|
||||||
|
]
|
||||||
)
|
)
|
||||||
class ConfigControllerTest {
|
class ConfigControllerTest {
|
||||||
|
|
||||||
@ -143,8 +145,10 @@ class ConfigControllerTest {
|
|||||||
"app.security.admin-user=admin"
|
"app.security.admin-user=admin"
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
@MockBean(
|
@MockitoBean(
|
||||||
|
types = [
|
||||||
TokenService::class
|
TokenService::class
|
||||||
|
]
|
||||||
)
|
)
|
||||||
inner class WithTokensEnabled {
|
inner class WithTokensEnabled {
|
||||||
private lateinit var tokenService: TokenService
|
private lateinit var tokenService: TokenService
|
||||||
@ -252,8 +256,10 @@ class ConfigControllerTest {
|
|||||||
"app.security.admin-password={noop}very-secret"
|
"app.security.admin-password={noop}very-secret"
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
@MockBean(
|
@MockitoBean(
|
||||||
|
types = [
|
||||||
UserRoleService::class
|
UserRoleService::class
|
||||||
|
]
|
||||||
)
|
)
|
||||||
inner class WithUserRolesEnabled {
|
inner class WithUserRolesEnabled {
|
||||||
private lateinit var userRoleService: UserRoleService
|
private lateinit var userRoleService: UserRoleService
|
||||||
|
@ -19,8 +19,6 @@
|
|||||||
|
|
||||||
package dev.dnpm.etl.processor.web
|
package dev.dnpm.etl.processor.web
|
||||||
|
|
||||||
import com.gargoylesoftware.htmlunit.WebClient
|
|
||||||
import com.gargoylesoftware.htmlunit.html.HtmlPage
|
|
||||||
import dev.dnpm.etl.processor.*
|
import dev.dnpm.etl.processor.*
|
||||||
import dev.dnpm.etl.processor.config.AppConfiguration
|
import dev.dnpm.etl.processor.config.AppConfiguration
|
||||||
import dev.dnpm.etl.processor.config.AppSecurityConfiguration
|
import dev.dnpm.etl.processor.config.AppSecurityConfiguration
|
||||||
@ -30,6 +28,8 @@ import dev.dnpm.etl.processor.monitoring.RequestStatus
|
|||||||
import dev.dnpm.etl.processor.monitoring.RequestType
|
import dev.dnpm.etl.processor.monitoring.RequestType
|
||||||
import dev.dnpm.etl.processor.services.RequestService
|
import dev.dnpm.etl.processor.services.RequestService
|
||||||
import org.assertj.core.api.Assertions.assertThat
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
|
import org.htmlunit.WebClient
|
||||||
|
import org.htmlunit.html.HtmlPage
|
||||||
import org.junit.jupiter.api.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
import org.junit.jupiter.api.Nested
|
import org.junit.jupiter.api.Nested
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
@ -40,13 +40,13 @@ import org.mockito.kotlin.any
|
|||||||
import org.mockito.kotlin.whenever
|
import org.mockito.kotlin.whenever
|
||||||
import org.springframework.beans.factory.annotation.Autowired
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
|
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
|
||||||
import org.springframework.boot.test.mock.mockito.MockBean
|
|
||||||
import org.springframework.data.domain.Page
|
import org.springframework.data.domain.Page
|
||||||
import org.springframework.data.domain.PageImpl
|
import org.springframework.data.domain.PageImpl
|
||||||
import org.springframework.data.domain.Pageable
|
import org.springframework.data.domain.Pageable
|
||||||
import org.springframework.security.test.context.support.WithMockUser
|
import org.springframework.security.test.context.support.WithMockUser
|
||||||
import org.springframework.test.context.ContextConfiguration
|
import org.springframework.test.context.ContextConfiguration
|
||||||
import org.springframework.test.context.TestPropertySource
|
import org.springframework.test.context.TestPropertySource
|
||||||
|
import org.springframework.test.context.bean.override.mockito.MockitoBean
|
||||||
import org.springframework.test.context.junit.jupiter.SpringExtension
|
import org.springframework.test.context.junit.jupiter.SpringExtension
|
||||||
import org.springframework.test.web.servlet.MockMvc
|
import org.springframework.test.web.servlet.MockMvc
|
||||||
import org.springframework.test.web.servlet.get
|
import org.springframework.test.web.servlet.get
|
||||||
@ -71,8 +71,8 @@ import java.util.*
|
|||||||
"app.security.admin-password={noop}very-secret"
|
"app.security.admin-password={noop}very-secret"
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
@MockBean(
|
@MockitoBean(
|
||||||
RequestService::class
|
types = [RequestService::class]
|
||||||
)
|
)
|
||||||
class HomeControllerTest {
|
class HomeControllerTest {
|
||||||
|
|
||||||
|
@ -19,21 +19,21 @@
|
|||||||
|
|
||||||
package dev.dnpm.etl.processor.web
|
package dev.dnpm.etl.processor.web
|
||||||
|
|
||||||
import com.gargoylesoftware.htmlunit.WebClient
|
|
||||||
import com.gargoylesoftware.htmlunit.html.HtmlPage
|
|
||||||
import dev.dnpm.etl.processor.config.AppConfiguration
|
import dev.dnpm.etl.processor.config.AppConfiguration
|
||||||
import dev.dnpm.etl.processor.config.AppSecurityConfiguration
|
import dev.dnpm.etl.processor.config.AppSecurityConfiguration
|
||||||
import dev.dnpm.etl.processor.security.TokenService
|
import dev.dnpm.etl.processor.security.TokenService
|
||||||
import org.assertj.core.api.Assertions.assertThat
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
|
import org.htmlunit.WebClient
|
||||||
|
import org.htmlunit.html.HtmlPage
|
||||||
import org.junit.jupiter.api.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.jupiter.api.extension.ExtendWith
|
import org.junit.jupiter.api.extension.ExtendWith
|
||||||
import org.mockito.junit.jupiter.MockitoExtension
|
import org.mockito.junit.jupiter.MockitoExtension
|
||||||
import org.springframework.beans.factory.annotation.Autowired
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
|
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
|
||||||
import org.springframework.boot.test.mock.mockito.MockBean
|
|
||||||
import org.springframework.test.context.ContextConfiguration
|
import org.springframework.test.context.ContextConfiguration
|
||||||
import org.springframework.test.context.TestPropertySource
|
import org.springframework.test.context.TestPropertySource
|
||||||
|
import org.springframework.test.context.bean.override.mockito.MockitoBean
|
||||||
import org.springframework.test.context.junit.jupiter.SpringExtension
|
import org.springframework.test.context.junit.jupiter.SpringExtension
|
||||||
import org.springframework.test.web.servlet.MockMvc
|
import org.springframework.test.web.servlet.MockMvc
|
||||||
import org.springframework.test.web.servlet.get
|
import org.springframework.test.web.servlet.get
|
||||||
@ -56,8 +56,8 @@ import org.springframework.test.web.servlet.htmlunit.MockMvcWebClientBuilder
|
|||||||
"app.security.enable-tokens=true"
|
"app.security.enable-tokens=true"
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
@MockBean(
|
@MockitoBean(
|
||||||
TokenService::class,
|
types = [TokenService::class]
|
||||||
)
|
)
|
||||||
class LoginControllerTest {
|
class LoginControllerTest {
|
||||||
|
|
||||||
|
@ -19,9 +19,9 @@
|
|||||||
|
|
||||||
package dev.dnpm.etl.processor.web
|
package dev.dnpm.etl.processor.web
|
||||||
|
|
||||||
import com.gargoylesoftware.htmlunit.WebClient
|
|
||||||
import dev.dnpm.etl.processor.config.AppConfiguration
|
import dev.dnpm.etl.processor.config.AppConfiguration
|
||||||
import dev.dnpm.etl.processor.config.AppSecurityConfiguration
|
import dev.dnpm.etl.processor.config.AppSecurityConfiguration
|
||||||
|
import org.htmlunit.WebClient
|
||||||
import org.junit.jupiter.api.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.jupiter.api.extension.ExtendWith
|
import org.junit.jupiter.api.extension.ExtendWith
|
||||||
|
@ -41,10 +41,10 @@ import org.mockito.kotlin.doAnswer
|
|||||||
import org.mockito.kotlin.whenever
|
import org.mockito.kotlin.whenever
|
||||||
import org.springframework.beans.factory.annotation.Autowired
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
|
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
|
||||||
import org.springframework.boot.test.mock.mockito.MockBean
|
|
||||||
import org.springframework.http.MediaType.TEXT_EVENT_STREAM
|
import org.springframework.http.MediaType.TEXT_EVENT_STREAM
|
||||||
import org.springframework.test.context.ContextConfiguration
|
import org.springframework.test.context.ContextConfiguration
|
||||||
import org.springframework.test.context.TestPropertySource
|
import org.springframework.test.context.TestPropertySource
|
||||||
|
import org.springframework.test.context.bean.override.mockito.MockitoBean
|
||||||
import org.springframework.test.context.junit.jupiter.SpringExtension
|
import org.springframework.test.context.junit.jupiter.SpringExtension
|
||||||
import org.springframework.test.web.reactive.server.WebTestClient
|
import org.springframework.test.web.reactive.server.WebTestClient
|
||||||
import org.springframework.test.web.servlet.MockMvc
|
import org.springframework.test.web.servlet.MockMvc
|
||||||
@ -54,6 +54,7 @@ import org.springframework.web.context.WebApplicationContext
|
|||||||
import reactor.core.publisher.Sinks
|
import reactor.core.publisher.Sinks
|
||||||
import reactor.test.StepVerifier
|
import reactor.test.StepVerifier
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
|
import java.time.ZoneId
|
||||||
import java.time.temporal.ChronoUnit
|
import java.time.temporal.ChronoUnit
|
||||||
|
|
||||||
|
|
||||||
@ -73,8 +74,8 @@ import java.time.temporal.ChronoUnit
|
|||||||
"app.security.admin-password={noop}very-secret"
|
"app.security.admin-password={noop}very-secret"
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
@MockBean(
|
@MockitoBean(
|
||||||
RequestService::class
|
types = [RequestService::class]
|
||||||
)
|
)
|
||||||
class StatisticsRestControllerTest {
|
class StatisticsRestControllerTest {
|
||||||
|
|
||||||
@ -185,6 +186,7 @@ class StatisticsRestControllerTest {
|
|||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
fun setup() {
|
fun setup() {
|
||||||
|
val zoneId = ZoneId.of("Europe/Berlin")
|
||||||
doAnswer { _ ->
|
doAnswer { _ ->
|
||||||
listOf(
|
listOf(
|
||||||
Request(
|
Request(
|
||||||
@ -195,7 +197,7 @@ class StatisticsRestControllerTest {
|
|||||||
Fingerprint("0123456789abcdef1"),
|
Fingerprint("0123456789abcdef1"),
|
||||||
RequestType.MTB_FILE,
|
RequestType.MTB_FILE,
|
||||||
RequestStatus.SUCCESS,
|
RequestStatus.SUCCESS,
|
||||||
Instant.now().truncatedTo(ChronoUnit.DAYS).minus(2, ChronoUnit.DAYS)
|
Instant.now().atZone(zoneId).truncatedTo(ChronoUnit.DAYS).minus(2, ChronoUnit.DAYS).toInstant()
|
||||||
),
|
),
|
||||||
Request(
|
Request(
|
||||||
2,
|
2,
|
||||||
@ -205,7 +207,7 @@ class StatisticsRestControllerTest {
|
|||||||
Fingerprint("0123456789abcdef2"),
|
Fingerprint("0123456789abcdef2"),
|
||||||
RequestType.MTB_FILE,
|
RequestType.MTB_FILE,
|
||||||
RequestStatus.WARNING,
|
RequestStatus.WARNING,
|
||||||
Instant.now().truncatedTo(ChronoUnit.DAYS).minus(2, ChronoUnit.DAYS)
|
Instant.now().atZone(zoneId).truncatedTo(ChronoUnit.DAYS).minus(2, ChronoUnit.DAYS).toInstant()
|
||||||
),
|
),
|
||||||
Request(
|
Request(
|
||||||
3,
|
3,
|
||||||
@ -215,7 +217,7 @@ class StatisticsRestControllerTest {
|
|||||||
Fingerprint("0123456789abcdee1"),
|
Fingerprint("0123456789abcdee1"),
|
||||||
RequestType.DELETE,
|
RequestType.DELETE,
|
||||||
RequestStatus.ERROR,
|
RequestStatus.ERROR,
|
||||||
Instant.now().truncatedTo(ChronoUnit.DAYS).minus(1, ChronoUnit.DAYS)
|
Instant.now().atZone(zoneId).truncatedTo(ChronoUnit.DAYS).minus(1, ChronoUnit.DAYS).toInstant()
|
||||||
),
|
),
|
||||||
Request(
|
Request(
|
||||||
4,
|
4,
|
||||||
@ -225,7 +227,7 @@ class StatisticsRestControllerTest {
|
|||||||
Fingerprint("0123456789abcdef2"),
|
Fingerprint("0123456789abcdef2"),
|
||||||
RequestType.MTB_FILE,
|
RequestType.MTB_FILE,
|
||||||
RequestStatus.DUPLICATION,
|
RequestStatus.DUPLICATION,
|
||||||
Instant.now().truncatedTo(ChronoUnit.DAYS).minus(1, ChronoUnit.DAYS)
|
Instant.now().atZone(zoneId).truncatedTo(ChronoUnit.DAYS).minus(1, ChronoUnit.DAYS).toInstant()
|
||||||
),
|
),
|
||||||
Request(
|
Request(
|
||||||
5,
|
5,
|
||||||
@ -235,7 +237,7 @@ class StatisticsRestControllerTest {
|
|||||||
Fingerprint("0123456789abcdef2"),
|
Fingerprint("0123456789abcdef2"),
|
||||||
RequestType.DELETE,
|
RequestType.DELETE,
|
||||||
RequestStatus.UNKNOWN,
|
RequestStatus.UNKNOWN,
|
||||||
Instant.now().truncatedTo(ChronoUnit.DAYS)
|
Instant.now().atZone(zoneId).truncatedTo(ChronoUnit.DAYS).toInstant()
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}.whenever(requestService).findAll()
|
}.whenever(requestService).findAll()
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of ETL-Processor
|
* This file is part of ETL-Processor
|
||||||
*
|
*
|
||||||
* Copyright (c) 2024 Comprehensive Cancer Center Mainfranken, Datenintegrationszentrum Philipps-Universität Marburg and Contributors
|
* Copyright (c) 2025 Comprehensive Cancer Center Mainfranken, Datenintegrationszentrum Philipps-Universität Marburg and Contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Affero General Public License as published
|
||||||
@ -21,16 +21,10 @@ package dev.dnpm.etl.processor.config
|
|||||||
|
|
||||||
import dev.dnpm.etl.processor.security.Role
|
import dev.dnpm.etl.processor.security.Role
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties
|
import org.springframework.boot.context.properties.ConfigurationProperties
|
||||||
import org.springframework.boot.context.properties.DeprecatedConfigurationProperty
|
|
||||||
|
|
||||||
@ConfigurationProperties(AppConfigProperties.NAME)
|
@ConfigurationProperties(AppConfigProperties.NAME)
|
||||||
data class AppConfigProperties(
|
data class AppConfigProperties(
|
||||||
var bwhcUri: String?,
|
var bwhcUri: String?,
|
||||||
@get:DeprecatedConfigurationProperty(
|
|
||||||
reason = "Deprecated in favor of 'app.pseudonymize.generator'",
|
|
||||||
replacement = "app.pseudonymize.generator"
|
|
||||||
)
|
|
||||||
var pseudonymizer: PseudonymGenerator = PseudonymGenerator.BUILDIN,
|
|
||||||
var transformations: List<TransformationProperties> = listOf(),
|
var transformations: List<TransformationProperties> = listOf(),
|
||||||
var maxRetryAttempts: Int = 3,
|
var maxRetryAttempts: Int = 3,
|
||||||
var duplicationDetection: Boolean = true
|
var duplicationDetection: Boolean = true
|
||||||
@ -56,10 +50,6 @@ data class GPasConfigProperties(
|
|||||||
val target: String = "etl-processor",
|
val target: String = "etl-processor",
|
||||||
val username: String?,
|
val username: String?,
|
||||||
val password: String?,
|
val password: String?,
|
||||||
@get:DeprecatedConfigurationProperty(
|
|
||||||
reason = "Deprecated in favor of including Root CA"
|
|
||||||
)
|
|
||||||
val sslCaLocation: String?
|
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
const val NAME = "app.pseudonymize.gpas"
|
const val NAME = "app.pseudonymize.gpas"
|
||||||
@ -113,6 +103,9 @@ data class GIcsConfigProperties(
|
|||||||
@ConfigurationProperties(RestTargetProperties.NAME)
|
@ConfigurationProperties(RestTargetProperties.NAME)
|
||||||
data class RestTargetProperties(
|
data class RestTargetProperties(
|
||||||
val uri: String?,
|
val uri: String?,
|
||||||
|
val username: String?,
|
||||||
|
val password: String?,
|
||||||
|
val isBwhc: Boolean = false,
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
const val NAME = "app.rest"
|
const val NAME = "app.rest"
|
||||||
@ -123,18 +116,8 @@ data class RestTargetProperties(
|
|||||||
data class KafkaProperties(
|
data class KafkaProperties(
|
||||||
val inputTopic: String?,
|
val inputTopic: String?,
|
||||||
val outputTopic: String = "etl-processor",
|
val outputTopic: String = "etl-processor",
|
||||||
@get:DeprecatedConfigurationProperty(
|
|
||||||
reason = "Deprecated",
|
|
||||||
replacement = "outputTopic"
|
|
||||||
)
|
|
||||||
val topic: String = outputTopic,
|
|
||||||
val outputResponseTopic: String = "${outputTopic}_response",
|
val outputResponseTopic: String = "${outputTopic}_response",
|
||||||
@get:DeprecatedConfigurationProperty(
|
val groupId: String = "${outputTopic}_group",
|
||||||
reason = "Deprecated",
|
|
||||||
replacement = "outputResponseTopic"
|
|
||||||
)
|
|
||||||
val responseTopic: String = outputResponseTopic,
|
|
||||||
val groupId: String = "${topic}_group",
|
|
||||||
val servers: String = ""
|
val servers: String = ""
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of ETL-Processor
|
* This file is part of ETL-Processor
|
||||||
*
|
*
|
||||||
* Copyright (c) 2024 Comprehensive Cancer Center Mainfranken, Datenintegrationszentrum Philipps-Universität Marburg and Contributors
|
* Copyright (c) 2025 Comprehensive Cancer Center Mainfranken, Datenintegrationszentrum Philipps-Universität Marburg and Contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Affero General Public License as published
|
||||||
@ -35,12 +35,6 @@ import dev.dnpm.etl.processor.security.TokenRepository
|
|||||||
import dev.dnpm.etl.processor.security.TokenService
|
import dev.dnpm.etl.processor.security.TokenService
|
||||||
import dev.dnpm.etl.processor.services.Transformation
|
import dev.dnpm.etl.processor.services.Transformation
|
||||||
import dev.dnpm.etl.processor.services.TransformationService
|
import dev.dnpm.etl.processor.services.TransformationService
|
||||||
import org.apache.hc.client5.http.impl.classic.HttpClients
|
|
||||||
import org.apache.hc.client5.http.impl.io.BasicHttpClientConnectionManager
|
|
||||||
import org.apache.hc.client5.http.socket.ConnectionSocketFactory
|
|
||||||
import org.apache.hc.client5.http.socket.PlainConnectionSocketFactory
|
|
||||||
import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory
|
|
||||||
import org.apache.hc.core5.http.config.RegistryBuilder
|
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
|
||||||
@ -48,7 +42,6 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
|
|||||||
import org.springframework.context.annotation.Bean
|
import org.springframework.context.annotation.Bean
|
||||||
import org.springframework.context.annotation.Configuration
|
import org.springframework.context.annotation.Configuration
|
||||||
import org.springframework.data.jdbc.repository.config.AbstractJdbcConfiguration
|
import org.springframework.data.jdbc.repository.config.AbstractJdbcConfiguration
|
||||||
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory
|
|
||||||
import org.springframework.retry.RetryCallback
|
import org.springframework.retry.RetryCallback
|
||||||
import org.springframework.retry.RetryContext
|
import org.springframework.retry.RetryContext
|
||||||
import org.springframework.retry.RetryListener
|
import org.springframework.retry.RetryListener
|
||||||
@ -58,15 +51,9 @@ import org.springframework.retry.support.RetryTemplateBuilder
|
|||||||
import org.springframework.scheduling.annotation.EnableScheduling
|
import org.springframework.scheduling.annotation.EnableScheduling
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder
|
import org.springframework.security.crypto.password.PasswordEncoder
|
||||||
import org.springframework.security.provisioning.InMemoryUserDetailsManager
|
import org.springframework.security.provisioning.InMemoryUserDetailsManager
|
||||||
|
import org.springframework.web.client.HttpClientErrorException
|
||||||
import org.springframework.web.client.RestTemplate
|
import org.springframework.web.client.RestTemplate
|
||||||
import reactor.core.publisher.Sinks
|
import reactor.core.publisher.Sinks
|
||||||
import java.io.BufferedInputStream
|
|
||||||
import java.io.FileInputStream
|
|
||||||
import java.security.KeyStore
|
|
||||||
import java.security.cert.CertificateFactory
|
|
||||||
import java.security.cert.X509Certificate
|
|
||||||
import javax.net.ssl.SSLContext
|
|
||||||
import javax.net.ssl.TrustManagerFactory
|
|
||||||
import kotlin.time.Duration.Companion.seconds
|
import kotlin.time.Duration.Companion.seconds
|
||||||
import kotlin.time.toJavaDuration
|
import kotlin.time.toJavaDuration
|
||||||
|
|
||||||
@ -97,20 +84,8 @@ class AppConfiguration {
|
|||||||
|
|
||||||
@ConditionalOnProperty(value = ["app.pseudonymize.generator"], havingValue = "GPAS")
|
@ConditionalOnProperty(value = ["app.pseudonymize.generator"], havingValue = "GPAS")
|
||||||
@Bean
|
@Bean
|
||||||
fun gpasPseudonymGenerator(configProperties: GPasConfigProperties, retryTemplate: RetryTemplate, restTemplate: RestTemplate, appFhirConfig: AppFhirConfig): Generator {
|
fun gpasPseudonymGenerator(configProperties: GPasConfigProperties, retryTemplate: RetryTemplate, restTemplate: RestTemplate): Generator {
|
||||||
try {
|
return GpasPseudonymGenerator(configProperties, retryTemplate, restTemplate)
|
||||||
if (!configProperties.sslCaLocation.isNullOrBlank()) {
|
|
||||||
return GpasPseudonymGenerator(
|
|
||||||
configProperties,
|
|
||||||
retryTemplate,
|
|
||||||
createCustomGpasRestTemplate(configProperties),appFhirConfig
|
|
||||||
)
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
throw RuntimeException(e)
|
|
||||||
}
|
|
||||||
|
|
||||||
return GpasPseudonymGenerator(configProperties, retryTemplate, restTemplate,appFhirConfig)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ConditionalOnProperty(value = ["app.pseudonymize.generator"], havingValue = "BUILDIN", matchIfMissing = true)
|
@ConditionalOnProperty(value = ["app.pseudonymize.generator"], havingValue = "BUILDIN", matchIfMissing = true)
|
||||||
@ -119,92 +94,6 @@ class AppConfiguration {
|
|||||||
return AnonymizingGenerator()
|
return AnonymizingGenerator()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ConditionalOnProperty(value = ["app.pseudonymizer"], havingValue = "GPAS")
|
|
||||||
@ConditionalOnMissingBean
|
|
||||||
@Bean
|
|
||||||
fun gpasPseudonymGeneratorOnDeprecatedProperty(configProperties: GPasConfigProperties, retryTemplate: RetryTemplate, restTemplate: RestTemplate, appFhirConfig: AppFhirConfig): Generator {
|
|
||||||
try {
|
|
||||||
if (!configProperties.sslCaLocation.isNullOrBlank()) {
|
|
||||||
return GpasPseudonymGenerator(
|
|
||||||
configProperties,
|
|
||||||
retryTemplate,
|
|
||||||
createCustomGpasRestTemplate(configProperties),appFhirConfig
|
|
||||||
)
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
throw RuntimeException(e)
|
|
||||||
}
|
|
||||||
|
|
||||||
return GpasPseudonymGenerator(configProperties, retryTemplate, restTemplate,appFhirConfig)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun createCustomGpasRestTemplate(configProperties: GPasConfigProperties): RestTemplate {
|
|
||||||
fun getSslContext(certificateLocation: String): SSLContext? {
|
|
||||||
val ks = KeyStore.getInstance(KeyStore.getDefaultType())
|
|
||||||
|
|
||||||
val fis = FileInputStream(certificateLocation)
|
|
||||||
val ca = CertificateFactory.getInstance("X.509")
|
|
||||||
.generateCertificate(BufferedInputStream(fis)) as X509Certificate
|
|
||||||
|
|
||||||
ks.load(null, null)
|
|
||||||
ks.setCertificateEntry(1.toString(), ca)
|
|
||||||
|
|
||||||
val tmf = TrustManagerFactory.getInstance(
|
|
||||||
TrustManagerFactory.getDefaultAlgorithm()
|
|
||||||
)
|
|
||||||
tmf.init(ks)
|
|
||||||
|
|
||||||
val sslContext = SSLContext.getInstance("TLS")
|
|
||||||
sslContext.init(null, tmf.trustManagers, null)
|
|
||||||
|
|
||||||
return sslContext
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getCustomRestTemplate(customSslContext: SSLContext): RestTemplate {
|
|
||||||
val sslsf = SSLConnectionSocketFactory(customSslContext)
|
|
||||||
val socketFactoryRegistry = RegistryBuilder.create<ConnectionSocketFactory>()
|
|
||||||
.register("https", sslsf).register("http", PlainConnectionSocketFactory()).build()
|
|
||||||
|
|
||||||
val connectionManager = BasicHttpClientConnectionManager(
|
|
||||||
socketFactoryRegistry
|
|
||||||
)
|
|
||||||
val httpClient = HttpClients.custom()
|
|
||||||
.setConnectionManager(connectionManager).build()
|
|
||||||
|
|
||||||
val requestFactory = HttpComponentsClientHttpRequestFactory(
|
|
||||||
httpClient
|
|
||||||
)
|
|
||||||
return RestTemplate(requestFactory)
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!configProperties.sslCaLocation.isNullOrBlank()) {
|
|
||||||
val customSslContext = getSslContext(configProperties.sslCaLocation)
|
|
||||||
logger.warn(
|
|
||||||
String.format(
|
|
||||||
"%s has been initialized with SSL certificate %s. This is deprecated in favor of including Root CA.",
|
|
||||||
this.javaClass.name, configProperties.sslCaLocation
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if (customSslContext != null) {
|
|
||||||
return getCustomRestTemplate(customSslContext)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
throw RuntimeException(e)
|
|
||||||
}
|
|
||||||
|
|
||||||
throw RuntimeException("Custom SSL configuration for gPAS not usable")
|
|
||||||
}
|
|
||||||
|
|
||||||
@ConditionalOnProperty(value = ["app.pseudonymizer"], havingValue = "BUILDIN")
|
|
||||||
@ConditionalOnMissingBean
|
|
||||||
@Bean
|
|
||||||
fun buildinPseudonymGeneratorOnDeprecatedProperty(): Generator {
|
|
||||||
return AnonymizingGenerator()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
fun pseudonymizeService(
|
fun pseudonymizeService(
|
||||||
generator: Generator,
|
generator: Generator,
|
||||||
@ -233,6 +122,8 @@ class AppConfiguration {
|
|||||||
fun retryTemplate(configProperties: AppConfigProperties): RetryTemplate {
|
fun retryTemplate(configProperties: AppConfigProperties): RetryTemplate {
|
||||||
return RetryTemplateBuilder()
|
return RetryTemplateBuilder()
|
||||||
.notRetryOn(IllegalArgumentException::class.java)
|
.notRetryOn(IllegalArgumentException::class.java)
|
||||||
|
.notRetryOn(HttpClientErrorException.BadRequest::class.java)
|
||||||
|
.notRetryOn(HttpClientErrorException.UnprocessableEntity::class.java)
|
||||||
.exponentialBackoff(2.seconds.toJavaDuration(), 1.25, 5.seconds.toJavaDuration())
|
.exponentialBackoff(2.seconds.toJavaDuration(), 1.25, 5.seconds.toJavaDuration())
|
||||||
.customPolicy(SimpleRetryPolicy(configProperties.maxRetryAttempts))
|
.customPolicy(SimpleRetryPolicy(configProperties.maxRetryAttempts))
|
||||||
.withListener(object : RetryListener {
|
.withListener(object : RetryListener {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of ETL-Processor
|
* This file is part of ETL-Processor
|
||||||
*
|
*
|
||||||
* Copyright (c) 2024 Comprehensive Cancer Center Mainfranken, Datenintegrationszentrum Philipps-Universität Marburg and Contributors
|
* Copyright (c) 2025 Comprehensive Cancer Center Mainfranken, Datenintegrationszentrum Philipps-Universität Marburg and Contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Affero General Public License as published
|
||||||
@ -71,7 +71,7 @@ class AppKafkaConfiguration {
|
|||||||
kafkaProperties: KafkaProperties,
|
kafkaProperties: KafkaProperties,
|
||||||
kafkaResponseProcessor: KafkaResponseProcessor
|
kafkaResponseProcessor: KafkaResponseProcessor
|
||||||
): KafkaMessageListenerContainer<String, String> {
|
): KafkaMessageListenerContainer<String, String> {
|
||||||
val containerProperties = ContainerProperties(kafkaProperties.responseTopic)
|
val containerProperties = ContainerProperties(kafkaProperties.outputResponseTopic)
|
||||||
containerProperties.messageListener = kafkaResponseProcessor
|
containerProperties.messageListener = kafkaResponseProcessor
|
||||||
return KafkaMessageListenerContainer(consumerFactory, containerProperties)
|
return KafkaMessageListenerContainer(consumerFactory, containerProperties)
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of ETL-Processor
|
* This file is part of ETL-Processor
|
||||||
*
|
*
|
||||||
* Copyright (c) 2024 Comprehensive Cancer Center Mainfranken, Datenintegrationszentrum Philipps-Universität Marburg and Contributors
|
* Copyright (c) 2025 Comprehensive Cancer Center Mainfranken, Datenintegrationszentrum Philipps-Universität Marburg and Contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Affero General Public License as published
|
||||||
@ -21,9 +21,11 @@ package dev.dnpm.etl.processor.config
|
|||||||
|
|
||||||
import dev.dnpm.etl.processor.monitoring.ConnectionCheckResult
|
import dev.dnpm.etl.processor.monitoring.ConnectionCheckResult
|
||||||
import dev.dnpm.etl.processor.monitoring.ConnectionCheckService
|
import dev.dnpm.etl.processor.monitoring.ConnectionCheckService
|
||||||
|
import dev.dnpm.etl.processor.monitoring.ReportService
|
||||||
import dev.dnpm.etl.processor.monitoring.RestConnectionCheckService
|
import dev.dnpm.etl.processor.monitoring.RestConnectionCheckService
|
||||||
import dev.dnpm.etl.processor.output.MtbFileSender
|
import dev.dnpm.etl.processor.output.MtbFileSender
|
||||||
import dev.dnpm.etl.processor.output.RestMtbFileSender
|
import dev.dnpm.etl.processor.output.RestBwhcMtbFileSender
|
||||||
|
import dev.dnpm.etl.processor.output.RestDipMtbFileSender
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
|
||||||
@ -52,10 +54,16 @@ class AppRestConfiguration {
|
|||||||
fun restMtbFileSender(
|
fun restMtbFileSender(
|
||||||
restTemplate: RestTemplate,
|
restTemplate: RestTemplate,
|
||||||
restTargetProperties: RestTargetProperties,
|
restTargetProperties: RestTargetProperties,
|
||||||
retryTemplate: RetryTemplate
|
retryTemplate: RetryTemplate,
|
||||||
|
reportService: ReportService,
|
||||||
): MtbFileSender {
|
): MtbFileSender {
|
||||||
logger.info("Selected 'RestMtbFileSender'")
|
if (restTargetProperties.isBwhc) {
|
||||||
return RestMtbFileSender(restTemplate, restTargetProperties, retryTemplate)
|
logger.info("Selected 'RestBwhcMtbFileSender'")
|
||||||
|
return RestBwhcMtbFileSender(restTemplate, restTargetProperties, retryTemplate, reportService)
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("Selected 'RestDipMtbFileSender'")
|
||||||
|
return RestDipMtbFileSender(restTemplate, restTargetProperties, retryTemplate, reportService)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of ETL-Processor
|
* This file is part of ETL-Processor
|
||||||
*
|
*
|
||||||
* Copyright (c) 2023 Comprehensive Cancer Center Mainfranken, Datenintegrationszentrum Philipps-Universität Marburg and Contributors
|
* Copyright (c) 2025 Comprehensive Cancer Center Mainfranken, Datenintegrationszentrum Philipps-Universität Marburg and Contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Affero General Public License as published
|
||||||
@ -44,6 +44,8 @@ import org.springframework.security.web.SecurityFilterChain
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
|
||||||
|
private const val LOGIN_PATH = "/login"
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableConfigurationProperties(
|
@EnableConfigurationProperties(
|
||||||
value = [
|
value = [
|
||||||
@ -85,9 +87,14 @@ class AppSecurityConfiguration(
|
|||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnProperty(value = ["app.security.enable-oidc"], havingValue = "true")
|
@ConditionalOnProperty(value = ["app.security.enable-oidc"], havingValue = "true")
|
||||||
fun filterChainOidc(http: HttpSecurity, passwordEncoder: PasswordEncoder, userRoleRepository: UserRoleRepository, sessionRegistry: SessionRegistry): SecurityFilterChain {
|
fun filterChainOidc(
|
||||||
|
http: HttpSecurity,
|
||||||
|
passwordEncoder: PasswordEncoder,
|
||||||
|
userRoleRepository: UserRoleRepository,
|
||||||
|
sessionRegistry: SessionRegistry
|
||||||
|
): SecurityFilterChain {
|
||||||
http {
|
http {
|
||||||
authorizeRequests {
|
authorizeHttpRequests {
|
||||||
authorize("/configs/**", hasRole("ADMIN"))
|
authorize("/configs/**", hasRole("ADMIN"))
|
||||||
authorize("/mtbfile/**", hasAnyRole("MTBFILE", "ADMIN", "USER"))
|
authorize("/mtbfile/**", hasAnyRole("MTBFILE", "ADMIN", "USER"))
|
||||||
authorize("/report/**", hasAnyRole("ADMIN", "USER"))
|
authorize("/report/**", hasAnyRole("ADMIN", "USER"))
|
||||||
@ -104,15 +111,15 @@ class AppSecurityConfiguration(
|
|||||||
realmName = "ETL-Processor"
|
realmName = "ETL-Processor"
|
||||||
}
|
}
|
||||||
formLogin {
|
formLogin {
|
||||||
loginPage = "/login"
|
loginPage = LOGIN_PATH
|
||||||
}
|
}
|
||||||
oauth2Login {
|
oauth2Login {
|
||||||
loginPage = "/login"
|
loginPage = LOGIN_PATH
|
||||||
}
|
}
|
||||||
sessionManagement {
|
sessionManagement {
|
||||||
sessionConcurrency {
|
sessionConcurrency {
|
||||||
maximumSessions = 1
|
maximumSessions = 1
|
||||||
expiredUrl = "/login?expired"
|
expiredUrl = "$LOGIN_PATH?expired"
|
||||||
}
|
}
|
||||||
sessionFixation {
|
sessionFixation {
|
||||||
newSession()
|
newSession()
|
||||||
@ -125,13 +132,22 @@ class AppSecurityConfiguration(
|
|||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnProperty(value = ["app.security.enable-oidc"], havingValue = "true")
|
@ConditionalOnProperty(value = ["app.security.enable-oidc"], havingValue = "true")
|
||||||
fun grantedAuthoritiesMapper(userRoleRepository: UserRoleRepository, appSecurityConfigProperties: SecurityConfigProperties): GrantedAuthoritiesMapper {
|
fun grantedAuthoritiesMapper(
|
||||||
|
userRoleRepository: UserRoleRepository,
|
||||||
|
appSecurityConfigProperties: SecurityConfigProperties
|
||||||
|
): GrantedAuthoritiesMapper {
|
||||||
return GrantedAuthoritiesMapper { grantedAuthority ->
|
return GrantedAuthoritiesMapper { grantedAuthority ->
|
||||||
grantedAuthority.filterIsInstance<OidcUserAuthority>()
|
grantedAuthority.filterIsInstance<OidcUserAuthority>()
|
||||||
.onEach {
|
.onEach {
|
||||||
val userRole = userRoleRepository.findByUsername(it.userInfo.preferredUsername)
|
val userRole = userRoleRepository.findByUsername(it.userInfo.preferredUsername)
|
||||||
if (userRole.isEmpty) {
|
if (userRole.isEmpty) {
|
||||||
userRoleRepository.save(UserRole(null, it.userInfo.preferredUsername, appSecurityConfigProperties.defaultNewUserRole))
|
userRoleRepository.save(
|
||||||
|
UserRole(
|
||||||
|
null,
|
||||||
|
it.userInfo.preferredUsername,
|
||||||
|
appSecurityConfigProperties.defaultNewUserRole
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.map {
|
.map {
|
||||||
@ -145,7 +161,7 @@ class AppSecurityConfiguration(
|
|||||||
@ConditionalOnProperty(value = ["app.security.enable-oidc"], havingValue = "false", matchIfMissing = true)
|
@ConditionalOnProperty(value = ["app.security.enable-oidc"], havingValue = "false", matchIfMissing = true)
|
||||||
fun filterChain(http: HttpSecurity, passwordEncoder: PasswordEncoder): SecurityFilterChain {
|
fun filterChain(http: HttpSecurity, passwordEncoder: PasswordEncoder): SecurityFilterChain {
|
||||||
http {
|
http {
|
||||||
authorizeRequests {
|
authorizeHttpRequests {
|
||||||
authorize("/configs/**", hasRole("ADMIN"))
|
authorize("/configs/**", hasRole("ADMIN"))
|
||||||
authorize("/mtbfile/**", hasAnyRole("MTBFILE", "ADMIN"))
|
authorize("/mtbfile/**", hasAnyRole("MTBFILE", "ADMIN"))
|
||||||
authorize("/report/**", hasRole("ADMIN"))
|
authorize("/report/**", hasRole("ADMIN"))
|
||||||
@ -155,7 +171,7 @@ class AppSecurityConfiguration(
|
|||||||
realmName = "ETL-Processor"
|
realmName = "ETL-Processor"
|
||||||
}
|
}
|
||||||
formLogin {
|
formLogin {
|
||||||
loginPage = "/login"
|
loginPage = LOGIN_PATH
|
||||||
}
|
}
|
||||||
csrf { disable() }
|
csrf { disable() }
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of ETL-Processor
|
* This file is part of ETL-Processor
|
||||||
*
|
*
|
||||||
* Copyright (c) 2024 Comprehensive Cancer Center Mainfranken, Datenintegrationszentrum Philipps-Universität Marburg and Contributors
|
* Copyright (c) 2025 Comprehensive Cancer Center Mainfranken, Datenintegrationszentrum Philipps-Universität Marburg and Contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Affero General Public License as published
|
||||||
@ -22,12 +22,14 @@ package dev.dnpm.etl.processor.input
|
|||||||
import com.fasterxml.jackson.databind.ObjectMapper
|
import com.fasterxml.jackson.databind.ObjectMapper
|
||||||
import de.ukw.ccc.bwhc.dto.Consent
|
import de.ukw.ccc.bwhc.dto.Consent
|
||||||
import de.ukw.ccc.bwhc.dto.MtbFile
|
import de.ukw.ccc.bwhc.dto.MtbFile
|
||||||
|
import dev.dnpm.etl.processor.CustomMediaType
|
||||||
import dev.dnpm.etl.processor.PatientId
|
import dev.dnpm.etl.processor.PatientId
|
||||||
import dev.dnpm.etl.processor.RequestId
|
import dev.dnpm.etl.processor.RequestId
|
||||||
import dev.dnpm.etl.processor.consent.ConsentStatus
|
import dev.dnpm.etl.processor.consent.ConsentStatus
|
||||||
import dev.dnpm.etl.processor.services.RequestProcessor
|
import dev.dnpm.etl.processor.services.RequestProcessor
|
||||||
import org.apache.kafka.clients.consumer.ConsumerRecord
|
import org.apache.kafka.clients.consumer.ConsumerRecord
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
|
import org.springframework.http.MediaType
|
||||||
import org.springframework.kafka.listener.MessageListener
|
import org.springframework.kafka.listener.MessageListener
|
||||||
|
|
||||||
class KafkaInputListener(
|
class KafkaInputListener(
|
||||||
@ -36,10 +38,29 @@ class KafkaInputListener(
|
|||||||
) : MessageListener<String, String> {
|
) : MessageListener<String, String> {
|
||||||
private val logger = LoggerFactory.getLogger(KafkaInputListener::class.java)
|
private val logger = LoggerFactory.getLogger(KafkaInputListener::class.java)
|
||||||
|
|
||||||
override fun onMessage(data: ConsumerRecord<String, String>) {
|
override fun onMessage(record: ConsumerRecord<String, String>) {
|
||||||
val mtbFile = objectMapper.readValue(data.value(), MtbFile::class.java)
|
when (guessMimeType(record)) {
|
||||||
|
MediaType.APPLICATION_JSON_VALUE -> handleBwhcMessage(record)
|
||||||
|
CustomMediaType.APPLICATION_VND_DNPM_V2_MTB_JSON_VALUE -> handleDnpmV2Message(record)
|
||||||
|
else -> {
|
||||||
|
/* ignore other messages */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun guessMimeType(record: ConsumerRecord<String, String>): String {
|
||||||
|
if (record.headers().headers("contentType").toList().isEmpty()) {
|
||||||
|
// Fallback if no contentType set (old behavior)
|
||||||
|
return MediaType.APPLICATION_JSON_VALUE
|
||||||
|
}
|
||||||
|
|
||||||
|
return record.headers().headers("contentType")?.firstOrNull()?.value().contentToString()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun handleBwhcMessage(record: ConsumerRecord<String, String>) {
|
||||||
|
val mtbFile = objectMapper.readValue(record.value(), MtbFile::class.java)
|
||||||
val patientId = PatientId(mtbFile.patient.id)
|
val patientId = PatientId(mtbFile.patient.id)
|
||||||
val firstRequestIdHeader = data.headers().headers("requestId")?.firstOrNull()
|
val firstRequestIdHeader = record.headers().headers("requestId")?.firstOrNull()
|
||||||
val requestId = if (null != firstRequestIdHeader) {
|
val requestId = if (null != firstRequestIdHeader) {
|
||||||
RequestId(String(firstRequestIdHeader.value()))
|
RequestId(String(firstRequestIdHeader.value()))
|
||||||
} else {
|
} else {
|
||||||
@ -66,4 +87,10 @@ class KafkaInputListener(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun handleDnpmV2Message(record: ConsumerRecord<String, String>) {
|
||||||
|
// Do not handle DNPM-V2 for now
|
||||||
|
logger.warn("Ignoring MTB File in DNPM V2 format: Not implemented yet")
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of ETL-Processor
|
* This file is part of ETL-Processor
|
||||||
*
|
*
|
||||||
* Copyright (c) 2024 Comprehensive Cancer Center Mainfranken, Datenintegrationszentrum Philipps-Universität Marburg and Contributors
|
* Copyright (c) 2025 Comprehensive Cancer Center Mainfranken, Datenintegrationszentrum Philipps-Universität Marburg and Contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Affero General Public License as published
|
||||||
@ -21,16 +21,19 @@ package dev.dnpm.etl.processor.input
|
|||||||
|
|
||||||
import de.ukw.ccc.bwhc.dto.Consent
|
import de.ukw.ccc.bwhc.dto.Consent
|
||||||
import de.ukw.ccc.bwhc.dto.MtbFile
|
import de.ukw.ccc.bwhc.dto.MtbFile
|
||||||
|
import dev.dnpm.etl.processor.CustomMediaType
|
||||||
import dev.dnpm.etl.processor.PatientId
|
import dev.dnpm.etl.processor.PatientId
|
||||||
import dev.dnpm.etl.processor.consent.ICheckConsent
|
import dev.dnpm.etl.processor.consent.ICheckConsent
|
||||||
import dev.dnpm.etl.processor.consent.ConsentStatus
|
import dev.dnpm.etl.processor.consent.ConsentStatus
|
||||||
import dev.dnpm.etl.processor.services.RequestProcessor
|
import dev.dnpm.etl.processor.services.RequestProcessor
|
||||||
|
import dev.pcvolkmer.mv64e.mtb.Mtb
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
|
import org.springframework.http.MediaType
|
||||||
import org.springframework.http.ResponseEntity
|
import org.springframework.http.ResponseEntity
|
||||||
import org.springframework.web.bind.annotation.*
|
import org.springframework.web.bind.annotation.*
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping(path = ["mtbfile"])
|
@RequestMapping(path = ["mtbfile", "mtb"])
|
||||||
class MtbFileRestController(
|
class MtbFileRestController(
|
||||||
private val requestProcessor: RequestProcessor, private val constService: ICheckConsent
|
private val requestProcessor: RequestProcessor, private val constService: ICheckConsent
|
||||||
) {
|
) {
|
||||||
@ -42,32 +45,35 @@ class MtbFileRestController(
|
|||||||
return ResponseEntity.ok("Test")
|
return ResponseEntity.ok("Test")
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping( consumes = [ MediaType.APPLICATION_JSON_VALUE ] )
|
||||||
fun mtbFile(@RequestBody mtbFile: MtbFile): ResponseEntity<Void> {
|
fun mtbFile(@RequestBody mtbFile: MtbFile): ResponseEntity<Unit> {
|
||||||
|
|
||||||
var consentStatus = constService.isConsented(mtbFile.patient.id)
|
var consentStatus = constService.isConsented(mtbFile.patient.id)
|
||||||
|
|
||||||
if (mtbFile.consent.status == Consent.Status.ACTIVE && (consentStatus.equals(ConsentStatus.CONSENTED) || consentStatus.equals(
|
if (mtbFile.consent.status == Consent.Status.ACTIVE && (consentStatus.equals(ConsentStatus.CONSENTED) || consentStatus.equals(
|
||||||
ConsentStatus.IGNORED
|
ConsentStatus.IGNORED
|
||||||
))
|
))
|
||||||
) {
|
) {
|
||||||
logger.debug("Accepted MTB File for processing")
|
logger.debug("Accepted MTB File (bwHC V1) for processing")
|
||||||
requestProcessor.processMtbFile(mtbFile)
|
requestProcessor.processMtbFile(mtbFile)
|
||||||
} else {
|
} else {
|
||||||
var msg = "Accepted MTB File and process deletion"
|
logger.debug("Accepted MTB File (bwHC V1) and process deletion")
|
||||||
if (!consentStatus.equals(ConsentStatus.CONSENTED) || consentStatus.equals(ConsentStatus.IGNORED)) {
|
|
||||||
msg = "Accepted MTB File. But consent is missing, therefore process deletion."
|
|
||||||
}
|
|
||||||
if (mtbFile.consent.status == Consent.Status.REJECTED) consentStatus =
|
if (mtbFile.consent.status == Consent.Status.REJECTED) consentStatus =
|
||||||
ConsentStatus.CONSENT_REJECTED
|
ConsentStatus.CONSENT_REJECTED
|
||||||
logger.debug(msg)
|
|
||||||
val patientId = PatientId(mtbFile.patient.id)
|
val patientId = PatientId(mtbFile.patient.id)
|
||||||
requestProcessor.processDeletion(patientId, consentStatus)
|
requestProcessor.processDeletion(patientId, consentStatus)
|
||||||
}
|
}
|
||||||
return ResponseEntity.accepted().build()
|
return ResponseEntity.accepted().build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping( consumes = [ CustomMediaType.APPLICATION_VND_DNPM_V2_MTB_JSON_VALUE] )
|
||||||
|
fun mtbFile(@RequestBody mtbFile: Mtb): ResponseEntity<Unit> {
|
||||||
|
logger.debug("Accepted MTB File (DNPM V2) for processing")
|
||||||
|
requestProcessor.processMtbFile(mtbFile)
|
||||||
|
return ResponseEntity.accepted().build()
|
||||||
|
}
|
||||||
|
|
||||||
@DeleteMapping(path = ["{patientId}"])
|
@DeleteMapping(path = ["{patientId}"])
|
||||||
fun deleteData(@PathVariable patientId: String): ResponseEntity<Void> {
|
fun deleteData(@PathVariable patientId: String): ResponseEntity<Unit> {
|
||||||
logger.debug("Accepted patient ID to process deletion")
|
logger.debug("Accepted patient ID to process deletion")
|
||||||
requestProcessor.processDeletion(PatientId(patientId), ConsentStatus.IGNORED)
|
requestProcessor.processDeletion(PatientId(patientId), ConsentStatus.IGNORED)
|
||||||
return ResponseEntity.accepted().build()
|
return ResponseEntity.accepted().build()
|
||||||
|
@ -35,7 +35,7 @@ import java.time.Instant
|
|||||||
import kotlin.time.Duration.Companion.seconds
|
import kotlin.time.Duration.Companion.seconds
|
||||||
import kotlin.time.toJavaDuration
|
import kotlin.time.toJavaDuration
|
||||||
|
|
||||||
interface ConnectionCheckService {
|
fun interface ConnectionCheckService {
|
||||||
|
|
||||||
fun connectionAvailable(): ConnectionCheckResult
|
fun connectionAvailable(): ConnectionCheckResult
|
||||||
|
|
||||||
@ -88,7 +88,7 @@ class KafkaConnectionCheckService(
|
|||||||
Instant.now(),
|
Instant.now(),
|
||||||
if (result.available == available) { result.lastChange } else { Instant.now() }
|
if (result.available == available) { result.lastChange } else { Instant.now() }
|
||||||
)
|
)
|
||||||
} catch (e: TimeoutException) {
|
} catch (_: TimeoutException) {
|
||||||
ConnectionCheckResult.KafkaConnectionCheckResult(
|
ConnectionCheckResult.KafkaConnectionCheckResult(
|
||||||
false,
|
false,
|
||||||
Instant.now(),
|
Instant.now(),
|
||||||
@ -121,7 +121,15 @@ class RestConnectionCheckService(
|
|||||||
fun check() {
|
fun check() {
|
||||||
result = try {
|
result = try {
|
||||||
val available = restTemplate.getForEntity(
|
val available = restTemplate.getForEntity(
|
||||||
restTargetProperties.uri?.replace("/etl/api", "").toString(),
|
if (restTargetProperties.isBwhc) {
|
||||||
|
UriComponentsBuilder.fromUriString(restTargetProperties.uri.toString()).path("").toUriString()
|
||||||
|
} else {
|
||||||
|
UriComponentsBuilder.fromUriString(restTargetProperties.uri.toString())
|
||||||
|
.pathSegment("mtb")
|
||||||
|
.pathSegment("kaplan-meier")
|
||||||
|
.pathSegment("config")
|
||||||
|
.toUriString()
|
||||||
|
},
|
||||||
String::class.java
|
String::class.java
|
||||||
).statusCode == HttpStatus.OK
|
).statusCode == HttpStatus.OK
|
||||||
|
|
||||||
@ -130,7 +138,7 @@ class RestConnectionCheckService(
|
|||||||
Instant.now(),
|
Instant.now(),
|
||||||
if (result.available == available) { result.lastChange } else { Instant.now() }
|
if (result.available == available) { result.lastChange } else { Instant.now() }
|
||||||
)
|
)
|
||||||
} catch (e: Exception) {
|
} catch (_: Exception) {
|
||||||
ConnectionCheckResult.RestConnectionCheckResult(
|
ConnectionCheckResult.RestConnectionCheckResult(
|
||||||
false,
|
false,
|
||||||
Instant.now(),
|
Instant.now(),
|
||||||
@ -162,11 +170,8 @@ class GPasConnectionCheckService(
|
|||||||
fun check() {
|
fun check() {
|
||||||
result = try {
|
result = try {
|
||||||
val uri = UriComponentsBuilder.fromUriString(
|
val uri = UriComponentsBuilder.fromUriString(
|
||||||
gPasConfigProperties.uri?.replace("/\$pseudonymizeAllowCreate", "/\$pseudonymize").toString()
|
gPasConfigProperties.uri?.replace("/\$pseudonymizeAllowCreate", "/metadata").toString()
|
||||||
)
|
).build().toUri()
|
||||||
.queryParam("target", gPasConfigProperties.target)
|
|
||||||
.queryParam("original", "???")
|
|
||||||
.build().toUri()
|
|
||||||
|
|
||||||
val headers = HttpHeaders()
|
val headers = HttpHeaders()
|
||||||
headers.contentType = MediaType.APPLICATION_JSON
|
headers.contentType = MediaType.APPLICATION_JSON
|
||||||
@ -186,7 +191,7 @@ class GPasConnectionCheckService(
|
|||||||
Instant.now(),
|
Instant.now(),
|
||||||
if (result.available == available) { result.lastChange } else { Instant.now() }
|
if (result.available == available) { result.lastChange } else { Instant.now() }
|
||||||
)
|
)
|
||||||
} catch (e: Exception) {
|
} catch (_: Exception) {
|
||||||
ConnectionCheckResult.GPasConnectionCheckResult(
|
ConnectionCheckResult.GPasConnectionCheckResult(
|
||||||
false,
|
false,
|
||||||
Instant.now(),
|
Instant.now(),
|
||||||
|
@ -25,6 +25,9 @@ import com.fasterxml.jackson.annotation.JsonValue
|
|||||||
import com.fasterxml.jackson.core.JsonParseException
|
import com.fasterxml.jackson.core.JsonParseException
|
||||||
import com.fasterxml.jackson.databind.JsonMappingException
|
import com.fasterxml.jackson.databind.JsonMappingException
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper
|
import com.fasterxml.jackson.databind.ObjectMapper
|
||||||
|
import dev.dnpm.etl.processor.monitoring.ReportService.Issue
|
||||||
|
import dev.dnpm.etl.processor.monitoring.ReportService.Severity
|
||||||
|
import java.util.Optional
|
||||||
|
|
||||||
class ReportService(
|
class ReportService(
|
||||||
private val objectMapper: ObjectMapper
|
private val objectMapper: ObjectMapper
|
||||||
@ -55,7 +58,11 @@ class ReportService(
|
|||||||
private data class DataQualityReport(val issues: List<Issue>)
|
private data class DataQualityReport(val issues: List<Issue>)
|
||||||
|
|
||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
data class Issue(val severity: Severity, @JsonAlias("details") val message: String)
|
data class Issue(
|
||||||
|
val severity: Severity,
|
||||||
|
@JsonAlias("details") val message: String,
|
||||||
|
val path: Optional<String> = Optional.empty()
|
||||||
|
)
|
||||||
|
|
||||||
enum class Severity(@JsonValue val value: String) {
|
enum class Severity(@JsonValue val value: String) {
|
||||||
FATAL("fatal"),
|
FATAL("fatal"),
|
||||||
@ -64,3 +71,12 @@ class ReportService(
|
|||||||
INFO("info")
|
INFO("info")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun List<Issue>.asRequestStatus(): RequestStatus {
|
||||||
|
val severity = this.minOfOrNull { it.severity }
|
||||||
|
return when (severity) {
|
||||||
|
Severity.FATAL, Severity.ERROR -> RequestStatus.ERROR
|
||||||
|
Severity.WARNING -> RequestStatus.WARNING
|
||||||
|
else -> RequestStatus.SUCCESS
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of ETL-Processor
|
* This file is part of ETL-Processor
|
||||||
*
|
*
|
||||||
* Copyright (c) 2024 Comprehensive Cancer Center Mainfranken, Datenintegrationszentrum Philipps-Universität Marburg and Contributors
|
* Copyright (c) 2025 Comprehensive Cancer Center Mainfranken, Datenintegrationszentrum Philipps-Universität Marburg and Contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Affero General Public License as published
|
||||||
@ -22,10 +22,12 @@ package dev.dnpm.etl.processor.output
|
|||||||
import com.fasterxml.jackson.databind.ObjectMapper
|
import com.fasterxml.jackson.databind.ObjectMapper
|
||||||
import de.ukw.ccc.bwhc.dto.Consent
|
import de.ukw.ccc.bwhc.dto.Consent
|
||||||
import de.ukw.ccc.bwhc.dto.MtbFile
|
import de.ukw.ccc.bwhc.dto.MtbFile
|
||||||
import dev.dnpm.etl.processor.RequestId
|
import dev.dnpm.etl.processor.CustomMediaType
|
||||||
import dev.dnpm.etl.processor.config.KafkaProperties
|
import dev.dnpm.etl.processor.config.KafkaProperties
|
||||||
import dev.dnpm.etl.processor.monitoring.RequestStatus
|
import dev.dnpm.etl.processor.monitoring.RequestStatus
|
||||||
|
import org.apache.kafka.clients.producer.ProducerRecord
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
|
import org.springframework.http.MediaType
|
||||||
import org.springframework.kafka.core.KafkaTemplate
|
import org.springframework.kafka.core.KafkaTemplate
|
||||||
import org.springframework.retry.support.RetryTemplate
|
import org.springframework.retry.support.RetryTemplate
|
||||||
|
|
||||||
@ -38,14 +40,20 @@ class KafkaMtbFileSender(
|
|||||||
|
|
||||||
private val logger = LoggerFactory.getLogger(KafkaMtbFileSender::class.java)
|
private val logger = LoggerFactory.getLogger(KafkaMtbFileSender::class.java)
|
||||||
|
|
||||||
override fun send(request: MtbFileSender.MtbFileRequest): MtbFileSender.Response {
|
override fun <T> send(request: MtbFileRequest<T>): MtbFileSender.Response {
|
||||||
return try {
|
return try {
|
||||||
return retryTemplate.execute<MtbFileSender.Response, Exception> {
|
return retryTemplate.execute<MtbFileSender.Response, Exception> {
|
||||||
val result = kafkaTemplate.send(
|
val record =
|
||||||
kafkaProperties.topic,
|
ProducerRecord(kafkaProperties.outputTopic, key(request), objectMapper.writeValueAsString(request))
|
||||||
key(request),
|
when (request) {
|
||||||
objectMapper.writeValueAsString(Data(request.requestId, request.mtbFile))
|
is BwhcV1MtbFileRequest -> record.headers()
|
||||||
)
|
.add("contentType", MediaType.APPLICATION_JSON_VALUE.toByteArray())
|
||||||
|
|
||||||
|
is DnpmV2MtbFileRequest -> record.headers()
|
||||||
|
.add("contentType", CustomMediaType.APPLICATION_VND_DNPM_V2_MTB_JSON_VALUE.toByteArray())
|
||||||
|
}
|
||||||
|
|
||||||
|
val result = kafkaTemplate.send(record)
|
||||||
if (result.get() != null) {
|
if (result.get() != null) {
|
||||||
logger.debug("Sent file via KafkaMtbFileSender")
|
logger.debug("Sent file via KafkaMtbFileSender")
|
||||||
MtbFileSender.Response(RequestStatus.UNKNOWN)
|
MtbFileSender.Response(RequestStatus.UNKNOWN)
|
||||||
@ -59,7 +67,7 @@ class KafkaMtbFileSender(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun send(request: MtbFileSender.DeleteRequest): MtbFileSender.Response {
|
override fun send(request: DeleteRequest): MtbFileSender.Response {
|
||||||
val dummyMtbFile = MtbFile.builder()
|
val dummyMtbFile = MtbFile.builder()
|
||||||
.withConsent(
|
.withConsent(
|
||||||
Consent.builder()
|
Consent.builder()
|
||||||
@ -71,12 +79,15 @@ class KafkaMtbFileSender(
|
|||||||
|
|
||||||
return try {
|
return try {
|
||||||
return retryTemplate.execute<MtbFileSender.Response, Exception> {
|
return retryTemplate.execute<MtbFileSender.Response, Exception> {
|
||||||
val result = kafkaTemplate.send(
|
val record =
|
||||||
kafkaProperties.topic,
|
ProducerRecord(
|
||||||
|
kafkaProperties.outputTopic,
|
||||||
key(request),
|
key(request),
|
||||||
objectMapper.writeValueAsString(Data(request.requestId, dummyMtbFile))
|
// Always use old BwhcV1FileRequest with Consent REJECT
|
||||||
|
objectMapper.writeValueAsString(BwhcV1MtbFileRequest(request.requestId, dummyMtbFile))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val result = kafkaTemplate.send(record)
|
||||||
if (result.get() != null) {
|
if (result.get() != null) {
|
||||||
logger.debug("Sent deletion request via KafkaMtbFileSender")
|
logger.debug("Sent deletion request via KafkaMtbFileSender")
|
||||||
MtbFileSender.Response(RequestStatus.UNKNOWN)
|
MtbFileSender.Response(RequestStatus.UNKNOWN)
|
||||||
@ -91,16 +102,15 @@ class KafkaMtbFileSender(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun endpoint(): String {
|
override fun endpoint(): String {
|
||||||
return "${this.kafkaProperties.servers} (${this.kafkaProperties.topic}/${this.kafkaProperties.responseTopic})"
|
return "${this.kafkaProperties.servers} (${this.kafkaProperties.outputTopic}/${this.kafkaProperties.outputResponseTopic})"
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun key(request: MtbFileSender.MtbFileRequest): String {
|
private fun key(request: MtbRequest): String {
|
||||||
return "{\"pid\": \"${request.mtbFile.patient.id}\"}"
|
return when (request) {
|
||||||
|
is BwhcV1MtbFileRequest -> "{\"pid\": \"${request.content.patient.id}\"}"
|
||||||
|
is DnpmV2MtbFileRequest -> "{\"pid\": \"${request.content.patient.id}\"}"
|
||||||
|
is DeleteRequest -> "{\"pid\": \"${request.patientId.value}\"}"
|
||||||
|
else -> throw IllegalArgumentException("Unsupported request type: ${request::class.simpleName}")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun key(request: MtbFileSender.DeleteRequest): String {
|
|
||||||
return "{\"pid\": \"${request.patientId.value}\"}"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data class Data(val requestId: RequestId, val content: MtbFile)
|
|
||||||
}
|
}
|
@ -19,25 +19,17 @@
|
|||||||
|
|
||||||
package dev.dnpm.etl.processor.output
|
package dev.dnpm.etl.processor.output
|
||||||
|
|
||||||
import de.ukw.ccc.bwhc.dto.MtbFile
|
|
||||||
import dev.dnpm.etl.processor.PatientPseudonym
|
|
||||||
import dev.dnpm.etl.processor.RequestId
|
|
||||||
import dev.dnpm.etl.processor.monitoring.RequestStatus
|
import dev.dnpm.etl.processor.monitoring.RequestStatus
|
||||||
import org.springframework.http.HttpStatusCode
|
import org.springframework.http.HttpStatusCode
|
||||||
|
|
||||||
interface MtbFileSender {
|
interface MtbFileSender {
|
||||||
fun send(request: MtbFileRequest): Response
|
fun <T> send(request: MtbFileRequest<T>): Response
|
||||||
|
|
||||||
fun send(request: DeleteRequest): Response
|
fun send(request: DeleteRequest): Response
|
||||||
|
|
||||||
fun endpoint(): String
|
fun endpoint(): String
|
||||||
|
|
||||||
data class Response(val status: RequestStatus, val body: String = "")
|
data class Response(val status: RequestStatus, val body: String = "")
|
||||||
|
|
||||||
data class MtbFileRequest(val requestId: RequestId, val mtbFile: MtbFile)
|
|
||||||
|
|
||||||
data class DeleteRequest(val requestId: RequestId, val patientId: PatientPseudonym)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Int.asRequestStatus(): RequestStatus {
|
fun Int.asRequestStatus(): RequestStatus {
|
||||||
|
59
src/main/kotlin/dev/dnpm/etl/processor/output/MtbRequest.kt
Normal file
59
src/main/kotlin/dev/dnpm/etl/processor/output/MtbRequest.kt
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ETL-Processor
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025 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.output
|
||||||
|
|
||||||
|
import de.ukw.ccc.bwhc.dto.MtbFile
|
||||||
|
import dev.dnpm.etl.processor.PatientPseudonym
|
||||||
|
import dev.dnpm.etl.processor.RequestId
|
||||||
|
import dev.pcvolkmer.mv64e.mtb.Mtb
|
||||||
|
|
||||||
|
interface MtbRequest {
|
||||||
|
val requestId: RequestId
|
||||||
|
}
|
||||||
|
|
||||||
|
sealed interface MtbFileRequest<out T> : MtbRequest {
|
||||||
|
override val requestId: RequestId
|
||||||
|
val content: T
|
||||||
|
|
||||||
|
fun patientPseudonym(): PatientPseudonym
|
||||||
|
}
|
||||||
|
|
||||||
|
data class BwhcV1MtbFileRequest(
|
||||||
|
override val requestId: RequestId,
|
||||||
|
override val content: MtbFile
|
||||||
|
) : MtbFileRequest<MtbFile> {
|
||||||
|
override fun patientPseudonym(): PatientPseudonym {
|
||||||
|
return PatientPseudonym(content.patient.id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data class DnpmV2MtbFileRequest(
|
||||||
|
override val requestId: RequestId,
|
||||||
|
override val content: Mtb
|
||||||
|
) : MtbFileRequest<Mtb> {
|
||||||
|
override fun patientPseudonym(): PatientPseudonym {
|
||||||
|
return PatientPseudonym(content.patient.id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data class DeleteRequest(
|
||||||
|
override val requestId: RequestId,
|
||||||
|
val patientId: PatientPseudonym
|
||||||
|
) : MtbRequest
|
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ETL-Processor
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025 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.output
|
||||||
|
|
||||||
|
import dev.dnpm.etl.processor.PatientPseudonym
|
||||||
|
import dev.dnpm.etl.processor.config.RestTargetProperties
|
||||||
|
import dev.dnpm.etl.processor.monitoring.ReportService
|
||||||
|
import org.springframework.retry.support.RetryTemplate
|
||||||
|
import org.springframework.web.client.RestTemplate
|
||||||
|
import org.springframework.web.util.UriComponentsBuilder
|
||||||
|
|
||||||
|
class RestBwhcMtbFileSender(
|
||||||
|
restTemplate: RestTemplate,
|
||||||
|
private val restTargetProperties: RestTargetProperties,
|
||||||
|
retryTemplate: RetryTemplate,
|
||||||
|
reportService: ReportService,
|
||||||
|
) : RestMtbFileSender(restTemplate, restTargetProperties, retryTemplate, reportService) {
|
||||||
|
|
||||||
|
override fun sendUrl(): String {
|
||||||
|
return UriComponentsBuilder
|
||||||
|
.fromUriString(restTargetProperties.uri.toString())
|
||||||
|
.pathSegment("MTBFile")
|
||||||
|
.toUriString()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun deleteUrl(patientId: PatientPseudonym): String {
|
||||||
|
return UriComponentsBuilder
|
||||||
|
.fromUriString(restTargetProperties.uri.toString())
|
||||||
|
.pathSegment("Patient")
|
||||||
|
.pathSegment(patientId.value)
|
||||||
|
.toUriString()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ETL-Processor
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025 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.output
|
||||||
|
|
||||||
|
import dev.dnpm.etl.processor.PatientPseudonym
|
||||||
|
import dev.dnpm.etl.processor.config.RestTargetProperties
|
||||||
|
import dev.dnpm.etl.processor.monitoring.ReportService
|
||||||
|
import org.springframework.retry.support.RetryTemplate
|
||||||
|
import org.springframework.web.client.RestTemplate
|
||||||
|
import org.springframework.web.util.UriComponentsBuilder
|
||||||
|
|
||||||
|
class RestDipMtbFileSender(
|
||||||
|
restTemplate: RestTemplate,
|
||||||
|
private val restTargetProperties: RestTargetProperties,
|
||||||
|
retryTemplate: RetryTemplate,
|
||||||
|
reportService: ReportService
|
||||||
|
) : RestMtbFileSender(restTemplate, restTargetProperties, retryTemplate, reportService) {
|
||||||
|
|
||||||
|
override fun sendUrl(): String {
|
||||||
|
return UriComponentsBuilder
|
||||||
|
.fromUriString(restTargetProperties.uri.toString())
|
||||||
|
.pathSegment("mtb")
|
||||||
|
.pathSegment("etl")
|
||||||
|
.pathSegment("patient-record")
|
||||||
|
.toUriString()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun deleteUrl(patientId: PatientPseudonym): String {
|
||||||
|
return UriComponentsBuilder
|
||||||
|
.fromUriString(restTargetProperties.uri.toString())
|
||||||
|
.pathSegment("mtb")
|
||||||
|
.pathSegment("etl")
|
||||||
|
.pathSegment("patient")
|
||||||
|
.pathSegment(patientId.value)
|
||||||
|
.toUriString()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of ETL-Processor
|
* This file is part of ETL-Processor
|
||||||
*
|
*
|
||||||
* Copyright (c) 2024 Comprehensive Cancer Center Mainfranken, Datenintegrationszentrum Philipps-Universität Marburg and Contributors
|
* Copyright (c) 2025 Comprehensive Cancer Center Mainfranken, Datenintegrationszentrum Philipps-Universität Marburg and Contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Affero General Public License as published
|
||||||
@ -19,62 +19,71 @@
|
|||||||
|
|
||||||
package dev.dnpm.etl.processor.output
|
package dev.dnpm.etl.processor.output
|
||||||
|
|
||||||
|
import dev.dnpm.etl.processor.CustomMediaType
|
||||||
|
import dev.dnpm.etl.processor.PatientPseudonym
|
||||||
import dev.dnpm.etl.processor.config.RestTargetProperties
|
import dev.dnpm.etl.processor.config.RestTargetProperties
|
||||||
|
import dev.dnpm.etl.processor.monitoring.ReportService
|
||||||
import dev.dnpm.etl.processor.monitoring.RequestStatus
|
import dev.dnpm.etl.processor.monitoring.RequestStatus
|
||||||
|
import dev.dnpm.etl.processor.monitoring.asRequestStatus
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import org.springframework.http.HttpEntity
|
import org.springframework.http.HttpEntity
|
||||||
import org.springframework.http.HttpHeaders
|
import org.springframework.http.HttpHeaders
|
||||||
import org.springframework.http.MediaType
|
import org.springframework.http.MediaType
|
||||||
import org.springframework.retry.support.RetryTemplate
|
import org.springframework.retry.support.RetryTemplate
|
||||||
import org.springframework.web.client.RestClientException
|
import org.springframework.web.client.RestClientException
|
||||||
|
import org.springframework.web.client.RestClientResponseException
|
||||||
import org.springframework.web.client.RestTemplate
|
import org.springframework.web.client.RestTemplate
|
||||||
|
|
||||||
class RestMtbFileSender(
|
abstract class RestMtbFileSender(
|
||||||
private val restTemplate: RestTemplate,
|
private val restTemplate: RestTemplate,
|
||||||
private val restTargetProperties: RestTargetProperties,
|
private val restTargetProperties: RestTargetProperties,
|
||||||
private val retryTemplate: RetryTemplate
|
private val retryTemplate: RetryTemplate,
|
||||||
|
private val reportService: ReportService
|
||||||
) : MtbFileSender {
|
) : MtbFileSender {
|
||||||
|
|
||||||
private val logger = LoggerFactory.getLogger(RestMtbFileSender::class.java)
|
private val logger = LoggerFactory.getLogger(RestMtbFileSender::class.java)
|
||||||
|
|
||||||
override fun send(request: MtbFileSender.MtbFileRequest): MtbFileSender.Response {
|
abstract fun sendUrl(): String
|
||||||
|
|
||||||
|
abstract fun deleteUrl(patientId: PatientPseudonym): String
|
||||||
|
|
||||||
|
override fun <T> send(request: MtbFileRequest<T>): MtbFileSender.Response {
|
||||||
try {
|
try {
|
||||||
return retryTemplate.execute<MtbFileSender.Response, Exception> {
|
return retryTemplate.execute<MtbFileSender.Response, Exception> {
|
||||||
val headers = HttpHeaders()
|
val headers = getHttpHeaders(request)
|
||||||
headers.contentType = MediaType.APPLICATION_JSON
|
val entityReq = HttpEntity(request.content, headers)
|
||||||
val entityReq = HttpEntity(request.mtbFile, headers)
|
|
||||||
val response = restTemplate.postForEntity(
|
val response = restTemplate.postForEntity(
|
||||||
"${restTargetProperties.uri}/MTBFile",
|
sendUrl(),
|
||||||
entityReq,
|
entityReq,
|
||||||
String::class.java
|
String::class.java
|
||||||
)
|
)
|
||||||
if (!response.statusCode.is2xxSuccessful) {
|
if (!response.statusCode.is2xxSuccessful) {
|
||||||
logger.warn("Error sending to remote system: {}", response.body)
|
logger.warn("Error sending to remote system: {}", response.body)
|
||||||
return@execute MtbFileSender.Response(
|
return@execute MtbFileSender.Response(
|
||||||
response.statusCode.asRequestStatus(),
|
reportService.deserialize(response.body).asRequestStatus(),
|
||||||
"Status-Code: ${response.statusCode.value()}"
|
"Status-Code: ${response.statusCode.value()}"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
logger.debug("Sent file via RestMtbFileSender")
|
logger.debug("Sent file via RestMtbFileSender")
|
||||||
return@execute MtbFileSender.Response(response.statusCode.asRequestStatus(), response.body.orEmpty())
|
return@execute MtbFileSender.Response(reportService.deserialize(response.body).asRequestStatus(), response.body.orEmpty())
|
||||||
}
|
}
|
||||||
} catch (e: IllegalArgumentException) {
|
} catch (e: IllegalArgumentException) {
|
||||||
logger.error("Not a valid URI to export to: '{}'", restTargetProperties.uri!!)
|
logger.error("Not a valid URI to export to: '{}'", restTargetProperties.uri!!)
|
||||||
} catch (e: RestClientException) {
|
} catch (e: RestClientResponseException) {
|
||||||
logger.info(restTargetProperties.uri!!.toString())
|
logger.info(restTargetProperties.uri!!.toString())
|
||||||
logger.error("Cannot send data to remote system", e)
|
logger.error("Request data not accepted by remote system", e)
|
||||||
|
return MtbFileSender.Response(reportService.deserialize(e.responseBodyAsString).asRequestStatus(), e.responseBodyAsString)
|
||||||
}
|
}
|
||||||
return MtbFileSender.Response(RequestStatus.ERROR, "Sonstiger Fehler bei der Übertragung")
|
return MtbFileSender.Response(RequestStatus.ERROR, "Sonstiger Fehler bei der Übertragung")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun send(request: MtbFileSender.DeleteRequest): MtbFileSender.Response {
|
override fun send(request: DeleteRequest): MtbFileSender.Response {
|
||||||
try {
|
try {
|
||||||
return retryTemplate.execute<MtbFileSender.Response, Exception> {
|
return retryTemplate.execute<MtbFileSender.Response, Exception> {
|
||||||
val headers = HttpHeaders()
|
val headers = getHttpHeaders(request)
|
||||||
headers.contentType = MediaType.APPLICATION_JSON
|
|
||||||
val entityReq = HttpEntity(null, headers)
|
val entityReq = HttpEntity(null, headers)
|
||||||
restTemplate.delete(
|
restTemplate.delete(
|
||||||
"${restTargetProperties.uri}/Patient/${request.patientId}",
|
deleteUrl(request.patientId),
|
||||||
entityReq,
|
entityReq,
|
||||||
String::class.java
|
String::class.java
|
||||||
)
|
)
|
||||||
@ -94,4 +103,22 @@ class RestMtbFileSender(
|
|||||||
return this.restTargetProperties.uri.orEmpty()
|
return this.restTargetProperties.uri.orEmpty()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getHttpHeaders(request: MtbRequest): HttpHeaders {
|
||||||
|
val username = restTargetProperties.username
|
||||||
|
val password = restTargetProperties.password
|
||||||
|
val headers = HttpHeaders()
|
||||||
|
headers.contentType = when (request) {
|
||||||
|
is BwhcV1MtbFileRequest -> MediaType.APPLICATION_JSON
|
||||||
|
is DnpmV2MtbFileRequest -> CustomMediaType.APPLICATION_VND_DNPM_V2_MTB_JSON
|
||||||
|
else -> MediaType.APPLICATION_JSON
|
||||||
|
}
|
||||||
|
|
||||||
|
if (username.isNullOrBlank() || password.isNullOrBlank()) {
|
||||||
|
return headers
|
||||||
|
}
|
||||||
|
|
||||||
|
headers.setBasicAuth(username, password)
|
||||||
|
return headers
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -21,12 +21,12 @@ package dev.dnpm.etl.processor.pseudonym
|
|||||||
|
|
||||||
import de.ukw.ccc.bwhc.dto.MtbFile
|
import de.ukw.ccc.bwhc.dto.MtbFile
|
||||||
import dev.dnpm.etl.processor.PatientId
|
import dev.dnpm.etl.processor.PatientId
|
||||||
|
import dev.pcvolkmer.mv64e.mtb.Mtb
|
||||||
import org.apache.commons.codec.digest.DigestUtils
|
import org.apache.commons.codec.digest.DigestUtils
|
||||||
|
|
||||||
/** Replaces patient ID with generated patient pseudonym
|
/** Replaces patient ID with generated patient pseudonym
|
||||||
*
|
*
|
||||||
* @param pseudonymizeService The pseudonymizeService to be used
|
* @param pseudonymizeService The pseudonymizeService to be used
|
||||||
*
|
|
||||||
* @return The MTB file containing patient pseudonymes
|
* @return The MTB file containing patient pseudonymes
|
||||||
*/
|
*/
|
||||||
infix fun MtbFile.pseudonymizeWith(pseudonymizeService: PseudonymizeService) {
|
infix fun MtbFile.pseudonymizeWith(pseudonymizeService: PseudonymizeService) {
|
||||||
@ -49,7 +49,11 @@ infix fun MtbFile.pseudonymizeWith(pseudonymizeService: PseudonymizeService) {
|
|||||||
}
|
}
|
||||||
this.lastGuidelineTherapies?.forEach { it.patient = patientPseudonym }
|
this.lastGuidelineTherapies?.forEach { it.patient = patientPseudonym }
|
||||||
this.molecularPathologyFindings?.forEach { it.patient = patientPseudonym }
|
this.molecularPathologyFindings?.forEach { it.patient = patientPseudonym }
|
||||||
this.molecularTherapies?.forEach { molecularTherapy -> molecularTherapy.history.forEach { it.patient = patientPseudonym } }
|
this.molecularTherapies?.forEach { molecularTherapy ->
|
||||||
|
molecularTherapy.history.forEach {
|
||||||
|
it.patient = patientPseudonym
|
||||||
|
}
|
||||||
|
}
|
||||||
this.ngsReports?.forEach { it.patient = patientPseudonym }
|
this.ngsReports?.forEach { it.patient = patientPseudonym }
|
||||||
this.previousGuidelineTherapies?.forEach { it.patient = patientPseudonym }
|
this.previousGuidelineTherapies?.forEach { it.patient = patientPseudonym }
|
||||||
this.rebiopsyRequests?.forEach { it.patient = patientPseudonym }
|
this.rebiopsyRequests?.forEach { it.patient = patientPseudonym }
|
||||||
@ -63,7 +67,6 @@ infix fun MtbFile.pseudonymizeWith(pseudonymizeService: PseudonymizeService) {
|
|||||||
* Creates new hash of content IDs with given prefix except for patient IDs
|
* Creates new hash of content IDs with given prefix except for patient IDs
|
||||||
*
|
*
|
||||||
* @param pseudonymizeService The pseudonymizeService to be used
|
* @param pseudonymizeService The pseudonymizeService to be used
|
||||||
*
|
|
||||||
* @return The MTB file containing rehashed content IDs
|
* @return The MTB file containing rehashed content IDs
|
||||||
*/
|
*/
|
||||||
infix fun MtbFile.anonymizeContentWith(pseudonymizeService: PseudonymizeService) {
|
infix fun MtbFile.anonymizeContentWith(pseudonymizeService: PseudonymizeService) {
|
||||||
@ -224,3 +227,89 @@ infix fun MtbFile.anonymizeContentWith(pseudonymizeService: PseudonymizeService)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Replaces patient ID with generated patient pseudonym
|
||||||
|
*
|
||||||
|
* @since 0.11.0
|
||||||
|
*
|
||||||
|
* @param pseudonymizeService The pseudonymizeService to be used
|
||||||
|
* @return The MTB file containing patient pseudonymes
|
||||||
|
*/
|
||||||
|
infix fun Mtb.pseudonymizeWith(pseudonymizeService: PseudonymizeService) {
|
||||||
|
val patientPseudonym = pseudonymizeService.patientPseudonym(PatientId(this.patient.id)).value
|
||||||
|
|
||||||
|
this.episodesOfCare?.forEach { it.patient.id = patientPseudonym }
|
||||||
|
this.carePlans?.forEach {
|
||||||
|
it.patient.id = patientPseudonym
|
||||||
|
it.rebiopsyRequests?.forEach { it.patient.id = patientPseudonym }
|
||||||
|
it.histologyReevaluationRequests?.forEach { it.patient.id = patientPseudonym }
|
||||||
|
it.medicationRecommendations.forEach { it.patient.id = patientPseudonym }
|
||||||
|
it.studyEnrollmentRecommendations?.forEach { it.patient.id = patientPseudonym }
|
||||||
|
it.procedureRecommendations?.forEach { it.patient.id = patientPseudonym }
|
||||||
|
it.geneticCounselingRecommendation.patient.id = patientPseudonym
|
||||||
|
}
|
||||||
|
this.diagnoses?.forEach { it.patient.id = patientPseudonym }
|
||||||
|
this.guidelineTherapies?.forEach { it.patient.id = patientPseudonym }
|
||||||
|
this.guidelineProcedures?.forEach { it.patient.id = patientPseudonym }
|
||||||
|
this.patient.id = patientPseudonym
|
||||||
|
this.claims?.forEach { it.patient.id = patientPseudonym }
|
||||||
|
this.claimResponses?.forEach { it.patient.id = patientPseudonym }
|
||||||
|
this.diagnoses?.forEach { it.patient.id = patientPseudonym }
|
||||||
|
this.histologyReports?.forEach {
|
||||||
|
it.patient.id = patientPseudonym
|
||||||
|
it.results.tumorMorphology?.patient?.id = patientPseudonym
|
||||||
|
it.results.tumorCellContent?.patient?.id = patientPseudonym
|
||||||
|
}
|
||||||
|
this.ngsReports?.forEach {
|
||||||
|
it.patient.id = patientPseudonym
|
||||||
|
it.results.simpleVariants?.forEach { it.patient.id = patientPseudonym }
|
||||||
|
it.results.copyNumberVariants?.forEach { it.patient.id = patientPseudonym }
|
||||||
|
it.results.dnaFusions?.forEach { it.patient.id = patientPseudonym }
|
||||||
|
it.results.rnaFusions?.forEach { it.patient.id = patientPseudonym }
|
||||||
|
it.results.tumorCellContent?.patient?.id = patientPseudonym
|
||||||
|
it.results.brcaness?.patient?.id = patientPseudonym
|
||||||
|
it.results.tmb?.patient?.id = patientPseudonym
|
||||||
|
it.results.hrdScore?.patient?.id = patientPseudonym
|
||||||
|
}
|
||||||
|
this.ihcReports?.forEach {
|
||||||
|
it.patient.id = patientPseudonym
|
||||||
|
it.results.msiMmr?.forEach { it.patient.id = patientPseudonym }
|
||||||
|
it.results.proteinExpression?.forEach { it.patient.id = patientPseudonym }
|
||||||
|
}
|
||||||
|
this.responses?.forEach { it.patient.id = patientPseudonym }
|
||||||
|
this.specimens?.forEach { it.patient.id = patientPseudonym }
|
||||||
|
this.priorDiagnosticReports?.forEach { it.patient.id = patientPseudonym }
|
||||||
|
this.performanceStatus.forEach { it.patient.id = patientPseudonym }
|
||||||
|
this.systemicTherapies.forEach {
|
||||||
|
it.history?.forEach {
|
||||||
|
it.patient.id = patientPseudonym
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates new hash of content IDs with given prefix except for patient IDs
|
||||||
|
*
|
||||||
|
* @since 0.11.0
|
||||||
|
*
|
||||||
|
* @param pseudonymizeService The pseudonymizeService to be used
|
||||||
|
* @return The MTB file containing rehashed content IDs
|
||||||
|
*/
|
||||||
|
infix fun Mtb.anonymizeContentWith(pseudonymizeService: PseudonymizeService) {
|
||||||
|
val prefix = pseudonymizeService.prefix()
|
||||||
|
|
||||||
|
fun anonymize(id: String): String {
|
||||||
|
val hash = DigestUtils.sha256Hex("$prefix-$id").substring(0, 41).lowercase()
|
||||||
|
return "$prefix$hash"
|
||||||
|
}
|
||||||
|
|
||||||
|
this.episodesOfCare?.forEach {
|
||||||
|
it?.apply {
|
||||||
|
id = id?.let {
|
||||||
|
anonymize(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO all other properties
|
||||||
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of ETL-Processor
|
* This file is part of ETL-Processor
|
||||||
*
|
*
|
||||||
* Copyright (c) 2023 Comprehensive Cancer Center Mainfranken, Datenintegrationszentrum Philipps-Universität Marburg and Contributors
|
* Copyright (c) 2025 Comprehensive Cancer Center Mainfranken, Datenintegrationszentrum Philipps-Universität Marburg and Contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Affero General Public License as published
|
||||||
@ -28,10 +28,11 @@ import dev.dnpm.etl.processor.monitoring.Report
|
|||||||
import dev.dnpm.etl.processor.monitoring.Request
|
import dev.dnpm.etl.processor.monitoring.Request
|
||||||
import dev.dnpm.etl.processor.monitoring.RequestStatus
|
import dev.dnpm.etl.processor.monitoring.RequestStatus
|
||||||
import dev.dnpm.etl.processor.monitoring.RequestType
|
import dev.dnpm.etl.processor.monitoring.RequestType
|
||||||
import dev.dnpm.etl.processor.output.MtbFileSender
|
import dev.dnpm.etl.processor.output.*
|
||||||
import dev.dnpm.etl.processor.pseudonym.PseudonymizeService
|
import dev.dnpm.etl.processor.pseudonym.PseudonymizeService
|
||||||
import dev.dnpm.etl.processor.pseudonym.anonymizeContentWith
|
import dev.dnpm.etl.processor.pseudonym.anonymizeContentWith
|
||||||
import dev.dnpm.etl.processor.pseudonym.pseudonymizeWith
|
import dev.dnpm.etl.processor.pseudonym.pseudonymizeWith
|
||||||
|
import dev.pcvolkmer.mv64e.mtb.Mtb
|
||||||
import org.apache.commons.codec.binary.Base32
|
import org.apache.commons.codec.binary.Base32
|
||||||
import org.apache.commons.codec.digest.DigestUtils
|
import org.apache.commons.codec.digest.DigestUtils
|
||||||
import org.springframework.context.ApplicationEventPublisher
|
import org.springframework.context.ApplicationEventPublisher
|
||||||
@ -56,30 +57,40 @@ class RequestProcessor(
|
|||||||
|
|
||||||
fun processMtbFile(mtbFile: MtbFile, requestId: RequestId) {
|
fun processMtbFile(mtbFile: MtbFile, requestId: RequestId) {
|
||||||
val pid = PatientId(mtbFile.patient.id)
|
val pid = PatientId(mtbFile.patient.id)
|
||||||
|
|
||||||
mtbFile pseudonymizeWith pseudonymizeService
|
mtbFile pseudonymizeWith pseudonymizeService
|
||||||
mtbFile anonymizeContentWith pseudonymizeService
|
mtbFile anonymizeContentWith pseudonymizeService
|
||||||
|
val request = BwhcV1MtbFileRequest(requestId, transformationService.transform(mtbFile))
|
||||||
|
saveAndSend(request, pid)
|
||||||
|
}
|
||||||
|
|
||||||
val request =
|
fun processMtbFile(mtbFile: Mtb) {
|
||||||
MtbFileSender.MtbFileRequest(requestId, transformationService.transform(mtbFile))
|
processMtbFile(mtbFile, randomRequestId())
|
||||||
|
}
|
||||||
|
|
||||||
val patientPseudonym = PatientPseudonym(request.mtbFile.patient.id)
|
fun processMtbFile(mtbFile: Mtb, requestId: RequestId) {
|
||||||
|
val pid = PatientId(mtbFile.patient.id)
|
||||||
|
mtbFile pseudonymizeWith pseudonymizeService
|
||||||
|
mtbFile anonymizeContentWith pseudonymizeService
|
||||||
|
val request = DnpmV2MtbFileRequest(requestId, transformationService.transform(mtbFile))
|
||||||
|
saveAndSend(request, pid)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun <T> saveAndSend(request: MtbFileRequest<T>, pid: PatientId) {
|
||||||
requestService.save(
|
requestService.save(
|
||||||
Request(
|
Request(
|
||||||
requestId,
|
request.requestId,
|
||||||
patientPseudonym,
|
request.patientPseudonym(),
|
||||||
pid,
|
pid,
|
||||||
fingerprint(request.mtbFile),
|
fingerprint(request),
|
||||||
RequestType.MTB_FILE,
|
RequestType.MTB_FILE,
|
||||||
RequestStatus.UNKNOWN
|
RequestStatus.UNKNOWN
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
if (appConfigProperties.duplicationDetection && isDuplication(mtbFile)) {
|
if (appConfigProperties.duplicationDetection && isDuplication(request)) {
|
||||||
applicationEventPublisher.publishEvent(
|
applicationEventPublisher.publishEvent(
|
||||||
ResponseEvent(
|
ResponseEvent(
|
||||||
requestId,
|
request.requestId,
|
||||||
Instant.now(),
|
Instant.now(),
|
||||||
RequestStatus.DUPLICATION
|
RequestStatus.DUPLICATION
|
||||||
)
|
)
|
||||||
@ -91,19 +102,22 @@ class RequestProcessor(
|
|||||||
|
|
||||||
applicationEventPublisher.publishEvent(
|
applicationEventPublisher.publishEvent(
|
||||||
ResponseEvent(
|
ResponseEvent(
|
||||||
requestId,
|
request.requestId,
|
||||||
Instant.now(),
|
Instant.now(),
|
||||||
responseStatus.status,
|
responseStatus.status,
|
||||||
when (responseStatus.status) {
|
when (responseStatus.status) {
|
||||||
RequestStatus.WARNING -> Optional.of(responseStatus.body)
|
RequestStatus.ERROR, RequestStatus.WARNING -> Optional.of(responseStatus.body)
|
||||||
else -> Optional.empty()
|
else -> Optional.empty()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isDuplication(pseudonymizedMtbFile: MtbFile): Boolean {
|
private fun <T> isDuplication(pseudonymizedMtbFileRequest: MtbFileRequest<T>): Boolean {
|
||||||
val patientPseudonym = PatientPseudonym(pseudonymizedMtbFile.patient.id)
|
val patientPseudonym = when (pseudonymizedMtbFileRequest) {
|
||||||
|
is BwhcV1MtbFileRequest -> PatientPseudonym(pseudonymizedMtbFileRequest.content.patient.id)
|
||||||
|
is DnpmV2MtbFileRequest -> PatientPseudonym(pseudonymizedMtbFileRequest.content.patient.id)
|
||||||
|
}
|
||||||
|
|
||||||
val lastMtbFileRequestForPatient =
|
val lastMtbFileRequestForPatient =
|
||||||
requestService.lastMtbFileRequestForPatientPseudonym(patientPseudonym)
|
requestService.lastMtbFileRequestForPatientPseudonym(patientPseudonym)
|
||||||
@ -112,7 +126,7 @@ class RequestProcessor(
|
|||||||
|
|
||||||
return null != lastMtbFileRequestForPatient
|
return null != lastMtbFileRequestForPatient
|
||||||
&& !isLastRequestDeletion
|
&& !isLastRequestDeletion
|
||||||
&& lastMtbFileRequestForPatient.fingerprint == fingerprint(pseudonymizedMtbFile)
|
&& lastMtbFileRequestForPatient.fingerprint == fingerprint(pseudonymizedMtbFileRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun processDeletion(patientId: PatientId, isConsented: ConsentStatus) {
|
fun processDeletion(patientId: PatientId, isConsented: ConsentStatus) {
|
||||||
@ -141,10 +155,7 @@ class RequestProcessor(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
val responseStatus =
|
val responseStatus = sender.send(DeleteRequest(requestId, patientPseudonym))
|
||||||
sender.send(MtbFileSender.DeleteRequest(requestId, patientPseudonym))
|
|
||||||
|
|
||||||
//fixme: publish proper report if consent check failed
|
|
||||||
|
|
||||||
applicationEventPublisher.publishEvent(
|
applicationEventPublisher.publishEvent(
|
||||||
ResponseEvent(
|
ResponseEvent(
|
||||||
@ -173,8 +184,11 @@ class RequestProcessor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun fingerprint(mtbFile: MtbFile): Fingerprint {
|
private fun <T> fingerprint(request: MtbFileRequest<T>): Fingerprint {
|
||||||
return fingerprint(objectMapper.writeValueAsString(mtbFile))
|
return when (request) {
|
||||||
|
is BwhcV1MtbFileRequest -> fingerprint(objectMapper.writeValueAsString(request.content))
|
||||||
|
is DnpmV2MtbFileRequest -> fingerprint(objectMapper.writeValueAsString(request.content))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun fingerprint(s: String): Fingerprint {
|
private fun fingerprint(s: String): Fingerprint {
|
||||||
@ -184,4 +198,5 @@ class RequestProcessor(
|
|||||||
.lowercase()
|
.lowercase()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -23,10 +23,21 @@ import com.fasterxml.jackson.databind.ObjectMapper
|
|||||||
import com.jayway.jsonpath.JsonPath
|
import com.jayway.jsonpath.JsonPath
|
||||||
import com.jayway.jsonpath.PathNotFoundException
|
import com.jayway.jsonpath.PathNotFoundException
|
||||||
import de.ukw.ccc.bwhc.dto.MtbFile
|
import de.ukw.ccc.bwhc.dto.MtbFile
|
||||||
|
import dev.pcvolkmer.mv64e.mtb.Mtb
|
||||||
|
|
||||||
class TransformationService(private val objectMapper: ObjectMapper, private val transformations: List<Transformation>) {
|
class TransformationService(private val objectMapper: ObjectMapper, private val transformations: List<Transformation>) {
|
||||||
fun transform(mtbFile: MtbFile): MtbFile {
|
fun transform(mtbFile: MtbFile): MtbFile {
|
||||||
var json = objectMapper.writeValueAsString(mtbFile)
|
val json = transform(objectMapper.writeValueAsString(mtbFile))
|
||||||
|
return objectMapper.readValue(json, MtbFile::class.java)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun transform(mtbFile: Mtb): Mtb {
|
||||||
|
val json = transform(objectMapper.writeValueAsString(mtbFile))
|
||||||
|
return objectMapper.readValue(json, Mtb::class.java)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun transform(content: String): String {
|
||||||
|
var json = content
|
||||||
|
|
||||||
transformations.forEach { transformation ->
|
transformations.forEach { transformation ->
|
||||||
val jsonPath = JsonPath.parse(json)
|
val jsonPath = JsonPath.parse(json)
|
||||||
@ -48,7 +59,7 @@ class TransformationService(private val objectMapper: ObjectMapper, private val
|
|||||||
json = jsonPath.jsonString()
|
json = jsonPath.jsonString()
|
||||||
}
|
}
|
||||||
|
|
||||||
return objectMapper.readValue(json, MtbFile::class.java)
|
return json
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getTransformations(): List<Transformation> {
|
fun getTransformations(): List<Transformation> {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of ETL-Processor
|
* This file is part of ETL-Processor
|
||||||
*
|
*
|
||||||
* Copyright (c) 2024 Comprehensive Cancer Center Mainfranken, Datenintegrationszentrum Philipps-Universität Marburg and Contributors
|
* Copyright (c) 2025 Comprehensive Cancer Center Mainfranken, Datenintegrationszentrum Philipps-Universität Marburg and Contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Affero General Public License as published
|
||||||
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package dev.dnpm.etl.processor
|
package dev.dnpm.etl.processor
|
||||||
|
|
||||||
|
import org.springframework.http.MediaType
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class Fingerprint(val value: String) {
|
class Fingerprint(val value: String) {
|
||||||
@ -47,3 +48,16 @@ value class PatientId(val value: String)
|
|||||||
value class PatientPseudonym(val value: String)
|
value class PatientPseudonym(val value: String)
|
||||||
|
|
||||||
fun emptyPatientPseudonym() = PatientPseudonym("")
|
fun emptyPatientPseudonym() = PatientPseudonym("")
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom MediaTypes
|
||||||
|
*
|
||||||
|
* @since 0.11.0
|
||||||
|
*/
|
||||||
|
object CustomMediaType {
|
||||||
|
val APPLICATION_VND_DNPM_V2_MTB_JSON = MediaType("application", "vnd.dnpm.v2.mtb+json")
|
||||||
|
const val APPLICATION_VND_DNPM_V2_MTB_JSON_VALUE = "application/vnd.dnpm.v2.mtb+json"
|
||||||
|
|
||||||
|
val APPLICATION_VND_DNPM_V2_RD_JSON = MediaType("application", "vnd.dnpm.v2.rd+json")
|
||||||
|
const val APPLICATION_VND_DNPM_V2_RD_JSON_VALUE = "application/vnd.dnpm.v2.rd+json"
|
||||||
|
}
|
||||||
|
@ -650,11 +650,12 @@ input.inline:focus-visible {
|
|||||||
|
|
||||||
.tab:hover,
|
.tab:hover,
|
||||||
.tab.active {
|
.tab.active {
|
||||||
background: var(--table-border);
|
background: var(--bg-gray);
|
||||||
|
color: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tabcontent {
|
.tabcontent {
|
||||||
border: 1px solid var(--table-border);
|
border: 2px solid var(--bg-gray);
|
||||||
border-radius: 0 .5em .5em .5em;
|
border-radius: 0 .5em .5em .5em;
|
||||||
display: none;
|
display: none;
|
||||||
padding: 1em;
|
padding: 1em;
|
||||||
@ -697,3 +698,13 @@ a.reload {
|
|||||||
padding: 1em;
|
padding: 1em;
|
||||||
background: var(--bg-red-op);
|
background: var(--bg-red-op);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.issue-message {
|
||||||
|
font-family: monospace;
|
||||||
|
font-weight: bolder;
|
||||||
|
}
|
||||||
|
|
||||||
|
.issue-path {
|
||||||
|
font-family: monospace;
|
||||||
|
line-height: 1rem;
|
||||||
|
}
|
@ -20,7 +20,8 @@
|
|||||||
<img th:if="${mtbFileSender.startsWith('Kafka')}" th:src="@{/kafka.png}" alt="Kafka-Broker" />
|
<img th:if="${mtbFileSender.startsWith('Kafka')}" th:src="@{/kafka.png}" alt="Kafka-Broker" />
|
||||||
<span>ETL-Processor</span>
|
<span>ETL-Processor</span>
|
||||||
<span></span>
|
<span></span>
|
||||||
<span th:if="${mtbFileSender.startsWith('Rest')}">bwHC-Backend</span>
|
<span th:if="${mtbFileSender.startsWith('RestBwhc')}">bwHC-Backend</span>
|
||||||
|
<span th:if="${mtbFileSender.startsWith('RestDip')}">DNPM:DIP-Backend</span>
|
||||||
<span th:if="${mtbFileSender.startsWith('Kafka')}">Kafka-Broker</span>
|
<span th:if="${mtbFileSender.startsWith('Kafka')}">Kafka-Broker</span>
|
||||||
</div>
|
</div>
|
||||||
</th:block>
|
</th:block>
|
@ -47,7 +47,7 @@
|
|||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Schweregrad</th>
|
<th>Schweregrad</th>
|
||||||
<th>Beschreibung</th>
|
<th>Beschreibung und Pfad</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@ -56,7 +56,11 @@
|
|||||||
<td th:if="${issue.severity.value == 'warning'}" class="bg-yellow"><small>[[ ${issue.severity} ]]</small></td>
|
<td th:if="${issue.severity.value == 'warning'}" class="bg-yellow"><small>[[ ${issue.severity} ]]</small></td>
|
||||||
<td th:if="${issue.severity.value == 'error'}" class="bg-red"><small>[[ ${issue.severity} ]]</small></td>
|
<td th:if="${issue.severity.value == 'error'}" class="bg-red"><small>[[ ${issue.severity} ]]</small></td>
|
||||||
<td th:if="${issue.severity.value == 'fatal'}" class="bg-red"><small>[[ ${issue.severity} ]]</small></td>
|
<td th:if="${issue.severity.value == 'fatal'}" class="bg-red"><small>[[ ${issue.severity} ]]</small></td>
|
||||||
<td>[[ ${issue.message} ]]</td>
|
<td>
|
||||||
|
<div class="issue-message">[[ ${issue.message} ]]</div>
|
||||||
|
<div class="issue-path" th:if="${issue.path.isPresent()}">[[ ${issue.path.get()} ]]</div>
|
||||||
|
<div class="issue-path" th:if="${issue.path.isEmpty()}"><i>Keine Angabe</i></div>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
@ -18,12 +18,3 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
package dev.dnpm.etl.processor
|
package dev.dnpm.etl.processor
|
||||||
|
|
||||||
import org.mockito.ArgumentMatchers
|
|
||||||
|
|
||||||
inline fun <reified T> anyValueClass(): T {
|
|
||||||
val unboxedClass = T::class.java.declaredFields.first().type
|
|
||||||
return ArgumentMatchers.any(unboxedClass as Class<T>)
|
|
||||||
?: T::class.java.getDeclaredMethod("box-impl", unboxedClass)
|
|
||||||
.invoke(null, null) as T
|
|
||||||
}
|
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of ETL-Processor
|
* This file is part of ETL-Processor
|
||||||
*
|
*
|
||||||
* Copyright (c) 2024 Comprehensive Cancer Center Mainfranken, Datenintegrationszentrum Philipps-Universität Marburg and Contributors
|
* Copyright (c) 2025 Comprehensive Cancer Center Mainfranken, Datenintegrationszentrum Philipps-Universität Marburg and Contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Affero General Public License as published
|
||||||
@ -25,6 +25,7 @@ import de.ukw.ccc.bwhc.dto.MtbFile
|
|||||||
import de.ukw.ccc.bwhc.dto.Patient
|
import de.ukw.ccc.bwhc.dto.Patient
|
||||||
import dev.dnpm.etl.processor.anyValueClass
|
import dev.dnpm.etl.processor.anyValueClass
|
||||||
import dev.dnpm.etl.processor.consent.ConsentStatus
|
import dev.dnpm.etl.processor.consent.ConsentStatus
|
||||||
|
import dev.dnpm.etl.processor.CustomMediaType
|
||||||
import dev.dnpm.etl.processor.services.RequestProcessor
|
import dev.dnpm.etl.processor.services.RequestProcessor
|
||||||
import org.apache.kafka.clients.consumer.ConsumerRecord
|
import org.apache.kafka.clients.consumer.ConsumerRecord
|
||||||
import org.apache.kafka.common.header.internals.RecordHeader
|
import org.apache.kafka.common.header.internals.RecordHeader
|
||||||
@ -75,7 +76,7 @@ class KafkaInputListenerTest {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
verify(requestProcessor, times(1)).processMtbFile(any())
|
verify(requestProcessor, times(1)).processMtbFile(any<MtbFile>())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -108,14 +109,7 @@ class KafkaInputListenerTest {
|
|||||||
.withConsent(Consent.builder().withStatus(Consent.Status.ACTIVE).build())
|
.withConsent(Consent.builder().withStatus(Consent.Status.ACTIVE).build())
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
val headers = RecordHeaders(
|
val headers = RecordHeaders(listOf(RecordHeader("requestId", UUID.randomUUID().toString().toByteArray())))
|
||||||
listOf(
|
|
||||||
RecordHeader(
|
|
||||||
"requestId",
|
|
||||||
UUID.randomUUID().toString().toByteArray()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
kafkaInputListener.onMessage(
|
kafkaInputListener.onMessage(
|
||||||
ConsumerRecord(
|
ConsumerRecord(
|
||||||
"testtopic",
|
"testtopic",
|
||||||
@ -132,7 +126,7 @@ class KafkaInputListenerTest {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
verify(requestProcessor, times(1)).processMtbFile(any(), anyValueClass())
|
verify(requestProcessor, times(1)).processMtbFile(any<MtbFile>(), anyValueClass())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -142,12 +136,36 @@ class KafkaInputListenerTest {
|
|||||||
.withConsent(Consent.builder().withStatus(Consent.Status.REJECTED).build())
|
.withConsent(Consent.builder().withStatus(Consent.Status.REJECTED).build())
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
|
val headers = RecordHeaders(listOf(RecordHeader("requestId", UUID.randomUUID().toString().toByteArray())))
|
||||||
|
kafkaInputListener.onMessage(
|
||||||
|
ConsumerRecord(
|
||||||
|
"testtopic",
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
-1L,
|
||||||
|
TimestampType.NO_TIMESTAMP_TYPE,
|
||||||
|
-1,
|
||||||
|
-1,
|
||||||
|
"",
|
||||||
|
this.objectMapper.writeValueAsString(mtbFile),
|
||||||
|
headers,
|
||||||
|
Optional.empty()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
verify(requestProcessor, times(1)).processDeletion(anyValueClass(), anyValueClass(), eq(ConsentStatus.IGNORED)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun shouldNotProcessDnpmV2Request() {
|
||||||
|
val mtbFile = MtbFile.builder()
|
||||||
|
.withPatient(Patient.builder().withId("DUMMY_12345678").build())
|
||||||
|
.withConsent(Consent.builder().withStatus(Consent.Status.REJECTED).build())
|
||||||
|
.build()
|
||||||
|
|
||||||
val headers = RecordHeaders(
|
val headers = RecordHeaders(
|
||||||
listOf(
|
listOf(
|
||||||
RecordHeader(
|
RecordHeader("requestId", UUID.randomUUID().toString().toByteArray()),
|
||||||
"requestId",
|
RecordHeader("contentType", CustomMediaType.APPLICATION_VND_DNPM_V2_MTB_JSON_VALUE.toByteArray())
|
||||||
UUID.randomUUID().toString().toByteArray()
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
kafkaInputListener.onMessage(
|
kafkaInputListener.onMessage(
|
||||||
@ -165,11 +183,7 @@ class KafkaInputListenerTest {
|
|||||||
Optional.empty()
|
Optional.empty()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
verify(requestProcessor, times(1)).processDeletion(
|
verify(requestProcessor, times(0)).processDeletion(anyValueClass(), anyValueClass(), eq(ConsentStatus.IGNORED)
|
||||||
anyValueClass(),
|
|
||||||
anyValueClass(),
|
|
||||||
eq(ConsentStatus.IGNORED)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of ETL-Processor
|
* This file is part of ETL-Processor
|
||||||
*
|
*
|
||||||
* Copyright (c) 2024 Comprehensive Cancer Center Mainfranken, Datenintegrationszentrum Philipps-Universität Marburg and Contributors
|
* Copyright (c) 2025 Comprehensive Cancer Center Mainfranken, Datenintegrationszentrum Philipps-Universität Marburg and Contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Affero General Public License as published
|
||||||
@ -24,14 +24,19 @@ import de.ukw.ccc.bwhc.dto.*
|
|||||||
import dev.dnpm.etl.processor.anyValueClass
|
import dev.dnpm.etl.processor.anyValueClass
|
||||||
import dev.dnpm.etl.processor.consent.ConsentCheckedIgnored
|
import dev.dnpm.etl.processor.consent.ConsentCheckedIgnored
|
||||||
import dev.dnpm.etl.processor.consent.ConsentStatus
|
import dev.dnpm.etl.processor.consent.ConsentStatus
|
||||||
|
import dev.dnpm.etl.processor.CustomMediaType
|
||||||
import dev.dnpm.etl.processor.services.RequestProcessor
|
import dev.dnpm.etl.processor.services.RequestProcessor
|
||||||
|
import dev.pcvolkmer.mv64e.mtb.Mtb
|
||||||
import org.junit.jupiter.api.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
|
import org.junit.jupiter.api.Nested
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.jupiter.api.extension.ExtendWith
|
import org.junit.jupiter.api.extension.ExtendWith
|
||||||
import org.mockito.Mock
|
import org.mockito.Mock
|
||||||
import org.mockito.Mockito.*
|
import org.mockito.Mockito.*
|
||||||
import org.mockito.junit.jupiter.MockitoExtension
|
import org.mockito.junit.jupiter.MockitoExtension
|
||||||
import org.mockito.kotlin.any
|
import org.mockito.kotlin.any
|
||||||
|
import org.mockito.kotlin.anyValueClass
|
||||||
|
import org.springframework.core.io.ClassPathResource
|
||||||
import org.springframework.http.MediaType
|
import org.springframework.http.MediaType
|
||||||
import org.springframework.test.web.servlet.MockMvc
|
import org.springframework.test.web.servlet.MockMvc
|
||||||
import org.springframework.test.web.servlet.delete
|
import org.springframework.test.web.servlet.delete
|
||||||
@ -41,52 +46,28 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders
|
|||||||
@ExtendWith(MockitoExtension::class)
|
@ExtendWith(MockitoExtension::class)
|
||||||
class MtbFileRestControllerTest {
|
class MtbFileRestControllerTest {
|
||||||
|
|
||||||
|
private val objectMapper = ObjectMapper()
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
inner class BwhcRequests {
|
||||||
|
|
||||||
private lateinit var mockMvc: MockMvc
|
private lateinit var mockMvc: MockMvc
|
||||||
|
|
||||||
private lateinit var requestProcessor: RequestProcessor
|
private lateinit var requestProcessor: RequestProcessor
|
||||||
|
|
||||||
private val objectMapper = ObjectMapper()
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
fun setup(
|
fun setup(
|
||||||
@Mock requestProcessor: RequestProcessor
|
@Mock requestProcessor: RequestProcessor
|
||||||
) {
|
) {
|
||||||
this.requestProcessor = requestProcessor
|
this.requestProcessor = requestProcessor
|
||||||
val controller = MtbFileRestController(
|
val controller = MtbFileRestController(requestProcessor, ConsentCheckedIgnored())
|
||||||
requestProcessor, ConsentCheckedIgnored()
|
|
||||||
)
|
|
||||||
|
|
||||||
this.mockMvc = MockMvcBuilders.standaloneSetup(controller).build()
|
this.mockMvc = MockMvcBuilders.standaloneSetup(controller).build()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun shouldProcessMtbFilePostRequest() {
|
fun shouldProcessPostRequest() {
|
||||||
val mtbFile = MtbFile.builder()
|
|
||||||
.withPatient(
|
|
||||||
Patient.builder()
|
|
||||||
.withId("TEST_12345678")
|
|
||||||
.withBirthDate("2000-08-08")
|
|
||||||
.withGender(Patient.Gender.MALE)
|
|
||||||
.build()
|
|
||||||
)
|
|
||||||
.withConsent(
|
|
||||||
Consent.builder()
|
|
||||||
.withId("1")
|
|
||||||
.withStatus(Consent.Status.ACTIVE)
|
|
||||||
.withPatient("TEST_12345678")
|
|
||||||
.build()
|
|
||||||
)
|
|
||||||
.withEpisode(
|
|
||||||
Episode.builder()
|
|
||||||
.withId("1")
|
|
||||||
.withPatient("TEST_12345678")
|
|
||||||
.withPeriod(PeriodStart("2023-08-08"))
|
|
||||||
.build()
|
|
||||||
)
|
|
||||||
.build()
|
|
||||||
|
|
||||||
mockMvc.post("/mtbfile") {
|
mockMvc.post("/mtbfile") {
|
||||||
content = objectMapper.writeValueAsString(mtbFile)
|
content = objectMapper.writeValueAsString(bwhcMtbFileContent(Consent.Status.ACTIVE))
|
||||||
contentType = MediaType.APPLICATION_JSON
|
contentType = MediaType.APPLICATION_JSON
|
||||||
}.andExpect {
|
}.andExpect {
|
||||||
status {
|
status {
|
||||||
@ -94,37 +75,13 @@ class MtbFileRestControllerTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
verify(requestProcessor, times(1)).processMtbFile(any())
|
verify(requestProcessor, times(1)).processMtbFile(any<MtbFile>())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun shouldProcessMtbFilePostRequestWithRejectedConsent() {
|
fun shouldProcessPostRequestWithRejectedConsent() {
|
||||||
val mtbFile = MtbFile.builder()
|
|
||||||
.withPatient(
|
|
||||||
Patient.builder()
|
|
||||||
.withId("TEST_12345678")
|
|
||||||
.withBirthDate("2000-08-08")
|
|
||||||
.withGender(Patient.Gender.MALE)
|
|
||||||
.build()
|
|
||||||
)
|
|
||||||
.withConsent(
|
|
||||||
Consent.builder()
|
|
||||||
.withId("1")
|
|
||||||
.withStatus(Consent.Status.REJECTED)
|
|
||||||
.withPatient("TEST_12345678")
|
|
||||||
.build()
|
|
||||||
)
|
|
||||||
.withEpisode(
|
|
||||||
Episode.builder()
|
|
||||||
.withId("1")
|
|
||||||
.withPatient("TEST_12345678")
|
|
||||||
.withPeriod(PeriodStart("2023-08-08"))
|
|
||||||
.build()
|
|
||||||
)
|
|
||||||
.build()
|
|
||||||
|
|
||||||
mockMvc.post("/mtbfile") {
|
mockMvc.post("/mtbfile") {
|
||||||
content = objectMapper.writeValueAsString(mtbFile)
|
content = objectMapper.writeValueAsString(bwhcMtbFileContent(Consent.Status.REJECTED))
|
||||||
contentType = MediaType.APPLICATION_JSON
|
contentType = MediaType.APPLICATION_JSON
|
||||||
}.andExpect {
|
}.andExpect {
|
||||||
status {
|
status {
|
||||||
@ -132,24 +89,134 @@ class MtbFileRestControllerTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
verify(requestProcessor, times(1)).processDeletion(
|
verify(requestProcessor, times(1)).processDeletion(anyValueClass())
|
||||||
anyValueClass(),
|
|
||||||
org.mockito.kotlin.eq(ConsentStatus.CONSENT_REJECTED)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun shouldProcessMtbFileDeleteRequest() {
|
fun shouldProcessDeleteRequest() {
|
||||||
mockMvc.delete("/mtbfile/TEST_12345678").andExpect {
|
mockMvc.delete("/mtbfile/TEST_12345678").andExpect {
|
||||||
status {
|
status {
|
||||||
isAccepted()
|
isAccepted()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
verify(requestProcessor, times(1)).processDeletion(
|
verify(requestProcessor, times(1)).processDeletion(anyValueClass())
|
||||||
anyValueClass(),
|
}
|
||||||
org.mockito.kotlin.eq(ConsentStatus.IGNORED)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
inner class BwhcRequestsWithAlias {
|
||||||
|
|
||||||
|
private lateinit var mockMvc: MockMvc
|
||||||
|
|
||||||
|
private lateinit var requestProcessor: RequestProcessor
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
fun setup(
|
||||||
|
@Mock requestProcessor: RequestProcessor
|
||||||
|
) {
|
||||||
|
this.requestProcessor = requestProcessor
|
||||||
|
val controller = MtbFileRestController(requestProcessor)
|
||||||
|
this.mockMvc = MockMvcBuilders.standaloneSetup(controller).build()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun shouldProcessPostRequest() {
|
||||||
|
mockMvc.post("/mtb") {
|
||||||
|
content = objectMapper.writeValueAsString(bwhcMtbFileContent(Consent.Status.ACTIVE))
|
||||||
|
contentType = MediaType.APPLICATION_JSON
|
||||||
|
}.andExpect {
|
||||||
|
status {
|
||||||
|
isAccepted()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
verify(requestProcessor, times(1)).processMtbFile(any<MtbFile>())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun shouldProcessPostRequestWithRejectedConsent() {
|
||||||
|
mockMvc.post("/mtb") {
|
||||||
|
content = objectMapper.writeValueAsString(bwhcMtbFileContent(Consent.Status.REJECTED))
|
||||||
|
contentType = MediaType.APPLICATION_JSON
|
||||||
|
}.andExpect {
|
||||||
|
status {
|
||||||
|
isAccepted()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
verify(requestProcessor, times(1)).processDeletion(anyValueClass())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun shouldProcessDeleteRequest() {
|
||||||
|
mockMvc.delete("/mtb/TEST_12345678").andExpect {
|
||||||
|
status {
|
||||||
|
isAccepted()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
verify(requestProcessor, times(1)).processDeletion(anyValueClass())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
inner class RequestsForDnpmDataModel21 {
|
||||||
|
|
||||||
|
private lateinit var mockMvc: MockMvc
|
||||||
|
|
||||||
|
private lateinit var requestProcessor: RequestProcessor
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
fun setup(
|
||||||
|
@Mock requestProcessor: RequestProcessor
|
||||||
|
) {
|
||||||
|
this.requestProcessor = requestProcessor
|
||||||
|
val controller = MtbFileRestController(requestProcessor)
|
||||||
|
this.mockMvc = MockMvcBuilders.standaloneSetup(controller).build()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun shouldRespondPostRequest() {
|
||||||
|
val mtbFileContent = ClassPathResource("mv64e-mtb-fake-patient.json").inputStream.readAllBytes().toString(Charsets.UTF_8)
|
||||||
|
|
||||||
|
mockMvc.post("/mtb") {
|
||||||
|
content = mtbFileContent
|
||||||
|
contentType = CustomMediaType.APPLICATION_VND_DNPM_V2_MTB_JSON
|
||||||
|
}.andExpect {
|
||||||
|
status {
|
||||||
|
isAccepted()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
verify(requestProcessor, times(1)).processMtbFile(any<Mtb>())
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun bwhcMtbFileContent(consentStatus: Consent.Status) = MtbFile.builder()
|
||||||
|
.withPatient(
|
||||||
|
Patient.builder()
|
||||||
|
.withId("TEST_12345678")
|
||||||
|
.withBirthDate("2000-08-08")
|
||||||
|
.withGender(Patient.Gender.MALE)
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
.withConsent(
|
||||||
|
Consent.builder()
|
||||||
|
.withId("1")
|
||||||
|
.withStatus(consentStatus)
|
||||||
|
.withPatient("TEST_12345678")
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
.withEpisode(
|
||||||
|
Episode.builder()
|
||||||
|
.withId("1")
|
||||||
|
.withPatient("TEST_12345678")
|
||||||
|
.withPeriod(PeriodStart("2023-08-08"))
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
.build()
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of ETL-Processor
|
* This file is part of ETL-Processor
|
||||||
*
|
*
|
||||||
* Copyright (c) 2024 Comprehensive Cancer Center Mainfranken, Datenintegrationszentrum Philipps-Universität Marburg and Contributors
|
* Copyright (c) 2025 Comprehensive Cancer Center Mainfranken, Datenintegrationszentrum Philipps-Universität Marburg and Contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Affero General Public License as published
|
||||||
@ -21,20 +21,25 @@ package dev.dnpm.etl.processor.output
|
|||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper
|
import com.fasterxml.jackson.databind.ObjectMapper
|
||||||
import de.ukw.ccc.bwhc.dto.*
|
import de.ukw.ccc.bwhc.dto.*
|
||||||
|
import de.ukw.ccc.bwhc.dto.Patient
|
||||||
|
import dev.dnpm.etl.processor.CustomMediaType
|
||||||
import dev.dnpm.etl.processor.PatientPseudonym
|
import dev.dnpm.etl.processor.PatientPseudonym
|
||||||
import dev.dnpm.etl.processor.RequestId
|
import dev.dnpm.etl.processor.RequestId
|
||||||
import dev.dnpm.etl.processor.config.KafkaProperties
|
import dev.dnpm.etl.processor.config.KafkaProperties
|
||||||
import dev.dnpm.etl.processor.monitoring.RequestStatus
|
import dev.dnpm.etl.processor.monitoring.RequestStatus
|
||||||
|
import dev.pcvolkmer.mv64e.mtb.*
|
||||||
|
import org.apache.kafka.clients.producer.ProducerRecord
|
||||||
import org.assertj.core.api.Assertions.assertThat
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
import org.junit.jupiter.api.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
|
import org.junit.jupiter.api.Nested
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.jupiter.api.extension.ExtendWith
|
import org.junit.jupiter.api.extension.ExtendWith
|
||||||
import org.junit.jupiter.params.ParameterizedTest
|
import org.junit.jupiter.params.ParameterizedTest
|
||||||
import org.junit.jupiter.params.provider.MethodSource
|
import org.junit.jupiter.params.provider.MethodSource
|
||||||
import org.mockito.ArgumentMatchers.anyString
|
|
||||||
import org.mockito.Mock
|
import org.mockito.Mock
|
||||||
import org.mockito.junit.jupiter.MockitoExtension
|
import org.mockito.junit.jupiter.MockitoExtension
|
||||||
import org.mockito.kotlin.*
|
import org.mockito.kotlin.*
|
||||||
|
import org.springframework.http.MediaType
|
||||||
import org.springframework.kafka.core.KafkaTemplate
|
import org.springframework.kafka.core.KafkaTemplate
|
||||||
import org.springframework.kafka.support.SendResult
|
import org.springframework.kafka.support.SendResult
|
||||||
import org.springframework.retry.policy.SimpleRetryPolicy
|
import org.springframework.retry.policy.SimpleRetryPolicy
|
||||||
@ -45,6 +50,9 @@ import java.util.concurrent.ExecutionException
|
|||||||
@ExtendWith(MockitoExtension::class)
|
@ExtendWith(MockitoExtension::class)
|
||||||
class KafkaMtbFileSenderTest {
|
class KafkaMtbFileSenderTest {
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
inner class BwhcV1Record {
|
||||||
|
|
||||||
private lateinit var kafkaTemplate: KafkaTemplate<String, String>
|
private lateinit var kafkaTemplate: KafkaTemplate<String, String>
|
||||||
|
|
||||||
private lateinit var kafkaMtbFileSender: KafkaMtbFileSender
|
private lateinit var kafkaMtbFileSender: KafkaMtbFileSender
|
||||||
@ -65,67 +73,69 @@ class KafkaMtbFileSenderTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("requestWithResponseSource")
|
@MethodSource("dev.dnpm.etl.processor.output.KafkaMtbFileSenderTest#requestWithResponseSource")
|
||||||
fun shouldSendMtbFileRequestAndReturnExpectedState(testData: TestData) {
|
fun shouldSendMtbFileRequestAndReturnExpectedState(testData: TestData) {
|
||||||
doAnswer {
|
doAnswer {
|
||||||
if (null != testData.exception) {
|
if (null != testData.exception) {
|
||||||
throw testData.exception
|
throw testData.exception
|
||||||
}
|
}
|
||||||
completedFuture(SendResult<String, String>(null, null))
|
completedFuture(SendResult<String, String>(null, null))
|
||||||
}.whenever(kafkaTemplate).send(anyString(), anyString(), anyString())
|
}.whenever(kafkaTemplate).send(any<ProducerRecord<String, String>>())
|
||||||
|
|
||||||
val response = kafkaMtbFileSender.send(MtbFileSender.MtbFileRequest(TEST_REQUEST_ID, mtbFile(Consent.Status.ACTIVE)))
|
val response = kafkaMtbFileSender.send(BwhcV1MtbFileRequest(TEST_REQUEST_ID, bwhcV1MtbFile(Consent.Status.ACTIVE)))
|
||||||
assertThat(response.status).isEqualTo(testData.requestStatus)
|
assertThat(response.status).isEqualTo(testData.requestStatus)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("requestWithResponseSource")
|
@MethodSource("dev.dnpm.etl.processor.output.KafkaMtbFileSenderTest#requestWithResponseSource")
|
||||||
fun shouldSendDeleteRequestAndReturnExpectedState(testData: TestData) {
|
fun shouldSendDeleteRequestAndReturnExpectedState(testData: TestData) {
|
||||||
doAnswer {
|
doAnswer {
|
||||||
if (null != testData.exception) {
|
if (null != testData.exception) {
|
||||||
throw testData.exception
|
throw testData.exception
|
||||||
}
|
}
|
||||||
completedFuture(SendResult<String, String>(null, null))
|
completedFuture(SendResult<String, String>(null, null))
|
||||||
}.whenever(kafkaTemplate).send(anyString(), anyString(), anyString())
|
}.whenever(kafkaTemplate).send(any<ProducerRecord<String, String>>())
|
||||||
|
|
||||||
val response = kafkaMtbFileSender.send(MtbFileSender.DeleteRequest(TEST_REQUEST_ID, TEST_PATIENT_PSEUDONYM))
|
val response = kafkaMtbFileSender.send(DeleteRequest(TEST_REQUEST_ID, TEST_PATIENT_PSEUDONYM))
|
||||||
assertThat(response.status).isEqualTo(testData.requestStatus)
|
assertThat(response.status).isEqualTo(testData.requestStatus)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun shouldSendMtbFileRequestWithCorrectKeyAndBody() {
|
fun shouldSendMtbFileRequestWithCorrectKeyAndHeaderAndBody() {
|
||||||
doAnswer {
|
doAnswer {
|
||||||
completedFuture(SendResult<String, String>(null, null))
|
completedFuture(SendResult<String, String>(null, null))
|
||||||
}.whenever(kafkaTemplate).send(anyString(), anyString(), anyString())
|
}.whenever(kafkaTemplate).send(any<ProducerRecord<String, String>>())
|
||||||
|
|
||||||
kafkaMtbFileSender.send(MtbFileSender.MtbFileRequest(TEST_REQUEST_ID, mtbFile(Consent.Status.ACTIVE)))
|
kafkaMtbFileSender.send(BwhcV1MtbFileRequest(TEST_REQUEST_ID, bwhcV1MtbFile(Consent.Status.ACTIVE)))
|
||||||
|
|
||||||
val captor = argumentCaptor<String>()
|
val captor = argumentCaptor<ProducerRecord<String, String>>()
|
||||||
verify(kafkaTemplate, times(1)).send(anyString(), captor.capture(), captor.capture())
|
verify(kafkaTemplate, times(1)).send(captor.capture())
|
||||||
assertThat(captor.firstValue).isNotNull
|
assertThat(captor.firstValue.key()).isNotNull
|
||||||
assertThat(captor.firstValue).isEqualTo("{\"pid\": \"PID\"}")
|
assertThat(captor.firstValue.key()).isEqualTo("{\"pid\": \"PID\"}")
|
||||||
assertThat(captor.secondValue).isNotNull
|
assertThat(captor.firstValue.headers().headers("contentType")).isNotNull
|
||||||
assertThat(captor.secondValue).isEqualTo(objectMapper.writeValueAsString(kafkaRecordData(TEST_REQUEST_ID, Consent.Status.ACTIVE)))
|
assertThat(captor.firstValue.headers().headers("contentType")?.firstOrNull()?.value()).isEqualTo(MediaType.APPLICATION_JSON_VALUE.toByteArray())
|
||||||
|
assertThat(captor.firstValue.value()).isNotNull
|
||||||
|
assertThat(captor.firstValue.value()).isEqualTo(objectMapper.writeValueAsString(bwhcV1kafkaRecordData(TEST_REQUEST_ID, Consent.Status.ACTIVE)))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun shouldSendDeleteRequestWithCorrectKeyAndBody() {
|
fun shouldSendDeleteRequestWithCorrectKeyAndBody() {
|
||||||
doAnswer {
|
doAnswer {
|
||||||
completedFuture(SendResult<String, String>(null, null))
|
completedFuture(SendResult<String, String>(null, null))
|
||||||
}.whenever(kafkaTemplate).send(anyString(), anyString(), anyString())
|
}.whenever(kafkaTemplate).send(any<ProducerRecord<String, String>>())
|
||||||
|
|
||||||
kafkaMtbFileSender.send(MtbFileSender.DeleteRequest(TEST_REQUEST_ID, TEST_PATIENT_PSEUDONYM))
|
kafkaMtbFileSender.send(DeleteRequest(TEST_REQUEST_ID, TEST_PATIENT_PSEUDONYM))
|
||||||
|
|
||||||
val captor = argumentCaptor<String>()
|
val captor = argumentCaptor<ProducerRecord<String, String>>()
|
||||||
verify(kafkaTemplate, times(1)).send(anyString(), captor.capture(), captor.capture())
|
verify(kafkaTemplate, times(1)).send(captor.capture())
|
||||||
assertThat(captor.firstValue).isNotNull
|
assertThat(captor.firstValue.key()).isNotNull
|
||||||
assertThat(captor.firstValue).isEqualTo("{\"pid\": \"PID\"}")
|
assertThat(captor.firstValue.key()).isEqualTo("{\"pid\": \"PID\"}")
|
||||||
assertThat(captor.secondValue).isNotNull
|
assertThat(captor.firstValue.value()).isNotNull
|
||||||
assertThat(captor.secondValue).isEqualTo(objectMapper.writeValueAsString(kafkaRecordData(TEST_REQUEST_ID, Consent.Status.REJECTED)))
|
assertThat(captor.firstValue.value()).isEqualTo(objectMapper.writeValueAsString(bwhcV1kafkaRecordData(TEST_REQUEST_ID, Consent.Status.REJECTED)))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("requestWithResponseSource")
|
@MethodSource("dev.dnpm.etl.processor.output.KafkaMtbFileSenderTest#requestWithResponseSource")
|
||||||
fun shouldRetryOnMtbFileKafkaSendError(testData: TestData) {
|
fun shouldRetryOnMtbFileKafkaSendError(testData: TestData) {
|
||||||
val kafkaProperties = KafkaProperties("testtopic")
|
val kafkaProperties = KafkaProperties("testtopic")
|
||||||
val retryTemplate = RetryTemplateBuilder().customPolicy(SimpleRetryPolicy(3)).build()
|
val retryTemplate = RetryTemplateBuilder().customPolicy(SimpleRetryPolicy(3)).build()
|
||||||
@ -136,9 +146,9 @@ class KafkaMtbFileSenderTest {
|
|||||||
throw testData.exception
|
throw testData.exception
|
||||||
}
|
}
|
||||||
completedFuture(SendResult<String, String>(null, null))
|
completedFuture(SendResult<String, String>(null, null))
|
||||||
}.whenever(kafkaTemplate).send(anyString(), anyString(), anyString())
|
}.whenever(kafkaTemplate).send(any<ProducerRecord<String, String>>())
|
||||||
|
|
||||||
kafkaMtbFileSender.send(MtbFileSender.MtbFileRequest(TEST_REQUEST_ID, mtbFile(Consent.Status.ACTIVE)))
|
kafkaMtbFileSender.send(BwhcV1MtbFileRequest(TEST_REQUEST_ID, bwhcV1MtbFile(Consent.Status.ACTIVE)))
|
||||||
|
|
||||||
val expectedCount = when (testData.exception) {
|
val expectedCount = when (testData.exception) {
|
||||||
// OK - No Retry
|
// OK - No Retry
|
||||||
@ -147,11 +157,11 @@ class KafkaMtbFileSenderTest {
|
|||||||
else -> times(3)
|
else -> times(3)
|
||||||
}
|
}
|
||||||
|
|
||||||
verify(kafkaTemplate, expectedCount).send(anyString(), anyString(), anyString())
|
verify(kafkaTemplate, expectedCount).send(any<ProducerRecord<String, String>>())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("requestWithResponseSource")
|
@MethodSource("dev.dnpm.etl.processor.output.KafkaMtbFileSenderTest#requestWithResponseSource")
|
||||||
fun shouldRetryOnDeleteKafkaSendError(testData: TestData) {
|
fun shouldRetryOnDeleteKafkaSendError(testData: TestData) {
|
||||||
val kafkaProperties = KafkaProperties("testtopic")
|
val kafkaProperties = KafkaProperties("testtopic")
|
||||||
val retryTemplate = RetryTemplateBuilder().customPolicy(SimpleRetryPolicy(3)).build()
|
val retryTemplate = RetryTemplateBuilder().customPolicy(SimpleRetryPolicy(3)).build()
|
||||||
@ -162,9 +172,9 @@ class KafkaMtbFileSenderTest {
|
|||||||
throw testData.exception
|
throw testData.exception
|
||||||
}
|
}
|
||||||
completedFuture(SendResult<String, String>(null, null))
|
completedFuture(SendResult<String, String>(null, null))
|
||||||
}.whenever(kafkaTemplate).send(anyString(), anyString(), anyString())
|
}.whenever(kafkaTemplate).send(any<ProducerRecord<String, String>>())
|
||||||
|
|
||||||
kafkaMtbFileSender.send(MtbFileSender.DeleteRequest(TEST_REQUEST_ID, TEST_PATIENT_PSEUDONYM))
|
kafkaMtbFileSender.send(DeleteRequest(TEST_REQUEST_ID, TEST_PATIENT_PSEUDONYM))
|
||||||
|
|
||||||
val expectedCount = when (testData.exception) {
|
val expectedCount = when (testData.exception) {
|
||||||
// OK - No Retry
|
// OK - No Retry
|
||||||
@ -173,14 +183,98 @@ class KafkaMtbFileSenderTest {
|
|||||||
else -> times(3)
|
else -> times(3)
|
||||||
}
|
}
|
||||||
|
|
||||||
verify(kafkaTemplate, expectedCount).send(anyString(), anyString(), anyString())
|
verify(kafkaTemplate, expectedCount).send(any<ProducerRecord<String, String>>())
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
inner class DnpmV2Record {
|
||||||
|
|
||||||
|
private lateinit var kafkaTemplate: KafkaTemplate<String, String>
|
||||||
|
|
||||||
|
private lateinit var kafkaMtbFileSender: KafkaMtbFileSender
|
||||||
|
|
||||||
|
private lateinit var objectMapper: ObjectMapper
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
fun setup(
|
||||||
|
@Mock kafkaTemplate: KafkaTemplate<String, String>
|
||||||
|
) {
|
||||||
|
val kafkaProperties = KafkaProperties("testtopic")
|
||||||
|
val retryTemplate = RetryTemplateBuilder().customPolicy(SimpleRetryPolicy(1)).build()
|
||||||
|
|
||||||
|
this.objectMapper = ObjectMapper()
|
||||||
|
this.kafkaTemplate = kafkaTemplate
|
||||||
|
|
||||||
|
this.kafkaMtbFileSender = KafkaMtbFileSender(kafkaTemplate, kafkaProperties, retryTemplate, objectMapper)
|
||||||
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@MethodSource("dev.dnpm.etl.processor.output.KafkaMtbFileSenderTest#requestWithResponseSource")
|
||||||
|
fun shouldSendMtbFileRequestAndReturnExpectedState(testData: TestData) {
|
||||||
|
doAnswer {
|
||||||
|
if (null != testData.exception) {
|
||||||
|
throw testData.exception
|
||||||
|
}
|
||||||
|
completedFuture(SendResult<String, String>(null, null))
|
||||||
|
}.whenever(kafkaTemplate).send(any<ProducerRecord<String, String>>())
|
||||||
|
|
||||||
|
val response = kafkaMtbFileSender.send(DnpmV2MtbFileRequest(TEST_REQUEST_ID, dnpmV2MtbFile()))
|
||||||
|
assertThat(response.status).isEqualTo(testData.requestStatus)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun shouldSendMtbFileRequestWithCorrectKeyAndHeaderAndBody() {
|
||||||
|
doAnswer {
|
||||||
|
completedFuture(SendResult<String, String>(null, null))
|
||||||
|
}.whenever(kafkaTemplate).send(any<ProducerRecord<String, String>>())
|
||||||
|
|
||||||
|
kafkaMtbFileSender.send(DnpmV2MtbFileRequest(TEST_REQUEST_ID, dnpmV2MtbFile()))
|
||||||
|
|
||||||
|
val captor = argumentCaptor<ProducerRecord<String, String>>()
|
||||||
|
verify(kafkaTemplate, times(1)).send(captor.capture())
|
||||||
|
assertThat(captor.firstValue.key()).isNotNull
|
||||||
|
assertThat(captor.firstValue.key()).isEqualTo("{\"pid\": \"PID\"}")
|
||||||
|
assertThat(captor.firstValue.headers().headers("contentType")).isNotNull
|
||||||
|
assertThat(captor.firstValue.headers().headers("contentType")?.firstOrNull()?.value()).isEqualTo(CustomMediaType.APPLICATION_VND_DNPM_V2_MTB_JSON_VALUE.toByteArray())
|
||||||
|
assertThat(captor.firstValue.value()).isNotNull
|
||||||
|
assertThat(captor.firstValue.value()).isEqualTo(objectMapper.writeValueAsString(dnmpV2kafkaRecordData(TEST_REQUEST_ID)))
|
||||||
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@MethodSource("dev.dnpm.etl.processor.output.KafkaMtbFileSenderTest#requestWithResponseSource")
|
||||||
|
fun shouldRetryOnMtbFileKafkaSendError(testData: TestData) {
|
||||||
|
val kafkaProperties = KafkaProperties("testtopic")
|
||||||
|
val retryTemplate = RetryTemplateBuilder().customPolicy(SimpleRetryPolicy(3)).build()
|
||||||
|
this.kafkaMtbFileSender = KafkaMtbFileSender(this.kafkaTemplate, kafkaProperties, retryTemplate, this.objectMapper)
|
||||||
|
|
||||||
|
doAnswer {
|
||||||
|
if (null != testData.exception) {
|
||||||
|
throw testData.exception
|
||||||
|
}
|
||||||
|
completedFuture(SendResult<String, String>(null, null))
|
||||||
|
}.whenever(kafkaTemplate).send(any<ProducerRecord<String, String>>())
|
||||||
|
|
||||||
|
kafkaMtbFileSender.send(DnpmV2MtbFileRequest(TEST_REQUEST_ID, dnpmV2MtbFile()))
|
||||||
|
|
||||||
|
val expectedCount = when (testData.exception) {
|
||||||
|
// OK - No Retry
|
||||||
|
null -> times(1)
|
||||||
|
// Request failed - Retry max 3 times
|
||||||
|
else -> times(3)
|
||||||
|
}
|
||||||
|
|
||||||
|
verify(kafkaTemplate, expectedCount).send(any<ProducerRecord<String, String>>())
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val TEST_REQUEST_ID = RequestId("TestId")
|
val TEST_REQUEST_ID = RequestId("TestId")
|
||||||
val TEST_PATIENT_PSEUDONYM = PatientPseudonym("PID")
|
val TEST_PATIENT_PSEUDONYM = PatientPseudonym("PID")
|
||||||
|
|
||||||
fun mtbFile(consentStatus: Consent.Status): MtbFile {
|
fun bwhcV1MtbFile(consentStatus: Consent.Status): MtbFile {
|
||||||
return if (consentStatus == Consent.Status.ACTIVE) {
|
return if (consentStatus == Consent.Status.ACTIVE) {
|
||||||
MtbFile.builder()
|
MtbFile.builder()
|
||||||
.withPatient(
|
.withPatient(
|
||||||
@ -215,8 +309,31 @@ class KafkaMtbFileSenderTest {
|
|||||||
}.build()
|
}.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun kafkaRecordData(requestId: RequestId, consentStatus: Consent.Status): KafkaMtbFileSender.Data {
|
fun dnpmV2MtbFile(): Mtb = Mtb.builder()
|
||||||
return KafkaMtbFileSender.Data(requestId, mtbFile(consentStatus))
|
.withPatient(
|
||||||
|
dev.pcvolkmer.mv64e.mtb.Patient.builder()
|
||||||
|
.withId("PID")
|
||||||
|
.withBirthDate("2000-08-08")
|
||||||
|
.withGender(CodingGender.builder().withCode(CodingGender.Code.MALE).build())
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
.withEpisodesOfCare(
|
||||||
|
listOf(
|
||||||
|
MTBEpisodeOfCare.builder()
|
||||||
|
.withId("1")
|
||||||
|
.withPatient(Reference("PID"))
|
||||||
|
.withPeriod(PeriodDate.builder().withStart("2023-08-08").build())
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.build()
|
||||||
|
|
||||||
|
fun bwhcV1kafkaRecordData(requestId: RequestId, consentStatus: Consent.Status): MtbRequest {
|
||||||
|
return BwhcV1MtbFileRequest(requestId, bwhcV1MtbFile(consentStatus))
|
||||||
|
}
|
||||||
|
|
||||||
|
fun dnmpV2kafkaRecordData(requestId: RequestId): MtbRequest {
|
||||||
|
return DnpmV2MtbFileRequest(requestId, dnpmV2MtbFile())
|
||||||
}
|
}
|
||||||
|
|
||||||
data class TestData(val requestStatus: RequestStatus, val exception: Throwable? = null)
|
data class TestData(val requestStatus: RequestStatus, val exception: Throwable? = null)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of ETL-Processor
|
* This file is part of ETL-Processor
|
||||||
*
|
*
|
||||||
* Copyright (c) 2024 Comprehensive Cancer Center Mainfranken, Datenintegrationszentrum Philipps-Universität Marburg and Contributors
|
* Copyright (c) 2025 Comprehensive Cancer Center Mainfranken, Datenintegrationszentrum Philipps-Universität Marburg and Contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Affero General Public License as published
|
||||||
@ -19,54 +19,61 @@
|
|||||||
|
|
||||||
package dev.dnpm.etl.processor.output
|
package dev.dnpm.etl.processor.output
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper
|
||||||
|
import com.fasterxml.jackson.module.kotlin.KotlinModule
|
||||||
import de.ukw.ccc.bwhc.dto.*
|
import de.ukw.ccc.bwhc.dto.*
|
||||||
import dev.dnpm.etl.processor.PatientPseudonym
|
import dev.dnpm.etl.processor.PatientPseudonym
|
||||||
import dev.dnpm.etl.processor.RequestId
|
import dev.dnpm.etl.processor.RequestId
|
||||||
import dev.dnpm.etl.processor.config.RestTargetProperties
|
import dev.dnpm.etl.processor.config.RestTargetProperties
|
||||||
|
import dev.dnpm.etl.processor.monitoring.ReportService
|
||||||
import dev.dnpm.etl.processor.monitoring.RequestStatus
|
import dev.dnpm.etl.processor.monitoring.RequestStatus
|
||||||
import org.assertj.core.api.Assertions.assertThat
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
import org.junit.jupiter.api.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
import org.junit.jupiter.params.ParameterizedTest
|
import org.junit.jupiter.params.ParameterizedTest
|
||||||
import org.junit.jupiter.params.provider.MethodSource
|
import org.junit.jupiter.params.provider.MethodSource
|
||||||
|
import org.springframework.http.HttpHeaders
|
||||||
import org.springframework.http.HttpMethod
|
import org.springframework.http.HttpMethod
|
||||||
import org.springframework.http.HttpStatus
|
import org.springframework.http.HttpStatus
|
||||||
|
import org.springframework.http.MediaType
|
||||||
import org.springframework.retry.policy.SimpleRetryPolicy
|
import org.springframework.retry.policy.SimpleRetryPolicy
|
||||||
import org.springframework.retry.support.RetryTemplateBuilder
|
import org.springframework.retry.support.RetryTemplateBuilder
|
||||||
import org.springframework.test.web.client.ExpectedCount
|
import org.springframework.test.web.client.ExpectedCount
|
||||||
import org.springframework.test.web.client.MockRestServiceServer
|
import org.springframework.test.web.client.MockRestServiceServer
|
||||||
import org.springframework.test.web.client.match.MockRestRequestMatchers.method
|
import org.springframework.test.web.client.match.MockRestRequestMatchers.*
|
||||||
import org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo
|
|
||||||
import org.springframework.test.web.client.response.MockRestResponseCreators.withStatus
|
import org.springframework.test.web.client.response.MockRestResponseCreators.withStatus
|
||||||
import org.springframework.web.client.RestTemplate
|
import org.springframework.web.client.RestTemplate
|
||||||
|
|
||||||
class RestMtbFileSenderTest {
|
class RestBwhcMtbFileSenderTest {
|
||||||
|
|
||||||
private lateinit var mockRestServiceServer: MockRestServiceServer
|
private lateinit var mockRestServiceServer: MockRestServiceServer
|
||||||
|
|
||||||
private lateinit var restMtbFileSender: RestMtbFileSender
|
private lateinit var restMtbFileSender: RestMtbFileSender
|
||||||
|
|
||||||
|
private var reportService = ReportService(ObjectMapper().registerModule(KotlinModule.Builder().build()))
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
fun setup() {
|
fun setup() {
|
||||||
val restTemplate = RestTemplate()
|
val restTemplate = RestTemplate()
|
||||||
val restTargetProperties = RestTargetProperties("http://localhost:9000/mtbfile")
|
val restTargetProperties = RestTargetProperties("http://localhost:9000/mtbfile", null, null)
|
||||||
val retryTemplate = RetryTemplateBuilder().customPolicy(SimpleRetryPolicy(1)).build()
|
val retryTemplate = RetryTemplateBuilder().customPolicy(SimpleRetryPolicy(1)).build()
|
||||||
|
|
||||||
this.mockRestServiceServer = MockRestServiceServer.createServer(restTemplate)
|
this.mockRestServiceServer = MockRestServiceServer.createServer(restTemplate)
|
||||||
|
|
||||||
this.restMtbFileSender = RestMtbFileSender(restTemplate, restTargetProperties, retryTemplate)
|
this.restMtbFileSender =
|
||||||
|
RestBwhcMtbFileSender(restTemplate, restTargetProperties, retryTemplate, reportService)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("deleteRequestWithResponseSource")
|
@MethodSource("deleteRequestWithResponseSource")
|
||||||
fun shouldReturnExpectedResponseForDelete(requestWithResponse: RequestWithResponse) {
|
fun shouldReturnExpectedResponseForDelete(requestWithResponse: RequestWithResponse) {
|
||||||
this.mockRestServiceServer.expect {
|
this.mockRestServiceServer
|
||||||
method(HttpMethod.DELETE)
|
.expect(method(HttpMethod.DELETE))
|
||||||
requestTo("/mtbfile")
|
.andExpect(requestTo("http://localhost:9000/mtbfile/Patient/${TEST_PATIENT_PSEUDONYM.value}"))
|
||||||
}.andRespond {
|
.andRespond {
|
||||||
withStatus(requestWithResponse.httpStatus).body(requestWithResponse.body).createResponse(it)
|
withStatus(requestWithResponse.httpStatus).body(requestWithResponse.body).createResponse(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
val response = restMtbFileSender.send(MtbFileSender.DeleteRequest(TEST_REQUEST_ID, TEST_PATIENT_PSEUDONYM))
|
val response = restMtbFileSender.send(DeleteRequest(TEST_REQUEST_ID, TEST_PATIENT_PSEUDONYM))
|
||||||
assertThat(response.status).isEqualTo(requestWithResponse.response.status)
|
assertThat(response.status).isEqualTo(requestWithResponse.response.status)
|
||||||
assertThat(response.body).isEqualTo(requestWithResponse.response.body)
|
assertThat(response.body).isEqualTo(requestWithResponse.response.body)
|
||||||
}
|
}
|
||||||
@ -74,14 +81,15 @@ class RestMtbFileSenderTest {
|
|||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("mtbFileRequestWithResponseSource")
|
@MethodSource("mtbFileRequestWithResponseSource")
|
||||||
fun shouldReturnExpectedResponseForMtbFilePost(requestWithResponse: RequestWithResponse) {
|
fun shouldReturnExpectedResponseForMtbFilePost(requestWithResponse: RequestWithResponse) {
|
||||||
this.mockRestServiceServer.expect {
|
this.mockRestServiceServer
|
||||||
method(HttpMethod.POST)
|
.expect(method(HttpMethod.POST))
|
||||||
requestTo("/mtbfile")
|
.andExpect(requestTo("http://localhost:9000/mtbfile/MTBFile"))
|
||||||
}.andRespond {
|
.andExpect(header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE))
|
||||||
|
.andRespond {
|
||||||
withStatus(requestWithResponse.httpStatus).body(requestWithResponse.body).createResponse(it)
|
withStatus(requestWithResponse.httpStatus).body(requestWithResponse.body).createResponse(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
val response = restMtbFileSender.send(MtbFileSender.MtbFileRequest(TEST_REQUEST_ID, mtbFile))
|
val response = restMtbFileSender.send(BwhcV1MtbFileRequest(TEST_REQUEST_ID, mtbFile))
|
||||||
assertThat(response.status).isEqualTo(requestWithResponse.response.status)
|
assertThat(response.status).isEqualTo(requestWithResponse.response.status)
|
||||||
assertThat(response.body).isEqualTo(requestWithResponse.response.body)
|
assertThat(response.body).isEqualTo(requestWithResponse.response.body)
|
||||||
}
|
}
|
||||||
@ -90,11 +98,12 @@ class RestMtbFileSenderTest {
|
|||||||
@MethodSource("mtbFileRequestWithResponseSource")
|
@MethodSource("mtbFileRequestWithResponseSource")
|
||||||
fun shouldRetryOnMtbFileHttpRequestError(requestWithResponse: RequestWithResponse) {
|
fun shouldRetryOnMtbFileHttpRequestError(requestWithResponse: RequestWithResponse) {
|
||||||
val restTemplate = RestTemplate()
|
val restTemplate = RestTemplate()
|
||||||
val restTargetProperties = RestTargetProperties("http://localhost:9000/mtbfile")
|
val restTargetProperties = RestTargetProperties("http://localhost:9000/mtbfile", null, null)
|
||||||
val retryTemplate = RetryTemplateBuilder().customPolicy(SimpleRetryPolicy(3)).build()
|
val retryTemplate = RetryTemplateBuilder().customPolicy(SimpleRetryPolicy(3)).build()
|
||||||
|
|
||||||
this.mockRestServiceServer = MockRestServiceServer.createServer(restTemplate)
|
this.mockRestServiceServer = MockRestServiceServer.createServer(restTemplate)
|
||||||
this.restMtbFileSender = RestMtbFileSender(restTemplate, restTargetProperties, retryTemplate)
|
this.restMtbFileSender =
|
||||||
|
RestBwhcMtbFileSender(restTemplate, restTargetProperties, retryTemplate, reportService)
|
||||||
|
|
||||||
val expectedCount = when (requestWithResponse.httpStatus) {
|
val expectedCount = when (requestWithResponse.httpStatus) {
|
||||||
// OK - No Retry
|
// OK - No Retry
|
||||||
@ -103,14 +112,14 @@ class RestMtbFileSenderTest {
|
|||||||
else -> ExpectedCount.max(3)
|
else -> ExpectedCount.max(3)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.mockRestServiceServer.expect(expectedCount) {
|
this.mockRestServiceServer
|
||||||
method(HttpMethod.POST)
|
.expect(expectedCount, method(HttpMethod.POST))
|
||||||
requestTo("/mtbfile")
|
.andExpect(requestTo("http://localhost:9000/mtbfile/MTBFile"))
|
||||||
}.andRespond {
|
.andRespond {
|
||||||
withStatus(requestWithResponse.httpStatus).body(requestWithResponse.body).createResponse(it)
|
withStatus(requestWithResponse.httpStatus).body(requestWithResponse.body).createResponse(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
val response = restMtbFileSender.send(MtbFileSender.MtbFileRequest(TEST_REQUEST_ID, mtbFile))
|
val response = restMtbFileSender.send(BwhcV1MtbFileRequest(TEST_REQUEST_ID, mtbFile))
|
||||||
assertThat(response.status).isEqualTo(requestWithResponse.response.status)
|
assertThat(response.status).isEqualTo(requestWithResponse.response.status)
|
||||||
assertThat(response.body).isEqualTo(requestWithResponse.response.body)
|
assertThat(response.body).isEqualTo(requestWithResponse.response.body)
|
||||||
}
|
}
|
||||||
@ -119,11 +128,12 @@ class RestMtbFileSenderTest {
|
|||||||
@MethodSource("deleteRequestWithResponseSource")
|
@MethodSource("deleteRequestWithResponseSource")
|
||||||
fun shouldRetryOnDeleteHttpRequestError(requestWithResponse: RequestWithResponse) {
|
fun shouldRetryOnDeleteHttpRequestError(requestWithResponse: RequestWithResponse) {
|
||||||
val restTemplate = RestTemplate()
|
val restTemplate = RestTemplate()
|
||||||
val restTargetProperties = RestTargetProperties("http://localhost:9000/mtbfile")
|
val restTargetProperties = RestTargetProperties("http://localhost:9000/mtbfile", null, null)
|
||||||
val retryTemplate = RetryTemplateBuilder().customPolicy(SimpleRetryPolicy(3)).build()
|
val retryTemplate = RetryTemplateBuilder().customPolicy(SimpleRetryPolicy(3)).build()
|
||||||
|
|
||||||
this.mockRestServiceServer = MockRestServiceServer.createServer(restTemplate)
|
this.mockRestServiceServer = MockRestServiceServer.createServer(restTemplate)
|
||||||
this.restMtbFileSender = RestMtbFileSender(restTemplate, restTargetProperties, retryTemplate)
|
this.restMtbFileSender =
|
||||||
|
RestBwhcMtbFileSender(restTemplate, restTargetProperties, retryTemplate, reportService)
|
||||||
|
|
||||||
val expectedCount = when (requestWithResponse.httpStatus) {
|
val expectedCount = when (requestWithResponse.httpStatus) {
|
||||||
// OK - No Retry
|
// OK - No Retry
|
||||||
@ -132,14 +142,14 @@ class RestMtbFileSenderTest {
|
|||||||
else -> ExpectedCount.max(3)
|
else -> ExpectedCount.max(3)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.mockRestServiceServer.expect(expectedCount) {
|
this.mockRestServiceServer
|
||||||
method(HttpMethod.DELETE)
|
.expect(expectedCount, method(HttpMethod.DELETE))
|
||||||
requestTo("/mtbfile")
|
.andExpect(requestTo("http://localhost:9000/mtbfile/Patient/${TEST_PATIENT_PSEUDONYM.value}"))
|
||||||
}.andRespond {
|
.andRespond {
|
||||||
withStatus(requestWithResponse.httpStatus).body(requestWithResponse.body).createResponse(it)
|
withStatus(requestWithResponse.httpStatus).body(requestWithResponse.body).createResponse(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
val response = restMtbFileSender.send(MtbFileSender.DeleteRequest(TEST_REQUEST_ID, TEST_PATIENT_PSEUDONYM))
|
val response = restMtbFileSender.send(DeleteRequest(TEST_REQUEST_ID, TEST_PATIENT_PSEUDONYM))
|
||||||
assertThat(response.status).isEqualTo(requestWithResponse.response.status)
|
assertThat(response.status).isEqualTo(requestWithResponse.response.status)
|
||||||
assertThat(response.body).isEqualTo(requestWithResponse.response.body)
|
assertThat(response.body).isEqualTo(requestWithResponse.response.body)
|
||||||
}
|
}
|
||||||
@ -154,24 +164,6 @@ class RestMtbFileSenderTest {
|
|||||||
val TEST_REQUEST_ID = RequestId("TestId")
|
val TEST_REQUEST_ID = RequestId("TestId")
|
||||||
val TEST_PATIENT_PSEUDONYM = PatientPseudonym("PID")
|
val TEST_PATIENT_PSEUDONYM = PatientPseudonym("PID")
|
||||||
|
|
||||||
private val warningBody = """
|
|
||||||
{
|
|
||||||
"patient_id": "PID",
|
|
||||||
"issues": [
|
|
||||||
{ "severity": "warning", "message": "Something is not right" }
|
|
||||||
]
|
|
||||||
}
|
|
||||||
""".trimIndent()
|
|
||||||
|
|
||||||
private val errorBody = """
|
|
||||||
{
|
|
||||||
"patient_id": "PID",
|
|
||||||
"issues": [
|
|
||||||
{ "severity": "error", "message": "Something is very bad" }
|
|
||||||
]
|
|
||||||
}
|
|
||||||
""".trimIndent()
|
|
||||||
|
|
||||||
val mtbFile: MtbFile = MtbFile.builder()
|
val mtbFile: MtbFile = MtbFile.builder()
|
||||||
.withPatient(
|
.withPatient(
|
||||||
Patient.builder()
|
Patient.builder()
|
||||||
@ -205,31 +197,44 @@ class RestMtbFileSenderTest {
|
|||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun mtbFileRequestWithResponseSource(): Set<RequestWithResponse> {
|
fun mtbFileRequestWithResponseSource(): Set<RequestWithResponse> {
|
||||||
return setOf(
|
return setOf(
|
||||||
RequestWithResponse(HttpStatus.OK, "{}", MtbFileSender.Response(RequestStatus.SUCCESS, "{}")),
|
RequestWithResponse(
|
||||||
|
HttpStatus.OK,
|
||||||
|
responseBodyWithMaxSeverity(ReportService.Severity.INFO),
|
||||||
|
MtbFileSender.Response(
|
||||||
|
RequestStatus.SUCCESS,
|
||||||
|
responseBodyWithMaxSeverity(ReportService.Severity.INFO)
|
||||||
|
)
|
||||||
|
),
|
||||||
RequestWithResponse(
|
RequestWithResponse(
|
||||||
HttpStatus.CREATED,
|
HttpStatus.CREATED,
|
||||||
warningBody,
|
responseBodyWithMaxSeverity(ReportService.Severity.WARNING),
|
||||||
MtbFileSender.Response(RequestStatus.WARNING, warningBody)
|
MtbFileSender.Response(
|
||||||
|
RequestStatus.WARNING,
|
||||||
|
responseBodyWithMaxSeverity(ReportService.Severity.WARNING)
|
||||||
|
)
|
||||||
),
|
),
|
||||||
RequestWithResponse(
|
RequestWithResponse(
|
||||||
HttpStatus.BAD_REQUEST,
|
HttpStatus.BAD_REQUEST,
|
||||||
"??",
|
responseBodyWithMaxSeverity(ReportService.Severity.ERROR),
|
||||||
MtbFileSender.Response(RequestStatus.ERROR, ERROR_RESPONSE_BODY)
|
MtbFileSender.Response(RequestStatus.ERROR, responseBodyWithMaxSeverity(ReportService.Severity.ERROR))
|
||||||
),
|
),
|
||||||
RequestWithResponse(
|
RequestWithResponse(
|
||||||
HttpStatus.UNPROCESSABLE_ENTITY,
|
HttpStatus.UNPROCESSABLE_ENTITY,
|
||||||
errorBody,
|
responseBodyWithMaxSeverity(ReportService.Severity.FATAL),
|
||||||
MtbFileSender.Response(RequestStatus.ERROR, ERROR_RESPONSE_BODY)
|
MtbFileSender.Response(
|
||||||
|
RequestStatus.ERROR,
|
||||||
|
responseBodyWithMaxSeverity(ReportService.Severity.FATAL)
|
||||||
|
)
|
||||||
),
|
),
|
||||||
// Some more errors not mentioned in documentation
|
// Some more errors not mentioned in documentation
|
||||||
RequestWithResponse(
|
RequestWithResponse(
|
||||||
HttpStatus.NOT_FOUND,
|
HttpStatus.NOT_FOUND,
|
||||||
"what????",
|
ERROR_RESPONSE_BODY,
|
||||||
MtbFileSender.Response(RequestStatus.ERROR, ERROR_RESPONSE_BODY)
|
MtbFileSender.Response(RequestStatus.ERROR, ERROR_RESPONSE_BODY)
|
||||||
),
|
),
|
||||||
RequestWithResponse(
|
RequestWithResponse(
|
||||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||||
"what????",
|
ERROR_RESPONSE_BODY,
|
||||||
MtbFileSender.Response(RequestStatus.ERROR, ERROR_RESPONSE_BODY)
|
MtbFileSender.Response(RequestStatus.ERROR, ERROR_RESPONSE_BODY)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -256,6 +261,52 @@ class RestMtbFileSenderTest {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun responseBodyWithMaxSeverity(severity: ReportService.Severity): String {
|
||||||
|
return when (severity) {
|
||||||
|
ReportService.Severity.INFO -> """
|
||||||
|
{
|
||||||
|
"patient": "PID",
|
||||||
|
"issues": [
|
||||||
|
{ "severity": "info", "message": "Info Message" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
ReportService.Severity.WARNING -> """
|
||||||
|
{
|
||||||
|
"patient": "PID",
|
||||||
|
"issues": [
|
||||||
|
{ "severity": "info", "message": "Info Message" },
|
||||||
|
{ "severity": "warning", "message": "Warning Message" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
ReportService.Severity.ERROR -> """
|
||||||
|
{
|
||||||
|
"patient": "PID",
|
||||||
|
"issues": [
|
||||||
|
{ "severity": "info", "message": "Info Message" },
|
||||||
|
{ "severity": "warning", "message": "Warning Message" },
|
||||||
|
{ "severity": "error", "message": "Error Message" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
ReportService.Severity.FATAL -> """
|
||||||
|
{
|
||||||
|
"patient": "PID",
|
||||||
|
"issues": [
|
||||||
|
{ "severity": "info", "message": "Info Message" },
|
||||||
|
{ "severity": "warning", "message": "Warning Message" },
|
||||||
|
{ "severity": "error", "message": "Error Message" },
|
||||||
|
{ "severity": "fatal", "message": "Fatal Message" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,405 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ETL-Processor
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025 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.output
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper
|
||||||
|
import com.fasterxml.jackson.module.kotlin.KotlinModule
|
||||||
|
import de.ukw.ccc.bwhc.dto.*
|
||||||
|
import de.ukw.ccc.bwhc.dto.Patient
|
||||||
|
import dev.dnpm.etl.processor.CustomMediaType
|
||||||
|
import dev.dnpm.etl.processor.PatientPseudonym
|
||||||
|
import dev.dnpm.etl.processor.RequestId
|
||||||
|
import dev.dnpm.etl.processor.config.AppConfigProperties
|
||||||
|
import dev.dnpm.etl.processor.config.AppConfiguration
|
||||||
|
import dev.dnpm.etl.processor.config.RestTargetProperties
|
||||||
|
import dev.dnpm.etl.processor.monitoring.ReportService
|
||||||
|
import dev.dnpm.etl.processor.monitoring.RequestStatus
|
||||||
|
import dev.pcvolkmer.mv64e.mtb.*
|
||||||
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
|
import org.junit.jupiter.api.BeforeEach
|
||||||
|
import org.junit.jupiter.api.Nested
|
||||||
|
import org.junit.jupiter.params.ParameterizedTest
|
||||||
|
import org.junit.jupiter.params.provider.MethodSource
|
||||||
|
import org.springframework.http.HttpHeaders
|
||||||
|
import org.springframework.http.HttpMethod
|
||||||
|
import org.springframework.http.HttpStatus
|
||||||
|
import org.springframework.http.MediaType
|
||||||
|
import org.springframework.retry.backoff.NoBackOffPolicy
|
||||||
|
import org.springframework.retry.policy.SimpleRetryPolicy
|
||||||
|
import org.springframework.retry.support.RetryTemplateBuilder
|
||||||
|
import org.springframework.test.web.client.ExpectedCount
|
||||||
|
import org.springframework.test.web.client.MockRestServiceServer
|
||||||
|
import org.springframework.test.web.client.match.MockRestRequestMatchers.*
|
||||||
|
import org.springframework.test.web.client.response.MockRestResponseCreators.withStatus
|
||||||
|
import org.springframework.web.client.RestTemplate
|
||||||
|
|
||||||
|
class RestDipMtbFileSenderTest {
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
inner class BwhcV1ContentRequest {
|
||||||
|
|
||||||
|
private lateinit var mockRestServiceServer: MockRestServiceServer
|
||||||
|
|
||||||
|
private lateinit var restMtbFileSender: RestMtbFileSender
|
||||||
|
|
||||||
|
private var reportService = ReportService(ObjectMapper().registerModule(KotlinModule.Builder().build()))
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
fun setup() {
|
||||||
|
val restTemplate = RestTemplate()
|
||||||
|
val restTargetProperties = RestTargetProperties("http://localhost:9000/api", null, null, false)
|
||||||
|
val retryTemplate = RetryTemplateBuilder().customPolicy(SimpleRetryPolicy(1)).build()
|
||||||
|
|
||||||
|
this.mockRestServiceServer = MockRestServiceServer.createServer(restTemplate)
|
||||||
|
|
||||||
|
this.restMtbFileSender =
|
||||||
|
RestDipMtbFileSender(restTemplate, restTargetProperties, retryTemplate, reportService)
|
||||||
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@MethodSource("dev.dnpm.etl.processor.output.RestDipMtbFileSenderTest#mtbFileRequestWithResponseSource")
|
||||||
|
fun shouldReturnExpectedResponseForMtbFilePost(requestWithResponse: RequestWithResponse) {
|
||||||
|
this.mockRestServiceServer
|
||||||
|
.expect(method(HttpMethod.POST))
|
||||||
|
.andExpect(requestTo("http://localhost:9000/api/mtb/etl/patient-record"))
|
||||||
|
.andExpect(header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE))
|
||||||
|
.andRespond {
|
||||||
|
withStatus(requestWithResponse.httpStatus).body(requestWithResponse.body).createResponse(it)
|
||||||
|
}
|
||||||
|
|
||||||
|
val response = restMtbFileSender.send(BwhcV1MtbFileRequest(TEST_REQUEST_ID, bwhcV1mtbFile))
|
||||||
|
assertThat(response.status).isEqualTo(requestWithResponse.response.status)
|
||||||
|
assertThat(response.body).isEqualTo(requestWithResponse.response.body)
|
||||||
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@MethodSource("dev.dnpm.etl.processor.output.RestDipMtbFileSenderTest#mtbFileRequestWithResponseSource")
|
||||||
|
fun shouldRetryOnMtbFileHttpRequestError(requestWithResponse: RequestWithResponse) {
|
||||||
|
val restTemplate = RestTemplate()
|
||||||
|
val restTargetProperties = RestTargetProperties("http://localhost:9000/api", null, null, false)
|
||||||
|
val retryTemplate = AppConfiguration().retryTemplate(AppConfigProperties("http://localhost:9000"))
|
||||||
|
retryTemplate.setBackOffPolicy(NoBackOffPolicy())
|
||||||
|
|
||||||
|
this.mockRestServiceServer = MockRestServiceServer.createServer(restTemplate)
|
||||||
|
this.restMtbFileSender =
|
||||||
|
RestDipMtbFileSender(restTemplate, restTargetProperties, retryTemplate, reportService)
|
||||||
|
|
||||||
|
val expectedCount = when (requestWithResponse.httpStatus) {
|
||||||
|
// OK - No Retry
|
||||||
|
HttpStatus.OK, HttpStatus.CREATED, HttpStatus.UNPROCESSABLE_ENTITY, HttpStatus.BAD_REQUEST -> ExpectedCount.max(
|
||||||
|
1
|
||||||
|
)
|
||||||
|
// Request failed - Retry max 3 times
|
||||||
|
else -> ExpectedCount.max(3)
|
||||||
|
}
|
||||||
|
|
||||||
|
this.mockRestServiceServer
|
||||||
|
.expect(expectedCount, method(HttpMethod.POST))
|
||||||
|
.andExpect(requestTo("http://localhost:9000/api/mtb/etl/patient-record"))
|
||||||
|
.andRespond {
|
||||||
|
withStatus(requestWithResponse.httpStatus).body(requestWithResponse.body).createResponse(it)
|
||||||
|
}
|
||||||
|
|
||||||
|
val response = restMtbFileSender.send(BwhcV1MtbFileRequest(TEST_REQUEST_ID, bwhcV1mtbFile))
|
||||||
|
assertThat(response.status).isEqualTo(requestWithResponse.response.status)
|
||||||
|
assertThat(response.body).isEqualTo(requestWithResponse.response.body)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
inner class DnpmV2ContentRequest {
|
||||||
|
|
||||||
|
private lateinit var mockRestServiceServer: MockRestServiceServer
|
||||||
|
|
||||||
|
private lateinit var restMtbFileSender: RestMtbFileSender
|
||||||
|
|
||||||
|
private var reportService = ReportService(ObjectMapper().registerModule(KotlinModule.Builder().build()))
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
fun setup() {
|
||||||
|
val restTemplate = RestTemplate()
|
||||||
|
val restTargetProperties = RestTargetProperties("http://localhost:9000/api", null, null, false)
|
||||||
|
val retryTemplate = RetryTemplateBuilder().customPolicy(SimpleRetryPolicy(1)).build()
|
||||||
|
|
||||||
|
this.mockRestServiceServer = MockRestServiceServer.createServer(restTemplate)
|
||||||
|
|
||||||
|
this.restMtbFileSender = RestDipMtbFileSender(restTemplate, restTargetProperties, retryTemplate, reportService)
|
||||||
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@MethodSource("dev.dnpm.etl.processor.output.RestDipMtbFileSenderTest#mtbFileRequestWithResponseSource")
|
||||||
|
fun shouldReturnExpectedResponseForDnpmV2MtbFilePost(requestWithResponse: RequestWithResponse) {
|
||||||
|
this.mockRestServiceServer
|
||||||
|
.expect(method(HttpMethod.POST))
|
||||||
|
.andExpect(requestTo("http://localhost:9000/api/mtb/etl/patient-record"))
|
||||||
|
.andExpect(header(HttpHeaders.CONTENT_TYPE, CustomMediaType.APPLICATION_VND_DNPM_V2_MTB_JSON_VALUE))
|
||||||
|
.andRespond {
|
||||||
|
withStatus(requestWithResponse.httpStatus).body(requestWithResponse.body).createResponse(it)
|
||||||
|
}
|
||||||
|
|
||||||
|
val response = restMtbFileSender.send(DnpmV2MtbFileRequest(TEST_REQUEST_ID, dnpmV2MtbFile))
|
||||||
|
assertThat(response.status).isEqualTo(requestWithResponse.response.status)
|
||||||
|
assertThat(response.body).isEqualTo(requestWithResponse.response.body)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
inner class DeleteRequest {
|
||||||
|
|
||||||
|
private lateinit var mockRestServiceServer: MockRestServiceServer
|
||||||
|
|
||||||
|
private lateinit var restMtbFileSender: RestMtbFileSender
|
||||||
|
|
||||||
|
private var reportService = ReportService(ObjectMapper().registerModule(KotlinModule.Builder().build()))
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
fun setup() {
|
||||||
|
val restTemplate = RestTemplate()
|
||||||
|
val restTargetProperties = RestTargetProperties("http://localhost:9000/api", null, null, false)
|
||||||
|
val retryTemplate = RetryTemplateBuilder().customPolicy(SimpleRetryPolicy(1)).build()
|
||||||
|
|
||||||
|
this.mockRestServiceServer = MockRestServiceServer.createServer(restTemplate)
|
||||||
|
|
||||||
|
this.restMtbFileSender =
|
||||||
|
RestDipMtbFileSender(restTemplate, restTargetProperties, retryTemplate, reportService)
|
||||||
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@MethodSource("dev.dnpm.etl.processor.output.RestDipMtbFileSenderTest#deleteRequestWithResponseSource")
|
||||||
|
fun shouldReturnExpectedResponseForDelete(requestWithResponse: RequestWithResponse) {
|
||||||
|
this.mockRestServiceServer
|
||||||
|
.expect(method(HttpMethod.DELETE))
|
||||||
|
.andExpect(requestTo("http://localhost:9000/api/mtb/etl/patient/${TEST_PATIENT_PSEUDONYM.value}"))
|
||||||
|
.andRespond {
|
||||||
|
withStatus(requestWithResponse.httpStatus).body(requestWithResponse.body).createResponse(it)
|
||||||
|
}
|
||||||
|
|
||||||
|
val response = restMtbFileSender.send(DeleteRequest(TEST_REQUEST_ID, TEST_PATIENT_PSEUDONYM))
|
||||||
|
assertThat(response.status).isEqualTo(requestWithResponse.response.status)
|
||||||
|
assertThat(response.body).isEqualTo(requestWithResponse.response.body)
|
||||||
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@MethodSource("dev.dnpm.etl.processor.output.RestDipMtbFileSenderTest#deleteRequestWithResponseSource")
|
||||||
|
fun shouldRetryOnDeleteHttpRequestError(requestWithResponse: RequestWithResponse) {
|
||||||
|
val restTemplate = RestTemplate()
|
||||||
|
val restTargetProperties = RestTargetProperties("http://localhost:9000/api", null, null, false)
|
||||||
|
val retryTemplate = AppConfiguration().retryTemplate(AppConfigProperties("http://localhost:9000"))
|
||||||
|
retryTemplate.setBackOffPolicy(NoBackOffPolicy())
|
||||||
|
|
||||||
|
this.mockRestServiceServer = MockRestServiceServer.createServer(restTemplate)
|
||||||
|
this.restMtbFileSender =
|
||||||
|
RestDipMtbFileSender(restTemplate, restTargetProperties, retryTemplate, reportService)
|
||||||
|
|
||||||
|
val expectedCount = when (requestWithResponse.httpStatus) {
|
||||||
|
// OK - No Retry
|
||||||
|
HttpStatus.OK, HttpStatus.CREATED, HttpStatus.UNPROCESSABLE_ENTITY, HttpStatus.BAD_REQUEST -> ExpectedCount.max(
|
||||||
|
1
|
||||||
|
)
|
||||||
|
// Request failed - Retry max 3 times
|
||||||
|
else -> ExpectedCount.max(3)
|
||||||
|
}
|
||||||
|
|
||||||
|
this.mockRestServiceServer
|
||||||
|
.expect(expectedCount, method(HttpMethod.DELETE))
|
||||||
|
.andExpect(requestTo("http://localhost:9000/api/mtb/etl/patient/${TEST_PATIENT_PSEUDONYM.value}"))
|
||||||
|
.andRespond {
|
||||||
|
withStatus(requestWithResponse.httpStatus).body(requestWithResponse.body).createResponse(it)
|
||||||
|
}
|
||||||
|
|
||||||
|
val response = restMtbFileSender.send(DeleteRequest(TEST_REQUEST_ID, TEST_PATIENT_PSEUDONYM))
|
||||||
|
assertThat(response.status).isEqualTo(requestWithResponse.response.status)
|
||||||
|
assertThat(response.body).isEqualTo(requestWithResponse.response.body)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
data class RequestWithResponse(
|
||||||
|
val httpStatus: HttpStatus,
|
||||||
|
val body: String,
|
||||||
|
val response: MtbFileSender.Response
|
||||||
|
)
|
||||||
|
|
||||||
|
val TEST_REQUEST_ID = RequestId("TestId")
|
||||||
|
val TEST_PATIENT_PSEUDONYM = PatientPseudonym("PID")
|
||||||
|
|
||||||
|
val bwhcV1mtbFile: MtbFile = MtbFile.builder()
|
||||||
|
.withPatient(
|
||||||
|
Patient.builder()
|
||||||
|
.withId("PID")
|
||||||
|
.withBirthDate("2000-08-08")
|
||||||
|
.withGender(Patient.Gender.MALE)
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
.withConsent(
|
||||||
|
Consent.builder()
|
||||||
|
.withId("1")
|
||||||
|
.withStatus(Consent.Status.ACTIVE)
|
||||||
|
.withPatient("PID")
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
.withEpisode(
|
||||||
|
Episode.builder()
|
||||||
|
.withId("1")
|
||||||
|
.withPatient("PID")
|
||||||
|
.withPeriod(PeriodStart("2023-08-08"))
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
.build()
|
||||||
|
|
||||||
|
val dnpmV2MtbFile: Mtb = Mtb.builder()
|
||||||
|
.withPatient(
|
||||||
|
dev.pcvolkmer.mv64e.mtb.Patient.builder()
|
||||||
|
.withId("PID")
|
||||||
|
.withBirthDate("2000-08-08")
|
||||||
|
.withGender(CodingGender.builder().withCode(CodingGender.Code.MALE).build())
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
.withEpisodesOfCare(
|
||||||
|
listOf(
|
||||||
|
MTBEpisodeOfCare.builder()
|
||||||
|
.withId("1")
|
||||||
|
.withPatient(Reference("PID"))
|
||||||
|
.withPeriod(PeriodDate.builder().withStart("2023-08-08").build())
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.build()
|
||||||
|
|
||||||
|
private const val ERROR_RESPONSE_BODY = "Sonstiger Fehler bei der Übertragung"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Synthetic http responses with related request status
|
||||||
|
* Also see: https://ibmi-intra.cs.uni-tuebingen.de/display/ZPM/bwHC+REST+API
|
||||||
|
*/
|
||||||
|
@JvmStatic
|
||||||
|
fun mtbFileRequestWithResponseSource(): Set<RequestWithResponse> {
|
||||||
|
return setOf(
|
||||||
|
RequestWithResponse(
|
||||||
|
HttpStatus.OK,
|
||||||
|
responseBodyWithMaxSeverity(ReportService.Severity.INFO),
|
||||||
|
MtbFileSender.Response(
|
||||||
|
RequestStatus.SUCCESS,
|
||||||
|
responseBodyWithMaxSeverity(ReportService.Severity.INFO)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
RequestWithResponse(
|
||||||
|
HttpStatus.CREATED,
|
||||||
|
responseBodyWithMaxSeverity(ReportService.Severity.WARNING),
|
||||||
|
MtbFileSender.Response(RequestStatus.WARNING, responseBodyWithMaxSeverity(ReportService.Severity.WARNING))
|
||||||
|
),
|
||||||
|
RequestWithResponse(
|
||||||
|
HttpStatus.BAD_REQUEST,
|
||||||
|
responseBodyWithMaxSeverity(ReportService.Severity.ERROR),
|
||||||
|
MtbFileSender.Response(RequestStatus.ERROR, responseBodyWithMaxSeverity(ReportService.Severity.ERROR))
|
||||||
|
),
|
||||||
|
RequestWithResponse(
|
||||||
|
HttpStatus.UNPROCESSABLE_ENTITY,
|
||||||
|
responseBodyWithMaxSeverity(ReportService.Severity.ERROR),
|
||||||
|
MtbFileSender.Response(RequestStatus.ERROR, responseBodyWithMaxSeverity(ReportService.Severity.ERROR))
|
||||||
|
),
|
||||||
|
// Some more errors not mentioned in documentation
|
||||||
|
RequestWithResponse(
|
||||||
|
HttpStatus.NOT_FOUND,
|
||||||
|
ERROR_RESPONSE_BODY,
|
||||||
|
MtbFileSender.Response(RequestStatus.ERROR, ERROR_RESPONSE_BODY)
|
||||||
|
),
|
||||||
|
RequestWithResponse(
|
||||||
|
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||||
|
ERROR_RESPONSE_BODY,
|
||||||
|
MtbFileSender.Response(RequestStatus.ERROR, ERROR_RESPONSE_BODY)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Synthetic http responses with related request status
|
||||||
|
* Also see: https://ibmi-intra.cs.uni-tuebingen.de/display/ZPM/bwHC+REST+API
|
||||||
|
*/
|
||||||
|
@JvmStatic
|
||||||
|
fun deleteRequestWithResponseSource(): Set<RequestWithResponse> {
|
||||||
|
return setOf(
|
||||||
|
RequestWithResponse(HttpStatus.OK, "", MtbFileSender.Response(RequestStatus.SUCCESS)),
|
||||||
|
// Some more errors not mentioned in documentation
|
||||||
|
RequestWithResponse(
|
||||||
|
HttpStatus.NOT_FOUND,
|
||||||
|
"what????",
|
||||||
|
MtbFileSender.Response(RequestStatus.ERROR, ERROR_RESPONSE_BODY)
|
||||||
|
),
|
||||||
|
RequestWithResponse(
|
||||||
|
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||||
|
"what????",
|
||||||
|
MtbFileSender.Response(RequestStatus.ERROR, ERROR_RESPONSE_BODY)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun responseBodyWithMaxSeverity(severity: ReportService.Severity): String {
|
||||||
|
return when (severity) {
|
||||||
|
ReportService.Severity.INFO -> """
|
||||||
|
{
|
||||||
|
"patient": "PID",
|
||||||
|
"issues": [
|
||||||
|
{ "severity": "info", "message": "Info Message" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
ReportService.Severity.WARNING -> """
|
||||||
|
{
|
||||||
|
"patient": "PID",
|
||||||
|
"issues": [
|
||||||
|
{ "severity": "info", "message": "Info Message" },
|
||||||
|
{ "severity": "warning", "message": "Warning Message" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
ReportService.Severity.ERROR -> """
|
||||||
|
{
|
||||||
|
"patient": "PID",
|
||||||
|
"issues": [
|
||||||
|
{ "severity": "info", "message": "Info Message" },
|
||||||
|
{ "severity": "warning", "message": "Warning Message" },
|
||||||
|
{ "severity": "error", "message": "Error Message" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
ReportService.Severity.FATAL -> """
|
||||||
|
{
|
||||||
|
"patient": "PID",
|
||||||
|
"issues": [
|
||||||
|
{ "severity": "info", "message": "Info Message" },
|
||||||
|
{ "severity": "warning", "message": "Warning Message" },
|
||||||
|
{ "severity": "error", "message": "Error Message" },
|
||||||
|
{ "severity": "fatal", "message": "Fatal Message" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of ETL-Processor
|
* This file is part of ETL-Processor
|
||||||
*
|
*
|
||||||
* Copyright (c) 2023 Comprehensive Cancer Center Mainfranken, Datenintegrationszentrum Philipps-Universität Marburg and Contributors
|
* Copyright (c) 2025 Comprehensive Cancer Center Mainfranken, Datenintegrationszentrum Philipps-Universität Marburg and Contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Affero General Public License as published
|
||||||
@ -21,23 +21,31 @@ package dev.dnpm.etl.processor.pseudonym
|
|||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper
|
import com.fasterxml.jackson.databind.ObjectMapper
|
||||||
import de.ukw.ccc.bwhc.dto.*
|
import de.ukw.ccc.bwhc.dto.*
|
||||||
import dev.dnpm.etl.processor.anyValueClass
|
import dev.pcvolkmer.mv64e.mtb.MTBEpisodeOfCare
|
||||||
|
import dev.pcvolkmer.mv64e.mtb.Mtb
|
||||||
|
import dev.pcvolkmer.mv64e.mtb.PeriodDate
|
||||||
|
import dev.pcvolkmer.mv64e.mtb.Reference
|
||||||
import org.assertj.core.api.Assertions.assertThat
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
|
import org.junit.jupiter.api.Nested
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.jupiter.api.assertThrows
|
import org.junit.jupiter.api.assertThrows
|
||||||
import org.junit.jupiter.api.extension.ExtendWith
|
import org.junit.jupiter.api.extension.ExtendWith
|
||||||
import org.mockito.Mock
|
import org.mockito.Mock
|
||||||
import org.mockito.junit.jupiter.MockitoExtension
|
import org.mockito.junit.jupiter.MockitoExtension
|
||||||
|
import org.mockito.kotlin.anyValueClass
|
||||||
import org.mockito.kotlin.doAnswer
|
import org.mockito.kotlin.doAnswer
|
||||||
import org.mockito.kotlin.whenever
|
import org.mockito.kotlin.whenever
|
||||||
import org.springframework.core.io.ClassPathResource
|
import org.springframework.core.io.ClassPathResource
|
||||||
|
|
||||||
const val FAKE_MTB_FILE_PATH = "fake_MTBFile.json"
|
|
||||||
const val CLEAN_PATIENT_ID = "5dad2f0b-49c6-47d8-a952-7b9e9e0f7549"
|
|
||||||
|
|
||||||
@ExtendWith(MockitoExtension::class)
|
@ExtendWith(MockitoExtension::class)
|
||||||
class ExtensionsTest {
|
class ExtensionsTest {
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
inner class UsingBwhcDatamodel {
|
||||||
|
|
||||||
|
val FAKE_MTB_FILE_PATH = "fake_MTBFile.json"
|
||||||
|
val CLEAN_PATIENT_ID = "5dad2f0b-49c6-47d8-a952-7b9e9e0f7549"
|
||||||
|
|
||||||
private fun fakeMtbFile(): MtbFile {
|
private fun fakeMtbFile(): MtbFile {
|
||||||
val mtbFile = ClassPathResource(FAKE_MTB_FILE_PATH).inputStream
|
val mtbFile = ClassPathResource(FAKE_MTB_FILE_PATH).inputStream
|
||||||
return ObjectMapper().readValue(mtbFile, MtbFile::class.java)
|
return ObjectMapper().readValue(mtbFile, MtbFile::class.java)
|
||||||
@ -191,8 +199,83 @@ class ExtensionsTest {
|
|||||||
mtbFile.pseudonymizeWith(pseudonymizeService)
|
mtbFile.pseudonymizeWith(pseudonymizeService)
|
||||||
mtbFile.anonymizeContentWith(pseudonymizeService)
|
mtbFile.anonymizeContentWith(pseudonymizeService)
|
||||||
|
|
||||||
|
|
||||||
assertThat(mtbFile.episode.id).isNotNull()
|
assertThat(mtbFile.episode.id).isNotNull()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
inner class UsingDnpmV2Datamodel {
|
||||||
|
|
||||||
|
val FAKE_MTB_FILE_PATH = "mv64e-mtb-fake-patient.json"
|
||||||
|
val CLEAN_PATIENT_ID = "63f8fd7b-8127-4f3c-8843-aa9199e21c29"
|
||||||
|
|
||||||
|
private fun fakeMtbFile(): Mtb {
|
||||||
|
val mtbFile = ClassPathResource(FAKE_MTB_FILE_PATH).inputStream
|
||||||
|
return ObjectMapper().readValue(mtbFile, Mtb::class.java)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun Mtb.serialized(): String {
|
||||||
|
return ObjectMapper().writeValueAsString(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun shouldNotContainCleanPatientId(@Mock pseudonymizeService: PseudonymizeService) {
|
||||||
|
doAnswer {
|
||||||
|
it.arguments[0]
|
||||||
|
"PSEUDO-ID"
|
||||||
|
}.whenever(pseudonymizeService).patientPseudonym(anyValueClass())
|
||||||
|
|
||||||
|
val mtbFile = fakeMtbFile()
|
||||||
|
|
||||||
|
mtbFile.pseudonymizeWith(pseudonymizeService)
|
||||||
|
|
||||||
|
assertThat(mtbFile.patient.id).isEqualTo("PSEUDO-ID")
|
||||||
|
assertThat(mtbFile.serialized()).doesNotContain(CLEAN_PATIENT_ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun shouldNotThrowExceptionOnNullValues(@Mock pseudonymizeService: PseudonymizeService) {
|
||||||
|
doAnswer {
|
||||||
|
it.arguments[0]
|
||||||
|
"PSEUDO-ID"
|
||||||
|
}.whenever(pseudonymizeService).patientPseudonym(anyValueClass())
|
||||||
|
|
||||||
|
doAnswer {
|
||||||
|
"TESTDOMAIN"
|
||||||
|
}.whenever(pseudonymizeService).prefix()
|
||||||
|
|
||||||
|
val mtbFile = Mtb.builder()
|
||||||
|
.withPatient(
|
||||||
|
dev.pcvolkmer.mv64e.mtb.Patient.builder()
|
||||||
|
.withId("1")
|
||||||
|
.withBirthDate("2000-08-08")
|
||||||
|
.withGender(null)
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
.withEpisodesOfCare(
|
||||||
|
listOf(
|
||||||
|
MTBEpisodeOfCare.builder()
|
||||||
|
.withId("1")
|
||||||
|
.withPatient(Reference("1"))
|
||||||
|
.withPeriod(PeriodDate.builder().withStart("2023-08-08").build())
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.withClaims(null)
|
||||||
|
.withDiagnoses(null)
|
||||||
|
.withCarePlans(null)
|
||||||
|
.withClaimResponses(null)
|
||||||
|
.withHistologyReports(null)
|
||||||
|
.withNgsReports(null)
|
||||||
|
.withResponses(null)
|
||||||
|
.withSpecimens(null)
|
||||||
|
.build()
|
||||||
|
|
||||||
|
mtbFile.pseudonymizeWith(pseudonymizeService)
|
||||||
|
mtbFile.anonymizeContentWith(pseudonymizeService)
|
||||||
|
|
||||||
|
assertThat(mtbFile.episodesOfCare).hasSize(1)
|
||||||
|
assertThat(mtbFile.episodesOfCare.map { it.id }).isNotNull
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of ETL-Processor
|
* This file is part of ETL-Processor
|
||||||
*
|
*
|
||||||
* Copyright (c) 2023 Comprehensive Cancer Center Mainfranken, Datenintegrationszentrum Philipps-Universität Marburg and Contributors
|
* Copyright (c) 2025 Comprehensive Cancer Center Mainfranken, Datenintegrationszentrum Philipps-Universität Marburg and Contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Affero General Public License as published
|
||||||
@ -22,9 +22,14 @@ package dev.dnpm.etl.processor.services
|
|||||||
import com.fasterxml.jackson.databind.ObjectMapper
|
import com.fasterxml.jackson.databind.ObjectMapper
|
||||||
import com.fasterxml.jackson.module.kotlin.KotlinModule
|
import com.fasterxml.jackson.module.kotlin.KotlinModule
|
||||||
import dev.dnpm.etl.processor.monitoring.ReportService
|
import dev.dnpm.etl.processor.monitoring.ReportService
|
||||||
|
import dev.dnpm.etl.processor.monitoring.RequestStatus
|
||||||
|
import dev.dnpm.etl.processor.monitoring.asRequestStatus
|
||||||
import org.assertj.core.api.Assertions.assertThat
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
import org.junit.jupiter.api.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
import org.junit.jupiter.params.ParameterizedTest
|
||||||
|
import org.junit.jupiter.params.provider.Arguments
|
||||||
|
import org.junit.jupiter.params.provider.MethodSource
|
||||||
|
|
||||||
class ReportServiceTest {
|
class ReportServiceTest {
|
||||||
|
|
||||||
@ -60,6 +65,15 @@ class ReportServiceTest {
|
|||||||
assertThat(actual[2].message).isEqualTo("Warning Message")
|
assertThat(actual[2].message).isEqualTo("Warning Message")
|
||||||
assertThat(actual[3].severity).isEqualTo(ReportService.Severity.INFO)
|
assertThat(actual[3].severity).isEqualTo(ReportService.Severity.INFO)
|
||||||
assertThat(actual[3].message).isEqualTo("Info Message")
|
assertThat(actual[3].message).isEqualTo("Info Message")
|
||||||
|
|
||||||
|
assertThat(actual.asRequestStatus()).isEqualTo(RequestStatus.ERROR)
|
||||||
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@MethodSource("testData")
|
||||||
|
fun shouldParseDataQualityReport(json: String, requestStatus: RequestStatus) {
|
||||||
|
val actual = this.reportService.deserialize(json)
|
||||||
|
assertThat(actual.asRequestStatus()).isEqualTo(requestStatus)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -73,4 +87,75 @@ class ReportServiceTest {
|
|||||||
assertThat(actual[0].message).isEqualTo("Not parsable data quality report '$invalidResponse'")
|
assertThat(actual[0].message).isEqualTo("Not parsable data quality report '$invalidResponse'")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun testData(): Set<Arguments> {
|
||||||
|
return setOf(
|
||||||
|
Arguments.of(
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"patient": "4711",
|
||||||
|
"issues": [
|
||||||
|
{ "severity": "info", "message": "Info Message" },
|
||||||
|
{ "severity": "warning", "message": "Warning Message" },
|
||||||
|
{ "severity": "error", "message": "Error Message" },
|
||||||
|
{ "severity": "fatal", "message": "Fatal Message" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
""".trimIndent(),
|
||||||
|
RequestStatus.ERROR
|
||||||
|
),
|
||||||
|
Arguments.of(
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"patient": "4711",
|
||||||
|
"issues": [
|
||||||
|
{ "severity": "info", "message": "Info Message" },
|
||||||
|
{ "severity": "warning", "message": "Warning Message" },
|
||||||
|
{ "severity": "error", "message": "Error Message" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
""".trimIndent(),
|
||||||
|
RequestStatus.ERROR
|
||||||
|
),
|
||||||
|
Arguments.of(
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"patient": "4711",
|
||||||
|
"issues": [
|
||||||
|
{ "severity": "error", "message": "Error Message" }
|
||||||
|
{ "severity": "info", "message": "Info Message" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
""".trimIndent(),
|
||||||
|
RequestStatus.ERROR
|
||||||
|
),
|
||||||
|
Arguments.of(
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"patient": "4711",
|
||||||
|
"issues": [
|
||||||
|
{ "severity": "info", "message": "Info Message" },
|
||||||
|
{ "severity": "warning", "message": "Warning Message" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
""".trimIndent(),
|
||||||
|
RequestStatus.WARNING
|
||||||
|
),
|
||||||
|
Arguments.of(
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"patient": "4711",
|
||||||
|
"issues": [
|
||||||
|
{ "severity": "info", "message": "Info Message" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
""".trimIndent(),
|
||||||
|
RequestStatus.SUCCESS
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -21,15 +21,20 @@ package dev.dnpm.etl.processor.services
|
|||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper
|
import com.fasterxml.jackson.databind.ObjectMapper
|
||||||
import de.ukw.ccc.bwhc.dto.*
|
import de.ukw.ccc.bwhc.dto.*
|
||||||
import dev.dnpm.etl.processor.*
|
import dev.dnpm.etl.processor.Fingerprint
|
||||||
|
import dev.dnpm.etl.processor.PatientId
|
||||||
|
import dev.dnpm.etl.processor.PatientPseudonym
|
||||||
import dev.dnpm.etl.processor.config.AppConfigProperties
|
import dev.dnpm.etl.processor.config.AppConfigProperties
|
||||||
import dev.dnpm.etl.processor.consent.ConsentStatus
|
import dev.dnpm.etl.processor.consent.ConsentStatus
|
||||||
import dev.dnpm.etl.processor.monitoring.Request
|
import dev.dnpm.etl.processor.monitoring.Request
|
||||||
import dev.dnpm.etl.processor.monitoring.RequestStatus
|
import dev.dnpm.etl.processor.monitoring.RequestStatus
|
||||||
import dev.dnpm.etl.processor.monitoring.RequestType
|
import dev.dnpm.etl.processor.monitoring.RequestType
|
||||||
|
import dev.dnpm.etl.processor.output.BwhcV1MtbFileRequest
|
||||||
|
import dev.dnpm.etl.processor.output.DeleteRequest
|
||||||
import dev.dnpm.etl.processor.output.MtbFileSender
|
import dev.dnpm.etl.processor.output.MtbFileSender
|
||||||
import dev.dnpm.etl.processor.output.RestMtbFileSender
|
import dev.dnpm.etl.processor.output.RestMtbFileSender
|
||||||
import dev.dnpm.etl.processor.pseudonym.PseudonymizeService
|
import dev.dnpm.etl.processor.pseudonym.PseudonymizeService
|
||||||
|
import dev.dnpm.etl.processor.randomRequestId
|
||||||
import org.assertj.core.api.Assertions.assertThat
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
import org.junit.jupiter.api.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
@ -38,6 +43,7 @@ import org.mockito.Mock
|
|||||||
import org.mockito.Mockito.*
|
import org.mockito.Mockito.*
|
||||||
import org.mockito.junit.jupiter.MockitoExtension
|
import org.mockito.junit.jupiter.MockitoExtension
|
||||||
import org.mockito.kotlin.any
|
import org.mockito.kotlin.any
|
||||||
|
import org.mockito.kotlin.anyValueClass
|
||||||
import org.mockito.kotlin.argumentCaptor
|
import org.mockito.kotlin.argumentCaptor
|
||||||
import org.mockito.kotlin.whenever
|
import org.mockito.kotlin.whenever
|
||||||
import org.springframework.context.ApplicationEventPublisher
|
import org.springframework.context.ApplicationEventPublisher
|
||||||
@ -109,7 +115,7 @@ class RequestProcessorTest {
|
|||||||
|
|
||||||
doAnswer {
|
doAnswer {
|
||||||
it.arguments[0]
|
it.arguments[0]
|
||||||
}.whenever(transformationService).transform(any())
|
}.whenever(transformationService).transform(any<MtbFile>())
|
||||||
|
|
||||||
val mtbFile = MtbFile.builder()
|
val mtbFile = MtbFile.builder()
|
||||||
.withPatient(
|
.withPatient(
|
||||||
@ -168,7 +174,7 @@ class RequestProcessorTest {
|
|||||||
|
|
||||||
doAnswer {
|
doAnswer {
|
||||||
it.arguments[0]
|
it.arguments[0]
|
||||||
}.whenever(transformationService).transform(any())
|
}.whenever(transformationService).transform(any<MtbFile>())
|
||||||
|
|
||||||
val mtbFile = MtbFile.builder()
|
val mtbFile = MtbFile.builder()
|
||||||
.withPatient(
|
.withPatient(
|
||||||
@ -223,7 +229,7 @@ class RequestProcessorTest {
|
|||||||
|
|
||||||
doAnswer {
|
doAnswer {
|
||||||
MtbFileSender.Response(status = RequestStatus.SUCCESS)
|
MtbFileSender.Response(status = RequestStatus.SUCCESS)
|
||||||
}.whenever(sender).send(any<MtbFileSender.MtbFileRequest>())
|
}.whenever(sender).send(any<BwhcV1MtbFileRequest>())
|
||||||
|
|
||||||
doAnswer {
|
doAnswer {
|
||||||
it.arguments[0] as String
|
it.arguments[0] as String
|
||||||
@ -231,7 +237,7 @@ class RequestProcessorTest {
|
|||||||
|
|
||||||
doAnswer {
|
doAnswer {
|
||||||
it.arguments[0]
|
it.arguments[0]
|
||||||
}.whenever(transformationService).transform(any())
|
}.whenever(transformationService).transform(any<MtbFile>())
|
||||||
|
|
||||||
val mtbFile = MtbFile.builder()
|
val mtbFile = MtbFile.builder()
|
||||||
.withPatient(
|
.withPatient(
|
||||||
@ -286,7 +292,7 @@ class RequestProcessorTest {
|
|||||||
|
|
||||||
doAnswer {
|
doAnswer {
|
||||||
MtbFileSender.Response(status = RequestStatus.ERROR)
|
MtbFileSender.Response(status = RequestStatus.ERROR)
|
||||||
}.whenever(sender).send(any<MtbFileSender.MtbFileRequest>())
|
}.whenever(sender).send(any<BwhcV1MtbFileRequest>())
|
||||||
|
|
||||||
doAnswer {
|
doAnswer {
|
||||||
it.arguments[0] as String
|
it.arguments[0] as String
|
||||||
@ -294,7 +300,7 @@ class RequestProcessorTest {
|
|||||||
|
|
||||||
doAnswer {
|
doAnswer {
|
||||||
it.arguments[0]
|
it.arguments[0]
|
||||||
}.whenever(transformationService).transform(any())
|
}.whenever(transformationService).transform(any<MtbFile>())
|
||||||
|
|
||||||
val mtbFile = MtbFile.builder()
|
val mtbFile = MtbFile.builder()
|
||||||
.withPatient(
|
.withPatient(
|
||||||
@ -336,7 +342,7 @@ class RequestProcessorTest {
|
|||||||
|
|
||||||
doAnswer {
|
doAnswer {
|
||||||
MtbFileSender.Response(status = RequestStatus.UNKNOWN)
|
MtbFileSender.Response(status = RequestStatus.UNKNOWN)
|
||||||
}.whenever(sender).send(any<MtbFileSender.DeleteRequest>())
|
}.whenever(sender).send(any<DeleteRequest>())
|
||||||
|
|
||||||
this.requestProcessor.processDeletion(TEST_PATIENT_ID, isConsented = ConsentStatus.IGNORED)
|
this.requestProcessor.processDeletion(TEST_PATIENT_ID, isConsented = ConsentStatus.IGNORED)
|
||||||
|
|
||||||
@ -354,7 +360,7 @@ class RequestProcessorTest {
|
|||||||
|
|
||||||
doAnswer {
|
doAnswer {
|
||||||
MtbFileSender.Response(status = RequestStatus.SUCCESS)
|
MtbFileSender.Response(status = RequestStatus.SUCCESS)
|
||||||
}.whenever(sender).send(any<MtbFileSender.DeleteRequest>())
|
}.whenever(sender).send(any<DeleteRequest>())
|
||||||
|
|
||||||
this.requestProcessor.processDeletion(TEST_PATIENT_ID, isConsented = ConsentStatus.IGNORED)
|
this.requestProcessor.processDeletion(TEST_PATIENT_ID, isConsented = ConsentStatus.IGNORED)
|
||||||
|
|
||||||
@ -372,7 +378,7 @@ class RequestProcessorTest {
|
|||||||
|
|
||||||
doAnswer {
|
doAnswer {
|
||||||
MtbFileSender.Response(status = RequestStatus.ERROR)
|
MtbFileSender.Response(status = RequestStatus.ERROR)
|
||||||
}.whenever(sender).send(any<MtbFileSender.DeleteRequest>())
|
}.whenever(sender).send(any<DeleteRequest>())
|
||||||
|
|
||||||
this.requestProcessor.processDeletion(TEST_PATIENT_ID, isConsented = ConsentStatus.IGNORED)
|
this.requestProcessor.processDeletion(TEST_PATIENT_ID, isConsented = ConsentStatus.IGNORED)
|
||||||
|
|
||||||
@ -404,11 +410,11 @@ class RequestProcessorTest {
|
|||||||
|
|
||||||
doAnswer {
|
doAnswer {
|
||||||
it.arguments[0]
|
it.arguments[0]
|
||||||
}.whenever(transformationService).transform(any())
|
}.whenever(transformationService).transform(any<MtbFile>())
|
||||||
|
|
||||||
doAnswer {
|
doAnswer {
|
||||||
MtbFileSender.Response(status = RequestStatus.SUCCESS)
|
MtbFileSender.Response(status = RequestStatus.SUCCESS)
|
||||||
}.whenever(sender).send(any<MtbFileSender.MtbFileRequest>())
|
}.whenever(sender).send(any<BwhcV1MtbFileRequest>())
|
||||||
|
|
||||||
val mtbFile = MtbFile.builder()
|
val mtbFile = MtbFile.builder()
|
||||||
.withPatient(
|
.withPatient(
|
||||||
|
@ -31,6 +31,7 @@ import org.junit.jupiter.api.extension.ExtendWith
|
|||||||
import org.mockito.Mock
|
import org.mockito.Mock
|
||||||
import org.mockito.Mockito.*
|
import org.mockito.Mockito.*
|
||||||
import org.mockito.junit.jupiter.MockitoExtension
|
import org.mockito.junit.jupiter.MockitoExtension
|
||||||
|
import org.mockito.kotlin.anyValueClass
|
||||||
import org.mockito.kotlin.whenever
|
import org.mockito.kotlin.whenever
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
|
|
||||||
|
File diff suppressed because one or more lines are too long
2243
src/test/resources/mv64e-mtb-fake-patient.json
Normal file
2243
src/test/resources/mv64e-mtb-fake-patient.json
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user