From a114d751db50341c5511580ab429367831ee2507 Mon Sep 17 00:00:00 2001 From: dotasek Date: Tue, 27 Jun 2023 11:29:24 -0400 Subject: [PATCH] Refactor version utility code --- .../hl7/fhir/utilities/VersionUtilities.java | 24 ++++++++++++++----- .../validation/cli/tasks/ValidateTask.java | 4 ++-- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/VersionUtilities.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/VersionUtilities.java index 4a967c6bc..6dd7e178b 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/VersionUtilities.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/VersionUtilities.java @@ -1,9 +1,6 @@ package org.hl7.fhir.utilities; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; -import java.util.HashSet; +import java.util.*; import org.apache.commons.lang3.StringUtils; import org.hl7.fhir.exceptions.FHIRException; @@ -41,6 +38,9 @@ import org.hl7.fhir.exceptions.FHIRException; public class VersionUtilities { + public static final String[] SUPPORTED_MAJOR_VERSIONS = {"1.0", "1.4", "3.0", "4.0", "5.0", "6.0"}; + public static final String[] SUPPORTED_VERSIONS = {"1.0.2", "1.4.0", "3.0.2", "4.0.1", "4.1.0", "4.3.0", "5.0.0", "6.0.0"}; + public static class VersionURLInfo { private String version; private String url; @@ -138,11 +138,23 @@ public class VersionUtilities { if (version.contains("-")) { version = version.substring(0, version.indexOf("-")); } - return Utilities.existsInList(version, "1.0.2", "1.4.0", "3.0.2", "4.0.1", "4.1.0", "4.3.0", "5.0.0", "6.0.0"); + return Utilities.existsInList(version, SUPPORTED_VERSIONS); } public static String listSupportedVersions() { - return "1.0.2, 1.4.0, 3.0.2, 4.0.1, 4.1.0, 4.3.0, 5.0, 6.0"; + return listVersions(SUPPORTED_VERSIONS); + } + + public static String listSupportedMajorVersions() { + return listVersions(SUPPORTED_MAJOR_VERSIONS); + } + + private static String listVersions(String[] versions) { + StringJoiner stringJoiner = new StringJoiner(", "); + for (String supportedVersion : versions) { + stringJoiner.add(supportedVersion); + } + return stringJoiner.toString(); } public static boolean isR6Ver(String ver) { diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/tasks/ValidateTask.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/tasks/ValidateTask.java index 68b49cbcc..5ee5547c5 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/tasks/ValidateTask.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/tasks/ValidateTask.java @@ -19,8 +19,8 @@ public class ValidateTask extends ValidationEngineTask { final static String[][] PLACEHOLDERS = { { "XML_AND_JSON_FHIR_VERSIONS", "1.0, 1.4, 3.0, 4.0, " + Constants.VERSION_MM + ", 6.0" }, { "TURTLE_FHIR_VERSIONS", "3.0, 4.0, " + Constants.VERSION_MM }, - { "FHIR_MAJOR_VERSIONS", "1.0, 1.4, 3.0, 4.0, " + Constants.VERSION_MM, "6.0"}, - { "FHIR_MINOR_VERSIONS", "1.0.2, 1.4.0, 3.0.2, 4.0.1, 4.1.0, 4.3.0, 5.0.0, 6.0.0" }, + { "FHIR_MAJOR_VERSIONS", VersionUtilities.listSupportedMajorVersions()}, + { "FHIR_MINOR_VERSIONS", VersionUtilities.listSupportedVersions() }, { "FHIR_CURRENT_VERSION", Constants.VERSION_MM} };