From a0c40cf98a52acf639701be5d82f4bbb9b3c787e Mon Sep 17 00:00:00 2001 From: James Agnew Date: Sat, 5 May 2018 12:21:56 -0400 Subject: [PATCH] Move a few more constants around --- .../provider/JpaResourceProviderDstu2.java | 14 +++++------- .../dstu3/JpaResourceProviderDstu3.java | 20 +++++++---------- .../provider/r4/JpaResourceProviderR4.java | 22 +++++++------------ .../ca/uhn/fhir/jpa/util/JpaConstants.java | 19 ++++++++++++++++ .../provider/r4/ResourceProviderR4Test.java | 3 ++- pom.xml | 2 +- 6 files changed, 44 insertions(+), 36 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/JpaResourceProviderDstu2.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/JpaResourceProviderDstu2.java index 0b7a5b21007..31527e0c65d 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/JpaResourceProviderDstu2.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/JpaResourceProviderDstu2.java @@ -38,11 +38,9 @@ import org.hl7.fhir.instance.model.api.IIdType; import javax.servlet.http.HttpServletRequest; -public class JpaResourceProviderDstu2 extends BaseJpaResourceProvider { +import static ca.uhn.fhir.jpa.util.JpaConstants.*; - public static final String OPERATION_NAME_META = "$meta"; - public static final String OPERATION_NAME_META_DELETE = "$meta-delete"; - public static final String OPERATION_NAME_META_ADD = "$meta-add"; +public class JpaResourceProviderDstu2 extends BaseJpaResourceProvider { public JpaResourceProviderDstu2() { // nothing @@ -105,7 +103,7 @@ public class JpaResourceProviderDstu2 extends BaseJpaResour return JpaSystemProviderDstu2.toExpungeResponse(retVal); } - @Operation(name = OPERATION_NAME_META, idempotent = true, returnParameters = { + @Operation(name = OPERATION_META, idempotent = true, returnParameters = { @OperationParam(name = "return", type = MetaDt.class) }) public Parameters meta(RequestDetails theRequestDetails) { @@ -115,7 +113,7 @@ public class JpaResourceProviderDstu2 extends BaseJpaResour return parameters; } - @Operation(name = OPERATION_NAME_META, idempotent = true, returnParameters = { + @Operation(name = OPERATION_META, idempotent = true, returnParameters = { @OperationParam(name = "return", type = MetaDt.class) }) public Parameters meta(@IdParam IdDt theId, RequestDetails theRequestDetails) { @@ -125,7 +123,7 @@ public class JpaResourceProviderDstu2 extends BaseJpaResour return parameters; } - @Operation(name = OPERATION_NAME_META_ADD, idempotent = true, returnParameters = { + @Operation(name = OPERATION_META_ADD, idempotent = true, returnParameters = { @OperationParam(name = "return", type = MetaDt.class) }) public Parameters metaAdd(@IdParam IdDt theId, @OperationParam(name = "meta") MetaDt theMeta, RequestDetails theRequestDetails) { @@ -138,7 +136,7 @@ public class JpaResourceProviderDstu2 extends BaseJpaResour return parameters; } - @Operation(name = OPERATION_NAME_META_DELETE, idempotent = true, returnParameters = { + @Operation(name = OPERATION_META_DELETE, idempotent = true, returnParameters = { @OperationParam(name = "return", type = MetaDt.class) }) public Parameters metaDelete(@IdParam IdDt theId, @OperationParam(name = "meta") MetaDt theMeta, RequestDetails theRequestDetails) { diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/dstu3/JpaResourceProviderDstu3.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/dstu3/JpaResourceProviderDstu3.java index 8bafc5c9c9d..5f171580cee 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/dstu3/JpaResourceProviderDstu3.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/dstu3/JpaResourceProviderDstu3.java @@ -38,11 +38,11 @@ import org.hl7.fhir.instance.model.api.IIdType; import javax.servlet.http.HttpServletRequest; -public class JpaResourceProviderDstu3 extends BaseJpaResourceProvider { +import static ca.uhn.fhir.jpa.util.JpaConstants.OPERATION_META; +import static ca.uhn.fhir.jpa.util.JpaConstants.OPERATION_META_ADD; +import static ca.uhn.fhir.jpa.util.JpaConstants.OPERATION_META_DELETE; - public static final String OPERATION_NAME_META = "$meta"; - public static final String OPERATION_NAME_META_DELETE = "$meta-delete"; - public static final String OPERATION_NAME_META_ADD = "$meta-add"; +public class JpaResourceProviderDstu3 extends BaseJpaResourceProvider { public JpaResourceProviderDstu3() { // nothing @@ -113,11 +113,9 @@ public class JpaResourceProviderDstu3 extends BaseJpaRes } } - //@formatter:off - @Operation(name = OPERATION_NAME_META, idempotent = true, returnParameters = { + @Operation(name = OPERATION_META, idempotent = true, returnParameters = { @OperationParam(name = "return", type = Meta.class) }) - //@formatter:on public Parameters meta(RequestDetails theRequestDetails) { Parameters parameters = new Parameters(); Meta metaGetOperation = getDao().metaGetOperation(Meta.class, theRequestDetails); @@ -125,11 +123,9 @@ public class JpaResourceProviderDstu3 extends BaseJpaRes return parameters; } - //@formatter:off - @Operation(name = OPERATION_NAME_META, idempotent = true, returnParameters = { + @Operation(name = OPERATION_META, idempotent = true, returnParameters = { @OperationParam(name = "return", type = Meta.class) }) - //@formatter:on public Parameters meta(@IdParam IdType theId, RequestDetails theRequestDetails) { Parameters parameters = new Parameters(); Meta metaGetOperation = getDao().metaGetOperation(Meta.class, theId, theRequestDetails); @@ -137,7 +133,7 @@ public class JpaResourceProviderDstu3 extends BaseJpaRes return parameters; } - @Operation(name = OPERATION_NAME_META_ADD, idempotent = true, returnParameters = { + @Operation(name = OPERATION_META_ADD, idempotent = true, returnParameters = { @OperationParam(name = "return", type = Meta.class) }) public Parameters metaAdd(@IdParam IdType theId, @OperationParam(name = "meta") Meta theMeta, RequestDetails theRequestDetails) { @@ -150,7 +146,7 @@ public class JpaResourceProviderDstu3 extends BaseJpaRes return parameters; } - @Operation(name = OPERATION_NAME_META_DELETE, idempotent = true, returnParameters = { + @Operation(name = OPERATION_META_DELETE, idempotent = true, returnParameters = { @OperationParam(name = "return", type = Meta.class) }) public Parameters metaDelete(@IdParam IdType theId, @OperationParam(name = "meta") Meta theMeta, RequestDetails theRequestDetails) { diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/r4/JpaResourceProviderR4.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/r4/JpaResourceProviderR4.java index e89d3e1c76f..791b9b60fc4 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/r4/JpaResourceProviderR4.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/r4/JpaResourceProviderR4.java @@ -35,11 +35,11 @@ import org.hl7.fhir.r4.model.*; import javax.servlet.http.HttpServletRequest; -public class JpaResourceProviderR4 extends BaseJpaResourceProvider { +import static ca.uhn.fhir.jpa.util.JpaConstants.OPERATION_META; +import static ca.uhn.fhir.jpa.util.JpaConstants.OPERATION_META_ADD; +import static ca.uhn.fhir.jpa.util.JpaConstants.OPERATION_META_DELETE; - public static final String OPERATION_NAME_META = "$meta"; - public static final String OPERATION_NAME_META_DELETE = "$meta-delete"; - public static final String OPERATION_NAME_META_ADD = "$meta-add"; +public class JpaResourceProviderR4 extends BaseJpaResourceProvider { public JpaResourceProviderR4() { // nothing @@ -100,7 +100,7 @@ public class JpaResourceProviderR4 extends BaseJpaResour return super.doExpunge(null, theLimit, theExpungeDeletedResources, theExpungeOldVersions, null); } - @Operation(name = OPERATION_NAME_META, idempotent = true, returnParameters = { + @Operation(name = OPERATION_META, idempotent = true, returnParameters = { @OperationParam(name = "return", type = Meta.class) }) public Parameters meta(RequestDetails theRequestDetails) { @@ -110,11 +110,9 @@ public class JpaResourceProviderR4 extends BaseJpaResour return parameters; } - //@formatter:off - @Operation(name = OPERATION_NAME_META, idempotent = true, returnParameters = { + @Operation(name = OPERATION_META, idempotent = true, returnParameters = { @OperationParam(name = "return", type = Meta.class) }) - //@formatter:on public Parameters meta(@IdParam IdType theId, RequestDetails theRequestDetails) { Parameters parameters = new Parameters(); Meta metaGetOperation = getDao().metaGetOperation(Meta.class, theId, theRequestDetails); @@ -122,11 +120,9 @@ public class JpaResourceProviderR4 extends BaseJpaResour return parameters; } - //@formatter:off - @Operation(name = OPERATION_NAME_META_ADD, idempotent = true, returnParameters = { + @Operation(name = OPERATION_META_ADD, idempotent = true, returnParameters = { @OperationParam(name = "return", type = Meta.class) }) - //@formatter:on public Parameters metaAdd(@IdParam IdType theId, @OperationParam(name = "meta") Meta theMeta, RequestDetails theRequestDetails) { if (theMeta == null) { throw new InvalidRequestException("Input contains no parameter with name 'meta'"); @@ -137,11 +133,9 @@ public class JpaResourceProviderR4 extends BaseJpaResour return parameters; } - //@formatter:off - @Operation(name = OPERATION_NAME_META_DELETE, idempotent = true, returnParameters = { + @Operation(name = OPERATION_META_DELETE, idempotent = true, returnParameters = { @OperationParam(name = "return", type = Meta.class) }) - //@formatter:on public Parameters metaDelete(@IdParam IdType theId, @OperationParam(name = "meta") Meta theMeta, RequestDetails theRequestDetails) { if (theMeta == null) { throw new InvalidRequestException("Input contains no parameter with name 'meta'"); diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/util/JpaConstants.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/util/JpaConstants.java index f8ef0c4a352..dd80d0b63e5 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/util/JpaConstants.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/util/JpaConstants.java @@ -20,6 +20,8 @@ package ca.uhn.fhir.jpa.util; * #L% */ +import ca.uhn.fhir.rest.api.Constants; + public class JpaConstants { public static final String EXT_SP_UNIQUE = "http://hapifhir.io/fhir/StructureDefinition/sp-unique"; @@ -132,6 +134,12 @@ public class JpaConstants { */ public static final String OPERATION_META = "$meta"; + /** + * Operation name for the $validate operation + */ + // NB don't delete this, it's used in Smile as well, even though hapi-fhir-server uses the version from Constants.java + public static final String OPERATION_VALIDATE = Constants.EXTOP_VALIDATE; + /** * Operation name for the $suggest-keywords operation */ @@ -141,4 +149,15 @@ public class JpaConstants { * Operation name for the $everything operation */ public static final String OPERATION_EVERYTHING = "$everything"; + + /** + * Operation name for the $meta-delete operation + */ + public static final String OPERATION_META_DELETE = "$meta-delete"; + + /** + * Operation name for the $meta-add operation + */ + public static final String OPERATION_META_ADD = "$meta-add"; + } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java index e590ee1a247..c03e8f850aa 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java @@ -5,6 +5,7 @@ import ca.uhn.fhir.jpa.dao.DaoConfig; import ca.uhn.fhir.jpa.entity.ResourceHistoryTable; import ca.uhn.fhir.jpa.entity.Search; import ca.uhn.fhir.jpa.search.SearchCoordinatorSvcImpl; +import ca.uhn.fhir.jpa.util.JpaConstants; import ca.uhn.fhir.util.StopWatch; import ca.uhn.fhir.model.api.TemporalPrecisionEnum; import ca.uhn.fhir.model.primitive.InstantDt; @@ -1561,7 +1562,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { public void testExtensionUrlWithHl7Url() throws IOException { String input = IOUtils.toString(ResourceProviderR4Test.class.getResourceAsStream("/bug872-ext-with-hl7-url.json"), Charsets.UTF_8); - HttpPost post = new HttpPost(ourServerBase + "/Patient/$validate"); + HttpPost post = new HttpPost(ourServerBase + "/Patient/" + JpaConstants.OPERATION_VALIDATE); post.setEntity(new StringEntity(input, ContentType.APPLICATION_JSON)); CloseableHttpResponse resp = ourHttpClient.execute(post); diff --git a/pom.xml b/pom.xml index ee13619ae21..3095fe8f8b3 100644 --- a/pom.xml +++ b/pom.xml @@ -1312,7 +1312,7 @@ org.codehaus.mojo license-maven-plugin - 1.14 + 1.16 true false