diff --git a/efsity/build.gradle.kts b/efsity/build.gradle.kts index cc80e204..bb776e83 100644 --- a/efsity/build.gradle.kts +++ b/efsity/build.gradle.kts @@ -18,7 +18,7 @@ repositories { group = "org.smartregister" -version = "2.3.6-SNAPSHOT" +version = "2.3.7-SNAPSHOT" description = "fhircore-tooling (efsity)" diff --git a/efsity/src/main/java/org/smartregister/command/PublishFhirResourcesCommand.java b/efsity/src/main/java/org/smartregister/command/PublishFhirResourcesCommand.java index 71e71e7a..8d5f4bba 100644 --- a/efsity/src/main/java/org/smartregister/command/PublishFhirResourcesCommand.java +++ b/efsity/src/main/java/org/smartregister/command/PublishFhirResourcesCommand.java @@ -7,11 +7,9 @@ import com.google.gson.JsonParser; import java.io.BufferedReader; import java.io.File; -import java.io.FileInputStream; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; -import java.io.InputStream; import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; import java.nio.file.Files; @@ -105,13 +103,9 @@ public class PublishFhirResourcesCommand implements Runnable { public void run() { long start = System.currentTimeMillis(); if (propertiesFile != null && !propertiesFile.isBlank()) { - try (InputStream inputProperties = new FileInputStream(propertiesFile)) { - Properties properties = new Properties(); - properties.load(inputProperties); - setProperties(properties); - } catch (IOException e) { - throw new RuntimeException(e); - } + + Properties properties = FctUtils.readPropertiesFile(propertiesFile); + setProperties(properties); } try { if (compositionFilePath != null) { diff --git a/efsity/src/main/java/org/smartregister/command/TranslateCommand.java b/efsity/src/main/java/org/smartregister/command/TranslateCommand.java index 678c5ff6..7f693fac 100644 --- a/efsity/src/main/java/org/smartregister/command/TranslateCommand.java +++ b/efsity/src/main/java/org/smartregister/command/TranslateCommand.java @@ -223,7 +223,7 @@ private static void mergeContent( objectMapper.readTree(Files.newBufferedReader(inputFilePath, StandardCharsets.UTF_8)); // Load the translation properties - Properties translationProperties = getPropertiesFile(translationFile); + Properties translationProperties = FctUtils.readPropertiesFile(translationFile); // Traverse and update the JSON structure JsonNode updatedJson = updateJson(rootNode, translationProperties, locale, targetFields); @@ -235,20 +235,6 @@ private static void mergeContent( String.format("Merged JSON saved to \u001b[36m%s\u001b[0m", inputFilePath.toString())); } - public static Properties getPropertiesFile(String propertiesFilePath) throws IOException { - Properties properties = new Properties(); - // Read existing properties file, if it exists - if (Files.exists(Paths.get(propertiesFilePath))) { - try (FileInputStream fileInputStream = new FileInputStream(propertiesFilePath); - InputStreamReader reader = - new InputStreamReader(fileInputStream, StandardCharsets.UTF_8)) { - - properties.load(reader); - } - } - return properties; - } - private static JsonNode updateJson( JsonNode node, Properties translationProperties, String locale, Set targetFields) throws NoSuchAlgorithmException { @@ -416,7 +402,7 @@ private static void extractContent( throw new RuntimeException("Provide a valid `resourceFile` directory or file."); } - Properties existingProperties = getPropertiesFile(propertiesFilePath.toString()); + Properties existingProperties = FctUtils.readPropertiesFile(propertiesFilePath.toString()); // Merge existing properties with new properties existingProperties.putAll(textToHash); diff --git a/efsity/src/test/java/org/smartregister/command/TranslateCommandTest.java b/efsity/src/test/java/org/smartregister/command/TranslateCommandTest.java index 5a5d2d68..4b1d290a 100644 --- a/efsity/src/test/java/org/smartregister/command/TranslateCommandTest.java +++ b/efsity/src/test/java/org/smartregister/command/TranslateCommandTest.java @@ -4,9 +4,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import java.io.FileInputStream; import java.io.IOException; -import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; @@ -15,6 +13,7 @@ import java.util.Properties; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.smartregister.util.FctUtils; public class TranslateCommandTest { @@ -55,14 +54,11 @@ public void testRunExtract() throws IOException { assertDoesNotThrow(() -> translateCommand.run()); - Properties existingProperties = new Properties(); - InputStream defaultPropertiesInput = new FileInputStream(defaultPropertiesPath.toFile()); - existingProperties.load(defaultPropertiesInput); + Properties existingProperties = + FctUtils.readPropertiesFile(defaultPropertiesPath.toFile().getAbsolutePath()); - Properties newProperties = new Properties(); - InputStream tempDefaultPropertiesInput = - new FileInputStream(tempDefaultPropertiesPath.toFile()); - newProperties.load(tempDefaultPropertiesInput); + Properties newProperties = + FctUtils.readPropertiesFile(tempDefaultPropertiesPath.toFile().getAbsolutePath()); // Compare the contents of the two files assertEquals(existingProperties, newProperties, "File contents are similar."); diff --git a/efsity/src/test/resources/strings_fr.properties b/efsity/src/test/resources/strings_fr.properties index 9a59bf0d..44a1b58d 100644 --- a/efsity/src/test/resources/strings_fr.properties +++ b/efsity/src/test/resources/strings_fr.properties @@ -1,5 +1,5 @@ #Thu Nov 02 09:51:17 EAT 2023 b989b9027fad22ec89690367614e2da6=Raison de l?examen abdominal -f89de0a4cd9317a2987dfc2546e2da5e=Examen abdominal effectué +f89de0a4cd9317a2987dfc2546e2da5e=Examen abdominal effectué bafd7322c6e97d25b6299b5d6fe8920b=Non 93cba07454f06a4a960172bbd6e2a435=Oui