Skip to content

Commit

Permalink
MARP-463 Multilingualism for Website - landing page (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
phhung-axonivy authored Jul 5, 2024
1 parent 9dc6a5f commit 6880dac
Show file tree
Hide file tree
Showing 26 changed files with 297 additions and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public ProductModel toModel(Product product) {

private ProductModel createResource(ProductModel model, Product product) {
model.setId(product.getId());
model.setName(product.getName());
model.setShortDescription(product.getShortDescription());
model.setNames(product.getNames());
model.setShortDescriptions(product.getShortDescriptions());
model.setType(product.getType());
model.setTags(product.getTags());
model.setLogoUrl(product.getLogoUrl());
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/com/axonivy/market/constants/GitHubConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class GitHubConstants {
public static final String AXONIVY_MARKET_ORGANIZATION_NAME = "axonivy-market";
public static final String AXONIVY_MARKETPLACE_REPO_NAME = "market";
public static final String AXONIVY_MARKETPLACE_PATH = "market";
public static final String PRODUCT_JSON_FILE_PATH_FORMAT = "%s/product.json";
}
public static final String AXONIVY_MARKET_ORGANIZATION_NAME = "axonivy-market";
public static final String AXONIVY_MARKETPLACE_REPO_NAME = "market";
public static final String AXONIVY_MARKETPLACE_PATH = "market";
public static final String DEFAULT_BRANCH = "feature/MARP-463-Multilingualism-for-Website";
public static final String PRODUCT_JSON_FILE_PATH_FORMAT = "%s/product.json";
}
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
10 changes: 5 additions & 5 deletions src/main/java/com/axonivy/market/entity/MavenArtifactModel.java
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
9 changes: 7 additions & 2 deletions src/main/java/com/axonivy/market/entity/Product.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

import com.axonivy.market.model.MultilingualismValue;
import com.fasterxml.jackson.annotation.JsonProperty;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -28,9 +31,11 @@ public class Product implements Serializable {
@Id
private String id;
private String marketDirectory;
private String name;
@JsonProperty
private MultilingualismValue names;
private String version;
private String shortDescription;
@JsonProperty
private MultilingualismValue shortDescriptions;
private String logoUrl;
private Boolean listed;
private String type;
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/axonivy/market/enums/Language.java
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;
}
8 changes: 7 additions & 1 deletion src/main/java/com/axonivy/market/enums/SortOption.java
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;
}
}
24 changes: 22 additions & 2 deletions src/main/java/com/axonivy/market/factory/ProductFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@
import static org.apache.commons.lang3.StringUtils.EMPTY;

import java.io.IOException;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.kohsuke.github.GHContent;
import org.springframework.util.CollectionUtils;

import com.axonivy.market.entity.Product;
import com.axonivy.market.enums.Language;
import com.axonivy.market.github.model.Meta;
import com.axonivy.market.github.util.GitHubUtils;
import com.axonivy.market.model.DisplayValue;
import com.axonivy.market.model.MultilingualismValue;
import com.fasterxml.jackson.databind.ObjectMapper;

import lombok.AccessLevel;
Expand Down Expand Up @@ -49,13 +54,13 @@ public static Product mappingByMetaJSONFile(Product product, GHContent ghContent
}

product.setId(meta.getId());
product.setName(meta.getName());
product.setNames(mappingMultilingualismValueByMetaJSONFile(meta.getNames()));
product.setMarketDirectory(extractParentDirectory(ghContent));
product.setListed(meta.getListed());
product.setType(meta.getType());
product.setTags(meta.getTags());
product.setVersion(meta.getVersion());
product.setShortDescription(meta.getDescription());
product.setShortDescriptions(mappingMultilingualismValueByMetaJSONFile(meta.getDescriptions()));
product.setVendor(meta.getVendor());
product.setVendorImage(meta.getVendorImage());
product.setVendorUrl(meta.getVendorUrl());
Expand All @@ -68,6 +73,21 @@ public static Product mappingByMetaJSONFile(Product product, GHContent ghContent
return product;
}

private static MultilingualismValue mappingMultilingualismValueByMetaJSONFile(List<DisplayValue> list) {
MultilingualismValue value = new MultilingualismValue();
if (!CollectionUtils.isEmpty(list)) {
for (DisplayValue name : list) {
if (Language.EN.getValue().equalsIgnoreCase(name.getLocale())) {
value.setEn(name.getValue());
} else if (Language.DE.getValue().equalsIgnoreCase(name.getLocale())) {
value.setDe(name.getValue());
}
}
}

return value;
}

