From 0d00954852711f9a43f67e8bd67c0f63cb7e13c5 Mon Sep 17 00:00:00 2001 From: Marcelo Avancini Date: Tue, 2 Feb 2021 16:25:07 -0300 Subject: [PATCH] Added @Inherited to ResourceDef annotation (#2340) This change avoids duplication of ResourceDef on custom resources, where there is no changes on resource name or profile. --- .../model/api/annotation/ResourceDef.java | 2 ++ .../fhir/context/ModelScannerDstu3Test.java | 26 ++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/annotation/ResourceDef.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/annotation/ResourceDef.java index 83455a7510c..19b5634da72 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/annotation/ResourceDef.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/annotation/ResourceDef.java @@ -21,6 +21,7 @@ package ca.uhn.fhir.model.api.annotation; */ import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; @@ -28,6 +29,7 @@ import java.lang.annotation.Target; /** * Class annotation which indicates a resource definition class */ +@Inherited @Retention(RetentionPolicy.RUNTIME) @Target(value= {ElementType.TYPE}) public @interface ResourceDef { diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/context/ModelScannerDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/context/ModelScannerDstu3Test.java index 85724c4a12e..b938320d5a7 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/context/ModelScannerDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/context/ModelScannerDstu3Test.java @@ -13,6 +13,7 @@ import ca.uhn.fhir.util.TestUtil; import org.hl7.fhir.dstu3.model.Binary; import org.hl7.fhir.dstu3.model.CarePlan; import org.hl7.fhir.dstu3.model.CodeType; +import org.hl7.fhir.dstu3.model.DomainResource; import org.hl7.fhir.dstu3.model.IdType; import org.hl7.fhir.dstu3.model.Meta; import org.hl7.fhir.dstu3.model.Patient; @@ -89,6 +90,15 @@ public class ModelScannerDstu3Test { } } + @Test + public void testResourceWithInheritedDef() { + try { + FhirContext.forDstu3().getResourceDefinition(InheritedResourceDef.class); + } catch (ConfigurationException e) { + fail("The InheritedResourceDef class should contain a valid HAPI-FHIR annotation inherited from superclass"); + } + } + @Test public void testScanExtensionTypes() throws DataFormatException { @@ -238,11 +248,25 @@ public class ModelScannerDstu3Test { } } - class NoResourceDef extends Patient { + class NoResourceDef extends DomainResource { @SearchParamDefinition(name = "foo", path = "Patient.telecom", type = "bar") public static final String SP_TELECOM = "foo"; private static final long serialVersionUID = 1L; + @Override + public DomainResource copy() { + return null; + } + + @Override + public ResourceType getResourceType() { + return null; + } + } + + static class InheritedResourceDef extends Patient { + public InheritedResourceDef() { + } } @ResourceDef(name = "Patient")