From 8a664a698838a3195d45483b55b2ad2cc4e90486 Mon Sep 17 00:00:00 2001 From: ThishaniLucas Date: Wed, 8 Nov 2023 13:47:04 +0530 Subject: [PATCH] Add multiple fixes * Upgrading to bal 8 * Fixing https://github.com/wso2-enterprise/open-healthcare/issues/1443 * Adding a validation for dependent package name fixing https://github.com/wso2-enterprise/open-healthcare/issues/1445 * Adding a summary for package md * Updating help text --- .github/workflows/cd.yml | 4 +- .github/workflows/ci.yml | 4 +- README.md | 4 +- ballerina/pom.xml | 2 +- .../health-tool-ballerina/.devcontainer.json | 4 -- .../health-tool-ballerina/Dependencies.toml | 71 ------------------- .../packagegen/tool/ToolConstants.java | 2 + .../modelgen/DatatypeContextGenerator.java | 2 + .../modelgen/ResourceContextGenerator.java | 6 +- .../src/main/resources/templates/package.vm | 2 + .../ballerina/health/cmd/fhir/FhirSubCmd.java | 7 ++ .../src/main/resources/ballerina-health.help | 48 +++++++------ .../src/main/resources/tool-config.json | 4 +- pom.xml | 2 +- 14 files changed, 53 insertions(+), 109 deletions(-) delete mode 100644 ballerina/src/main/resources/health-tool-ballerina/.devcontainer.json delete mode 100644 ballerina/src/main/resources/health-tool-ballerina/Dependencies.toml diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 3d6acf0..dc34463 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -29,13 +29,13 @@ jobs: - name: Setup Java and Maven uses: actions/setup-java@v2 with: - java-version: '11' + java-version: '17' distribution: 'temurin' - name: Setup Ballerina uses: ballerina-platform/setup-ballerina@v1.1.0 with: - version: 2201.7.0 + version: 2201.8.1 - name: Create settings.xml run: echo ' diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c435cdd..9f40133 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,13 +22,13 @@ jobs: - name: Setup Maven uses: actions/setup-java@v2 with: - java-version: '11' + java-version: '17' distribution: 'temurin' - name: Setup Ballerina uses: ballerina-platform/setup-ballerina@v1.1.0 with: - version: 2201.7.0 + version: 2201.8.1 - name: Create settings.xml run: echo ' diff --git a/README.md b/README.md index 29e2192..02b3a63 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ ## Building form Source ### Prerequisites -- [Java 11](https://openjdk.org/projects/jdk/11/) (v11.0.19) -- [Ballerina Swan Lake Update 7](https://ballerina.io/downloads/) (v2201.7.0) +- [Java 17](https://openjdk.org/projects/jdk/17/) +- [Ballerina Swan Lake Update 8](https://ballerina.io/downloads/) (v2201.8.1) - Add your Github Personal Access Token to the `.m2/settings.xml` to get access the `ballerina-lang` dependencies. (Make sure to have the id as `ballerina-language-repo`) ```xml diff --git a/ballerina/pom.xml b/ballerina/pom.xml index ab9831b..ba885e4 100644 --- a/ballerina/pom.xml +++ b/ballerina/pom.xml @@ -33,7 +33,7 @@ ${project.version} - 2201.6.0 + 2201.8.1 diff --git a/ballerina/src/main/resources/health-tool-ballerina/.devcontainer.json b/ballerina/src/main/resources/health-tool-ballerina/.devcontainer.json deleted file mode 100644 index ff72130..0000000 --- a/ballerina/src/main/resources/health-tool-ballerina/.devcontainer.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "image": "ballerina/ballerina-devcontainer:2201.5.0-SNAPSHOT", - "extensions": ["WSO2.ballerina"], -} diff --git a/ballerina/src/main/resources/health-tool-ballerina/Dependencies.toml b/ballerina/src/main/resources/health-tool-ballerina/Dependencies.toml deleted file mode 100644 index 3673845..0000000 --- a/ballerina/src/main/resources/health-tool-ballerina/Dependencies.toml +++ /dev/null @@ -1,71 +0,0 @@ -# AUTO-GENERATED FILE. DO NOT MODIFY. - -# This file is auto-generated by Ballerina for managing dependency versions. -# It should not be modified by hand. - -[ballerina] -dependencies-toml-version = "2" -distribution-version = "2201.6.0" - -[[package]] -org = "ballerina" -name = "io" -version = "1.4.1" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.value"} -] -modules = [ - {org = "ballerina", packageName = "io", moduleName = "io"} -] - -[[package]] -org = "ballerina" -name = "jballerina.java" -version = "0.0.0" -scope = "testOnly" - -[[package]] -org = "ballerina" -name = "lang.error" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - -[[package]] -org = "ballerina" -name = "lang.value" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - -[[package]] -org = "ballerina" -name = "test" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.error"} -] -modules = [ - {org = "ballerina", packageName = "test", moduleName = "test"} -] - -[[package]] -org = "isurusamaranayake" -name = "health" -version = "0.1.10" -dependencies = [ - {org = "ballerina", name = "io"}, - {org = "ballerina", name = "test"} -] -modules = [ - {org = "isurusamaranayake", packageName = "health", moduleName = "health"} -] - diff --git a/native/fhir-to-bal-lib/src/main/java/org/wso2/healthcare/fhir/ballerina/packagegen/tool/ToolConstants.java b/native/fhir-to-bal-lib/src/main/java/org/wso2/healthcare/fhir/ballerina/packagegen/tool/ToolConstants.java index 6a672fc..89925c1 100644 --- a/native/fhir-to-bal-lib/src/main/java/org/wso2/healthcare/fhir/ballerina/packagegen/tool/ToolConstants.java +++ b/native/fhir-to-bal-lib/src/main/java/org/wso2/healthcare/fhir/ballerina/packagegen/tool/ToolConstants.java @@ -69,6 +69,8 @@ public class ToolConstants { public static final String TOML_EXTENSION = ".toml"; public static final String MD_EXTENSION = ".md"; public static final String CONSTRAINTS_LIB_IMPORT = "ballerina/constraint"; + public static final String ELEMENT = "Element"; + public enum TokenPosition { BEGIN, MIDDLE, diff --git a/native/fhir-to-bal-lib/src/main/java/org/wso2/healthcare/fhir/ballerina/packagegen/tool/modelgen/DatatypeContextGenerator.java b/native/fhir-to-bal-lib/src/main/java/org/wso2/healthcare/fhir/ballerina/packagegen/tool/modelgen/DatatypeContextGenerator.java index b30797b..34bc39d 100644 --- a/native/fhir-to-bal-lib/src/main/java/org/wso2/healthcare/fhir/ballerina/packagegen/tool/modelgen/DatatypeContextGenerator.java +++ b/native/fhir-to-bal-lib/src/main/java/org/wso2/healthcare/fhir/ballerina/packagegen/tool/modelgen/DatatypeContextGenerator.java @@ -94,6 +94,8 @@ private void populateDatatypeContext() { String typeCode = elementDefinition.getType().get(0).getCode(); if (GeneratorUtils.getInstance().shouldReplacedByBalType(typeCode)) { element.setDataType(GeneratorUtils.getInstance().resolveDataType(typeCode)); + } else if (ToolConstants.ELEMENT.equals(typeCode)) { + element.setDataType(ToolConstants.ELEMENT + CommonUtil.toCamelCase(elementName)); } else { element.setDataType(typeCode); } diff --git a/native/fhir-to-bal-lib/src/main/java/org/wso2/healthcare/fhir/ballerina/packagegen/tool/modelgen/ResourceContextGenerator.java b/native/fhir-to-bal-lib/src/main/java/org/wso2/healthcare/fhir/ballerina/packagegen/tool/modelgen/ResourceContextGenerator.java index 14ee927..04a0829 100644 --- a/native/fhir-to-bal-lib/src/main/java/org/wso2/healthcare/fhir/ballerina/packagegen/tool/modelgen/ResourceContextGenerator.java +++ b/native/fhir-to-bal-lib/src/main/java/org/wso2/healthcare/fhir/ballerina/packagegen/tool/modelgen/ResourceContextGenerator.java @@ -265,7 +265,11 @@ private Element populateElement(String rootName, String name, ElementDefinition. Element element = new Element(); element.setName(GeneratorUtils.getInstance().resolveSpecialCharacters(name)); element.setRootElementName(rootName); - element.setDataType(GeneratorUtils.getInstance().resolveDataType(toolConfig, type.getCode())); + if (ToolConstants.ELEMENT.equals(type.getCode())) { + element.setDataType(ToolConstants.ELEMENT + CommonUtil.toCamelCase(name)); + } else { + element.setDataType(GeneratorUtils.getInstance().resolveDataType(toolConfig, type.getCode())); + } //Adding profiles of the resource element type List profiles = type.getProfile(); if (!profiles.isEmpty()) { diff --git a/native/fhir-to-bal-lib/src/main/resources/templates/package.vm b/native/fhir-to-bal-lib/src/main/resources/templates/package.vm index b69cf00..6c4b753 100644 --- a/native/fhir-to-bal-lib/src/main/resources/templates/package.vm +++ b/native/fhir-to-bal-lib/src/main/resources/templates/package.vm @@ -1,4 +1,6 @@ #set( $H = '#' ) +Ballerina package containing FHIR resource data models +compliant with $igUrl implementation guide. #if(!$isBasePackage) $H FHIR R4 ${igName} package diff --git a/native/health-cli/src/main/java/io/ballerina/health/cmd/fhir/FhirSubCmd.java b/native/health-cli/src/main/java/io/ballerina/health/cmd/fhir/FhirSubCmd.java index 83a4bc6..ff820c0 100644 --- a/native/health-cli/src/main/java/io/ballerina/health/cmd/fhir/FhirSubCmd.java +++ b/native/health-cli/src/main/java/io/ballerina/health/cmd/fhir/FhirSubCmd.java @@ -155,6 +155,13 @@ public void execute() { printStream.println("Try bal health --help for more information."); HealthCmdUtils.exitError(exitWhenFinish); } + if (dependentPackage != null && !dependentPackage.isEmpty()) { + if (!dependentPackage.matches("^[^/]+/[^/]+$")) { + printStream.println("Format of the dependent package is incorrect."); + printStream.println("Try bal health --help for more information."); + HealthCmdUtils.exitError(exitWhenFinish); + } + } if (this.engageSubCommand(argList)) { if (CMD_MODE_TEMPLATE.equals(mode)) { printStream.println("Ballerina FHIR API templates generation completed successfully. Generated templates can be found at " + targetOutputPath); diff --git a/native/health-cli/src/main/resources/ballerina-health.help b/native/health-cli/src/main/resources/ballerina-health.help index 17e8aac..128f940 100644 --- a/native/health-cli/src/main/resources/ballerina-health.help +++ b/native/health-cli/src/main/resources/ballerina-health.help @@ -21,7 +21,7 @@ DESCRIPTION Implementation Guides can be found in http://fhir.org/guides/registry/) The ballerina-health tool is compatible with Ballerina - version 2201.7.0 (Swan Lake Update 7) onwards. + version 2201.8.1 (Swan Lake Update 8) onwards. OPTIONS -v, --version @@ -37,18 +37,25 @@ COMMANDS OPTIONS -m, --mode Mode can be 'package' or 'template'. If the mode is set to 'package', - a Ballerina package will be generated including - all the records and types. - If the mode is set to ‘template’, tool will generate Ballerina templates - for each FHIR resource definition available in - the specified path. This is a MANDATORY input for fhir command. + a Ballerina package will be generated including all the records + and types. If the mode is set to ‘template’, tool will generate + Ballerina templates for each FHIR resource definition available + in the specified path. This is a MANDATORY input for fhir command. + --package-name + Only applicable in ‘package’ mode. Name of the Ballerina package + to be generated. This is a MANDATORY input in ‘package’ mode. + Refer https://ballerina.io/learn/package-references/#the-name-field + --dependent-package + Only applicable in ‘template’ mode. Fully qualified name of the + published Ballerina package containing IG resources [eg: /]. + This option can be used to generate templates specifically for the + resources in the given IG. The package name part of this value + will be added as a prefix to the template name. + This is a MANDATORY input in ‘template’ mode. -o, --output Location of the generated Ballerina artifacts. If this path is not specified, the output will be written to the same directory from which the command is run. - --package-name - Only applicable in ‘package’ mode. Name of the Ballerina package to be generated. - Refer https://ballerina.io/learn/package-references/#the-name-field --org-name Organization name of the Ballerina package/template to be generated. Refer https://ballerina.io/learn/package-references/#the-org-field @@ -56,20 +63,14 @@ COMMANDS Version of the Ballerina package/template to be generated. Refer https://semver.org/ --included-profile - Only applicable in ‘template’ mode. If only a specific profile/s needs to be generated as - templates, specify the profile URL as the value of this parameter. - This argument can be used more than once. + Only applicable in ‘template’ mode. If only a specific profile/s + needs to be generated as templates, specify the profile URL + as the value of this parameter. This argument can be used more than once. --excluded-profile - Only applicable in ‘template’ mode. If only a specific profile/s needs to be skipped when - generating templates, specify the profile URL - as the value of this parameter. - This argument can be used more than once. - --dependent-package - Only applicable in ‘template’ mode. Fully qualified name of the Ballerina package containing IG - resources [eg: /]. This option can be used to generate templates - specifically for the resources in the given IG. - The package name part of this value will be added - as a prefix to the template name. + Only applicable in ‘template’ mode. If only a specific profile/s + needs to be skipped when generating templates, specify the + profile URL as the value of this parameter. This argument + can be used more than once. EXAMPLES Generate a Ballerina package for the FHIR artifacts of USCore @@ -85,6 +86,7 @@ COMMANDS Generate Ballerina templates for all the FHIR resource profiles of USCore implementation guide. - $ bal health fhir -m template --dependent-package ballerinax/health.fhir.r4.uscore501 \ + $ bal health fhir -m template \ + --dependent-package ballerinax/health.fhir.r4.uscore501 \ ./path_to_uscore_definitions diff --git a/native/health-cli/src/main/resources/tool-config.json b/native/health-cli/src/main/resources/tool-config.json index 20e3e15..47eba8b 100644 --- a/native/health-cli/src/main/resources/tool-config.json +++ b/native/health-cli/src/main/resources/tool-config.json @@ -9,7 +9,7 @@ "org": "healthcare", "name": "healthcare.fhir", "version": "1.0.0", - "ballerinaDistribution": "2201.7.0", + "ballerinaDistribution": "2201.8.1", "authors": [ "Ballerina" ], @@ -29,7 +29,7 @@ "org": "healthcare", "namePrefix": "health.fhir.r4.international401", "version": "1.0.0", - "distribution": "2201.7.0", + "distribution": "2201.8.1", "authors": [ "Ballerina" ], diff --git a/pom.xml b/pom.xml index 3ddc40a..f20b810 100644 --- a/pom.xml +++ b/pom.xml @@ -42,7 +42,7 @@ 11 UTF-8 1.0.0 - 2201.6.0 + 2201.8.1 1.8 3.8.1 3.1.1