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
|
||||
|
||||
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.extension.ExtendWith
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.context.SpringBootTest
|
||||
import org.springframework.boot.test.mock.mockito.MockBean
|
||||
import org.springframework.context.ApplicationContext
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension
|
||||
import org.testcontainers.junit.jupiter.Testcontainers
|
||||
|
||||
@ -34,7 +37,9 @@ import org.testcontainers.junit.jupiter.Testcontainers
|
||||
class EtlProcessorApplicationTests : AbstractTestcontainerTest() {
|
||||
|
||||
@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 {
|
||||
|
||||
private final static FhirContext r4Context = FhirContext.forR4();
|
||||
private final String gPasUrl;
|
||||
private final String psnTargetDomain;
|
||||
private static FhirContext r4Context = FhirContext.forR4();
|
||||
private final HttpHeaders httpHeader;
|
||||
|
||||
private final RetryTemplate retryTemplate = defaultTemplate();
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(GpasPseudonymGenerator.class);
|
||||
|
||||
private SSLContext customSslContext;
|
||||
|
@ -23,7 +23,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties
|
||||
|
||||
@ConfigurationProperties(AppConfigProperties.NAME)
|
||||
data class AppConfigProperties(
|
||||
var bwhc_uri: String?,
|
||||
var bwhcUri: String?,
|
||||
var generator: PseudonymGenerator = PseudonymGenerator.BUILDIN
|
||||
) {
|
||||
companion object {
|
||||
|
@ -38,7 +38,7 @@ infix fun MtbFile.pseudonymizeWith(pseudonymizeService: PseudonymizeService) {
|
||||
this.histologyReports.forEach { it.patient = patientPseudonym }
|
||||
this.lastGuidelineTherapies.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.previousGuidelineTherapies.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 org.apache.commons.codec.binary.Base32
|
||||
import org.apache.commons.codec.digest.DigestUtils
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.context.ApplicationEventPublisher
|
||||
import org.springframework.stereotype.Service
|
||||
import java.time.Instant
|
||||
@ -45,8 +44,6 @@ class RequestProcessor(
|
||||
private val applicationEventPublisher: ApplicationEventPublisher
|
||||
) {
|
||||
|
||||
private val logger = LoggerFactory.getLogger(RequestProcessor::class.java)
|
||||
|
||||
fun processMtbFile(mtbFile: MtbFile) {
|
||||
val requestId = UUID.randomUUID().toString()
|
||||
val pid = mtbFile.patient.id
|
||||
|
@ -19,7 +19,6 @@
|
||||
|
||||
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.RequestRepository
|
||||
import dev.dnpm.etl.processor.monitoring.RequestStatus
|
||||
@ -33,8 +32,7 @@ import java.util.*
|
||||
@Service
|
||||
class ResponseProcessor(
|
||||
private val requestRepository: RequestRepository,
|
||||
private val statisticsUpdateProducer: Sinks.Many<Any>,
|
||||
private val objectMapper: ObjectMapper
|
||||
private val statisticsUpdateProducer: Sinks.Many<Any>
|
||||
) {
|
||||
|
||||
private val logger = LoggerFactory.getLogger(ResponseProcessor::class.java)
|
||||
|
@ -83,9 +83,9 @@ class StatisticsRestController(
|
||||
.groupBy { formatter.format(it.processedAt) }
|
||||
.map {
|
||||
val requestList = it.value
|
||||
.groupBy { it.status }
|
||||
.map {
|
||||
Pair(it.key, it.value.size)
|
||||
.groupBy { request -> request.status }
|
||||
.map { request ->
|
||||
Pair(request.key, request.value.size)
|
||||
}
|
||||
.toMap()
|
||||
Pair(
|
||||
|
@ -105,7 +105,7 @@ class RestMtbFileSenderTest {
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
val mtbFile = MtbFile.builder()
|
||||
val mtbFile: MtbFile = MtbFile.builder()
|
||||
.withPatient(
|
||||
Patient.builder()
|
||||
.withId("PID")
|
||||
@ -129,7 +129,7 @@ class RestMtbFileSenderTest {
|
||||
)
|
||||
.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
|
||||
@ -147,23 +147,23 @@ class RestMtbFileSenderTest {
|
||||
RequestWithResponse(
|
||||
HttpStatus.BAD_REQUEST,
|
||||
"??",
|
||||
MtbFileSender.Response(RequestStatus.ERROR, errorResponseBody)
|
||||
MtbFileSender.Response(RequestStatus.ERROR, ERROR_RESPONSE_BODY)
|
||||
),
|
||||
RequestWithResponse(
|
||||
HttpStatus.UNPROCESSABLE_ENTITY,
|
||||
errorBody,
|
||||
MtbFileSender.Response(RequestStatus.ERROR, errorResponseBody)
|
||||
MtbFileSender.Response(RequestStatus.ERROR, ERROR_RESPONSE_BODY)
|
||||
),
|
||||
// Some more errors not mentioned in documentation
|
||||
RequestWithResponse(
|
||||
HttpStatus.NOT_FOUND,
|
||||
"what????",
|
||||
MtbFileSender.Response(RequestStatus.ERROR, errorResponseBody)
|
||||
MtbFileSender.Response(RequestStatus.ERROR, ERROR_RESPONSE_BODY)
|
||||
),
|
||||
RequestWithResponse(
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
"what????",
|
||||
MtbFileSender.Response(RequestStatus.ERROR, errorResponseBody)
|
||||
MtbFileSender.Response(RequestStatus.ERROR, ERROR_RESPONSE_BODY)
|
||||
)
|
||||
)
|
||||
}
|
||||
@ -180,12 +180,12 @@ class RestMtbFileSenderTest {
|
||||
RequestWithResponse(
|
||||
HttpStatus.NOT_FOUND,
|
||||
"what????",
|
||||
MtbFileSender.Response(RequestStatus.ERROR, errorResponseBody)
|
||||
MtbFileSender.Response(RequestStatus.ERROR, ERROR_RESPONSE_BODY)
|
||||
),
|
||||
RequestWithResponse(
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
"what????",
|
||||
MtbFileSender.Response(RequestStatus.ERROR, errorResponseBody)
|
||||
MtbFileSender.Response(RequestStatus.ERROR, ERROR_RESPONSE_BODY)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
@ -19,8 +19,6 @@
|
||||
|
||||
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.RequestRepository
|
||||
import dev.dnpm.etl.processor.monitoring.RequestStatus
|
||||
@ -62,12 +60,10 @@ class ResponseProcessorTest {
|
||||
@Mock requestRepository: RequestRepository,
|
||||
@Mock statisticsUpdateProducer: Sinks.Many<Any>
|
||||
) {
|
||||
val objectMapper = ObjectMapper().registerModule(KotlinModule.Builder().build())
|
||||
|
||||
this.requestRepository = requestRepository
|
||||
this.statisticsUpdateProducer = statisticsUpdateProducer
|
||||
|
||||
this.responseProcessor = ResponseProcessor(requestRepository, statisticsUpdateProducer, objectMapper)
|
||||
this.responseProcessor = ResponseProcessor(requestRepository, statisticsUpdateProducer)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -45,7 +45,7 @@ class KafkaResponseProcessorTest {
|
||||
|
||||
private lateinit var kafkaResponseProcessor: KafkaResponseProcessor
|
||||
|
||||
private fun createkafkaRecord(
|
||||
private fun createKafkaRecord(
|
||||
requestId: String? = null,
|
||||
statusCode: Int = 200,
|
||||
statusBody: Map<String, Any>? = mapOf()
|
||||
@ -79,14 +79,14 @@ class KafkaResponseProcessorTest {
|
||||
|
||||
@Test
|
||||
fun shouldNotProcessRecordsWithoutValidKey() {
|
||||
this.kafkaResponseProcessor.onMessage(createkafkaRecord(null, 200))
|
||||
this.kafkaResponseProcessor.onMessage(createKafkaRecord(null, 200))
|
||||
|
||||
verify(eventPublisher, never()).publishEvent(any())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun shouldNotProcessRecordsWithoutValidBody() {
|
||||
this.kafkaResponseProcessor.onMessage(createkafkaRecord(requestId = "TestID1234", statusBody = null))
|
||||
this.kafkaResponseProcessor.onMessage(createKafkaRecord(requestId = "TestID1234", statusBody = null))
|
||||
|
||||
verify(eventPublisher, never()).publishEvent(any())
|
||||
}
|
||||
@ -94,7 +94,7 @@ class KafkaResponseProcessorTest {
|
||||
@ParameterizedTest
|
||||
@MethodSource("statusCodeSource")
|
||||
fun shouldProcessValidRecordsWithStatusCode(statusCode: Int) {
|
||||
this.kafkaResponseProcessor.onMessage(createkafkaRecord("TestID1234", statusCode))
|
||||
this.kafkaResponseProcessor.onMessage(createKafkaRecord("TestID1234", statusCode))
|
||||
verify(eventPublisher, times(1)).publishEvent(any<ResponseEvent>())
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user