Skip to content

Commit

Permalink
Merge pull request #177 from jvitrifork/spring-pr
Browse files Browse the repository at this point in the history
Ease setting environment configuration values
  • Loading branch information
jamesagnew committed Dec 4, 2020
2 parents 25b0fef + 0b34ae2 commit 3326300
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 42 deletions.
23 changes: 8 additions & 15 deletions src/main/java/ca/uhn/fhir/jpa/starter/AppProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import org.hl7.fhir.r4.model.Bundle;

import org.springframework.boot.context.properties.ConfigurationProperties;
Expand Down Expand Up @@ -55,12 +57,12 @@ public class AppProperties {
private Boolean narrative_enabled = true;

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 Subscription subscription = new Subscription();
private Cors cors = null;
private Partitioning partitioning = null;
private List<ImplementationGuide> implementationGuides = null;
private Map<String, ImplementationGuide> implementationGuides = null;

private Boolean lastn_enabled = false;

Expand All @@ -72,11 +74,11 @@ public void setDefer_indexing_for_codesystems_of_size(Integer defer_indexing_for
this.defer_indexing_for_codesystems_of_size = defer_indexing_for_codesystems_of_size;
}

public List<ImplementationGuide> getImplementationGuides() {
public Map<String, ImplementationGuide> getImplementationGuides() {
return implementationGuides;
}

public void setImplementationGuides(List<ImplementationGuide> implementationGuides) {
public void setImplementationGuides(Map<String, ImplementationGuide> implementationGuides) {
this.implementationGuides = implementationGuides;
}

Expand Down Expand Up @@ -366,11 +368,11 @@ public void setReuse_cached_search_results_millis(Long reuse_cached_search_resul
this.reuse_cached_search_results_millis = reuse_cached_search_results_millis;
}

public List<Tester> getTester() {
public Map<String, Tester> getTester() {
return tester;
}

public void setTester(List<Tester> tester) {
public void setTester(Map<String, Tester> tester) {
this.tester = tester;
}

Expand Down Expand Up @@ -458,7 +460,6 @@ public void setLog_exceptions(Boolean log_exceptions) {

public static class Tester {

private String id = "home";
private String name = "Local Tester";
private String server_address = "http:https://localhost:8080/fhir";
private Boolean refuse_to_fetch_third_party_urls = true;
Expand All @@ -472,14 +473,6 @@ public void setFhir_version(FhirVersionEnum fhir_version) {
this.fhir_version = fhir_version;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getName() {
return name;
}
Expand Down
15 changes: 6 additions & 9 deletions src/main/java/ca/uhn/fhir/jpa/starter/BaseJpaRestfulServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@
import org.springframework.web.cors.CorsConfiguration;

import javax.servlet.ServletException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.*;
import java.util.stream.Collectors;

public class BaseJpaRestfulServer extends RestfulServer {
Expand Down Expand Up @@ -351,12 +348,12 @@ protected void initialize() throws ServletException {
}

if (appProperties.getImplementationGuides() != null) {
List<AppProperties.ImplementationGuide> guides = appProperties.getImplementationGuides();
for (AppProperties.ImplementationGuide guide : guides) {
Map<String, AppProperties.ImplementationGuide> guides = appProperties.getImplementationGuides();
for (Map.Entry<String, AppProperties.ImplementationGuide> guide : guides.entrySet()) {
packageInstallerSvc.install(new PackageInstallationSpec()
.setPackageUrl(guide.getUrl())
.setName(guide.getName())
.setVersion(guide.getVersion())
.setPackageUrl(guide.getValue().getUrl())
.setName(guide.getValue().getName())
.setVersion(guide.getValue().getVersion())
.setInstallMode(PackageInstallationSpec.InstallModeEnum.STORE_AND_INSTALL));
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/ca/uhn/fhir/jpa/starter/FhirTesterConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ public class FhirTesterConfig {
@Bean
public TesterConfig testerConfig(AppProperties appProperties) {
TesterConfig retVal = new TesterConfig();
appProperties.getTester().stream().forEach(t -> {
appProperties.getTester().entrySet().stream().forEach(t -> {
retVal
.addServer()
.withId(t.getId())
.withFhirVersion(t.getFhir_version())
.withBaseUrl(t.getServer_address())
.withName(t.getName());
.withId(t.getKey())
.withFhirVersion(t.getValue().getFhir_version())
.withBaseUrl(t.getValue().getServer_address())
.withName(t.getValue().getName());
retVal.setRefuseToFetchThirdPartyUrls(
t.getRefuse_to_fetch_third_party_urls());
t.getValue().getRefuse_to_fetch_third_party_urls());

});
return retVal;
Expand Down
27 changes: 15 additions & 12 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
spring:
datasource:
url: 'jdbc:h2:file:./target/database/h2'
#url: jdbc:h2:mem:test_mem
username: sa
password: null
driverClassName: org.h2.Driver
Expand Down Expand Up @@ -32,14 +33,16 @@ hapi:
### This is the FHIR version. Choose between, DSTU2, DSTU3, R4 or R5
fhir_version: R4
# defer_indexing_for_codesystems_of_size: 101
# implementationguides:
# -
# url: https://build.fhir.org/ig/hl7dk/dk-medcom/branches/corrections/package.tgz
# name: dk.fhir.ig.medcom-core
# version: 0.8.0
# -
# name: hl7.fhir.uv.ips
# version: 0.3.0
#implementationguides:
#example from registry (packages.fhir.org)
#swiss:
#name: swiss.mednet.fhir
#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
#version: 1.0.0

#supported_resource_types:
# - Patient
Expand Down Expand Up @@ -89,14 +92,14 @@ hapi:
# retain_cached_searches_mins: 60
# reuse_cached_search_results_millis: 60000
tester:
-
id: home

home:
name: Local Tester
server_address: 'http:https://localhost:8080/fhir'
refuse_to_fetch_third_party_urls: false
fhir_version: R4
-
id: global

global:
name: Global Tester
server_address: "http:https://hapi.fhir.org/baseR4"
refuse_to_fetch_third_party_urls: false
Expand Down

0 comments on commit 3326300

Please sign in to comment.