Skip to content

Commit

Permalink
MARP-975 Handle Feedbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
tvtphuc-axonivy committed Dec 23, 2024
1 parent 12220ae commit a5965e7
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -195,7 +195,7 @@ private List<String> updateLatestChangeToProductsFromGithubRepo() {
Map<String, List<GitHubFile>> 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()));
Expand Down Expand Up @@ -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)
Expand All @@ -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);
}

Expand All @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -145,4 +146,8 @@ public static List<String> getInstallableVersionsFromMetadataList(List<Metadata>
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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,12 @@ protected ProductMarketplaceData getMockProductMarketplaceData() {
protected List<VersionAndUrlModel> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a5965e7

Please sign in to comment.