From 322051a383bfd4ab9529af2161c6c97e9816a699 Mon Sep 17 00:00:00 2001 From: James Agnew Date: Sat, 14 Jan 2017 07:55:42 -0600 Subject: [PATCH] Fix failing tests --- .../ca/uhn/fhir/context/ModelScanner.java | 12 ------ .../context/RuntimeResourceDefinition.java | 15 +++++++ .../fhir/rest/gclient/TokenClientParam.java | 34 +++++++++++++++ .../uhn/fhir/rest/gclient/TokenCriterion.java | 4 ++ .../dstu3/ResourceProviderDstu3Test.java | 43 +++++++++++++++++-- .../context/ResourceWithExtensionsDstu3A.java | 20 ++------- 6 files changed, 96 insertions(+), 32 deletions(-) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/ModelScanner.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/ModelScanner.java index e2873b67c03..42776441e9a 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/ModelScanner.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/ModelScanner.java @@ -382,18 +382,6 @@ class ModelScanner { * sure that this type gets scanned as well */ resourceDef.populateScanAlso(myScanAlso); - - /* - * See #504: - * Bundle types may not have extensions - */ - if (resourceDef.hasExtensions()) { - if (IAnyResource.class.isAssignableFrom(theClass)) { - if (!IDomainResource.class.isAssignableFrom(theClass)) { - throw new ConfigurationException("Class \"" + theClass + "\" is invalid. This resource type is not a DomainResource, it must not have extensions"); - } - } - } return resourceName; } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeResourceDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeResourceDefinition.java index 16f72f5acde..e19e162e520 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeResourceDefinition.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeResourceDefinition.java @@ -28,8 +28,10 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import org.hl7.fhir.instance.model.api.IAnyResource; import org.hl7.fhir.instance.model.api.IBase; import org.hl7.fhir.instance.model.api.IBaseResource; +import org.hl7.fhir.instance.model.api.IDomainResource; import ca.uhn.fhir.model.api.annotation.ResourceDef; import ca.uhn.fhir.util.UrlUtil; @@ -203,6 +205,19 @@ public class RuntimeResourceDefinition extends BaseRuntimeElementCompositeDefini myBaseType = (Class) target; } } while (target.equals(Object.class) == false); + + /* + * See #504: + * Bundle types may not have extensions + */ + if (hasExtensions()) { + if (IAnyResource.class.isAssignableFrom(getImplementingClass())) { + if (!IDomainResource.class.isAssignableFrom(getImplementingClass())) { + throw new ConfigurationException("Class \"" + getImplementingClass() + "\" is invalid. This resource type is not a DomainResource, it must not have extensions"); + } + } + } + } @Deprecated diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/gclient/TokenClientParam.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/gclient/TokenClientParam.java index 40b6a1c5f98..91d7cc84b1f 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/gclient/TokenClientParam.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/gclient/TokenClientParam.java @@ -86,6 +86,18 @@ public class TokenClientParam extends BaseClientParam implements IParam { return new TokenCriterion(getParamName(), defaultString(theSystem), convertToList(theValues)); } + @Override + public ICriterion codes(String... theCodes) { + return new TokenCriterion(getParamName(), convertToList(theCodes)); + } + + @Override + public ICriterion codes(Collection theCodes) { + return new TokenCriterion(getParamName(), theCodes); + } + + + private List convertToList(String[] theValues) { String[] values = ObjectUtils.defaultIfNull(theValues, EMPTY_STRING_LIST); return Arrays.asList(values); @@ -126,6 +138,17 @@ public class TokenClientParam extends BaseClientParam implements IParam { ICriterion code(String theIdentifier); + /** + * Creates a search criterion that matches a given system with a collection of possible + * codes (this will be used to form a comma-separated OR query) with any system value. + * The URL form of this method will create a parameter like + * parameter=code1,code2 + * + * @param theCodes The codes + */ + ICriterion codes(Collection theCodes); + + /** * Creates a search criterion that matches against the given identifier (system and code if both are present, or whatever is present) * @@ -204,6 +227,17 @@ public class TokenClientParam extends BaseClientParam implements IParam { */ public ICriterion systemAndValues(String theSystem, Collection theValues); + + /** + * Creates a search criterion that matches a given system with a collection of possible + * codes (this will be used to form a comma-separated OR query) with any system value. + * The URL form of this method will create a parameter like + * parameter=code1,code2 + * + * @param theCodes The codes + */ + ICriterion codes(String...theCodes); + } } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/gclient/TokenCriterion.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/gclient/TokenCriterion.java index 4417a531d8d..66ff0668534 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/gclient/TokenCriterion.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/gclient/TokenCriterion.java @@ -85,6 +85,10 @@ class TokenCriterion implements ICriterion, ICriterionInternal myValue = b.toString(); } + public TokenCriterion(String theParamName, Collection theCodes) { + this(theParamName, null, theCodes); + } + @Override public String getParameterValue(FhirContext theContext) { return myValue; diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3Test.java index 08ec2719c49..341adb09a2d 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3Test.java @@ -2287,16 +2287,53 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { .search() .forResource(Patient.class) .where(BaseResource.RES_ID.exactly().systemAndValues(null, id1.getIdPart(), id2.getIdPart())) - .and(BaseResource.RES_ID.exactly().systemAndCode(null, id1.getIdPart())) .returnBundle(Bundle.class) .execute(); - assertThat(toUnqualifiedVersionlessIds(found), containsInAnyOrder(id1)); + assertThat(toUnqualifiedVersionlessIds(found), empty()); found = ourClient .search() .forResource(Patient.class) - .where(BaseResource.RES_ID.exactly().systemAndValues(null, id1.getIdPart(), id2.getIdPart())) + .where(BaseResource.RES_ID.exactly().systemAndValues(null, Arrays.asList(id1.getIdPart(), id2.getIdPart(), "FOOOOO"))) + .returnBundle(Bundle.class) + .execute(); + + assertThat(toUnqualifiedVersionlessIds(found), empty()); + + found = ourClient + .search() + .forResource(Patient.class) + .where(BaseResource.RES_ID.exactly().systemAndCode(null, id1.getIdPart())) + .returnBundle(Bundle.class) + .execute(); + + assertThat(toUnqualifiedVersionlessIds(found), empty()); + + found = ourClient + .search() + .forResource(Patient.class) + .where(BaseResource.RES_ID.exactly().codes(id1.getIdPart(), id2.getIdPart())) + .and(BaseResource.RES_ID.exactly().code(id1.getIdPart())) + .returnBundle(Bundle.class) + .execute(); + + assertThat(toUnqualifiedVersionlessIds(found), containsInAnyOrder(id1)); + + found = ourClient + .search() + .forResource(Patient.class) + .where(BaseResource.RES_ID.exactly().codes(Arrays.asList(id1.getIdPart(), id2.getIdPart(), "FOOOOO"))) + .and(BaseResource.RES_ID.exactly().code(id1.getIdPart())) + .returnBundle(Bundle.class) + .execute(); + + assertThat(toUnqualifiedVersionlessIds(found), containsInAnyOrder(id1)); + + found = ourClient + .search() + .forResource(Patient.class) + .where(BaseResource.RES_ID.exactly().codes(id1.getIdPart(), id2.getIdPart(), "FOOO")) .returnBundle(Bundle.class) .execute(); diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/context/ResourceWithExtensionsDstu3A.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/context/ResourceWithExtensionsDstu3A.java index 4fdd13f797f..c07606fec4c 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/context/ResourceWithExtensionsDstu3A.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/context/ResourceWithExtensionsDstu3A.java @@ -2,21 +2,7 @@ package ca.uhn.fhir.context; import java.util.List; -import org.hl7.fhir.dstu3.model.BaseResource; -import org.hl7.fhir.dstu3.model.CodeType; -import org.hl7.fhir.dstu3.model.CodeableConcept; -import org.hl7.fhir.dstu3.model.DateType; -import org.hl7.fhir.dstu3.model.IdType; -import org.hl7.fhir.dstu3.model.Identifier; -import org.hl7.fhir.dstu3.model.Meta; -import org.hl7.fhir.dstu3.model.Property; -import org.hl7.fhir.dstu3.model.Resource; -import org.hl7.fhir.dstu3.model.ResourceType; -import org.hl7.fhir.dstu3.model.StringType; -import org.hl7.fhir.instance.model.api.IAnyResource; -import org.hl7.fhir.instance.model.api.IBaseMetaType; -import org.hl7.fhir.instance.model.api.IIdType; -import org.hl7.fhir.instance.model.api.IPrimitiveType; +import org.hl7.fhir.dstu3.model.*; import ca.uhn.fhir.model.api.BaseIdentifiableElement; import ca.uhn.fhir.model.api.IElement; @@ -28,7 +14,7 @@ import ca.uhn.fhir.model.api.annotation.Extension; import ca.uhn.fhir.model.api.annotation.ResourceDef; @ResourceDef(name = "ResourceWithExtensionsA", id="0001") -public class ResourceWithExtensionsDstu3A extends Resource { +public class ResourceWithExtensionsDstu3A extends DomainResource { /* * NB: several unit tests depend on the structure here @@ -243,7 +229,7 @@ public class ResourceWithExtensionsDstu3A extends Resource { } @Override - public Resource copy() { + public DomainResource copy() { return null; }