Refactor fix for #520 a bit so that version in DSTU3 is always pulled

from the model
This commit is contained in:
James 2016-12-10 14:40:27 -05:00
parent 47ea6c3426
commit b0d656e5d9
18 changed files with 106 additions and 95 deletions

View File

@ -74,7 +74,7 @@ public class GenericClientDstu3IT {
}
private String expectedUserAgent() {
return "HAPI-FHIR/" + VersionUtil.getVersion() + " (FHIR Client; FHIR " + FhirVersionEnum.DSTU3.getFhirVersionString() + "/DSTU3; okhttp/3.4.1)";
return "HAPI-FHIR/" + VersionUtil.getVersion() + " (FHIR Client; FHIR " + FhirVersionEnum.DSTU3.getVersionImplementation().getVersionString() + "/DSTU3; okhttp/3.4.1)";
}

View File

@ -34,32 +34,26 @@ public enum FhirVersionEnum {
* ***********************
*/
DSTU1("ca.uhn.fhir.model.dstu.FhirDstu1", null, false, "0.0.82"),
DSTU1("ca.uhn.fhir.model.dstu.FhirDstu1", null, false),
DSTU2("ca.uhn.fhir.model.dstu2.FhirDstu2", null, false, "1.0.2"),
DSTU2("ca.uhn.fhir.model.dstu2.FhirDstu2", null, false),
DSTU2_HL7ORG("org.hl7.fhir.instance.FhirDstu2Hl7Org", DSTU2, true, "1.0.2"),
DSTU2_HL7ORG("org.hl7.fhir.instance.FhirDstu2Hl7Org", DSTU2, true),
DSTU2_1("NONE", null, true, "1.4.0"),
DSTU2_1("NONE", null, true),
DSTU3("org.hl7.fhir.dstu3.hapi.ctx.FhirDstu3", null, true, "1.6.0");
DSTU3("org.hl7.fhir.dstu3.hapi.ctx.FhirDstu3", null, true);
private final FhirVersionEnum myEquivalent;
private final String myFhirVersionString;
private final boolean myIsRi;
private volatile Boolean myPresentOnClasspath;
private final String myVersionClass;
private volatile IFhirVersion myVersionImplementation;
FhirVersionEnum(String theVersionClass, FhirVersionEnum theEquivalent, boolean theIsRi, String theFhirVersion) {
FhirVersionEnum(String theVersionClass, FhirVersionEnum theEquivalent, boolean theIsRi) {
myVersionClass = theVersionClass;
myEquivalent = theEquivalent;
myIsRi = theIsRi;
myFhirVersionString = theFhirVersion;
}
public String getFhirVersionString() {
return myFhirVersionString;
}
public IFhirVersion getVersionImplementation() {

View File

@ -40,32 +40,34 @@ import ca.uhn.fhir.rest.server.RestfulServer;
public interface IFhirVersion {
FhirVersionEnum getVersion();
IFluentPath createFluentPathExecutor(FhirContext theFhirContext);
IResourceProvider createServerProfilesProvider(RestfulServer theRestfulServer);
IServerConformanceProvider<? extends IBaseResource> createServerConformanceProvider(RestfulServer theRestfulServer);
InputStream getFhirVersionPropertiesFile();
IResourceProvider createServerProfilesProvider(RestfulServer theRestfulServer);
IContextValidationSupport<?, ?, ?, ?, ?, ?> createValidationSupport();
IBaseResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition, String theServerBase);
IServerConformanceProvider<? extends IBaseResource> createServerConformanceProvider(RestfulServer theRestfulServer);
Class<?> getContainedType();
InputStream getFhirVersionPropertiesFile();
IPrimitiveType<Date> getLastUpdated(IBaseResource theResource);
String getPathToSchemaDefinitions();
Class<? extends IBase> getResourceReferenceType();
Class<?> getContainedType();
FhirVersionEnum getVersion();
IBase newCodingDt();
String getVersionString();
IVersionSpecificBundleFactory newBundleFactory(FhirContext theContext);
IPrimitiveType<Date> getLastUpdated(IBaseResource theResource);
IBase newCodingDt();
IIdType newIdType();
IContextValidationSupport<?, ?, ?, ?, ?, ?> createValidationSupport();
IFluentPath createFluentPathExecutor(FhirContext theFhirContext);
}

View File

@ -30,7 +30,7 @@ public class HttpClientUtil {
b.append("HAPI-FHIR/");
b.append(VersionUtil.getVersion());
b.append(" (FHIR Client; FHIR ");
b.append(theContext.getVersion().getVersion().getFhirVersionString());
b.append(theContext.getVersion().getVersionString());
b.append('/');
b.append(theContext.getVersion().getVersion().name());
b.append("; ");

View File

@ -158,7 +158,7 @@ public class RestfulServer extends HttpServlet implements IRestfulServer<Servlet
b.append("HAPI FHIR ");
b.append(VersionUtil.getVersion());
b.append(" REST Server (FHIR Server; FHIR ");
b.append(myFhirContext.getVersion().getVersion().getFhirVersionString());
b.append(myFhirContext.getVersion().getVersionString());
b.append('/');
b.append(myFhirContext.getVersion().getVersion().name());
b.append(")");

View File

@ -77,15 +77,6 @@ public class RestfulServerUtils {
private static final HashSet<String> TEXT_ENCODE_ELEMENTS = new HashSet<String>(Arrays.asList("Bundle", "*.text", "*.(mandatory)"));
private static String actualDstu3FhirVersion = FhirVersionEnum.DSTU3.getFhirVersionString();
static {
try {
Class c = Class.forName("org.hl7.fhir.dstu3.model.Constants");
actualDstu3FhirVersion = (String) c.getDeclaredField("VERSION").get(null);
} catch (Exception e) {
}
}
public static void configureResponseParser(RequestDetails theRequestDetails, IParser parser) {
// Pretty print
boolean prettyPrint = RestfulServerUtils.prettyPrintResponse(theRequestDetails.getServer(), theRequestDetails);
@ -768,14 +759,14 @@ public class RestfulServerUtils {
if (theContentType.equals(EncodingEnum.JSON_PLAIN_STRING) || theContentType.equals(EncodingEnum.XML_PLAIN_STRING)) {
FhirVersionEnum ctxtEnum = theCtx.getVersion().getVersion();
myNonLegacy = ctxtEnum.isNewerThan(FhirVersionEnum.DSTU3)
|| (ctxtEnum.isEquivalentTo(FhirVersionEnum.DSTU3) && !"1.4.0".equals(actualDstu3FhirVersion));
|| (ctxtEnum.isEquivalentTo(FhirVersionEnum.DSTU3) && !"1.4.0".equals(theCtx.getVersion().getVersionString()));
} else {
myNonLegacy = EncodingEnum.isNonLegacy(theContentType);
}
} else {
FhirVersionEnum ctxtEnum = theCtx.getVersion().getVersion();
if (ctxtEnum.isOlderThan(FhirVersionEnum.DSTU3)
|| (ctxtEnum.isEquivalentTo(FhirVersionEnum.DSTU3) && "1.4.0".equals(actualDstu3FhirVersion))) {
|| (ctxtEnum.isEquivalentTo(FhirVersionEnum.DSTU3) && "1.4.0".equals(theCtx.getVersion().getVersionString()))) {
myNonLegacy = null;
} else {
myNonLegacy = Boolean.TRUE;

View File

@ -405,5 +405,10 @@ public class FhirDstu1 implements IFhirVersion {
throw new UnsupportedOperationException("FluentPath is not supported in DSTU1 contexts");
}
@Override
public String getVersionString() {
return "0.0.82";
}
}

View File

@ -56,6 +56,11 @@ public class FhirDstu2 implements IFhirVersion {
private String myId;
@Override
public IFluentPath createFluentPathExecutor(FhirContext theFhirContext) {
throw new UnsupportedOperationException("FluentPath is not supported in DSTU2 contexts");
}
@Override
public ServerConformanceProvider createServerConformanceProvider(RestfulServer theServer) {
return new ServerConformanceProvider(theServer);
@ -66,6 +71,11 @@ public class FhirDstu2 implements IFhirVersion {
return new ServerProfileProvider(theRestfulServer);
}
@Override
public IContextValidationSupport<?, ?, ?, ?, ?, ?> createValidationSupport() {
throw new UnsupportedOperationException("Validation support is not supported in DSTU2 contexts");
}
@Override
public IResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition, String theServerBase) {
StructureDefinition retVal = new StructureDefinition();
@ -118,6 +128,11 @@ public class FhirDstu2 implements IFhirVersion {
return FhirVersionEnum.DSTU2;
}
@Override
public String getVersionString() {
return "1.0.2";
}
@Override
public IVersionSpecificBundleFactory newBundleFactory(FhirContext theContext) {
return new Dstu2BundleFactory(theContext);
@ -133,15 +148,5 @@ public class FhirDstu2 implements IFhirVersion {
return new IdDt();
}
@Override
public IContextValidationSupport<?, ?, ?, ?, ?, ?> createValidationSupport() {
throw new UnsupportedOperationException("Validation support is not supported in DSTU2 contexts");
}
@Override
public IFluentPath createFluentPathExecutor(FhirContext theFhirContext) {
throw new UnsupportedOperationException("FluentPath is not supported in DSTU2 contexts");
}
}

View File

@ -31,6 +31,7 @@ import org.hl7.fhir.dstu3.hapi.rest.server.ServerCapabilityStatementProvider;
import org.hl7.fhir.dstu3.hapi.rest.server.ServerProfileProvider;
import org.hl7.fhir.dstu3.hapi.validation.DefaultProfileValidationSupport;
import org.hl7.fhir.dstu3.model.Coding;
import org.hl7.fhir.dstu3.model.Constants;
import org.hl7.fhir.dstu3.model.IdType;
import org.hl7.fhir.dstu3.model.Reference;
import org.hl7.fhir.dstu3.model.Resource;
@ -57,6 +58,11 @@ public class FhirDstu3 implements IFhirVersion {
private String myId;
@Override
public IFluentPath createFluentPathExecutor(FhirContext theFhirContext) {
return new FluentPathDstu3(theFhirContext);
}
@Override
public ServerCapabilityStatementProvider createServerConformanceProvider(RestfulServer theServer) {
return new ServerCapabilityStatementProvider(theServer);
@ -67,6 +73,11 @@ public class FhirDstu3 implements IFhirVersion {
return new ServerProfileProvider(theRestfulServer);
}
@Override
public IContextValidationSupport<?, ?, ?, ?, ?, ?> createValidationSupport() {
return new DefaultProfileValidationSupport();
}
@Override
public IBaseResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition, String theServerBase) {
StructureDefinition retVal = new StructureDefinition();
@ -104,7 +115,7 @@ public class FhirDstu3 implements IFhirVersion {
public IPrimitiveType<Date> getLastUpdated(IBaseResource theResource) {
return ((Resource) theResource).getMeta().getLastUpdatedElement();
}
@Override
public String getPathToSchemaDefinitions() {
return "/org/hl7/fhir/instance/model/dstu3/schema";
@ -120,6 +131,11 @@ public class FhirDstu3 implements IFhirVersion {
return FhirVersionEnum.DSTU3;
}
@Override
public String getVersionString() {
return Constants.VERSION;
}
@Override
public IVersionSpecificBundleFactory newBundleFactory(FhirContext theContext) {
return new Dstu3BundleFactory(theContext);
@ -135,14 +151,4 @@ public class FhirDstu3 implements IFhirVersion {
return new IdType();
}
@Override
public IContextValidationSupport<?, ?, ?, ?, ?, ?> createValidationSupport() {
return new DefaultProfileValidationSupport();
}
@Override
public IFluentPath createFluentPathExecutor(FhirContext theFhirContext) {
return new FluentPathDstu3(theFhirContext);
}
}

View File

@ -213,7 +213,7 @@ public class ServerCapabilityStatementProvider implements IServerConformanceProv
retVal.setPublisher(myPublisher);
retVal.setDateElement(conformanceDate());
retVal.setFhirVersion(FhirVersionEnum.DSTU3.getFhirVersionString());
retVal.setFhirVersion(FhirVersionEnum.DSTU3.getVersionImplementation().getVersionString());
retVal.setAcceptUnknown(UnknownContentCode.EXTENSIONS); // TODO: make this configurable - this is a fairly big
// effort since the parser
// needs to be modified to actually allow it

View File

@ -216,7 +216,7 @@ public class ServerConformanceProvider implements IServerConformanceProvider<Con
retVal.setPublisher(myPublisher);
retVal.setDateElement(conformanceDate());
retVal.setFhirVersion(FhirVersionEnum.DSTU3.getFhirVersionString());
retVal.setFhirVersion(FhirVersionEnum.DSTU3.getVersionImplementation().getVersionString());
retVal.setAcceptUnknown(UnknownContentCode.EXTENSIONS); // TODO: make this configurable - this is a fairly big
// effort since the parser
// needs to be modified to actually allow it

View File

@ -337,7 +337,7 @@ public final class HapiWorkerContext implements IWorkerContext, ValueSetExpander
@Override
public String getVersion() {
return myCtx.getVersion().getVersion().getFhirVersionString();
return myCtx.getVersion().getVersionString();
}
@Override

View File

@ -1,7 +1,6 @@
package org.hl7.fhir.dstu3.model;
import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.hamcrest.Matchers.emptyOrNullString;
import java.util.Calendar;
import java.util.Date;

View File

@ -91,7 +91,7 @@ public class GenericClientDstu3Test {
}
private String expectedUserAgent() {
return "HAPI-FHIR/" + VersionUtil.getVersion() + " (FHIR Client; FHIR " + FhirVersionEnum.DSTU3.getFhirVersionString() + "/DSTU3; apache)";
return "HAPI-FHIR/" + VersionUtil.getVersion() + " (FHIR Client; FHIR " + FhirVersionEnum.DSTU3.getVersionImplementation().getVersionString() + "/DSTU3; apache)";
}
private byte[] extractBodyAsByteArray(ArgumentCaptor<HttpUriRequest> capt) throws IOException {

View File

@ -108,7 +108,7 @@ public class MetadataCapabilityStatementDstu3Test {
output = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8);
assertEquals(200, status.getStatusLine().getStatusCode());
assertThat(output, containsString("<CapabilityStatement"));
assertEquals("HAPI FHIR " + VersionUtil.getVersion() + " REST Server (FHIR Server; FHIR " + FhirVersionEnum.DSTU3.getFhirVersionString() + "/DSTU3)",
assertEquals("HAPI FHIR " + VersionUtil.getVersion() + " REST Server (FHIR Server; FHIR " + FhirVersionEnum.DSTU3.getVersionImplementation().getVersionString() + "/DSTU3)",
status.getFirstHeader("X-Powered-By").getValue());
} finally {
IOUtils.closeQuietly(status.getEntity().getContent());

View File

@ -110,7 +110,7 @@ public class MetadataConformanceDstu3Test {
output = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8);
assertEquals(200, status.getStatusLine().getStatusCode());
assertThat(output, containsString("<Conformance"));
assertEquals("HAPI FHIR " + VersionUtil.getVersion() + " REST Server (FHIR Server; FHIR " + FhirVersionEnum.DSTU3.getFhirVersionString() + "/DSTU3)", status.getFirstHeader("X-Powered-By").getValue());
assertEquals("HAPI FHIR " + VersionUtil.getVersion() + " REST Server (FHIR Server; FHIR " + FhirVersionEnum.DSTU3.getVersionImplementation().getVersionString() + "/DSTU3)", status.getFirstHeader("X-Powered-By").getValue());
} finally {
IOUtils.closeQuietly(status.getEntity().getContent());
}

View File

@ -52,11 +52,26 @@ public class FhirDstu2Hl7Org implements IFhirVersion {
private String myId;
@Override
public IFluentPath createFluentPathExecutor(FhirContext theFhirContext) {
throw new UnsupportedOperationException("FluentPath is not supported in DSTU2 contexts");
}
@Override
public ServerConformanceProvider createServerConformanceProvider(RestfulServer theServer) {
return new ServerConformanceProvider(theServer);
}
@Override
public IResourceProvider createServerProfilesProvider(RestfulServer theRestfulServer) {
return new ServerProfileProvider(theRestfulServer);
}
@Override
public IContextValidationSupport<?, ?, ?, ?, ?, ?> createValidationSupport() {
throw new UnsupportedOperationException("Validation support is not supported in DSTU2 contexts");
}
@Override
public StructureDefinition generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition, String theServerBase) {
StructureDefinition retVal = new StructureDefinition();
@ -72,14 +87,10 @@ public class FhirDstu2Hl7Org implements IFhirVersion {
return retVal;
}
@SuppressWarnings("rawtypes")
@Override
public IResourceProvider createServerProfilesProvider(RestfulServer theRestfulServer) {
return new ServerProfileProvider(theRestfulServer);
}
@Override
public FhirVersionEnum getVersion() {
return FhirVersionEnum.DSTU2_HL7ORG;
public Class<ArrayList> getContainedType() {
return ArrayList.class;
}
@Override
@ -95,6 +106,11 @@ public class FhirDstu2Hl7Org implements IFhirVersion {
return str;
}
@Override
public IPrimitiveType<Date> getLastUpdated(IBaseResource theResource) {
return ((Resource)theResource).getMeta().getLastUpdatedElement();
}
@Override
public String getPathToSchemaDefinitions() {
return "/org/hl7/fhir/instance/model/schema";
@ -105,25 +121,25 @@ public class FhirDstu2Hl7Org implements IFhirVersion {
return Reference.class;
}
@SuppressWarnings("rawtypes")
@Override
public Class<ArrayList> getContainedType() {
return ArrayList.class;
public FhirVersionEnum getVersion() {
return FhirVersionEnum.DSTU2_HL7ORG;
}
@Override
public BaseCodingDt newCodingDt() {
throw new UnsupportedOperationException();
}
@Override
public String getVersionString() {
return "1.0.2";
}
@Override
@Override
public IVersionSpecificBundleFactory newBundleFactory(FhirContext theContext) {
return new Dstu2Hl7OrgBundleFactory(theContext);
}
@Override
public IPrimitiveType<Date> getLastUpdated(IBaseResource theResource) {
return ((Resource)theResource).getMeta().getLastUpdatedElement();
@Override
public BaseCodingDt newCodingDt() {
throw new UnsupportedOperationException();
}
@Override
@ -131,16 +147,5 @@ public class FhirDstu2Hl7Org implements IFhirVersion {
return new IdType();
}
@Override
public IContextValidationSupport<?, ?, ?, ?, ?, ?> createValidationSupport() {
throw new UnsupportedOperationException("Validation support is not supported in DSTU2 contexts");
}
@Override
public IFluentPath createFluentPathExecutor(FhirContext theFhirContext) {
throw new UnsupportedOperationException("FluentPath is not supported in DSTU2 contexts");
}
}

View File

@ -113,7 +113,11 @@
that servers which receive an invalid enum velue will return
an HTTP 400 instead of an HTTP 500. Thanks to Jim
Steel for reporting!
</action>
</action>
<action type="add" issue="520">
DSTU3 context now pulls the FHIR version from the actual
model classes. Thanks to Michael Lawley for the pull request!
</action>
</release>
<release version="2.1" date="2016-11-11">
<action type="add">