Merge branch 'master' into language-rework

This commit is contained in:
Grahame Grieve 2023-08-28 20:13:42 +02:00 committed by GitHub
commit d0815682b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 95 additions and 84 deletions

View File

@ -16,4 +16,6 @@
# Actually a BSD license https://mvnrepository.com/artifact/org.antlr/ST4/4.1
(Unknown license) StringTemplate 4 (org.antlr:ST4:4.1 - http://nexus.sonatype.org/oss-repository-hosting.html/ST4)
# without dependencies is incorrectly intepreted as a license name
(Apache License, Version 2.0) Byte Buddy (without dependencies) (net.bytebuddy:byte-buddy:1.12.14 - https://bytebuddy.net/byte-buddy)
(Apache License, Version 2.0) Byte Buddy (without dependencies) (net.bytebuddy:byte-buddy:1.12.14 - https://bytebuddy.net/byte-buddy)
# Appears to be Apache 2.0: https://github.com/NCIP/lexevs/blob/master/lgSharedLibraries/apache/commons/jakarta-regexp-1.4.license.txt
(Unknown license) jakarta-regexp (jakarta-regexp:jakarta-regexp:1.4 - no url defined)

View File

@ -82,15 +82,10 @@
</dependency>
<dependency>
<groupId>xpp3</groupId>
<groupId>org.ogce</groupId>
<artifactId>xpp3</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>xpp3</groupId>
<artifactId>xpp3_xpath</artifactId>
<optional>true</optional>
</dependency>
<!-- HTTP Client -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>

View File

@ -200,6 +200,11 @@ public class TerminologyClientR2 implements ITerminologyClient {
return this;
}
@Override
public String getUserAgent() {
return client.getUserAgent();
}
@Override
public String getServerVersion() {
return client.getServerVersion();

View File

@ -202,6 +202,11 @@ public class TerminologyClientR3 implements ITerminologyClient {
return this;
}
@Override
public String getUserAgent() {
return client.getUserAgent();
}
@Override
public String getServerVersion() {
return client.getServerVersion();

View File

@ -210,6 +210,11 @@ public class TerminologyClientR4 implements ITerminologyClient {
return this;
}
@Override
public String getUserAgent() {
return client.getUserAgent();
}
@Override
public String getServerVersion() {
return client.getServerVersion();

View File

@ -190,6 +190,11 @@ public class TerminologyClientR5 implements ITerminologyClient {
return this;
}
@Override
public String getUserAgent() {
return client.getUserAgent();
}
@Override
public String getServerVersion() {
return client.getServerVersion();

View File

@ -37,15 +37,10 @@
<!-- XML Parsers -->
<dependency>
<groupId>xpp3</groupId>
<groupId>org.ogce</groupId>
<artifactId>xpp3</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>xpp3</groupId>
<artifactId>xpp3_xpath</artifactId>
<optional>true</optional>
</dependency>
<!-- JSON Parsers -->
<dependency>

View File

@ -37,14 +37,8 @@
<!-- XML Parsers -->
<dependency>
<groupId>xpp3</groupId>
<groupId>org.ogce</groupId>
<artifactId>xpp3</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>xpp3</groupId>
<artifactId>xpp3_xpath</artifactId>
<optional>true</optional>
</dependency>
<!-- JSON Parsers -->

View File

@ -37,15 +37,11 @@
<!-- XML Parsers -->
<dependency>
<groupId>xpp3</groupId>
<groupId>org.ogce</groupId>
<artifactId>xpp3</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>xpp3</groupId>
<artifactId>xpp3_xpath</artifactId>
<optional>true</optional>
</dependency>
<!-- JSON Parsers -->
<dependency>

View File

@ -44,15 +44,10 @@
<!-- XML Parsers -->
<dependency>
<groupId>xpp3</groupId>
<groupId>org.ogce</groupId>
<artifactId>xpp3</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>xpp3</groupId>
<artifactId>xpp3_xpath</artifactId>
<optional>true</optional>
</dependency>
<!-- JSON Parsers -->
<dependency>

View File

@ -43,15 +43,10 @@
<!-- XML Parsers -->
<dependency>
<groupId>xpp3</groupId>
<groupId>org.ogce</groupId>
<artifactId>xpp3</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>xpp3</groupId>
<artifactId>xpp3_xpath</artifactId>
<optional>true</optional>
</dependency>
<!-- JSON Parsers -->
<dependency>

View File

@ -44,15 +44,11 @@
<!-- XML Parsers -->
<dependency>
<groupId>xpp3</groupId>
<groupId>org.ogce</groupId>
<artifactId>xpp3</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>xpp3</groupId>
<artifactId>xpp3_xpath</artifactId>
<optional>true</optional>
</dependency>
<!-- JSON Parsers -->
<dependency>

View File

@ -66,4 +66,5 @@ public interface ITerminologyClient {
ITerminologyClient setClientHeaders(ClientHeaders clientHeaders);
ITerminologyClient setUserAgent(String userAgent);
ITerminologyClient setLanguage(String lang);
String getUserAgent();
}

View File

@ -84,15 +84,11 @@
<optional>true</optional>
</dependency>
<dependency>
<groupId>xpp3</groupId>
<groupId>org.ogce</groupId>
<artifactId>xpp3</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>xpp3</groupId>
<artifactId>xpp3_xpath</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.ibm.icu</groupId>

View File

@ -288,13 +288,10 @@
<artifactId>ucum</artifactId>
</dependency>
<dependency>
<groupId>xpp3</groupId>
<groupId>org.ogce</groupId>
<artifactId>xpp3</artifactId>
</dependency>
<dependency>
<groupId>xpp3</groupId>
<artifactId>xpp3_xpath</artifactId>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>

View File

@ -82,13 +82,9 @@
<artifactId>Saxon-HE</artifactId>
</dependency>
<dependency>
<groupId>xpp3</groupId>
<groupId>org.ogce</groupId>
<artifactId>xpp3</artifactId>
</dependency>
<dependency>
<groupId>xpp3</groupId>
<artifactId>xpp3_xpath</artifactId>
</dependency>
<!-- JSON Utilities -->
<dependency>

View File

@ -34,6 +34,9 @@ import org.hl7.fhir.utilities.json.model.JsonObject;
import org.hl7.fhir.utilities.json.parser.JsonParser;
import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager;
import org.hl7.fhir.utilities.npm.NpmPackage;
import org.hl7.fhir.validation.cli.utils.Common;
import javax.annotation.Nonnull;
public class StandAloneValidatorFetcher implements IValidatorResourceFetcher, IValidationPolicyAdvisor, IWorkerContextManager.ICanonicalResourceLocator {
@ -258,14 +261,18 @@ public class StandAloneValidatorFetcher implements IValidatorResourceFetcher, IV
String root = getRoot(p, url);
if (root != null) {
ITerminologyClient c;
c = TerminologyClientFactory.makeClient("source", root, "fhir/validator", context.getVersion());
return c.read(p[p.length - 2], p[p.length - 1]);
ITerminologyClient terminologyClient = getTerminologyClient(root);
return terminologyClient.read(p[p.length - 2], p[p.length - 1]);
} else {
throw new FHIRException("The URL '" + url + "' is not known to the FHIR validator, and has not been provided as part of the setup / parameters");
}
}
@Nonnull
protected ITerminologyClient getTerminologyClient(String root) throws URISyntaxException {
return TerminologyClientFactory.makeClient("source", root, Common.getValidatorUserAgent(), context.getVersion());
}
private String getRoot(String[] p, String url) {
if (p.length > 3 && Utilities.isValidId(p[p.length - 1]) && context.getResourceNames().contains(p[p.length - 2])) {
url = url.substring(0, url.lastIndexOf("/"));

View File

@ -77,6 +77,7 @@ import org.hl7.fhir.validation.cli.renderers.DefaultRenderer;
import org.hl7.fhir.validation.cli.renderers.ESLintCompactRenderer;
import org.hl7.fhir.validation.cli.renderers.NativeRenderer;
import org.hl7.fhir.validation.cli.renderers.ValidationOutputRenderer;
import org.hl7.fhir.validation.cli.utils.Common;
import org.hl7.fhir.validation.cli.utils.EngineMode;
import org.hl7.fhir.validation.cli.utils.VersionSourceInformation;
@ -441,7 +442,7 @@ public class ValidationService {
@Nonnull
protected ValidationEngine buildValidationEngine( CliContext cliContext, String definitions, TimeTracker timeTracker) throws IOException, URISyntaxException {
System.out.print(" Load FHIR v" + cliContext.getSv() + " from " + definitions);
ValidationEngine validationEngine = getValidationEngineBuilder().withTHO(false).withVersion(cliContext.getSv()).withTimeTracker(timeTracker).withUserAgent("fhir/validator").fromSource(definitions);
ValidationEngine validationEngine = getValidationEngineBuilder().withTHO(false).withVersion(cliContext.getSv()).withTimeTracker(timeTracker).withUserAgent(Common.getValidatorUserAgent()).fromSource(definitions);
System.out.println(" - " + validationEngine.getContext().countAllCaches() + " resources (" + timeTracker.milestone() + ")");

View File

@ -6,6 +6,8 @@ import org.hl7.fhir.utilities.VersionUtilities;
import org.hl7.fhir.utilities.settings.FhirSettings;
import org.hl7.fhir.validation.ValidationEngine;
import javax.annotation.Nonnull;
public class Common {
public static String getVersion(String[] args) {
@ -70,18 +72,9 @@ public class Common {
return defaultValue;
}
/**
* 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, FhirSettings.getTxFhirProduction(), definitions, txLog, tt);
}
public static ValidationEngine getValidationEngine(String version, String txServer, String definitions, String txLog, TimeTracker tt) throws Exception {
System.out.println("Loading (v = " + version + ", tx server -> " + txServer + ")");
ValidationEngine ve = new ValidationEngine.ValidationEngineBuilder().withVersion(version).withTimeTracker(tt).withUserAgent("fhir/validator").fromSource(definitions);
ve.connectToTSServer(txServer, txLog, FhirPublication.fromCode(version));
return ve;
@Nonnull
public static String getValidatorUserAgent() {
return "fhir/validator/" + VersionUtil.getVersion();
}
public static boolean isNetworkPath(String path) {

View File

@ -197,7 +197,9 @@ public class CodeSystemValidator extends BaseValidator {
warning(errors, "2023-08-15", IssueType.INVALID, nstack, count < statedCount, I18nConstants.CODESYSTEM_CS_COUNT_FRAGMENT_WRONG, count, statedCount);
break;
case "not-present":
hint(errors, "2023-08-15", IssueType.INVALID, stack.push(cs.getNamedChild("concept"), -1, null, null), statedCount > 0, I18nConstants.CODESYSTEM_CS_COUNT_NOTPRESENT_ZERO, statedCount);
if (cs.hasChildren("concept")) {
hint(errors, "2023-08-15", IssueType.INVALID, stack.push(cs.getNamedChild("concept"), -1, null, null), statedCount > 0, I18nConstants.CODESYSTEM_CS_COUNT_NOTPRESENT_ZERO, statedCount);
}
break;
case "supplement":
CodeSystem css = context.fetchCodeSystem(supp);

View File

@ -0,0 +1,23 @@
package org.hl7.fhir.validation.cli.services;
import org.hl7.fhir.r5.context.IWorkerContext;
import org.hl7.fhir.r5.terminologies.client.ITerminologyClient;
import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager;
import org.hl7.fhir.validation.cli.utils.VersionUtil;
import org.junit.Test;
import java.net.URISyntaxException;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;
public class StandAloneValidatorFetcherTests
{
@Test
public void testGetTerminologyClient() throws URISyntaxException {
StandAloneValidatorFetcher standAloneValidatorFetcher = new StandAloneValidatorFetcher(mock(FilesystemPackageCacheManager.class), mock(IWorkerContext.class), mock(IPackageInstaller.class));
ITerminologyClient client = standAloneValidatorFetcher.getTerminologyClient("http://dummyserver/fhir");
assertEquals("fhir/validator/" + VersionUtil.getVersion(), client.getUserAgent());
}
}

View File

@ -35,6 +35,7 @@ import org.hl7.fhir.validation.ValidationEngine;
import org.hl7.fhir.validation.cli.model.CliContext;
import org.hl7.fhir.validation.cli.model.FileInfo;
import org.hl7.fhir.validation.cli.model.ValidationRequest;
import org.hl7.fhir.validation.cli.utils.VersionUtil;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
@ -228,8 +229,10 @@ class ValidationServiceTest {
return cliContext;
}
/* This is a particularly long way to test that a single field in ValidationEngine was set.
However, it does provide example code to test other parts of the buildValidationEngine method as well.
/* This is a particularly long way to test that fields in ValidationEngine are
set to expected default values.
It also provides example code to test other parts of the buildValidationEngine method as well.
*/
@Test
public void buildValidationEngineTest() throws IOException, URISyntaxException {
@ -241,12 +244,11 @@ class ValidationServiceTest {
final ValidationEngine validationEngine = mock(ValidationEngine.class);
when(validationEngine.getContext()).thenReturn(workerContext);
final ValidationEngine.ValidationEngineBuilder validationEngineBuilder = mock(ValidationEngine.ValidationEngineBuilder.class);;
final ValidationService validationService = new ValidationService() {
@Override
protected ValidationEngine.ValidationEngineBuilder getValidationEngineBuilder() {
ValidationEngine.ValidationEngineBuilder validationEngineBuilder = mock(ValidationEngine.ValidationEngineBuilder.class);
when(validationEngineBuilder.withTHO(anyBoolean())).thenReturn(validationEngineBuilder);
when(validationEngineBuilder.withVersion(isNull())).thenReturn(validationEngineBuilder);
when(validationEngineBuilder.withTimeTracker(any())).thenReturn(validationEngineBuilder);
@ -267,10 +269,10 @@ class ValidationServiceTest {
}
};
CliContext cliContext = new CliContext();
validationService.buildValidationEngine(cliContext, null, timeTracker);
verify(validationEngineBuilder).withUserAgent(eq("fhir/validator/" + VersionUtil.getVersion()));
}
}

View File

@ -278,6 +278,11 @@
<artifactId>thymeleaf</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.ogce</groupId>
<artifactId>xpp3</artifactId>
<version>1.1.6</version>
</dependency>
</dependencies>
</dependencyManagement>