diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/FhirContext.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/FhirContext.java index acc1f898574..796c9f7392e 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/FhirContext.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/FhirContext.java @@ -1293,7 +1293,15 @@ public class FhirContext { * @since 5.1.0 */ public static FhirContext forCached(FhirVersionEnum theFhirVersionEnum) { - return ourStaticContexts.computeIfAbsent(theFhirVersionEnum, v -> new FhirContext(v)); + return ourStaticContexts.computeIfAbsent(theFhirVersionEnum, FhirContext::forVersion); + } + + /** + * An uncached version of forCached() + * @return a new FhirContext for theFhirVersionEnum + */ + public static FhirContext forVersion(FhirVersionEnum theFhirVersionEnum) { + return new FhirContext(theFhirVersionEnum); } private static Collection> toCollection( diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/FhirVersionEnum.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/FhirVersionEnum.java index 8666fd77ce0..2c3e0082bcf 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/FhirVersionEnum.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/FhirVersionEnum.java @@ -135,15 +135,19 @@ public enum FhirVersionEnum { /** * Creates a new FhirContext for this FHIR version + * @deprecated since 7.7. Use {@link FhirContext#forVersion(FhirVersionEnum)} instead */ + @Deprecated(forRemoval = true, since = "7.7") public FhirContext newContext() { - return new FhirContext(this); + return FhirContext.forVersion(this); } /** * Creates a new FhirContext for this FHIR version, or returns a previously created one if one exists. This * method uses {@link FhirContext#forCached(FhirVersionEnum)} to return a cached instance. + * @deprecated since 7.7. Use {@link FhirContext#forCached(FhirVersionEnum)} instead */ + @Deprecated(forRemoval = true, since = "7.7") public FhirContext newContextCached() { return FhirContext.forCached(this); } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/narrative2/NarrativeGeneratorTemplateUtils.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/narrative2/NarrativeGeneratorTemplateUtils.java index 21cdab2dcde..a6a9406d72b 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/narrative2/NarrativeGeneratorTemplateUtils.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/narrative2/NarrativeGeneratorTemplateUtils.java @@ -20,6 +20,7 @@ package ca.uhn.fhir.narrative2; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.util.BundleUtil; import org.apache.commons.lang3.tuple.Pair; import org.hl7.fhir.instance.model.api.IBaseBundle; @@ -42,7 +43,8 @@ public class NarrativeGeneratorTemplateUtils { * Given a Bundle as input, are any entries present with a given resource type */ public boolean bundleHasEntriesWithResourceType(IBaseBundle theBaseBundle, String theResourceType) { - FhirContext ctx = theBaseBundle.getStructureFhirVersionEnum().newContextCached(); + FhirVersionEnum fhirVersionEnum = theBaseBundle.getStructureFhirVersionEnum(); + FhirContext ctx = FhirContext.forCached(fhirVersionEnum); List> entryResources = BundleUtil.getBundleEntryUrlsAndResources(ctx, theBaseBundle); return entryResources.stream() diff --git a/hapi-fhir-cli/hapi-fhir-cli-api/src/main/java/ca/uhn/fhir/cli/BaseCommand.java b/hapi-fhir-cli/hapi-fhir-cli-api/src/main/java/ca/uhn/fhir/cli/BaseCommand.java index be49c375f4e..0077accc776 100644 --- a/hapi-fhir-cli/hapi-fhir-cli-api/src/main/java/ca/uhn/fhir/cli/BaseCommand.java +++ b/hapi-fhir-cli/hapi-fhir-cli-api/src/main/java/ca/uhn/fhir/cli/BaseCommand.java @@ -668,7 +668,7 @@ public abstract class BaseCommand implements Comparable { protected void parseFhirContext(CommandLine theCommandLine) throws ParseException { FhirVersionEnum versionEnum = parseFhirVersion(theCommandLine); - myFhirCtx = versionEnum.newContext(); + myFhirCtx = FhirContext.forVersion(versionEnum); } public abstract void run(CommandLine theCommandLine) throws ParseException, ExecutionException; diff --git a/hapi-fhir-converter/src/main/java/ca/uhn/hapi/converters/canonical/VersionCanonicalizer.java b/hapi-fhir-converter/src/main/java/ca/uhn/hapi/converters/canonical/VersionCanonicalizer.java index 0a01892f056..25c8ab333c1 100644 --- a/hapi-fhir-converter/src/main/java/ca/uhn/hapi/converters/canonical/VersionCanonicalizer.java +++ b/hapi-fhir-converter/src/main/java/ca/uhn/hapi/converters/canonical/VersionCanonicalizer.java @@ -98,7 +98,7 @@ public class VersionCanonicalizer { private final FhirContext myContext; public VersionCanonicalizer(FhirVersionEnum theTargetVersion) { - this(theTargetVersion.newContextCached()); + this(FhirContext.forCached(theTargetVersion)); } public VersionCanonicalizer(FhirContext theTargetContext) { diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_8_0/6512-snip-fhir-context.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_8_0/6512-snip-fhir-context.yaml new file mode 100644 index 00000000000..71d35b1adf4 --- /dev/null +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_8_0/6512-snip-fhir-context.yaml @@ -0,0 +1,4 @@ +--- +type: remove +issue: 6512 +title: "The methods on FhirVersionEnum which produces a FhirContext (newContext() ,and newContextCached()) have been deprecated, and will be removed." diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/RestfulServerUtils.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/RestfulServerUtils.java index a88e50327b6..8477293b90b 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/RestfulServerUtils.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/RestfulServerUtils.java @@ -686,7 +686,7 @@ public class RestfulServerUtils { if (context.getVersion().getVersion() != theForVersion) { context = myFhirContextMap.get(theForVersion); if (context == null) { - context = theForVersion.newContext(); + context = FhirContext.forVersion(theForVersion); myFhirContextMap.put(theForVersion, context); } } diff --git a/hapi-fhir-testpage-overlay/src/main/java/ca/uhn/fhir/to/BaseController.java b/hapi-fhir-testpage-overlay/src/main/java/ca/uhn/fhir/to/BaseController.java index f51dc5a4500..ba607ace1d9 100644 --- a/hapi-fhir-testpage-overlay/src/main/java/ca/uhn/fhir/to/BaseController.java +++ b/hapi-fhir-testpage-overlay/src/main/java/ca/uhn/fhir/to/BaseController.java @@ -297,7 +297,7 @@ public class BaseController { FhirVersionEnum version = theRequest.getFhirVersion(myConfig); VersionCanonicalizer retVal = myCanonicalizers.get(version); if (retVal == null) { - retVal = new VersionCanonicalizer(version.newContext()); + retVal = new VersionCanonicalizer(FhirContext.forVersion(version)); myCanonicalizers.put(version, retVal); } return retVal;