Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/axonivy-market/marketplace
Browse files Browse the repository at this point in the history
… into feature/MARP-223-Detail-pages-for-new-market-Main-content

# Conflicts:
#	marketplace-service/src/main/java/com/axonivy/market/assembler/ProductModelAssembler.java
#	marketplace-service/src/main/java/com/axonivy/market/constants/CommonConstants.java
#	marketplace-service/src/main/java/com/axonivy/market/constants/GitHubConstants.java
#	marketplace-service/src/main/java/com/axonivy/market/entity/Product.java
#	marketplace-service/src/main/java/com/axonivy/market/factory/ProductFactory.java
#	marketplace-service/src/main/java/com/axonivy/market/github/model/Meta.java
#	marketplace-service/src/main/java/com/axonivy/market/github/service/GHAxonIvyProductRepoService.java
#	marketplace-service/src/main/java/com/axonivy/market/github/service/impl/GHAxonIvyMarketRepoServiceImpl.java
#	marketplace-service/src/main/java/com/axonivy/market/github/service/impl/GHAxonIvyProductRepoServiceImpl.java
#	marketplace-service/src/main/java/com/axonivy/market/repository/ProductRepository.java
#	marketplace-service/src/main/java/com/axonivy/market/service/ProductService.java
#	marketplace-service/src/main/java/com/axonivy/market/service/impl/ProductServiceImpl.java
#	marketplace-service/src/main/java/com/axonivy/market/util/XmlReaderUtils.java
#	marketplace-service/src/main/java/com/axonivy/market/utils/XmlReaderUtils.java
#	marketplace-service/src/test/java/com/axonivy/market/controller/ProductDetailsControllerTest.java
#	marketplace-service/src/test/java/com/axonivy/market/factory/ProductFactoryTest.java
#	marketplace-service/src/test/java/com/axonivy/market/github/service/GHAxonIvyProductRepoServiceImplTest.java
#	marketplace-service/src/test/java/com/axonivy/market/service/GHAxonIvyProductRepoServiceImplTest.java
#	marketplace-service/src/test/java/com/axonivy/market/service/ProductServiceImplTest.java
#	marketplace-service/src/test/java/com/axonivy/market/service/VersionServiceImplTest.java
#	marketplace-service/src/test/java/com/axonivy/market/util/XmlReaderUtilsTest.java
#	marketplace-service/src/test/java/com/axonivy/market/utils/XmlReaderUtilsTest.java
#	src/main/java/com/axonivy/market/utils/XmlReaderUtils.java
#	src/test/java/com/axonivy/market/github/service/GHAxonIvyProductRepoServiceImplTest.java
#	src/test/java/com/axonivy/market/utils/XmlReaderUtilsTest.java
  • Loading branch information
