mirror of
https://github.com/pcvolkmer/etl-processor.git
synced 2025-04-19 17:26:51 +00:00
Code cleanup
This commit is contained in:
parent
bc48a7217e
commit
72295202ec
@ -20,10 +20,13 @@
|
|||||||
package dev.dnpm.etl.processor
|
package dev.dnpm.etl.processor
|
||||||
|
|
||||||
import dev.dnpm.etl.processor.output.MtbFileSender
|
import dev.dnpm.etl.processor.output.MtbFileSender
|
||||||
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
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.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.boot.test.mock.mockito.MockBean
|
||||||
|
import org.springframework.context.ApplicationContext
|
||||||
import org.springframework.test.context.junit.jupiter.SpringExtension
|
import org.springframework.test.context.junit.jupiter.SpringExtension
|
||||||
import org.testcontainers.junit.jupiter.Testcontainers
|
import org.testcontainers.junit.jupiter.Testcontainers
|
||||||
|
|
||||||
@ -34,7 +37,9 @@ import org.testcontainers.junit.jupiter.Testcontainers
|
|||||||
class EtlProcessorApplicationTests : AbstractTestcontainerTest() {
|
class EtlProcessorApplicationTests : AbstractTestcontainerTest() {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun contextLoadsIfMtbFileSenderConfigured() {
|
fun contextLoadsIfMtbFileSenderConfigured(@Autowired context: ApplicationContext) {
|
||||||
|
// Simply check bean configuration
|
||||||
|
assertThat(context).isNotNull
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -69,13 +69,11 @@ import java.util.HashMap;
|
|||||||
|
|
||||||
public class GpasPseudonymGenerator implements Generator {
|
public class GpasPseudonymGenerator implements Generator {
|
||||||
|
|
||||||
|
private final static FhirContext r4Context = FhirContext.forR4();
|
||||||
private final String gPasUrl;
|
private final String gPasUrl;
|
||||||
private final String psnTargetDomain;
|
private final String psnTargetDomain;
|
||||||
private static FhirContext r4Context = FhirContext.forR4();
|
|
||||||
private final HttpHeaders httpHeader;
|
private final HttpHeaders httpHeader;
|
||||||
|
|
||||||
private final RetryTemplate retryTemplate = defaultTemplate();
|
private final RetryTemplate retryTemplate = defaultTemplate();
|
||||||
|
|
||||||
private final Logger log = LoggerFactory.getLogger(GpasPseudonymGenerator.class);
|
private final Logger log = LoggerFactory.getLogger(GpasPseudonymGenerator.class);
|
||||||
|
|
||||||
private SSLContext customSslContext;
|
private SSLContext customSslContext;
|
||||||
|
@ -23,7 +23,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties
|
|||||||
|
|
||||||
@ConfigurationProperties(AppConfigProperties.NAME)
|
@ConfigurationProperties(AppConfigProperties.NAME)
|
||||||
data class AppConfigProperties(
|
data class AppConfigProperties(
|
||||||
var bwhc_uri: String?,
|
var bwhcUri: String?,
|
||||||
var generator: PseudonymGenerator = PseudonymGenerator.BUILDIN
|
var generator: PseudonymGenerator = PseudonymGenerator.BUILDIN
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -38,7 +38,7 @@ infix fun MtbFile.pseudonymizeWith(pseudonymizeService: PseudonymizeService) {
|
|||||||
this.histologyReports.forEach { it.patient = patientPseudonym }
|
this.histologyReports.forEach { it.patient = patientPseudonym }
|
||||||
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 { it.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 }
|
||||||
|
@ -30,7 +30,6 @@ import dev.dnpm.etl.processor.pseudonym.PseudonymizeService
|
|||||||
import dev.dnpm.etl.processor.pseudonym.pseudonymizeWith
|
import dev.dnpm.etl.processor.pseudonym.pseudonymizeWith
|
||||||
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.slf4j.LoggerFactory
|
|
||||||
import org.springframework.context.ApplicationEventPublisher
|
import org.springframework.context.ApplicationEventPublisher
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
@ -45,8 +44,6 @@ class RequestProcessor(
|
|||||||
private val applicationEventPublisher: ApplicationEventPublisher
|
private val applicationEventPublisher: ApplicationEventPublisher
|
||||||
) {
|
) {
|
||||||
|
|
||||||
private val logger = LoggerFactory.getLogger(RequestProcessor::class.java)
|
|
||||||
|
|
||||||
fun processMtbFile(mtbFile: MtbFile) {
|
fun processMtbFile(mtbFile: MtbFile) {
|
||||||
val requestId = UUID.randomUUID().toString()
|
val requestId = UUID.randomUUID().toString()
|
||||||
val pid = mtbFile.patient.id
|
val pid = mtbFile.patient.id
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
package dev.dnpm.etl.processor.services
|
package dev.dnpm.etl.processor.services
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper
|
|
||||||
import dev.dnpm.etl.processor.monitoring.Report
|
import dev.dnpm.etl.processor.monitoring.Report
|
||||||
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
|
||||||
@ -33,8 +32,7 @@ import java.util.*
|
|||||||
@Service
|
@Service
|
||||||
class ResponseProcessor(
|
class ResponseProcessor(
|
||||||
private val requestRepository: RequestRepository,
|
private val requestRepository: RequestRepository,
|
||||||
private val statisticsUpdateProducer: Sinks.Many<Any>,
|
private val statisticsUpdateProducer: Sinks.Many<Any>
|
||||||
private val objectMapper: ObjectMapper
|
|
||||||
) {
|
) {
|
||||||
|
|
||||||
private val logger = LoggerFactory.getLogger(ResponseProcessor::class.java)
|
private val logger = LoggerFactory.getLogger(ResponseProcessor::class.java)
|
||||||
|
@ -83,9 +83,9 @@ class StatisticsRestController(
|
|||||||
.groupBy { formatter.format(it.processedAt) }
|
.groupBy { formatter.format(it.processedAt) }
|
||||||
.map {
|
.map {
|
||||||
val requestList = it.value
|
val requestList = it.value
|
||||||
.groupBy { it.status }
|
.groupBy { request -> request.status }
|
||||||
.map {
|
.map { request ->
|
||||||
Pair(it.key, it.value.size)
|
Pair(request.key, request.value.size)
|
||||||
}
|
}
|
||||||
.toMap()
|
.toMap()
|
||||||
Pair(
|
Pair(
|
||||||
|
@ -105,7 +105,7 @@ class RestMtbFileSenderTest {
|
|||||||
}
|
}
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
|
|
||||||
val mtbFile = MtbFile.builder()
|
val mtbFile: MtbFile = MtbFile.builder()
|
||||||
.withPatient(
|
.withPatient(
|
||||||
Patient.builder()
|
Patient.builder()
|
||||||
.withId("PID")
|
.withId("PID")
|
||||||
@ -129,7 +129,7 @@ class RestMtbFileSenderTest {
|
|||||||
)
|
)
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
private val errorResponseBody = "Sonstiger Fehler bei der Übertragung"
|
private const val ERROR_RESPONSE_BODY = "Sonstiger Fehler bei der Übertragung"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Synthetic http responses with related request status
|
* Synthetic http responses with related request status
|
||||||
@ -147,23 +147,23 @@ class RestMtbFileSenderTest {
|
|||||||
RequestWithResponse(
|
RequestWithResponse(
|
||||||
HttpStatus.BAD_REQUEST,
|
HttpStatus.BAD_REQUEST,
|
||||||
"??",
|
"??",
|
||||||
MtbFileSender.Response(RequestStatus.ERROR, errorResponseBody)
|
MtbFileSender.Response(RequestStatus.ERROR, ERROR_RESPONSE_BODY)
|
||||||
),
|
),
|
||||||
RequestWithResponse(
|
RequestWithResponse(
|
||||||
HttpStatus.UNPROCESSABLE_ENTITY,
|
HttpStatus.UNPROCESSABLE_ENTITY,
|
||||||
errorBody,
|
errorBody,
|
||||||
MtbFileSender.Response(RequestStatus.ERROR, errorResponseBody)
|
MtbFileSender.Response(RequestStatus.ERROR, ERROR_RESPONSE_BODY)
|
||||||
),
|
),
|
||||||
// Some more errors not mentioned in documentation
|
// Some more errors not mentioned in documentation
|
||||||
RequestWithResponse(
|
RequestWithResponse(
|
||||||
HttpStatus.NOT_FOUND,
|
HttpStatus.NOT_FOUND,
|
||||||
"what????",
|
"what????",
|
||||||
MtbFileSender.Response(RequestStatus.ERROR, errorResponseBody)
|
MtbFileSender.Response(RequestStatus.ERROR, ERROR_RESPONSE_BODY)
|
||||||
),
|
),
|
||||||
RequestWithResponse(
|
RequestWithResponse(
|
||||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||||
"what????",
|
"what????",
|
||||||
MtbFileSender.Response(RequestStatus.ERROR, errorResponseBody)
|
MtbFileSender.Response(RequestStatus.ERROR, ERROR_RESPONSE_BODY)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -180,12 +180,12 @@ class RestMtbFileSenderTest {
|
|||||||
RequestWithResponse(
|
RequestWithResponse(
|
||||||
HttpStatus.NOT_FOUND,
|
HttpStatus.NOT_FOUND,
|
||||||
"what????",
|
"what????",
|
||||||
MtbFileSender.Response(RequestStatus.ERROR, errorResponseBody)
|
MtbFileSender.Response(RequestStatus.ERROR, ERROR_RESPONSE_BODY)
|
||||||
),
|
),
|
||||||
RequestWithResponse(
|
RequestWithResponse(
|
||||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||||
"what????",
|
"what????",
|
||||||
MtbFileSender.Response(RequestStatus.ERROR, errorResponseBody)
|
MtbFileSender.Response(RequestStatus.ERROR, ERROR_RESPONSE_BODY)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -19,8 +19,6 @@
|
|||||||
|
|
||||||
package dev.dnpm.etl.processor.services
|
package dev.dnpm.etl.processor.services
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper
|
|
||||||
import com.fasterxml.jackson.module.kotlin.KotlinModule
|
|
||||||
import dev.dnpm.etl.processor.monitoring.Request
|
import dev.dnpm.etl.processor.monitoring.Request
|
||||||
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
|
||||||
@ -62,12 +60,10 @@ class ResponseProcessorTest {
|
|||||||
@Mock requestRepository: RequestRepository,
|
@Mock requestRepository: RequestRepository,
|
||||||
@Mock statisticsUpdateProducer: Sinks.Many<Any>
|
@Mock statisticsUpdateProducer: Sinks.Many<Any>
|
||||||
) {
|
) {
|
||||||
val objectMapper = ObjectMapper().registerModule(KotlinModule.Builder().build())
|
|
||||||
|
|
||||||
this.requestRepository = requestRepository
|
this.requestRepository = requestRepository
|
||||||
this.statisticsUpdateProducer = statisticsUpdateProducer
|
this.statisticsUpdateProducer = statisticsUpdateProducer
|
||||||
|
|
||||||
this.responseProcessor = ResponseProcessor(requestRepository, statisticsUpdateProducer, objectMapper)
|
this.responseProcessor = ResponseProcessor(requestRepository, statisticsUpdateProducer)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -45,7 +45,7 @@ class KafkaResponseProcessorTest {
|
|||||||
|
|
||||||
private lateinit var kafkaResponseProcessor: KafkaResponseProcessor
|
private lateinit var kafkaResponseProcessor: KafkaResponseProcessor
|
||||||
|
|
||||||
private fun createkafkaRecord(
|
private fun createKafkaRecord(
|
||||||
requestId: String? = null,
|
requestId: String? = null,
|
||||||
statusCode: Int = 200,
|
statusCode: Int = 200,
|
||||||
statusBody: Map<String, Any>? = mapOf()
|
statusBody: Map<String, Any>? = mapOf()
|
||||||
@ -79,14 +79,14 @@ class KafkaResponseProcessorTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun shouldNotProcessRecordsWithoutValidKey() {
|
fun shouldNotProcessRecordsWithoutValidKey() {
|
||||||
this.kafkaResponseProcessor.onMessage(createkafkaRecord(null, 200))
|
this.kafkaResponseProcessor.onMessage(createKafkaRecord(null, 200))
|
||||||
|
|
||||||
verify(eventPublisher, never()).publishEvent(any())
|
verify(eventPublisher, never()).publishEvent(any())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun shouldNotProcessRecordsWithoutValidBody() {
|
fun shouldNotProcessRecordsWithoutValidBody() {
|
||||||
this.kafkaResponseProcessor.onMessage(createkafkaRecord(requestId = "TestID1234", statusBody = null))
|
this.kafkaResponseProcessor.onMessage(createKafkaRecord(requestId = "TestID1234", statusBody = null))
|
||||||
|
|
||||||
verify(eventPublisher, never()).publishEvent(any())
|
verify(eventPublisher, never()).publishEvent(any())
|
||||||
}
|
}
|
||||||
@ -94,7 +94,7 @@ class KafkaResponseProcessorTest {
|
|||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("statusCodeSource")
|
@MethodSource("statusCodeSource")
|
||||||
fun shouldProcessValidRecordsWithStatusCode(statusCode: Int) {
|
fun shouldProcessValidRecordsWithStatusCode(statusCode: Int) {
|
||||||
this.kafkaResponseProcessor.onMessage(createkafkaRecord("TestID1234", statusCode))
|
this.kafkaResponseProcessor.onMessage(createKafkaRecord("TestID1234", statusCode))
|
||||||
verify(eventPublisher, times(1)).publishEvent(any<ResponseEvent>())
|
verify(eventPublisher, times(1)).publishEvent(any<ResponseEvent>())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user