diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/exceptions/ResourceGoneException.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/exceptions/ResourceGoneException.java index 28235b61d33..cda3aed4410 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/exceptions/ResourceGoneException.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/exceptions/ResourceGoneException.java @@ -9,9 +9,9 @@ package ca.uhn.fhir.rest.server.exceptions; * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDao.java index 3172a0d5626..3bd664ef406 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDao.java @@ -9,9 +9,9 @@ package ca.uhn.fhir.jpa.dao; * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/any/AnyBundle.java b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/any/AnyBundle.java new file mode 100644 index 00000000000..4492f2bebca --- /dev/null +++ b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/any/AnyBundle.java @@ -0,0 +1,110 @@ +package ca.uhn.fhir.jpa.model.any; + +/*- + * #%L + * HAPI FHIR Model + * %% + * Copyright (C) 2014 - 2019 University Health Network + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + +import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.FhirVersionEnum; +import org.apache.commons.lang3.Validate; +import org.hl7.fhir.instance.model.api.IBaseBundle; +import org.hl7.fhir.instance.model.api.IBaseResource; + +public class AnyBundle { + private final FhirVersionEnum myFhirVersion; + private final IBaseBundle myBundle; + + public static AnyBundle fromFhirContext(FhirContext theFhirContext) { + FhirVersionEnum version = theFhirContext.getVersion().getVersion(); + switch (version) { + case DSTU2: + return new AnyBundle(new ca.uhn.fhir.model.dstu2.resource.Bundle()); + case DSTU3: + return new AnyBundle(new org.hl7.fhir.dstu3.model.Bundle()); + case R4: + return new AnyBundle(new org.hl7.fhir.r4.model.Bundle()); + default: + throw new UnsupportedOperationException(version + " not supported"); + } + } + + public AnyBundle(ca.uhn.fhir.model.dstu2.resource.Bundle theBundleR2) { + myFhirVersion = FhirVersionEnum.DSTU2; + myBundle = theBundleR2; + } + + public AnyBundle(org.hl7.fhir.dstu3.model.Bundle theBundleR3) { + myFhirVersion = FhirVersionEnum.DSTU3; + myBundle = theBundleR3; + } + + public AnyBundle(org.hl7.fhir.r4.model.Bundle theBundleR4) { + myFhirVersion = FhirVersionEnum.R4; + myBundle = theBundleR4; + } + + public static AnyBundle fromResource(IBaseResource theBundle) { + if (theBundle instanceof ca.uhn.fhir.model.dstu2.resource.Bundle) { + return new AnyBundle((ca.uhn.fhir.model.dstu2.resource.Bundle) theBundle); + } else if (theBundle instanceof org.hl7.fhir.dstu3.model.Bundle) { + return new AnyBundle((org.hl7.fhir.dstu3.model.Bundle) theBundle); + } else if (theBundle instanceof org.hl7.fhir.r4.model.Bundle) { + return new AnyBundle((org.hl7.fhir.r4.model.Bundle) theBundle); + } else { + throw new UnsupportedOperationException("Cannot convert " + theBundle.getClass().getName() + " to AnyBundle"); + } + } + + public IBaseBundle get() { + return myBundle; + } + + public ca.uhn.fhir.model.dstu2.resource.Bundle getDstu2() { + Validate.isTrue(myFhirVersion == FhirVersionEnum.DSTU2); + return (ca.uhn.fhir.model.dstu2.resource.Bundle) get(); + } + + public org.hl7.fhir.dstu3.model.Bundle getDstu3() { + Validate.isTrue(myFhirVersion == FhirVersionEnum.DSTU3); + return (org.hl7.fhir.dstu3.model.Bundle) get(); + } + + public org.hl7.fhir.r4.model.Bundle getR4() { + Validate.isTrue(myFhirVersion == FhirVersionEnum.R4); + return (org.hl7.fhir.r4.model.Bundle) get(); + } + + public void addResource(IBaseResource theResource) { + switch (myFhirVersion) { + case DSTU3: + org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent entry = new org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent(); + entry.setResource((org.hl7.fhir.dstu3.model.Resource) theResource); + getDstu3().getEntry().add(entry); + break; + case R4: + org.hl7.fhir.r4.model.Bundle.BundleEntryComponent entryr4 = new org.hl7.fhir.r4.model.Bundle.BundleEntryComponent(); + entryr4.setResource((org.hl7.fhir.r4.model.Resource) theResource); + getR4().getEntry().add(entryr4); + break; + default: + throw new UnsupportedOperationException(myFhirVersion + " not supported"); + } + + } +} diff --git a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/config/SearchParamR4Config.java b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/config/SearchParamR4Config.java index 9b1e9897bae..97b33256e8e 100644 --- a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/config/SearchParamR4Config.java +++ b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/config/SearchParamR4Config.java @@ -53,10 +53,4 @@ public class SearchParamR4Config extends BaseSearchParamConfig { public SearchParamExtractorR4 searchParamExtractor() { return new SearchParamExtractorR4(); } - - @Primary - @Bean(autowire = Autowire.BY_NAME, name = "myJpaValidationSupportChainR4") - public IValidationSupport validationSupportChainR4() { - return new DefaultProfileValidationSupport(); - } } diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/config/SubscriptionR4Config.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/config/SubscriptionR4Config.java index 5c758a15fd6..9176dd3bac5 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/config/SubscriptionR4Config.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/config/SubscriptionR4Config.java @@ -21,8 +21,19 @@ package ca.uhn.fhir.jpa.subscription.module.config; */ import ca.uhn.fhir.jpa.searchparam.config.SearchParamR4Config; +import org.hl7.fhir.r4.hapi.ctx.DefaultProfileValidationSupport; +import org.hl7.fhir.r4.hapi.ctx.IValidationSupport; +import org.springframework.beans.factory.annotation.Autowire; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Import; +import org.springframework.context.annotation.Primary; @Import({SearchParamR4Config.class}) public class SubscriptionR4Config extends BaseSubscriptionConfig { + + @Primary + @Bean(autowire = Autowire.BY_NAME, name = "myJpaValidationSupportChainR4") + public IValidationSupport validationSupportChainR4() { + return new DefaultProfileValidationSupport(); + } } diff --git a/hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/LoggingRule.java b/hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/LoggingRule.java index cd96bb3a750..929da8f6826 100644 --- a/hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/LoggingRule.java +++ b/hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/LoggingRule.java @@ -16,6 +16,26 @@ package ca.uhn.fhir.test.utilities; +/*- + * #%L + * HAPI FHIR Test Utilities + * %% + * Copyright (C) 2014 - 2019 University Health Network + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + import org.junit.rules.TestRule; import org.junit.runner.Description; import org.junit.runners.model.Statement;