nqhoan-axonivy committed Jul 5, 2024
2 parents 37ca9a7 + 79ce2ac commit 5e1b12b
Show file tree
Hide file tree
Showing 15 changed files with 141 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ public ProductController(ProductService service, ProductModelAssembler assembler
@GetMapping()
public ResponseEntity<PagedModel<ProductModel>> findProducts(
@RequestParam(required = true, name = "type") String type,
@RequestParam(required = false, name = "keyword") String keyword, Pageable pageable) {
Page<Product> results = service.findProducts(type, keyword, pageable);
@RequestParam(required = false, name = "keyword") String keyword,
@RequestParam(required = true, name = "language") String language, Pageable pageable) {
Page<Product> results = service.findProducts(type, keyword, language, pageable);
if (results.isEmpty()) {
return generateEmptyPagedModel();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.axonivy.market.entity;

import com.axonivy.market.github.model.MavenArtifact;
import java.io.Serializable;
import java.util.Objects;

import org.springframework.data.annotation.Transient;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.data.annotation.Transient;

import java.io.Serializable;
import java.util.Objects;

@AllArgsConstructor
@NoArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
@NoArgsConstructor
@Document(MAVEN_ARTIFACT_VERSION)
public class MavenArtifactVersion implements Serializable {
@Id
private static final long serialVersionUID = -6492612804634492078L;

@Id
private String productId;
private List<String> versions = new ArrayList<>();
private Map<String, List<MavenArtifactModel>> productArtifactWithVersionReleased = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.axonivy.market.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum Language {
EN("en"), DE("de");

private String value;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@Getter
@AllArgsConstructor
public enum SortOption {
POPULARITY("popularity", "installationCount"), ALPHABETICALLY("alphabetically", "name"),
POPULARITY("popularity", "installationCount"), ALPHABETICALLY("alphabetically", "names"),
RECENT("recent", "newestPublishedDate");

private String option;
Expand All @@ -25,4 +25,10 @@ public static SortOption of(String option) {
}
throw new InvalidParamException(ErrorCode.PRODUCT_SORT_INVALID, "SortOption: " + option);
}

public String getCode(String language) {
return StringUtils.isNotBlank(language) && ALPHABETICALLY.option.equalsIgnoreCase(option)
? String.format("%s.%s", ALPHABETICALLY.code, language)
: code;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public interface GitHubService {

public GHRepository getRepository(String repositoryPath) throws IOException;

public List<GHContent> getDirectoryContent(GHRepository ghRepository, String path) throws IOException;
public List<GHContent> getDirectoryContent(GHRepository ghRepository, String path, String ref) throws IOException;

public GHContent getGHContent(GHRepository ghRepository, String path) throws IOException;
public GHContent getGHContent(GHRepository ghRepository, String path, String ref) throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public GHOrganization getOrganization(String orgName) throws IOException {
}

@Override
public List<GHContent> getDirectoryContent(GHRepository ghRepository, String path) throws IOException {
public List<GHContent> getDirectoryContent(GHRepository ghRepository, String path, String ref) throws IOException {
Assert.notNull(ghRepository, "Repository must not be null");
return ghRepository.getDirectoryContent(path);
return ghRepository.getDirectoryContent(path, ref);
}

@Override
Expand All @@ -45,8 +45,8 @@ public GHRepository getRepository(String repositoryPath) throws IOException {
}

@Override
public GHContent getGHContent(GHRepository ghRepository, String path) throws IOException {
public GHContent getGHContent(GHRepository ghRepository, String path, String ref) throws IOException {
Assert.notNull(ghRepository, "Repository must not be null");
return ghRepository.getFileContent(path);
return ghRepository.getFileContent(path, ref);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.axonivy.market.model;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonIgnoreProperties(ignoreUnknown = true)
public class DisplayValue {

private String locale;
private String value;

@Override
public boolean equals(Object obj) {
if (!(obj instanceof DisplayValue)) {
return false;
}
DisplayValue other = (DisplayValue) obj;
EqualsBuilder builder = new EqualsBuilder();
builder.append(value, other.getValue());
builder.append(locale, other.locale);
return builder.isEquals();
}

@Override
public int hashCode() {
HashCodeBuilder builder = new HashCodeBuilder();
builder.append(getValue());
builder.append(getLocale());
return builder.hashCode();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.axonivy.market.model;

import java.io.Serializable;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@NoArgsConstructor
public class MultilingualismValue implements Serializable {
private static final long serialVersionUID = -4193508237020296419L;

private String en;
private String de;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
@JsonInclude(Include.NON_NULL)
public class ProductModel extends RepresentationModel<ProductModel> {
private String id;
private String name;
private String shortDescription;
private MultilingualismValue names;
private MultilingualismValue shortDescriptions;
private String logoUrl;
private String type;
private List<String> tags;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public boolean isOfficialVersionOrUnReleasedDevVersion(List<String> versions, St
} else {
bugfixVersion = getBugfixVersion(version.split(MavenConstants.SPRINT_RELEASE_POSTFIX)[0]);
}
return versions.stream().noneMatch(currentVersion -> !currentVersion.equals(version)
return versions.stream().noneMatch(currentVersion -> !currentVersion.equals(version) && isReleasedVersion(currentVersion)
&& getBugfixVersion(currentVersion).equals(bugfixVersion));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@
import com.axonivy.market.enums.ErrorCode;
import com.axonivy.market.enums.SortOption;
import com.axonivy.market.enums.TypeOption;
import com.axonivy.market.model.MultilingualismValue;
import com.axonivy.market.service.ProductService;

@ExtendWith(MockitoExtension.class)
class ProductControllerTest {
private static final String PRODUCT_NAME_SAMPLE = "Amazon Comprehend";
private static final String PRODUCT_NAME_DE_SAMPLE = "Amazon Comprehend DE";
private static final String PRODUCT_DESC_SAMPLE = "Amazon Comprehend is a AI service that uses machine learning to uncover information in unstructured data.";
private static final String PRODUCT_DESC_DE_SAMPLE = "Amazon Comprehend is a AI service that uses machine learning to uncover information in unstructured data. DE";

@Mock
private ProductService service;
Expand All @@ -59,9 +62,9 @@ void setup() {
void testFindProductsAsEmpty() {
PageRequest pageable = PageRequest.of(0, 20);
Page<Product> mockProducts = new PageImpl<Product>(List.of(), pageable, 0);
when(service.findProducts(any(), any(), any())).thenReturn(mockProducts);
when(service.findProducts(any(), any(), any(), any())).thenReturn(mockProducts);
when(pagedResourcesAssembler.toEmptyModel(any(), any())).thenReturn(PagedModel.empty());
var result = productController.findProducts(TypeOption.ALL.getOption(), null, pageable);
var result = productController.findProducts(TypeOption.ALL.getOption(), null, "en", pageable);
assertEquals(HttpStatus.OK, result.getStatusCode());
assertTrue(result.hasBody());
assertEquals(0, result.getBody().getContent().size());
Expand All @@ -73,16 +76,17 @@ void testFindProducts() {
Product mockProduct = createProductMock();

Page<Product> mockProducts = new PageImpl<Product>(List.of(mockProduct), pageable, 1);
when(service.findProducts(any(), any(), any())).thenReturn(mockProducts);
when(service.findProducts(any(), any(), any(), any())).thenReturn(mockProducts);
assembler = new ProductModelAssembler();
var mockProductModel = assembler.toModel(mockProduct);
var mockPagedModel = PagedModel.of(List.of(mockProductModel), new PageMetadata(1, 0, 1));
when(pagedResourcesAssembler.toModel(any(), any(ProductModelAssembler.class))).thenReturn(mockPagedModel);
var result = productController.findProducts(TypeOption.ALL.getOption(), null, pageable);
var result = productController.findProducts(TypeOption.ALL.getOption(), "", "en", pageable);
assertEquals(HttpStatus.OK, result.getStatusCode());
assertTrue(result.hasBody());
assertEquals(1, result.getBody().getContent().size());
assertEquals(PRODUCT_NAME_SAMPLE, result.getBody().getContent().iterator().next().getName());
assertEquals(PRODUCT_NAME_SAMPLE, result.getBody().getContent().iterator().next().getNames().getEn());
assertEquals(PRODUCT_NAME_DE_SAMPLE, result.getBody().getContent().iterator().next().getNames().getDe());
}

@Test
Expand All @@ -96,8 +100,14 @@ void testSyncProducts() {
private Product createProductMock() {
Product mockProduct = new Product();
mockProduct.setId("amazon-comprehend");
mockProduct.setName(PRODUCT_NAME_SAMPLE);
mockProduct.setShortDescription(PRODUCT_DESC_SAMPLE);
MultilingualismValue name = new MultilingualismValue();
name.setEn(PRODUCT_NAME_SAMPLE);
name.setDe(PRODUCT_NAME_DE_SAMPLE);
mockProduct.setNames(name);
MultilingualismValue shortDescription = new MultilingualismValue();
shortDescription.setEn(PRODUCT_DESC_SAMPLE);
shortDescription.setDe(PRODUCT_DESC_DE_SAMPLE);
mockProduct.setShortDescriptions(shortDescription);
mockProduct.setType("connector");
mockProduct.setTags(List.of("AI"));
return mockProduct;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void testFetchAllMarketItems() throws IOException {
mockGhContents.add(mockGHContent);
when(mockGHFileContent.isFile()).thenReturn(true);
when(pagedGHContent.toList()).thenReturn(List.of(mockGHFileContent));
when(gitHubService.getDirectoryContent(any(), any())).thenReturn(mockGhContents);
when(gitHubService.getDirectoryContent(any(), any(), any())).thenReturn(mockGhContents);

ghContentMap = axonIvyMarketRepoServiceImpl.fetchAllMarketItems();
assertEquals(1, ghContentMap.values().size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ void testGetGithubContent() throws IOException {
var mockGHContent = mock(GHContent.class);
final String dummryURL = DUMMY_API_URL.concat("/dummry-content");
when(mockGHContent.getUrl()).thenReturn(dummryURL);
when(ghRepository.getFileContent(any())).thenReturn(mockGHContent);
var result = gitHubService.getGHContent(ghRepository, "");
when(ghRepository.getFileContent(any(), any())).thenReturn(mockGHContent);
var result = gitHubService.getGHContent(ghRepository, "", "");
assertEquals(dummryURL, result.getUrl());
}

@Test
void testGetDirectoryContent() throws IOException {
var result = gitHubService.getDirectoryContent(ghRepository, "");
var result = gitHubService.getDirectoryContent(ghRepository, "", "");
assertEquals(0, result.size());
}

Expand Down
22 changes: 20 additions & 2 deletions marketplace-service/src/test/resources/meta.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
{
"$schema": "https://json-schema.axonivy.com/market/10.0.0/meta.json",
"id": "amazon-comprehend",
"name": "Amazon Comprehend",
"description": "Amazon Comprehend is a AI service that uses machine learning to uncover information in unstructured data.",
"names": [
{
"locale":"en",
"value": "Amazon Comprehend"
},
{
"locale":"de",
"value": "Amazon Comprehend DE"
}
],
"descriptions": [
{
"locale":"en",
"value": "Amazon Comprehend is a AI service that uses machine learning to uncover information in unstructured data."
},
{
"locale":"de",
"value": "Amazon Comprehend is a AI service that uses machine learning to uncover information in unstructured data. DE"
}
],
"type": "connector",
"platformReview": "4.5",
"sourceUrl": "https://github.com/axonivy-market/amazon-comprehend-connector",
Expand Down

0 comments on commit 5e1b12b

Please sign in to comment.