diff --git a/operation/fhir-operation-bulkdata/src/main/java/com/ibm/fhir/operation/bulkdata/ExportOperation.java b/operation/fhir-operation-bulkdata/src/main/java/com/ibm/fhir/operation/bulkdata/ExportOperation.java index 19a3867be9b..acd662024f0 100644 --- a/operation/fhir-operation-bulkdata/src/main/java/com/ibm/fhir/operation/bulkdata/ExportOperation.java +++ b/operation/fhir-operation-bulkdata/src/main/java/com/ibm/fhir/operation/bulkdata/ExportOperation.java @@ -12,6 +12,7 @@ import javax.ws.rs.core.MediaType; import com.ibm.fhir.core.FHIRMediaType; +import com.ibm.fhir.core.FHIRVersionParam; import com.ibm.fhir.exception.FHIROperationException; import com.ibm.fhir.model.resource.OperationDefinition; import com.ibm.fhir.model.resource.Parameters; @@ -66,7 +67,8 @@ protected Parameters doInvoke(FHIROperationContext operationContext, Class types = export.checkAndValidateTypes(exportType, getParameters(parameters, OperationConstants.PARAM_TYPE)); + FHIRVersionParam fhirVersion = (FHIRVersionParam) operationContext.getProperty(FHIROperationContext.PROPNAME_FHIR_VERSION); + Set types = export.checkAndValidateTypes(exportType, fhirVersion, getParameters(parameters, OperationConstants.PARAM_TYPE)); if (!ExportType.INVALID.equals(exportType)) { diff --git a/operation/fhir-operation-bulkdata/src/main/java/com/ibm/fhir/operation/bulkdata/ImportOperation.java b/operation/fhir-operation-bulkdata/src/main/java/com/ibm/fhir/operation/bulkdata/ImportOperation.java index 91d5998679c..6d1072813c5 100644 --- a/operation/fhir-operation-bulkdata/src/main/java/com/ibm/fhir/operation/bulkdata/ImportOperation.java +++ b/operation/fhir-operation-bulkdata/src/main/java/com/ibm/fhir/operation/bulkdata/ImportOperation.java @@ -9,6 +9,7 @@ import java.io.InputStream; import java.util.List; +import com.ibm.fhir.core.FHIRVersionParam; import com.ibm.fhir.exception.FHIROperationException; import com.ibm.fhir.model.format.Format; import com.ibm.fhir.model.parser.FHIRParser; @@ -70,7 +71,8 @@ protected Parameters doInvoke(FHIROperationContext operationContext, Class inputs = util.retrieveInputs(); + FHIRVersionParam fhirVersion = (FHIRVersionParam) operationContext.getProperty(FHIROperationContext.PROPNAME_FHIR_VERSION); + List inputs = util.retrieveInputs(fhirVersion); // Parameter: storageDetail StorageDetail storageDetail = util.retrieveStorageDetails(); @@ -86,7 +88,7 @@ private void checkImportType(FHIROperationContext.Type type) throws FHIROperatio // Check Import Type is System. We only support system right now. if (!FHIROperationContext.Type.SYSTEM.equals(type)) { - throw buildExceptionWithIssue("Invalid call $import operation call only system is allowed", + throw buildExceptionWithIssue("Invalid call; $import can only be invoked at the system level", IssueType.INVALID); } } diff --git a/operation/fhir-operation-bulkdata/src/main/java/com/ibm/fhir/operation/bulkdata/config/preflight/impl/AzurePreflight.java b/operation/fhir-operation-bulkdata/src/main/java/com/ibm/fhir/operation/bulkdata/config/preflight/impl/AzurePreflight.java index 6287ac21ee6..c9c8cc889a4 100644 --- a/operation/fhir-operation-bulkdata/src/main/java/com/ibm/fhir/operation/bulkdata/config/preflight/impl/AzurePreflight.java +++ b/operation/fhir-operation-bulkdata/src/main/java/com/ibm/fhir/operation/bulkdata/config/preflight/impl/AzurePreflight.java @@ -1,5 +1,5 @@ /* - * (C) Copyright IBM Corp. 2021 + * (C) Copyright IBM Corp. 2021, 2022 * * SPDX-License-Identifier: Apache-2.0 */ @@ -41,13 +41,13 @@ public void preflight() throws FHIROperationException { /** * validates the azure provider is properly configured. * - * @param source + * @param storageProvider * @throws FHIROperationException */ - public void validate(String source) throws FHIROperationException { + public void validate(String storageProvider) throws FHIROperationException { ConfigurationAdapter adapter = ConfigurationFactory.getInstance(); - if (adapter.isStorageProviderAuthTypeConnectionString(source)) { - String conn = adapter.getStorageProviderAuthTypeConnectionString(source); + if (adapter.isStorageProviderAuthTypeConnectionString(storageProvider)) { + String conn = adapter.getStorageProviderAuthTypeConnectionString(storageProvider); if (conn == null || conn.isEmpty()) { throw export.buildOperationException("bad configuration for the Azure Blob Container's connection configuration", IssueType.EXCEPTION); } @@ -56,7 +56,7 @@ public void validate(String source) throws FHIROperationException { } // Used to get the Azure Container - if (adapter.getStorageProviderBucketName(source) == null || adapter.getStorageProviderBucketName(source).isEmpty()) { + if (adapter.getStorageProviderBucketName(storageProvider) == null || adapter.getStorageProviderBucketName(storageProvider).isEmpty()) { throw export.buildOperationException("bad configuration for the basic configuration with bucketname", IssueType.EXCEPTION); } } diff --git a/operation/fhir-operation-bulkdata/src/main/java/com/ibm/fhir/operation/bulkdata/util/BulkDataExportUtil.java b/operation/fhir-operation-bulkdata/src/main/java/com/ibm/fhir/operation/bulkdata/util/BulkDataExportUtil.java index 473b4583c60..73795a4e737 100644 --- a/operation/fhir-operation-bulkdata/src/main/java/com/ibm/fhir/operation/bulkdata/util/BulkDataExportUtil.java +++ b/operation/fhir-operation-bulkdata/src/main/java/com/ibm/fhir/operation/bulkdata/util/BulkDataExportUtil.java @@ -22,6 +22,7 @@ import com.ibm.fhir.config.FHIRConfigHelper; import com.ibm.fhir.core.FHIRMediaType; +import com.ibm.fhir.core.FHIRVersionParam; import com.ibm.fhir.exception.FHIROperationException; import com.ibm.fhir.model.resource.OperationOutcome.Issue; import com.ibm.fhir.model.resource.Parameters; @@ -161,11 +162,13 @@ public Instant checkAndExtractSince(Parameters parameters) { * processes both the Parameters object and the query parameters * * @param exportType + * @param fhirVersion * @param parameters * @return * @throws FHIROperationException */ - public Set checkAndValidateTypes(OperationConstants.ExportType exportType, List parameters) throws FHIROperationException { + public Set checkAndValidateTypes(OperationConstants.ExportType exportType, FHIRVersionParam fhirVersion, List parameters) + throws FHIROperationException { /* * Only resources of the specified resource types(s) SHALL be included in the response. If this parameter is * omitted, the server SHALL return all supported resources within the scope of the client authorization. For @@ -179,7 +182,7 @@ public Set checkAndValidateTypes(OperationConstants.ExportType exportTyp * within the file set. For example _type=Practitioner could be used to bulk data extract all Practitioner * resources from a FHIR endpoint. */ - Set supportedResourceTypes = FHIRConfigHelper.getSupportedResourceTypes(); + Set supportedResourceTypes = FHIRConfigHelper.getSupportedResourceTypes(fhirVersion); Set result = new HashSet<>(); if (parameters != null) { for (Parameters.Parameter parameter : parameters) { @@ -203,7 +206,7 @@ public Set checkAndValidateTypes(OperationConstants.ExportType exportTyp } } - // The case where no resourceTypes are specified, inlining only the supported ResourceTypes + // The case where no resourceTypes are specified on a system export, inlining only the supported ResourceTypes if (result.isEmpty() && ExportType.SYSTEM.equals(exportType)) { result = new HashSet<>(supportedResourceTypes); } else if (ExportType.PATIENT.equals(exportType) || ExportType.GROUP.equals(exportType)) { @@ -234,7 +237,7 @@ private Set filterTypesToPatientResourceTypes(Set resourceTypes) result.add(resourceType); } else { LOG.info("Requested type '" + Encode.forHtml(resourceType) + "' cannot be in the Patient compartment;" - + "this is not supported for Patient/Group export and so this type will be skipped"); + + " this is not supported for Patient/Group export and so this type will be skipped"); } } diff --git a/operation/fhir-operation-bulkdata/src/main/java/com/ibm/fhir/operation/bulkdata/util/BulkDataImportUtil.java b/operation/fhir-operation-bulkdata/src/main/java/com/ibm/fhir/operation/bulkdata/util/BulkDataImportUtil.java index ea4448f7e99..2dc62f280a4 100644 --- a/operation/fhir-operation-bulkdata/src/main/java/com/ibm/fhir/operation/bulkdata/util/BulkDataImportUtil.java +++ b/operation/fhir-operation-bulkdata/src/main/java/com/ibm/fhir/operation/bulkdata/util/BulkDataImportUtil.java @@ -6,6 +6,7 @@ package com.ibm.fhir.operation.bulkdata.util; +import static com.ibm.fhir.model.util.ModelSupport.FHIR_STRING; import static com.ibm.fhir.operation.bulkdata.util.CommonUtil.buildExceptionWithIssue; import java.util.ArrayList; @@ -16,8 +17,10 @@ import java.util.Set; import com.ibm.fhir.config.FHIRConfigHelper; +import com.ibm.fhir.core.FHIRVersionParam; import com.ibm.fhir.exception.FHIROperationException; import com.ibm.fhir.model.resource.Parameters; +import com.ibm.fhir.model.type.Uri; import com.ibm.fhir.model.type.code.IssueType; import com.ibm.fhir.model.util.ModelSupport; import com.ibm.fhir.operation.bulkdata.OperationConstants; @@ -95,7 +98,7 @@ public String retrieveInputSource() throws FHIROperationException { Iterator iter = result.iterator(); while (iter.hasNext()) { FHIRPathElementNode node = (FHIRPathElementNode) iter.next(); - return node.asElementNode().element().as(com.ibm.fhir.model.type.Uri.class).getValue(); + return node.asElementNode().element().as(Uri.class).getValue(); } } catch (NoSuchElementException | ClassCastException | FHIRPathException e) { throw buildExceptionWithIssue("invalid $import parameter value in 'inputSource'", e, IssueType.INVALID); @@ -105,17 +108,18 @@ public String retrieveInputSource() throws FHIROperationException { } /** - * processes the retrieve inputs from the Parameters object and evaluationContext. + * Validate and retrieve the inputs from the Parameters object. * + * @param fhirVersion * @return * @throws FHIROperationException */ - public List retrieveInputs() throws FHIROperationException { + public List retrieveInputs(FHIRVersionParam fhirVersion) throws FHIROperationException { // Parameter: input (required) List inputs = new ArrayList<>(); try { - Set supportedResourceTypes = FHIRConfigHelper.getSupportedResourceTypes(); + Set supportedResourceTypes = FHIRConfigHelper.getSupportedResourceTypes(fhirVersion); Collection result = evaluator.evaluate(evaluationContext, "parameter.where(name = 'input')"); Iterator iter = result.iterator(); @@ -230,7 +234,7 @@ public StorageDetail retrieveStorageDetails() throws FHIROperationException { EvaluationContext evaluationContextPartType = new EvaluationContext(node.element()); Collection resultPartType = evaluator.evaluate(evaluationContextPartType, "value"); String type = - ((FHIRPathElementNode) resultPartType.iterator().next()).element().as(com.ibm.fhir.model.type.String.class).getValue(); + ((FHIRPathElementNode) resultPartType.iterator().next()).element().as(FHIR_STRING).getValue(); // Checks if not valid, and throws exception if (!OperationConstants.STORAGE_TYPES.contains(type)) { diff --git a/operation/fhir-operation-bulkdata/src/test/java/com/ibm/fhir/operation/bulkdata/util/BulkDataExportUtilTest.java b/operation/fhir-operation-bulkdata/src/test/java/com/ibm/fhir/operation/bulkdata/util/BulkDataExportUtilTest.java index 26b7124cebd..c4668e648b0 100644 --- a/operation/fhir-operation-bulkdata/src/test/java/com/ibm/fhir/operation/bulkdata/util/BulkDataExportUtilTest.java +++ b/operation/fhir-operation-bulkdata/src/test/java/com/ibm/fhir/operation/bulkdata/util/BulkDataExportUtilTest.java @@ -33,6 +33,7 @@ import com.ibm.fhir.config.FHIRConfiguration; import com.ibm.fhir.config.FHIRRequestContext; +import com.ibm.fhir.core.FHIRVersionParam; import com.ibm.fhir.exception.FHIRException; import com.ibm.fhir.exception.FHIROperationException; import com.ibm.fhir.model.resource.Group; @@ -281,42 +282,42 @@ public void testCheckAndExtractSinceWithInvalidType() { @Test(expectedExceptions = { com.ibm.fhir.exception.FHIROperationException.class }) public void testCheckAndValidateTypesEmpty() throws FHIROperationException { List parameters = List.of(Parameter.builder().name(string("_type")).value(string("1")).build()); - util.checkAndValidateTypes(ExportType.SYSTEM, parameters); + util.checkAndValidateTypes(ExportType.SYSTEM, FHIRVersionParam.VERSION_43, parameters); fail(); } @Test(expectedExceptions = { com.ibm.fhir.exception.FHIROperationException.class }) public void testCheckAndValidateTypesNull() throws FHIROperationException { List parameters = List.of(Parameter.builder().name(string("_type")).value((Element)null).build()); - util.checkAndValidateTypes(ExportType.SYSTEM, parameters); + util.checkAndValidateTypes(ExportType.SYSTEM, FHIRVersionParam.VERSION_43, parameters); fail(); } @Test(expectedExceptions = { com.ibm.fhir.exception.FHIROperationException.class }) public void testCheckAndValidateTypesNullQPS() throws FHIROperationException { List parameters = List.of(Parameter.builder().name(string("_type")).value((Element) null).build()); - util.checkAndValidateTypes(ExportType.SYSTEM, parameters); + util.checkAndValidateTypes(ExportType.SYSTEM, FHIRVersionParam.VERSION_43, parameters); fail(); } @Test public void testCheckAndValidateTypesPatientWithoutComma() throws FHIROperationException { List parameters = List.of(Parameter.builder().name(string("_type")).value(string("Patient")).build()); - Set types = util.checkAndValidateTypes(ExportType.SYSTEM, parameters); + Set types = util.checkAndValidateTypes(ExportType.SYSTEM, FHIRVersionParam.VERSION_43, parameters); assertNotNull(types); } @Test public void testCheckAndValidateTypesPatientWithComma() throws FHIROperationException { List parameters = List.of(Parameter.builder().name(string("_type")).value(string("Patient,")).build()); - Set types = util.checkAndValidateTypes(ExportType.SYSTEM, parameters); + Set types = util.checkAndValidateTypes(ExportType.SYSTEM, FHIRVersionParam.VERSION_43, parameters); assertNotNull(types); } @Test public void testCheckAndValidateTypesPatientMedicationWithComma() throws FHIROperationException { List parameters = List.of(Parameter.builder().name(string("_type")).value(string("Patient,Medication")).build()); - Set types = util.checkAndValidateTypes(ExportType.SYSTEM, parameters); + Set types = util.checkAndValidateTypes(ExportType.SYSTEM, FHIRVersionParam.VERSION_43, parameters); assertNotNull(types); } @@ -324,7 +325,7 @@ public void testCheckAndValidateTypesPatientMedicationWithComma() throws FHIROpe public void testCheckAndValidateTypesPatientMedicationWithExtraComma() throws FHIROperationException { // parameters List parameters = List.of(Parameter.builder().name(string("_type")).value(string("Patient,,Medication")).build()); - util.checkAndValidateTypes(ExportType.SYSTEM, parameters); + util.checkAndValidateTypes(ExportType.SYSTEM, FHIRVersionParam.VERSION_43, parameters); fail(); } @@ -332,7 +333,7 @@ public void testCheckAndValidateTypesPatientMedicationWithExtraComma() throws FH public void testCheckAndValidateTypesWithExtraComma() throws FHIROperationException { // parameters List parameters = List.of(Parameter.builder().name(string("_type")).value(string(",,")).build()); - Set result = util.checkAndValidateTypes(ExportType.SYSTEM, parameters); + Set result = util.checkAndValidateTypes(ExportType.SYSTEM, FHIRVersionParam.VERSION_43, parameters); assertNotNull(result); assertFalse(result.isEmpty()); } @@ -341,14 +342,14 @@ public void testCheckAndValidateTypesWithExtraComma() throws FHIROperationExcept public void testCheckAndValidateTypesNoParameters() throws FHIROperationException { // parameters List parameters = List.of(Parameter.builder().name(string("french")).value(string("Patient,,Medication")).build()); - Set result = util.checkAndValidateTypes(ExportType.SYSTEM, parameters); + Set result = util.checkAndValidateTypes(ExportType.SYSTEM, FHIRVersionParam.VERSION_43, parameters); assertNotNull(result); assertFalse(result.isEmpty()); } @Test public void testCheckAndValidateTypesEmptyParameters() throws FHIROperationException { - Set result = util.checkAndValidateTypes(ExportType.SYSTEM, null); + Set result = util.checkAndValidateTypes(ExportType.SYSTEM, FHIRVersionParam.VERSION_43, null); assertNotNull(result); assertFalse(result.isEmpty()); } diff --git a/operation/fhir-operation-bulkdata/src/test/java/com/ibm/fhir/operation/bulkdata/util/BulkDataImportUtilTest.java b/operation/fhir-operation-bulkdata/src/test/java/com/ibm/fhir/operation/bulkdata/util/BulkDataImportUtilTest.java index 3a4d61d59e9..40953c90389 100644 --- a/operation/fhir-operation-bulkdata/src/test/java/com/ibm/fhir/operation/bulkdata/util/BulkDataImportUtilTest.java +++ b/operation/fhir-operation-bulkdata/src/test/java/com/ibm/fhir/operation/bulkdata/util/BulkDataImportUtilTest.java @@ -32,6 +32,7 @@ import com.ibm.fhir.config.FHIRConfiguration; import com.ibm.fhir.config.FHIRRequestContext; +import com.ibm.fhir.core.FHIRVersionParam; import com.ibm.fhir.exception.FHIRException; import com.ibm.fhir.exception.FHIROperationException; import com.ibm.fhir.model.format.Format; @@ -66,8 +67,8 @@ public void testBulkImportUtilInputs() throws IOException, FHIRException { FHIRRequestContext.set(context); context.setTenantId("not-config"); BulkDataImportUtil util = new BulkDataImportUtil(getContext(), loadTestFile("/testdata/import/import-demo.json")); - assertFalse(util.retrieveInputs().isEmpty()); - assertEquals(util.retrieveInputs().size(), 2); + assertFalse(util.retrieveInputs(FHIRVersionParam.VERSION_43).isEmpty()); + assertEquals(util.retrieveInputs(FHIRVersionParam.VERSION_43).size(), 2); } @Test @@ -160,7 +161,7 @@ public void testCheckAllowedResourceTypesForInputs() throws IOException, FHIRExc FHIRRequestContext.set(context); context.setTenantId("config"); BulkDataImportUtil util = new BulkDataImportUtil(getContext(), loadTestFile("/testdata/import/import-demo-config.json")); - util.retrieveInputs(); + util.retrieveInputs(FHIRVersionParam.VERSION_43); } @Test(expectedExceptions = { FHIROperationException.class }) @@ -169,7 +170,7 @@ public void testCheckAllowedResourceTypesForInputsBad() throws IOException, FHIR FHIRRequestContext.set(context); context.setTenantId("not-config"); BulkDataImportUtil util = new BulkDataImportUtil(getContext(), loadTestFile("/testdata/import/import-demo-not-config.json")); - util.retrieveInputs(); + util.retrieveInputs(FHIRVersionParam.VERSION_43); } public Parameters loadTestFile(String file) throws FHIRParserException, IOException { diff --git a/operation/fhir-operation-everything/src/main/java/com/ibm/fhir/operation/everything/EverythingOperation.java b/operation/fhir-operation-everything/src/main/java/com/ibm/fhir/operation/everything/EverythingOperation.java index 97da2c0672c..ca80210de2b 100644 --- a/operation/fhir-operation-everything/src/main/java/com/ibm/fhir/operation/everything/EverythingOperation.java +++ b/operation/fhir-operation-everything/src/main/java/com/ibm/fhir/operation/everything/EverythingOperation.java @@ -46,7 +46,6 @@ import com.ibm.fhir.model.type.code.BundleType; import com.ibm.fhir.model.type.code.HTTPVerb; import com.ibm.fhir.model.type.code.IssueType; -import com.ibm.fhir.model.type.code.SearchEntryMode; import com.ibm.fhir.model.util.ModelSupport; import com.ibm.fhir.model.util.ReferenceFinder; import com.ibm.fhir.registry.FHIRRegistry; @@ -205,7 +204,7 @@ protected Parameters doInvoke(FHIROperationContext operationContext, Class queryParametersWithoutDates = new MultivaluedHashMap(queryParameters); boolean startOrEndProvided = queryParametersWithoutDates.remove(DATE_QUERY_PARAMETER) != null; - List defaultResourceTypes = new ArrayList(0); + List defaultResourceTypes; try { FHIRVersionParam fhirVersion = (FHIRVersionParam) operationContext.getProperty(FHIROperationContext.PROPNAME_FHIR_VERSION); defaultResourceTypes = getDefaultIncludedResourceTypes(resourceHelper, fhirVersion);