diff --git a/pom.xml b/pom.xml index 645e7e2dd..962595fa9 100755 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ opensrp-server-core jar - 2.14.10-SNAPSHOT + 2.14.11-ALPHA2-SNAPSHOT opensrp-server-core OpenSRP Server Core module https://github.com/OpenSRP/opensrp-server-core diff --git a/src/main/java/org/opensrp/repository/postgres/StocksRepositoryImpl.java b/src/main/java/org/opensrp/repository/postgres/StocksRepositoryImpl.java index c744ddcb1..2882a00f4 100755 --- a/src/main/java/org/opensrp/repository/postgres/StocksRepositoryImpl.java +++ b/src/main/java/org/opensrp/repository/postgres/StocksRepositoryImpl.java @@ -20,6 +20,7 @@ import org.opensrp.repository.postgres.mapper.custom.CustomStockMetadataMapper; import org.opensrp.search.StockSearchBean; import org.opensrp.util.RepositoryUtil; +import org.opensrp.util.Utils; import org.smartregister.converters.StockConverter; import org.smartregister.domain.PhysicalLocation; import org.smartregister.domain.ProductCatalogue; @@ -453,8 +454,12 @@ public List getInventoryWithProductDetailsByStockId(Stri } private List convertToFHIR(List stockAndProductDetails) { - return stockAndProductDetails.stream().map(stockAndProductDetail -> StockConverter.convertStockToBundleResource(stockAndProductDetail)) - .collect(Collectors.toList()); + return stockAndProductDetails.stream().map(stockAndProductDetail -> { + String productNameWithProperWhiteSpacing = Utils.replaceConsecutiveSpaces(stockAndProductDetail.getProductCatalogue().getProductName()); + stockAndProductDetail.getProductCatalogue().setProductName(productNameWithProperWhiteSpacing); + return StockConverter.convertStockToBundleResource(stockAndProductDetail); + }) + .collect(Collectors.toList()); } } diff --git a/src/main/java/org/opensrp/service/ProductCatalogueService.java b/src/main/java/org/opensrp/service/ProductCatalogueService.java index ea1aff509..1dcc906d2 100644 --- a/src/main/java/org/opensrp/service/ProductCatalogueService.java +++ b/src/main/java/org/opensrp/service/ProductCatalogueService.java @@ -3,6 +3,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.opensrp.util.Utils; import org.smartregister.domain.ProductCatalogue; import org.opensrp.repository.ProductCatalogueRepository; import org.opensrp.search.ProductCatalogueSearchBean; @@ -90,6 +91,7 @@ private void validateFields(ProductCatalogue productCatalogue) { } else if (productCatalogue.getAccountabilityPeriod() == null) { throw new IllegalArgumentException("Accountability period was not specified"); } else { + productCatalogue.setProductName(Utils.replaceConsecutiveSpaces(productCatalogue.getProductName())); logger.info("All validations on fields passed"); } } diff --git a/src/main/java/org/opensrp/service/StockService.java b/src/main/java/org/opensrp/service/StockService.java index af72005e7..7401a7e0f 100755 --- a/src/main/java/org/opensrp/service/StockService.java +++ b/src/main/java/org/opensrp/service/StockService.java @@ -9,6 +9,7 @@ import org.opensrp.domain.postgres.Structure; import org.opensrp.domain.postgres.StructureMetadataExample; import org.opensrp.repository.postgres.mapper.custom.CustomStructureMetadataMapper; +import org.opensrp.util.Utils; import org.smartregister.domain.Inventory; import org.smartregister.domain.ProductCatalogue; import org.smartregister.domain.PhysicalLocation; diff --git a/src/main/java/org/opensrp/util/Utils.java b/src/main/java/org/opensrp/util/Utils.java index 55c22225b..45b1b33d6 100644 --- a/src/main/java/org/opensrp/util/Utils.java +++ b/src/main/java/org/opensrp/util/Utils.java @@ -157,6 +157,11 @@ public static void closeCloseable(Closeable closeable) { logger.error(e.getMessage(), e); } } + + public static String replaceConsecutiveSpaces(String input) { + // Use regular expression to replace consecutive spaces with a single space + return input.trim().replaceAll("\\s+", " "); + } public static class DatabaseConnectionParams { diff --git a/src/test/java/org/opensrp/util/UtilTest.java b/src/test/java/org/opensrp/util/UtilTest.java index e77dee530..b018871f8 100644 --- a/src/test/java/org/opensrp/util/UtilTest.java +++ b/src/test/java/org/opensrp/util/UtilTest.java @@ -70,4 +70,19 @@ public void testGetXlsToJsonForInvalidXls() throws IOException, JSONException { Utils.getXlsToJson(path); } + @Test + public void testReplaceConsecutiveSpaces(){ + // Test string with spaces in between words + String inputString = "Medicines (PPOS)"; + String modifiedString = Utils.replaceConsecutiveSpaces(inputString); + assertEquals("Medicines (PPOS)", modifiedString); + // Test string with space after words + inputString = "Medicines (PPOS) "; + modifiedString = Utils.replaceConsecutiveSpaces(inputString); + assertEquals("Medicines (PPOS)", modifiedString); + // Test string with space before words + inputString = "Medicines (PPOS)"; + modifiedString = Utils.replaceConsecutiveSpaces(inputString); + assertEquals("Medicines (PPOS)", modifiedString); + } }