reorg server settings

This commit is contained in:
Grahame Grieve 2023-04-21 18:52:36 +08:00
parent 45005b9ff7
commit fe86ab1d7c
15 changed files with 75 additions and 33 deletions

View File

@ -4,7 +4,7 @@ import java.net.URISyntaxException;
import org.hl7.fhir.r5.terminologies.TerminologyClient;
import org.hl7.fhir.utilities.FhirPublication;
import org.hl7.fhir.utilities.Servers;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.VersionUtilities;
@ -61,7 +61,7 @@ public class TerminologyClientFactory {
private static String checkEndsWith(String term, String url) {
if (url.endsWith(term))
return url;
if (Servers.isTxFhirOrg(url)) {
if (Utilities.isTxFhirOrgServer(url)) {
return Utilities.pathURL(url, term);
}
return url;

View File

@ -21,7 +21,8 @@ import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.model.TerminologyCapabilities;
import org.hl7.fhir.r5.utils.client.network.Client;
import org.hl7.fhir.r5.utils.client.network.ResourceRequest;
import org.hl7.fhir.utilities.Servers;
import org.hl7.fhir.utilities.settings.FhirSettings;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -38,7 +39,7 @@ import static org.mockito.Mockito.times;
class FHIRToolingClientTest {
String TX_ADDR = Servers.TX_SERVER_DEV;
String TX_ADDR = FhirSettings.getTxFhirDevelopment();
Header h1 = new Header("header1", "value1");
Header h2 = new Header("header2", "value2");

View File

@ -1,13 +0,0 @@
package org.hl7.fhir.utilities;
public class Servers {
public static final String TX_SERVER_PROD = "http://tx.fhir.org";
public static final String TX_SERVER_DEV = "http://tx-dev.fhir.org";
public static final String TX_SERVER_LOCAL = "http://local.fhir.org";
public static boolean isTxFhirOrg(String s) {
return Utilities.startsWithInList(s.replace("https://", "http://"), TX_SERVER_PROD, TX_SERVER_DEV, TX_SERVER_LOCAL);
}
}

View File

@ -64,6 +64,7 @@ import java.util.zip.ZipInputStream;
import org.apache.commons.io.FileUtils;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.utilities.FileNotifier.FileNotifier2;
import org.hl7.fhir.utilities.settings.FhirSettings;
import javax.annotation.Nullable;
@ -1961,4 +1962,8 @@ public class Utilities {
//}
public static boolean isTxFhirOrgServer(String s) {
return Utilities.startsWithInList(s.replace("https://", "http://"), FhirSettings.getTxFhirProduction(), FhirSettings.getTxFhirDevelopment(), FhirSettings.getTxFhirLocal());
}
}

View File

@ -1224,6 +1224,10 @@ public class NpmPackage {
public String toString() {
return "NpmPackage "+name()+"#"+version()+" [path=" + path + "]";
}
public String getFilePath(String d) throws IOException {
return Utilities.path(path, "package", d);
}
}

View File

@ -11,9 +11,9 @@ import java.io.IOException;
import java.io.InputStream;
public class FhirSettings {
public static final String FHIR_SETTINGS_PATH = "fhir.settings.path";
private static String explicitFilePath = null;
private static Boolean prohibitNetworkAccess;
@ -136,6 +136,28 @@ public class FhirSettings {
prohibitNetworkAccess = value;
}
public static String getTxFhirProduction() {
getInstance();
return instance.fhirSettings.getTxFhirProduction() == null
? FhirSettingsPOJO.TX_SERVER_PROD
: instance.fhirSettings.getTxFhirProduction();
}
public static String getTxFhirDevelopment() {
getInstance();
return instance.fhirSettings.getTxFhirDevelopment() == null
? FhirSettingsPOJO.TX_SERVER_PROD
: instance.fhirSettings.getTxFhirDevelopment();
}
public static String getTxFhirLocal() {
getInstance();
return instance.fhirSettings.getTxFhirLocal() == null
? FhirSettingsPOJO.TX_SERVER_PROD
: instance.fhirSettings.getTxFhirLocal();
}
private static FhirSettings instance = null;
private static FhirSettings getInstance() {
@ -187,4 +209,5 @@ public class FhirSettings {
protected static String getDefaultSettingsPath() throws IOException {
return Utilities.path(System.getProperty("user.home"), ".fhir", "fhir-settings.json");
}
}

View File

@ -13,6 +13,11 @@ import java.util.Map;
@AllArgsConstructor
public class FhirSettingsPOJO {
protected static final String TX_SERVER_PROD = "http://tx.fhir.org";
protected static final String TX_SERVER_DEV = "http://tx-dev.fhir.org";
protected static final String TX_SERVER_LOCAL = "http://local.fhir.org";
private String fhirDirectory;
private Map<String, String> apiKeys;
@ -30,6 +35,10 @@ public class FhirSettingsPOJO {
private Boolean prohibitNetworkAccess;
private String txFhirProduction;
private String txFhirDevelopment;
private String txFhirLocal;
protected FhirSettingsPOJO() {
apiKeys = null;
npmPath = null;
@ -38,5 +47,8 @@ public class FhirSettingsPOJO {
diffToolPath = null;
tempPath = null;
testIgsPath = null;
txFhirProduction = TX_SERVER_PROD;
txFhirDevelopment = TX_SERVER_DEV;
txFhirLocal = TX_SERVER_LOCAL;
}
}

View File

@ -335,6 +335,9 @@ public class ValidatorCli {
case SNAPSHOT:
validationService.generateSnapshot(cliContext, validator);
break;
case INSTALL:
validationService.install(cliContext, validator);
break;
case SPREADSHEET:
validationService.generateSpreadsheet(cliContext, validator);
break;

View File

@ -9,8 +9,9 @@ import java.util.Objects;
import org.hl7.fhir.r5.terminologies.JurisdictionUtilities;
import org.hl7.fhir.r5.utils.validation.BundleValidationRule;
import org.hl7.fhir.utilities.Servers;
import org.hl7.fhir.utilities.VersionUtilities;
import org.hl7.fhir.utilities.settings.FhirSettings;
import org.hl7.fhir.validation.cli.utils.EngineMode;
import org.hl7.fhir.validation.cli.utils.QuestionnaireMode;
import org.hl7.fhir.validation.cli.utils.ValidationLevel;
@ -62,7 +63,7 @@ public class CliContext {
@JsonProperty("htmlOutput")
private String htmlOutput = null;
@JsonProperty("txServer")
private String txServer = Servers.TX_SERVER_PROD;
private String txServer = FhirSettings.getTxFhirProduction();
@JsonProperty("sv")
private String sv = null;
@JsonProperty("txLog")

View File

@ -2,9 +2,10 @@ package org.hl7.fhir.validation.cli.utils;
import org.hl7.fhir.r5.model.Constants;
import org.hl7.fhir.utilities.FhirPublication;
import org.hl7.fhir.utilities.Servers;
import org.hl7.fhir.utilities.TimeTracker;
import org.hl7.fhir.utilities.VersionUtilities;
import org.hl7.fhir.utilities.settings.FhirSettings;
import org.hl7.fhir.validation.ValidationEngine;
public class Common {
@ -75,7 +76,7 @@ public class Common {
* Default validation engine will point to "http://tx.fhir.org" terminology server.
*/
public static ValidationEngine getValidationEngine(String version, String definitions, String txLog, TimeTracker tt) throws Exception {
return getValidationEngine(version, Servers.TX_SERVER_PROD, definitions, txLog, tt);
return getValidationEngine(version, FhirSettings.getTxFhirProduction(), definitions, txLog, tt);
}
public static ValidationEngine getValidationEngine(String version, String txServer, String definitions, String txLog, TimeTracker tt) throws Exception {

View File

@ -46,7 +46,7 @@ import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.model.StructureDefinition;
import org.hl7.fhir.r5.model.ValueSet;
import org.hl7.fhir.r5.test.utils.TestingUtilities;
import org.hl7.fhir.utilities.Servers;
import org.hl7.fhir.utilities.TextFile;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.VersionUtilities;
@ -54,6 +54,7 @@ import org.hl7.fhir.utilities.npm.CommonPackages;
import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager;
import org.hl7.fhir.utilities.npm.NpmPackage;
import org.hl7.fhir.utilities.npm.ToolsVersion;
import org.hl7.fhir.utilities.settings.FhirSettings;
import org.hl7.fhir.utilities.validation.ValidationMessage;
import org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity;
import org.hl7.fhir.utilities.xhtml.XhtmlComposer;
@ -94,7 +95,7 @@ public class ComparisonTests {
private static IWorkerContext context;
private JsonObject content;
private static final String DEF_TX = Servers.TX_SERVER_DEV;
private static final String DEF_TX = FhirSettings.getTxFhirDevelopment();
private static final String HEADER = "<html><link href=\"http://hl7.org/fhir/fhir.css\" rel=\"stylesheet\"/><body>";
private static final String BREAK = "<hr/>";
private static final String FOOTER = "</body></html>";

View File

@ -22,8 +22,9 @@ import org.hl7.fhir.r5.formats.XmlParser;
import org.hl7.fhir.r5.model.Constants;
import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.test.utils.TestingUtilities;
import org.hl7.fhir.utilities.Servers;
import org.hl7.fhir.utilities.json.model.JsonObject;
import org.hl7.fhir.utilities.settings.FhirSettings;
import org.hl7.fhir.validation.special.TxTester;
import org.hl7.fhir.validation.special.TxTester.ITxTesterLoader;
@ -47,8 +48,8 @@ public class ExternalTerminologyServiceTests implements ITxTesterLoader {
private JsonObject test;
}
private static final String SERVER = Servers.TX_SERVER_DEV;
// private static final String SERVER = Servers.TX_SERVER_LOCAL;
private static final String SERVER = FhirSettings.getTxFhirDevelopment();
// private static final String SERVER = FhirSettings.getTxFhirLocal();
@Parameters(name = "{index}: id {0}")
public static Iterable<Object[]> data() throws IOException {

View File

@ -25,8 +25,9 @@ import org.hl7.fhir.r5.test.utils.CompareUtilities;
import org.hl7.fhir.r5.test.utils.TestingUtilities;
import org.hl7.fhir.r5.utils.validation.IResourceValidator;
import org.hl7.fhir.utilities.FhirPublication;
import org.hl7.fhir.utilities.Servers;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.settings.FhirSettings;
import org.hl7.fhir.utilities.validation.ValidationMessage;
import org.hl7.fhir.validation.instance.InstanceValidator;
import org.hl7.fhir.validation.tests.ValidationEngineTests;
@ -47,7 +48,7 @@ public class ResourceValidationTests {
TestingUtilities.injectCorePackageLoader();
if (val == null) {
ctxt = TestingUtilities.getSharedWorkerContext();
engine = TestUtilities.getValidationEngine("hl7.fhir.r5.core#5.0.0", Servers.TX_SERVER_DEV, null, FhirPublication.R5, true, "5.0.0");
engine = TestUtilities.getValidationEngine("hl7.fhir.r5.core#5.0.0", FhirSettings.getTxFhirDevelopment(), null, FhirPublication.R5, true, "5.0.0");
val = engine.getValidator(null);
val.setDebug(false);
}

View File

@ -4,7 +4,8 @@ import java.util.ArrayList;
import java.util.List;
import org.hl7.fhir.utilities.FhirPublication;
import org.hl7.fhir.utilities.Servers;
import org.hl7.fhir.utilities.settings.FhirSettings;
import org.hl7.fhir.utilities.tests.CacheVerificationLogger;
import org.hl7.fhir.r5.elementmodel.Manager.FhirFormat;
import org.hl7.fhir.r5.model.OperationOutcome;
@ -21,8 +22,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
public class ValidationEngineTests {
private static final String DEF_TX = Servers.TX_SERVER_DEV;
// private static final String DEF_TX = Servers.TX_SERVER_LOCAL;
private static final String DEF_TX = FhirSettings.getTxFhirDevelopment();
// private static final String DEF_TX = FhirSettings.getTxFhirLocal();
public static boolean inbuild;

View File

@ -72,6 +72,7 @@ import org.hl7.fhir.utilities.SimpleHTTPClient.HTTPResult;
import org.hl7.fhir.utilities.json.JsonTrackingParser;
import org.hl7.fhir.utilities.json.JsonUtilities;
import org.hl7.fhir.utilities.npm.NpmPackage;
import org.hl7.fhir.utilities.settings.FhirSettings;
import org.hl7.fhir.utilities.validation.ValidationMessage;
import org.hl7.fhir.validation.IgLoader;
import org.hl7.fhir.validation.ValidationEngine;
@ -404,7 +405,7 @@ public class ValidationTests implements IEvaluationContext, IValidatorResourceFe
private ValidationEngine buildVersionEngine(String ver, String txLog) throws Exception {
String server = Servers.TX_SERVER_DEV;
String server = FhirSettings.getTxFhirDevelopment();
switch (ver) {
case "1.0": return TestUtilities.getValidationEngine("hl7.fhir.r2.core#1.0.2", server, txLog, FhirPublication.DSTU2, true, "1.0.2");
case "1.4": return TestUtilities.getValidationEngine("hl7.fhir.r2b.core#1.4.0", server, txLog, FhirPublication.DSTU2016May, true, "1.4.0");