diff --git a/marketplace-service/src/main/java/com/axonivy/market/assembler/ProductDetailModelAssembler.java b/marketplace-service/src/main/java/com/axonivy/market/assembler/ProductDetailModelAssembler.java index 18a73cf4..1c1ca581 100644 --- a/marketplace-service/src/main/java/com/axonivy/market/assembler/ProductDetailModelAssembler.java +++ b/marketplace-service/src/main/java/com/axonivy/market/assembler/ProductDetailModelAssembler.java @@ -6,14 +6,12 @@ import com.axonivy.market.entity.Product; import com.axonivy.market.model.ProductDetailModel; import com.axonivy.market.util.ImageUtils; -import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.hateoas.Link; import org.springframework.hateoas.server.mvc.RepresentationModelAssemblerSupport; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Component; -import java.util.List; import java.util.Optional; import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo; diff --git a/marketplace-service/src/main/java/com/axonivy/market/constants/CommonConstants.java b/marketplace-service/src/main/java/com/axonivy/market/constants/CommonConstants.java index e80c2b57..a56b5b88 100644 --- a/marketplace-service/src/main/java/com/axonivy/market/constants/CommonConstants.java +++ b/marketplace-service/src/main/java/com/axonivy/market/constants/CommonConstants.java @@ -19,4 +19,5 @@ public class CommonConstants { public static final String ID_WITH_NUMBER_PATTERN = "%s-%s"; public static final String ERROR = "error"; public static final String MESSAGE = "message"; + public static final String COMPATIBILITY_RANGE_FORMAT = "%s - %s"; } 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 7861e480..7ad5535d 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 @@ -1,7 +1,6 @@ package com.axonivy.market.service.impl; import com.axonivy.market.bo.Artifact; -import com.axonivy.market.constants.CommonConstants; import com.axonivy.market.constants.GitHubConstants; import com.axonivy.market.constants.MavenConstants; import com.axonivy.market.constants.MetaConstants; @@ -70,6 +69,7 @@ import static com.axonivy.market.enums.DocumentField.SHORT_DESCRIPTIONS; import static com.axonivy.market.enums.FileStatus.ADDED; import static com.axonivy.market.enums.FileStatus.MODIFIED; +import static com.axonivy.market.util.VersionUtils.getPrefixOfVersion; import static java.util.Optional.ofNullable; import static org.apache.commons.lang3.StringUtils.EMPTY; @@ -96,7 +96,7 @@ public class ProductServiceImpl implements ProductService { private final ProductMarketplaceDataService productMarketplaceDataService; private final ProductMarketplaceDataRepository productMarketplaceDataRepo; private GHCommit lastGHCommit; - private VersionService versionService; + private final VersionService versionService; private GitHubRepoMeta marketRepoMeta; @Value("${market.github.market.branch}") private String marketRepoBranch; @@ -195,7 +195,7 @@ private List updateLatestChangeToProductsFromGithubRepo() { Map> groupGitHubFiles = new HashMap<>(); for (var file : gitHubFileChanges) { String filePath = file.getFileName(); - var parentPath = filePath.substring(0, filePath.lastIndexOf(CommonConstants.SLASH) + 1); + var parentPath = filePath.substring(0, filePath.lastIndexOf(SLASH) + 1); var files = groupGitHubFiles.getOrDefault(parentPath, new ArrayList<>()); files.add(file); files.sort((file1, file2) -> GitHubUtils.sortMetaJsonFirst(file1.getFileName(), file2.getFileName())); @@ -762,6 +762,11 @@ public boolean syncFirstPublishedDateOfAllProducts() { } } + /** + * MARP-975: Retrieve the list containing all versions for the designer and + * split the versions to obtain the first prefix,then format them for compatibility range. + * ex: 11.0+ , 10.0 - 12.0+ , ... + */ private String getCompatibilityRange(String productId) { return Optional.of(versionService.getVersionsForDesigner(productId)) .filter(ObjectUtils::isNotEmpty) @@ -770,11 +775,10 @@ private String getCompatibilityRange(String productId) { 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); + String maxVersion = splitVersion(versions.get(0)).concat(PLUS); + String minVersion = splitVersion(versions.get(versions.size() - 1)); + return getPrefixOfVersion(minVersion).equals(getPrefixOfVersion(maxVersion)) ? + minVersion.concat(PLUS) : String.format(COMPATIBILITY_RANGE_FORMAT, minVersion, maxVersion); }).orElse(null); } @@ -784,7 +788,4 @@ private String splitVersion(String version) { return version.substring(0, secondDot); } - private String getPrefixOfVersion(String version) { - return version.substring(0, version.indexOf(DOT_SEPARATOR)); - } } \ No newline at end of file diff --git a/marketplace-service/src/main/java/com/axonivy/market/util/VersionUtils.java b/marketplace-service/src/main/java/com/axonivy/market/util/VersionUtils.java index ced7b904..237aba1a 100644 --- a/marketplace-service/src/main/java/com/axonivy/market/util/VersionUtils.java +++ b/marketplace-service/src/main/java/com/axonivy/market/util/VersionUtils.java @@ -20,6 +20,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import static com.axonivy.market.constants.CommonConstants.DOT_SEPARATOR; import static com.axonivy.market.constants.MavenConstants.*; @Log4j2 @NoArgsConstructor(access = AccessLevel.PRIVATE) @@ -145,4 +146,8 @@ public static List getInstallableVersionsFromMetadataList(List metadata -> metadata.getVersions().stream().sorted(new LatestVersionComparator()).collect( Collectors.toList())).orElse(new ArrayList<>()); } + + public static String getPrefixOfVersion(String version) { + return version.substring(0, version.indexOf(DOT_SEPARATOR)); + } } diff --git a/marketplace-service/src/test/java/com/axonivy/market/BaseSetup.java b/marketplace-service/src/test/java/com/axonivy/market/BaseSetup.java index 27913863..87d41f0e 100644 --- a/marketplace-service/src/test/java/com/axonivy/market/BaseSetup.java +++ b/marketplace-service/src/test/java/com/axonivy/market/BaseSetup.java @@ -270,12 +270,12 @@ protected ProductMarketplaceData getMockProductMarketplaceData() { protected List mockVersionAndUrlModels() { VersionAndUrlModel versionAndUrlModel = VersionAndUrlModel.builder() .version("10.0.21") - .url("/api/product-details/productjsoncontent/portal/10.0.21") + .url("/api/product-details/portal/10.0.21/json") .build(); VersionAndUrlModel versionAndUrlModel2 = VersionAndUrlModel.builder() .version("10.0.22") - .url("/api/product-details/productjsoncontent/portal/10.0.22") + .url("/api/product-details/portal/10.0.22/json") .build(); return List.of(versionAndUrlModel, versionAndUrlModel2); diff --git a/marketplace-service/src/test/java/com/axonivy/market/controller/ProductDetailsControllerTest.java b/marketplace-service/src/test/java/com/axonivy/market/controller/ProductDetailsControllerTest.java index 8c1e8602..812f4fc4 100644 --- a/marketplace-service/src/test/java/com/axonivy/market/controller/ProductDetailsControllerTest.java +++ b/marketplace-service/src/test/java/com/axonivy/market/controller/ProductDetailsControllerTest.java @@ -169,10 +169,10 @@ void findProductVersionsById() { assertEquals(2, Objects.requireNonNull(result.getBody()).size()); assertEquals("10.0.21", Objects.requireNonNull(result.getBody()).get(0).getVersion()); - assertEquals("/api/product-details/productjsoncontent/portal/10.0.21", + assertEquals("/api/product-details/portal/10.0.21/json", Objects.requireNonNull(result.getBody()).get(0).getUrl()); assertEquals("10.0.22", Objects.requireNonNull(result.getBody()).get(1).getVersion()); - assertEquals("/api/product-details/productjsoncontent/portal/10.0.22", + assertEquals("/api/product-details/portal/10.0.22/json", Objects.requireNonNull(result.getBody()).get(1).getUrl()); } 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 8830e093..1138fa27 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("10.0+", result.getCompatibilityRange()); result = productService.fetchProductDetail(MOCK_PRODUCT_ID, true); - assertEquals("10.0-11.3+", result.getCompatibilityRange()); + assertEquals("10.0 - 11.3+", result.getCompatibilityRange()); result = productService.fetchProductDetail(MOCK_PRODUCT_ID, true); - assertEquals("10.0-11.3+", result.getCompatibilityRange()); + assertEquals("10.0 - 11.3+", result.getCompatibilityRange()); result = productService.fetchProductDetail(MOCK_PRODUCT_ID, true); - assertEquals("10.0-12.0+", result.getCompatibilityRange()); + assertEquals("10.0 - 12.0+", result.getCompatibilityRange()); } @Test