private static String extractParentDirectory(GHContent ghContent) {
var path = StringUtils.defaultIfEmpty(ghContent.getPath(), EMPTY);
return path.replace(ghContent.getName(), EMPTY);
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/axonivy/market/github/model/Meta.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.List;

import com.axonivy.market.model.DisplayValue;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
Expand All @@ -19,8 +20,8 @@ public class Meta {
@JsonProperty("$schema")
private String schema;
private String id;
private String name;
private String description;
private List<DisplayValue> names;
private List<DisplayValue> descriptions;
private String type;
private String platformReview;
private String sourceUrl;
Expand Down
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 @@ -29,7 +29,6 @@
@Log4j2
@Service
public class GHAxonIvyMarketRepoServiceImpl implements GHAxonIvyMarketRepoService {
private static final String DEFAULT_BRANCH = "master";
private static final LocalDateTime INITIAL_COMMIT_DATE = LocalDateTime.of(2020, 10, 30, 0, 0);
private GHOrganization organization;
private GHRepository repository;
Expand All @@ -45,7 +44,7 @@ public Map<String, List<GHContent>> fetchAllMarketItems() {
Map<String, List<GHContent>> ghContentMap = new HashMap<>();
try {
List<GHContent> directoryContent = gitHubService.getDirectoryContent(getRepository(),
GitHubConstants.AXONIVY_MARKETPLACE_PATH);
GitHubConstants.AXONIVY_MARKETPLACE_PATH, GitHubConstants.DEFAULT_BRANCH);
for (var content : directoryContent) {
extractFileInDirectoryContent(content, ghContentMap);
}
Expand Down Expand Up @@ -85,7 +84,7 @@ public GHCommit getLastCommit(long lastCommitTime) {
}

private GHCommitQueryBuilder createQueryCommitsBuilder(long lastCommitTime) {
return getRepository().queryCommits().since(lastCommitTime).from(DEFAULT_BRANCH);
return getRepository().queryCommits().since(lastCommitTime).from(GitHubConstants.DEFAULT_BRANCH);
}

@Override
Expand Down
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);
}
}
44 changes: 44 additions & 0 deletions src/main/java/com/axonivy/market/model/DisplayValue.java
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();
}
}
17 changes: 17 additions & 0 deletions src/main/java/com/axonivy/market/model/MultilingualismValue.java
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;
}
4 changes: 2 additions & 2 deletions src/main/java/com/axonivy/market/model/ProductModel.java
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 @@ -22,9 +22,9 @@ public interface ProductRepository extends MongoRepository<Product, String> {
@Query("{'marketDirectory': {$regex : ?0, $options: 'i'}}")
Product findByMarketDirectoryRegex(String search);

@Query("{ $and: [ { $or: [ { 'name': { $regex: ?0, $options: 'i' } }, { 'shortDescription': { $regex: ?0, $options: 'i' } } ] }, { 'type': ?1 } ] }")
Page<Product> searchByKeywordAndType(String keyword, String type, Pageable unifiedPageabe);
@Query("{ $and: [ { $or: [ { 'names.?': { $regex: ?0, $options: 'i' } }, { 'shortDescriptions.?': { $regex: ?0, $options: 'i' } } ] }, { 'type': ?1 } ] }")
Page<Product> searchByKeywordAndType(String keyword, String type, String language, Pageable unifiedPageabe);

@Query("{ $or: [ { 'name': { $regex: ?0, $options: 'i' } }, { 'shortDescription': { $regex: ?0, $options: 'i' } } ] }")
Page<Product> searchByNameOrShortDescriptionRegex(String keyword, Pageable unifiedPageabe);
@Query("{ $or: [ { 'names.?1': { $regex: ?0, $options: 'i' } }, { 'shortDescriptions.?1': { $regex: ?0, $options: 'i' } } ] }")
Page<Product> searchByNameOrShortDescriptionRegex(String keyword, String language, Pageable unifiedPageabe);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.axonivy.market.entity.Product;

public interface ProductService {
Page<Product> findProducts(String type, String keyword, Pageable pageable);
Page<Product> findProducts(String type, String keyword, String language, Pageable pageable);

boolean syncLatestDataFromMarketRepo();
}
Loading

0 comments on commit 6880dac

Please sign in to comment.