Merge pull request #177 from jvitrifork/spring-pr

Ease setting environment configuration values
This commit is contained in:
James Agnew
2020-12-04 17:11:24 -05:00
committed by GitHub
4 changed files with 35 additions and 42 deletions

View File

@@ -7,8 +7,10 @@ import ca.uhn.fhir.rest.api.EncodingEnum;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import org.hl7.fhir.r4.model.Bundle; import org.hl7.fhir.r4.model.Bundle;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
@@ -55,12 +57,12 @@ public class AppProperties {
private Boolean narrative_enabled = true; private Boolean narrative_enabled = true;
private Validation validation = new Validation(); private Validation validation = new Validation();
private List<Tester> tester = ImmutableList.of(new Tester()); private Map<String, Tester> tester = ImmutableMap.of("home", new Tester());
private Logger logger = new Logger(); private Logger logger = new Logger();
private Subscription subscription = new Subscription(); private Subscription subscription = new Subscription();
private Cors cors = null; private Cors cors = null;
private Partitioning partitioning = null; private Partitioning partitioning = null;
private List<ImplementationGuide> implementationGuides = null; private Map<String, ImplementationGuide> implementationGuides = null;
private Boolean lastn_enabled = false; private Boolean lastn_enabled = false;
@@ -72,11 +74,11 @@ public class AppProperties {
this.defer_indexing_for_codesystems_of_size = defer_indexing_for_codesystems_of_size; this.defer_indexing_for_codesystems_of_size = defer_indexing_for_codesystems_of_size;
} }
public List<ImplementationGuide> getImplementationGuides() { public Map<String, ImplementationGuide> getImplementationGuides() {
return implementationGuides; return implementationGuides;
} }
public void setImplementationGuides(List<ImplementationGuide> implementationGuides) { public void setImplementationGuides(Map<String, ImplementationGuide> implementationGuides) {
this.implementationGuides = implementationGuides; this.implementationGuides = implementationGuides;
} }
@@ -366,11 +368,11 @@ public class AppProperties {
this.reuse_cached_search_results_millis = reuse_cached_search_results_millis; this.reuse_cached_search_results_millis = reuse_cached_search_results_millis;
} }
public List<Tester> getTester() { public Map<String, Tester> getTester() {
return tester; return tester;
} }
public void setTester(List<Tester> tester) { public void setTester(Map<String, Tester> tester) {
this.tester = tester; this.tester = tester;
} }
@@ -458,7 +460,6 @@ public class AppProperties {
public static class Tester { public static class Tester {
private String id = "home";
private String name = "Local Tester"; private String name = "Local Tester";
private String server_address = "http://localhost:8080/fhir"; private String server_address = "http://localhost:8080/fhir";
private Boolean refuse_to_fetch_third_party_urls = true; private Boolean refuse_to_fetch_third_party_urls = true;
@@ -472,14 +473,6 @@ public class AppProperties {
this.fhir_version = fhir_version; this.fhir_version = fhir_version;
} }
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() { public String getName() {
return name; return name;
} }

View File

@@ -40,10 +40,7 @@ import org.springframework.http.HttpHeaders;
import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.CorsConfiguration;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import java.util.Arrays; import java.util.*;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class BaseJpaRestfulServer extends RestfulServer { public class BaseJpaRestfulServer extends RestfulServer {
@@ -351,12 +348,12 @@ public class BaseJpaRestfulServer extends RestfulServer {
} }
if (appProperties.getImplementationGuides() != null) { if (appProperties.getImplementationGuides() != null) {
List<AppProperties.ImplementationGuide> guides = appProperties.getImplementationGuides(); Map<String, AppProperties.ImplementationGuide> guides = appProperties.getImplementationGuides();
for (AppProperties.ImplementationGuide guide : guides) { for (Map.Entry<String, AppProperties.ImplementationGuide> guide : guides.entrySet()) {
packageInstallerSvc.install(new PackageInstallationSpec() packageInstallerSvc.install(new PackageInstallationSpec()
.setPackageUrl(guide.getUrl()) .setPackageUrl(guide.getValue().getUrl())
.setName(guide.getName()) .setName(guide.getValue().getName())
.setVersion(guide.getVersion()) .setVersion(guide.getValue().getVersion())
.setInstallMode(PackageInstallationSpec.InstallModeEnum.STORE_AND_INSTALL)); .setInstallMode(PackageInstallationSpec.InstallModeEnum.STORE_AND_INSTALL));
} }
} }

View File

@@ -36,15 +36,15 @@ public class FhirTesterConfig {
@Bean @Bean
public TesterConfig testerConfig(AppProperties appProperties) { public TesterConfig testerConfig(AppProperties appProperties) {
TesterConfig retVal = new TesterConfig(); TesterConfig retVal = new TesterConfig();
appProperties.getTester().stream().forEach(t -> { appProperties.getTester().entrySet().stream().forEach(t -> {
retVal retVal
.addServer() .addServer()
.withId(t.getId()) .withId(t.getKey())
.withFhirVersion(t.getFhir_version()) .withFhirVersion(t.getValue().getFhir_version())
.withBaseUrl(t.getServer_address()) .withBaseUrl(t.getValue().getServer_address())
.withName(t.getName()); .withName(t.getValue().getName());
retVal.setRefuseToFetchThirdPartyUrls( retVal.setRefuseToFetchThirdPartyUrls(
t.getRefuse_to_fetch_third_party_urls()); t.getValue().getRefuse_to_fetch_third_party_urls());
}); });
return retVal; return retVal;

View File

@@ -1,6 +1,7 @@
spring: spring:
datasource: datasource:
url: 'jdbc:h2:file:./target/database/h2' url: 'jdbc:h2:file:./target/database/h2'
#url: jdbc:h2:mem:test_mem
username: sa username: sa
password: null password: null
driverClassName: org.h2.Driver driverClassName: org.h2.Driver
@@ -33,13 +34,15 @@ hapi:
fhir_version: R4 fhir_version: R4
# defer_indexing_for_codesystems_of_size: 101 # defer_indexing_for_codesystems_of_size: 101
#implementationguides: #implementationguides:
# - #example from registry (packages.fhir.org)
# url: https://build.fhir.org/ig/hl7dk/dk-medcom/branches/corrections/package.tgz #swiss:
# name: dk.fhir.ig.medcom-core #name: swiss.mednet.fhir
#version: 0.8.0 #version: 0.8.0
# - #example not from registry
#ips_1_0_0:
#url: https://build.fhir.org/ig/HL7/fhir-ips/package.tgz
#name: hl7.fhir.uv.ips #name: hl7.fhir.uv.ips
# version: 0.3.0 #version: 1.0.0
#supported_resource_types: #supported_resource_types:
# - Patient # - Patient
@@ -89,14 +92,14 @@ hapi:
# retain_cached_searches_mins: 60 # retain_cached_searches_mins: 60
# reuse_cached_search_results_millis: 60000 # reuse_cached_search_results_millis: 60000
tester: tester:
-
id: home home:
name: Local Tester name: Local Tester
server_address: 'http://localhost:8080/fhir' server_address: 'http://localhost:8080/fhir'
refuse_to_fetch_third_party_urls: false refuse_to_fetch_third_party_urls: false
fhir_version: R4 fhir_version: R4
-
id: global global:
name: Global Tester name: Global Tester
server_address: "http://hapi.fhir.org/baseR4" server_address: "http://hapi.fhir.org/baseR4"
refuse_to_fetch_third_party_urls: false refuse_to_fetch_third_party_urls: false