diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/ResourceMetadataKeyEnum.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/ResourceMetadataKeyEnum.java index 12e8f3091ab..a4dd53ff6ce 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/ResourceMetadataKeyEnum.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/ResourceMetadataKeyEnum.java @@ -27,19 +27,13 @@ import ca.uhn.fhir.model.primitive.InstantDt; import ca.uhn.fhir.model.valueset.BundleEntrySearchModeEnum; import ca.uhn.fhir.model.valueset.BundleEntryTransactionMethodEnum; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; -import org.apache.commons.lang3.StringUtils; import org.hl7.fhir.instance.model.api.IAnyResource; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IPrimitiveType; import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collections; import java.util.Date; import java.util.List; -import java.util.Map; - -import static org.apache.commons.lang3.StringUtils.isNotBlank; /** * Keys in this map refer to resource metadata keys, which are keys used to access information about specific resource instances that live outside of the resource body. Typically, these are @@ -65,23 +59,6 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank; */ public abstract class ResourceMetadataKeyEnum implements Serializable { - // TODO: JA - Replace all of the various other get/put methods in subclasses with just using the two that are here - public T get(IBaseResource theResource) { - if (theResource instanceof IAnyResource) { - return (T) theResource.getUserData(name()); - } else { - return (T) ((IResource)theResource).getResourceMetadata().get(this); - } - } - - public void put(IBaseResource theResource, T theValue) { - if (theResource instanceof IAnyResource) { - theResource.setUserData(name(), theValue); - } else { - ((IResource)theResource).getResourceMetadata().put(this, theValue); - } - } - /** * If present and populated with a date/time (as an instance of {@link InstantDt}), this value is an indication that the resource is in the deleted state. This key is only used in a limited number * of scenarios, such as POSTing transaction bundles to a server, or returning resource history. @@ -89,21 +66,8 @@ public abstract class ResourceMetadataKeyEnum implements Serializable { * Values for this key are of type {@link InstantDt} *

*/ - public static final ResourceMetadataKeyEnum> DELETED_AT = new ResourceMetadataKeyEnum<>("DELETED_AT") { - private static final long serialVersionUID = 1L; - - @Override - public IPrimitiveType get(IResource theResource) { - return (IPrimitiveType) theResource.getResourceMetadata().get(this); - } - - @Override - public void put(IResource theResource, IPrimitiveType theObject) { - theResource.getResourceMetadata().put(this, theObject); - } - + public static final ResourceMetadataKeyEnum> DELETED_AT = new ResourceMetadataKeyEnum<>("DELETED_AT", IPrimitiveType.class) { }; - /** * If present and populated with a {@link BundleEntrySearchModeEnum}, contains the "bundle entry search mode", which is the value of the status field in the Bundle entry containing this resource. * The value for this key corresponds to field Bundle.entry.search.mode. This value can be set to provide a status value of "include" for included resources being returned by a @@ -115,28 +79,7 @@ public abstract class ResourceMetadataKeyEnum implements Serializable { * Values for this key are of type {@link BundleEntrySearchModeEnum} *

*/ - public static final ResourceMetadataKeySupportingAnyResource ENTRY_SEARCH_MODE = new ResourceMetadataKeySupportingAnyResource("ENTRY_SEARCH_MODE") { - private static final long serialVersionUID = 1L; - - @Override - public BundleEntrySearchModeEnum get(IResource theResource) { - return getEnumFromMetadataOrNullIfNone(theResource.getResourceMetadata(), ENTRY_SEARCH_MODE, BundleEntrySearchModeEnum.class, BundleEntrySearchModeEnum.VALUESET_BINDER); - } - - @Override - public String get(IAnyResource theResource) { - return (String) theResource.getUserData(ENTRY_SEARCH_MODE.name()); - } - - @Override - public void put(IResource theResource, BundleEntrySearchModeEnum theObject) { - theResource.getResourceMetadata().put(ENTRY_SEARCH_MODE, theObject); - } - - @Override - public void put(IAnyResource theResource, String theObject) { - theResource.setUserData(ENTRY_SEARCH_MODE.name(), theObject); - } + public static final ResourceMetadataKeyEnum ENTRY_SEARCH_MODE = new ResourceMetadataKeyEnum<>("ENTRY_SEARCH_MODE", BundleEntrySearchModeEnum.class) { }; /** * If present and populated with a {@link BundleEntryTransactionMethodEnum}, contains the "bundle entry transaction operation", which is the value of the status field in the Bundle entry @@ -150,33 +93,8 @@ public abstract class ResourceMetadataKeyEnum implements Serializable { * Values for this key are of type {@link BundleEntryTransactionMethodEnum} *

*/ - public static final ResourceMetadataKeySupportingAnyResource ENTRY_TRANSACTION_METHOD = new ResourceMetadataKeySupportingAnyResource( - "ENTRY_TRANSACTION_OPERATION") { - private static final long serialVersionUID = 1L; - - @Override - public BundleEntryTransactionMethodEnum get(IResource theResource) { - return getEnumFromMetadataOrNullIfNone(theResource.getResourceMetadata(), ENTRY_TRANSACTION_METHOD, BundleEntryTransactionMethodEnum.class, - BundleEntryTransactionMethodEnum.VALUESET_BINDER); - } - - @Override - public String get(IAnyResource theResource) { - return (String) theResource.getUserData(ENTRY_TRANSACTION_METHOD.name()); - } - - @Override - public void put(IResource theResource, BundleEntryTransactionMethodEnum theObject) { - theResource.getResourceMetadata().put(ENTRY_TRANSACTION_METHOD, theObject); - } - - @Override - public void put(IAnyResource theResource, String theObject) { - theResource.setUserData(ENTRY_TRANSACTION_METHOD.name(), theObject); - } - + public static final ResourceMetadataKeyEnum ENTRY_TRANSACTION_METHOD = new ResourceMetadataKeyEnum<>("ENTRY_TRANSACTION_OPERATION", BundleEntryTransactionMethodEnum.class) { }; - /** * The value for this key represents a {@link List} of profile IDs that this resource claims to conform to. *

@@ -184,18 +102,7 @@ public abstract class ResourceMetadataKeyEnum implements Serializable { * Values for this key are of type List<IdDt>. Note that the returned list is unmodifiable, so you need to create a new list and call put to change its value. *

*/ - public static final ResourceMetadataKeyEnum> PROFILES = new ResourceMetadataKeyEnum>("PROFILES") { - private static final long serialVersionUID = 1L; - - @Override - public List get(IResource theResource) { - return getIdListFromMetadataOrNullIfNone(theResource.getResourceMetadata(), PROFILES); - } - - @Override - public void put(IResource theResource, List theObject) { - theResource.getResourceMetadata().put(PROFILES, theObject); - } + public static final ResourceMetadataKeyEnum> PROFILES = new ResourceMetadataKeyEnum<>("PROFILES", List.class) { }; /** * The value for this key is the bundle entry Published time. This is defined by FHIR as "Time resource copied into the feed", which is generally best left to the current time. @@ -208,37 +115,9 @@ public abstract class ResourceMetadataKeyEnum implements Serializable { * * @see InstantDt */ - public static final ResourceMetadataKeyEnum PUBLISHED = new ResourceMetadataKeyEnum("PUBLISHED") { - private static final long serialVersionUID = 1L; - - @Override - public InstantDt get(IResource theResource) { - return getInstantFromMetadataOrNullIfNone(theResource.getResourceMetadata(), PUBLISHED); - } - - @Override - public void put(IResource theResource, InstantDt theObject) { - theResource.getResourceMetadata().put(PUBLISHED, theObject); - } + public static final ResourceMetadataKeyEnum PUBLISHED = new ResourceMetadataKeyEnum<>("PUBLISHED", InstantDt.class) { }; - public static final ResourceMetadataKeyEnum> SECURITY_LABELS = new ResourceMetadataKeyEnum>("SECURITY_LABELS") { - private static final long serialVersionUID = 1L; - - @Override - public List get(IResource resource) { - Object obj = resource.getResourceMetadata().get(SECURITY_LABELS); - if (obj == null) { - return null; - } - //noinspection unchecked - return (List) obj; - } - - @Override - public void put(IResource iResource, List labels) { - iResource.getResourceMetadata().put(SECURITY_LABELS, labels); - } - + public static final ResourceMetadataKeyEnum> SECURITY_LABELS = new ResourceMetadataKeyEnum<>("SECURITY_LABELS", List.class) { }; /** * The value for this key is the list of tags associated with this resource @@ -248,23 +127,7 @@ public abstract class ResourceMetadataKeyEnum implements Serializable { * * @see TagList */ - public static final ResourceMetadataKeyEnum TAG_LIST = new ResourceMetadataKeyEnum("TAG_LIST") { - private static final long serialVersionUID = 1L; - - @Override - public TagList get(IResource theResource) { - Object retValObj = theResource.getResourceMetadata().get(TAG_LIST); - if (retValObj == null) { - return null; - } else { - return (TagList) retValObj; - } - } - - @Override - public void put(IResource theResource, TagList theObject) { - theResource.getResourceMetadata().put(TAG_LIST, theObject); - } + public static final ResourceMetadataKeyEnum TAG_LIST = new ResourceMetadataKeyEnum<>("TAG_LIST", TagList.class) { }; /** * The value for this key is the bundle entry Updated time. This is defined by FHIR as "Last Updated for resource". This value is also used for populating the "Last-Modified" header in the @@ -275,18 +138,7 @@ public abstract class ResourceMetadataKeyEnum implements Serializable { * * @see InstantDt */ - public static final ResourceMetadataKeyEnum UPDATED = new ResourceMetadataKeyEnum("UPDATED") { - private static final long serialVersionUID = 1L; - - @Override - public InstantDt get(IResource theResource) { - return getInstantFromMetadataOrNullIfNone(theResource.getResourceMetadata(), UPDATED); - } - - @Override - public void put(IResource theResource, InstantDt theObject) { - theResource.getResourceMetadata().put(UPDATED, theObject); - } + public static final ResourceMetadataKeyEnum UPDATED = new ResourceMetadataKeyEnum<>("UPDATED", InstantDt.class) { }; /** * The value for this key is the version ID of the resource object. @@ -297,18 +149,7 @@ public abstract class ResourceMetadataKeyEnum implements Serializable { * @deprecated The {@link IResource#getId()} resource ID will now be populated with the version ID via the {@link IdDt#getVersionIdPart()} method */ @Deprecated - public static final ResourceMetadataKeyEnum VERSION = new ResourceMetadataKeyEnum("VERSION") { - private static final long serialVersionUID = 1L; - - @Override - public String get(IResource theResource) { - return getStringFromMetadataOrNullIfNone(theResource.getResourceMetadata(), VERSION); - } - - @Override - public void put(IResource theResource, String theObject) { - theResource.getResourceMetadata().put(VERSION, theObject); - } + public static final ResourceMetadataKeyEnum VERSION = new ResourceMetadataKeyEnum<>("VERSION", String.class) { }; /** * The value for this key is the version ID of the resource object. @@ -319,24 +160,48 @@ public abstract class ResourceMetadataKeyEnum implements Serializable { * @deprecated The {@link IResource#getId()} resource ID will now be populated with the version ID via the {@link IdDt#getVersionIdPart()} method */ @Deprecated - public static final ResourceMetadataKeyEnum VERSION_ID = new ResourceMetadataKeyEnum("VERSION_ID") { - private static final long serialVersionUID = 1L; - - @Override - public IdDt get(IResource theResource) { - return getIdFromMetadataOrNullIfNone(theResource.getResourceMetadata()); - } - - @Override - public void put(IResource theResource, IdDt theObject) { - theResource.getResourceMetadata().put(VERSION_ID, theObject); - } + public static final ResourceMetadataKeyEnum VERSION_ID = new ResourceMetadataKeyEnum<>("VERSION_ID", IdDt.class) { }; private static final long serialVersionUID = 1L; private final String myValue; + private final Class myType; - public ResourceMetadataKeyEnum(String theValue) { + public ResourceMetadataKeyEnum(String theValue, Class theType) { myValue = theValue; + myType = theType; + } + + // TODO: JA - Replace all of the various other get/put methods in subclasses with just using the two that are here + public T get(IBaseResource theResource) { + Object retVal; + if (theResource instanceof IAnyResource) { + retVal = theResource.getUserData(name()); + } else { + retVal = ((IResource) theResource).getResourceMetadata().get(this); + } + + if (retVal != null && !myType.isAssignableFrom(retVal.getClass())) { + throw new InternalErrorException(Msg.code(1890) + "Found an object of type '" + retVal.getClass().getCanonicalName() + + "' in resource metadata for key " + this.name() + " - Expected " + + myType.getCanonicalName()); + } + + //noinspection unchecked + return (T) retVal; + } + + public void put(IBaseResource theResource, T theValue) { + if (theValue != null && !myType.isAssignableFrom(theValue.getClass())) { + throw new InternalErrorException(Msg.code(1891) + "Can not put object of type '" + theValue.getClass().getCanonicalName() + + "' in resource metadata for key " + this.name() + " - Expected " + + myType.getCanonicalName()); + } + + if (theResource instanceof IAnyResource) { + theResource.setUserData(name(), theValue); + } else { + ((IResource) theResource).getResourceMetadata().put(this, theValue); + } } @Override @@ -349,15 +214,10 @@ public abstract class ResourceMetadataKeyEnum implements Serializable { return false; ResourceMetadataKeyEnum other = (ResourceMetadataKeyEnum) obj; if (myValue == null) { - if (other.myValue != null) - return false; - } else if (!myValue.equals(other.myValue)) - return false; - return true; + return other.myValue == null; + } else return myValue.equals(other.myValue); } - public abstract T get(IResource theResource); - @Override public int hashCode() { final int prime = 31; @@ -370,138 +230,9 @@ public abstract class ResourceMetadataKeyEnum implements Serializable { return myValue; } - public abstract void put(IResource theResource, T theObject); - - public static abstract class ResourceMetadataKeySupportingAnyResource extends ResourceMetadataKeyEnum { - - private static final long serialVersionUID = 1L; - - public ResourceMetadataKeySupportingAnyResource(String theValue) { - super(theValue); - } - - public abstract T2 get(IAnyResource theResource); - - public abstract void put(IAnyResource theResource, T2 theObject); - - } - public static final class ExtensionResourceMetadataKey extends ResourceMetadataKeyEnum { public ExtensionResourceMetadataKey(String theUrl) { - super(theUrl); - } - - @Override - public ExtensionDt get(IResource theResource) { - Object retValObj = theResource.getResourceMetadata().get(this); - if (retValObj == null) { - return null; - } else if (retValObj instanceof ExtensionDt) { - return (ExtensionDt) retValObj; - } - throw new InternalErrorException(Msg.code(1890) + "Found an object of type '" + retValObj.getClass().getCanonicalName() - + "' in resource metadata for key " + this.name() + " - Expected " - + ExtensionDt.class.getCanonicalName()); - } - - @Override - public void put(IResource theResource, ExtensionDt theObject) { - theResource.getResourceMetadata().put(this, theObject); + super(theUrl, ExtensionDt.class); } } - - - @SuppressWarnings("unchecked") - private static > T getEnumFromMetadataOrNullIfNone(Map, Object> theResourceMetadata, ResourceMetadataKeyEnum theKey, Class theEnumType, - IValueSetEnumBinder theBinder) { - Object retValObj = theResourceMetadata.get(theKey); - if (retValObj == null) { - return null; - } else if (theEnumType.equals(retValObj.getClass())) { - return (T) retValObj; - } else if (retValObj instanceof String) { - return theBinder.fromCodeString((String) retValObj); - } - throw new InternalErrorException(Msg.code(1891) + "Found an object of type '" + retValObj.getClass().getCanonicalName() + "' in resource metadata for key " + theKey.name() + " - Expected " - + InstantDt.class.getCanonicalName()); - } - - private static IdDt getIdFromMetadataOrNullIfNone(Map, Object> theResourceMetadata) { - return toId(ResourceMetadataKeyEnum.VERSION_ID, theResourceMetadata.get(ResourceMetadataKeyEnum.VERSION_ID)); - } - - private static List getIdListFromMetadataOrNullIfNone(Map, Object> theResourceMetadata, ResourceMetadataKeyEnum theKey) { - Object retValObj = theResourceMetadata.get(theKey); - if (retValObj == null) { - return null; - } else if (retValObj instanceof List) { - List retValList = (List) retValObj; - for (Object next : retValList) { - if (!(next instanceof IdDt)) { - List retVal = new ArrayList(); - for (Object nextVal : retValList) { - retVal.add(toId(theKey, nextVal)); - } - return Collections.unmodifiableList(retVal); - } - } - @SuppressWarnings("unchecked") - List retVal = (List) retValList; - return Collections.unmodifiableList(retVal); - } else { - return Collections.singletonList(toId(theKey, retValObj)); - } - } - - private static InstantDt getInstantFromMetadataOrNullIfNone(Map, Object> theResourceMetadata, ResourceMetadataKeyEnum theKey) { - Object retValObj = theResourceMetadata.get(theKey); - if (retValObj == null) { - return null; - } else if (retValObj instanceof Date) { - return new InstantDt((Date) retValObj); - } else if (retValObj instanceof InstantDt) { - if (((InstantDt) retValObj).isEmpty()) { - return null; - } - return (InstantDt) retValObj; - } - throw new InternalErrorException(Msg.code(1892) + "Found an object of type '" + retValObj.getClass().getCanonicalName() + "' in resource metadata for key " + theKey.name() + " - Expected " - + InstantDt.class.getCanonicalName()); - } - - private static String getStringFromMetadataOrNullIfNone(Map, Object> theResourceMetadata, ResourceMetadataKeyEnum theKey) { - Object retValObj = theResourceMetadata.get(theKey); - if (retValObj == null) { - return null; - } else if (retValObj instanceof String) { - if (StringUtils.isBlank(((String) retValObj))) { - return null; - } - return (String) retValObj; - } - throw new InternalErrorException(Msg.code(1893) + "Found an object of type '" + retValObj.getClass().getCanonicalName() + "' in resource metadata for key " + theKey.name() + " - Expected " - + String.class.getCanonicalName()); - } - - private static IdDt toId(ResourceMetadataKeyEnum theKey, Object retValObj) { - if (retValObj == null) { - return null; - } else if (retValObj instanceof String) { - if (isNotBlank((String) retValObj)) { - return new IdDt((String) retValObj); - } - return null; - } else if (retValObj instanceof IdDt) { - if (((IdDt) retValObj).isEmpty()) { - return null; - } - return (IdDt) retValObj; - } else if (retValObj instanceof Number) { - return new IdDt(retValObj.toString()); - } - throw new InternalErrorException(Msg.code(1894) + "Found an object of type '" + retValObj.getClass().getCanonicalName() + "' in resource metadata for key " + theKey.name() + " - Expected " - + IdDt.class.getCanonicalName()); - } - - } diff --git a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/impl/GenericClient.java b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/impl/GenericClient.java index caec3d04e7a..6e33997f9d7 100644 --- a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/impl/GenericClient.java +++ b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/impl/GenericClient.java @@ -2206,28 +2206,15 @@ public class GenericClient extends BaseClient implements IGenericClient { Validate.notNull(theResources, "theResources must not be null"); for (IBaseResource next : theResources) { - String entryMethod = null; - if (next instanceof IResource) { - BundleEntryTransactionMethodEnum entryMethodEnum = ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.get((IResource) next); - if (entryMethodEnum != null) { - entryMethod = entryMethodEnum.getCode(); - } - } else { - entryMethod = ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.get((IAnyResource) next); - } + BundleEntryTransactionMethodEnum entryMethod = ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.get(next); - if (isBlank(entryMethod)) { + if (entryMethod == null) { if (isBlank(next.getIdElement().getValue())) { - entryMethod = "POST"; + entryMethod = BundleEntryTransactionMethodEnum.POST; } else { - entryMethod = "PUT"; + entryMethod = BundleEntryTransactionMethodEnum.PUT; } - if (next instanceof IResource) { - ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.put((IResource) next, BundleEntryTransactionMethodEnum.valueOf(entryMethod)); - } else { - ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.put((IAnyResource) next, entryMethod); - } - + ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.put(next, entryMethod); } } @@ -2305,7 +2292,7 @@ public class GenericClient extends BaseClient implements IGenericClient { OutcomeResponseHandler binding = new OutcomeResponseHandler(myPrefer); - Map> params = new HashMap>(); + Map> params = new HashMap<>(); return invoke(params, binding, invocation); } @@ -2362,7 +2349,7 @@ public class GenericClient extends BaseClient implements IGenericClient { @Override public MethodOutcome execute() { BaseHttpClientInvocation invocation = ValidateMethodBindingDstu2Plus.createValidateInvocation(myContext, myResource); - ResourceResponseHandler handler = new ResourceResponseHandler(null, null); + ResourceResponseHandler handler = new ResourceResponseHandler<>(null, null); IBaseOperationOutcome outcome = invoke(null, handler, invocation); MethodOutcome retVal = new MethodOutcome(); retVal.setOperationOutcome(outcome); @@ -2486,7 +2473,7 @@ public class GenericClient extends BaseClient implements IGenericClient { private static void addParam(Map> params, String parameterName, String parameterValue) { if (!params.containsKey(parameterName)) { - params.put(parameterName, new ArrayList()); + params.put(parameterName, new ArrayList<>()); } params.get(parameterName).add(parameterValue); } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/JpaStorageResourceParser.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/JpaStorageResourceParser.java index 438a6097290..45e53ec091a 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/JpaStorageResourceParser.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/JpaStorageResourceParser.java @@ -387,7 +387,7 @@ public class JpaStorageResourceParser implements IJpaStorageResourceParser { retVal = (R) res; ResourceMetadataKeyEnum.DELETED_AT.put(res, new InstantDt(theEntity.getDeleted())); if (theForHistoryOperation) { - ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.put(res, Bundle.HTTPVerb.DELETE.toCode()); + ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.put(res, BundleEntryTransactionMethodEnum.DELETE); } } else if (theForHistoryOperation) { /* @@ -396,9 +396,9 @@ public class JpaStorageResourceParser implements IJpaStorageResourceParser { Date published = theEntity.getPublished().getValue(); Date updated = theEntity.getUpdated().getValue(); if (published.equals(updated)) { - ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.put(res, Bundle.HTTPVerb.POST.toCode()); + ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.put(res, BundleEntryTransactionMethodEnum.POST); } else { - ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.put(res, Bundle.HTTPVerb.PUT.toCode()); + ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.put(res, BundleEntryTransactionMethodEnum.PUT); } } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/PersistedJpaSearchFirstPageBundleProvider.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/PersistedJpaSearchFirstPageBundleProvider.java index 64e83a343c9..f1d9be88b5c 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/PersistedJpaSearchFirstPageBundleProvider.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/PersistedJpaSearchFirstPageBundleProvider.java @@ -42,9 +42,9 @@ import java.util.stream.Collectors; public class PersistedJpaSearchFirstPageBundleProvider extends PersistedJpaBundleProvider { private static final Logger ourLog = LoggerFactory.getLogger(PersistedJpaSearchFirstPageBundleProvider.class); - private SearchTask mySearchTask; - private ISearchBuilder mySearchBuilder; - private Search mySearch; + private final SearchTask mySearchTask; + private final ISearchBuilder mySearchBuilder; + private final Search mySearch; /** * Constructor @@ -105,10 +105,7 @@ public class PersistedJpaSearchFirstPageBundleProvider extends PersistedJpaBundl } private boolean isInclude(IBaseResource theResource) { - if (theResource instanceof IAnyResource) { - return "include".equals(ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.get(((IAnyResource) theResource))); - } - BundleEntrySearchModeEnum searchMode = ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.get(((IResource) theResource)); + BundleEntrySearchModeEnum searchMode = ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.get(theResource); return BundleEntrySearchModeEnum.INCLUDE.equals(searchMode); } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/SearchCoordinatorSvcImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/SearchCoordinatorSvcImpl.java index 64ef4870975..a828159b31e 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/SearchCoordinatorSvcImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/SearchCoordinatorSvcImpl.java @@ -63,7 +63,6 @@ import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; import ca.uhn.fhir.rest.server.util.CompositeInterceptorBroadcaster; import ca.uhn.fhir.rest.server.util.ISearchParamRegistry; import ca.uhn.fhir.util.AsyncUtil; -import ca.uhn.fhir.util.ICallable; import ca.uhn.fhir.util.StopWatch; import ca.uhn.fhir.util.UrlUtil; import com.google.common.annotations.VisibleForTesting; @@ -293,7 +292,9 @@ public class SearchCoordinatorSvcImpl implements ISearchCoordinatorSvc { } } - AsyncUtil.sleep(500); + if (!search.getStatus().isDone()) { + AsyncUtil.sleep(500); + } } ourLog.trace("Finished looping"); @@ -444,7 +445,7 @@ public class SearchCoordinatorSvcImpl implements ISearchCoordinatorSvc { * In case there is no running search, if the total is listed as accurate we know one is coming * so let's wait a bit for it to show up */ - Optional search = myTxService.withRequest(theRequestDetails).execute(()->mySearchCacheSvc.fetchByUuid(theUuid)); + Optional search = myTxService.withRequest(theRequestDetails).execute(() -> mySearchCacheSvc.fetchByUuid(theUuid)); if (search.isPresent()) { Optional searchParameterMap = search.get().getSearchParameterMap(); if (searchParameterMap.isPresent() && searchParameterMap.get().getSearchTotalMode() == SearchTotalModeEnum.ACCURATE) { diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/builder/SearchBuilder.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/builder/SearchBuilder.java index eb2df93afc2..99bdfb5221e 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/builder/SearchBuilder.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/builder/SearchBuilder.java @@ -903,18 +903,10 @@ public class SearchBuilder implements ISearchBuilder { continue; } - if (resource instanceof IResource) { - if (theIncludedPids.contains(resourceId)) { - ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put((IResource) resource, BundleEntrySearchModeEnum.INCLUDE); - } else { - ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put((IResource) resource, BundleEntrySearchModeEnum.MATCH); - } + if (theIncludedPids.contains(resourceId)) { + ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put(resource, BundleEntrySearchModeEnum.INCLUDE); } else { - if (theIncludedPids.contains(resourceId)) { - ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put((IAnyResource) resource, BundleEntrySearchModeEnum.INCLUDE.getCode()); - } else { - ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put((IAnyResource) resource, BundleEntrySearchModeEnum.MATCH.getCode()); - } + ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put(resource, BundleEntrySearchModeEnum.MATCH); } theResourceListToPopulate.set(index, resource); diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/util/AllowStatusChangeMetadata.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/util/AllowStatusChangeMetadata.java deleted file mode 100644 index 17d3059cb97..00000000000 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/util/AllowStatusChangeMetadata.java +++ /dev/null @@ -1,46 +0,0 @@ -package ca.uhn.fhir.jpa.util; - -/*- - * #%L - * HAPI FHIR JPA Server - * %% - * Copyright (C) 2014 - 2023 Smile CDR, Inc. - * %% - * 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.i18n.Msg; -import ca.uhn.fhir.model.api.IResource; -import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum; -import ca.uhn.fhir.util.CoverageIgnore; - -final class AllowStatusChangeMetadata extends ResourceMetadataKeyEnum { - private static final long serialVersionUID = 1; - - AllowStatusChangeMetadata(String theValue) { - super(theValue); - } - - @CoverageIgnore - @Override - public Object get(IResource theResource) { - throw new UnsupportedOperationException(Msg.code(805)); - } - - @CoverageIgnore - @Override - public void put(IResource theResource, Object theObject) { - throw new UnsupportedOperationException(Msg.code(806)); - } -} diff --git a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/search/SearchStatusEnum.java b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/search/SearchStatusEnum.java index cfe6e91b54b..152e72ed206 100644 --- a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/search/SearchStatusEnum.java +++ b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/search/SearchStatusEnum.java @@ -25,24 +25,36 @@ public enum SearchStatusEnum { /** * The search is currently actively working */ - LOADING, + LOADING(false), /** * The search has loaded a set of results and has stopped searching because it * reached an appropriate threshold */ - PASSCMPLET, + PASSCMPLET(false), /** * The search completed normally and loaded all of the results it as permitted to * load */ - FINISHED, + FINISHED(true), /** * The search failed and will not continue */ - FAILED, + FAILED(true), /** * The search has been expired and will be expunged shortly */ - GONE + GONE(true); + private final boolean myDone; + + SearchStatusEnum(boolean theDone) { + myDone = theDone; + } + + /** + * Returns true if no more work will happen for this search (finished, failed, gone) + */ + public boolean isDone() { + return myDone; + } } diff --git a/hapi-fhir-jpaserver-test-dstu2/src/test/java/ca/uhn/fhir/jpa/search/SearchCoordinatorSvcImplTest.java b/hapi-fhir-jpaserver-test-dstu2/src/test/java/ca/uhn/fhir/jpa/search/SearchCoordinatorSvcImplTest.java index f991726f0d2..b4bb16a7cee 100644 --- a/hapi-fhir-jpaserver-test-dstu2/src/test/java/ca/uhn/fhir/jpa/search/SearchCoordinatorSvcImplTest.java +++ b/hapi-fhir-jpaserver-test-dstu2/src/test/java/ca/uhn/fhir/jpa/search/SearchCoordinatorSvcImplTest.java @@ -449,6 +449,7 @@ public class SearchCoordinatorSvcImplTest extends BaseSearchSvc{ search.setUuid(uuid); search.setSearchType(SearchTypeEnum.SEARCH); search.setResourceType("Patient"); + search.setStatus(SearchStatusEnum.LOADING); when(mySearchCacheSvc.fetchByUuid(eq(uuid))).thenReturn(Optional.of(search)); doAnswer(loadPids()).when(mySearchBuilder).loadResourcesByPid(any(Collection.class), any(Collection.class), any(List.class), anyBoolean(), any()); diff --git a/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3Test.java b/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3Test.java index 73a8ca2dd02..7d6dc68d02e 100644 --- a/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3Test.java +++ b/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3Test.java @@ -1055,7 +1055,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { IBundleProvider history = myPatientDao.history(null, null, null, mySrd); assertEquals(4 + initialHistory, history.size().intValue()); List resources = history.getResources(0, 4); - assertNotNull(ResourceMetadataKeyEnum.DELETED_AT.get((IAnyResource) resources.get(0))); + assertNotNull(ResourceMetadataKeyEnum.DELETED_AT.get(resources.get(0))); try { myPatientDao.delete(id2, mySrd); @@ -1164,9 +1164,9 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { IBundleProvider history = myPatientDao.history(id, null, null, null, mySrd); assertEquals(2, history.size().intValue()); - assertNotNull(ResourceMetadataKeyEnum.DELETED_AT.get((IAnyResource) history.getResources(0, 1).get(0))); - assertNotNull(ResourceMetadataKeyEnum.DELETED_AT.get((IAnyResource) history.getResources(0, 1).get(0)).getValue()); - assertNull(ResourceMetadataKeyEnum.DELETED_AT.get((IAnyResource) history.getResources(1, 2).get(0))); + assertNotNull(ResourceMetadataKeyEnum.DELETED_AT.get(history.getResources(0, 1).get(0))); + assertNotNull(ResourceMetadataKeyEnum.DELETED_AT.get(history.getResources(0, 1).get(0)).getValue()); + assertNull(ResourceMetadataKeyEnum.DELETED_AT.get(history.getResources(1, 2).get(0))); } @@ -1386,7 +1386,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { } List patients = toList(myPatientDao.history(idv1.toVersionless(), null, null, null, mySrd)); - assertTrue(patients.size() == 2); + assertEquals(2, patients.size()); // Newest first assertEquals("Patient/testHistoryByForcedId/_history/2", patients.get(0).getIdElement().toUnqualified().getValue()); assertEquals("Patient/testHistoryByForcedId/_history/1", patients.get(1).getIdElement().toUnqualified().getValue()); @@ -1622,14 +1622,14 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { assertEquals(id.withVersion("2"), entries.get(1).getIdElement()); assertEquals(id.withVersion("1"), entries.get(2).getIdElement()); - assertNull(ResourceMetadataKeyEnum.DELETED_AT.get((IAnyResource) entries.get(0))); - assertEquals(BundleEntryTransactionMethodEnum.PUT.getCode(), ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.get((IAnyResource) entries.get(0))); + assertNull(ResourceMetadataKeyEnum.DELETED_AT.get(entries.get(0))); + assertEquals(BundleEntryTransactionMethodEnum.PUT, ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.get(entries.get(0))); - assertNotNull(ResourceMetadataKeyEnum.DELETED_AT.get((IAnyResource) entries.get(1))); - assertEquals(BundleEntryTransactionMethodEnum.DELETE.getCode(), ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.get((IAnyResource) entries.get(1))); + assertNotNull(ResourceMetadataKeyEnum.DELETED_AT.get(entries.get(1))); + assertEquals(BundleEntryTransactionMethodEnum.DELETE, ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.get(entries.get(1))); - assertNull(ResourceMetadataKeyEnum.DELETED_AT.get((IAnyResource) entries.get(2))); - assertEquals(BundleEntryTransactionMethodEnum.POST.getCode(), ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.get((IAnyResource) entries.get(2))); + assertNull(ResourceMetadataKeyEnum.DELETED_AT.get(entries.get(2))); + assertEquals(BundleEntryTransactionMethodEnum.POST, ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.get(entries.get(2))); } @Test @@ -2371,7 +2371,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { meta = myPatientDao.metaGetOperation(Meta.class, mySrd); List published = meta.getTag(); assertEquals(2, published.size()); - assertEquals(null, published.get(0).getSystem()); + assertNull(published.get(0).getSystem()); assertEquals("Dog", published.get(0).getCode()); assertEquals("Puppies", published.get(0).getDisplay()); assertEquals("http://foo", published.get(1).getSystem()); @@ -2472,7 +2472,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { meta = myPatientDao.metaGetOperation(Meta.class, mySrd); List published = meta.getTag(); assertEquals(2, published.size()); - assertEquals(null, published.get(0).getSystem()); + assertNull(published.get(0).getSystem()); assertEquals("Dog", published.get(0).getCode()); assertEquals("Puppies", published.get(0).getDisplay()); assertEquals("http://foo", published.get(1).getSystem()); @@ -2573,7 +2573,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { meta = myPatientDao.metaGetOperation(Meta.class, mySrd); List published = meta.getTag(); assertEquals(2, published.size()); - assertEquals(null, published.get(0).getSystem()); + assertNull(published.get(0).getSystem()); assertEquals("Dog", published.get(0).getCode()); assertEquals("Puppies", published.get(0).getDisplay()); assertEquals("http://foo", published.get(1).getSystem()); @@ -2649,9 +2649,9 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { List results = resultsP.getResources(0, resultsP.size()); assertEquals(2, results.size()); assertEquals(Organization.class, results.get(0).getClass()); - assertEquals(BundleEntrySearchModeEnum.MATCH.getCode(), ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.get((IAnyResource) results.get(0))); + assertEquals(BundleEntrySearchModeEnum.MATCH, ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.get(results.get(0))); assertEquals(Patient.class, results.get(1).getClass()); - assertEquals(BundleEntrySearchModeEnum.INCLUDE.getCode(), ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.get((IAnyResource) results.get(1))); + assertEquals(BundleEntrySearchModeEnum.INCLUDE, ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.get(results.get(1))); } @Test() @@ -3294,7 +3294,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { myOrganizationDao.create(org, mySrd); val = myOrganizationDao.searchForIds(new SearchParameterMap("name", new StringParam("P")), null); - assertEquals(initial + 0, val.size()); + assertEquals(initial, val.size()); val = myOrganizationDao.searchForIds(new SearchParameterMap("name", new StringParam(str.substring(0, ResourceIndexedSearchParamString.MAX_LENGTH))), null); assertEquals(initial + 1, val.size()); @@ -3340,7 +3340,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { assertEquals(2, published.size()); assertEquals("Dog", published.get(0).getCode()); assertEquals("Puppies", published.get(0).getDisplay()); - assertEquals(null, published.get(0).getSystem()); + assertNull(published.get(0).getSystem()); assertEquals("Cat", published.get(1).getCode()); assertEquals("Kittens", published.get(1).getDisplay()); assertEquals("http://foo", published.get(1).getSystem()); @@ -3368,7 +3368,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { sort(published); assertEquals("Dog", published.get(0).getCode()); assertEquals("Puppies", published.get(0).getDisplay()); - assertEquals(null, published.get(0).getSystem()); + assertNull(published.get(0).getSystem()); assertEquals("Cat", published.get(1).getCode()); assertEquals("Kittens", published.get(1).getDisplay()); assertEquals("http://foo", published.get(1).getSystem()); @@ -3398,7 +3398,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { assertEquals(3, published.size()); assertEquals("Dog", published.get(0).getCode()); assertEquals("Puppies", published.get(0).getDisplay()); - assertEquals(null, published.get(0).getSystem()); + assertNull(published.get(0).getSystem()); assertEquals("Cat", published.get(1).getCode()); assertEquals("Kittens", published.get(1).getDisplay()); assertEquals("http://foo", published.get(1).getSystem()); diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/client/ClientThreadedCapabilitiesTest.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/client/ClientThreadedCapabilitiesTest.java index 864151a5725..0f8805c12d5 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/client/ClientThreadedCapabilitiesTest.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/client/ClientThreadedCapabilitiesTest.java @@ -48,18 +48,15 @@ public class ClientThreadedCapabilitiesTest { private static final Logger ourLog = LoggerFactory.getLogger("ClientThreadedCapabilitiesTest"); private static final FhirContext fhirContext = FhirContext.forR4(); - private static final String SERVER_URL = "http://hapi.fhir.org/baseR4"; - private IGenericClient myClient; - private static final IClientInterceptor myCountingMetaClientInterceptor = new CountingMetaClientInterceptor(); + private static final IClientInterceptor myCountingMetaClientInterceptor = new CountingMetaClientInterceptor(); private static final Collection lastNames = Lists.newArrayList("Johnson", "Williams", "Brown", "Jones", "Garcia", "Miller", "Davis", "Rodriguez", "Martinez", "Hernandez", "Lopez", "Gonzalez", "Wilson", "Anderson", "Thomas", "Taylor", "Moore", "Jackson", "Martin", "Lee"); - @RegisterExtension public static RestfulServerExtension ourServer = new RestfulServerExtension(fhirContext) .registerProvider(new TestPatientResourceProvider()) .withValidationMode(ServerValidationModeEnum.ONCE) .registerInterceptor(new SearchPreferHandlingInterceptor()); - + private IGenericClient myClient; @BeforeEach public void beforeEach() throws Exception { @@ -74,13 +71,13 @@ public class ClientThreadedCapabilitiesTest { factory.setSocketTimeout(300 * 1000); Executor executor = Executors.newFixedThreadPool(lastNames.size(), r -> { - Thread t = new Thread(r); - t.setDaemon(true); - return t; - }); + Thread t = new Thread(r); + t.setDaemon(true); + return t; + }); Collection> futures = lastNames.stream() - .map(last -> CompletableFuture.supplyAsync(() -> searchPatient(last), executor)).collect(toList()); + .map(last -> CompletableFuture.supplyAsync(() -> searchPatient(last), executor)).collect(toList()); final StopWatch sw = new StopWatch(); @@ -139,7 +136,7 @@ public class ClientThreadedCapabilitiesTest { public Patient search(@OptionalParam(name = Patient.SP_FAMILY) StringParam theFamilyName) { Patient patient = new Patient(); patient.getIdElement().setValue("Patient/" + rand.nextInt() + "/_history/222"); - ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put(patient, BundleEntrySearchModeEnum.INCLUDE.getCode()); + ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put(patient, BundleEntrySearchModeEnum.INCLUDE); patient.addName(new HumanName().setFamily(theFamilyName.getValue())); patient.setActive(true); return patient; @@ -148,5 +145,4 @@ public class ClientThreadedCapabilitiesTest { } - } diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4Test.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4Test.java index 7fc41c9a002..32a402dc8ff 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4Test.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4Test.java @@ -123,6 +123,7 @@ import org.springframework.transaction.support.TransactionCallbackWithoutResult; import org.springframework.transaction.support.TransactionTemplate; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; @@ -837,7 +838,7 @@ public class FhirResourceDaoR4Test extends BaseJpaR4Test { String name = "profiles-resources"; ourLog.info("Uploading " + name); String vsContents; - vsContents = IOUtils.toString(FhirResourceDaoR4Test.class.getResourceAsStream("/org/hl7/fhir/r4/model/profile/" + name + ".xml"), "UTF-8"); + vsContents = IOUtils.toString(FhirResourceDaoR4Test.class.getResourceAsStream("/org/hl7/fhir/r4/model/profile/" + name + ".xml"), StandardCharsets.UTF_8); bundle = myFhirContext.newXmlParser().parseResource(org.hl7.fhir.r4.model.Bundle.class, vsContents); for (BundleEntryComponent i : bundle.getEntry()) { @@ -1018,15 +1019,15 @@ public class FhirResourceDaoR4Test extends BaseJpaR4Test { * If any of this ever fails, it means that one of the OperationOutcome issue severity codes has changed code value across versions. We store the string as a constant, so something will need to * be fixed. */ - assertEquals(org.hl7.fhir.dstu2.model.OperationOutcome.IssueSeverity.ERROR.toCode(), BaseHapiFhirDao.OO_SEVERITY_ERROR); + assertEquals(org.hl7.fhir.dstu2.model.OperationOutcome.IssueSeverity.ERROR.toCode(), BaseStorageDao.OO_SEVERITY_ERROR); assertEquals(org.hl7.fhir.r4.model.OperationOutcome.IssueSeverity.ERROR.toCode(), BaseStorageDao.OO_SEVERITY_ERROR); - assertEquals(org.hl7.fhir.r4.model.OperationOutcome.IssueSeverity.ERROR.toCode(), BaseHapiFhirDao.OO_SEVERITY_ERROR); - assertEquals(org.hl7.fhir.dstu2.model.OperationOutcome.IssueSeverity.INFORMATION.toCode(), BaseHapiFhirDao.OO_SEVERITY_INFO); + assertEquals(org.hl7.fhir.r4.model.OperationOutcome.IssueSeverity.ERROR.toCode(), BaseStorageDao.OO_SEVERITY_ERROR); + assertEquals(org.hl7.fhir.dstu2.model.OperationOutcome.IssueSeverity.INFORMATION.toCode(), BaseStorageDao.OO_SEVERITY_INFO); assertEquals(org.hl7.fhir.r4.model.OperationOutcome.IssueSeverity.INFORMATION.toCode(), BaseStorageDao.OO_SEVERITY_INFO); - assertEquals(org.hl7.fhir.r4.model.OperationOutcome.IssueSeverity.INFORMATION.toCode(), BaseHapiFhirDao.OO_SEVERITY_INFO); - assertEquals(org.hl7.fhir.dstu2.model.OperationOutcome.IssueSeverity.WARNING.toCode(), BaseHapiFhirDao.OO_SEVERITY_WARN); + assertEquals(org.hl7.fhir.r4.model.OperationOutcome.IssueSeverity.INFORMATION.toCode(), BaseStorageDao.OO_SEVERITY_INFO); + assertEquals(org.hl7.fhir.dstu2.model.OperationOutcome.IssueSeverity.WARNING.toCode(), BaseStorageDao.OO_SEVERITY_WARN); + assertEquals(org.hl7.fhir.r4.model.OperationOutcome.IssueSeverity.WARNING.toCode(), BaseStorageDao.OO_SEVERITY_WARN); assertEquals(org.hl7.fhir.r4.model.OperationOutcome.IssueSeverity.WARNING.toCode(), BaseStorageDao.OO_SEVERITY_WARN); - assertEquals(org.hl7.fhir.r4.model.OperationOutcome.IssueSeverity.WARNING.toCode(), BaseHapiFhirDao.OO_SEVERITY_WARN); } @Test @@ -1417,7 +1418,7 @@ public class FhirResourceDaoR4Test extends BaseJpaR4Test { IBundleProvider history = myPatientDao.history(null, null, null, mySrd); assertEquals(4 + initialHistory, history.size().intValue()); List resources = history.getResources(0, 4); - assertNotNull(ResourceMetadataKeyEnum.DELETED_AT.get((IAnyResource) resources.get(0))); + assertNotNull(ResourceMetadataKeyEnum.DELETED_AT.get(resources.get(0))); try { myPatientDao.delete(id2, mySrd); @@ -1518,7 +1519,7 @@ public class FhirResourceDaoR4Test extends BaseJpaR4Test { assertEquals("3", id5.getVersionIdPart()); patient = myPatientDao.read(id.withVersion("1")); - assertEquals(true, patient.getActive()); + assertTrue(patient.getActive()); try { myPatientDao.read(id.withVersion("2")); @@ -1528,7 +1529,7 @@ public class FhirResourceDaoR4Test extends BaseJpaR4Test { } patient = myPatientDao.read(id.withVersion("3")); - assertEquals(false, patient.getActive()); + assertFalse(patient.getActive()); } @@ -1592,9 +1593,9 @@ public class FhirResourceDaoR4Test extends BaseJpaR4Test { IBundleProvider history = myPatientDao.history(id, null, null, null, mySrd); assertEquals(2, history.size().intValue()); - assertNotNull(ResourceMetadataKeyEnum.DELETED_AT.get((IAnyResource) history.getResources(0, 1).get(0))); - assertNotNull(ResourceMetadataKeyEnum.DELETED_AT.get((IAnyResource) history.getResources(0, 1).get(0)).getValue()); - assertNull(ResourceMetadataKeyEnum.DELETED_AT.get((IAnyResource) history.getResources(1, 2).get(0))); + assertNotNull(ResourceMetadataKeyEnum.DELETED_AT.get(history.getResources(0, 1).get(0))); + assertNotNull(ResourceMetadataKeyEnum.DELETED_AT.get(history.getResources(0, 1).get(0)).getValue()); + assertNull(ResourceMetadataKeyEnum.DELETED_AT.get(history.getResources(1, 2).get(0))); } @@ -1837,7 +1838,7 @@ public class FhirResourceDaoR4Test extends BaseJpaR4Test { } List patients = toList(myPatientDao.history(idv1.toVersionless(), null, null, null, mySrd)); - assertTrue(patients.size() == 2); + assertEquals(2, patients.size()); // Newest first assertEquals("Patient/testHistoryByForcedId/_history/2", patients.get(0).getIdElement().toUnqualified().getValue()); assertEquals("Patient/testHistoryByForcedId/_history/1", patients.get(1).getIdElement().toUnqualified().getValue()); @@ -2072,14 +2073,14 @@ public class FhirResourceDaoR4Test extends BaseJpaR4Test { assertEquals(id.withVersion("2"), entries.get(1).getIdElement()); assertEquals(id.withVersion("1"), entries.get(2).getIdElement()); - assertNull(ResourceMetadataKeyEnum.DELETED_AT.get((IAnyResource) entries.get(0))); - assertEquals(BundleEntryTransactionMethodEnum.PUT.getCode(), ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.get((IAnyResource) entries.get(0))); + assertNull(ResourceMetadataKeyEnum.DELETED_AT.get(entries.get(0))); + assertEquals(BundleEntryTransactionMethodEnum.PUT, ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.get(entries.get(0))); - assertNotNull(ResourceMetadataKeyEnum.DELETED_AT.get((IAnyResource) entries.get(1))); - assertEquals(BundleEntryTransactionMethodEnum.DELETE.getCode(), ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.get((IAnyResource) entries.get(1))); + assertNotNull(ResourceMetadataKeyEnum.DELETED_AT.get(entries.get(1))); + assertEquals(BundleEntryTransactionMethodEnum.DELETE, ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.get(entries.get(1))); - assertNull(ResourceMetadataKeyEnum.DELETED_AT.get((IAnyResource) entries.get(2))); - assertEquals(BundleEntryTransactionMethodEnum.POST.getCode(), ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.get((IAnyResource) entries.get(2))); + assertNull(ResourceMetadataKeyEnum.DELETED_AT.get(entries.get(2))); + assertEquals(BundleEntryTransactionMethodEnum.POST, ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.get(entries.get(2))); } @Test @@ -2255,7 +2256,7 @@ public class FhirResourceDaoR4Test extends BaseJpaR4Test { myConditionDao.create(c2, mySrd).getId().toUnqualifiedVersionless(); Condition c3 = new Condition(); - c3.setOnset(new Range().setLow((SimpleQuantity) new SimpleQuantity().setValue(200L)).setHigh((SimpleQuantity) new SimpleQuantity().setValue(300L))); + c3.setOnset(new Range().setLow(new SimpleQuantity().setValue(200L)).setHigh(new SimpleQuantity().setValue(300L))); myConditionDao.create(c3, mySrd).getId().toUnqualifiedVersionless(); Condition c4 = new Condition(); @@ -2841,7 +2842,7 @@ public class FhirResourceDaoR4Test extends BaseJpaR4Test { meta = myPatientDao.metaGetOperation(Meta.class, mySrd); List published = meta.getTag(); assertEquals(2, published.size()); - assertEquals(null, published.get(0).getSystem()); + assertNull(published.get(0).getSystem()); assertEquals("Dog", published.get(0).getCode()); assertEquals("Puppies", published.get(0).getDisplay()); assertEquals("http://foo", published.get(1).getSystem()); @@ -2972,7 +2973,7 @@ public class FhirResourceDaoR4Test extends BaseJpaR4Test { meta = myPatientDao.metaGetOperation(Meta.class, mySrd); List published = meta.getTag(); assertEquals(2, published.size()); - assertEquals(null, published.get(0).getSystem()); + assertNull(published.get(0).getSystem()); assertEquals("Dog", published.get(0).getCode()); assertEquals("Puppies", published.get(0).getDisplay()); assertEquals("http://foo", published.get(1).getSystem()); @@ -3073,7 +3074,7 @@ public class FhirResourceDaoR4Test extends BaseJpaR4Test { meta = myPatientDao.metaGetOperation(Meta.class, mySrd); List published = meta.getTag(); assertEquals(2, published.size()); - assertEquals(null, published.get(0).getSystem()); + assertNull(published.get(0).getSystem()); assertEquals("Dog", published.get(0).getCode()); assertEquals("Puppies", published.get(0).getDisplay()); assertEquals("http://foo", published.get(1).getSystem()); @@ -3149,9 +3150,9 @@ public class FhirResourceDaoR4Test extends BaseJpaR4Test { List results = resultsP.getResources(0, resultsP.size()); assertEquals(2, results.size()); assertEquals(Organization.class, results.get(0).getClass()); - assertEquals(BundleEntrySearchModeEnum.MATCH.getCode(), ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.get((IAnyResource) results.get(0))); + assertEquals(BundleEntrySearchModeEnum.MATCH, ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.get(results.get(0))); assertEquals(Patient.class, results.get(1).getClass()); - assertEquals(BundleEntrySearchModeEnum.INCLUDE.getCode(), ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.get((IAnyResource) results.get(1))); + assertEquals(BundleEntrySearchModeEnum.INCLUDE, ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.get(results.get(1))); } @Test @@ -4033,7 +4034,7 @@ public class FhirResourceDaoR4Test extends BaseJpaR4Test { assertEquals(2, published.size()); assertEquals("Dog", published.get(0).getCode()); assertEquals("Puppies", published.get(0).getDisplay()); - assertEquals(null, published.get(0).getSystem()); + assertNull(published.get(0).getSystem()); assertEquals("Cat", published.get(1).getCode()); assertEquals("Kittens", published.get(1).getDisplay()); assertEquals("http://foo", published.get(1).getSystem()); @@ -4061,7 +4062,7 @@ public class FhirResourceDaoR4Test extends BaseJpaR4Test { sort(published); assertEquals("Dog", published.get(0).getCode()); assertEquals("Puppies", published.get(0).getDisplay()); - assertEquals(null, published.get(0).getSystem()); + assertNull(published.get(0).getSystem()); assertEquals("Cat", published.get(1).getCode()); assertEquals("Kittens", published.get(1).getDisplay()); assertEquals("http://foo", published.get(1).getSystem()); @@ -4091,7 +4092,7 @@ public class FhirResourceDaoR4Test extends BaseJpaR4Test { assertEquals(3, published.size()); assertEquals("Dog", published.get(0).getCode()); assertEquals("Puppies", published.get(0).getDisplay()); - assertEquals(null, published.get(0).getSystem()); + assertNull(published.get(0).getSystem()); assertEquals("Cat", published.get(1).getCode()); assertEquals("Kittens", published.get(1).getDisplay()); assertEquals("http://foo", published.get(1).getSystem()); diff --git a/hapi-fhir-storage/src/main/java/ca/uhn/fhir/jpa/api/dao/MetadataKeyCurrentlyReindexing.java b/hapi-fhir-storage/src/main/java/ca/uhn/fhir/jpa/api/dao/MetadataKeyCurrentlyReindexing.java index ee73f1372fa..6fa4385558b 100644 --- a/hapi-fhir-storage/src/main/java/ca/uhn/fhir/jpa/api/dao/MetadataKeyCurrentlyReindexing.java +++ b/hapi-fhir-storage/src/main/java/ca/uhn/fhir/jpa/api/dao/MetadataKeyCurrentlyReindexing.java @@ -20,23 +20,13 @@ package ca.uhn.fhir.jpa.api.dao; * #L% */ -import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum; public final class MetadataKeyCurrentlyReindexing extends ResourceMetadataKeyEnum { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 2L; MetadataKeyCurrentlyReindexing(String theValue) { - super(theValue); + super(theValue, Boolean.class); } - @Override - public Boolean get(IResource theResource) { - return (Boolean) theResource.getResourceMetadata().get(IDao.CURRENTLY_REINDEXING); - } - - @Override - public void put(IResource theResource, Boolean theObject) { - theResource.getResourceMetadata().put(IDao.CURRENTLY_REINDEXING, theObject); - } } diff --git a/hapi-fhir-storage/src/main/java/ca/uhn/fhir/jpa/api/dao/MetadataKeyResourcePid.java b/hapi-fhir-storage/src/main/java/ca/uhn/fhir/jpa/api/dao/MetadataKeyResourcePid.java index 459ae3a085b..e9f6413da39 100644 --- a/hapi-fhir-storage/src/main/java/ca/uhn/fhir/jpa/api/dao/MetadataKeyResourcePid.java +++ b/hapi-fhir-storage/src/main/java/ca/uhn/fhir/jpa/api/dao/MetadataKeyResourcePid.java @@ -20,34 +20,13 @@ package ca.uhn.fhir.jpa.api.dao; * #L% */ -import ca.uhn.fhir.model.api.IResource; -import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum.ResourceMetadataKeySupportingAnyResource; -import org.hl7.fhir.instance.model.api.IAnyResource; +import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum; -public final class MetadataKeyResourcePid extends ResourceMetadataKeySupportingAnyResource { - private static final long serialVersionUID = 1L; +public final class MetadataKeyResourcePid extends ResourceMetadataKeyEnum { + private static final long serialVersionUID = 2L; MetadataKeyResourcePid(String theValue) { - super(theValue); + super(theValue, Long.class); } - @Override - public Long get(IAnyResource theResource) { - return (Long) theResource.getUserData(IDao.RESOURCE_PID.name()); - } - - @Override - public Long get(IResource theResource) { - return (Long) theResource.getResourceMetadata().get(IDao.RESOURCE_PID); - } - - @Override - public void put(IAnyResource theResource, Long theObject) { - theResource.setUserData(IDao.RESOURCE_PID.name(), theObject); - } - - @Override - public void put(IResource theResource, Long theObject) { - theResource.getResourceMetadata().put(IDao.RESOURCE_PID, theObject); - } } diff --git a/hapi-fhir-structures-dstu2.1/src/main/java/org/hl7/fhir/dstu2016may/hapi/rest/server/Dstu2_1BundleFactory.java b/hapi-fhir-structures-dstu2.1/src/main/java/org/hl7/fhir/dstu2016may/hapi/rest/server/Dstu2_1BundleFactory.java index 886ba80e32d..e6a0a761510 100644 --- a/hapi-fhir-structures-dstu2.1/src/main/java/org/hl7/fhir/dstu2016may/hapi/rest/server/Dstu2_1BundleFactory.java +++ b/hapi-fhir-structures-dstu2.1/src/main/java/org/hl7/fhir/dstu2016may/hapi/rest/server/Dstu2_1BundleFactory.java @@ -24,6 +24,8 @@ import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.api.BundleInclusionRule; import ca.uhn.fhir.model.api.Include; import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum; +import ca.uhn.fhir.model.valueset.BundleEntrySearchModeEnum; +import ca.uhn.fhir.model.valueset.BundleEntryTransactionMethodEnum; import ca.uhn.fhir.model.valueset.BundleTypeEnum; import ca.uhn.fhir.rest.api.BundleLinks; import ca.uhn.fhir.rest.api.Constants; @@ -131,17 +133,17 @@ public class Dstu2_1BundleFactory implements IVersionSpecificBundleFactory { BundleEntryComponent entry = myBundle.addEntry().setResource((Resource) next); Resource nextAsResource = (Resource) next; IIdType id = populateBundleEntryFullUrl(next, entry); - String httpVerb = ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.get(nextAsResource); + BundleEntryTransactionMethodEnum httpVerb = ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.get(nextAsResource); if (httpVerb != null) { - entry.getRequest().getMethodElement().setValueAsString(httpVerb); + entry.getRequest().getMethodElement().setValueAsString(httpVerb.name()); if (id != null) { entry.getRequest().setUrl(id.getValue()); } } - String searchMode = ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.get(nextAsResource); + BundleEntrySearchModeEnum searchMode = ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.get(nextAsResource); if (searchMode != null) { - entry.getSearch().getModeElement().setValueAsString(searchMode); + entry.getSearch().getModeElement().setValueAsString(searchMode.getCode()); } } diff --git a/hapi-fhir-structures-dstu3/src/main/java/org/hl7/fhir/dstu3/hapi/rest/server/Dstu3BundleFactory.java b/hapi-fhir-structures-dstu3/src/main/java/org/hl7/fhir/dstu3/hapi/rest/server/Dstu3BundleFactory.java index 9813efc5694..89a95603686 100644 --- a/hapi-fhir-structures-dstu3/src/main/java/org/hl7/fhir/dstu3/hapi/rest/server/Dstu3BundleFactory.java +++ b/hapi-fhir-structures-dstu3/src/main/java/org/hl7/fhir/dstu3/hapi/rest/server/Dstu3BundleFactory.java @@ -24,6 +24,8 @@ import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.api.BundleInclusionRule; import ca.uhn.fhir.model.api.Include; import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum; +import ca.uhn.fhir.model.valueset.BundleEntrySearchModeEnum; +import ca.uhn.fhir.model.valueset.BundleEntryTransactionMethodEnum; import ca.uhn.fhir.model.valueset.BundleTypeEnum; import ca.uhn.fhir.rest.api.BundleLinks; import ca.uhn.fhir.rest.api.Constants; @@ -132,14 +134,14 @@ public class Dstu3BundleFactory implements IVersionSpecificBundleFactory { BundleEntryComponent entry = myBundle.addEntry().setResource((Resource) next); Resource nextAsResource = (Resource) next; IIdType id = populateBundleEntryFullUrl(next, entry); - String httpVerb = ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.get(nextAsResource); + BundleEntryTransactionMethodEnum httpVerb = ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.get(nextAsResource); if (httpVerb != null) { - entry.getRequest().getMethodElement().setValueAsString(httpVerb); + entry.getRequest().getMethodElement().setValueAsString(httpVerb.name()); if (id != null) { entry.getRequest().setUrl(id.toUnqualified().getValue()); } } - if ("DELETE".equals(httpVerb)) { + if (BundleEntryTransactionMethodEnum.DELETE.equals(httpVerb)) { entry.setResource(null); } @@ -161,9 +163,9 @@ public class Dstu3BundleFactory implements IVersionSpecificBundleFactory { } // Populate Bundle.entry.search - String searchMode = ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.get(nextAsResource); + BundleEntrySearchModeEnum searchMode = ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.get(nextAsResource); if (searchMode != null) { - entry.getSearch().getModeElement().setValueAsString(searchMode); + entry.getSearch().getModeElement().setValueAsString(searchMode.getCode()); } } diff --git a/hapi-fhir-structures-hl7org-dstu2/src/main/java/ca/uhn/fhir/rest/server/provider/dstu2hl7org/Dstu2Hl7OrgBundleFactory.java b/hapi-fhir-structures-hl7org-dstu2/src/main/java/ca/uhn/fhir/rest/server/provider/dstu2hl7org/Dstu2Hl7OrgBundleFactory.java index 80ef96fe2d7..91d1c4fd87c 100644 --- a/hapi-fhir-structures-hl7org-dstu2/src/main/java/ca/uhn/fhir/rest/server/provider/dstu2hl7org/Dstu2Hl7OrgBundleFactory.java +++ b/hapi-fhir-structures-hl7org-dstu2/src/main/java/ca/uhn/fhir/rest/server/provider/dstu2hl7org/Dstu2Hl7OrgBundleFactory.java @@ -24,6 +24,8 @@ import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.api.BundleInclusionRule; import ca.uhn.fhir.model.api.Include; import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum; +import ca.uhn.fhir.model.valueset.BundleEntrySearchModeEnum; +import ca.uhn.fhir.model.valueset.BundleEntryTransactionMethodEnum; import ca.uhn.fhir.model.valueset.BundleTypeEnum; import ca.uhn.fhir.rest.api.BundleLinks; import ca.uhn.fhir.rest.api.Constants; @@ -135,14 +137,14 @@ public class Dstu2Hl7OrgBundleFactory implements IVersionSpecificBundleFactory { BundleEntryComponent entry = myBundle.addEntry().setResource((Resource) next); Resource nextAsResource = (Resource) next; IIdType id = populateBundleEntryFullUrl(next, entry); - String httpVerb = ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.get(nextAsResource); + BundleEntryTransactionMethodEnum httpVerb = ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.get(nextAsResource); if (httpVerb != null) { - entry.getRequest().getMethodElement().setValueAsString(httpVerb); + entry.getRequest().getMethodElement().setValueAsString(httpVerb.name()); if (id != null) { entry.getRequest().setUrl(id.getValue()); } } - if ("DELETE".equals(httpVerb)) { + if (BundleEntryTransactionMethodEnum.DELETE.equals(httpVerb)) { entry.setResource(null); } @@ -166,9 +168,9 @@ public class Dstu2Hl7OrgBundleFactory implements IVersionSpecificBundleFactory { } // Populate Bundle.entry.search - String searchMode = ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.get(nextAsResource); + BundleEntrySearchModeEnum searchMode = ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.get(nextAsResource); if (searchMode != null) { - entry.getSearch().getModeElement().setValueAsString(searchMode); + entry.getSearch().getModeElement().setValueAsString(searchMode.getCode()); } } diff --git a/hapi-fhir-structures-r4/src/main/java/org/hl7/fhir/r4/hapi/rest/server/R4BundleFactory.java b/hapi-fhir-structures-r4/src/main/java/org/hl7/fhir/r4/hapi/rest/server/R4BundleFactory.java index d80fca6b4ed..c66f054de0f 100644 --- a/hapi-fhir-structures-r4/src/main/java/org/hl7/fhir/r4/hapi/rest/server/R4BundleFactory.java +++ b/hapi-fhir-structures-r4/src/main/java/org/hl7/fhir/r4/hapi/rest/server/R4BundleFactory.java @@ -24,6 +24,8 @@ import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.api.BundleInclusionRule; import ca.uhn.fhir.model.api.Include; import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum; +import ca.uhn.fhir.model.valueset.BundleEntrySearchModeEnum; +import ca.uhn.fhir.model.valueset.BundleEntryTransactionMethodEnum; import ca.uhn.fhir.model.valueset.BundleTypeEnum; import ca.uhn.fhir.rest.api.BundleLinks; import ca.uhn.fhir.rest.api.Constants; @@ -134,14 +136,14 @@ public class R4BundleFactory implements IVersionSpecificBundleFactory { IIdType id = populateBundleEntryFullUrl(next, entry); // Populate Request - String httpVerb = ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.get(nextAsResource); + BundleEntryTransactionMethodEnum httpVerb = ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.get(nextAsResource); if (httpVerb != null) { - entry.getRequest().getMethodElement().setValueAsString(httpVerb); + entry.getRequest().getMethodElement().setValueAsString(httpVerb.name()); if (id != null) { entry.getRequest().setUrl(id.toUnqualified().getValue()); } } - if ("DELETE".equals(httpVerb)) { + if (BundleEntryTransactionMethodEnum.DELETE.equals(httpVerb)) { entry.setResource(null); } @@ -164,9 +166,9 @@ public class R4BundleFactory implements IVersionSpecificBundleFactory { } // Populate Bundle.entry.search - String searchMode = ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.get(nextAsResource); + BundleEntrySearchModeEnum searchMode = ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.get(nextAsResource); if (searchMode != null) { - entry.getSearch().getModeElement().setValueAsString(searchMode); + entry.getSearch().getModeElement().setValueAsString(searchMode.getCode()); } } diff --git a/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/server/SearchPreferHandlingInterceptorTest.java b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/server/SearchPreferHandlingInterceptorTest.java index 3cd2408df06..31d1189c961 100644 --- a/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/server/SearchPreferHandlingInterceptorTest.java +++ b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/server/SearchPreferHandlingInterceptorTest.java @@ -154,7 +154,7 @@ public class SearchPreferHandlingInterceptorTest { for (int i = 0; i < 200; i++) { Patient patient = new Patient(); patient.getIdElement().setValue("Patient/" + i + "/_history/222"); - ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put(patient, BundleEntrySearchModeEnum.INCLUDE.getCode()); + ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put(patient, BundleEntrySearchModeEnum.INCLUDE); patient.addName(new HumanName().setFamily("FAMILY")); patient.setActive(true); retVal.add(patient); diff --git a/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/server/SearchR4Test.java b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/server/SearchR4Test.java index 9e66400024a..55d7ffd480f 100644 --- a/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/server/SearchR4Test.java +++ b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/server/SearchR4Test.java @@ -517,7 +517,7 @@ public class SearchR4Test { for (int i = 0; i < 200; i++) { Patient patient = new Patient(); patient.getIdElement().setValue("Patient/" + i + "/_history/222"); - ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put(patient, BundleEntrySearchModeEnum.INCLUDE.getCode()); + ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put(patient, BundleEntrySearchModeEnum.INCLUDE); patient.addName(new HumanName().setFamily("FAMILY")); patient.setActive(true); retVal.add(patient); @@ -534,7 +534,6 @@ public class SearchR4Test { return MedicationRequest.class; } - @SuppressWarnings("rawtypes") @Search() public List search( @IncludeParam Set theIncludes diff --git a/hapi-fhir-structures-r4b/src/main/java/org/hl7/fhir/r4b/hapi/rest/server/R4BBundleFactory.java b/hapi-fhir-structures-r4b/src/main/java/org/hl7/fhir/r4b/hapi/rest/server/R4BBundleFactory.java index 2a1c7f7d910..ab07c2fc5ac 100644 --- a/hapi-fhir-structures-r4b/src/main/java/org/hl7/fhir/r4b/hapi/rest/server/R4BBundleFactory.java +++ b/hapi-fhir-structures-r4b/src/main/java/org/hl7/fhir/r4b/hapi/rest/server/R4BBundleFactory.java @@ -24,6 +24,8 @@ import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.api.BundleInclusionRule; import ca.uhn.fhir.model.api.Include; import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum; +import ca.uhn.fhir.model.valueset.BundleEntrySearchModeEnum; +import ca.uhn.fhir.model.valueset.BundleEntryTransactionMethodEnum; import ca.uhn.fhir.model.valueset.BundleTypeEnum; import ca.uhn.fhir.rest.api.BundleLinks; import ca.uhn.fhir.rest.api.Constants; @@ -134,14 +136,14 @@ public class R4BBundleFactory implements IVersionSpecificBundleFactory { IIdType id = populateBundleEntryFullUrl(next, entry); // Populate Request - String httpVerb = ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.get(nextAsResource); + BundleEntryTransactionMethodEnum httpVerb = ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.get(nextAsResource); if (httpVerb != null) { - entry.getRequest().getMethodElement().setValueAsString(httpVerb); + entry.getRequest().getMethodElement().setValueAsString(httpVerb.name()); if (id != null) { entry.getRequest().setUrl(id.toUnqualified().getValue()); } } - if ("DELETE".equals(httpVerb)) { + if (BundleEntryTransactionMethodEnum.DELETE.equals(httpVerb)) { entry.setResource(null); } @@ -164,9 +166,9 @@ public class R4BBundleFactory implements IVersionSpecificBundleFactory { } // Populate Bundle.entry.search - String searchMode = ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.get(nextAsResource); + BundleEntrySearchModeEnum searchMode = ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.get(nextAsResource); if (searchMode != null) { - entry.getSearch().getModeElement().setValueAsString(searchMode); + entry.getSearch().getModeElement().setValueAsString(searchMode.getCode()); } } diff --git a/hapi-fhir-structures-r4b/src/test/java/ca/uhn/fhir/rest/server/SearchR4BTest.java b/hapi-fhir-structures-r4b/src/test/java/ca/uhn/fhir/rest/server/SearchR4BTest.java index 6ef1d042800..d330801ee90 100644 --- a/hapi-fhir-structures-r4b/src/test/java/ca/uhn/fhir/rest/server/SearchR4BTest.java +++ b/hapi-fhir-structures-r4b/src/test/java/ca/uhn/fhir/rest/server/SearchR4BTest.java @@ -9,8 +9,6 @@ import ca.uhn.fhir.rest.api.EncodingEnum; import ca.uhn.fhir.rest.param.TokenAndListParam; import ca.uhn.fhir.test.utilities.JettyUtil; import ca.uhn.fhir.util.TestUtil; -import ca.uhn.fhir.validation.FhirValidator; -import ca.uhn.fhir.validation.ValidationResult; import org.apache.commons.io.IOUtils; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; @@ -34,13 +32,12 @@ import java.util.List; import java.util.concurrent.TimeUnit; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.fail; public class SearchR4BTest { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(SearchR4BTest.class); + private static final FhirContext ourCtx = FhirContext.forR4BCached(); private static CloseableHttpClient ourClient; - private static FhirContext ourCtx = FhirContext.forR4BCached(); private static TokenAndListParam ourIdentifiers; private static String ourLastMethod; private static int ourPort; @@ -60,7 +57,6 @@ public class SearchR4BTest { try (CloseableHttpResponse status = ourClient.execute(httpGet)) { String responseContent = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8); ourLog.info(responseContent); -// validate(ourCtx.newJsonParser().parseResource(responseContent)); assertEquals(200, status.getStatusLine().getStatusCode()); assertEquals("search", ourLastMethod); @@ -72,15 +68,6 @@ public class SearchR4BTest { } - private void validate(IBaseResource theResource) { - FhirValidator validatorModule = ourCtx.newValidator(); - ValidationResult result = validatorModule.validateWithResult(theResource); - if (!result.isSuccessful()) { - fail(ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(result.toOperationOutcome())); - } - } - - public static class DummyPatientResourceProvider implements IResourceProvider { @Override @@ -99,7 +86,7 @@ public class SearchR4BTest { for (int i = 0; i < 200; i++) { Patient patient = new Patient(); patient.getIdElement().setValue("Patient/" + i + "/_history/222"); - ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put(patient, BundleEntrySearchModeEnum.INCLUDE.getCode()); + ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put(patient, BundleEntrySearchModeEnum.INCLUDE); patient.addName(new HumanName().setFamily("FAMILY")); patient.setActive(true); retVal.add(patient); @@ -132,7 +119,7 @@ public class SearchR4BTest { proxyHandler.addServletWithMapping(servletHolder, "/*"); ourServer.setHandler(proxyHandler); JettyUtil.startServer(ourServer); - ourPort = JettyUtil.getPortForStartedServer(ourServer); + ourPort = JettyUtil.getPortForStartedServer(ourServer); PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS); HttpClientBuilder builder = HttpClientBuilder.create(); diff --git a/hapi-fhir-structures-r5/src/main/java/org/hl7/fhir/r5/hapi/rest/server/R5BundleFactory.java b/hapi-fhir-structures-r5/src/main/java/org/hl7/fhir/r5/hapi/rest/server/R5BundleFactory.java index 47d6f1b4fa2..59cb0aedbea 100644 --- a/hapi-fhir-structures-r5/src/main/java/org/hl7/fhir/r5/hapi/rest/server/R5BundleFactory.java +++ b/hapi-fhir-structures-r5/src/main/java/org/hl7/fhir/r5/hapi/rest/server/R5BundleFactory.java @@ -24,6 +24,8 @@ import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.api.BundleInclusionRule; import ca.uhn.fhir.model.api.Include; import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum; +import ca.uhn.fhir.model.valueset.BundleEntrySearchModeEnum; +import ca.uhn.fhir.model.valueset.BundleEntryTransactionMethodEnum; import ca.uhn.fhir.model.valueset.BundleTypeEnum; import ca.uhn.fhir.rest.api.BundleLinks; import ca.uhn.fhir.rest.api.Constants; @@ -134,14 +136,14 @@ public class R5BundleFactory implements IVersionSpecificBundleFactory { IIdType id = populateBundleEntryFullUrl(next, entry); // Populate Request - String httpVerb = ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.get(nextAsResource); + BundleEntryTransactionMethodEnum httpVerb = ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.get(nextAsResource); if (httpVerb != null) { - entry.getRequest().getMethodElement().setValueAsString(httpVerb); + entry.getRequest().getMethodElement().setValueAsString(httpVerb.name()); if (id != null) { entry.getRequest().setUrl(id.toUnqualified().getValue()); } } - if ("DELETE".equals(httpVerb)) { + if (BundleEntryTransactionMethodEnum.DELETE.equals(httpVerb)) { entry.setResource(null); } @@ -164,9 +166,9 @@ public class R5BundleFactory implements IVersionSpecificBundleFactory { } // Populate Bundle.entry.search - String searchMode = ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.get(nextAsResource); + BundleEntrySearchModeEnum searchMode = ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.get(nextAsResource); if (searchMode != null) { - entry.getSearch().getModeElement().setValueAsString(searchMode); + entry.getSearch().getModeElement().setValueAsString(searchMode.getCode()); } } diff --git a/hapi-fhir-structures-r5/src/test/java/ca/uhn/fhir/rest/server/SearchR5Test.java b/hapi-fhir-structures-r5/src/test/java/ca/uhn/fhir/rest/server/SearchR5Test.java index b038694578f..69dbc01f7c5 100644 --- a/hapi-fhir-structures-r5/src/test/java/ca/uhn/fhir/rest/server/SearchR5Test.java +++ b/hapi-fhir-structures-r5/src/test/java/ca/uhn/fhir/rest/server/SearchR5Test.java @@ -9,8 +9,6 @@ import ca.uhn.fhir.rest.api.EncodingEnum; import ca.uhn.fhir.rest.param.TokenAndListParam; import ca.uhn.fhir.test.utilities.JettyUtil; import ca.uhn.fhir.util.TestUtil; -import ca.uhn.fhir.validation.FhirValidator; -import ca.uhn.fhir.validation.ValidationResult; import org.apache.commons.io.IOUtils; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; @@ -34,13 +32,12 @@ import java.util.List; import java.util.concurrent.TimeUnit; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.fail; public class SearchR5Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(SearchR5Test.class); + private static final FhirContext ourCtx = FhirContext.forR5Cached(); private static CloseableHttpClient ourClient; - private static FhirContext ourCtx = FhirContext.forR5(); private static TokenAndListParam ourIdentifiers; private static String ourLastMethod; private static int ourPort; @@ -60,7 +57,6 @@ public class SearchR5Test { try (CloseableHttpResponse status = ourClient.execute(httpGet)) { String responseContent = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8); ourLog.info(responseContent); -// validate(ourCtx.newJsonParser().parseResource(responseContent)); assertEquals(200, status.getStatusLine().getStatusCode()); assertEquals("search", ourLastMethod); @@ -72,15 +68,6 @@ public class SearchR5Test { } - private void validate(IBaseResource theResource) { - FhirValidator validatorModule = ourCtx.newValidator(); - ValidationResult result = validatorModule.validateWithResult(theResource); - if (!result.isSuccessful()) { - fail(ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(result.toOperationOutcome())); - } - } - - public static class DummyPatientResourceProvider implements IResourceProvider { @Override @@ -99,7 +86,7 @@ public class SearchR5Test { for (int i = 0; i < 200; i++) { Patient patient = new Patient(); patient.getIdElement().setValue("Patient/" + i + "/_history/222"); - ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put(patient, BundleEntrySearchModeEnum.INCLUDE.getCode()); + ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put(patient, BundleEntrySearchModeEnum.INCLUDE); patient.addName(new HumanName().setFamily("FAMILY")); patient.setActive(true); retVal.add(patient); @@ -132,7 +119,7 @@ public class SearchR5Test { proxyHandler.addServletWithMapping(servletHolder, "/*"); ourServer.setHandler(proxyHandler); JettyUtil.startServer(ourServer); - ourPort = JettyUtil.getPortForStartedServer(ourServer); + ourPort = JettyUtil.getPortForStartedServer(ourServer); PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS); HttpClientBuilder builder = HttpClientBuilder.create();