summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul-Christian Volkmer2023-10-05 11:37:10 +0200
committerPaul-Christian Volkmer2023-10-05 11:37:10 +0200
commit1e1db1c4d9cf0810056287c8895b1662c16daf2c (patch)
treebbd549713026fb537c95ddcfc5420b777d46da8c
parent7440fe1e23e730fd526a814cfde7cc86e105cf70 (diff)
Issue #12: Add application config for transformation configuration
-rw-r--r--src/integrationTest/kotlin/dev/dnpm/etl/processor/config/AppConfigurationTest.kt29
-rw-r--r--src/main/kotlin/dev/dnpm/etl/processor/config/AppConfigProperties.kt11
-rw-r--r--src/main/kotlin/dev/dnpm/etl/processor/config/AppConfiguration.kt8
-rw-r--r--src/main/kotlin/dev/dnpm/etl/processor/services/TransformationService.kt19
-rw-r--r--src/test/kotlin/dev/dnpm/etl/processor/services/TransformationServiceTest.kt19
5 files changed, 78 insertions, 8 deletions
diff --git a/src/integrationTest/kotlin/dev/dnpm/etl/processor/config/AppConfigurationTest.kt b/src/integrationTest/kotlin/dev/dnpm/etl/processor/config/AppConfigurationTest.kt
index 8bdaa60..99a5c72 100644
--- a/src/integrationTest/kotlin/dev/dnpm/etl/processor/config/AppConfigurationTest.kt
+++ b/src/integrationTest/kotlin/dev/dnpm/etl/processor/config/AppConfigurationTest.kt
@@ -31,13 +31,13 @@ import org.springframework.beans.factory.NoSuchBeanDefinitionException
import org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration
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.test.context.ContextConfiguration
import org.springframework.test.context.TestPropertySource
@SpringBootTest
-@ContextConfiguration(classes = [KafkaAutoConfiguration::class, AppKafkaConfiguration::class, AppRestConfiguration::class])
+@ContextConfiguration(classes = [AppConfiguration::class, KafkaAutoConfiguration::class, AppKafkaConfiguration::class, AppRestConfiguration::class])
+@MockBean(ObjectMapper::class)
class AppConfigurationTest {
@Nested
@@ -65,10 +65,7 @@ class AppConfigurationTest {
"app.kafka.group-id=test"
]
)
- @MockBeans(value = [
- MockBean(ObjectMapper::class),
- MockBean(RequestRepository::class)
- ])
+ @MockBean(RequestRepository::class)
inner class AppConfigurationKafkaTest(private val context: ApplicationContext) {
@Test
@@ -99,4 +96,24 @@ class AppConfigurationTest {
}
+ @Nested
+ @TestPropertySource(
+ properties = [
+ "app.transformations[0].path=consent.status",
+ "app.transformations[0].from=rejected",
+ "app.transformations[0].to=accept",
+ ]
+ )
+ inner class AppConfigurationTransformationTest(private val context: ApplicationContext) {
+
+ @Test
+ fun shouldRecognizeTransformations() {
+ val appConfigProperties = context.getBean(AppConfigProperties::class.java)
+
+ assertThat(appConfigProperties).isNotNull
+ assertThat(appConfigProperties.transformations).hasSize(1)
+ }
+
+ }
+
} \ No newline at end of file
diff --git a/src/main/kotlin/dev/dnpm/etl/processor/config/AppConfigProperties.kt b/src/main/kotlin/dev/dnpm/etl/processor/config/AppConfigProperties.kt
index 06e730b..6b85603 100644
--- a/src/main/kotlin/dev/dnpm/etl/processor/config/AppConfigProperties.kt
+++ b/src/main/kotlin/dev/dnpm/etl/processor/config/AppConfigProperties.kt
@@ -24,7 +24,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties
@ConfigurationProperties(AppConfigProperties.NAME)
data class AppConfigProperties(
var bwhcUri: String?,
- var generator: PseudonymGenerator = PseudonymGenerator.BUILDIN
+ var generator: PseudonymGenerator = PseudonymGenerator.BUILDIN,
+ var transformations: List<TransformationProperties> = listOf()
) {
companion object {
const val NAME = "app"
@@ -78,4 +79,10 @@ data class KafkaTargetProperties(
enum class PseudonymGenerator {
BUILDIN,
GPAS
-} \ No newline at end of file
+}
+
+data class TransformationProperties(
+ val path: String,
+ val from: String,
+ val to: String
+) \ No newline at end of file
diff --git a/src/main/kotlin/dev/dnpm/etl/processor/config/AppConfiguration.kt b/src/main/kotlin/dev/dnpm/etl/processor/config/AppConfiguration.kt
index 6b15fc0..ccc4b78 100644
--- a/src/main/kotlin/dev/dnpm/etl/processor/config/AppConfiguration.kt
+++ b/src/main/kotlin/dev/dnpm/etl/processor/config/AppConfiguration.kt
@@ -25,6 +25,7 @@ import dev.dnpm.etl.processor.pseudonym.AnonymizingGenerator
import dev.dnpm.etl.processor.pseudonym.Generator
import dev.dnpm.etl.processor.pseudonym.GpasPseudonymGenerator
import dev.dnpm.etl.processor.pseudonym.PseudonymizeService
+import dev.dnpm.etl.processor.services.Transformation
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.context.annotation.Bean
@@ -71,5 +72,12 @@ class AppConfiguration {
return Sinks.many().multicast().directBestEffort()
}
+ @Bean
+ fun transformations(configProperties: AppConfigProperties): List<Transformation> {
+ return configProperties.transformations.map {
+ Transformation.of(it.path) from it.from to it.to
+ }
+ }
+
}
diff --git a/src/main/kotlin/dev/dnpm/etl/processor/services/TransformationService.kt b/src/main/kotlin/dev/dnpm/etl/processor/services/TransformationService.kt
index 9be0216..f33900d 100644
--- a/src/main/kotlin/dev/dnpm/etl/processor/services/TransformationService.kt
+++ b/src/main/kotlin/dev/dnpm/etl/processor/services/TransformationService.kt
@@ -1,3 +1,22 @@
+/*
+ * This file is part of ETL-Processor
+ *
+ * Copyright (c) 2023 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.services
import com.fasterxml.jackson.databind.ObjectMapper
diff --git a/src/test/kotlin/dev/dnpm/etl/processor/services/TransformationServiceTest.kt b/src/test/kotlin/dev/dnpm/etl/processor/services/TransformationServiceTest.kt
index c6cd645..5b34562 100644
--- a/src/test/kotlin/dev/dnpm/etl/processor/services/TransformationServiceTest.kt
+++ b/src/test/kotlin/dev/dnpm/etl/processor/services/TransformationServiceTest.kt
@@ -1,3 +1,22 @@
+/*
+ * This file is part of ETL-Processor
+ *
+ * Copyright (c) 2023 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.services
import com.fasterxml.jackson.databind.ObjectMapper