Simplify FhirSettings format.
This commit is contained in:
parent
730a1781ee
commit
7c796b4ba4
|
@ -136,15 +136,13 @@ public class ManagedWebAccess {
|
|||
setAccessPolicy(FhirSettings.isProhibitNetworkAccess() ? WebAccessPolicy.PROHIBITED : WebAccessPolicy.DIRECT);
|
||||
setUserAgent("hapi-fhir-tooling-client");
|
||||
serverAuthDetails = new ArrayList<>();
|
||||
serverAuthDetails.addAll(FhirSettings.getPackageServers());
|
||||
serverAuthDetails.addAll(FhirSettings.getTerminologyServers());
|
||||
serverAuthDetails.addAll(FhirSettings.getServers());
|
||||
}
|
||||
|
||||
public static void loadFromFHIRSettings(FhirSettings settings) {
|
||||
setAccessPolicy(settings.isProhibitNetworkAccess() ? WebAccessPolicy.PROHIBITED : WebAccessPolicy.DIRECT);
|
||||
setUserAgent("hapi-fhir-tooling-client");
|
||||
serverAuthDetails = new ArrayList<>();
|
||||
serverAuthDetails.addAll(settings.getPackageServers());
|
||||
serverAuthDetails.addAll(settings.getTerminologyServers());
|
||||
serverAuthDetails.addAll(settings.getServers());
|
||||
}
|
||||
}
|
|
@ -69,13 +69,39 @@ public class PackageServer {
|
|||
return new PackageServer(pojo.getUrl())
|
||||
.withAuthenticationMode(getModeFromPOJO(pojo))
|
||||
.withServerType(
|
||||
pojo.getType() != null && pojo.getType().equalsIgnoreCase("npm-package") ? PackageServerType.NPM : PackageServerType.FHIR
|
||||
getPackageServerType(pojo.getType())
|
||||
)
|
||||
.withUsername(pojo.getUsername())
|
||||
.withPassword(pojo.getPassword())
|
||||
.withToken(pojo.getToken());
|
||||
}
|
||||
|
||||
private static boolean isPackageServer(String serverType) {
|
||||
if (serverType == null) {
|
||||
return false;
|
||||
}
|
||||
if (serverType.equals("fhir-package")) {
|
||||
return true;
|
||||
}
|
||||
if (serverType.equals("npm-package")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static PackageServerType getPackageServerType(String serverType) {
|
||||
if (serverType == null) {
|
||||
return null;
|
||||
}
|
||||
if (serverType.equals("fhir-package")) {
|
||||
return PackageServerType.FHIR;
|
||||
}
|
||||
if (serverType.equals("npm-package")) {
|
||||
return PackageServerType.NPM;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static HTTPAuthenticationMode getModeFromPOJO(ServerDetailsPOJO pojo) {
|
||||
if (pojo.getAuthenticationType().equalsIgnoreCase("basic")) return HTTPAuthenticationMode.BASIC;
|
||||
|
@ -84,9 +110,10 @@ public class PackageServer {
|
|||
}
|
||||
|
||||
public static List<PackageServer> getConfiguredServers() {
|
||||
return FhirSettings.getPackageServers().stream().map(
|
||||
PackageServer::getPackageServerFromPOJO
|
||||
).collect(Collectors.toList());
|
||||
return FhirSettings.getServers().stream()
|
||||
.filter(serverDetailsPOJO -> isPackageServer(serverDetailsPOJO.getType()))
|
||||
.map(PackageServer::getPackageServerFromPOJO)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -222,25 +222,17 @@ public class FhirSettings {
|
|||
|
||||
public static boolean isIgnoreDefaultPackageServers() {
|
||||
getInstance();
|
||||
if (instance.fhirSettings.getPackageManagement() == null || instance.fhirSettings.getPackageManagement().getIgnoreDefaultServers() == null) {
|
||||
if (instance.fhirSettings.getIgnoreDefaultPackageServers() == null) {
|
||||
return false;
|
||||
}
|
||||
return instance.fhirSettings.getPackageManagement().getIgnoreDefaultServers();
|
||||
return instance.fhirSettings.getIgnoreDefaultPackageServers();
|
||||
}
|
||||
|
||||
public static List<ServerDetailsPOJO> getPackageServers() {
|
||||
public static List<ServerDetailsPOJO> getServers() {
|
||||
getInstance();
|
||||
if (instance.fhirSettings.getPackageManagement() == null) {
|
||||
if (instance.fhirSettings.getServers() == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return Arrays.asList(instance.fhirSettings.getPackageManagement().getServers().toArray(new ServerDetailsPOJO[]{}));
|
||||
}
|
||||
|
||||
public static List<ServerDetailsPOJO> getTerminologyServers() {
|
||||
getInstance();
|
||||
if (instance.fhirSettings.getTerminologyServers() == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return Arrays.asList(instance.fhirSettings.getTerminologyServers().getServers().toArray(new ServerDetailsPOJO[]{}));
|
||||
return Arrays.asList(instance.fhirSettings.getServers().toArray(new ServerDetailsPOJO[]{}));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package org.hl7.fhir.utilities.settings;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
|
@ -39,8 +41,9 @@ public class FhirSettingsPOJO {
|
|||
private String txFhirDevelopment;
|
||||
private String txFhirLocal;
|
||||
|
||||
private PackageManagementPOJO packageManagement;
|
||||
private TerminologyServersPOJO terminologyServers;
|
||||
private Boolean ignoreDefaultPackageServers;
|
||||
|
||||
private List<ServerDetailsPOJO> servers;
|
||||
|
||||
protected FhirSettingsPOJO() {
|
||||
apiKeys = null;
|
||||
|
@ -53,8 +56,6 @@ public class FhirSettingsPOJO {
|
|||
txFhirProduction = TX_SERVER_PROD;
|
||||
txFhirDevelopment = TX_SERVER_DEV;
|
||||
txFhirLocal = TX_SERVER_LOCAL;
|
||||
|
||||
packageManagement = null;
|
||||
terminologyServers = null;
|
||||
servers = new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
package org.hl7.fhir.utilities.settings;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.extern.jackson.Jacksonized;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@Jacksonized
|
||||
@AllArgsConstructor
|
||||
public class PackageManagementPOJO {
|
||||
|
||||
private Boolean ignoreDefaultServers;
|
||||
|
||||
private List<ServerDetailsPOJO> servers;
|
||||
|
||||
protected PackageManagementPOJO() {
|
||||
ignoreDefaultServers = false;
|
||||
servers = new ArrayList<>();
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
package org.hl7.fhir.utilities.settings;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.extern.jackson.Jacksonized;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@Jacksonized
|
||||
@AllArgsConstructor
|
||||
public class TerminologyServersPOJO {
|
||||
|
||||
private List<ServerDetailsPOJO> servers;
|
||||
|
||||
protected TerminologyServersPOJO() {
|
||||
servers = new ArrayList<>();
|
||||
}
|
||||
}
|
|
@ -85,19 +85,19 @@ public class FhirSettingsTests implements ResourceLoaderTests {
|
|||
assertEquals("dummy-temp-path", fhirSettings.getTempPath());
|
||||
assertEquals("dummy-test-igs-path", fhirSettings.getTestIgsPath());
|
||||
|
||||
assertTrue(fhirSettings.getPackageManagement().getIgnoreDefaultServers());
|
||||
assertTrue(fhirSettings.getIgnoreDefaultPackageServers());
|
||||
|
||||
List<ServerDetailsPOJO> packageServers = fhirSettings.getPackageManagement().getServers();
|
||||
List<ServerDetailsPOJO> servers = fhirSettings.getServers();
|
||||
|
||||
assertEquals(2, packageServers.size());
|
||||
assertEquals(2, servers.size());
|
||||
|
||||
assertEquals("http://dummy.org", packageServers.get(0).url);
|
||||
assertEquals("npm-package", packageServers.get(0).type);
|
||||
assertEquals("joe", packageServers.get(0).username);
|
||||
assertEquals("swordfish", packageServers.get(0).password);
|
||||
assertEquals("BASIC", packageServers.get(0).authenticationType);
|
||||
assertEquals("http://dummy.org", servers.get(0).url);
|
||||
assertEquals("npm-package", servers.get(0).type);
|
||||
assertEquals("joe", servers.get(0).username);
|
||||
assertEquals("swordfish", servers.get(0).password);
|
||||
assertEquals("BASIC", servers.get(0).authenticationType);
|
||||
|
||||
assertEquals("http://dummy2.com", packageServers.get(1).url);
|
||||
assertEquals("http://dummy2.com", servers.get(1).url);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,30 +2,28 @@
|
|||
"apiKeys": {
|
||||
"dummy-api-key": "dummy-api-key-value"
|
||||
},
|
||||
"npmPath": "dummy-npm-path",
|
||||
"npmPath": "dummy-npm-path",
|
||||
"rubyPath": "dummy-ruby-path",
|
||||
"fhirTestCasesPath": "dummy-fhir-test-cases-path",
|
||||
"diffToolPath": "dummy-diff-tool-path",
|
||||
"tempPath": "dummy-temp-path",
|
||||
"testIgsPath": "dummy-test-igs-path",
|
||||
"unusedField" : "unused",
|
||||
"packageManagement" : {
|
||||
"ignoreDefaultServers" : true,
|
||||
"servers": [
|
||||
{
|
||||
"url": "http://dummy.org",
|
||||
"type": "npm-package",
|
||||
"authenticationType": "BASIC",
|
||||
"username": "joe",
|
||||
"password": "swordfish"
|
||||
},
|
||||
{
|
||||
"url": "http://dummy2.com",
|
||||
"goobledy-goo": 5
|
||||
}
|
||||
]
|
||||
},
|
||||
"unusedData" : {
|
||||
"unusedDateField" : "unused-data"
|
||||
"unusedField": "unused",
|
||||
"ignoreDefaultPackageServers": true,
|
||||
"servers": [
|
||||
{
|
||||
"url": "http://dummy.org",
|
||||
"type": "npm-package",
|
||||
"authenticationType": "BASIC",
|
||||
"username": "joe",
|
||||
"password": "swordfish"
|
||||
},
|
||||
{
|
||||
"url": "http://dummy2.com",
|
||||
"goobledy-goo": 5
|
||||
}
|
||||
],
|
||||
"unusedData": {
|
||||
"unusedDateField": "unused-data"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue