Skip to content

Commit

Permalink
Merge pull request #473 from medizininformatik-initiative/472-extract…
Browse files Browse the repository at this point in the history
…-common-agent-configuration

Extract Common Agent Configuration
  • Loading branch information
knoppiks authored Dec 11, 2024
2 parents ec90e88 + 416dab0 commit 1cd7b2d
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 125 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
package care.smith.fts.cda;

import static java.time.Duration.ofSeconds;

import ca.uhn.fhir.context.FhirContext;
import care.smith.fts.util.CustomErrorHandler;
import care.smith.fts.util.FhirCodecConfiguration;
import care.smith.fts.util.MetricsConfig;
import care.smith.fts.util.WebClientDefaults;
import care.smith.fts.util.WebClientFactory;
import care.smith.fts.util.auth.HttpServerAuthConfig;
import care.smith.fts.util.AgentConfiguration;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import java.net.http.HttpClient;
import java.nio.file.Path;
import java.nio.file.Paths;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -23,41 +14,17 @@
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Primary;

@Slf4j
@SpringBootApplication
@ConfigurationPropertiesScan
@Import({
WebClientDefaults.class,
FhirCodecConfiguration.class,
MetricsConfig.class,
HttpServerAuthConfig.class,
CustomErrorHandler.class,
WebClientFactory.class,
})
@Import(AgentConfiguration.class)
public class ClinicalDomainAgent {

public static void main(String... args) {
SpringApplication.run(ClinicalDomainAgent.class, args);
}

@Bean
public FhirContext fhirContext() {
return FhirContext.forR4();
}

@Bean
public HttpClient httpClient() {
return HttpClient.newBuilder().connectTimeout(ofSeconds(10)).build();
}

@Bean
@Primary
public ObjectMapper defaultObjectMapper() {
return new ObjectMapper().registerModule(new JavaTimeModule());
}

@Bean
public ObjectMapper transferProcessObjectMapper() {
return new ObjectMapper(new YAMLFactory())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
package care.smith.fts.rda;

import static java.time.Duration.ofSeconds;

import ca.uhn.fhir.context.FhirContext;
import care.smith.fts.util.CustomErrorHandler;
import care.smith.fts.util.FhirCodecConfiguration;
import care.smith.fts.util.MetricsConfig;
import care.smith.fts.util.WebClientDefaults;
import care.smith.fts.util.WebClientFactory;
import care.smith.fts.util.auth.HttpServerAuthConfig;
import care.smith.fts.util.AgentConfiguration;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import java.net.http.HttpClient;
import java.nio.file.Path;
import java.nio.file.Paths;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -23,41 +14,17 @@
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Primary;

@Slf4j
@SpringBootApplication
@ConfigurationPropertiesScan
@Import({
WebClientDefaults.class,
FhirCodecConfiguration.class,
MetricsConfig.class,
HttpServerAuthConfig.class,
CustomErrorHandler.class,
WebClientFactory.class,
})
@Import(AgentConfiguration.class)
public class ResearchDomainAgent {

public static void main(String... args) {
SpringApplication.run(ResearchDomainAgent.class, args);
}

@Bean
public FhirContext fhirContext() {
return FhirContext.forR4();
}

@Bean
public HttpClient httpClient() {
return HttpClient.newBuilder().connectTimeout(ofSeconds(10)).build();
}

@Bean
@Primary
public ObjectMapper defaultObjectMapper() {
return new ObjectMapper().registerModule(new JavaTimeModule());
}

@Bean
public ObjectMapper transferProcessObjectMapper() {
return new ObjectMapper(new YAMLFactory())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,55 +1,19 @@
package care.smith.fts.tca;

import static java.time.Duration.ofSeconds;

import ca.uhn.fhir.context.FhirContext;
import care.smith.fts.util.CustomErrorHandler;
import care.smith.fts.util.FhirCodecConfiguration;
import care.smith.fts.util.MetricsConfig;
import care.smith.fts.util.WebClientDefaults;
import care.smith.fts.util.WebClientFactory;
import care.smith.fts.util.auth.HttpServerAuthConfig;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import java.net.http.HttpClient;
import care.smith.fts.util.AgentConfiguration;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Primary;

@Slf4j
@SpringBootApplication
@ConfigurationPropertiesScan
@Import({
WebClientDefaults.class,
FhirCodecConfiguration.class,
MetricsConfig.class,
HttpServerAuthConfig.class,
CustomErrorHandler.class,
WebClientFactory.class,
})
@Import(AgentConfiguration.class)
public class TrustCenterAgent {

public static void main(String... args) {
SpringApplication.run(TrustCenterAgent.class, args);
}

@Bean
public FhirContext fhirContext() {
return FhirContext.forR4();
}

@Bean
public HttpClient httpClient() {
return HttpClient.newBuilder().connectTimeout(ofSeconds(10)).build();
}

@Bean
@Primary
public ObjectMapper defaultObjectMapper() {
return new ObjectMapper().registerModule(new JavaTimeModule());
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package care.smith.fts.tca.deidentification.configuration;

import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
Expand All @@ -13,7 +13,7 @@
@Slf4j
@Configuration
@ConfigurationProperties("de-identification")
@Data
@Setter
public class DeIdentificationConfiguration {
@NotBlank String keystoreUrl;

Expand Down
41 changes: 41 additions & 0 deletions util/src/main/java/care/smith/fts/util/AgentConfiguration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package care.smith.fts.util;

import static java.time.Duration.ofSeconds;

import ca.uhn.fhir.context.FhirContext;
import care.smith.fts.util.auth.HttpServerAuthConfig;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import java.net.http.HttpClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Primary;

@Configuration
@Import({
WebClientDefaults.class,
FhirCodecConfiguration.class,
MetricsConfig.class,
HttpServerAuthConfig.class,
CustomErrorHandler.class,
WebClientFactory.class,
})
public class AgentConfiguration {

@Bean
public FhirContext fhirContext() {
return FhirContext.forR4();
}

@Bean
public HttpClient httpClient() {
return HttpClient.newBuilder().connectTimeout(ofSeconds(10)).build();
}

@Bean
@Primary
public ObjectMapper defaultObjectMapper() {
return new ObjectMapper().registerModule(new JavaTimeModule());
}
}
2 changes: 0 additions & 2 deletions util/src/main/java/care/smith/fts/util/MetricsConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import io.micrometer.core.instrument.Tag;
import io.micrometer.core.instrument.config.MeterFilter;
import java.util.Arrays;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer;
import org.springframework.boot.context.properties.ConfigurationProperties;
Expand All @@ -15,7 +14,6 @@
@Slf4j
@Configuration
@ConfigurationProperties(prefix = "management.metrics.distribution")
@Data
public class MetricsConfig {

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.Objects;
import java.util.stream.Stream;
import lombok.Data;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
Expand All @@ -17,7 +18,7 @@
@Slf4j
@EnableWebFluxSecurity
@ConfigurationProperties(prefix = "security")
@Data
@Setter
public class HttpServerAuthConfig {

private AuthMethod auth = HttpServerAuthMethod.NONE;
Expand Down
18 changes: 6 additions & 12 deletions util/src/test/java/care/smith/fts/util/WebServerFhirCodecTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@

@Slf4j
@SpringBootTest(
classes = {FhirCodecConfiguration.class, WebServerFhirCodecTest.Config.class, HttpServerAuthConfig.class},
classes = {
FhirCodecConfiguration.class,
WebServerFhirCodecTest.Config.class,
HttpServerAuthConfig.class
},
webEnvironment = RANDOM_PORT)
public class WebServerFhirCodecTest {

Expand Down Expand Up @@ -164,17 +168,7 @@ Mono<ResponseEntity<Bundle>> responseBundle(@RequestBody Mono<Bundle> body) {

@SpringBootApplication
@Import({WebServerFhirCodecTest.Controller.class, FhirCodecConfiguration.class})
public static class Config {
@Bean
FhirContext fhirContext() {
return forR4();
}

@Bean
public HttpClient httpClient() {
return HttpClient.newBuilder().connectTimeout(ofSeconds(10)).build();
}
}
public static class Config {}

private ResponseSpec getRequest(String path) {
return webClient
Expand Down

0 comments on commit 1cd7b2d

Please sign in to comment.