From 8ab4b1fbfecb092df5c0ced768f56e33a994ea92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=E1=BA=A7n=20V=C4=A9nh=20Thi=E1=BB=87n=20Ph=C3=BAc?= Date: Mon, 23 Dec 2024 11:03:27 +0700 Subject: [PATCH] MARP-975 Handle Feedback --- .../service/impl/ProductServiceImpl.java | 35 +++++++------------ .../service/impl/ProductServiceImplTest.java | 4 +-- 2 files changed, 15 insertions(+), 24 deletions(-) diff --git a/marketplace-service/src/main/java/com/axonivy/market/service/impl/ProductServiceImpl.java b/marketplace-service/src/main/java/com/axonivy/market/service/impl/ProductServiceImpl.java index d7040b2c..7861e480 100644 --- a/marketplace-service/src/main/java/com/axonivy/market/service/impl/ProductServiceImpl.java +++ b/marketplace-service/src/main/java/com/axonivy/market/service/impl/ProductServiceImpl.java @@ -763,28 +763,19 @@ public boolean syncFirstPublishedDateOfAllProducts() { } private String getCompatibilityRange(String productId) { - List versions = - versionService.getVersionsForDesigner(productId).stream().map(VersionAndUrlModel::getVersion).toList(); - if (ObjectUtils.isEmpty(versions)) { - return null; - } - - if (versions.size() == 1) { - return splitVersion(versions.get(0)); - } - - String currentMaxVersion = versions.get(0); - boolean isMoreThan1InMaxVersion = versions.stream() - .filter(version -> version.startsWith( - currentMaxVersion.substring(0, currentMaxVersion.indexOf(DOT_SEPARATOR)))).toList().size() > 1; - - String maxValue = isMoreThan1InMaxVersion ? splitVersion(currentMaxVersion).concat(PLUS) : splitVersion( - currentMaxVersion); - String minValue = splitVersion(versions.get(versions.size() - 1)); - - return getPrefixOfVersion(minValue).equals(getPrefixOfVersion(maxValue)) ? - minValue.concat(PLUS) : - minValue.concat(DASH_SEPARATOR).concat(maxValue); + return Optional.of(versionService.getVersionsForDesigner(productId)) + .filter(ObjectUtils::isNotEmpty) + .map(versions -> versions.stream().map(VersionAndUrlModel::getVersion).toList()) + .map(versions -> { + if (versions.size() == 1) { + return splitVersion(versions.get(0)).concat(PLUS); + } + String maxValue = splitVersion(versions.get(0)).concat(PLUS); + String minValue = splitVersion(versions.get(versions.size() - 1)); + return getPrefixOfVersion(minValue).equals(getPrefixOfVersion(maxValue)) ? + minValue.concat(PLUS) : + minValue.concat(DASH_SEPARATOR).concat(maxValue); + }).orElse(null); } private String splitVersion(String version) { diff --git a/marketplace-service/src/test/java/com/axonivy/market/service/impl/ProductServiceImplTest.java b/marketplace-service/src/test/java/com/axonivy/market/service/impl/ProductServiceImplTest.java index b8849798..3862a2ef 100644 --- a/marketplace-service/src/test/java/com/axonivy/market/service/impl/ProductServiceImplTest.java +++ b/marketplace-service/src/test/java/com/axonivy/market/service/impl/ProductServiceImplTest.java @@ -421,13 +421,13 @@ void testGetCompatibilityRangeAfterFetchProductDetail() { assertEquals(result.getCompatibilityRange(),"10.0+"); result = productService.fetchProductDetail(MOCK_PRODUCT_ID, true); - assertEquals(result.getCompatibilityRange(),"10.0-11.3"); + assertEquals(result.getCompatibilityRange(),"10.0-11.3+"); result = productService.fetchProductDetail(MOCK_PRODUCT_ID, true); assertEquals(result.getCompatibilityRange(),"10.0-11.3+"); result = productService.fetchProductDetail(MOCK_PRODUCT_ID, true); - assertEquals(result.getCompatibilityRange(),"10.0-12.0"); + assertEquals(result.getCompatibilityRange(),"10.0-12.0+"); } @Test