1
0
mirror of https://github.com/pcvolkmer/etl-processor.git synced 2025-04-20 17:56:50 +00:00

refactor: add additional constructors

This commit is contained in:
Paul-Christian Volkmer 2024-04-29 10:11:25 +02:00
parent 3bd7239812
commit 5fcc24f915
5 changed files with 167 additions and 148 deletions

View File

@ -76,33 +76,33 @@ class RequestServiceIntegrationTest : AbstractTestcontainerTest() {
this.requestRepository.saveAll( this.requestRepository.saveAll(
listOf( listOf(
Request( Request(
uuid = UUID.randomUUID().toString(), UUID.randomUUID().toString(),
patientId = "TEST_12345678901", "TEST_12345678901",
pid = "P1", "P1",
fingerprint = "0123456789abcdef1", "0123456789abcdef1",
type = RequestType.MTB_FILE, RequestType.MTB_FILE,
status = RequestStatus.SUCCESS, RequestStatus.SUCCESS,
processedAt = Instant.parse("2023-07-07T02:00:00Z") Instant.parse("2023-07-07T02:00:00Z")
), ),
// Should be ignored - wrong patient ID --> // Should be ignored - wrong patient ID -->
Request( Request(
uuid = UUID.randomUUID().toString(), UUID.randomUUID().toString(),
patientId = "TEST_12345678902", "TEST_12345678902",
pid = "P2", "P2",
fingerprint = "0123456789abcdef2", "0123456789abcdef2",
type = RequestType.MTB_FILE, RequestType.MTB_FILE,
status = RequestStatus.WARNING, RequestStatus.WARNING,
processedAt = Instant.parse("2023-08-08T00:00:00Z") Instant.parse("2023-08-08T00:00:00Z")
), ),
// <-- // <--
Request( Request(
uuid = UUID.randomUUID().toString(), UUID.randomUUID().toString(),
patientId = "TEST_12345678901", "TEST_12345678901",
pid = "P2", "P2",
fingerprint = "0123456789abcdee1", "0123456789abcdee1",
type = RequestType.DELETE, RequestType.DELETE,
status = RequestStatus.SUCCESS, RequestStatus.SUCCESS,
processedAt = Instant.parse("2023-08-08T02:00:00Z") Instant.parse("2023-08-08T02:00:00Z")
) )
) )
) )

View File

@ -43,7 +43,28 @@ data class Request(
var status: RequestStatus, var status: RequestStatus,
var processedAt: Instant = Instant.now(), var processedAt: Instant = Instant.now(),
@Embedded.Nullable var report: Report? = null @Embedded.Nullable var report: Report? = null
) ) {
constructor(
uuid: String,
patientId: String,
pid: String,
fingerprint: String,
type: RequestType,
status: RequestStatus
) :
this(null, uuid, patientId, pid, fingerprint, type, status, Instant.now())
constructor(
uuid: String,
patientId: String,
pid: String,
fingerprint: String,
type: RequestType,
status: RequestStatus,
processedAt: Instant
) :
this(null, uuid, patientId, pid, fingerprint, type, status, processedAt)
}
@JvmRecord @JvmRecord
data class Report( data class Report(

View File

@ -62,12 +62,12 @@ class RequestProcessor(
requestService.save( requestService.save(
Request( Request(
uuid = requestId, requestId,
patientId = request.mtbFile.patient.id, request.mtbFile.patient.id,
pid = pid, pid,
fingerprint = fingerprint(request.mtbFile), fingerprint(request.mtbFile),
status = RequestStatus.UNKNOWN, RequestType.MTB_FILE,
type = RequestType.MTB_FILE RequestStatus.UNKNOWN
) )
) )
@ -117,12 +117,12 @@ class RequestProcessor(
requestService.save( requestService.save(
Request( Request(
uuid = requestId, requestId,
patientId = patientPseudonym, patientPseudonym,
pid = patientId, patientId,
fingerprint = fingerprint(patientPseudonym), fingerprint(patientPseudonym),
status = RequestStatus.UNKNOWN, RequestType.DELETE,
type = RequestType.DELETE RequestStatus.UNKNOWN
) )
) )

View File

@ -22,9 +22,7 @@ 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.config.AppConfigProperties import dev.dnpm.etl.processor.config.AppConfigProperties
import dev.dnpm.etl.processor.monitoring.Request import dev.dnpm.etl.processor.monitoring.*
import dev.dnpm.etl.processor.monitoring.RequestStatus
import dev.dnpm.etl.processor.monitoring.RequestType
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
@ -88,14 +86,14 @@ class RequestProcessorTest {
fun testShouldSendMtbFileDuplicationAndSaveUnknownRequestStatusAtFirst() { fun testShouldSendMtbFileDuplicationAndSaveUnknownRequestStatusAtFirst() {
doAnswer { doAnswer {
Request( Request(
id = 1L, 1L,
uuid = UUID.randomUUID().toString(), UUID.randomUUID().toString(),
patientId = "TEST_12345678901", "TEST_12345678901",
pid = "P1", "P1",
fingerprint = "zdlzv5s5ydmd4ktw2v5piohegc4jcyrm6j66bq6tv2uxuerndmga", "zdlzv5s5ydmd4ktw2v5piohegc4jcyrm6j66bq6tv2uxuerndmga",
type = RequestType.MTB_FILE, RequestType.MTB_FILE,
status = RequestStatus.SUCCESS, RequestStatus.SUCCESS,
processedAt = Instant.parse("2023-08-08T02:00:00Z") Instant.parse("2023-08-08T02:00:00Z")
) )
}.`when`(requestService).lastMtbFileRequestForPatientPseudonym(anyString()) }.`when`(requestService).lastMtbFileRequestForPatientPseudonym(anyString())
@ -147,14 +145,14 @@ class RequestProcessorTest {
fun testShouldDetectMtbFileDuplicationAndSendDuplicationEvent() { fun testShouldDetectMtbFileDuplicationAndSendDuplicationEvent() {
doAnswer { doAnswer {
Request( Request(
id = 1L, 1L,
uuid = UUID.randomUUID().toString(), UUID.randomUUID().toString(),
patientId = "TEST_12345678901", "TEST_12345678901",
pid = "P1", "P1",
fingerprint = "zdlzv5s5ydmd4ktw2v5piohegc4jcyrm6j66bq6tv2uxuerndmga", "zdlzv5s5ydmd4ktw2v5piohegc4jcyrm6j66bq6tv2uxuerndmga",
type = RequestType.MTB_FILE, RequestType.MTB_FILE,
status = RequestStatus.SUCCESS, RequestStatus.SUCCESS,
processedAt = Instant.parse("2023-08-08T02:00:00Z") Instant.parse("2023-08-08T02:00:00Z")
) )
}.`when`(requestService).lastMtbFileRequestForPatientPseudonym(anyString()) }.`when`(requestService).lastMtbFileRequestForPatientPseudonym(anyString())
@ -206,14 +204,14 @@ class RequestProcessorTest {
fun testShouldSendMtbFileAndSendSuccessEvent() { fun testShouldSendMtbFileAndSendSuccessEvent() {
doAnswer { doAnswer {
Request( Request(
id = 1L, 1L,
uuid = UUID.randomUUID().toString(), UUID.randomUUID().toString(),
patientId = "TEST_12345678901", "TEST_12345678901",
pid = "P1", "P1",
fingerprint = "different", "different",
type = RequestType.MTB_FILE, RequestType.MTB_FILE,
status = RequestStatus.SUCCESS, RequestStatus.SUCCESS,
processedAt = Instant.parse("2023-08-08T02:00:00Z") Instant.parse("2023-08-08T02:00:00Z")
) )
}.`when`(requestService).lastMtbFileRequestForPatientPseudonym(anyString()) }.`when`(requestService).lastMtbFileRequestForPatientPseudonym(anyString())
@ -269,14 +267,14 @@ class RequestProcessorTest {
fun testShouldSendMtbFileAndSendErrorEvent() { fun testShouldSendMtbFileAndSendErrorEvent() {
doAnswer { doAnswer {
Request( Request(
id = 1L, 1L,
uuid = UUID.randomUUID().toString(), UUID.randomUUID().toString(),
patientId = "TEST_12345678901", "TEST_12345678901",
pid = "P1", "P1",
fingerprint = "different", "different",
type = RequestType.MTB_FILE, RequestType.MTB_FILE,
status = RequestStatus.SUCCESS, RequestStatus.SUCCESS,
processedAt = Instant.parse("2023-08-08T02:00:00Z") Instant.parse("2023-08-08T02:00:00Z")
) )
}.`when`(requestService).lastMtbFileRequestForPatientPseudonym(anyString()) }.`when`(requestService).lastMtbFileRequestForPatientPseudonym(anyString())

View File

@ -41,14 +41,14 @@ class RequestServiceTest {
private lateinit var requestService: RequestService private lateinit var requestService: RequestService
private fun anyRequest() = any(Request::class.java) ?: Request( private fun anyRequest() = any(Request::class.java) ?: Request(
id = 0L, 0L,
uuid = UUID.randomUUID().toString(), UUID.randomUUID().toString(),
patientId = "TEST_dummy", "TEST_dummy",
pid = "PX", "PX",
fingerprint = "dummy", "dummy",
type = RequestType.MTB_FILE, RequestType.MTB_FILE,
status = RequestStatus.SUCCESS, RequestStatus.SUCCESS,
processedAt = Instant.parse("2023-08-08T02:00:00Z") Instant.parse("2023-08-08T02:00:00Z")
) )
@BeforeEach @BeforeEach
@ -63,34 +63,34 @@ class RequestServiceTest {
fun shouldIndicateLastRequestIsDeleteRequest() { fun shouldIndicateLastRequestIsDeleteRequest() {
val requests = listOf( val requests = listOf(
Request( Request(
id = 1L, 1L,
uuid = UUID.randomUUID().toString(), UUID.randomUUID().toString(),
patientId = "TEST_12345678901", "TEST_12345678901",
pid = "P1", "P1",
fingerprint = "0123456789abcdef1", "0123456789abcdef1",
type = RequestType.MTB_FILE, RequestType.MTB_FILE,
status = RequestStatus.WARNING, RequestStatus.WARNING,
processedAt = Instant.parse("2023-07-07T00:00:00Z") Instant.parse("2023-07-07T00:00:00Z")
), ),
Request( Request(
id = 2L, 2L,
uuid = UUID.randomUUID().toString(), UUID.randomUUID().toString(),
patientId = "TEST_12345678901", "TEST_12345678901",
pid = "P1", "P1",
fingerprint = "0123456789abcdefd", "0123456789abcdefd",
type = RequestType.DELETE, RequestType.DELETE,
status = RequestStatus.WARNING, RequestStatus.WARNING,
processedAt = Instant.parse("2023-07-07T02:00:00Z") Instant.parse("2023-07-07T02:00:00Z")
), ),
Request( Request(
id = 3L, 3L,
uuid = UUID.randomUUID().toString(), UUID.randomUUID().toString(),
patientId = "TEST_12345678901", "TEST_12345678901",
pid = "P1", "P1",
fingerprint = "0123456789abcdef1", "0123456789abcdef1",
type = RequestType.MTB_FILE, RequestType.MTB_FILE,
status = RequestStatus.UNKNOWN, RequestStatus.UNKNOWN,
processedAt = Instant.parse("2023-08-11T00:00:00Z") Instant.parse("2023-08-11T00:00:00Z")
) )
) )
@ -103,34 +103,34 @@ class RequestServiceTest {
fun shouldIndicateLastRequestIsNotDeleteRequest() { fun shouldIndicateLastRequestIsNotDeleteRequest() {
val requests = listOf( val requests = listOf(
Request( Request(
id = 1L, 1L,
uuid = UUID.randomUUID().toString(), UUID.randomUUID().toString(),
patientId = "TEST_12345678901", "TEST_12345678901",
pid = "P1", "P1",
fingerprint = "0123456789abcdef1", "0123456789abcdef1",
type = RequestType.MTB_FILE, RequestType.MTB_FILE,
status = RequestStatus.WARNING, RequestStatus.WARNING,
processedAt = Instant.parse("2023-07-07T00:00:00Z") Instant.parse("2023-07-07T00:00:00Z")
), ),
Request( Request(
id = 2L, 2L,
uuid = UUID.randomUUID().toString(), UUID.randomUUID().toString(),
patientId = "TEST_12345678901", "TEST_12345678901",
pid = "P1", "P1",
fingerprint = "0123456789abcdef1", "0123456789abcdef1",
type = RequestType.MTB_FILE, RequestType.MTB_FILE,
status = RequestStatus.WARNING, RequestStatus.WARNING,
processedAt = Instant.parse("2023-07-07T02:00:00Z") Instant.parse("2023-07-07T02:00:00Z")
), ),
Request( Request(
id = 3L, 3L,
uuid = UUID.randomUUID().toString(), UUID.randomUUID().toString(),
patientId = "TEST_12345678901", "TEST_12345678901",
pid = "P1", "P1",
fingerprint = "0123456789abcdef1", "0123456789abcdef1",
type = RequestType.MTB_FILE, RequestType.MTB_FILE,
status = RequestStatus.UNKNOWN, RequestStatus.UNKNOWN,
processedAt = Instant.parse("2023-08-11T00:00:00Z") Instant.parse("2023-08-11T00:00:00Z")
) )
) )
@ -143,24 +143,24 @@ class RequestServiceTest {
fun shouldReturnPatientsLastRequest() { fun shouldReturnPatientsLastRequest() {
val requests = listOf( val requests = listOf(
Request( Request(
id = 1L, 1L,
uuid = UUID.randomUUID().toString(), UUID.randomUUID().toString(),
patientId = "TEST_12345678901", "TEST_12345678901",
pid = "P1", "P1",
fingerprint = "0123456789abcdef1", "0123456789abcdef1",
type = RequestType.DELETE, RequestType.DELETE,
status = RequestStatus.SUCCESS, RequestStatus.SUCCESS,
processedAt = Instant.parse("2023-07-07T02:00:00Z") Instant.parse("2023-07-07T02:00:00Z")
), ),
Request( Request(
id = 1L, 1L,
uuid = UUID.randomUUID().toString(), UUID.randomUUID().toString(),
patientId = "TEST_12345678902", "TEST_12345678902",
pid = "P2", "P2",
fingerprint = "0123456789abcdef2", "0123456789abcdef2",
type = RequestType.MTB_FILE, RequestType.MTB_FILE,
status = RequestStatus.WARNING, RequestStatus.WARNING,
processedAt = Instant.parse("2023-08-08T00:00:00Z") Instant.parse("2023-08-08T00:00:00Z")
) )
) )
@ -187,13 +187,13 @@ class RequestServiceTest {
}.`when`(requestRepository).save(anyRequest()) }.`when`(requestRepository).save(anyRequest())
val request = Request( val request = Request(
uuid = UUID.randomUUID().toString(), UUID.randomUUID().toString(),
patientId = "TEST_12345678901", "TEST_12345678901",
pid = "P1", "P1",
fingerprint = "0123456789abcdef1", "0123456789abcdef1",
type = RequestType.DELETE, RequestType.DELETE,
status = RequestStatus.SUCCESS, RequestStatus.SUCCESS,
processedAt = Instant.parse("2023-07-07T02:00:00Z") Instant.parse("2023-07-07T02:00:00Z")
) )
requestService.save(request) requestService.save(request)