mirror of
https://github.com/pcvolkmer/etl-processor.git
synced 2025-07-04 07:22:55 +00:00
refactor: use Fingerprint type instead of plain String
This commit is contained in:
@ -44,6 +44,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import org.springframework.data.jdbc.repository.config.AbstractJdbcConfiguration
|
||||
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory
|
||||
import org.springframework.retry.RetryCallback
|
||||
import org.springframework.retry.RetryContext
|
||||
@ -274,5 +275,9 @@ class AppConfiguration {
|
||||
return GPasConnectionCheckService(restTemplate, gPasConfigProperties, connectionCheckUpdateProducer)
|
||||
}
|
||||
|
||||
@Bean
|
||||
fun jdbcConfiguration(): AbstractJdbcConfiguration {
|
||||
return AppJdbcConfiguration()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,25 @@
|
||||
package dev.dnpm.etl.processor.config
|
||||
|
||||
import dev.dnpm.etl.processor.Fingerprint
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import org.springframework.core.convert.converter.Converter
|
||||
import org.springframework.data.jdbc.repository.config.AbstractJdbcConfiguration
|
||||
|
||||
@Configuration
|
||||
class AppJdbcConfiguration : AbstractJdbcConfiguration() {
|
||||
override fun userConverters(): MutableList<*> {
|
||||
return mutableListOf(StringToFingerprintConverter(), FingerprintToStringConverter())
|
||||
}
|
||||
}
|
||||
|
||||
class StringToFingerprintConverter : Converter<String, Fingerprint> {
|
||||
override fun convert(source: String): Fingerprint {
|
||||
return Fingerprint(source)
|
||||
}
|
||||
}
|
||||
|
||||
class FingerprintToStringConverter : Converter<Fingerprint, String> {
|
||||
override fun convert(source: Fingerprint): String {
|
||||
return source.value
|
||||
}
|
||||
}
|
@ -19,10 +19,12 @@
|
||||
|
||||
package dev.dnpm.etl.processor.monitoring
|
||||
|
||||
import dev.dnpm.etl.processor.Fingerprint
|
||||
import org.springframework.data.annotation.Id
|
||||
import org.springframework.data.domain.Page
|
||||
import org.springframework.data.domain.Pageable
|
||||
import org.springframework.data.jdbc.repository.query.Query
|
||||
import org.springframework.data.relational.core.mapping.Column
|
||||
import org.springframework.data.relational.core.mapping.Embedded
|
||||
import org.springframework.data.relational.core.mapping.Table
|
||||
import org.springframework.data.repository.CrudRepository
|
||||
@ -38,7 +40,8 @@ data class Request(
|
||||
val uuid: String = RequestId.randomUUID().toString(),
|
||||
val patientId: String,
|
||||
val pid: String,
|
||||
val fingerprint: String,
|
||||
@Column("fingerprint")
|
||||
val fingerprint: Fingerprint,
|
||||
val type: RequestType,
|
||||
var status: RequestStatus,
|
||||
var processedAt: Instant = Instant.now(),
|
||||
@ -48,7 +51,7 @@ data class Request(
|
||||
uuid: String,
|
||||
patientId: String,
|
||||
pid: String,
|
||||
fingerprint: String,
|
||||
fingerprint: Fingerprint,
|
||||
type: RequestType,
|
||||
status: RequestStatus
|
||||
) :
|
||||
@ -58,7 +61,7 @@ data class Request(
|
||||
uuid: String,
|
||||
patientId: String,
|
||||
pid: String,
|
||||
fingerprint: String,
|
||||
fingerprint: Fingerprint,
|
||||
type: RequestType,
|
||||
status: RequestStatus,
|
||||
processedAt: Instant
|
||||
|
@ -21,6 +21,7 @@ package dev.dnpm.etl.processor.services
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import de.ukw.ccc.bwhc.dto.MtbFile
|
||||
import dev.dnpm.etl.processor.Fingerprint
|
||||
import dev.dnpm.etl.processor.config.AppConfigProperties
|
||||
import dev.dnpm.etl.processor.monitoring.Report
|
||||
import dev.dnpm.etl.processor.monitoring.Request
|
||||
@ -146,7 +147,7 @@ class RequestProcessor(
|
||||
uuid = requestId,
|
||||
patientId = "???",
|
||||
pid = patientId,
|
||||
fingerprint = "",
|
||||
fingerprint = Fingerprint.empty(),
|
||||
status = RequestStatus.ERROR,
|
||||
type = RequestType.DELETE,
|
||||
report = Report("Fehler bei der Pseudonymisierung")
|
||||
@ -155,14 +156,16 @@ class RequestProcessor(
|
||||
}
|
||||
}
|
||||
|
||||
private fun fingerprint(mtbFile: MtbFile): String {
|
||||
private fun fingerprint(mtbFile: MtbFile): Fingerprint {
|
||||
return fingerprint(objectMapper.writeValueAsString(mtbFile))
|
||||
}
|
||||
|
||||
private fun fingerprint(s: String): String {
|
||||
return Base32().encodeAsString(DigestUtils.sha256(s))
|
||||
.replace("=", "")
|
||||
.lowercase()
|
||||
private fun fingerprint(s: String): Fingerprint {
|
||||
return Fingerprint(
|
||||
Base32().encodeAsString(DigestUtils.sha256(s))
|
||||
.replace("=", "")
|
||||
.lowercase()
|
||||
)
|
||||
}
|
||||
|
||||
}
|
11
src/main/kotlin/dev/dnpm/etl/processor/types.kt
Normal file
11
src/main/kotlin/dev/dnpm/etl/processor/types.kt
Normal file
@ -0,0 +1,11 @@
|
||||
package dev.dnpm.etl.processor
|
||||
|
||||
class Fingerprint(val value: String) {
|
||||
override fun hashCode() = value.hashCode()
|
||||
|
||||
override fun equals(other: Any?) = other is Fingerprint && other.value == value
|
||||
|
||||
companion object {
|
||||
fun empty() = Fingerprint("")
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user